Blinn–Phong Reflection Model
   HOME

TheInfoList



OR:

The Blinn–Phong reflection model, also called the modified Phong reflection model, is a modification developed by
Jim Blinn James F. Blinn (born 1949) is an American computer scientist who first became widely known for his work as a computer graphics expert at NASA's Jet Propulsion Laboratory (JPL), particularly his work on the pre-encounter animations for the Vo ...
to the
Phong reflection model 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 somet ...
. Blinn–Phong is the default shading model used in
OpenGL OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardwa ...
and
Direct3D Direct3D is a graphics application programming interface (API) for Microsoft Windows. Part of DirectX, Direct3D is used to render three-dimensional graphics in applications where performance is important, such as games. Direct3D uses hardware a ...
's fixed-function pipeline (before Direct3D 10 and OpenGL 3.1), and is carried out on each vertex as it passes down the
graphics pipeline In computer graphics, a computer graphics pipeline, rendering pipeline or simply graphics pipeline, is a conceptual model that describes what steps a graphics system needs to perform to Rendering (computer graphics), render a ...
;
pixel In digital imaging, a pixel (abbreviated px), pel, or picture element is the smallest addressable element in a raster image, or the smallest point in an all points addressable display device. In most digital display devices, pixels are the smal ...
values between vertices are interpolated by
Gouraud shading Gouraud shading, named after Henri Gouraud, is an interpolation method used in computer graphics to produce continuous shading of surfaces represented by polygon meshes. In practice, Gouraud shading is most often used to achieve continuous l ...
by default, rather than the more computationally-expensive
Phong shading In 3D computer graphics, Phong shading, Phong interpolation, or normal-vector interpolation shading is an interpolation technique for surface shading invented by computer graphics pioneer Bui Tuong Phong. Phong shading interpolates surface norm ...
.


Description

In Phong shading, one must continually recalculate the
dot product In mathematics, the dot product or scalar productThe term ''scalar product'' means literally "product with a scalar as a result". It is also used sometimes for other symmetric bilinear forms, for example in a pseudo-Euclidean space. is an algebra ...
R \cdot V between a viewer (''V'') and the beam from a light-source (''L'') reflected (''R'') on a surface. If, instead, one calculates a ''halfway vector'' between the viewer and light-source vectors, : H = \frac R \cdot V can be replaced with N \cdot H, where N is the normalized surface normal. In the above equation, L and V are both normalized vectors, and H is a solution to the equation V=P_H(-L), where P_H is the
Householder matrix In linear algebra, a Householder transformation (also known as a Householder reflection or elementary reflector) is a linear transformation that describes a reflection about a plane or hyperplane containing the origin. The Householder transformati ...
that reflects a point in the hyperplane that contains the origin and has the normal H. This dot product represents the cosine of an angle that is half of the angle represented by Phong's dot product if ''V'', ''L'', ''N'' and ''R'' all lie in the same plane. This relation between the angles remains approximately true when the vectors don't lie in the same plane, especially when the angles are small. The angle between ''N'' and ''H'' is therefore sometimes called the halfway angle. Considering that the angle between the halfway vector and the surface normal is likely to be smaller than the angle between ''R'' and ''V'' used in Phong's model (unless the surface is viewed from a very steep angle for which it is likely to be larger), and since Phong is using \left( R \cdot V \right)^, an
exponent Exponentiation is a mathematical operation, written as , involving two numbers, the '' base'' and the ''exponent'' or ''power'' , and pronounced as " (raised) to the (power of) ". When is a positive integer, exponentiation corresponds to re ...
can be set \alpha^\prime > \alpha such that \left(N \cdot H \right)^ is closer to the former expression. For front-lit surfaces (specular reflections on surfaces facing the viewer), \alpha^\prime = 4\,\alpha will result in specular highlights that very closely match the corresponding Phong reflections. However, while the Phong reflections are always round for a flat surface, the Blinn–Phong reflections become elliptical when the surface is viewed from a steep angle. This can be compared to the case where the sun is reflected in the sea close to the horizon, or where a far away street light is reflected in wet pavement, where the reflection will always be much more extended vertically than horizontally. Additionally, while it can be seen as an approximation to the Phong model, it produces more accurate models of empirically determined
bidirectional reflectance distribution function The bidirectional reflectance distribution function (BRDF; f_(\omega_,\, \omega_) ) is a function of four real variables that defines how light is reflected at an opaque surface. It is employed in the optics of real-world light, in compute ...
s than Phong for many types of surfaces.


Efficiency

Blinn-Phong will be faster than Phong in the case where the viewer and light are treated to be very remote, such as approaching or at infinity. This is the case for directional lights and orthographic/isometric cameras. In this case, the halfway vector is independent of position and surface curvature simply because the halfway vector is dependent on the direction to viewer's position and the direction to the light's position, which individually converge at this remote distance, hence the halfway vector can be thought of as constant in this case. H therefore can be computed once for each light and then used for the entire frame, or indeed while light and viewpoint remain in the same relative position. The same is not true with Phong's method of using the reflection vector which depends on the surface curvature and must be recalculated for each pixel of the image (or for each vertex of the model in the case of vertex lighting). In 3D scenes with perspective cameras, this optimization is not possible.


