Results 1 to 3 of 3

Thread: Lighting effect with culling backface

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    2

    Lighting effect with culling backface

    There are shadows in the lighting effect of the top graph, but there isn't in the bottom one.

    The code between the top graph and the bottom graph is that the GL_CULL_FACE is enabled in the bottom one. e.g.,
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    The teapot and that object are rendered at the same time, in the same window, and with the same lighting conditions. However, the light effect of the teapot is pretty good in both conditions.

    I don't know what the problem is. It seems the backface triangles reslut in the difference of lighting effect.

    The sample code of lighting is as follows:
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
    glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

    float fPos[] = {0, 1, 0, 0.f};
    glLightfv(GL_LIGHT0, GL_POSITION, fPos0);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, fDiffuse);


    Lighting effect image
    Thanks so much for any suggestion.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Dec 2008
    Location
    USA
    Posts
    134

    Re: Lighting effect with culling backface

    Since culling the back faces seems to fix the problem, it seems that drawing something in the top picture is wrong - you're drawing the dark grey bits over the lighter bits. I'm assuming the light is shining onto the side of the front of the objects, so the darker patches could be the far side of the cloud. These faces would be back facing. So...

    Did you enable depth testing? If you did not, you could be drawing the backs of the far side of the cloud over the near side of the cloud in the top picture. In the bottom, since these faces are backwards, they are not getting drawn and the picture looks correct.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    2

    Re: Lighting effect with culling backface

    Thanks so much for your reply.

    I found the problem resulted from GL_POLYGON_OFFSET_FILL.
    I enable it because I want to render polygon surface in FILL mode and LINE mode simutaneously. Although I only render in FILL mode in the picture, it seems GL_POLYGON_OFFSET_FILL should not used with lighting. I don't know if it is a known issue, or maybe I just don't know how to use it.

    glEnable(GL_POLYGON_OFFSET_FILL);
    glPolygonOffset(2.0, 2.0);

    I also find the larger the offset is, the worse the lighting effect will be.

    Thanks again.

Similar Threads

  1. "Second" backface culling
    By LaBasX2 in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 08-12-2002, 03:28 AM
  2. backface culling
    By blender in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 04-26-2002, 10:29 AM
  3. backface culling.
    By willmoores in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-15-2002, 01:38 PM
  4. 3d backface culling
    By imported_Theo in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-19-2000, 08:19 AM
  5. Backface culling
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-18-2000, 04:52 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