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 4 of 4

Thread: Shadow Volume problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    2

    [SOLVED] Shadow Volume problem

    Hi all,
    I have a problem calculating my shadows using shadow volumes and the stencil buffer. I have two triangles (triangle a and b). They have the same position except one of them is further away (triangle b), so triangle a is in front of triangle b. Now when the light is in front of them, the shadow of triangle a will cast correctly on triangle b. But when i move my light source behind triangle b, there is no shadow on triangle a. I am drawing my volumes like this:
    Code :
    glFrontFace(GL_CW);
    glStencilFunc(GL_ALWAYS, 0x0, 0xff);
    glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
    drawShadowVolume();
    glFrontFace(GL_CCW);		
    glStencilFunc(GL_ALWAYS, 0x0, 0xff);
    glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
    drawShadowVolume();
    I think, thats the common way of doing it. I also think, i know the problem. If the light is behind the triangles, the directions of the shadow volumes are changed, because the shadow volume is pointing in the direction of the camera instead of away from it. So the face culling is not working like it should be. If i swap glFrontFace(GL_CW); and glFrontFace(GL_CCW); like this:
    Code :
    glFrontFace(GL_CCW);
    glStencilFunc(GL_ALWAYS, 0x0, 0xff);
    glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
    drawShadowVolume();
    glFrontFace(GL_CW);		
    glStencilFunc(GL_ALWAYS, 0x0, 0xff);
    glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
    drawShadowVolume();
    then the shadow is working when the light is behind the triangles, but if the light is in front of them, it's not working (obviously). Now i don't know, how i could fix this.
    Does anyone have a clue what i could change to get it to work properly?
    If some screenshots or more code is needed, i will provide it.
    Thanks in advance...
    cookiehunter
    Last edited by cookiehunter; 05-29-2012 at 04:18 AM.

Tags for this Thread

Posting Permissions

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