Vertex Shader of Depth Prepass

Once the CPU submits the draw call for the depth prepass, the GPU begins executing it. At this point, it is important to understand how the vertex shader works, as the depth prepass does not require a pixel shader for our cube.

⚠️
If you want to debug vertex shader code like me, use PIX instead of RenderDoc.

A short description of the process is as follows:

  • The vertex shader input contains the vertex's position.
  • The vertex shader loads data from the uniform buffer, instance buffer, and other buffers to obtain the correct LocalToWorld matrix.
  • The WorldToClip matrix is loaded from the view data.
  • The position, LocalToWorld, and WorldToClip are multiplied together.
  • The result is written to output.

A simplified version is this image.

image

The core is:

(local) vertex position → LocalToWorld → WorldToClip → Output Position

  • (local) vertex position : from vertex shader input.
  • LocalToWorld: You can see how the vertex factory (local vertex factory) try to load the instance data based on vertex shader input data ( InstanceId ) , from the instance data buffer. The goal is to get the LocalToWorld matrix
  • WorldToClip: From the view uniform buffer data

In the case you want to check the details:

image

The most complex part is decoding the instance data, but we will discuss this later, so don't worry. For now, I recommend that you remember the first, simple image as a concept map and treat the second, more complex image as a reference.