Phong reflection model: Difference between revisions

Content deleted Content added
Monkbot (talk | contribs)
Line 10:
[[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_si_\text{s}</math> and <math>i_di_\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_ai_\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_sk_\text{s}</math>, which is a specular reflection constant, the ratio of reflection of the specular term of incoming light,
:<math>k_dk_\text{d}</math>, which is a diffuse reflection constant, the ratio of reflection of the diffuse term of incoming light ([[Lambertian reflectance]]),
:<math>k_ak_\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.
 
Furthermore, we have
 
:<math>\mathrm{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 27:
:<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_pI_\text{p}</math>:
 
:<math>I_pI_\text{p} = k_ak_\text{a} i_ai_\text{a} + \sum_\mathrm{m \; \in \; \text{lights}} (k_dk_\text{d} (\hat{L}_m \cdot \hat{N}) i_{m,\text{d}} + k_sk_\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>
Line 41:
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 reflections constants <math>k_ak_\text{a},</math> <math>k_dk_\text{d}</math> and <math>k_sk_\text{s}</math> for the different [[Channel (digital image)|color channels]].
 
=== Computationally more efficient alterations ===