My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Documentation  
Documentation of the shader format and execution method
Phase-Implementation, Featured
Updated Aug 18, 2011 by godisgovernment

Dolphin-emu's post-processing shaders are written in Cg (or C for Graphics) and are used to modify the output of each frame after all other visual changes, right before it is displayed on screen. They make changes one pixel at a time.

Knowledge of C Programming Language is required. If you don't know C, you should look for a tutorial or check out the wikipedia article.

Simple Shader Example:

uniform samplerRECT samp0 : register(s0);

void main(out float4 ocol0 : COLOR0, in float2 uv0 : TEXCOORD0)
{
  float4 c0 = texRECT(samp0, uv0).rgba; // creates a variable representing a pixel and is set to the input color data
  ocol0 = float4(c0.r, c0.g, c0.b, c0.a); // set the output color to the value of c0
}

The shader's entry point is void main(out float4 ocol0 : COLOR0, in float2 uv0 : TEXCOORD0), the code inside of main is executed on the GPU per pixel render.

The parameter list of main()

  • ocol0 - This is the outgoing color component
  • uv0 - This is the incoming Texture Mapping Coordinate data

Main() is called on the GPU and passes in the UV Mapping data into uv0 variable, while setting the ocol0 variable will set the resulting pixel color after the shader is done executing.

Variable Types

  • samplerRECT - This data represents a texture
  • texRECT(samplerRECT rect, float2 uv) - this represents on a Pixel Component
  • Params

    • rect - data representing a frame's pixel set
    • uv - data representing the UV Mapping (the coordinates of the pixel to be sampled).

    Members

    • (float4)rgba - RGBA color data of the presented pixel component

  • float4(float red, float green, float blue, float alpha) - represents a RGBA Color Component
  • Params

    • red - red component (value range: 0.0 - 1.0)
    • green - green component (value range: 0.0 - 1.0)
    • blue - blue component (value range: 0.0 - 1.0)
    • alpha - alpha component (value range: 0.0 - 1.0)

    Members

    • (float) r - red component
    • (float) g - green component
    • (float) b - blue component
    • (float) a - alpha component
  • float2(float u, float v) - this represents a Texture Mapping Coordinate
  • Params

    • u - Axis U Component Offset
    • v - Axis V Component Offset

    Array Access

    • (float) float2[0] - Axis U Component (value range: 0.0 - 1278.0)
    • (float) float2[1] - Axis V Component (value range: 162.0 - 1216.0)
  • Other types are detailed in the Cg wikipedia article.

Global Variables

  • samp0 - This variable represents the rendered frame

So if you want to remove red colors from the rendered graphics, you do it like this:

uniform samplerRECT samp0 : register(s0);

void main(out float4 ocol0 : COLOR0, in float2 uv0 : TEXCOORD0)
{
  float4 c0 = texRECT(samp0, uv0).rgba; // creates a variable representing a pixel and is set to the input color data
  ocol0 = float4(0.0, c0.g, c0.b, c0.a); // set the output color to the value of c0, but make red always 0
}

Notes:

  • Try to keep expensive loops out of the main() function, as they will kill performance.
  • Passing pixel coordinate values greater than 1278 or 1216 or less than 0 or 162 to texRECT() is allowed. If 0, 1278, or 1216 is exceded, the return value is the color of the closest existing pixel. However, if uv0[1] is less than 162, the color returned will be black.


Sign in to add a comment
Powered by Google Project Hosting