PDA

View Full Version : Camera inside shadow volume



halo
07-17-2006, 03:39 PM
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.


'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.vertexarra y)
glDrawElements GL_POLYGON,face.rendersurface.indicearray.size()/2,GL_UNSIGNED_SHORT,BankBuf(face.rendersurface.ind icearray)
EndIf
Next
glmatrixmode GL_MODELVIEW
glpopmatrix()

'Restore Settings
glenable GL_DEPTH_TEST
gldisable GL_STENCIL_TEST
gldepthmask GL_TRUE
glcolor4f 1,1,1,1

zeoverlord
07-17-2006, 04:42 PM
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

halo
07-17-2006, 05:19 PM
Well, I tried those two changes, but no shadows appear with the code I have above. What other changes are needed?

halo
07-18-2006, 11:11 AM
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.

cass
07-19-2006, 07:57 AM
I would suggest starting with some working example code. It can be tricky to debug problems with SSV rendering.

halo
07-19-2006, 01:27 PM
I'm afraid that's impossible, without posting my entire engine source.

Brolingstanz
07-19-2006, 04:16 PM
I thought your code didn't work.