PDA

View Full Version : Horrible lighting problem



dalangalma
05-09-2004, 12:03 AM
I'm having a terrible lighting problem, where all my vertices seem to be either completely white or completely black, and pop back and forth as I view around them.

Check out a screenshot of the game engine I've been working on rendering a glutSolidSphere for an example:

http://www.andrew.cmu.edu/~brh/badsphere.jpg

Has anybody seen this, and does anyone know how to fix it?

Mazy
05-09-2004, 12:45 AM
Looks like to much specular, what material settings are you using?

dalangalma
05-09-2004, 01:20 AM
Here, I changed the material of the sphere to a nice brass material I've used to good effect in other projects:

http://www.andrew.cmu.edu/~brh/badsphere2.jpg

The material is:
GLfloat ambientColor[] = {0.33, 0.22, 0.03, 1.0},
diffuseColor[] = {0.78, 0.57, 0.11, .8},
specularColor[] = {0.99, 0.91, 0.81, 1.0},
brass_shininess = 27.8;

And there is one point light:
const GLfloat light_ambient[] = { 0.1, 0.1, 0.1, 1.0 };
const GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
const GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
const GLfloat light0_position[] = { 50.0, 25.0, -60.0, 1.0 };

ZbuffeR
05-09-2004, 01:59 AM
The light seem much too bright. Try attenuation maybe ?

Or check your normals. See http://opengl.org/resources/faq/technical/lights.htm#ligh0090

dalangalma
05-09-2004, 09:44 AM
Hmm. Well, I've lit scenes involving a sphere with that material with lights of that intensity before...

Also, that's a glutSolidSphere and glEnable(GL_NORMALIZE) is on, so I think the normals are OK...

ZbuffeR
05-09-2004, 10:00 AM
Maybe try to specify 0 to all lights parameters but one, and test each to narrow the problem to the actual buggy parameters ? Or show some more code ?

dalangalma
05-09-2004, 10:24 AM
OK, I've made a test scene, and it exhibits the same problem. I must just be setting light parameters wrong. Here's some relevant exceprts from my test:

//The only light in the scene
GLfloat ambient0[] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat diffuse0[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular0[] = { 1.0, 1.0, 1.0, 1.0};
GLfloat light0_pos[] = { 50.0, 25.0, -60.0, 1.0 };

//The material on the sphere
float ambientColor[] = {0.33, 0.22, 0.03, 1.0};
float diffuseColor[] = {0.78, 0.57, 0.11, .8};
float specularColor[] = {0.99, 0.91, 0.81, 1.0};

void display()
{
int i;

//Clear necessary bits
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

//Apply all our transformations
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glTranslatef(50, 10, 25);

glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuseColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor);
glutSolidSphere(4.0, 20, 20);
glutSolidSphere(10.0,20,20);
glPopMatrix();

glPopMatrix();

//Get things drawn and swapped
glFlush();
glutSwapBuffers();
}

The lights are set up normally in initialization. This produces the same awful sphere as I've had in my other program.

dalangalma
05-09-2004, 10:30 AM
I tried zeroing out the everything but ambient, everything but diffuse, etc. It's definitely specular that's the problem. I just thought specular produced little highlights, as opposed to whiting out anything the light shines on.

dalangalma
05-09-2004, 10:39 AM
AHA! Adding a shininess value changed things a lot. Now it looks much more normal.

dorbie
05-09-2004, 11:35 AM
Shininess is the specular exponent. Specular is just a dot product of Blinn's half vector and the surface normal, so unless the exponent is reasonably high the specular term can be as 'spread out' as the diffuse term.