Content deleted Content added
m →Computationally more efficient alterations: Rephrased |
Link suggestions feature: 3 links added. Tags: Visual edit Mobile edit Mobile web edit Newcomer task Suggested: add links |
||
(35 intermediate revisions by 33 users not shown) | |||
Line 1:
{{Short description|Shading algorithm in computer graphics}}
{{distinguish|Phong shading}}
[[Image:Phong components version 4.png|
The '''Phong reflection model''' (also called '''Phong illumination''' or '''Phong lighting''') is an [[Empirical_modelling|empirical model]] of the [[illumination model|local illumination]] of points on a [[surface]]. In [[3D computer graphics]], it is sometimes ambiguously referred to as <!--DO NOT LINK-->"Phong shading"<!--DO NOT LINK-->, in particular if the model is used in combination with the [[Phong shading|interpolation method of the same name]] and in the context of [[pixel shader]]s 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 [[
== History ==
The Phong reflection model was developed by [[Bui Tuong Phong]] at the [[University of Utah]], who published it in his 1973 Ph.D. dissertation.<ref>Bui Tuong Phong, [http://www.cs.northwestern.edu/~ago820/cs395/Papers/Phong_1975.pdf Illumination for computer generated pictures], Communications of ACM 18 (1975), no. 6, 311–317.</ref><ref>University of Utah School of Computing, http://www.cs.utah.edu/school/history/#phong-ref</ref> It was published in conjunction with a method for interpolating the calculation for each individual [[pixel]] that is rasterized from a polygonal surface model; the interpolation technique is known as [[Phong shading]], even when it is used with a reflection model other than Phong's. Phong's methods were considered radical at the time of their introduction, but have since become the de facto baseline shading method for many rendering applications. Phong's methods have proven popular due to their generally efficient use of computation time per rendered pixel.▼
▲The Phong reflection model was developed by [[Bui Tuong Phong]] at the [[University of Utah]], who published it in his
Phong reflection is an empirical model of local illumination. It describes the way a surface reflects light as a combination of the [[diffuse reflection]] of rough surfaces with the [[specular reflection]] of shiny surfaces. It is based on [[Bui Tuong Phong]]'s informal observation that shiny surfaces have small intense [[specular highlight]]s, while dull surfaces have large highlights that fall off more gradually. The model also includes an ''ambient'' term to account for the small amount of light that is scattered about the entire scene.▼
== Concepts ==
▲Phong reflection is an empirical model of local illumination. It describes the way a surface reflects light as a combination of the [[diffuse reflection]] of rough surfaces with the [[specular reflection]] of shiny surfaces. It is based on
▲[[Image:Phong components version 4.png|655px|center|thumb|Visual illustration of the Phong equation: here the light is white, the ambient and diffuse colors are both blue, and the specular color is white, reflecting a small part of the light hitting the surface, but only in very narrow highlights. The intensity of the diffuse component varies with the direction of the surface, and the ambient component is uniform (independent of direction).]]
For each light source in the scene, components <math>i_\text{s}</math> and <math>i_\text{d}</math> are defined as the intensities (often as [[RGB]] values) of the specular and diffuse components of the light sources, respectively. A single term <math>i_\text{a}</math> controls the ambient lighting; it is sometimes computed as a sum of contributions from all light sources.
Line 21 ⟶ 24:
[[File:Blinn_Vectors.svg|thumb|Vectors for calculating Phong and Blinn–Phong shading]]
Furthermore,
:<math>\text{lights}</math>, which is the [[set (mathematics)|set]] of all light sources,
:<math>\hat{L}_m</math>, which is the direction vector from the point on the surface toward each light source (<math>m</math> specifies the light source),
:<math>\hat{N}</math>, which is the [[Surface normal|normal]] at this point on the surface,
Line 39 ⟶ 42:
:<math>\hat{R}_m = 2(\hat{L}_m\cdot \hat{N})\hat{N} - \hat{L}_m</math>
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
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 |
:<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>
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]]. If <math>\gamma</math> 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, i.e.
:<math>(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.</math>
This approximation of the specular term holds for a sufficiently large
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>, or as <math>\lambda = (\hat{R}_m \times \hat{V})\cdot(\hat{R}_m \times \hat{V}) / 2.</math> The latter is much less sensitive to normalization errors in <math>\hat{R}_m</math> and <math>\hat{V}</math> than
This method substitutes a few multiplications for a variable exponentiation, and removes the need for an accurate reciprocal-square-root-based vector normalization.
== Inverse
The Phong reflection model in combination with [[Phong shading]] is an approximation of shading of objects in real life. This means that the Phong equation can relate the shading seen in a [[photograph]] with the surface normals of the visible object. Inverse refers to the wish to estimate the surface normals given a rendered image, natural or computer-made.
The Phong reflection model contains many parameters, such as the surface diffuse reflection parameter ([[albedo]]) which may vary within the object. Thus the normals of an object in a photograph can only be determined, by introducing additional information such as the number of lights, light directions and reflection parameters.
For example, we have a cylindrical object, for instance a finger, and wish to compute the normal <math>N=[N_x, N_z]</math> 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:
:<math>I_p(x) = C_a + C_d (L(x) \cdot N(x)) </math>
Line 84 ⟶ 87:
:<math>1 = \sqrt{(N_x^2 + N_z^2)}</math>
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 <math>N=[N_x, N_y, N_z]</math>. 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 [[facial recognition system|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.<ref>{{cite
== Applications ==
== See also ==
* [[List of common shading algorithms]]▼
*
*
* {{anl|Phong shading}}
▲* [[Bidirectional reflectance distribution function]] – another reflection model
*
== References ==▼
{{refs}}
==External links==
* [http://michal.is/projects/phong-reflection-model-matlab/ Phong reflection model in Matlab]▼
* [http://www.sunandblackcat.com/tipFullView.php?l=eng&topicid=30 Phong reflection model in GLSL]▼
▲* [https://web.archive.org/web/20160525135133/http://michal.is/projects/phong-reflection-model-matlab/ Phong reflection model in Matlab]
▲==References==
▲* {{usurped|1=[https://web.archive.org/web/20180816064924/http://www.sunandblackcat.com/tipFullView.php?l=eng&topicid=30 Phong reflection model in GLSL]}}
[[Category:Computer graphics algorithms]]
[[Category:Shading]]
|