View Full Version : Odd light "popping"

12-31-2009, 10:46 AM
I just can't figure this out. This is part of a college project (and as such I'm reluctant to hand out full source because plagiarism filters pick up enough false positives as it is) and my lighting just isn't working as expected. Rather than smoothly fading from diffuse + ambient to ambient, it's snapping one to the other with no fade.

This is how I'm setting up my light:

glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_NORMALIZE );

float fLightPos[4] = {0, 8, 0,1.0};

glLightfv( GL_LIGHT0, GL_POSITION, fLightPos );
glLightf( GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1 ); //We don't want any falloff
float fMaterial[ 4 ] = { 1, 1, 1, 1 };
float fMaterialb[ 4 ] = { 0, 0, 0, 1 };
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, fMaterial );
glMaterialfv( GL_FRONT, GL_SPECULAR, fMaterial );
glLightfv( GL_LIGHT0, GL_DIFFUSE, fMaterial );
glLightfv( GL_LIGHT0, GL_SPECULAR, fMaterial );
glLightfv( GL_LIGHT0, GL_AMBIENT, fMaterialb );

I'm fairly certain my normals are good. Printing them out, they are all unit. No scaling is occuring, just translation and rotation. And GL_NORMALIZE is set beforehand anyway. If I apply a per-pixel GLSL shader, the lighting does blend but only across the width of a triangle. Basically, the same problem, but better interpolated.

Video Demonstration (http://www.youtube.com/watch?v=0TTBn-_HHpE)

Any ideas before I say it's cartoon shading and I meant to do it? I've spent a week trying to make this work and it just won't.

01-06-2010, 09:29 AM
From your video it appears that the light is moving, but your code indicates a constant position. Is your scene moving around your light? If so it is possible that your lighting is just fine and your rotation is not smooth. Can you offer any more details?


05-23-2010, 05:02 PM
The light is attached to one of the objects. The main problem appears to be in the specular highlight not the diffuse channel; the diffuse channel is fine.

05-24-2010, 02:23 AM
The default shininess exponent is 0, and with a white color, it will saturate quickly to the max white all accross the lighted model. Try setting GL_SHININESS to something like 20 or 30, and lowering the brightness of specular. Full white is a bit extreme.

05-26-2010, 02:44 AM
Ah, that's awesome, thanks. The shininess value's a bit weird; it powers the specular brightness!?

05-26-2010, 03:27 AM
Ah kids these days, they know nothing :)

See page 62 of the spec (page 76 of pdf), the shininess term is named srm and is indeed an exponent, like in a pow() operation:

Or more classically, this is the standard old school Phong shading equation, check here for the α (alpha) power term here :

05-26-2010, 11:34 AM
You're awesome mate. Thanks for not only solving my question but providing a lot of further sources of information.

05-26-2010, 02:23 PM
Glad that helped.