Jump to content

  • Log In with Google      Sign In   
  • Create Account


Point light shadows and clip planes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 belfegor   Crossbones+   -  Reputation: 2329

Like
0Likes
Like

Posted 16 June 2012 - 11:56 AM

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

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.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS