Back to main page

Post effects

Post effect can be used as image functions for applying effects on top of your game or just performing general calculations like image analysis or fluid simulations.

Some of these declarations are defined directly with these names and some are macro definitions to ensure version compability.

If you rename the pixel shader function to something else than PS then the engine will not find it.

The pixel shader must take the predefined type VS_to_PS as input and return float4.

VS_to_PS -> PS -> float4

Defining a vertex shader will do nothing because the engine will only compile the pixel shader.

The input argument must also keep it's name because it is used in macros.

Texture slots

// The effect's 16 texture and draw surface slots.

// Set them using PostEffect_GiveInputSurface each time before rendering the effect.

// Unused textures may contain a default texture.

Texture2D tex_0

...

Texture2D tex_15

Samplers

// Sampling without interpolation for input of the same size as the output surface.

SamplerState samConstant

// Sharp bilinear sampling.

SamplerState samLinear

// Like samConstant but with clamping.

SamplerState samClampedConstant

// Like samLinear but with clamping.

SamplerState samClampedLinear

Input structure

// Input to the pixel shader that will be accessed using the macro PixelPos.

struct VS_to_PS {

float4 Pos : SV_POSITION;

};

Arguments

// The effect's 16 input vectors.

// Set them using PostEffect_GiveInputVector each time before rendering the effect.

float4 Arg[0..15]

Vectors

// The ZW correction values for the 16 input surfaces.

// When an input surface is giving it's depth buffer, it will also give 2 values from the view matrix in the camera that took the picture.

// After sampling a surface that was giving it's depth buffer, you have the depth in the first channel in a ZW scale that is not linear.

// Use this formula to get the linear camera space depth from your sampled ZWDepth. LinearDepth = ZWCorrection[SurfaceIndex].y / (ZWDepth - ZWCorrection[SurfaceIndex].x)

float2 ZWCorrection[0..15]

// The width and height of the output surface.

// Use it to divide PixelPos to get the UV coordinates to sample from when making color functions.

float2 Dimensions

// The current pixel's 2D position on the output surface starting from the upper left corner at float2(0.5f,0.5f) and ending in the bottom right corner at float2(Output's width - 0.5f, Output's height - 0.5f).

// This is a macro definition for the only data given from the vertex structure.

// Defined as (input.Pos.xy) and will therefor need the default name for input.

float2 PixelPos

Scalars

// A global time variable that you can set using Shader_SetGlobalTime.

// It works with all shaders at any time.

float GlobalTime