View Full Version : 2D shadow mapping

03-28-2013, 01:28 PM

I have been wondering about how to implement this with openGL:


1. I have a map, with a flat floor and walls. Every thing here is 2d, there is no 3d geometry, only 2d poligons that compose the map.

2. Using the vertex of the polygons I cast shadows, to define the viewable area. The purple lines are part of the mask I use.

3. Using the shader when drawing the shadows on top of the scenario, I avoid the walls to be also obscured.

4. This way the shadows are cast dynamically along the walls as the field of view changes

My first approach was using shaders, just as I commented in the GLSL board (http://www.opengl.org/discussion_boards/showthread.php/181319-GLSL-questions), but this seems very very unefficient as I have to run a scan for every single fragment.

I have been suggested to approach this problem with shadow mapping. I should render the 2D scene into 4 different 1D textures that hold the depth of the distance to the first colliding surface.
The problem is that I have no idea how to render the projection of the 2d scene into the 1D texture. If I use, for example:
gluLookAt (x, y, 0.0, 0.0, x , y+1, 0.0, 0.0, 1.0);

to render the top view, the result is still 2D. Also, nothing would be rendered since all the vertex will be at the same plane, so all surfaces will be ortogonal to the camera.

Do you have any tip or idea of how to do these 2D-to-1D projections? I have been googling for scenarios like this one, but all of them are in 3D enviroments.


03-28-2013, 06:33 PM
Here is a library I made for 2D lighting a while ago: http://en.sfml-dev.org/forums/index.php?topic=6635.0