2
$\begingroup$

I'm a super beginner to GFX. So far I've learned about 3 shading models when rendering meshes The first is Flat Shading. I seem to understand this, from my understanding, you take the normal of the face/polygon, apply your lighting model based on that, and the light angle, and other parameters and based on what you get, shade your polygon with a single color, done.

I've learned about Phong Shading as well. Apparently Phong Shading takes the normals of the vertices of the polygon, and interpolates them for each pixel, thus sort of 'creating' a normal per every pixel, and shade accordingly. It is shaded per pixel, and as such you get smooth results

Gouraud shading is what I am most confused by. I referred to many online sources including this one and what I dont understand is how exactly the polygon is shaded? Is it shaded per pixel?

From my understanding, Gouraud is the same as Phong shading except that unlike Phong interpolating vertex normals, and creates normals for every pixel and shading each pixel, Gouraud interpolates just the vertex normals of the polygon.

Im not quite sure what it does after that. Does it take these interpolated vertex normals and shade the polygon in a single color? Does it shade pixel by pixel just like Phong?

$\endgroup$
2
$\begingroup$

The difference is in the number of lighting calculations done. Where the lighting calculation produces some color.

Flat does one per face, uses the color across the face.

Gourand does 3 (for a triangle, one for each vertex), interpolates the color across the face.

Phong does a light calculation for every pixel/fragment (where the normal is interpolated across the face).

enter image description here

$\endgroup$
5
  • $\begingroup$ So essentially gouraud calculates a color at 3 points and interpolates each of those 3 colors together for each pixel making up the image of the triangle? $\endgroup$
    – Hash
    Apr 25 at 19:25
  • $\begingroup$ Yup, with barycentric coordinates color = u * postLitColorV1 + v * postLitColorV2 + w * postLitColorV3. You can often tell when the triangles are large. I added an image. So you can see the differences in the specular highlight, bright where the normal is perpendicular to the viewing angle. In gourand this would only be at that one vertex, but in phong the normal is smoothly interpolated across the face $\endgroup$ Apr 25 at 21:39
  • $\begingroup$ What exactly does postLitColor mean here and what is a Barycentric coordinate mean in this context? Ive tried reading into the latter, and Im quite not able to grasp it and how it gives us the triangle color And to make sure, Phong : Calculates per pixel, shades each pixel, Gouraud : Calculates 3 vertices, shades each pixel after interpolating them based on their distance to the 3 vertices right? $\endgroup$
    – Hash
    Apr 26 at 15:07
  • $\begingroup$ postLitColor refers to the color obtained from the lighting equation at that particular vertex, since that is the only time the lighting model is evaluated in Gouraud shading. Once you have the color values for the three vertices, you can linearly interpolate them for any point inside the triangle using a local coordinate system (u,v,w) where V1=(1,0,0), V2=(0,1,0) and V3=(0,0,1). The Wikipedia article on Barycentric coordinates has a section on triangular coordinates and conversion to/from Cartesian coordinates. $\endgroup$ Apr 26 at 18:30
  • $\begingroup$ A simple example of a possible light equation would be postLitColor= diffuseColor * dot(lightDir, normal(x)), where diffuseColor is a constant set by you, lightDir is a 3 component vector giving a directional light, and normal(x) evaluates the normal of the surface at x. $\endgroup$ Apr 26 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.