PDA

View Full Version : Shadow Mapping Problems



Ehsan Kamrani
04-02-2007, 05:31 AM
I have two problems with shadow mapping(introduced by Lance Williams in 1978). Fisrt of all is the depth buffer precision. In Fisrt pass I draw the objects with ambient light. In thesecond pass, I use glDepthMask( GL_FALSE ) and glDepthFunc( GL_EQUAL ) and render the scene again with diffuse and specular light.The problem is that I see some artifacts when moving the camera in GeForce 4 MX because of finite precision in the depth buffer. I can solve this problem with stencil buffer, but it actually decreases the FPS.
The second problem is that both ARB_depth_texture and ARB_shadow extenstions are not supprted in GeForce 4 MX. Although it's an invaluable graphics card, But there are many people that use from such cards(GeForce 4 is only an example ).So we can not use shadow mappoing in such cards.A better approach is to use GLSL, But many cards don't support OpenGL 2.0.
So Is it a good idea to use shadow mapping in a commercial game?
-Ehsan-

therealremi
04-02-2007, 08:13 AM
I'm suprised anyone is still developing games for such acient cards as GeForce 4.
I'm not able to answer your question but I can give you an advice: develop a game that will run on Shader Model 3.0 compatible cards (which can be bought very cheap) and do not concern yourself with ancient hardware.

k_szczech
04-02-2007, 09:19 AM
I'm suprised anyone is still developing games for such acient cards as GeForce 4.My game was designed for GeForce 6, but still works on TNT2 :)


develop a game that will run on Shader Model 3.0 compatible cards and do not concern yourself with ancient hardware.What about Radeon X800 users? My friend has X850 which is as fast as my 7800GT (although with complex shaders GeForce is better).
Many of people still have Radeon 9800 and unfortunately many still have GeForce FX.

Ehsan: I got shadowmapping working on TNT2 for directional lights using pure OpenGL (no math or anything on CPU).
The trick is that shadowmapping is actually: sample texture and compare to linerily mapped value.
This is equivalent to: sample texture, subtract linearily mapped value and compare to constant.
And this is eqivalent to: sample texture, add reversed linearily mapped value and compare to constant.
This can be done using alpha test and 1D texture with GL_INTENSITY format and 256 pixels.
Unfortunately these are 8-bit shadowmaps, but can be enough for some light sources.

As for your precision problem - it should not happen if you do things right. Make sure you draw exactly the same geometry with the same matrices, clip planes, polygon winding, etc.

therealremi
04-02-2007, 10:35 AM
k_szczech, most of my friends have only laptops with some crappy integrated cards. But who cares? They do not buy games anyway;) Seriously, maybe you are right, I would be just too lazy to support old hardware.
Maybe you could post some link to a tutorial how to do some basic shadow mapping so that I could learn something too?

Ehsan Kamrani
04-03-2007, 03:19 AM
This page explains the problems I see in GeForce 4:
http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node20.html
If the problems is solved with glDepthMask( GL_FALSE ) and glDepthFunc( GL_EQUAL ), why this article has used the stencil buffer to solve the problem?
therealremi,
You can read these articles:
Projective Texture Mapping (http://developer.nvidia.com/object/Projective_Texture_Mapping.html)
Paul\'s Projects - Shadow Mapping Tutorial (http://www.paulsprojects.net/tutorials/smt/smt.html)

therealremi
04-03-2007, 05:51 AM
thanks Ehsan, I'm glad to see some serious game development going on in the Arab world. sory for the off-topic.

k_szczech
04-03-2007, 08:16 AM
why this article has used the stencil buffer to solve the problem?Because it rendered two polygons that ideally would lay on the same plane, but they were not identical (different vertices) therefore each pixel had a small depth error.
If the same example would draw two identical quads at the same location there would be no problem.

Some examples:
example #1:
Line 1 from point A to point B
Point C exactly in middle
Line 2 from A to C and line 3 from C to B

Ideally lines 2 and 3 would go through the same pixels that line A but in real life, point C must go through modelview and projection matrices and through rasterization. Subpixel accuracy is not unlimited.

example #2:
Line 1 from point A to point B
Line 2 from point A to point B with clip plane enabled that cuts line in half.

Again - second line will not cover first half of 1st line.

That's why you need to draw exactly the same thing in second pass. The only differences can be at fragment level (different shader, textures, blending, lighting, etc.).

And one more - if you use shaders then you have to use ftransform() in vertex shader to make it position invariant.

Ehsan Kamrani
04-03-2007, 10:22 AM
thanks Ehsan, I'm glad to see some serious game development going on in the Arab world. sory for the off-topic.
I'm not Arab. I'm Iranian and speak Farsi.
-Ehsan-