games101-note-L7 Shading1 (Illumination, Shading and Graphics Pipeline)

Z-Buffer

记录每个像素的当前最近距离,初始距离为∞

在判断绘制时,如果当前的距离 < 深度缓存中该像素的最近距离,就绘制该像素,并更新深度缓存中的最近距离。

This is the algorithm that eventually won.
Idea:
• Store current min. z-value for each sample (pixel)
• Needs an additional buffer for depth values

  • frame buffer stores color values
  • depth buffer (z-buffer) stores depth

IMPORTANT: For simplicity we suppose
z is always positive (smaller z -> closer, larger z -> further)

Z-Buffer

Complexity 复杂度
• O(n) for n triangles (assuming constant coverage)
• How is it possible to sort n triangles in linear time?

Drawing triangles in different orders?

和三角形绘制顺序没有关系

Most important visibility algorithm
• Implemented in hardware for all GPUs

Q&A:
对于MSAA来说,每一个采样点都会利用Z-Buffer进行判断
对于透明的物体而言,需要特殊处理

Shading 着色

Shading:The process of applying a material to an object

Blinn-Phong Reflectance Model

Compute light reflected toward cameraat a specific shading point

Inputs:

• Viewer direction, v

• Surface normal, n

• Light direction, l (for each of many lights)

• Surface parameters (color, shininess, …)

此处没有生成阴影(shadow)shading ≠ shadow

Diffuse Reflection

• Light is scattered uniformly in all directions

–Surface color is the same for all viewing directions

Diffuse Reflection

• But how much light (energy) is received?

–Lambert’s cosine law

Lambert’s cosine law

Lambertian (Diffuse) Shading

Lambertian (Diffuse) Shading

为什么要使用max?

当向量点乘为负数的时,没有物理意义,对亮度没有贡献。

漫反射系数:

kd = 0 完全吸收

kd = 1 完全不吸收