Odd light "popping"

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
        glLightf( GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0025 );
        glLightf( GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0025 );
        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 );
        glEnable( GL_COLOR_MATERIAL );
        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

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.

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?


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.

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.

Ah, that’s awesome, thanks. The shininess value’s a bit weird; it powers the specular brightness!?

Ah kids these days, they know nothing :slight_smile:

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 :

You’re awesome mate. Thanks for not only solving my question but providing a lot of further sources of information.

Glad that helped.