Original Post
HIya all.. Im working on a 3DEngine.. and im working with Pixel Shader now to create lighting and shadows.. I am using abit of code from the SDK Sample.. Im allso using the FX file from that Sample to have something to build on.. Now when i run my game.. the lighting is Black and when i walk towards the light it turns away from the camera.. Im using a camera object for the lighting view and one for the actual view of the screen.. it all work greate.. it renders the spot light but its black.. Have i got it all wrong ?? That this dose only render the shadows and not the lighting ?????
//First pass render the shadows
D3DXMATRIXA16 mLightView;
mLightView = *Light.GetViewMatrix();
g_pEffect->SetMatrix( "g_mProj", &g_mShadowProj);
// Freely moveable light. Get light parameter
// from the light camera.
D3DXVECTOR3 v = *Light.GetEyePt();
D3DXVECTOR4 v4;
D3DXVec3Transform( &v4, &v, &mLightView );
g_pEffect->SetVector( "g_vLightPos", &v4 );
*(D3DXVECTOR3*)&v4 = *Light.GetWorldAhead();
v4.w = 0.0f; // Set w 0 so that the translation part doesn't come to play
D3DXVec4Transform( &v4, &v4, &mLightView); // Direction in view space
D3DXVec3Normalize( (D3DXVECTOR3*)&v4, (D3DXVECTOR3*)&v4 );
g_pEffect->SetVector( "g_vLightDir", &v4 );
Mesh.Render(g_pEffect, true, &mLightView);
//Secound Pass Render Objects
const D3DXMATRIX *pmView = Camera1.GetViewMatrix();
g_pEffect->SetTexture( "g_txShadow", g_pShadowMap );
D3DXMATRIXA16 mViewToLightProj;
mViewToLightProj = *pmView;
D3DXMatrixInverse( &mViewToLightProj, NULL, &mViewToLightProj );
D3DXMatrixMultiply( &mViewToLightProj, &mViewToLightProj, &mLightView );
D3DXMatrixMultiply( &mViewToLightProj, &mViewToLightProj, &g_mShadowProj );
g_pEffect->SetMatrix( "g_mViewToLightProj", &mViewToLightProj );
g_pEffect->SetMatrix( "g_mProj", Camera1.GetProjMatrix());
v = *Light.GetEyePt();
D3DXVECTOR4 v42;
D3DXVec3Transform( &v42, &v, pmView );
g_pEffect->SetVector( "g_vLightPos", &v42 );
*(D3DXVECTOR3*)&v42 = *Light.GetWorldAhead();
v4.w = 0.0f; // Set w 0 so that the translation part doesn't come to play
D3DXVec4Transform( &v42, &v42, pmView ); // Direction in view space
D3DXVec3Normalize( (D3DXVECTOR3*)&v42, (D3DXVECTOR3*)&v42 );
g_pEffect->SetVector( "g_vLightDir", &v42 );
Mesh.Render(g_pEffect, false, pmView);
The Mesh.Render
VOID Mesh::Render(ID3DXEffect* g_pEffect, bool bRenderShadow, const D3DXMATRIX *pmView)
if( bRenderShadow )
g_pEffect->SetTechnique( "RenderShadow" );
if( !bRenderShadow )
g_pEffect->SetTechnique( "RenderScene" );
D3DXMATRIXA16 mWorldView = Meshes.WorldMatrix;
D3DXMatrixMultiply( &mWorldView, &mWorldView, pmView );
g_pEffect->SetMatrix( "g_mWorldView", &mWorldView );
UINT cPass;
g_pEffect->Begin( &cPass, 0 );
for( UINT p = 0; p < cPass; ++p )
{
g_pEffect->BeginPass( p );
for( DWORD i=0; i<Meshes.NumMaterials; i++ )
{
//D3DDevice->SetMaterial( &Meshes.Materials );
//D3DDevice->SetTexture( 0, Meshes.Textures );
//Meshes.Mesh->DrawSubset( i );
D3DXVECTOR4 vDif( Meshes.Materials.Diffuse.r,
Meshes.Materials.Diffuse.g,
Meshes.Materials.Diffuse.b,
Meshes.Materials.Diffuse.a );
g_pEffect->SetVector( "g_vMaterial", &vDif );
g_pEffect->SetTexture( "g_txScene", Meshes.Textures );
g_pEffect->CommitChanges();
Meshes.Mesh->DrawSubset( i );
}
g_pEffect->EndPass();
}
g_pEffect->End();