[2] In Phong shading, one must continually recalculate the dot product
is the Householder matrix that reflects a point in the hyperplane that contains the origin and has the normal
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.
will result in specular highlights that very closely match the corresponding Phong reflections.
Additionally, while it can be seen as an approximation to the Phong model, it produces more accurate models of empirically determined bidirectional reflectance distribution functions than Phong for many types of surfaces.
[4] 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.
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.
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).
A Lighting structure is returned; The below also needs to clamp certain dot products to zero in the case of negative answers.
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.
This sample in the OpenGL Shading Language consists of two code files, or shaders.
The first one is a so-called vertex shader and implements Phong shading, 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.
This vertex shader implements Phong shading: This fragment shader implements the Blinn–Phong shading model[5] and gamma correction: The colors ambientColor, diffuseColor and specColor are not supposed to be gamma corrected.
If they are colors obtained from gamma-corrected image files (JPEG, PNG, etc.
), they need to be linearized before working with them, which is done by scaling the channel values to the range [0, 1] and raising them to the gamma value of the image, which for images in the sRGB 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).
Modern graphics APIs have the ability to perform this gamma correction automatically when sampling from a texture or writing to a framebuffer.