This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Greetings, I implemented the shadow volume method very similar to how it's done on the DirectX9 SDK. Now, I got shadows to work, they show up and all, but there's terrible flickering going on. I realize that must be the shadow volume zfighting with the mesh. But the problem is, I'm not sure how to fix it! I tried offsetting the mesh in the vertex shader, via: Pos.xyz *= 0.975f; and this worked on my card, but the offset is quite noticeable (the shadow volume is smaller than the mesh), and on my friends card, it still flickers. What are my options for fixing this?

##### Share on other sites
I would try to offset the shadow volume along the normals of the current vertex.
Pos.xyz = Pos.xyz - Normal.xyz * 0.05f;

you could also try to add the normal to the position, don´t know what looks better.
You could also try to tweak the values for your near- and far-clipping-plane, as these greatly affect your z-buffer-precision.

##### Share on other sites
But how am I getting ZFighting if it's supposedly all in the stencil buffer?

##### Share on other sites

If I recall correctly, I had to change my z-func from less to lessequals, or something of the sort. Try messing around with the z-func a bit, till you get it right.

##### Share on other sites
Well, I messed with the ZFunc values, and nothing seems to improve the problem. Can someone at least explain why this flickering is going on?

##### Share on other sites
Once again I'm just guessing, because the hardcore theories still elude me :)

When rendering the shadow volume to the stencil you disable ZBuffer writing, but ZBuffer reading is still enabled. Because you probably have rendered the mesh before the shadow volume, the depth information of the mesh is still available and applied when rendering the shadow volume. If I'm correct, this is what could be causing the Depth fighting, even though it's not really an issue.

You might be able to solve this by disabling the ZBuffer completely when rendering the shadow volumes (IF I'm correct), but that'll most likely cause other problems. For my project, I simply translated the shadow volume a short distance (0.1f) along the light vector, which turned out to work fine, so I didn't bother with fiddling around with the RenderState settings.

##### Share on other sites
one quite normal issue with shadow-flickering in the zfail algorithm is flickering on the shadowcaster itself due to shader invariance on the near-cap. one (of many) solutions to this is simply to use the polygons facing away from the lightsource instead of those who face towards it.

##### Share on other sites
If I understood the principles of shadow volumes correctly:

I guess you won´t get around altering your shadow volume a bit, so it doesn´t fit the shadowcaster exactly, because exactly same points tend to give different results all the time due to z-fighting, I guess.
Remigius´s approach with moving the volume along the light´s direction vector could help, but wouldn´t do any good with faces parallel to the light´s direction. I would try it out, though, because this should be an extremely rare case, I guess. Downsizing the shadow volume along the normals of the shadowcaster, as I suggested in my previous post, should help, too.
Have you tried fiddling around with the values for near- and far-clipping-plane?
Won´t help when the shadow volume isn´t a small amount larger or smaller than the shadowcaster, but if it is, it should help you to minimize the inaccuracy of the volume.

##### Share on other sites
Hey, thanks for the replies! I'll try implementing a few of your ideas and see if they work.

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633354
• Total Posts
3011487
• ### Who's Online (See full list)

There are no registered users currently online

×