View Full Version : Hardware shadow mapping
11-21-2004, 01:59 AM
I tried to modify a Hardware shadow mapping project found at www.paulsprojects.net (http://www.paulsprojects.net) (this site has really many cool opengl projects!) in order to texture scene objects. However, when i bind textures (in the 3rd draw pass), shadows disappear. I fail to understand why that happen, if you dare to take a look at the code you may download it here (http://www.flightzone.us/ShadowMappingTutorial.zip) .
11-21-2004, 05:04 AM
In the demo, the active texture unit is used to store the depth map. In order to draw objects with a different texture while shadowing, you need to bind that different texture to a different texture unit.
Another way to think about it is that the depth texture functions like a "shadow blanket". It is "draped" over the scene. In order for the other objects to use a texture while the shadow blanket texture is enabled, then that other texture must be bound to a different texture unit.
Hope that helps...
11-21-2004, 05:51 AM
I've setup a multitexture system, so now it basically works, but there is still a problem: if you take a look at the code, the texture matrix is modified during the 3rd pass in order to calculate the shadow texture, so when i rotate the object its texture does not, because the coordinates are the shadow map texture ones. Probably with this code you can understand better what i mean:
//Calculate texture matrix for projection
//This matrix takes us from eye space to the light's clip space
//It is postmultiplied by the inverse of the current view matrix when specifying texgen
static MATRIX4X4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1]
MATRIX4X4 textureMatrix=biasMatrix*lightProjectionMatrix*lig htViewMatrix;
//Set up texture coordinate generation.
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0));
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1));
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2));
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3));
//Bind & enable shadow map texture
glActiveTextureARB( GL_TEXTURE0_ARB );
//Bind & enable object texture
glActiveTextureARB( GL_TEXTURE1_ARB );
//Enable shadow comparison
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
//Shadow comparison should be true (ie not in shadow) if r<=texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
//Shadow comparison should generate an INTENSITY result
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
//Set alpha test to discard false comparisons
I should define eye_linear coordinates for the object_texture, but is it possible to do that ? I mean, texture coordinate definition is relative to the object or to each texture ?
Can i define for example sphere_map coordinates for ARB0, eye_linear for ARB1 and then use multitexturing ?
i'm really confused ...
11-21-2004, 05:56 AM
I've updated the project code with lastest modifications here (http://www.flightzone.us/ShadowMappingTutorial.zip)
11-21-2004, 06:15 AM
You don't need texgen or comparison functions for the object texture. The coordinates passed should be relative to the texture. (e.g. one corner is 0,0 and the other is 1,1).
Thus the shadow texture coordinates are generated automatically using texgen.
The object texture coordinates should be passed manually - e.g. MultiTexCoord....
The comparison mode is only required for shadow.
Hope this helps...
11-21-2004, 12:19 PM
Thanks i got it working. However, i made some tests playing around also with the nvidia SDK and i arrived to the point that stencil shadows and hardware shadow mapping have the same identical performances.
I have a 32000 triangles model, with stencil shadows i get about 37fps, with hardware shadow mapping about 34 (so even slower). I have a P4 3.2 and a Geforce6800GT.
I supposed Hw shadow mapping would be much much faster. Is it so or am i mistaken somewhere ? There are other solutions in order to build fast self-cast shadows ?
11-21-2004, 03:05 PM
I think use GL_SGIX_shadow ...
will more quickly.
Shadowmap v7 by Bobby G Chance Jr.
11-21-2004, 04:47 PM
The specific bottleneck in a scene will vary quite widely. Are you CPU limited, vertex limited, raster limited, texture filtering limited, shader limited, or limited somewhere else? Depending on where it is, different techniques will give different results.
32,000 isn't a very big scene for today's cards, by the way.
11-22-2004, 11:16 AM
I tried Bobby's shadowmap, it uses a 235 triangles model and performances on a GF6800 is around 30fps. Didn't study the code but that is a very low performance ...
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.