bitplane wrote:are your normals normalized? if they have a length of anything other than 1.0 then you'll have lighting problems.
you can either recalculate them with the mesh manipulator, or if you want to keep their direction you can set the normalize normals
SMaterial flag and let the hardware fix them.
If that's not the problem, perhaps you can post the contents of the MTL file here
Yeap.
I manually inspected the .obj normals and the look like they have a unit length (1.0).
Looking deeper at the issue, I found this chunk of code (same for D3D8 and OpenGL).
Code: Select all
void CD3D9Driver::addDynamicLight(const SLight& dl)
{
if ((u32)LastSetLight == Caps.MaxActiveLights-1)
return;
CNullDriver::addDynamicLight(dl);
D3DLIGHT9 light;
if ( dl.Type == ELT_POINT )
{
light.Type = D3DLIGHT_POINT;
light.Position = *(D3DVECTOR*)((void*)(&dl.Position));
}
else
if ( dl.Type == ELT_DIRECTIONAL )
{
light.Type = D3DLIGHT_DIRECTIONAL;
light.Direction = *(D3DVECTOR*)((void*)(&dl.Position));
}
light.Diffuse = *(D3DCOLORVALUE*)((void*)(&dl.DiffuseColor));
light.Specular = *(D3DCOLORVALUE*)((void*)(&dl.SpecularColor));
light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor));
light.Range = MaxLightDistance;
light.Attenuation0 = 0.0f;
light.Attenuation1 = 1.0f / dl.Radius;
light.Attenuation2 = 0.0f;
++LastSetLight;
pID3DDevice->SetLight(LastSetLight, &light);
pID3DDevice->LightEnable(LastSetLight, true);
}
It's setting the linear attenuation based on the radius and the constant to 0. I think that's not quite the anticipated effect and responsible for the overbrightness.
For light attenuation values k0 k1 k2, the attenuation calculation is:
attenuation = 1.0 / (k0 + k1 * d + k2 * d^2)
So here's what happening.
blue - Constant attenuation.
purple - What's happening now. Instead of the light fading to black at the Radius, it's actually causing the light near the source become super brightened.
yellow - Closer to what I anticipated the system would work, fading from 1 near the source to 0 at the Radius.
Would it be possible to expose the attenuation values through the SLight structure? I don't know if the current setup is the intended lighting, but it would be nice to be able to override it so I can get the lighting I'm after.