Just realised that shadowPosition is not declared with the [[position]] attribute. So the rasterizer won’t have performed the perspective divide and viewport transform.

So I assume this calculation is actually where we perform the perspective divide and transform the z-coordinate from homogeneous clip space to normalized device coordinates?

I had assumed this was used to unproject the vertex…

The part that still confuses me is:

“Determine a coordinate pair from the shadow position that will serve as a screen
space pixel locator on the shadow texture. Then, you normalize the coordinates
from [-1, 1] to [0, 1]. Finally, you reverse the Y coordinate since it’s upside down.”

Since this seems to imply we are going from NDC coordinates to screen space coordinates in the range [0, 1]. Does the rasterizer in fact perform the perspective divide for shadowPosition but not the viewport transform?

I’m not in that headspace at them moment, so I am actually slightly puzzled at that code too .

Looking at the rendered data, shadowPosition is already in NDC due to the orthographic matrix, and the w is set to 1.0, so no point in dividing by it.

The rasteriser does not perform the perspective divide for shadow position. With orthographic matrices there is generally no perspective divide necessary anyway.

xy acts like uv coordinates which are from 0 to 1, and gets the texture data from the shadow map.