08 Shading 着色

Blinn-Phong Reflection Model
  1. Specular highlights Term 高光
    1. Intensity depends on view direction
      • Bright near mirror reflection direction
    2. V close to mirror direction <–> half vector near normal(h)
      • Measure “near” by dot productof unit vectors
    3. Formula: $L_s = k_s(I/r^2)max(0,<n,h>)^p$
      • What is the p in $max(0,<n,h>)^p$ for? Make it real:
        • If $\alpha $ is too big, $<n,h>^p$ is small.
  2. Ambient Term 环境光照
    • Assumption: Shading that does not depend on anything
      • Add constant color to account for disregarded
        illumination and fill in black shadows
      • This is approximate / fake !
    • Formula: $L_a=k_aI_a$
  3. Blinn-Phong Reflection Model:
    • $L=L_a+L_d+L_s$

Shading Frequencies 着色频率

  • Shade each triangle (flat shading)
    • Flat shading
      • Triangle face is flat — one normal vector
      • Not good for smooth surfaces
  • Shade each vertex (Gouraud shading)
    • Gouraud shading
      • Interpolate colors from vertices across triangle
      • Each vertex has a normal vector (how?)
  • Shade each pixel (Phong shading)
    • Phong shading
      • Interpolate normal vectors across each triangle
      • Compute full shading model at each pixel
      • Not the Blinn-Phong Reflectance Model
  1. Defining Per-vertex Normal vectors 怎么定义逐顶点法线
    • Simple scheme: average surrounding face normals
    • Formula: 法向量加权平均 $ n_v=\frac{s_i\times \sum_iN_i}{||\sum_iN_i||}$
  2. Defining Per-Pixel Normal vectors 怎么定义逐像素法线
    • Barycentric interpolation (introducing soon) of vertex normals

Graphics (Real-time Rendering) Pipeline 实时渲染管线

What is it?

graph LR
A(Application) -.Vertex Stream.-> B(Vertex Processing)
B -.Triangle Stream.-> C(Triangle Processing)
C -.Fragment Stream.-> D(Rasterization)
D -.Shaded Fragments.-> E(Fragment Processing)
E --> F(Display)

Shader Programs, How it works for a pixel/fragment/vertex

Texture Mapping 纹理映射

  • Surface are 2D, texture is a graph
  • 每个模型上的点对应纹理上的坐标(u,v),一般都映射成0~1