Original Post
Hi, I'm working on implementing basic Z-pass stencil shadow volumes... (Not carmack's reverse, I don't care about the case of the camera being within the volume) Anyways, it works perfectly on a sphere right now... but, for almost all models which are more complicated, it is completely messed up. Here is a screenshot (sorry for the ghettoness of the screenshot, didn't bother to texture the teapot or what-not):
I went over my shader and the code that sets up the stencil buffer and I can't seem to find anything wrong. Has anyone else ever had a problem like this, or might have some intuition as to what the problem could be? If it helps, here's a high level description of what I'm doing: 1. Render the scene normally 2. Enable stencil buffer, turn off Z write and writes to frame buffer 3. Render front faces of shadow volume, increment stencil buffer 4. Render back faces of shadow volume, decrement stencil buffer 5. Render a black quad over the screen, pass if stencil value >= 1 The shadow volume is drawn using a vertex shader which extrudes vertices which are facing away from the light. Here is the relevant section of the shader:
I went over my shader and the code that sets up the stencil buffer and I can't seem to find anything wrong. Has anyone else ever had a problem like this, or might have some intuition as to what the problem could be? If it helps, here's a high level description of what I'm doing: 1. Render the scene normally 2. Enable stencil buffer, turn off Z write and writes to frame buffer 3. Render front faces of shadow volume, increment stencil buffer 4. Render back faces of shadow volume, decrement stencil buffer 5. Render a black quad over the screen, pass if stencil value >= 1 The shadow volume is drawn using a vertex shader which extrudes vertices which are facing away from the light. Here is the relevant section of the shader:
dp3 r0.x, v3, -c4 // dot product between normal and light direction
sub r1, v0, c7 // get vector from light to vertex
slt r2.x, r0.x, c8.y // if dot product < 0 (facing away from light), then...
mul r2.x, r2.x, c8.x // Extrude by doing this:
mad r3, r2.x, r1, v0 // vertexPosition += distanceToExtrude * vLightToVertex
I have heard stencil volumes require highly tessellated meshes otherwise artifacts can occur. Also they don't work well for sharp edges. Could it be that the problem is with the mesh itself, and I need to somehow modify it to work with shadow volumes? Sorry if this post is kind of vague, any input would *really* be appreciated! :) roos [Edited by - roos on January 2, 2005 1:02:45 PM]