Skip to main content
GameDev.net gamedev.net
🔒 Locked

Stencil shadows problem

Started by roos Jan 2, 2005 at 12:41 PM 1 replies 300+ views
Original Post
roos
roos
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:

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]
gulgi
gulgi
Hello..

The high-tessilation is just to not get "popping" shadow effects. It's when a triangle is in shadow, then the next frame it's in light. If this hapends on big triangles, it not that nice.

I'm almost sertain your artifacts are because your model isn't closed. If it's a single "hole" in the geometry normal stencil shadows will show artifacts.
You can either close the geometry (go through the geometry and stitch it together) or.. there is a more complicated shadow extrusion algorithm that can handle non-closed geometry as well... (sorry, don't have the link)

Good luck!
MikeyO
MikeyO
I had a post up here a couple days ago, using about the same algorithm and shader, and I have the same trouble with the Teapot model and the Cylinder.

I am thinking of implementing the pre-calculated edge detection stuff once I figure out how.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.