Phong reflection model: Difference between revisions

Content deleted Content added
m Computationally more efficient alterations: Extracted second approximation into own paragraph
Computationally more efficient alterations: Added cross product approximation. The other approximation using only the difference between R and V doesn't guarantee to give good results if R and V are not normalized
Line 54:
where <math>\lambda = 1 - \hat{R}_m \cdot \hat{V}</math>, and <math>\beta = \alpha / \gamma\,</math> is a real number which doesn't have to be an integer. This approximation of the specular term holds for a sufficiently large, integer <math>\gamma</math> (typically, 4 or 8 will be enough). If this value is chosen to be a power of 2, i.e. <math>\gamma = 2^n</math> where <math>n</math> is an integer, then the expression <math>(1 - \beta\lambda)^\gamma</math> can be more efficiently calculated by squaring <math>(1 - \beta\lambda)\ n</math> times.
 
Furthermore, the value <math>\lambda</math> can be approximated as <math>\lambda = (\hat{R}_m - \hat{V})\cdot(\hat{R}_m - \hat{V}) / 2</math>;, thisor squaredas distance<math>\lambda between= the(\hat{R}_m vectors\times <math>\hat{V})\cdot(\hat{R}_m</math> and\times <math>\hat{V}) / 2.</math> The latter is much less sensitive to normalization errors in those<math>\hat{R}_m</math> vectorsand <math>\hat{V}</math> than what Phong's dot-product-based <math>\lambda = 1 - \hat{R}_m \cdot \hat{V}</math> is, and practically doesn't require <math>\hat{R}_m</math> and <math>\hat{V}</math> to be normalized unless for very low-resolved triangle meshes.
 
This method substitutes a few multiplications for a variable exponentiation, and removes the need for an accurate reciprocal-square-root-based vector normalization.