Buggy Shadow Volume / zfail

Started by
18 comments, last by jezham 15 years, 6 months ago
Ive been stuck on shadow volumes now for a while. almost there, always a last bug. I have a 'tree' mesh(es), which is a bunch of cones (made of triangles) stuck together like branches. Each cone is a solid model, each triangle wound the same (glcullface clips all in or all out) Im sure that this is well for the zfail, cause one cone produces a proper shadow (jsut like a simple cube goes well) but when the meshes overlap it forms a problem. At least, my guess is that seperate volumes cannot overlap or something (like when i 'stick' one cone in the other to make a 'branch'). however, when i have two cubes, and drag one in the other by hand, all seems well... the bug is that, only in the surfaces of the shadow, there are lines. also, the front and back cap; - the front cap is all triangles that are NOT facing the light ('back' of the mesh) - the back cap is the front-cap extruded to inf - when normally rendering the volume with culling enabled, you can see every side, when outside (and see nothing when inside) right ???? and a stupid question, should the back polygons be affected / be shaded? or only cast a shadow ? (of course it should be shaded, but does the zfail do that? i know it selfshadows, but the back faces seem different somehow) thanx
Advertisement
Holes are your problem.

If you are using a modeling program then just weld the verts from the tree's branch to the tree trunk, tidying up the seam.
If you want to stick to a cone, then ensure the base of the cone is closed. This will of course require extra triangles in your volume, but you only have to render them to the stencil buffer (not color/depth as they won't show unless you're inside the tree! - and that's regardless of viewing the extra triangles from front/back).

Hence, your second question...you also do not need to draw *any* back faces to color/depth buffers, only the stencil buffer like you are.
my cones have a base. they are solid and wounded. so i prety much rules out the geometry of one cone since they also produce a good shadow. its when they overlap. But understanding you, that shouldn't be a problem right ??
Apologies for not understanding the first time, you did clearly state the cones were solid.

The lines you describe, does every triangle of the cone produce them, or just the silhouette, or perhaps just the odd one here and there? And these lines are un-shadowed areas?

Another question, you say that two overlapping box's shadows never have this bug?
Quote:each triangle wound the same (glcullface clips all in or all out)


Not sure what you mean there (all in or all out)? Your volume's triangles should be defined the same way as you would if you were building a standard model.
right, thats what i mean. The inside is culled (standard), so you would see the volume as normal. completely visible when outside, completely invisible when inside.

There is no reason why an object can not penetrate another. I have various meshes overlapping (car / driver) working perfectly.

I guess a screenshot of the bug will really help here.
(http://www.tinypic.com/ are a good and fast host)


edit: I've just remembered a similar sounding bug which I used to have.
when drawing *front* faces of your volume's caps (not walls)
glEnable( GL_POLYGON_OFFSET_FILL );glPolygonOffset( 1.0f, 1.0f );...draw...glDisable( GL_POLYGON_OFFSET_FILL );

Without using the above I get "lines" too.

[Edited by - jezham on October 13, 2008 3:23:14 PM]
have also included that, but still those lines...
Perhaps try negative values in your situation (I draw lit areas first)? It really is tricky to say without seeing an image.
i tried al kinds of values.
at least its good to know that overlapping should be ok.
can you post me your pass code, or take a look at mine


glEnable (GL_POLYGON_OFFSET_FILL);
glPolygonOffset (1.0f, 1.0f);

// disable gl effects
glDisable (GL_LIGHTING);
glDisable (GL_BLEND);


// disable color and depth masks
glDepthFunc (GL_LEQUAL);
glDepthMask (GL_FALSE);
glColorMask (0,0,0,0);

// enable culling
glEnable (GL_CULL_FACE);
// setup stencil buffer
glEnable (GL_STENCIL_TEST);

// first pass
glCullFace (GL_FRONT); // Set Culling Face To Back Face
glStencilFunc (GL_ALWAYS, 0x0, 0xff);
glStencilOp (GL_KEEP, GL_INCR, GL_KEEP);
rdrsVolume (100.0f);

// Second Pass. Decrease Stencil Value In The Shadow
glCullFace (GL_BACK); // Set Culling Face To Back Face
glStencilFunc (GL_ALWAYS, 0x0, 0xff);
glStencilOp (GL_KEEP, GL_DECR, GL_KEEP);
rdrsVolume (100.0f);

glDisable (GL_POLYGON_OFFSET_FILL);

// set front face

glDisable (GL_CULL_FACE);

// Enable Rendering To Colour Buffer For All Components
glColorMask (1,1,1,1);

// setup stencil
glStencilFunc(GL_NOTEQUAL, 0x0, 0xff);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);

Vector clr = {0,0,0, 0.9f};
// render overlay
mod.renderFilter (clr);


thanx

This topic is closed to new replies.

Advertisement