Sign in to follow this  
belfegor

Point light shadows and clip planes

Recommended Posts

belfegor    2835
I am trying to render 6 spotlights shadow for point light and additive blend each side ( light contribution and shadows).
So i thought to render one "big" cube (big as my room that i have place light in) as light volume geometry and clip it with clip planes to get correct result instead to re-add 6 times to same "spot". But something is wrong with my code:

Clip planes functions
[code]
D3DXPLANE oldPlanes[6];

void enableClipPlanes(const D3DXMATRIX& view, const D3DXMATRIX& proj)
{
for(std::size_t i = 0; i < 6; ++i)
{
d3d9device->SetRenderState(D3DRS_CLIPPLANEENABLE, 1 << i);
d3d9device->GetClipPlane(i, oldPlanes[i]);
}

D3DXMATRIX viewProjection;
D3DXMatrixMultiply( &viewProjection, &view, &proj );

D3DXPLANE planes[6];
planes[0].a = viewProjection._14 + viewProjection._11;
planes[0].b = viewProjection._24 + viewProjection._21;
planes[0].c = viewProjection._34 + viewProjection._31;
planes[0].d = viewProjection._44 + viewProjection._41;

// Right plane
planes[1].a = viewProjection._14 - viewProjection._11;
planes[1].b = viewProjection._24 - viewProjection._21;
planes[1].c = viewProjection._34 - viewProjection._31;
planes[1].d = viewProjection._44 - viewProjection._41;

// Top plane
planes[2].a = viewProjection._14 - viewProjection._12;
planes[2].b = viewProjection._24 - viewProjection._22;
planes[2].c = viewProjection._34 - viewProjection._32;
planes[2].d = viewProjection._44 - viewProjection._42;

// Bottom plane
planes[3].a = viewProjection._14 + viewProjection._12;
planes[3].b = viewProjection._24 + viewProjection._22;
planes[3].c = viewProjection._34 + viewProjection._32;
planes[3].d = viewProjection._44 + viewProjection._42;

// Near plane
planes[4].a = viewProjection._13;
planes[4].b = viewProjection._23;
planes[4].c = viewProjection._33;
planes[4].d = viewProjection._43;

// Far plane
planes[5].a = viewProjection._14 - viewProjection._13;
planes[5].b = viewProjection._24 - viewProjection._23;
planes[5].c = viewProjection._34 - viewProjection._33;
planes[5].d = viewProjection._44 - viewProjection._43;

for(int i = 0; i < 6; ++i)
{
D3DXPlaneNormalize( &planes[i], &planes[i] );
D3DXPLANE worldSpacePlane, clipSpacePlane;
worldSpacePlane = -planes[i];// invert plane normal ??? SUSPICIOUS
D3DXPlaneNormalize(&worldSpacePlane, &worldSpacePlane);
D3DXMATRIX viewProjIT = view * proj;
D3DXMatrixInverse(&viewProjIT, NULL, &viewProjIT);
D3DXMatrixTranspose(&viewProjIT, &viewProjIT);
D3DXPlaneTransform(&clipSpacePlane, &worldSpacePlane, &viewProjIT);
d3d9device->SetClipPlane(i, clipSpacePlane);
}
}

// restore old clip planes
void disableClipPlanes()
{
for(std::size_t i = 0; i < 6; ++i)
{
d3d9device->SetClipPlane(i, oldPlanes[i]);
}
}
[/code]

and then i render lights/shadows
[code]
for(...)
{
....
renderDepth();
...
setRenderTarget( lightAccumRT );
...
enableClipPlanes(lightView, lightProj);

effect->SetTechnique(...);
effect->Begin(...);
...
drawBox();
...
effect->End();

disableClipPlanes();
}
[/code]

draw box with this states:
[code]
ALPHABLENDENABLE = TRUE;
SRCBLEND = ONE;
DESTBLEND = ONE;

STENCILENABLE = FALSE;
COLORWRITEENABLE = 0x0000000F;
ZFUNC = GREATEREQUAL;
CULLMODE = CW;
ZWRITEENABLE = FALSE;
[/code]

Now all i get is black? Any idea?

If you need more info please tell.

Thanks for your time.

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