Section 4.2. Normals


4.2. Normals

OpenGL uses the current normal at each vertex to determine the orientation of the surface with respect to the light source and viewer. Lighting calculations occur in eye-coordinate space. OpenGL transforms normals into eye coordinates using a matrix derived from the model-view matrix.

The current normal affects the results of diffuse and specular lighting computation. The OpenGL lighting equations produce realistic results when the current normal is unit length. If you know your model-view matrix doesn't contain a scale transformation, you'll achieve good lighting results by simply sending unit-length normals.

Model-view matrices that contain scale transformations, however, produce distorted eye-coordinate normals that cause abnormal lighting results. This commonly occurs when applications must display models in a non-native unit space (for example, your application uses meter space, but your models were created in feet spaceoften solved by applying a scale transformation before rendering the model). OpenGL provides two ways to restore distorted normals to unit length: normal rescaling and normalization.

If the model-view scale transformation is uniform in x, y, and z, and if your application specifies unit-length normals (that is, they're unit length in object coordinates before the transformation into eye coordinates), the least expensive method is to enable normal rescaling. This causes OpenGL to scale transformed normals back to unit length, using a scale factor derived from the model-view matrix.

Enable normal rescaling with glEnable( GL_RESCALE_NORMAL ). Normal rescaling is available in OpenGL version 1.2 and later.

If the model-view scale transformation isn't uniform, or if your object-coordinate normals aren't unit length, OpenGL will make them unit length if you enable normalization. Enable normalization by calling glEnable( GL_NORMALIZE ). Normalization is available in OpenGL version 1.0 and later.

A simplistic OpenGL implementation effects normalization by computing a square root for each (eye-coordinate) normal and dividing its x, y, and z components by the result. Though less expensive implementations are common, normalization always involves more operations than normal rescaling, which performs better. Of course, the best-performing solution is to scale the vertices of your geometry at init time and ensure that all normals are unit length.




OpenGL Distilled
OpenGL Distilled
ISBN: 0321336798
EAN: 2147483647
Year: 2007
Pages: 123
Authors: Paul Martz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net