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

Thread: Camera inside shadow volume

  1. #1
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Camera inside shadow volume

    I can only get shadow volumes to work like this. When the camera goes inside the volume, the shadow disappears. I have read several papers on "Carmack's Reverse" but it results in no shadows when I use all the settings other people suggest. Please show me what to replace in this code to make it work right.

    The object brush I draw at the end is an extruded shape that contains the entire shadow volume mesh. This will cover the entire area of the shadow on screen, so I use it instead of covering the whole screen with a quad.

    Code :
    								'Draw shadows
    								glclear GL_STENCIL_BUFFER_BIT
    								glDisable GL_LIGHTING
    								glDepthMask GL_FALSE
    								glEnable GL_STENCIL_TEST
    								glColorMask GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE
    								glStencilFunc GL_ALWAYS,1,255
     
    								'First Pass. Increase Stencil Value In The Shadow
    								glFrontFace GL_CCW
    								glStencilOp GL_KEEP,GL_KEEP,GL_INCR
    								lightlink.shadowvolume.draw()
     
    								'Second Pass. Decrease Stencil Value In The Shadow
    								glFrontFace GL_CW
    								glStencilOp GL_KEEP,GL_KEEP,GL_DECR
    								lightlink.shadowvolume.draw()
     
    								'Final pass
    								glFrontFace GL_CCW
    								glColorMask GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE
    								glColor4f 0.0,0.0,0.0,a
    								glStencilFunc GL_NOTEQUAL,0,255
    								glStencilOp GL_KEEP,GL_KEEP,GL_KEEP
    								gldisable GL_DEPTH_TEST
     
    								'Draw object brush
    								glmatrixmode GL_MODELVIEW
    								glpushmatrix()
    								glloadidentity()
    								glRotatef camera.roll,0,0,1
    								glRotatef camera.pitch,1,0,0
    								glRotatef -camera.yaw,0,1,0
    								glTranslatef -camera.x,-camera.y,camera.z
    								glScalef 1,1,-1
    								lightlink.brushvolume.build()
    								For face:tface=EachIn lightlink.brushvolume.faces
    									If pointplanedistance(camera.x,camera.y,camera.z,face.nx,face.ny,face.nz,face.d)<0.0
    										glenableclientstate GL_VERTEX_ARRAY
    										glVertexPointer 3,GL_FLOAT,0,BankBuf(face.rendersurface.vertexarray)
    										glDrawElements GL_POLYGON,face.rendersurface.indicearray.size()/2,GL_UNSIGNED_SHORT,BankBuf(face.rendersurface.indicearray)
    									EndIf
    								Next
    								glmatrixmode GL_MODELVIEW
    								glpopmatrix()
     
    								'Restore Settings
    								glenable GL_DEPTH_TEST
    								gldisable GL_STENCIL_TEST
    								gldepthmask GL_TRUE
    								glcolor4f 1,1,1,1

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    748

    Re: Camera inside shadow volume

    for z-fail (or carmacs reverse) it's glStencilOp GL_KEEP GL_INCR GL_KEEP
    not glStencilOp GL_KEEP,GL_KEEP,GL_INCR

    and glStencilOp GL_KEEP,GL_DECR,GL_KEEP instead of glStencilOp GL_KEEP,GL_KEEP,GL_DECR

    And don't forget to cap of the shadow volumes

  3. #3
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Re: Camera inside shadow volume

    Well, I tried those two changes, but no shadows appear with the code I have above. What other changes are needed?

  4. #4
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Re: Camera inside shadow volume

    Anyone? If I use my original code, shadows appear, but disappear when I enter the volume. If I make the suggested changes, no shadows appear at all.

  5. #5
    Senior Member OpenGL Pro cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    1,058

    Re: Camera inside shadow volume

    I would suggest starting with some working example code. It can be tricky to debug problems with SSV rendering.
    Cass Everitt -- cass@xyzw.us

  6. #6
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Re: Camera inside shadow volume

    I'm afraid that's impossible, without posting my entire engine source.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,401

    Re: Camera inside shadow volume

    I thought your code didn't work.

Posting Permissions

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