Original Post
Hello,
I am confused as to why I can't get diffuse lighting to work.
It looks as if I've set all the right render states and enabled lighting correctly but I just can't spot the problem.
I enable lighting and call DrawSubset
I've set the material to use for the model:
D3DXMATERIAL mtrl;
ZeroMemory(&mtrl.MatD3D, sizeof(D3DMATERIAL9));
mtrl.MatD3D.Diffuse = d3d::WHITE;
mtrl.MatD3D.Ambient = mtrl.MatD3D.Diffuse;
mtrl.MatD3D.Specular = d3d::WHITE;
and call Device->SetMaterial
I have computed vertex normals for each vertex
I've compared my code with an example of diffuse lighting and can't see anything i've done different that would affect the lighting
I enable the light before rendering is done using:
Device->SetLight(0, &dirLight1);
Device->LightEnable(0, true);
and set up the light in a function
D3DLIGHT9 d3d::InitDirectionalLight()
{
D3DLIGHT9 light; // create the light struct
ZeroMemory(&light, sizeof(light)); // clear out the light struct for use
light.Type = D3DLIGHT_DIRECTIONAL; // make the light type 'directional light'
light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); // set the light's color
light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f);
return light;
}
Any idea what's wrong?
The other thing is I'm using an ortho projection but I checked it against a perspective projection
and the diffuse lighting doesn't work with that either.
I am confused as to why I can't get diffuse lighting to work.
It looks as if I've set all the right render states and enabled lighting correctly but I just can't spot the problem.
I enable lighting and call DrawSubset
I've set the material to use for the model:
D3DXMATERIAL mtrl;
ZeroMemory(&mtrl.MatD3D, sizeof(D3DMATERIAL9));
mtrl.MatD3D.Diffuse = d3d::WHITE;
mtrl.MatD3D.Ambient = mtrl.MatD3D.Diffuse;
mtrl.MatD3D.Specular = d3d::WHITE;
and call Device->SetMaterial
I have computed vertex normals for each vertex
I've compared my code with an example of diffuse lighting and can't see anything i've done different that would affect the lighting
I enable the light before rendering is done using:
Device->SetLight(0, &dirLight1);
Device->LightEnable(0, true);
and set up the light in a function
D3DLIGHT9 d3d::InitDirectionalLight()
{
D3DLIGHT9 light; // create the light struct
ZeroMemory(&light, sizeof(light)); // clear out the light struct for use
light.Type = D3DLIGHT_DIRECTIONAL; // make the light type 'directional light'
light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); // set the light's color
light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f);
return light;
}
Any idea what's wrong?
The other thing is I'm using an ortho projection but I checked it against a perspective projection
and the diffuse lighting doesn't work with that either.