Normalize or Not

Should Normalize

NormalInterpolation

Normalization is an expensive operation. So, some may think a vertex shader is the right place to do this rather than a fragment shader. However, even if the vertex shader always generates unit-length surface normals, interpolation can change their length. Linear interpolation of unit normals across a surface results in interpolated vectors with lengths less than one. As shown above, the interpolation will be skewed if the normal length varies significantly between vertices such as a side effect of vertex blending. Therefore, interpolated vectors should be normalized before and after interpolation, that is, in both the vertex and fragment shaders.

Should Not Normalize

VectorInterpolation

Unlike the surface normals, vectors that point toward specific locations, such as the view vector and the light vector for punctual lights that have no area, are typically not interpolated. Instead, the interpolated surface position is used to compute these vectors in the fragment shader. If for some reason it is necessary to interpolate these vectors, do not normalize them beforehand. This will yield incorrect results as above.

Reference

[1] Tomas Akenine-Mller, Eric Haines, and Naty Hoffman. 2018. Real-Time Rendering, Fourth Edition (4th. ed.). A. K. Peters, Ltd., USA.


© 2024. All rights reserved.