I am simply trying to render spheres with a light source coming from directly over head and the spheres have some ambient and diffuse lighting too... but when i change the scale of the mesh, the lighting goes all weird (see screeshots below)
Here is the lighting code:
private void SetupLighting(){
myDevice.Lights[
0].Type = LightType.Directional;myDevice.Lights[
0].Diffuse = Color.White;myDevice.Lights[
0].Ambient = Color.FromArgb(0x404040);myDevice.Lights[
0].Specular = Color.White;myDevice.Lights[
0].Direction = new Vector3(0.0f, -1.0f, 0.0f);myDevice.Lights[
0].Enabled = true;myDevice.RenderState.Lighting =
true; // myDevice.RenderState.SpecularEnable = true;myDevice.RenderState.Ambient =
Color.FromArgb(60, 60, 60);}
And here is the material code:
myMaterial.Diffuse =
Color.FromArgb(23, 170, 51);myMaterial.Ambient =
Color.FromArgb(23, 140, 51);myScaling.Multiply(0
.5f);Now if I don't scale the size of the mesh, I get this... (satisfactory)
However if I scale the size of the mesh, in this case down to half size, the result is a horribly lit sphere. (not satisfactory)
If however I don't scale the sphere and just reduce its radius by half, I get smaller but properly lit spheres again. (satisfactory)
How can i scale my mesh but still get the lighting to look decent Why does scaling the mesh break the lighting




Mesh scaling and lighting problems
Mathias Vestergaard
Lighting caluclations are based on the normals. When you set a scale for a mesh it scales the normals too affecting the lighting.
Set the RenderState 'NormalizeNormals' to TRUE and the fixed function pipeline will fix all the normals for you at a slight performance cost.
Speedipus
The Zman strikes again!
That fixed the problem like a charm! Thanks a ton!