Sign in to follow this  

ShadowMapping light always follow camera

This topic is 1947 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

Hi!

I have finally got the Shadow mapping to work a little bit, not perfect. I am so tired right now so i need help to see why my light is following the camera?

this is my RenderScene function

SetVector for Light and Position is static so i don´t understand why it is always constant?
It is like they are not transformed into World-Space vectors?

One good thing is that the shadows looks pretty good, i need a bigger textureMap but so far it is ok. =)
[source lang="cpp"]void RenderScene(bool bRenderShadow, float fElapsedTime)
{

mPos.z-=0.1f;
mView.z-=0.1f;
mView.x+=0.01f;
mPos.x+=0.01f;

D3DXMatrixLookAtLH(&matView,&mPos,&mView,&mUp);
D3DXMATRIX matWorld;
D3DXMatrixIdentity(&matWorld);
d3ddev->SetTransform(D3DTS_VIEW, &matView);


g_pEffect->SetMatrix( "g_mProj", &matProjection );
g_pEffect->SetVector( "g_vLightPos", &D3DXVECTOR4(0,0,0,0) );
g_pEffect->SetVector( "g_vLightDir", &D3DXVECTOR4(-5,-13,2,0) );

d3ddev->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );
//If i delete these two rows i still have the same result = Wierd?
if( bRenderShadow )
g_pEffect->SetTechnique( "RenderShadow" );

// Begin the scene
d3ddev->BeginScene();

//When i delete these two rows i can see the ShadowMap rendering only = positive thing
if( !bRenderShadow )
g_pEffect->SetTechnique( "RenderScene" );


//if i set this effect to matWorld i can´t move my camera?!?!
g_pEffect->SetMatrix( "g_mWorldView", &matView );
LPD3DXMESH pMesh = FPSL1;
UINT cPass;
g_pEffect->Begin( &cPass, 0);
for( UINT p = 0; p < cPass; ++p )
{
g_pEffect->BeginPass( p );

for(DWORD i = 0; i < numMaterials; i++)
{
D3DXVECTOR4 vDif( FPSL1Material[i].Diffuse.r,
FPSL1Material[i].Diffuse.g,
FPSL1Material[i].Diffuse.b,
FPSL1Material[i].Diffuse.a );
g_pEffect->SetVector( "g_vMaterial", &vDif );
g_pEffect->SetTexture( "g_txScene", texture[i] );
g_pEffect->CommitChanges();
pMesh->DrawSubset( i );
}


g_pEffect->EndPass();
}
g_pEffect->End();


d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}
[/source]

Share this post


Link to post
Share on other sites
Sign in to follow this