Results 1 to 8 of 8

Thread: Odd light "popping"

  1. #1
    Senior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    105

    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:

    Code :
            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.

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    9

    Re: Odd light "popping"

    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?

    David

  3. #3
    Senior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    105

    Re: Odd light "popping"

    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.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Odd light "popping"

    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.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    105

    Re: Odd light "popping"

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

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Odd light "popping"

    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:
    http://www.opengl.org/registry/doc/g...1.20061201.pdf

    Or more classically, this is the standard old school Phong shading equation, check here for the α (alpha) power term here :
    http://en.wikipedia.org/wiki/Phong_s...flection_model

  7. #7
    Senior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    105

    Re: Odd light "popping"

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

  8. #8
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Odd light "popping"

    Glad that helped.

Similar Threads

  1. Switching between "arcball" and "fps-style" camera rotation
    By bsabiston in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-31-2017, 12:37 PM
  2. Replies: 2
    Last Post: 02-21-2014, 02:52 PM
  3. egl gles2 "function is no-op" "Mesa: User error"
    By unixmania in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-17-2013, 05:30 AM
  4. Replies: 1
    Last Post: 10-26-2012, 02:19 AM
  5. "best" linux dist for a "Gelato" render farm?
    By ArtificialArtOfficial in forum OpenGL: Linux
    Replies: 10
    Last Post: 12-23-2007, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean