ReShadeFX for Beginners#

Straight to the point:

  • Vertex Shader: Code that operates on each vertex.

  • Pixel Shader: Code that operates on each pixel.

What is a Shader?#

A shader is code that performs mathematical operations.

Think of it like drawing a square:

  1. Define the square’s outline.

  2. Connect the outline.

  3. Fill the square with color.

Your First Vertex Shader#

 1// Vertex shader: Generates a screen-filling triangle.
 2// Based on: https://www.reddit.com/r/gamedev/comments/2j17wk/a_slightly_faster_bufferless_vertex_shader_trick/
 3
 4void PostProcessVS(
 5   in uint id : SV_VertexID,           // Vertex ID from CPU.
 6   out float4 position : SV_Position,  // Vertex position for GPU.
 7   out float2 texcoord : TEXCOORD      // Texture coordinates for GPU.
 8)
 9{
10   // PART 1: Calculate texture coordinates.
11   // Texture coordinates range from 0 to 1.
12
13   texcoord.x = (id == 2) ? 2.0 : 0.0;
14   texcoord.y = (id == 1) ? 2.0 : 0.0;
15
16   // PART 2: Calculate clip-space position.
17   // Clip-space:
18   //   Bottom-left: (-1.0, -1.0)
19   //   Top-right: (1.0, 1.0)
20
21   position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
22
23   // PART 3: GPU clipping and interpolation.
24   //   - Fragments outside [-1, 1) are clipped.
25   //   - texcoord and position are interpolated.
26}

Your First Pixel Shader#

 1// Pixel shader: Colors each pixel of the triangle.
 2
 3void PostProcessPS(
 4   in float2 texcoord : TEXCOORD, // Texture coordinates from GPU.
 5   out float4 color : SV_Target   // Pixel color for GPU.
 6)
 7{
 8   // Use texcoord to set color.
 9   //   texcoord(1.0, 0.0) -> red
10   //   texcoord(0.0, 1.0) -> green
11   //   texcoord(1.0, 1.0) -> yellow
12
13   color.r = texcoord.x;
14   color.g = texcoord.y;
15   color.b = 0.0;
16   color.a = 1.0;
17}

Your First Technique#

1technique ExampleShader
2{
3   pass
4   {
5      VertexShader = PostProcessVS;
6      PixelShader = PostProcessPS;
7   }
8}