Jump to content

Computer Graphics: Difference between revisions

Line 122: Line 122:
===Gourard Shading===
===Gourard Shading===
===Phong Shading===
===Phong Shading===
{{main | Wikipedia: Phong shading | Wikipedia: Phong reflection model}}
See [https://www.scratchapixel.com/lessons/3d-basic-rendering/phong-shader-BRDF scratchapixel phong shader BRDF]
Here, the image is a linear combination of ambient, diffuse, and specular colors. 
If <math>N</math> is the normal vector, <math>V</math> is a vector from the vertex to the viewer, <math>L</math> from the light to the vertex, and <math>R</math> the incident vector (i.e. L rotated 180 around N) then
* Ambient is a constant color for every pixel.
* The diffuse coefficient is <math>N \cdot L</math>.
* The specular coefficient is <math>(R \cdot V)^n</math> where <math>n</math> is the ''shininess''.
The final color is <math>k_{ambient} * ambientColor + k_{diffuse} * (N \cdot L) * diffuseColor + k_{specular} * (R \cdot V)^n * specularColor</math>.
In Phong shading, the color is computed in the fragment shader where normals are interpolated between vertices from being passed by the vertex shader.


==More Terms==
==More Terms==