Kyle Hayward's

Portfolio

Post Processing Framework

Description

This is a post processing framework developed in C# for XNA as a tutorial for my graphics programming blog [link]. It allows the user to easily connect arbitrary post processes. At the bottom of the hierarchy is the PostProcessComponent (component) which represents a single atomic process. It has input and output in the form of textures and is combined with other components to form an entire PostProcessEffect (effect). The effect contains a chain of components to implement a single post process effect such as Depth-of-Field. The effect also handles linking input/output to/from its various components. This allows the components to be completely independent and also very simple in their implementation. Finally, there is a PostProcessManager, and this operates very similarly to the PostProcessEffect in that it contains a chain of effects and handles their input and output.

Features

  • Dynamic enabling/disabling of effects at run-time

  • Render target caching

  • Simple, independent components

  • Debugging easier due to components being simple

  • Chain together multiple arbitrary effects to achieve a specific result

  • Framework includes Bloom, Depth-of-Field, a distortion effect, and a radial blur as examples

Screen Shots

Video

Source Snippet

/// <summary>
/// This components applies a full-screen distortion to the framebuffer by
/// using a bumpmap to randomly displace the pixels.
/// </summary>
public class BumpmapDistortComponent : PostProcessComponent
{
    private double elapsedTime;

    public BumpmapDistortComponent(ContentManager content, GraphicsDevice gDevice)
        : base(content, gDevice)
    {
        elapsedTime = 0.0f;

        requiresBackbuffer = true;
        requiresSceneTexture = true;
        updatesSceneTexture = true;
    }

    public override void LoadContent()
    {
        base.LoadContent();

        effect = content.Load<Effect>(@"Shaders/BumpmapDistort");

        effect.CurrentTechnique = effect.Techniques[0];

        Texture2D fractalTex = content.Load<Texture2D>(@"Textures/bumpmap");
        effect.Parameters["Bumpmap"].SetValue(fractalTex);

        int width = backBuffer.Width;
        int height = backBuffer.Height;

        outputRT = new RenderTarget2D(graphics, width, height, 1, backBuffer.Format);
    }

    public override void Draw(GameTime gameTime)
    {
        //set the scene texture
        effect.Parameters["SceneTex"].SetValue(inputTexture);

        DrawFullscreenQuad(inputTexture, outputRT, effect);

        //update all components that need an up to date sceneTexture
        if (OnUpdateSceneTexture != null)
            OnUpdateSceneTexture(outputRT.GetTexture());
    }

    public override void Update(GameTime gameTime)
    {
        elapsedTime += gameTime.ElapsedGameTime.TotalSeconds;

        if (elapsedTime >= 10.0f)
            elapsedTime = 0.0f;

        effect.Parameters["Offset"].SetValue((float)elapsedTime * .1f);
    }
}

Downloads

Binary: XNA 3.0 Redist and .Net 3.5 Framework is required to be installed in order to run the demo.

Source: XNA Game Studio 3.0 and DirectX is required to be installed in order to build and run the source.