Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Hardware shadow mapping

Hybrid View

  1. #1
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Hardware shadow mapping

    I tried to modify a Hardware shadow mapping project found at 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 .
    Thanks

    Alex

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2002
    Posts
    166

    Re: Hardware shadow mapping

    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...

  3. #3
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Re: Hardware shadow mapping

    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:

    Code :
    	//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*lightViewMatrix;
     
    	//Set up texture coordinate generation.
    	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
    	glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0));
    	glEnable(GL_TEXTURE_GEN_S);
     
    	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
    	glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1));
    	glEnable(GL_TEXTURE_GEN_T);
     
    	glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
    	glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2));
    	glEnable(GL_TEXTURE_GEN_R);
     
    	glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
    	glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3));
    	glEnable(GL_TEXTURE_GEN_Q);
     
    	//Bind & enable shadow map texture
    	glEnable(GL_TEXTURE_2D);
    	glActiveTextureARB( GL_TEXTURE0_ARB );
    	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
     
    /////////////////////////////////////////////////
     
    	//Bind & enable object texture
    	glEnable(GL_TEXTURE_2D);
    	glActiveTextureARB( GL_TEXTURE1_ARB );
    	glBindTexture(GL_TEXTURE_2D, object_texture);
    	//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
    	glAlphaFunc(GL_GEQUAL, 0.99f);
    	glEnable(GL_ALPHA_TEST);
     
    Draw_OBJECT();
    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 ...

  4. #4
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Re: Hardware shadow mapping

    I've updated the project code with lastest modifications here

  5. #5
    Junior Member Regular Contributor
    Join Date
    May 2002
    Posts
    166

    Re: Hardware shadow mapping

    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...

  6. #6
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Re: Hardware shadow mapping

    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 ?

  7. #7
    Intern Newbie
    Join Date
    Dec 2003
    Location
    china
    Posts
    37

    Re: Hardware shadow mapping

    I think use GL_SGIX_shadow ...
    will more quickly.

    samples:
    http://nehe.gamedev.net/data/downloa...d.asp?letter=S

    Shadowmap v7 by Bobby G Chance Jr.

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: Hardware shadow mapping

    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.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  9. #9
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Re: Hardware shadow mapping

    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 ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •