I am having trouble with simple, fixed function pipeline bumpmapping in DX8. What is happening is that the texture comes out too dark.
Here are some piccies :
My Bumpmap and the
results.
As you can see I am using the tiger.x model (with the texture to go with it) and am setting up my rendering as such :
D3DXVECTOR3 vLight = D3DXVECTOR3(0.0f, -1.0f, -1.0f); // Light direction
D3DXMATRIX mtxWorld;
m_mshTest->Get_Matrix(&mtxWorld); // World matrix of mesh
D3DXVec3TransformNormal(&vLight, &vLight, &mtxWorld);
D3DXVec3Normalize( &vLight, &vLight );
DWORD r = (DWORD)(127.0f * vLight.x + 128.0f);
DWORD g = (DWORD)(127.0f * vLight.y + 128.0f);
DWORD b = (DWORD)(127.0f * vLight.z + 128.0f);
DWORD dwFactor = D3DCOLOR_XRGB(r, g, b);
d3dd->SetRenderState(D3DRS_TEXTUREFACTOR, dwFactor);
d3dd->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3 );
d3dd->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3dd->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );
d3dd->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
d3dd->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
d3dd->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
d3dd->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3dd->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
d3dd->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
d3dd->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
d3dd->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0); // Only have 1 set of tex coords
d3dd->SetTexture(0, m_texNormalMap); // Normal map
d3dd->SetTexture(1, g_Engine->Get_TextureKeeper()->Get_Texture(m_adwTextures[dw])); // The valid texture
I am creating my bumpmap by doing :
if (FAILED(D3DXCreateTexture(d3dd, 128, 128, 1, D3DX_DEFAULT, D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT, &m_texNormalMap))) {
ErrorPrint(false, ("Failed to create bumpmap.\n"));
return false;
}
if (FAILED(D3DXComputeNormalMap(m_texNormalMap, texBumpMap, NULL, 0, D3DX_CHANNEL_RED, 10.0f))) {
ErrorPrint(false, ("Failed to compute normal map.\n"));
return false;
}
Where texBumpMap is the loaded bumpmap texture.
Anyone got any ideas of where I am going wrong? The texture only seems to appear in the highlights of the bumpmap and totally black everywhere else.
Thanks for any help,
Steele.
[Edited by - Crow-knee on September 22, 2005 7:11:54 AM]