07 Shading 着色

解决遮挡(Visibility)与着色的问题———Z-buffering
Blinn-Phong Reflection Model
现在只针对于一个点的着色

1.Painter’s Algorithm

  • 遮挡和覆盖overwrite
  • 但是对于物体,填充顺序是个问题
  • nlog(n)

2.Z-Buffer 深度缓存,n triangle

  • idea :存储min.z-value, for every pixel
    • Frame buffer
    • Depth buffer
  • Algorithm 维护当前看到的最浅深度的信息
    • initialize depth buffer to infinity
    • zbuffer[x,y] denotes the screen’s pixel buffer
    • framebuffer[x,y] denotes the information(r,g,b) of the pixel
    • for(every triangle)
      • for(every sample(x,y,z)in Triangle)
        • if(z<zbuffer[x,y])
          • framebuffer[x,y]= rgb of sample
          • zbuffer[x,y]= z
  • Time Complexity= o(n), but cost more space of zbuffer

3. Shading 着色

(Blinn-Phong Reflectance Model) 弄成不同材质

  1. Perceptual Observation 感知观察,三类不同的光
    1. Specular highlights 高光
    2. Diffuse reflection 漫反射
    3. Ambient lighting 环境光照
  2. Shading is Local(局部)
    1. copute light at a specific shading point
    2. inputs:
      • viewer direction, v
      • surface normal, n 法向量
      • Light direction, I
      • surface parameters, like color shiness, etc.
    3. well, no shadow will be generated.(shading $\neq$ shadow)
  3. Diffuse Reflection 漫反射的散射和吸收,对局部光照来说,对四面八方的反射一样
    1. Lambert’s cosine law: $cos\theta =<I,n>$光通量: $\Phi =S*cos\theta$
    2. Light Falloff 光衰减: 距离的平方反比
    3. Lambertian Diffuse Shading: $L_d = k_d (I/r^2)max(0,<n,l>)$ ( $k_d$ is diffuse coefficient(color))