Search code examples
opengl3dcad

OpenGL mesh + mirror transformation = wrong lighting


Frequently, you need to add to the 3D graphics scene a mirrored copy of the same object, like a car door or the left version of the right shoe. When you do this with a mirror transformation on a display list containing a mesh of triangles (vertices, triangles, and normals) you get illumination problems.

We are able to detect a reflection inside a 4x4 transformation matrix but we don't know how to recycle the same display list (draw it with correct illumination) simply changing OpenGL status flags.

I'm thinking of glFrontFace(), GL_NORMALIZE, etc.

Do you think it is possible without building a new display list of the mirrored object? If yes, how?


Solution

  • Given your usage of "display lists" and GL_NORMALIZE, it sounds like you're using old school fixed-function OpenGL. You'll want to enable a feature that was called two-sided lighting:

    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
    

    As a side note, if you have backface culling enabled you'll also want to flip the culling direction when drawing the flipped geometry:

    glFrontFace(GL_CW); // the default setting is GL_CCW
    

    Good luck, and I hope you can modernize; shaders are great!