lighting with FVF problems
I'm trying to light a basic scene. I set up the lights once in my InitD3D() function with the following code:
int numLights=0;
VOID SetLight(float x, float y, float z, float intensity)
{
D3DLIGHT9 PointLight;
ZeroMemory(&PointLight, sizeof(D3DLIGHT9));
PointLight.Type=D3DLIGHT_POINT;
PointLight.Position=D3DXVECTOR3(x, y, z);
PointLight.Diffuse=D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
PointLight.Range=intensity*100.0f;
g_pd3dDevice->SetLight(numLights, &PointLight);
g_pd3dDevice->LightEnable(numLights++, TRUE);
}
I set up two lights, which both succeed in turning on and lighting the scene... but they turn everything pure white, and when I move my character past the light the shadow is a definite line that separates white from black. Before this function was working correctly, I forgot to set PointLight.Type=D3DLIGHT_POINT, and it actually lit my scene the way I wanted it to: by shading things properly and according to their material, rather than turning everything white and without gradient. I couldn't manipulate this light, however, since it's something of a DX default fall-back, so I can't resort to that.
I'm wondering, I only set these lights up during initialization. Do i need to set the lights each DrawSubset() call in Render()?
The default light type, if you don't specify one, is a D3DLIGHT_DIRECTIONAL. Directional lights are good for full-scene lighting, for simulating the sun or something.
I'm not sure why your light is turning everything pure white. However, your second problem sounds like you haven't set the attenuation of the light. Try setting the .Fallof member to 1 and the .Attenuation0 member to 1 as well. It'll make the light intensity fall off gradually from full brightness at the light source to nothing at the edge of its range.
I'm not sure why your light is turning everything pure white. However, your second problem sounds like you haven't set the attenuation of the light. Try setting the .Fallof member to 1 and the .Attenuation0 member to 1 as well. It'll make the light intensity fall off gradually from full brightness at the light source to nothing at the edge of its range.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement