OpenGL Normals don't work?
-
09-10-2019 - |
سؤال
I'm working on a OpenGL project and I want at least a little lighting in it. I'm trying to use OpenGLs built in lighting for a while now but I'm not having much success.
Models I load have their correct normals (calculated by Wings3D) attached to vertices in that order:
loop all faces {
GL.Normal3(...);
GL.TexCoord2(...);
GL.Vertex3(...);
... (two more in same order, faces are all triangles)
}
Models do have some Material
calls prior the GL.Begin(BeginMode.Triangles)
like:
GL.Material(MaterialFace.FrontAndBack, MaterialParameter.AmbientAndDiffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Shininess, 99.0f);
Here are the first three normals of the first model loaded (credibility check) n(x,y,z):
0(0.6331236, 0.428246439, 0.6447942)
1(0.507037938, -0.6987222, 0.504677951)
2(-0.768829644, -0.494915247, 0.404919624)
This is how I set up lighting:
GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.ColorMaterial);
GL.Enable(EnableCap.Texture2D);
GL.Enable(EnableCap.Normalize);
GL.ShadeModel(ShadingModel.Flat);
GL.Enable(EnableCap.Lighting);
GL.Enable(EnableCap.Light0);
GL.Light(LightName.Light0, LightParameter.Position, new float[] { 0.0f, 1000.0f, 0.0f, 1.0f });
GL.Light(LightName.Light0, LightParameter.Ambient, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
GL.Light(LightName.Light0, LightParameter.Specular, new float[] { 0.0f, 0.0f, 0.0f, 0.0f });
GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
GL.Light(LightName.Light0, LightParameter.SpotExponent, 0.0f);
Objects react on the settings being played around but all faces sadly have the same brightness.
Am I missing something or am I doing anything wrong?
المحلول
Setting the Ambient light to {1,1,1,1} means that everything will be fully lit, regardless of direction from the light. Try setting the Ambient values lower (e.g. 0.2f), so that the Diffuse component can have some effect.