I’m trying to wrap my head around how I would implement 2D shadow mapping for a series of lights.
The tutorial I’m following is this one, although it applies to 3D directional lights, so I’m just looking to it for general guidance:
For simplicity what I have at the moment is a series of vertices inside a buffer object, which I’m drawing as lines with one program.
I’m now looking to generate shadow maps using depth textures, which I can then pass to my final shader program to work out what’s in or out of the shadow and by how much.
I have a few assumptions about what I’d need to do to apply this to 2D, but I’d prefer to just run these by someone:
- I’ll need to redraw the scene from the perspective of each point light to create one depth texture per light.
- These depth textures will be something like 1024x1 in resolution, or potentially just a 1D texture if that’s possible.
- Each draw to these depth textures should use a perspective projection matrix.
- Once all depth textures are drawn they’ll be passed into another shader program as an array of textures, and these will inform whether a particular fragment is in shadow.
- This other program will effectively just be drawing a screen sized quad using an orthographic projection, passing over every fragment, and computing shadow / lighting intensities for an untextured background.
- I’m assuming that the best approach to using the depth textures is to derive the position in the depth texture from the angle between the current fragment and the light in question, then checking whether this corresponding value in the depth texture is nearer or further than the current fragment to find whether it’s in shadow.
Do these sound like reasonable assumptions to make?