Code samples


High-Level Shading Language code sample

This sample in
High-Level Shading Language The High-Level Shader Language or High-Level Shading Language (HLSL) is a proprietary shading language developed by Microsoft for the Direct3D 9 API to augment the shader assembly language, and went on to become the required shading language ...
is a method of determining the diffuse and specular light from a point light. The light structure, position in space of the surface, view direction vector and the normal of the surface are passed through. A Lighting structure is returned; The below also needs to clamp certain dot products to zero in the case of negative answers. Without that, light heading away from the camera is treated the same way as light heading towards it. For the specular calculation, an incorrect "halo" of light glancing off the edges of an object and away from the camera might appear as bright as the light directly being reflected towards the camera. struct Lighting ; struct PointLight ; Lighting GetPointLight(PointLight light, float3 pos3D, float3 viewDir, float3 normal)


OpenGL Shading Language code sample

This sample in the
OpenGL Shading Language OpenGL Shading Language (GLSL) is a high-level shading language with a syntax based on the C programming language. It was created by the OpenGL ARB (OpenGL Architecture Review Board) to give developers more direct control of the graphics pipelin ...
consists of two code files, or ''shaders''. The first one is a so-called ''vertex shader'' and implements
Phong shading In 3D computer graphics, Phong shading, Phong interpolation, or normal-vector interpolation shading is an interpolation technique for surface shading invented by computer graphics pioneer Bui Tuong Phong. Phong shading interpolates surface norm ...
, which is used to interpolate the surface normal between vertices. The second shader is a so-called ''fragment shader'' and implements the Blinn–Phong shading model in order to determine the diffuse and specular light from a point light source.


Vertex shader

This vertex shader implements
Phong shading In 3D computer graphics, Phong shading, Phong interpolation, or normal-vector interpolation shading is an interpolation technique for surface shading invented by computer graphics pioneer Bui Tuong Phong. Phong shading interpolates surface norm ...
: attribute vec3 inputPosition; attribute vec3 inputNormal; uniform mat4 projection, modelview, normalMat; varying vec3 normalInterp; varying vec3 vertPos; void main()


Fragment shader

This fragment shader implements the Blinn–Phong shading model and
gamma correction Gamma correction or gamma is a nonlinear operation used to encode and decode luminance or tristimulus values in video or still image systems. Gamma correction is, in the simplest cases, defined by the following power-law expression: : V_\text = ...
: precision mediump float; in vec3 normalInterp; in vec3 vertPos; uniform int mode; const vec3 lightPos = vec3(1.0, 1.0, 1.0); const vec3 lightColor = vec3(1.0, 1.0, 1.0); const float lightPower = 40.0; const vec3 ambientColor = vec3(0.1, 0.0, 0.0); const vec3 diffuseColor = vec3(0.5, 0.0, 0.0); const vec3 specColor = vec3(1.0, 1.0, 1.0); const float shininess = 16.0; const float screenGamma = 2.2; // Assume the monitor is calibrated to the sRGB color space void main() The colors , and are not supposed to be gamma corrected. If they are colors obtained from gamma-corrected image files (
JPEG JPEG ( ) is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and imag ...
, PNG, etc.), they need to be linearized before working with them, which is done by scaling the channel values to the range and raising them to the gamma value of the image, which for images in the
sRGB sRGB is a standard RGB (red, green, blue) color space that HP and Microsoft created cooperatively in 1996 to use on monitors, printers, and the World Wide Web. It was subsequently standardized by the International Electrotechnical Commission ( ...
color space can be assumed to be about 2.2 (even though for this specific color space, a simple power relation is just an approximation of the actual
transformation Transformation may refer to: Science and mathematics In biology and medicine * Metamorphosis, the biological process of changing physical form after birth or hatching * Malignant transformation, the process of cells becoming cancerous * Trans ...
). Modern graphics APIs have the ability to perform this gamma correction automatically when sampling from a
texture Texture may refer to: Science and technology * Surface texture, the texture means smoothness, roughness, or bumpiness of the surface of an object * Texture (roads), road surface characteristics with waves shorter than road roughness * Texture ...
or writing to a
framebuffer A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM) containing a bitmap that drives a video display. It is a memory buffer containing data representing all the pixels in a complete video frame. Modern ...
.https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_sRGB.txt


See also

*
List of common shading algorithms {{Short description, none This article lists common shading algorithms used in computer graphics. Interpolation techniques These techniques can be combined with any illumination model: * Flat shading * Gouraud shading * Phong shading Illuminatio ...
*
Phong reflection model 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 somet ...
for Phong's corresponding model *
Gamma correction Gamma correction or gamma is a nonlinear operation used to encode and decode luminance or tristimulus values in video or still image systems. Gamma correction is, in the simplest cases, defined by the following power-law expression: : V_\text = ...
*
Specular highlight A specular highlight is the bright spot of light that appears on shiny objects when illuminated (for example, see image on right). Specular highlights are important in 3D computer graphics, as they provide a strong visual cue for the shape of a ...


References

{{DEFAULTSORT:Blinn-Phong shading model Shading