Back to main page

Draw shaders

Draw shaders are used instead of post effect shaders when you only need to change a small part of an image to draw a line, box, circle, ellipse, character, rotated image or anything else that you can draw inside the quad.

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 look for 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 Draw_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 macros.

struct VS_to_PS {

float4 Pos : SV_POSITION;

float4 Tex : TEXCOORD1;

float2 Pos_ObjectSpace : TEXCOORD2;

};

Arguments

// The effect's 16 input vectors.

// Set them using Draw_GiveInputVector each time before drawing with Draw_RenderQuad.

float4 Arg[0..15]

Vectors

// The width and height of the output surface.

// Use it to divide PixelPos to get the UV coordinates for a texture projection covering the entire output surface.

float2 Dimensions

// The current pixel's 2D position on the output surface starting from the upper left corner at float2(0.0f,0.0f).

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

float2 PixelPos

// The current pixel's 2D position in the drawn object from -1 to +1 in both dimensions.

// It goes from -1 to +1 from left to right.

// It goes from -1 to +1 from top to bottom.

// Defined as input.Pos_ObjectSpace and will therefor need the default name for input.

float2 ObjectPos

// The current pixel's UV1 coordinates.

// U goes from it's MinU to MaxU from left to right.

// V goes from it's MinV to MaxV from top to bottom.

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

float2 UV1

// The current pixel's UV2 coordinates.

// U goes from it's MinU to MaxU from left to right.

// V goes from it's MinV to MaxV from top to bottom.

// Defined as (input.Tex.zw) and will therefor need the default name for input.

float2 UV2

// Red,Green,Blue,Alpha in x,y,z,w.

// Set it using Draw_GiveInputColor before drawing with Draw_RenderQuad.

// Use it as you want for anything related to colors that need (1,1,1,1) as the default value.

float4 Color

Scalars

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

// It works with all shaders at any time.

float GlobalTime