Some Notes on Lighting in OpenGL ES

While lighting can add some nice eye candy, it has its limits and pitfalls. Here's a few things you should take to heart.

Lighting is expensive, especially on low-end devices. Use it with care. The more light sources you enable the more computational power is required to render the scene.

When specifying the position/direction of point/directional lights, you must do it after you have loaded the camera matrices and before you multiply the model-view matrix with any matrices to move and rotate objects around! This is crucial. If you don't follow this method, you will have some inexplicable lighting artifacts.

When you use glScalef() to change the size of a model, its normals will also be scaled. This is bad, because OpenGL ES expects unit-length normals. To work around this issue you can use the command glEnable(GLl0.GL_N0RMALIZE) or in some circumstances glEnable(GLl0.GL_RESCALE_N0RMAL). I'd suggest sticking to the former, as the later has some restrictions and caveats. The problem is that normalizing or rescaling normals is computationally heavy. Not scaling your lit objects is best for performance.

0 0

Post a comment