Sign in to follow this  
jhk8211

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
"Why ZBIAS is not a good thing"...
http://tomsdxfaq.blogspot.com/

This is different than the new dx9 D3DRS_SLOPESCALEDEPTHBIAS and D3DRS_DEPTHBIAS.

Also see the "ZBias - 2003 and beyond" thread at http://sourceforge.net/mailarchive/forum.php?forum=gdalgorithms-list

Share this post


Link to post
Share on other sites
thx all about replies.. ^^

I was busy, because working my team project.. so,

I see this thread now. I solved this problem using not only Depth-Bias but also controlling a bit Projection Matrix method. ^^

[Edited by - jhk8211 on December 2, 2004 6:09:37 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this