Skip to content
Advertisement

Phong and Gouraud Shading WebGL

I read that that in Gouraud Shading, the color for the fragment is computed in the Vertex Shader. Whereas, in Phong Shading, the color for the fragment is computed in the Fragment Shader.

In this implementation , which of these are we using ?

I did not understand exactly the difference between them. Could anyone help me ? Thanks

JavaScript

Advertisement

Answer

I did not understand exactly the difference between them. Could anyone help me ?

The technique used in the code snippet of the question is Gouraud Shading.

In common Phong shading means the technique, which does the light calculations per fragment, in compare at Gouraud Shading, the light calculations ar done per vertex.

This means that at Phong shading the light calcualtions ar done in the fragment shader (Not to be confused with Phong reflection model).

Phong shading:
phong

At Gouraud Shading the light calculations are done in the vertex shader, for the corners of the primitives (corners of the triangles). The calculated light is (either in a perspective correct manner or linearly) interpolated for all the fragments covered by the primitive, according to the Barycentric coordinate. This increases the performance, but gives a big loss of quality, especially on large primitives and strong specular highlights.

Gouraud Shading:
gouraud

Note, the light is not linear distributed on a surface. If the light is only calculated for some samples and interpolated in between them, this causes flat stains.

See the example, which compares the 2 techniques:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement