suppress self shadows

i’m working with stencil shadow volumes and i’d like to get rid of those nasty self shadows on cylinders and spheres. does anyone have a good idea how to suppress those? it’s no problem to keep certain geometry from receiving shadows at all, but i still want it to recieve shadows from other models, just not from itself. thx!

Are you using different models to generate shadow polys from, then the models you’re actually drawing for lighting? I dont see any other reason to have bad self shadowing :slight_smile: When I use the same model, everything works nicely!

But to stop something self-shadowing I guess when you draw it you want the stencil to exclude the object itself. Well the first thing that comes to mind is:

Draw stencil volumes for scene into stencil (exclude model)
Draw model thats not self shadowing with lighting (only that model!)
Draw model volumes into stencil
Draw rest of scene with lighting

There might be a more optimal/less intrusive method though? :slight_smile:

If you use a very large polygon offset (or a vertex program) to push just the z-value of the shadow volumes to the back you can avoid 99% of all popping artefacts.

The popping that occurs comes from phong (or gouraud if someone uses that :slight_smile: ) shading, since it also illuminate backfaces. There are a few ways to deal with it.

  1. N.L^value, to “narrow” the shading. In other words; make it less illuminated.
  2. Renderer back-faces from the light source where stencil=1 and set stencil=0.
  3. Disable self-shadowing (like DOOM 3).

Another possible way to do it, might be easier to implement and work better with deferred shading:

If you sorted your shadow volumes so that you draw all the ones for objects that dont self shadow first, then zeroed the stencil buffer with the visible faces of those objects, then proceed as normal with the rest of your regular shadow volumes & lighting, it should work out. This would prohibit any non-self shadowing object from casting onto another non-self shadowing object though, and it might be a bit slower than cheifwiggums suggestion… but it lets you do all your volumes without switching gl state back and forth from rendering to stencil fill.

P.S. of course if you should only be attenuating the direct illumination term if you’re stencil testing ambient & other stuff then that’s just idiotic.

wow thanks for the feedback. i’ll give ChiefWiggum’s suggestion a try and will also take a closer look at the code from :slight_smile:

Originally posted by dorbie:
[b] [/b]
From the lenghty discussion I remember there were some problems with this technique (especially with concave objects) that were unsolved. Has that changed?

After all the things I tried I really found that the simplest solution is the best: Offset the shadow volumes away from the viewer. This avoids those artefacts that come from the fighting between gouraud shading and the discrete silhouette approximation.

Offset the shadow volumes away from the viewer.
what exactly does this mean? thx! :slight_smile:

Originally posted by Vexator:
[quote]Offset the shadow volumes away from the viewer.
what exactly does this mean? thx! :slight_smile:
[/QUOTE]Add an appropriate value to the z-coordinate of the shadow volumes in eye view (the simplest solution is to use glPolygonOffset() with a factor of 0 and a high value for units)