• Advertisement
Sign in to follow this  

Point light shadows and clip planes

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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

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, &planes );
D3DXPLANE worldSpacePlane, clipSpacePlane;
worldSpacePlane = -planes;// 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);
}
}


and then i render lights/shadows

for(...)
{
....
renderDepth();
...
setRenderTarget( lightAccumRT );
...
enableClipPlanes(lightView, lightProj);

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

disableClipPlanes();
}


draw box with this states:

ALPHABLENDENABLE = TRUE;
SRCBLEND = ONE;
DESTBLEND = ONE;

STENCILENABLE = FALSE;
COLORWRITEENABLE = 0x0000000F;
ZFUNC = GREATEREQUAL;
CULLMODE = CW;
ZWRITEENABLE = FALSE;


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
Advertisement
Sign in to follow this  

  • Advertisement