Example: Post Processing with PFX

The PFX file format can be used to create post processing effects

Post-processing refers to any full-screen technique performed on a scene after the scene has been fully composited and rendered. Instead of rendering 3D objects directly, the scene is first rendered to a texture. Pixel shaders are then used to apply filters to the texture before displaying it. Post-processing allows effects to be used that require awareness of the entire image such as high dynamic range, bloom, motion blur, screen space ambient occlusion, crepuscular rays, film grain simulation, depth of field, and shadow mapping.

Post-processing example

Post-process effects are created by chaining multiple effect blocks together. This can be done by setting the output of one effect block as the input of the next. The output of an effect block is set using the TARGET flag, while the input is set using the TEXTURE flag.

An example of this can be found below:

[TEXTURE]
NAME Lena
PATH "LenaPVR"
MINIFICATION LINEAR
MAGNIFICATION LINEAR
MIPMAP NEAREST
[/TEXTURE]

[TARGET]
NAME InputEffectOutput
SURFACETYPE RGB888
RESOLUTION 512 512
MINIFICATION LINEAR
MAGNIFICATION LINEAR
[/TARGET]

[TARGET]
NAME GreyscaleEffectOutput
SURFACETYPE RGB888
RESOLUTION 512 512
MINIFICATION LINEAR
MAGNIFICATION LINEAR
[/TARGET]

[TARGET]
NAME MixEffectOutput
SURFACETYPE RGB888
RESOLUTION 512 512
MINIFICATION LINEAR
MAGNIFICATION LINEAR
[/TARGET]

[EFFECT]
NAME InputEffect
ATTRIBUTE inVertex POSITION
ATTRIBUTE inTexCoord UV0
UNIFORM sTexture TEXTURE0
TEXTURE 0 Lena
TARGET COLOR0 InputEffectOutput
VERTEXSHADER ScreenAlignedVS
FRAGMENTSHADER InputFS
[/EFFECT]

[EFFECT]
NAME GreyscaleEffect
ATTRIBUTE inVertex POSITION
ATTRIBUTE inTexCoord UV0
UNIFORM sTexture TEXTURE0
TEXTURE 0 InputEffectOutput
TARGET COLOR0 GreyscaleEffectOutput
VERTEXSHADER ScreenAlignedVS
FRAGMENTSHADER GreyScaleFS
[/EFFECT]

[EFFECT]
NAME MixEffect
ATTRIBUTE inVertex POSITION
ATTRIBUTE inTexCoord UV0
UNIFORM sOriginal TEXTURE0
UNIFORM sGreyscale TEXTURE1
TEXTURE 0 InputEffectOutput
TEXTURE 1 GreyscaleEffectOutput
TARGET COLOR0 MixEffectOutput
VERTEXSHADER ScreenAlignedVS
FRAGMENTSHADER MixFS
[/EFFECT]

Breaking down this example

Assuming that MixEffect has been selected, the following steps will occur as illustrated in the image below.

  1. Lena.pvr, a texture file, is used as an input for the InputEffect block.
  2. The InputEffect block is run, outputting to InputEffectOutput.
  3. InputEffectOutput is used as an input for the GreyscaleEffect block.
  4. The GreyscaleEffect block is run, outputting to GreyscaleEffectOutput.
  5. InputEffectOutput and GreyscaleEffectOutput are used as inputs for the MixEffect block.
  6. The MixEffect block is run, rendering to MixEffectOutput.

Outputting to the Framebuffer

When a post-process effect is selected from the PVRShaman GUI, a dependency tree is built. This tree is used to determine which renders must be run and in which order to correctly display the selected effect. Once this effect has been run, its output is displayed in the Visualization Panel. It should be noted that the post-process effects described here cannot be applied to a model, unlike the render-to-texture effects.