When implementing the Phong reflection model, there are a number of methods for approximating the model, rather than implementing the exact formulas, which can speed up the calculation; for example, the [[Blinn–Phong reflection model]] is a modification of the Phong reflection model, which is more efficient if the viewer and the light source are treated to be at infinity.
Another approximation<ref>{{cite web |url=http://dicklyon.com/tech/Graphics/Phong_TR-Lyon.pdf |title=Phong Shading Reformulation for Hardware Renderer Simplification |last1=Lyon |first1=Richard F. |date= August 2, 1993 |work= |publisher= |accessdate=7 March 2011}}</ref> alsothat addresses the computationcalculation of the specularexponentiation term sincein the calculation of the powerspecular term mayis be computationallythe expensive.following: Considering that the specular term should be taken into account only if its dot product is positive, it can be approximated by realizing thatas
:<math>\max(0, \hat{R}_m \cdot \hat{V})^\alpha = \max(0, 1-\lambda)^{\beta \gamma} = \left(\max(0,1-\lambda)^\beta\right)^\gamma \approx \max(0, 1 - \beta \lambda)^\gamma </math>
forwhere <math>\lambda = 1 - \hat{R}_m \cdot \hat{V}</math>, for a sufficiently large, fixed integer <math>\gamma</math> (typically 4 will be enough), whereand <math>\beta = \alpha / \gamma\,</math> is a real number (notwhich necessarilydoesn't have to be an integer). TheFurthermore, the value <math>\lambda</math> can be further approximated as <math>\lambda = (\hat{R}_m - \hat{V})\cdot(\hat{R}_m - \hat{V}) / 2</math>; this squared distance between the vectors <math>\hat{R}_m</math> and <math>\hat{V}</math> is much less sensitive to normalization errors in those vectors than iswhat Phong's dot-product-based <math>\lambda = 1 - \hat{R}_m \cdot \hat{V}</math> is.
TheThis approximation of the specular term holds for a sufficiently large, integer <math>\gamma</math> value(typically, can4 or 8 will be enough). If this value is chosen to be a fixed power of 2, i.e. <math>\gamma = 2^n</math> where <math>n</math> is a smallan integer;, then the expression <math>(1 - \beta\lambda)^\gamma</math> can be more efficiently calculated by squaring <math>(1 - \beta\lambda)</math>\ <math>n</math> times. Here the ''shininess'' parameter is <math>\beta</math>, proportional to the original parameter <math>\alpha</math>.
This method substitutes a few multiplications for a variable exponentiation, and removes the need for an accurate reciprocal-square-root-based vector normalization.
|