Phong reflection model

Uses your system voice; voice and rate in settings.

Snapshot

≈ 6 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

The Phong reflection model (also called Phong illumination or Phong lighting) is an empirical model of the local illumination of points on a surface designed by the computer graphics researcher Bui Tuong Phong. In 3D computer graphics, it is sometimes referred to as "Phong shading" , particularly if the model is used with the interpolation method of the same name and in the context of pixel shaders or other places where a lighting calculation can be referred to as “shading”.

The Phong reflection model (also called Phong illumination or Phong lighting) is an empirical model of the local illumination of points on a surface designed by the computer graphics researcher Bui Tuong Phong. In 3D computer graphics, it is sometimes referred to as "Phong shading" , particularly if the model is used with the interpolation method of the same name and in the context of pixel shaders or other places where a lighting calculation can be referred to as “shading”. I_\text{p} = k_\text{a} i_\text{a} + \sum_{m\;\in\;\text{lights}} (k_\text{d} (\hat{L}_m \cdot \hat{N}) i_{m,\text{d}} + k_\text{s} (\hat{R}_m \cdot \hat{V})^{\alpha}i_{m,\text{s}}). where the direction vector \hat{R}_m is calculated as the reflection of \hat{L}_m on the surface characterized by the surface normal \hat{N} using \hat{R}_m = 2(\hat{L}_m\cdot \hat{N})\hat{N} - \hat{L}_m The hats indicate that the vectors are normalized. The diffuse term is not affected by the viewer direction ( \hat{V} ). The specular term is large only when the viewer direction ( \hat{V} ) is aligned with the reflection direction \hat{R}_m . Their alignment is measured by the \alpha power of the cosine of the angle between them. The cosine of the angle between the normalized vectors \hat{R}_m and \hat{V} is equal to their dot product. When \alpha is large, in the case of a nearly mirror-like reflection, the specular highlight will be small, because any viewpoint not aligned with the reflection will have a cosine less than one which rapidly approaches zero when raised to a high power. Although the above formulation is the common way of presenting the Phong reflection model, each term should only be included if the term's dot product is positive. (Additionally, the specular term should only be included if the dot product of the diffuse term is positive.) When the color is represented as RGB values, as often is the case in computer graphics, this equation is typically modeled separately for R, G and B intensities, allowing different reflection constants k_\text{a}, k_\text{d} and k_\text{s} for the different color channels. 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 that addresses the calculation of the exponentiation in the specular term is the following: Considering that the specular term should be taken into account only if its dot product is positive, it can be approximated as \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 where \lambda = 1 - \hat{R}_m \cdot \hat{V} , and \beta = \alpha / \gamma\, is a real number which doesn't have to be an integer. If \gamma is chosen to be a power of 2, i.e. \gamma = 2^n where n is an integer, then the expression (1 - \beta\lambda)^\gamma can be more efficiently calculated by squaring (1 - \beta\lambda)\ n times, i.e. (1 - \beta\lambda)^\gamma \,=\, (1 - \beta\lambda)^{2^n} \,=\, (1 - \beta\lambda)^{\overbrace{\scriptstyle 2\,\cdot\,2\,\cdot\,\dots\,\cdot\,2}^n} \,=\, (\dots((1 - \beta\lambda)\overbrace{^2)^2\dots)^2}^n. This approximation of the specular term holds for a sufficiently large integer \gamma (typically, 4 or 8 will be enough). Furthermore, the value \lambda can be approximated as \lambda = (\hat{R}_m - \hat{V})\cdot(\hat{R}_m - \hat{V}) / 2 , or as \lambda = (\hat{R}_m \times \hat{V})\cdot(\hat{R}_m \times \hat{V}) / 2. The latter is much less sensitive to normalization errors in \hat{R}_m and \hat{V} than Phong's dot-product-based \lambda = 1 - \hat{R}_m \cdot \hat{V} is , and practically doesn't require \hat{R}_m and \hat{V} to be normalized except 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. For example, we have a cylindrical object, for instance a finger, and wish to compute the normal N=[N_x, N_z] on a line on the object. We assume only one light, no specular reflection, and uniform known (approximated) reflection parameters. We can then simplify the Phong equation to: I_p(x) = C_a + C_d (L(x) \cdot N(x)) With C_a a constant equal to the ambient light and C_d a constant equal to the diffusion reflection. We can re-write the equation to: ( I_p(x)- C_a ) / C_d = L(x) \cdot N(x) Which can be rewritten for a line through the cylindrical object as: ( I_p- C_a ) / C_d = L_x N_x + L_z N_z For instance if the light direction is 45 degrees above the object L=[0.71, 0.71] we get two equations with two unknowns. ( I_p- C_a ) / C_d = 0.71 N_x + 0.71 N_z 1 = \sqrt{(N_x^2 + N_z^2)} Because of the powers of two in the equation there are two possible solutions for the normal direction. Thus some prior information of the geometry is needed to define the correct normal direction. The normals are directly related to angles of inclination of the line on the object surface. Thus the normals allow the calculation of the relative surface heights of the line on the object using a line integral, if we assume a continuous surface. If the object is not cylindrical, we have three unknown normal values N=[N_x, N_y, N_z] . Then the two equations still allow the normal to rotate around the view vector, thus additional constraints are needed from prior geometric information. For instance in face recognition those geometric constraints can be obtained using principal component analysis (PCA) on a database of depth-maps of faces, allowing only surface normals solutions which are found in a normal population.

External links

Phong reflection model in Matlab

Text derived from https://en.wikipedia.org/w/index.php?oldid=1311915114 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

4 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.