Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: ShadowMapping: Shadows only visible at y=0

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    16

    ShadowMapping: Shadows only visible at y=0

    hello,
    i have implemented shadowmapping with an FBO and GLSL.
    it is used on a heightfield. that is some objects (trees, plants, ...) cast shadows on the heightfield.

    the problem i have, is that the shadows are only visible on the ground of the heightfield. that is, where the heightfield's height = 0. as soon as there is some height involved, the shadows disappear. if i look at the shadowmap itself, everything looks fine... objects that are closer to the light are darker.

    here is my GLSL code:
    Code :
    uniform mat4 lightView, lightProjection;
     
    const mat4 biasMatrix = mat4(	0.5, 0.0, 0.0, 0.0,
    								0.0, 0.5, 0.0, 0.0,
    								0.0, 0.0, 0.5, 0.0,
    								0.5, 0.5, 0.5, 1.0);	//bias from [-1, 1] to [0, 1]
     
    void main()
    {	
    	gl_Position = ftransform();	
     
    	mat4 shadowMatrix = biasMatrix * lightProjection * lightView;
    	shadowTexCoord = shadowMatrix * gl_Vertex;    
    }
    Code :
    uniform sampler2DShadow shadowmap;
    varying vec4 shadowTexCoord;
     
    void main() 
    {    
        vec4 shadow = shadow2DProj(shadowmap, shadowTexCoord, 0.0);
        float colorshadow = shadow.r < 0.1 ? 0.5 : 1.0;
     
    vec4 color = vec4(1,1,1,1);	
     
    	gl_FragColor = vec4( color*colorshadow, color.w );	
    }

    thanks a lot for any help on this!

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    16

    Re: ShadowMapping: Shadows only visible at y=0

    (bump)

    i am still having this problem. btw: shadows are there on objects that are below height 0 too. so it is not just at height 0 but on anything below 0 but not above 0.

    thanks for any help!

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: ShadowMapping: Shadows only visible at y=0

    Code :
    const mat4 biasMatrix = mat4( 0.5, 0.0, 0.0, 0.0,
    			      0.0, 0.5, 0.0, 0.0,
    			      0.0, 0.0, 0.5, 0.0,
    			      0.5, 0.5, 0.5, 1.0);

    That looks suspect. You should transpose the matrix before using it.

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    16

    Re: ShadowMapping: Shadows only visible at y=0

    thanks for your reply!

    if i transpose it, it looks like this right?
    Code :
    const mat4 biasMatrix = mat4(	0.5, 0.0, 0.0, 0.5,
    				0.0, 0.5, 0.0, 0.5,
    				0.0, 0.0, 0.5, 0.5,
    				0.0, 0.0, 0.0, 1.0);	//bias from [-1, 1] to [0, 1]

    anyways, this results in no shadows at all

  5. #5
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: ShadowMapping: Shadows only visible at y=0

    You should also check if the lightView and lightProjection matrices are correct. gl_Vertex is treated as a column vector, so matrix elements should be set in the column major order.

  6. #6
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    16

    Re: ShadowMapping: Shadows only visible at y=0

    thanks for your reply.
    well the matrices are pretty much what i get from
    glGetFloatv(GL_PROJECTION_MATRIX) in the shadowpass.

    in detail my shadowpass setup looks like this:

    Code :
    	glClearColor(1,1,1,1);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	glPushAttrib(GL_VIEWPORT_BIT);
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	int const size = 50;
    	glOrtho(-size, size, -size, size, 1.0, 100.0);
     
     
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
     
    	gluLookAt(	myp.lx+10, myp.ly+40, myp.lz+10, 
    				myp.lx, myp.ly, myp.lz, 
    				0, 1, 0); // light view matrix
     
    	glViewport(0, 0, sm_size, sm_size);
     
    	glGetFloatv(GL_PROJECTION_MATRIX, lpm);
    	glGetFloatv(GL_MODELVIEW_MATRIX, lvm);

  7. #7
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: ShadowMapping: Shadows only visible at y=0

    Oops! Actually you were right, the bias matrix you set at the beginning is the right one, as elements are set in column major order as I said So once the matrix content written, it looks like the transpose one. Sorry, no more idea for now!

  8. #8
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: ShadowMapping: Shadows only visible at y=0

    Realizing that you are using the shadow2DProj built-in function, did you set correctly the depth comparison mode to the depth texture? Something like:

    Code :
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);

  9. #9
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    16

    Re: ShadowMapping: Shadows only visible at y=0

    thanks!

    yes these two parameters are set to the depth texture.

    the really strange thing is, that shadows are visible on anything that is below the height of zero (y<0) in the scene. but anything above it, does not have shadows, although everything looks fine in the shadowmap itself.

  10. #10
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    16

    Re: ShadowMapping: Shadows only visible at y=0

    (bump)

    could it be, that i forgot to integrate the transformations into the shadowtexcoords? because after thinking about this for a while, it seems that the shadowcoords do not respect the place, rotation and scaling of the objects.

Posting Permissions

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