View Full Version : Diffuse lighting not yeilding correct result?

08-08-2004, 10:09 PM
I have a very simple scene,

- One flat polygon coloured dark blue - glColor3f(0.2f,0.2f,0.5f);
- One point light in front of the polygon (but not very close)

Both material and light have a diffuse component of (0.1f, 0.1f, 0.1f) - everything else is set to 0.0.

GL_LIGHTING and GL_COLOR_MATERIAL are enabled, shade model is set to GL_SMOOTH.

So why oh why oh why is my polygon WHITE???

btw if I move the light so it is to the left (or right, etc) of the polygon the polygon will then shade the right blue. (Not that I expected that either, I would have expected it to be a much darker blue too).

Can anyone help?

08-09-2004, 12:28 AM
everything else is set to 0.0 Are you sure?
Sounds like a specular lighting effect. Check the normal vector and the specular settings.

08-09-2004, 12:43 AM
Pritty sure... I do after all do this...

GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat no_shininess[] = { 0.0 };

glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, no_mat);
glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);and..

GLfloat LightDiffuse[]= { 0.1f, 0.1f, 0.1f, 1.0f };
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse LightIf I swap GL_DIFFUSE for GL_AMBIENT I get the results I would expect for ambient light...

Unless there is something I have missed...

08-09-2004, 01:53 AM
Are you sure you're looking to the right side of the polygon?
Perhaps try GL_FRONT_AND_BACK instead of GL_FRONT. :confused:

08-09-2004, 04:02 AM
Trying GL_FRONT_AND_BACK made no difference.

08-09-2004, 05:32 AM
ok, and if you say "GL_COLOR_MATERIAL is enabled", do you mean you have only glEnable(GL_COLOR_MATERIAL) or do you have also glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) f.e. ;) ? (Even though this should be the default values)

08-09-2004, 05:38 AM
Originally I only had glEnable(GL_COLOR_MATERIAL) but adding glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) made no difference to the scene.

08-09-2004, 05:41 AM
By the way, if you enable color material with ambient and diffuse, the values you set with glMaterial have no effect.
The color you set before drawing the polygon is then your ambient and diffuse color.

08-09-2004, 06:05 AM
And be careful to avoid pitfall #14:
It's important WHEN you enable color material.
As an OpenGL rule of thumb, always set things first, then enable!

08-09-2004, 10:14 PM
Pitfall #14 has been avoided, I am using AMBIENT_AND_DIFFUSE material, I have ensured the light ambient is off. My colour is glColor3f(0.2f,0.2f,0.5f); therefore (if I read the instructions correctly) the materials ambeint and diffuse properties should be the same. With the lights diffuse at (0.1, 0.1, 0.1) the resulting colour should be (roughly) (0.02, 0.02, 0.05) for the final diffuse property. (with everything else "off" in one way or another I would expect the vetex colour to be (0.02, 0.02, 0.05) - am I being stupid?)

08-09-2004, 11:08 PM
hmmm...perhaps it would be useful if you could post more code, f.e. how your polygon looks like (vertices and normals) and where your light is exactly placed.

08-09-2004, 11:37 PM
Ok, I've found what it is.

There's a glScale hiding in my code which I had forgotten I'd put in there and only just noticed, so of course it was messing up my normals. Just enabled GL_NORMALIZE and I am getting results more along the lines I expected.