The problem of Z-Fighting from shadow volume....

Started by
10 comments, last by jhk8211 19 years, 4 months ago
Hi, I,m developer of korea so.. my English can be very poor. -_-; therefore,, plz understand ^^ Ok, I have implemented Shadow Volume using Depth-Pass algorithm. Edge detect, Insert degenerated quad, extrude volume opposite light pos.. 2-sided stencil buffer operation... these all parts are working very well. and closed volume is robust. all things is OK. but, I have encountered other problem. The volume's front cap and original mesh are raised Z-Fighting problem. because the volume's front cap and original mesh's light casted faces are coplanar planes. So, I decrease scale slightly for remove Z-Fighting. The Z-Fighting removed.. but, Mesh that like teapot is not symmetric mesh so, if decrease scale of teapot volume then teapot's handle is out of original mesh's handle and be shadow. This result is not expected. I heared that Depth-Bias (In DX 8.1 Z-Bias) is not robust solution. The DX 9.0c Shadow Volume sample is very complexity source and the sample is not use Depth-Bias and decrease volume's scale. How solve this problem? What solution is best?
Advertisement
I had a similar problem using openGL, I managed to clear it up using the glPolygonOffset command.
Unfortunately I have no experience with d3d so I dont know if there is a similar command available.
You just have to modify your projection matrix before rendering the shadow volume.
Like this, the volume will be pushed a little bit behind the original mesh polygons.
I don't have the code piece at hand, but googling should give you this rapidly.
For closed meshes you can extrude the front faces away from the light instead of the back faces.
at last, solved out this problem use depth bias method.



Maybe.. OpenGL's glPolygonOffset command is similar with DX 9.0c's Depth-Bias, I think.

Thanx for all answers. ^^
be aware that depth bias is flawed and hardly controlabele.
plus, it doesn't behave the same on all graphics cards i believe.

also, not sure, but i think i was told that only dx is touched by this problem, i believe the glPolygonOffset is much more portable, but again, i'm really not sure...
Hmm..

I know that depth-bias is not robust solution, I said above.

you said,,

"You just have to modify your projection matrix before rendering the shadow volume.
Like this, the volume will be pushed a little bit behind the original mesh polygons."

so,,, how do I modify projection matrix for locating volume mesh to little bit behind the original mesh polygons..?

sorry, I don't understand what your method.
There's a link that I used to have (sorry, can't find it) where it explains the fact that depth bias (polygon offset) are potentially slow, and the units are really undefined. So it may or may not work on any random card, and if it does work, the value that you have to plug in is impossible to predict. Instead, you can modify your projection matrix to give the same effect, in a predictable manner. Effectively you just shift your near/far planes slightly, so that objects at the same Z value map to different values in the z buffer (after projection). You can probably fiddle and find a value that works (given your mesh scale, etc...) without too much trouble.
From memory, it should be something like this :

// 1) render the scene

// 2) modify the projection matrix to shift the near plane a bit

m_pd3dDevice->GetTransform (D3DTS_PROJECTION, &matProj);

float Epsilon = 0.0001f;

// not sure it's the _33 component
// check the D3D docs about projection matrix to verify
matProj._33 += Epsilon; // (maybe it's -=)

m_pd3dDevice->SetTransform (D3DTS_PROJECTION, &matProj);

// 3) render the shadow volume

// 4) restore the original projection matrix

Voila, i hope you get the idea.
Depth bias does exactly the same as what your projection matrix do : It increases the Z-value by a specified epsilon. And afaik, depth bias is supported by lots of cards, recent or not (still got to check this). So the Z-bias method works as well.

This topic is closed to new replies.

Advertisement