http://ogldev.atspace.co.uk/www/tutorial24/tutorial24.html
in the previous tutorial we learned the basic principle behind the shadow mapping technique and saw how to render the depth into a texture and later display it on the screen by sampling from the depth buffer.
in this tutorial we will see how to use this capability and display the shadow itself.
we know that shadow mapping is a two-pass technique and that in the first pass the scene is rendered from the point of view of the light.
let us review what happens to the Z component of the position vector during the first pass:
- the position of the vertices that are fed into the vertex shader are generally specified in local space.
- the vertex shader transforms the position from local space to clip space and forwards it down the pipeline (see tutorial 12 if u need a refresher about clip space).
- the rasterizer performs perspective divide (a division of the position vector by its W component). this takes the position vector from clip space to NDC spcae. in NDC space everything which ends up on the screen has a X,Y and Z components in the range [-1,1]. things outside these ranges are clipped away.
- The rasterizer maps the X and Y of the position vector to the dimensions of the framebuffer (e.g. 800x600, 1024x768, etc). The results are the screen space coordinates of the position vector.