Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Phong reflection model
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== 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 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. 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. For each ''material'' in the scene, the following parameters are defined: :<math>k_\text{s}</math>, which is a specular reflection constant, the ratio of reflection of the specular term of incoming light, :<math>k_\text{d}</math>, which is a diffuse reflection constant, the ratio of reflection of the diffuse term of incoming light ([[Lambertian reflectance]]), :<math>k_\text{a}</math>, which is an ambient reflection constant, the ratio of reflection of the ambient term present in all points in the scene rendered, and :<math>\alpha</math>, which is a ''shininess'' constant for this material, which is larger for surfaces that are smoother and more mirror-like. When this constant is large the specular highlight is small. [[File:Blinn_Vectors.svg|thumb|Vectors for calculating Phong and Blinn–Phong shading]] Furthermore, there is :<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, :<math>\hat{R}_m</math>, which is the direction that a perfectly reflected ray of light would take from this point on the surface, and :<math>\hat{V}</math>, which is the direction pointing towards the viewer (such as a virtual camera). Then the Phong reflection model provides an equation for computing the illumination of each surface point <math>I_\text{p}</math>: :<math>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}}).</math> <!-- WHICH variable is the index of summation in this sum, running through the list of all members of the set called "lights"?? --> <!-- SEVERAL variables depend on the light: direction vectors L and R, intensities i_d and i_s. All of these could be subscripted with a light index if desired, but it's not needed. --> where the direction vector <math>\hat{R}_m</math> is calculated as the [[Specular reflection#Direction of reflection|reflection]] of <math>\hat{L}_m</math> on the surface characterized by the surface normal <math>\hat{N}</math> using :<math>\hat{R}_m = 2(\hat{L}_m\cdot \hat{N})\hat{N} - \hat{L}_m</math> The hats indicate that the vectors are [[Unit vector|normalized]]. The diffuse term is not affected by the viewer direction (<math>\hat{V}</math>). The specular term is large only when the viewer direction (<math>\hat{V}</math>) is aligned with the reflection direction <math>\hat{R}_m</math>. Their alignment is measured by the <math>\alpha</math> power of the cosine of the angle between them. The cosine of the angle between the normalized vectors <math>\hat{R}_m</math> and <math>\hat{V}</math> is equal to their [[dot product]]. When <math>\alpha</math> 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 <math>k_\text{a},</math> <math>k_\text{d}</math> and <math>k_\text{s}</math> for the different [[Channel (digital image)|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<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 |access-date=7 March 2011}}</ref> 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 :<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 integer <math>\gamma</math> (typically, 4 or 8 will be enough). 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 Phong's dot-product-based <math>\lambda = 1 - \hat{R}_m \cdot \hat{V}</math> is{{Citation needed|reason=Lyon-1993 does not reference this anywhere|date=April 2022}}, and practically doesn't require <math>\hat{R}_m</math> and <math>\hat{V}</math> to be normalized{{Citation needed|reason=Lyon-1993 does not reference this anywhere|date=April 2022}} 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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)