Surface Normals and Phong Shading Explanation
How Surface Normals are Obtained:
The surface normals are loaded from the OBJ file. The OBJ file contains vertex normals (vn lines) that are specified per vertex. These normals are passed through the vertex shader and interpolated across each triangle face during rasterization.
How Normals are Used:
In the vertex shader, normals are transformed to world space using the model matrix (without translation). In the fragment shader, the interpolated normals are normalized and used to calculate lighting using the Phong illumination model:
- Ambient: baseColor × kd × La (with ka = kd)
- Diffuse: baseColor × kd × max(N·ωi, 0) × Le
- Specular (Phong): (1,1,1) × ks × max(ωr·ωo, 0)s × Le, with reflection ωr = 2(ωi·N)N − ωi and ωo toward the viewer
Surface Smoothness and Triangle Meshes:
The smoothness of the rendered surface depends on how normals are defined. When normals are interpolated per-vertex (as in this teapot), the GPU interpolates them across faces, creating smooth shading even though the mesh is made of flat triangles. This is called Phong shading or smooth shading.
If we used face normals (one normal per triangle) instead, each triangle would appear flat with visible edges, creating a faceted look. The vertex normal approach gives the illusion of a curved surface from a polygonal mesh.