Volumetric Shadows and the Stencil Buffer!!!!!!!!!

Hi all

I’m having real problems with volumetric shadows, using a Geforce 2 and opengl. I appear to be getting gaps between triangles, sharing a common edge, rendered into the stencil


The four vertices

a(50, 30, 50);
b(50, 30, 100);
c(100, 30, 100);
d(100, 30, 50);

And the two triangles

1: a b c
2 a c d

When they are rendered into the stencil buffer, and the scene is re-rendered with lighting enabled, pixel sized gaps beween the shared edge (a to c) are coming through, resulting in pixels of the green texture (of the terrain) showing through in the shadow. It is obvious that some pixels arent getting set correctly in the stencil buffer, but is this because of something I’m not setting in OpenGL, or due to the way opengl’s line drawing is handled?

Any ideas why? Cos Its driving me crazy!!

Any help would be greatly appreciated.



That should not happen. You should probably post more of your code here so we can see what OpenGL state you have set. If you’re using glPolygonOffset, that might cause it (but probably not).

Now, that being said, you are actually using the exact same vertices, correct? You aren’t using one set of vertices for the first poly and another set for the second, correct? Even if they look the same, they could be subtly different in their floating-point representation. In order for that edge to have no cracks, the line must be defined by the exact same floating-point values.

yup, they are exactly the same, and im not using polygonoffset. The example above produces a crack…and the vertices are the same. I think i know what the problem is, plz refer to my post above


You’re right these two triangles should produce a fine quad without any cracks.

Questions: Basically how and under which enviroment does your algorithm draw what geometry?

  • What is your color resolution? Only true color has 8 bit HW stencil on GeForce.
  • Do you have antilaliasing of any kind enabled? (GL_POLYGON_SMOOTH etc.)
  • Does it work if you use a quad instead of the two triangles?
  • What is the depth compare set to?
  • What are the stencil func, op and mask set to?
  • Does it work if you use the MS software renderer? (set suitable pixelformat with PFD_GENERIC_FORMAT)
  • Did you have a look at the real stencil buffer contents? (glReadPixels(…GL_STENCIL_INDEX,…)
  • What is the number of depth bits and how is your viewing frustum zFar/zNear set?

i dont know if this is it (i havent used stencil that much)

perhaps post a small snipet of the stencil code.
ive got a feeling youre doing something like drawing one tri into the stencil, + then when you draw the other tri along the edge because how the stencil is set up, the edge pixels are being removed.
sorry bad explanation