Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: Little Lighting issue

  1. #1
    Member Newbie
    Join Date
    Jan 2011
    Location
    Lincoln, UK
    Posts
    36

    Little Lighting issue

    First of all, i want to thank everyone for the wealth of info that is on this site, it has helped me get over other issues which i have come across. The current issue however, i cant seem to find an explaination for!

    I have been working on a small game for my computer science uni course, but have ran into a little issue with lighting. Basically, the lights aren't working as i would expect to, i must be setting something wrong, but i cant figure out what!

    The image attached probably explains this better than i can in words, butbasically i am drawing two rectangles (track start, and then the length), texturing them, creating the normals etc. but as you can see, the lighting stops on the first rectangle, and then restarts on the second rectangle.

    What i am trying to implement is a light in the middle of the track, but i cant figure out how to do this.


    My lighting function is as follows:
    Code :
    void initLighting()
    {	
        // set up light colours (ambient, diffuse, specular)
        GLfloat lightLa[] = {1.0, 0.0, 0.0, 1.0};	// ambient
        GLfloat lightLd[] = {1.0, 1.0, 1.0, 1.0};	// diffuse
        GLfloat lightLs[] = {1.0, 1.0, 1.0, 1.0};	// specular
        float lightPs[4] = {20, 20, -200, 1}; // position of light 
     
        glLightfv(GL_LIGHT0, GL_AMBIENT, lightLa);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightLd);
        glLightfv(GL_LIGHT0, GL_SPECULAR, lightLs);
        glLightfv(GL_LIGHT0, GL_POSITION, lightPs);
     
        GLfloat materialMs[] = {1.0f, 1.0f, 1.0f, 1.0f}; // specular
        GLfloat materialMe[] = {1.0f, 1.0f, 1.0f, 1.0f}; // emission
        glLightfv(GL_LIGHT0, GL_AMBIENT, materialMs);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, materialMe);
     
        //glLightfv(GL_LIGHT0, GL_CONSTANT_ATTENUATION, lightPos);
        glEnable(GL_COLOR_MATERIAL);
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);                       
    }

    Any help would be greatly appreciated.

    Thanks,
    Dale

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,661

    Re: Little Lighting issue

    Quote Originally Posted by dalemac
    ...basically i am drawing two rectangles (track start, and then the length), texturing them, creating the normals etc. but as you can see, the lighting stops on the first rectangle, and then restarts on the second rectangle.

    What i am trying to implement is a light in the middle of the track, but i cant figure out how to do this.
    Ok, there may be other problems but here is your main problem.

    With the fixed function pipeline (which you are using with these legacy lighting calls), lighting is performed "per vertex" and the color resulting from lighting is then interpolated across the polygon (and your texturing is applied on top of that interpolated color).

    So when you're drawing the entire track with only 6 vertices (effectively), you're only evaluating the lighting environment at those 6 points in space, and you shouldn't expect to get a nice radial lighting effect on the track right above your light source.

    Now to do better, you can use shaders, interpolate the normals across the polygon, and evaluate lighting at every pixel. Then you'll get the nice radial lighting effect on the track even when you have a very low number of verts like this.

    Another approach which would let you keep using the fixed-function lighting functionality and still get a nice radial lighting effect is to use a bunch more vertices to draw your track. This gets expensive, but it's nevertheless possible.

    Note that there's another issue with the lighting results in your picture: Because there's a hard lighting "seam" between your two rectangles, I suspect the shared vertices in the middle are being sent down the pipe with different normals depending on which quad they are in. You should use the same normal (and same position and color) when sending those verts down so that the pipeline computes the same lighting value for them in both triangles. Then, assuming you have smooth shading on (see glShadeModel), you'll at least get rid of the hard seam your lighting has there, even if you won't get an awesome radial falloff to your light.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: Little Lighting issue

    This doesn't really look like a lighting problem because of that hard seam. Are you sure you have matching colors and textures on the two polys? What happens if you turn lighting off entirely and render the same scene with simple coloring? Does the seam go away?
    Am I doing your homework for you?

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

    Re: Little Lighting issue

    Did you check your normals ? If they are not continuous, you will see discontinuities like that.

  5. #5
    Member Newbie
    Join Date
    Jan 2011
    Location
    Lincoln, UK
    Posts
    36

    Re: Little Lighting issue

    Hey Dark Photon, thankyou for your insight and suggestions.

    How would i go about implementing your first suggestion?

    Your second suggestion i understand, but i dont really want to be adding too many vertices.

    i spent most of yesterday playing around with my normals but i couldnt get it right. I am only calculating one normal per face, because when i calculated one per vertices, it was the same for each anyway. is this correct?

    also, i am feeding the co-ordinates into my normal function for both rectangles as so:
    Code :
    calcNormals(tl_x, tl_y, tl_z, bl_x, bl_y, bl_z, br_x, br_y, br_z)
    where tl = top left, bl = bottom left, and br = bottom right. This is the same order in which they are being drawn in, and yes i am culling the faces.

    So should i be feeding the co-ordinates into the second calcNormals call (i.e. the second rectangle) in a different order?


    MaxH:
    if i disable texturing and lighting, there is no seam

    ZbuffeR:
    see above about my confusion with normals.

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

    Re: Little Lighting issue

    You can force road normals to have only vertical component at 1.0, the two others at 0.0 : is it better ?

    Anyway, fixed path lighting is very poor, you need to have highly tesselated geometry to get anything passable.
    http://www.opengl.org/resources/feat...es/oglpitfall/
    http://www.opengl.org/resources/faq/...cal/lights.htm

    These links are all about deprecated OpenGL, and totally superseded by shaders.

  7. #7
    Member Newbie
    Join Date
    Jan 2011
    Location
    Lincoln, UK
    Posts
    36

    Re: Little Lighting issue

    hi ZbuffeR,

    i forced the normals to 0.0,1.0,0.0, but this made no diffence. when i checked the output from the normals function, the values above were the same. (for both rectangles).

    Like i said, i am calculating one normal per face, is that correct?

    I have read the first link, and i understand the tesselation effect now. but my question is, if i were to split the track length into say 10 seperate rectangles, wouldnt i just be reproducing the split another 10 times?

    Im going to read the second article now.

    Thanks,

    Dale

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,661

    Re: Little Lighting issue

    Quote Originally Posted by dalemac
    I am only calculating one normal per face, because when i calculated one per vertices, it was the same for each anyway. is this correct?
    ...
    if i disable texturing and lighting, there is no seam
    What about if you disable texturing but keep lighting. Is there a seam?

    If so, then your problem is likely that the normals at the shared vertices don't match between the quads.

    If not, then it's a fair bet that the textures don't match. Enable texturing but disable lighting to be sure.

    How would i go about implementing your first suggestion?
    Before we do that, we should get to the bottom of your problem here first. If the above doesn't nail down your problem, could you post a short GLUT test program that illustrates it? This will also provide a framework to plug in your "per pixel" lighting.

    If you want to read ahead on that, here's a good lighting tutorial that describes how to take lighting to the pixel level:

    http://www.lighthouse3d.com/opengl/g...dex.php?lights

  9. #9
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: Little Lighting issue

    Quote Originally Posted by dalemac
    MaxH:
    if i disable texturing and lighting, there is no seam
    That's not what I meant for you to do. Disable lighting only. Keep the texturing on (like Photon said).
    Am I doing your homework for you?

  10. #10
    Member Newbie
    Join Date
    Jan 2011
    Location
    Lincoln, UK
    Posts
    36

    Re: Little Lighting issue

    Hey guys, thanks for your continued input.

    I didnt notice at first, but there does seem to be a small gap in the textures, take a look at the image. (see the red box in the bottom right corner)

    how can i get rid of this seam?

    Thanks,

    Dale

Page 1 of 3 123 LastLast

Similar Threads

  1. GLSL Lighting Issue
    By tdkr80 in forum OpenGL: GLSL
    Replies: 1
    Last Post: 05-20-2017, 04:48 AM
  2. lighting issue (can't get specular highlights)
    By coffeeaddict in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-31-2011, 03:22 PM
  3. Issue with lighting intensity
    By Budois in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-27-2010, 02:36 PM
  4. Computer speed - issue or non-issue
    By howie in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 07-11-2004, 05:21 AM
  5. Simple lighting issue
    By BennUK in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-02-2004, 10:25 AM

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