traditional shadow mappingdisable back-face cullingUsing polygon offsetShadows and Shadow Mapping
Shadows has remained as a big challenge for years in computer graphics. There are many ways to achieve “shadows”, some methods require special data structures and coding, and some has quality and speed falloffs.
Shadow mapping is one of methods been used by now, presenting relatively easy implementation and reasonable speed, at cost of aliasing effect for shadows far from the camera, a shadow texture to hold information for each point light (more for soft shadows) and big sized shadow map texture memory space requirement.
For more information:
http://en.wikipedia.org/wiki/Shadow_mapping
http://www.paulsprojects.net/tutorials/smt/smt.html

Back-face Culling
Back-face culling is the process of discarding polygons that are not facing towards the camera where the image is taken from. So often used in 3D video games, the process allows rendering of scene much faster by eliminating the calculation of back-facing polygons-those eventually will be covered by another front-facing polygons. To get a better understanding, one can imagine a box, having all the 6 faces facing outer from the cube, that means the top face will orient towards above the cube, and bottom face will orient below. So, any camera that is in the outer space of the cube will see the all 6 faces, but a camera in the cube will not see any.

Back-face Culling and Shadow Maps
In general purpose 3D drawing software and CAD applications, it is often impossible to determine the correct orientation of faces. Any single face in 3D space may be clock-wise or counter clock-wise, constructing a outer face of an entity or should be just a plane with both sides visible, depending on the whole drawing. So, all faces in CAD applications are simply rendered without back-face culling, remaining both sides visible.
On the other hand, shadowing with shadow map method requires back-face culling turned on, makes it impossible to use with CAD applications. After searching everywhere to find a way to make shadow mapping work while back-face culling is off, I haven’t came to any solution. Then I have decided to play a bit and finally made it! So here it is.

The Sample
I will be using a very good, yet simple to understand sample project, developed by Paul Baker. You can find his tutorial at http://www.paulsprojects.net/tutorials/smt/smt.html.
Load the project into Microsoft Visual Studio and run. Then open the file main.cpp and locate glEnable(GL_CULL_FACE); in function bool Init(void) on line 70 and replace it with glEnable(GL_CULL_FACE); and run again. When back-face culling disabled, you will see there is disturbing Z-fight effect, due to multi pass rendering required for shadow maps (Three passes actually, in this example).

The fix
This time, comment out glEnable(GL_CULL_FACE); and after that, insert:
glDisable(GL_CULL_FACE);
glPolygonOffset(1.0, 1.0);
glEnable(GL_POLYGON_OFFSET_FILL);
Shadows should be rendering correct again.

Polygon Offset
Polygon offset is useful when you face coplanar faces, ie: faces on the same exact location and depth to the camera. If such coplanar faces are fed to OpenGL pipeline for drawing, you will see the disturbing z-fight effect, random colors from both faces, as in the image at the top line of this post. The reason of the z-fight effect in the previous example is that the lit and dark areas both are the same distance to the camera, having the same depth values causing the trouble. Polygon offset comes for help:
Polygon offset does not only correct z-fight effects but can also be used for highlighting the edges of a solid object and create some other effects. For more information on polygon offset, refer to: http://www.opengl.org/resources/faq/technical/polygonoffset.htm


3 Comments to “Shadow Mapping and Back-face Culling”  

  1. 1 Igor

    Vorld is in shadovs, vere is light, shit in pants

  2. 2 wodamineralna

    I used to be very happy to find this net-site.I needed to thanks for your time for this glorious learn!! I undoubtedly having fun with every little little bit of it and I’ve you bookmarked to take a look at new stuff you weblog post. Forum Woda Mineralna

  3. 3 ilovewro

    I used to be very pleased to seek out this net-site.I needed to thanks in your time for this glorious read!! I undoubtedly having fun with every little little bit of it and I’ve you bookmarked to take a look at new stuff you blog post. I Love Wrocław

Leave a Reply