Skip to content

7. Screen space shaders

theproadam edited this page Apr 8, 2020 · 1 revision

Screen Space Shader Code

Just like the fragment shader which outputs a pointer to the pixels that it will set, the screen space shader works in the same way. However, the screen space shader also outputs the X and Y pixel positions.

unsafe void ScreenSpacePass(byte* BGR, int posX, int posY)
{
    BGR[0] = 255; //Blue
    BGR[1] = 255; //Green
    BGR[2] = 255; //Red
}

Please don't exceed BGR[3]. Doing so may cause crashes. BGR[3] controls alpha, however currently renderXF ignores alpha values.

Once the shader code is ready, just create a instance of the shader class linked with your shader code method.

Shader ScreenSpaceShader = new Shader(ScreenSpacePass);

Using the shader

To use a created screen space shader, just select it with SelectShader(), and then use the Pass() function:

GL.SelectShader(ScreenSpaceShader);
GL.Pass();