Diffuse Lighting Position Problem (long)

I’m trying to debug some lighting problems with an older program that I wrote several years ago. The problem is that the expected results for my positional diffuse light is reversed from what I expect.

I corrected some issues with the normals that I found and this seemed to fix the problem. I removed some debugging code, recompiled and the lighting was wrong again. I’ve checked the actual position of the lights using glGetLight and the lights are where I placed them but the results are wrong and I’m not sure what else to look.

Program Info:

  • OpenGL 1.4
  • Orthographic Projection
  • Uses multiplication of the Model Matrix for rotations
  • GL_NORMALIZE is enabled

It’s a fairly complex application (geology visualization) so posting the code isn’t too practical unless there are certain sections that you’d like to see.

Please ask if there’s anything else that would help.

Mitch Wolberg,
RockWare, Inc.
http://www.rockware.com

If you could extract the rendering code and show us a minimal example you will be much more likely to receive help. At the moment it is rather difficult to suggest anything…

T

I’ve spent the morning going back over this problem and somehow the normals had been reversed again. I’m not sure how that happened but it was probably something stupid on my part.

I’d like to post some of the code but my rendering is distributed over many procedures and units. I render a variety of different complex objects from as simple as triangles and labels to iso-surfaces. It isn’t pretty or fast but it does work, at least most of the time.

Perhaps you could help us by going into some detail about what “wrong” means for your lighting. Is it only about the flipped normals you mention? Or is the scenery as a whole lit from a different direction than you expect? Does whatever effect you’re seeing depend on your view transformation? Is it affecting only parts of your scenery, or all of it? Etc.

Have you tried creating a sample app where you recreate your view, projection, and lighting, and see if that produces what you expect for some simple geometry, like a sphere or a box?

The problem was that the lighting appeared to come from the opposite direction then expected. Fixing the order of the triangle and quad vertices also fixed the calculation of normals.