Hi
Ok, this is driving me nuts for weeks now.
I've read every lighting-thread on gamedev.net about a hundred times now, but still can't get my (point-) light to work.
One reason might be that I don't understand the DX lighting system :D
Ok, here we go (just in case you're curios, "gState" is my statemanager so I don't get any "redundant render state" warnings):
gState.SetRenderState(D3DRS_LIGHTING, TRUE); // eh...yeah :)
Here's my light:
D3DLIGHT9 lfFlashlight;
ZeroMemory(<Flashlight, sizeof(ltFlashlight));
D3DXVECTOR3 vecLight(playerPosition.pos);
vecLight.z += 2.0f;
ltFlashlight.Type = D3DLIGHT_POINT;
ltFlashlight.Diffuse.r = ltFlashlight.Ambient.r = 0.0f;
ltFlashlight.Diffuse.g = ltFlashlight.Ambient.g = 0.0f;
ltFlashlight.Diffuse.b = ltFlashlight.Ambient.b = 1.0f;
ltFlashlight.Diffuse.a = ltFlashlight.Ambient.a = 0.0f;
ltFlashlight.Range = 100.0f;
ltFlashlight.Position = vecLight;
ltFlashlight.Attenuation0 = 0.0f;
ltFlashlight.Attenuation1 = 1.0f;
ltFlashlight.Attenuation2 = 0.0f;
hRes = pD3DDevice->SetLight(0, <Flashlight); // S_OK
hRes = pD3DDevice->LightEnable(0, TRUE); // S_OK
These are the texture states I set before rendering my level (BSP):
gState.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
gState.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
gState.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
gState.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
gState.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
gState.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
This is blending the level texture with a lightmap - works fine without lighting.
My vertex struct:
struct VERTEX
{
D3DXVECTOR3 pos;
TEXCOORDS surface;
TEXCOORDS lightmap;
D3DXVECTOR3 normal;
byte color[4];
};
Vertex declaration...
const D3DVERTEXELEMENT9 vertexDeclaration[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 40, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
D3DDECL_END()
};
I draw the normals and they are correct, they're normalized.
So, why isn't my light working? :(
thanks in advance