generated from cotes2020/chirpy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create "GAMES101 第7讲 着色(Blinn-Phong反射模型, 漫反射)"
- Loading branch information
1 parent
9dd23bb
commit 80b3923
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
title: GAMES101 第7讲 着色(Blinn-Phong反射模型, 漫反射) | ||
date: 2024-12-05 21:17:00 +0800 | ||
categories: [笔记, GAMES101] | ||
tags: [GAMES101, 计算机图形学] | ||
math: true | ||
--- | ||
|
||
## 着色的定义 | ||
|
||
**着色(Shading)** 在计算机图形学中, 指的是对不同物体应用不同材质的过程. | ||
|
||
## Blinn-Phong 反射模型 | ||
|
||
![Blinn-Phong的三个分量](/assets/posts/GAMES101-Lecture07/01.png){:width="400px"} | ||
|
||
- **高光(Specular Highlights)**: 比较光滑的物体表面, 会出现类似镜面反射的效果, 反射颜色较亮 | ||
- **漫反射(Diffuse Reflection)**: 光线击中物体表面后, 会均匀地反射到各个方向, 一般是物体表面颜色变换不明显的部分 | ||
- **环境光(Ambient Lighting)**: 在不能被光源直接照射到的区域, 由于光线的多次反射, 会有一些光线被反射到这些区域, 使得这些区域不会完全黑暗 | ||
|
||
### Shading Point 着色点 | ||
|
||
计算反射到相机的光线颜色时, 是在物体表面上的一个点上进行计算的, 这个点称为**着色点(Shading Point)**. | ||
|
||
着色点的参数有: | ||
- **观测点方向(Viewer Direction)**: 从着色点指向相机的方向, 一般用 $v$ 表示 | ||
- **表面法线(Surface Normal)**: 与表面垂直的方向, 一般用 $n$ 表示 | ||
- **光源方向(Light Direction)**: 从着色点指向光源的方向, 一般用 $l$ 表示, 每个光源都有一个光源方向 | ||
- **表面参数(Surface Parameters)**: 用于计算颜色的参数, 例如颜色, shininess(高光的锐度)等 | ||
|
||
> **着色有局部性**: 着色(Shading)不等于阴影(Shadow), 不会生成阴影, 只是计算光线反射到相机的颜色 | ||
## 漫反射 | ||
|
||
### 漫反射的原理 | ||
|
||
当一个光线击中物体表面时, 会均匀地反射到各个方向, 这种反射称为**漫反射(Diffuse Reflection)**. | ||
|
||
![漫反射](/assets/posts/GAMES101-Lecture07/02.png){:width="400px"} | ||
|
||
如上图中, 当光线与物体表面成角度时, 不同角度下的光线产生的明暗程度不同, 一般来说, 光线与表面法线的夹角越小, 反射光线越亮. | ||
|
||
这是因为, 假设光照可以分解成多个光线, 每根光线都有一定的能量, 当光线垂直于表面时, 物体表面单位面积下会接收到更多的光线, 反射的光线也会更亮; 当物体旋转一定的角度后, 单位面积接受到的光线会减少, 因此反射的光线也会变暗. (如下图) | ||
|
||
![漫反射](/assets/posts/GAMES101-Lecture07/03.png){:width="500px"} | ||
|
||
将此过程推广到数学上, 可以得到: 光源方向 $l$ 和表面法线 $n$ 的夹角 $\theta$ 越小, 反射光线的亮度越高. | ||
|
||
![漫反射公式](/assets/posts/GAMES101-Lecture07/04.png){:width="300px"} | ||
|
||
### Light Falloff 光线衰减 | ||
|
||
光线在空间中传播时, 会随着距离的增加而衰减, 这种现象称为**光线衰减(Light Falloff)**. | ||
|
||
因为由于能量守恒, 从光源发出的总能量是一定的, 但是距离光源越远, 光照所覆盖的面积就越大, 因此单位面积接收到的光线就会减少: | ||
|
||
![光线衰减](/assets/posts/GAMES101-Lecture07/05.png){:width="500px"} | ||
|
||
光线衰减的公式一般为: | ||
|
||
$$ | ||
\text{Intensity} = \frac{Light}{\text{Distance}^2} | ||
$$ | ||
|
||
### Lambertian (Diffuse) Shading | ||
|
||
**Lambertian 漫反射模型**是最简单的漫反射模型, 它不依赖于观察方向, 只依赖于光源方向和表面法线: | ||
|
||
$$ | ||
L_d=k_d\left(I/r^2\right)\max(0,\mathbf{n}\cdot\mathbf{l}) | ||
$$ | ||
|
||
- $L_d$: 漫反射光线的颜色 | ||
- $k_d$: 漫反射系数 | ||
- $I$: 光源在单位面积上的光照强度 | ||
- $r$: 光源到着色点的距离 | ||
- $\mathbf{n}$: 表面法线 | ||
- $\mathbf{l}$: 光源方向 | ||
|
||
**漫反射系数 $k_d$** 是一个常数, 物体吸收一部分光线, 反射一部分光线, 因此需要一个系数来表示被吸收过光线后的反射光线的强度变化. | ||
|
||
![漫反射系数的变化](/assets/posts/GAMES101-Lecture07/06.png){:width="700px"} | ||
|
||
**$\max(0,\mathbf{n}\cdot\mathbf{l})$**: 当两个点乘的结果小于0时, 即光线从表面的下方照射到表面上时, 没有物理意义, 因此取0 | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.