Volumetric Shadows..part 2

ok, just following up on my Volumetric Shadows post yesterday. I believe I know what the problem is, opengl rendering adjacent polygons. E.g.

The two triangles (a shadow volume)

glBegin(GL_QUAD_STRIP);
glVertex3f(0, 0.1, 0);
glVertex3f(0, -100, 0);
glVertex3f(0, 0.1, 2);
glVertex3f(0, -100, 2);
glVertex3f(2, 0.1, 2);
glVertex3f(2, -100, 2);
glVertex3f(0, 0.1, 0);
glVertex3f(0, -100, 0);
glEnd();

glBegin(GL_QUAD_STRIP);
glVertex3f(0, 0.1, 0);
glVertex3f(0, -100, 0);
glVertex3f(2, 0.1, 2);
glVertex3f(2, -100, 2);
glVertex3f(2, 0.1, 0);
glVertex3f(2, -100, 0);
glVertex3f(0, 0.1, 0);
glVertex3f(0, -100, 0);
glEnd();

are rendered into the stencil buffer. When the scene is re-rendered to update the pixels in the shadow volume, pixels from the texture underneath are popping though the adjacent edge (0,0) to (2,2) of the shadow. I dont think this is z-fighting, more like the pixels drawn to the stencil buffer (when the vertices of the polygon are projected out from the light) are snapping to the wrong pixel.

So…anyone else had problems with opengl drawing adjacent triangles, and if so, how can I get round it!

thnx

Lloyd

I am not quite clear about what your problem is, but it may have something to do with your display card. I have written a shadow volume demo before. On my G200, the stencil buffer is software simulated, and it does not display correctly, but on a TNT or TNT2, it all works OK.

Does anyone have code for this that they could post?

Hi,

I also noticed some artifacts related to stencil shadows, due, I believe, to some kind of rasterization imprecisions (on my GeForce1)… I also noticed that NVidia’s MD2 viewer (with shadow, bump+…) by Mark Kilgard exhibited the same artifacts!

I don’t believe there’s anything we can do about it if it’s really a rasterization issue (or turn back to a custom software rasterizer . Anyway, if someone has an idea, it’s welcome.

This is just venturing a guess, but it might make sense… Although the two quads being described have identical vertices (and hence we expect them to project to the exact same pixels) they are probably not drawn when GL is in the exact same state. If one is drawn with stencil test enabled, and the other without, then the OpenGL invariants do not guarantee that the exact same fragments will be generated. This is obviously going to be true on cards with only a software stencil buffer as things draw with stencil test will be software-rendered and things drawn without will be hardware rendered, but it could even be true on systems with hardware stencil. Try to render in a way such that you never disable stencil testing (keep it always on) but instead just set the stencil test to GL_ALWAYS or whatever so that you get the same effect as if it were off. In this case you should be guaranteed the same exact fragments by GL both times…

oops… i didn’t notice that the two quads only share an edge and are not identical, and that they are both part of the shadow volume. In this case I have no idea why you are getting “cracks” between these polygons. They should be getting drawn in the exact same state, right?