4
$\begingroup$

When I flip between flat and smooth shading, I see that the vertex normals flip between n vertices for n meeting faces and single (averaged) normal. Once the vertex normals are deduced, how're objects with Smooth Shading rendered? I'm interested in the shading algorithm/interpolation model (Phong, Gouraud, etc.) than the illumination model (like Blinn-Phong, etc.) used. When smooth shading, are lighting calculations done per-vertex or per-fragment?

I'm a graphics programmer (OpenGL) who recently started learning Blender. I'd like to understand how Blender works under the hood for better understanding.

I searched in the manual but couldn't find anything regarding this, understandably. The Blender 3D Wikibook says Phong while an answer here says Gouraud.

When flat shading, the usual technique is to just shade the entire tri or quad with one lighting calculation performed with the face normal. I hope this holds true with Blender too.

$\endgroup$
7
  • 1
    $\begingroup$ Hey there! In case you didn't know, Blender is also open-source, so you can take a look at its source code to see how it does smooth shading. $\endgroup$
    – Najm Hoda
    Jun 12, 2020 at 17:15
  • $\begingroup$ Here is the source code for Blender: developer.blender.org/diffusion/B $\endgroup$
    – Najm Hoda
    Jun 12, 2020 at 17:22
  • $\begingroup$ Thanks for the tip :) Yes, reading the code is an option, while having someone (with context) explain it to you is a lot better. However, I'd do this if we don't get any answers. Thanks! $\endgroup$
    – legends2k
    Jun 12, 2020 at 17:49
  • $\begingroup$ I assume you want a pointer to the code in question. What engine are you asking for workbench, Eevee or Cycles? $\endgroup$
    – Robert Gützkow
    Jun 12, 2020 at 21:45
  • $\begingroup$ @Robert The viewport renderer; not sure of its name though. Is that the one called workbench? $\endgroup$
    – legends2k
    Jun 13, 2020 at 2:14

2 Answers 2

2
$\begingroup$

As phong uses interpolated vertex normals this is the method used checking the docs of the source code.

source: https://github.com/blender/blender/blob/01a2bd03695f217616acc2581fe8746f5cd226d7/scripts/modules/bpy_types.py#L672

def shade_smooth(self):
        """
        Render and display faces smooth, using interpolated vertex normals,
        removing the "sharp_face" attribute
        """
        _name_convention_attribute_remove(self.attributes, "sharp_face")
$\endgroup$
3
$\begingroup$

"Phong" and "Gouraud" are not always used consistently between sources. If we consider Phong shading to be a shading algorithm where the interpolation of vertex normal is used to light fragments, and Gouraud shading to be a shading algorithm where the interpolation of vertex lighting is used to light fragments, then Workbench uses Phong shading.

We can see this by looking at the specular highlight of a smooth shaded object in Workbench:

enter image description here

The vertices of this smooth shaded cube are all darker than the specular highlight in the middle of the face. That highlight cannot be created by interpolation of vertex lighting. As a comparison with Gouraud shading, you can see the demonstration of specular artifacts at https://en.wikipedia.org/wiki/Gouraud_shading .

As for how we get that fragment normal, it is the renormalized weighted average of vertex normals of its (triangulated) face's vertices. The weights are the barycentric coordinates of the fragment. If we'd like, we can see these coordinates by using a geometry/parametric node in a shader.

$\endgroup$
1
  • $\begingroup$ Agree with the inconsistent usage of the term; it's why I'd used different terms in my question: interpolation model (where/how many calculations are done) vs illumination model (calculations made at each unit to arrive at a colour). $\endgroup$
    – legends2k
    Nov 22, 2023 at 4:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .