more light problems

Started by
3 comments, last by GameDev.net 18 years, 8 months ago
More OpenGL lighting problems. My lighting doesn't seem to be moving now. It stays the same when I move around, which is basically doing a translate in the x or y direction when I press on the directional keys. The problem arises when I do a rotate in the Y-axis. glRotatef(mAngle, 0.0f, 1.0f, 0.0f); The shadows change for some reason. I made some screenshots to show what happens.

This is basically a simple heightfield terrain. I use triangle strips to create the terrain. What could cause the shadow to change?

:: site :: project ::
Advertisement
I can't stop thinking about this problem since I fell asleep (which can also be a problem when I'm currently at work). Anyway, my current reasoning as to what's wrong is the normal. Is there a difference whether the normal is say going out from the FRONT face or going out from the BACK face? I think I may have my normal's in the wrong direction and when I turn a certain way, the angle of the light rays to the normal is greater than 180 degrees and OpenGL will think these polygons shouldn't be lit...??? Bah, still don't get it...
:: site :: project ::
....... it was a typo... blahhhhh
anonymous was me ... pretty obvious
:: site :: project ::
The problem is OpenGL's lighting system is intimately linked with the ModelView matrix. You can not separate them. You either do not use OpenGL lighting. Or you must perform transformations at the vertex level before submission to the pipeline. Or you could come up with complex inverse transformations to adjust for rotations by adapting the light position. This would involve a multiplication of the inverse rotation matrix against the light position vector then applying the light position update after the translations on your object. Either way, by the time you've gone through all this headache and with the limitations of the OpenGL lighting system in general, my verdict is to never use OpenGL lighting.

Either use your own per-vertex lighting calculations or use per-pixel effects with shaders, dot env combiners, or however you prefer. Lastly, if light/dark mapping is possible that is also an option.

I am currently working on a full production title and ran into this problem. I wish OpenGL used Direct3D's style of lighting.

PS - Don't try fooling with the order either. It just can't be done. I've tried every combination.

This topic is closed to new replies.

Advertisement