Sign in to follow this  
slicer4ever

[SOLVED]Shadow Volume issues.

Recommended Posts

Hello everyone, i'm currently wnorking on shadows for my game, and am running into an issue with some polygons shadow "streak" being seen.

This is the model i'm working with, very simple for demonstrating the problem:

[img]http://i42.tinypic.com/350094x.png[/img]


Here is the scene, without shadows, the whire square is the light:

[img]http://i40.tinypic.com/95svo8.png[/img]


This is the shadow volume(colored white):

[img]http://i44.tinypic.com/9aplzk.png[/img]


This is the shadow stenciled volume

[img]http://i42.tinypic.com/11m4arc.jpg[/img]



as you can see, the problem is the top edge is extended through the model.

here's is my shadow stencil code, it uses the z-pass method(no caps, since my camera well never be inside the shadow volume):

[code]void BattleWorld::DrawShadows(NVVideoDriver *Driver){
Driver->DisableState(NVLIGHTING);
Driver->SetDepthMask(0);
Driver->SetColorMask(0,0,0,0);
Driver->EnableState(NVSTENCIL_TEST);
Driver->SetStencilFunc(NVTEST_ALWAYS, 0, 0xFFFFFFFF);
Driver->SetStencilOp(NVOP_KEEP, NVOP_KEEP, NVOP_INCR);
for(BDisplayObject *N,*F=m_FirstDisp?m_FirstDisp->AddRef():0x0; F; N = F->GetNext(), N=N?N->AddRef():N, F->RemoveRef(), F = N){
F->SwapShadow();
Driver->PushMatrix();
Driver->MultMatrix(F->GetDrawMatrix());
Driver->DrawMesh(F->GetDrawShadow()->GetShadowMesh());
Driver->PopMatrix();
}
Driver->SetStencilOp(NVOP_KEEP, NVOP_KEEP, NVOP_DECR);
Driver->SetCullFace(NVFACE_FRONT);
for(BDisplayObject *N,*F=m_FirstDisp?m_FirstDisp->AddRef():0x0; F; N = F->GetNext(), N=N?N->AddRef():N, F->RemoveRef(), F = N){
Driver->PushMatrix();
Driver->MultMatrix(F->GetDrawMatrix());
Driver->DrawMesh(F->GetDrawShadow()->GetShadowMesh());
Driver->PopMatrix();
}
Driver->SetCullFace(NVFACE_BACK);
Driver->SetStencilFunc(NVTEST_NEQUAL, 0, 0xFFFFFFFF);
Driver->SetStencilOp(NVOP_KEEP, NVOP_KEEP, NVOP_KEEP);
Driver->SetColorMask(1,1,1,1);
Driver->PushMatrix();
Driver->ResetMatrix();
Driver->BeginObject(NVDRAW_TRIANGLE_STRIP);
Driver->DefinePoint(-0.1f, 0.1f, -0.1f);
Driver->DefinePoint(-0.1f,-0.1f, -0.1f);
Driver->DefinePoint( 0.1f, 0.1f, -0.1f);
Driver->DefinePoint( 0.1f,-0.1f, -0.1f);
Driver->EndObject();
Driver->PopMatrix();
Driver->DisableState(NVSTENCIL_TEST);
Driver->SetDepthMask(1);
return;
}[/code]




EDIT: ////////////////////////////////////////

I discovered my problem, in creating the model, their was a face in between seen here:

[img]http://i41.tinypic.com/2evuwea.png[/img]

is their anyway i can take this into account for my models that might have this happen to?

////////////////////////////////////////////////
:

Share this post


Link to post
Share on other sites
Hello everyone again, i've been attempting to solve this with a new method, but for some reason, it seems to be failing.

basically, the idea is such:

1. Disable color/depth mask.
2. Set Depth test to GL_LESS, so the shadow volume pixel that is on an object, will fail the depth test.
3. Set Stencil so that it set's a 1 into all the area's that fail depth test.
4. Draw Shadow volume.
5. Set depth test to GL_LEQUAL, so the shadow volume pixel that is on an object, should pass the depth test.
6. Set stencil so that it only draw's shadow where the stencil is 1.
7. Enable color mask.
8. Draw shadow volume.

but, my problem seems to be due to depth precision?

here's two images:
[img]http://s15.postimage.org/4052x3u3f/Image_A.png[/img]

^^GL_LESS stenciled 1 area's^^

[img]http://s17.postimage.org/j8ilrrygf/Image_B.png[/img]

^^ GL_LEQUAL stencil area^^

in the first image, i expected the shadow volume to include the square/triangle under the object, instead, it's blank, as if GL_LEQUAL testing was in effect.
The second image looks correct.

Share this post


Link to post
Share on other sites
ok guys, so after some thinking, i realized why my idea was horrible flawed, although once i understood why it was horribly flawed, i understood the stencil algorithm for shadow volumes much better.

but in it's wake, and doing much research, i came across this paper:

[url="http://hungryspoon.com/PX_web/paper/paper.pdf"]http://hungryspoon.c...paper/paper.pdf[/url]

it is an amazing paper, and gives me the exact information i require for fixing this problem.

In short, this is now solved, and to anyone who comes across this thread with similar problems, hopefully that link won't be dead, as it's an excellent solution to non-manifold shadow volume geometry.

edit: in case the link ever goes dead, the paper is called:

Robust, Geometry-Independent Shadow Volumes
By: Eric Woods

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