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

## 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:

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

This is the shadow volume(colored white):

This is the shadow stenciled volume

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):

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; }

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

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

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

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

##### 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:

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.
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.

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

here's two images:

^^GL_LESS stenciled 1 area's^^

^^ 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 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:

http://hungryspoon.c...paper/paper.pdf

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:

By: Eric Woods

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013613
×