Shading Models
Shading determines the color of surfaces based on lighting, material properties, and viewing direction. Different shading techniques trade quality for performance.
Flat Shading
Each polygon is assigned a single color computed from its face normal. Simple and fast, but produces visible polygon boundaries.
Flat Shading:
1. Compute face normal: n = (V1-V0) × (V2-V0)
2. Compute lighting once per face
3. All pixels in the face get the same color
+--------+ +--------+
| color1 | | color1 | Entire face
| color1 | | color1 | same color
| color1 | | color1 |
+--------+ +--------+
Pros: Fast
Cons: Faceted appearance
Gouraud Shading
Computes lighting at each vertex, then interpolates colors across the triangle. Produces smooth gradients but can miss specular highlights.
Gouraud Shading:
1. Compute normal at each vertex (average adjacent faces)
2. Compute color at each vertex using lighting model
3. Interpolate colors across triangle using barycentric coords
V0(color0)---------V1(color1)
\ \
\ interpolated \
\ colors \
\ \
V2(color2)-------------------
Color at pixel P:
C(P) = λ0*C(V0) + λ1*C(V1) + λ2*C(V2)
Pros: Smooth appearance, moderate cost
Cons: Misses per-pixel highlights
Phong Shading
Interpolates normals across the triangle and computes lighting at each pixel. Produces the most accurate highlights but is computationally expensive.
Phong Shading:
1. Compute normal at each vertex
2. Interpolate normals across triangle:
n(P) = λ0*n(V0) + λ1*n(V1) + λ2*n(V2)
3. Compute lighting at each pixel using interpolated normal
V0(n0)-------------V1(n1)
\ \
\ interpolated \
\ normals \
\ \
V2(n2)-------------------
For each pixel: compute lighting with local normal
Pros: Best visual quality, accurate highlights
Cons: Most expensive per pixel
Comparison
Method | Per-Vertex | Per-Pixel | Quality | Speed
------------|-----------|-----------|---------|------
Flat | No | No | Low | Fastest
Gouraud | Yes | No | Medium | Medium
Phong | Yes | Yes | High | Slowest
Note: "Phong shading" ≠ "Phong reflection model"
- Phong shading = interpolation technique
- Phong reflection = lighting calculation