SlideShare a Scribd company logo
基於圖像的光照
Image based lighting
Sigma Lin
Contents
• Physically based rendering
• Rendering equation
• Bidirectional Reflectance Distribution Function
• Normalized Lambert
• Cook-Torrance Model
• Image based lighting
• Spherical Coordinates
• Monte Carlo method
• Importance sampling
• Low-discrepancy sequence
• Tone Mapping
• Result
• Running in Unity3D
Physically Based Rendering
• 光的計算,是基於物體的物理根據,使用反射模型來生成。
• 使用的反射模型,滿足能量守恆的條件。
• 物體材質球的參數,是根據物體特性而設定。
Rendering Equation
𝐿 𝑜 𝑥, 𝜔 𝑜, λ, 𝑡 = 𝐿 𝑒 𝑥, 𝜔 𝑜, λ, 𝑡 +
𝛺
𝑓𝑟 𝑥, 𝜔𝑖, 𝜔 𝑜, λ, 𝑡 𝐿𝑖(𝑥, 𝜔𝑖, λ, 𝑡)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖
• 𝐿 𝑒(𝑥, 𝜔 𝑜, λ, 𝑡) 自發光 (emitter)
• 𝑓𝑟(𝑥, 𝜔𝑖, 𝜔 𝑜, λ, 𝑡) bidirectional reflectance distribution function
• λ 光的波長
• t 時間
• 𝑥 渲染位置
• 𝜔𝑖 入射光向量
• 𝜔 𝑜 反射光向量
• 𝑛 法線向量
• 𝛺
半球積分
半球積分
• 放大渲染位置 x , x 在一個平面上
• 平面上的點 x ,來源光線的可能方向涵蓋整個半圓形
• 考慮 x 點的所有受光
Rendering Equation(簡化版)
𝐿 𝑜 𝑥, 𝜔 𝑜 = 𝑓𝑟(𝑥, 𝜔𝑖, 𝜔 𝑜)𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛)
• 只考慮單一方向光源
• 渲染物體不會發光
• 不考慮時間、氣候等現實因素
反射光
• Specular : 鏡面反射,也有人稱作 Highlight(高光),接觸到
物體後直接反射。
• Diffuse : 擴散反射,和 Specular 不同的地方在於接觸到物
體後,會進入到物體內部,然後在物體內部繼續反射,直
到離開物體。
• 兩者的差別就是有沒有進入物體內。
圖片引用來源: Wes McDermott「The Comprehensive PBR Guide by Allegorithmic - vol. 1 Light and Matter :
The theory of Physically-Based Rendering and Shading」©Allegorithmic
Reflectance
• 物體反射的 radiant energy (輻射能量) 佔總 radiant energy
的百分比
• 解釋了 Diffuse 和 Specular 的關係,Reflectance 越高,
Specular 越強。
資料來源 wikipedia
Unity Approximation
• 查表去計算每個物體的 Reflectance 是不實際的
• Unity 使用 metallic (金屬度) 作為求得 Reflectance 近似值的
參數
• 物體依照其物理特性可以區分成
• Dielectric 導電體,metallic = 0
• Insulator 絕緣體,metallic = 1
• 導電體的 IOR 在 1.3 ~ 1.7,取平均值 1.5
𝑅 =
(1−1.5)2
(1+1.5)2 = 0.04
𝑅 𝑈𝑛𝑖𝑡𝑦 𝐴𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 = 𝑙𝑒𝑟𝑝(0.04,1, 𝑚𝑒𝑡𝑎𝑙𝑙𝑖𝑐)
Schlick’s Approximation
𝐹𝜃 ≈ 𝐹0 + (1 − 𝐹0)(1 − cos 𝜃)5
Rendering Equation(簡化版2)
𝐿 𝑜 𝑥, 𝜔 𝑜 = 𝑓𝑟 𝑥, 𝜔𝑖, 𝜔 𝑜 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛
= 𝑘 𝑑 𝑓𝑑 + 𝑘 𝑠 𝑓𝑠 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛
= 𝑘 𝑑 𝑓𝑟𝑑 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛 + 𝑘 𝑠 𝑓𝑟𝑠 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛
• 𝑘 𝑑 光線接觸到物體的折射率
• 𝑘 𝑠 光線接觸到物體的反射率
• 𝑘 𝑑 + 𝑘 𝑠 = 1
• 𝑓𝑟𝑑 Diffuse 的 BRDF
• 𝑓𝑟𝑠 Specular 的 BRDF
Diffuse BRDF
• 使用 Lambert
圖片來源: Brian Karis, "Real Shading in Unreal Engine 4" SIGGRAPH 2013
Normalized Lambert
• 遵守能量守恆
• Lambert’s cosine law
• 𝛺
cos 𝜃 ⅆ𝜔 = 𝜋
• 𝐵𝑅𝐷𝐹𝐿𝑎𝑚𝑏𝑒𝑟𝑡 =
𝐶
𝜋
• C = Albedo
Specular BRDF
• Cook-Torrance Model
• 𝑓𝑟𝑠 𝑥, 𝜔𝑖, 𝜔 𝑜 =
𝐷𝐺𝐹
4(𝑛∙𝜔 𝑜)(𝑛∙𝜔 𝑖)
• D : Microfacet Distribution Fuctions
• G : Masking-Shadowing Fuctions
• F : Fresnel
Microfacet Model
• 模擬物體表面崎嶇程度
• 使用變數 roughness (粗糙度) 控制
• 參考 [Burley 2012] 設定
• Roughness 值域在 [0,1]
• 將 Roughness 分成兩個部分
• Perceptual roughness,美術人員控制效果用的參數
• Alpha roughness ,實際運算使用的參數
• 𝑅𝑜𝑢𝑔ℎ𝑛𝑒𝑠𝑠 𝑎𝑙𝑝ℎ𝑎 = (𝑅𝑜𝑢𝑔ℎ𝑛𝑒𝑠𝑠 𝑝𝑒𝑟𝑐𝑒𝑝𝑡𝑢𝑎𝑙)2
Specular Distribution
• 使用 Trowbridge-Reitz model
• 𝐷 ℎ =
𝑋+(𝑛∙ℎ)𝛼2
𝜋( 𝑛∙ℎ
2
𝛼2−1 +1)2
• 𝑋+
(𝑛 ∙ ℎ) 𝑖𝑓 𝑛 ∙ ℎ ≤ 0, 𝑟𝑒𝑡𝑢𝑟𝑛 0
𝑒𝑙𝑠𝑒 𝑟𝑒𝑡𝑢𝑟𝑛 1
• ℎ ∶ ℎ𝑎𝑙𝑓 𝑣𝑒𝑐𝑡𝑜𝑟
• 𝑛 ∶ 𝑛𝑜𝑟𝑚𝑎𝑙 𝑣𝑒𝑐𝑡𝑜𝑟
• 𝛼 ∶ 𝑎𝑙𝑝ℎ𝑎 𝑟𝑜𝑢𝑔ℎ𝑛𝑒𝑠𝑠
Geometric shadowing
• 使用 Schlick 提出的 Smith Model 近似法
• 𝐺𝑆𝑐ℎ𝑙𝑖𝑐𝑘 𝑣 =
𝑛∙𝑣
𝑛∙𝑣 1−𝑘 +𝑘
• 𝑘 = 𝛼
2
𝜋
• 考慮 masking 和 shadowing
• 𝐺𝑆𝑚𝑖𝑡ℎ 𝑙, 𝑣, ℎ = 𝐺𝑆𝑐ℎ𝑙𝑖𝑐𝑘 𝑙 𝐺𝑆𝑐ℎ𝑙𝑖𝑐𝑘 𝑣
• 𝑙 ∶ 𝑙𝑖𝑔ℎ𝑡 𝑣𝑒𝑐𝑡𝑜𝑟
• 𝑣: 𝑣𝑖𝑒𝑤 𝑣𝑒𝑐𝑡𝑜𝑟
單一方向光源 PBR
Metallic = 0 時, roughness 由左至右遞增
Metallic = 1 時, roughness 由左至右遞增
補充(1)
• Cook-Torrance Model
• 𝑓𝑟𝑠 𝑥, 𝜔𝑖, 𝜔 𝑜 =
𝐹
𝜋
𝐷𝐺
(𝑛∙𝜔 𝑜)(𝑛∙𝜔 𝑖)
[Cook and Torrance 1982]
• 𝑓𝑟𝑠 𝑥, 𝜔𝑖, 𝜔 𝑜 =
𝐷𝐺𝐹
4(𝑛∙𝜔 𝑜)(𝑛∙𝜔 𝑖)
[Walter et al. 2007]
補充(2)
• 𝑓𝑟𝑠(𝑥, 𝜔𝑖, 𝜔 𝑜) = 𝐷𝑉𝐹
• 𝑉 =
𝐺
4(𝑛∙ 𝑙)(𝑛∙𝑣)
間接光
• 𝛺
𝑓𝑟(𝑥, 𝜔𝑖, 𝜔 𝑜)𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔
• 計算龐大,不適合run-time處理
Image Based Lighting
• 實現環境光照的一種作法
• 將環境光源資料儲存在一張影像內(通常為 Cubemap),在
渲染時從影像取得光線資料做處理
• 參考 [Karis 2013] 內容實作
Requirements
• Spherical Coordinates
• Monte Carlo method
• Importance sampling
• Low-discrepancy sequence
• Tone Mapping
Spherical Coordinates
• 使用三個參數代表座標 (𝛾, 𝜃, 𝜑)
• 𝛾 表示原點到座標的距離, 𝛾 ≥ 0 ,因為反射光使用單位向量,
可省略。
• 𝜃 表示和 Z 軸的夾角,0 ≤ 𝜃 ≤ 𝜋,但反射光在 hemisphere 內,
0 ≤ 𝜃 ≤
𝜋
2
• 𝜑 表示在 X-Y 平面上和 X 軸的夾角,0 ≤ 𝜑 ≤ 2𝜋
• 對應到三維座標 𝑋, 𝑌, 𝑍 為
• X = 𝛾 ∗ sin 𝜃 ∗ cos 𝜑
• Y = 𝛾 ∗ sin 𝜃 ∗ sin 𝜑
• Z = 𝛾 ∗ cos 𝜃
Monte Carlo Method
• 求 f(𝑥) 積分
Monte Carlo Estimator (1)
• 𝑎
𝑏
𝑓(𝑥) ⅆ𝑥 ≈
𝑏−𝑎
𝑁 𝑖=1
𝑁
𝑓(𝑥𝑖)
• 證明
• 計算期望值
• E
𝑏−𝑎
𝑁 𝑖=1
𝑁
𝑓(𝑥𝑖)
• =
𝑏−𝑎
𝑁 𝑖=1
𝑁
𝐸 𝑓(𝑥𝑖)
• = 𝑏 − 𝑎 𝑎
𝑏
𝑓 𝑥 𝑝ⅆ𝑓 𝑥 ⅆ𝑥
• = 𝑏 − 𝑎 𝑎
𝑏 𝑓 𝑥
𝑏−𝑎
ⅆ𝑥 = 𝑎
𝑏
𝑓 𝑥 ⅆ𝑥
• pdf(x) : x 點上的 probability density function
• 當每個樣本的 pdf 都一樣,算式成立
• Law of large numbers
• 取樣數越多,結果越接近期望值
Monte Carlo Estimator (2)
• 𝑎
𝑏
𝑓(𝑥) ⅆ𝑥 ≈
1
𝑁 𝑖=1
𝑁 𝑓(𝑥 𝑖)
𝑝𝑑𝑓(𝑥 𝑖)
• 證明
• 計算期望值
• E
1
𝑁 𝑖=1
𝑁 𝑓(𝑥)
𝑝𝑑𝑓(𝑥 𝑖)
• =
1
𝑁
𝐸 𝑖=1
𝑁 𝑓(𝑥 𝑖)
𝑝𝑑𝑓(𝑥 𝑖)
• =
1
𝑁 𝑖=1
𝑁
𝑎
𝑏 𝑓 𝑥
𝑝𝑑𝑓 𝑥
𝑝ⅆ𝑓 𝑥 ⅆ𝑥
• =
1
𝑁 𝑖=1
𝑁
𝑎
𝑏
𝑓(𝑥) ⅆ𝑥 = 𝑎
𝑏
𝑓(𝑥) ⅆ𝑥
• 多元積分
• 𝑓(𝑥, 𝑦) ⅆ𝑥 ⅆ𝑦 ≈
1
𝑁 𝑖=1
𝑁 𝑓(𝑥 𝑖,𝑦 𝑖)
𝑝𝑑𝑓 𝑥 𝑖 𝑝𝑑𝑓(𝑦 𝑖)
Importance sampling (1)
• Monte Carlo Method
• 𝑎
𝑏
𝑓(𝑥) ⅆ𝑥 ≈
1
𝑁 𝑖=1
𝑁 𝑓 𝑥 𝑖
𝑝𝑑𝑓 𝑥 𝑖
=
1
𝑁
(
𝑓 𝑥1
𝑝𝑑𝑓 𝑥1
+
𝑓 𝑥2
𝑝𝑑𝑓 𝑥2
+ ⋯ +
𝑓(𝑥 𝑁)
𝑝𝑑𝑓(𝑥 𝑁)
)
•
𝑓(𝑥 𝑖)
𝑝𝑑𝑓(𝑥 𝑖)
→ 0
• 忽略影響低的樣本,只取影響高的樣本
• 𝑓(𝑥)和 𝑝ⅆ𝑓(𝑥) 分布形狀越接近,可使用越少的樣本數逼
近真實結果。
圖片來源 : Wojciech Jarosz's Dissertation Appendix A
Importance sampling (2)
• 找出影響最大的反射光,作為積分樣本
Importance sampling GGX
• 𝑓𝑟𝑠 𝑥, 𝜔𝑖, 𝜔 𝑜 =
𝐷𝐺𝐹
4(𝑛∙𝜔 𝑜)(𝑛∙𝜔 𝑖)
• 可從 D 項計算出法線分布,求得反射光方向
• 找出 D 項的 Importance sampling function
• Inverse transform sampling
Inversion method
• 𝐷 ℎ =
𝛼2 cos 𝜃 sin 𝜃
𝜋 (𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2
• 𝑝ⅆ𝑓: 𝑝ℎ 𝜃, 𝜑 =
𝛼2 cos 𝜃 sin 𝜃
𝜋( 𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2 [Walter et al. 2007]
• 𝑚ⅆ𝑓: 𝑝ℎ 𝜃 = 0
2𝜋
𝑝ℎ(𝜃, 𝜑) ⅆ𝜑 =
2𝛼2 cos 𝜃 sin 𝜃
( 𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2
• 𝑝ℎ 𝜑 𝜃 =
𝑝ℎ(𝜃,𝜑)
𝑝ℎ(𝜃)
=
𝛼2 cos 𝜃 sin 𝜃
𝜋( 𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2
2𝛼2 cos 𝜃 sin 𝜃
( 𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2
=
1
2𝜋
• 𝑐ⅆ𝑓 𝑃ℎ 𝜃 = 0
𝜃 2𝛼2 cos 𝑡 sin 𝑡
(𝑐𝑜𝑠2 𝑡 𝛼2−1 +1)2 ⅆ𝑡
• =
𝛼2
𝑐𝑜𝑠2 𝜃(𝛼2−1)2+(𝛼2−1)
−
1
𝛼2−1
= 𝜉1
• 𝑐ⅆ𝑓 𝑝ℎ 𝜑 𝜃 = 0
𝜑 1
2𝜋
ⅆ𝑡 =
𝜑
2𝜋
= 𝜉2
• 𝜃 = cos−1 1−𝜉1
𝜉1 𝛼2−1 +1
• 𝜑 = 2𝜋𝜉2
WolframAlpha
Low-discrepancy sequence
• 需要一個二維變數 (ξ1, ξ2) 做 Importance Sampling 樣本,求
得法線的(𝜃, 𝜑)
•
• Monte Carlo Method 使用亂數取 N 個樣本
• 收斂速度 O(𝑁−0.5) [Asmussen and Glynn 2007]
• 提升兩倍精度須提供四倍樣本數
• Quasi Monte Carlo Method 使用 Low-discrepancy sequence
取 N 個樣本
• 收斂數度 O
log 𝑁 𝐷𝑖𝑚
𝑁
• 在二維空間,提升兩倍精度只需兩倍樣本數
• 使用 Hammersley Sequence
Hammersley sequency
• 0.1 = 1 ∗ 2−1
= 0.5
• 0.01 = 0 ∗ 2−1
+ 1 ∗ 2−2
= 0.25
• 0.11 = 1 ∗ 2−1
+ 1 ∗ 2−2
= 0.75
• 0.001 = 0 ∗ 2−1
+ 0 ∗ 2−2
+ 1 ∗ 2−3
= 0.125
• ⋮
圖片來源 : Physically Based Rendering - 7.4 The Halton Sampler
Tone mapping
圖片來源:wikipedia
Image Based Lighting
• 𝛺
𝑓𝑟 𝑥, 𝜔𝑖, 𝜔 𝑜 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖
• = 𝛺
(𝑓𝑟𝑑 + 𝑓𝑟𝑠)𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖
• = 𝛺
𝑓𝑟𝑑 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 + 𝛺
𝑓𝑟𝑠 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖
• 拆分成 Diffuse 和 Specular 處理
• Off-line 計算結果,run-time 直接取用
• 使用 HDR 的 Environment map 作為環境光源
• 𝐿𝑖(𝑥, 𝜔𝑖) 來源
IBL - Diffuse
• 使用 Lambert
• 𝛺
𝑓𝑑 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛 ⅆ𝜔𝑖
• = 𝛺
𝑘 𝑑
𝑐
𝜋
𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖
• = 𝑘 𝑑
𝑐
𝜋 𝜑=0
2𝜋
𝜃=0
𝜋
2
𝐿𝑖(𝑥, 𝜔𝑖) cos 𝜃 sin 𝜃 ⅆ𝜑 ⅆ𝜃
• 積分使用 Riemann Sum
圖片來源 LearnOpenGL
IBL - Specular
• 使用 Cook-Torrance Model
• 𝛺
𝑓𝑟𝑠 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖
• = 𝛺
𝑘 𝑠
𝐷𝐹𝐺
4 𝜔 𝑜∙𝑛 𝜔𝑖∙𝑛
𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖
• 兩個變數 𝜔𝑖、𝜔 𝑜,複雜度高。
Split sun approximation
• Monte Carlo Method + importance sampling GGX
• 𝛺
𝑓𝑟𝑠 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖
• ≈
1
𝑁 𝑘=1
𝑁 𝑓𝑟𝑠 𝑙 𝑘 𝐿 𝑖 𝑙 𝑘
𝑝𝑑𝑓 𝑙 𝑘
(𝑙 𝑘 ∙ 𝑛)
• 𝑙 𝑘 使用 importance sampling 取得的反射光樣本
• pdf 𝑙 𝑘 =
𝐷(𝑛∙ℎ)
4(𝑣∙ℎ)
[Karis 2013]
•
1
𝑁 𝑘=1
𝑁 𝑓𝑟𝑠 𝑙 𝑘 𝐿 𝑖 𝑙 𝑘
𝑝𝑑𝑓 𝑙 𝑘
𝑙 𝑘 ∙ 𝑛
• =
1
𝑁 𝑘=1
𝑁 𝐷𝐹𝐺
4 𝑛∙𝑙 𝑘 𝑛∙𝑣
1
𝑝𝑑𝑓 𝑙 𝑘
𝐿𝑖(𝑙 𝑘)(𝑛 ∙ 𝑙 𝑘)
• =
1
𝑁 𝑘=1
𝑁 𝐹𝐺
𝑛∙𝑣 𝑛∙ℎ
(𝑣 ∙ ℎ)𝐿𝑖(𝑙 𝑘)
• ≈ (
1
𝑁 𝑘=1
𝑁 𝐹𝐺
𝑛∙𝑣 𝑛∙ℎ
𝑣 ∙ ℎ ) ∗ (
1
𝑘=1
𝑁
𝑛∙𝑙 𝑘
𝑘=1
𝑁
𝐿𝑖 𝑙 𝑘 𝑛 ∙ 𝑙 𝑘 )
Integral of BRDF (1)
• 𝐺 𝑣𝑖𝑠 =
𝐺
(𝑛∙𝑣)(𝑛∙ℎ)
•
1
𝑁 𝑘=1
𝑁 𝐹𝐺
𝑛∙𝑣 𝑛∙ℎ
(𝑣 ∙ ℎ) =
1
𝑁 𝑘=1
𝑁
𝐹𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ)
• F : Fresnel
• 𝐹𝑐 = (1 − (𝑣 ∙ ℎ))5
• 𝐹 ≈ 𝐹0 + 1 − 𝐹0 1 − 𝑣 ∙ ℎ
5
= 𝐹0 + (1 − 𝐹0)𝐹𝑐
•
1
𝑁 𝑘=1
𝑁
𝐹𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ) =
1
𝑁 𝑘=1
𝑁
(𝐹0 + (1 − 𝐹0)𝐹𝑐)𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ)
• =
1
𝑁 𝑘=1
𝑁
(𝐹0 1 − 𝐹𝑐 + 𝐹𝑐)𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ)
• =
1
𝑁 𝑘=1
𝑁
𝐹0(1 − 𝐹𝑐)𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ) +
1
𝑁 𝑘=1
𝑁
𝐹𝑐 𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ)
• = 𝐹0
1
𝑁 𝑘=1
𝑁
1 − 𝐹𝑐 𝐺 𝑣𝑖𝑠 𝑣 ∙ ℎ + (
1
𝑁 𝑘=1
𝑁
𝐹𝑐 𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ))
Integral of BRDF (2)
• 𝐺𝑠𝑐ℎ𝑙𝑖𝑐𝑘 𝑣 =
𝑛∙𝑣
𝑛∙𝑣 1−𝑘 +𝑘
• 𝑘 = 𝛼
2
𝜋
• 𝑘 =
𝛼
2
[Karis 2013]
𝑛 ∙ 𝑣
roughness
Integral of lighting
•
1
𝑘
𝑁
(𝑛∙𝑙 𝑘) 𝑘
𝑁
𝐿𝑖(𝑙 𝑘)(𝑛 ∙ 𝑙 𝑘)
• 使用 importance sampling GGX 取樣
• 需要從 法線 取得 Environment Map 內的光源資料
• Environment Map 使用 Cubemap,需要反射向量
• 令 normal = view = reflect
• 新增 cos 項作為權重可提升效果
• 將不同 roughness 結果用 mipmap 分開儲存[GPU Gems 3]
圖片來源 LearnOpenGL
效果比較
• 和 Unity standard shader 在 Unity 編輯器做比較
• 比對 metallic = 0 和 = 1 的效果
• Roughness 從左到右遞增
• Unity 使用 smoothness ,smoothness = 1 - roughness
• Prefilter Enviorment map : 512 x 512 Cubmap, 5 mipmap
• BRDF integrate map : 512 x 512 texture2D RGB24
• Diffuse irradiance : 32 x 32 Cubemap
• Environment Map 素材來源 HDRIHaven
Metallic = 0
Metallic = 1
Mobile 展示視頻
• 使用 Sony L3
• ApowerRec 錄製
Future work
• Dual Paraboloid Environment Map
• Cloth

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

基於圖像的光照 Image based lighting

  • 2. Contents • Physically based rendering • Rendering equation • Bidirectional Reflectance Distribution Function • Normalized Lambert • Cook-Torrance Model • Image based lighting • Spherical Coordinates • Monte Carlo method • Importance sampling • Low-discrepancy sequence • Tone Mapping • Result • Running in Unity3D
  • 3. Physically Based Rendering • 光的計算,是基於物體的物理根據,使用反射模型來生成。 • 使用的反射模型,滿足能量守恆的條件。 • 物體材質球的參數,是根據物體特性而設定。
  • 4. Rendering Equation 𝐿 𝑜 𝑥, 𝜔 𝑜, λ, 𝑡 = 𝐿 𝑒 𝑥, 𝜔 𝑜, λ, 𝑡 + 𝛺 𝑓𝑟 𝑥, 𝜔𝑖, 𝜔 𝑜, λ, 𝑡 𝐿𝑖(𝑥, 𝜔𝑖, λ, 𝑡)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 • 𝐿 𝑒(𝑥, 𝜔 𝑜, λ, 𝑡) 自發光 (emitter) • 𝑓𝑟(𝑥, 𝜔𝑖, 𝜔 𝑜, λ, 𝑡) bidirectional reflectance distribution function • λ 光的波長 • t 時間 • 𝑥 渲染位置 • 𝜔𝑖 入射光向量 • 𝜔 𝑜 反射光向量 • 𝑛 法線向量 • 𝛺 半球積分
  • 5. 半球積分 • 放大渲染位置 x , x 在一個平面上 • 平面上的點 x ,來源光線的可能方向涵蓋整個半圓形 • 考慮 x 點的所有受光
  • 6. Rendering Equation(簡化版) 𝐿 𝑜 𝑥, 𝜔 𝑜 = 𝑓𝑟(𝑥, 𝜔𝑖, 𝜔 𝑜)𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) • 只考慮單一方向光源 • 渲染物體不會發光 • 不考慮時間、氣候等現實因素
  • 7. 反射光 • Specular : 鏡面反射,也有人稱作 Highlight(高光),接觸到 物體後直接反射。 • Diffuse : 擴散反射,和 Specular 不同的地方在於接觸到物 體後,會進入到物體內部,然後在物體內部繼續反射,直 到離開物體。 • 兩者的差別就是有沒有進入物體內。 圖片引用來源: Wes McDermott「The Comprehensive PBR Guide by Allegorithmic - vol. 1 Light and Matter : The theory of Physically-Based Rendering and Shading」©Allegorithmic
  • 8. Reflectance • 物體反射的 radiant energy (輻射能量) 佔總 radiant energy 的百分比 • 解釋了 Diffuse 和 Specular 的關係,Reflectance 越高, Specular 越強。 資料來源 wikipedia
  • 9. Unity Approximation • 查表去計算每個物體的 Reflectance 是不實際的 • Unity 使用 metallic (金屬度) 作為求得 Reflectance 近似值的 參數 • 物體依照其物理特性可以區分成 • Dielectric 導電體,metallic = 0 • Insulator 絕緣體,metallic = 1 • 導電體的 IOR 在 1.3 ~ 1.7,取平均值 1.5 𝑅 = (1−1.5)2 (1+1.5)2 = 0.04 𝑅 𝑈𝑛𝑖𝑡𝑦 𝐴𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 = 𝑙𝑒𝑟𝑝(0.04,1, 𝑚𝑒𝑡𝑎𝑙𝑙𝑖𝑐)
  • 10. Schlick’s Approximation 𝐹𝜃 ≈ 𝐹0 + (1 − 𝐹0)(1 − cos 𝜃)5
  • 11. Rendering Equation(簡化版2) 𝐿 𝑜 𝑥, 𝜔 𝑜 = 𝑓𝑟 𝑥, 𝜔𝑖, 𝜔 𝑜 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛 = 𝑘 𝑑 𝑓𝑑 + 𝑘 𝑠 𝑓𝑠 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛 = 𝑘 𝑑 𝑓𝑟𝑑 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛 + 𝑘 𝑠 𝑓𝑟𝑠 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛 • 𝑘 𝑑 光線接觸到物體的折射率 • 𝑘 𝑠 光線接觸到物體的反射率 • 𝑘 𝑑 + 𝑘 𝑠 = 1 • 𝑓𝑟𝑑 Diffuse 的 BRDF • 𝑓𝑟𝑠 Specular 的 BRDF
  • 12. Diffuse BRDF • 使用 Lambert 圖片來源: Brian Karis, "Real Shading in Unreal Engine 4" SIGGRAPH 2013
  • 13. Normalized Lambert • 遵守能量守恆 • Lambert’s cosine law • 𝛺 cos 𝜃 ⅆ𝜔 = 𝜋 • 𝐵𝑅𝐷𝐹𝐿𝑎𝑚𝑏𝑒𝑟𝑡 = 𝐶 𝜋 • C = Albedo
  • 14. Specular BRDF • Cook-Torrance Model • 𝑓𝑟𝑠 𝑥, 𝜔𝑖, 𝜔 𝑜 = 𝐷𝐺𝐹 4(𝑛∙𝜔 𝑜)(𝑛∙𝜔 𝑖) • D : Microfacet Distribution Fuctions • G : Masking-Shadowing Fuctions • F : Fresnel
  • 15. Microfacet Model • 模擬物體表面崎嶇程度 • 使用變數 roughness (粗糙度) 控制 • 參考 [Burley 2012] 設定 • Roughness 值域在 [0,1] • 將 Roughness 分成兩個部分 • Perceptual roughness,美術人員控制效果用的參數 • Alpha roughness ,實際運算使用的參數 • 𝑅𝑜𝑢𝑔ℎ𝑛𝑒𝑠𝑠 𝑎𝑙𝑝ℎ𝑎 = (𝑅𝑜𝑢𝑔ℎ𝑛𝑒𝑠𝑠 𝑝𝑒𝑟𝑐𝑒𝑝𝑡𝑢𝑎𝑙)2
  • 16. Specular Distribution • 使用 Trowbridge-Reitz model • 𝐷 ℎ = 𝑋+(𝑛∙ℎ)𝛼2 𝜋( 𝑛∙ℎ 2 𝛼2−1 +1)2 • 𝑋+ (𝑛 ∙ ℎ) 𝑖𝑓 𝑛 ∙ ℎ ≤ 0, 𝑟𝑒𝑡𝑢𝑟𝑛 0 𝑒𝑙𝑠𝑒 𝑟𝑒𝑡𝑢𝑟𝑛 1 • ℎ ∶ ℎ𝑎𝑙𝑓 𝑣𝑒𝑐𝑡𝑜𝑟 • 𝑛 ∶ 𝑛𝑜𝑟𝑚𝑎𝑙 𝑣𝑒𝑐𝑡𝑜𝑟 • 𝛼 ∶ 𝑎𝑙𝑝ℎ𝑎 𝑟𝑜𝑢𝑔ℎ𝑛𝑒𝑠𝑠
  • 17. Geometric shadowing • 使用 Schlick 提出的 Smith Model 近似法 • 𝐺𝑆𝑐ℎ𝑙𝑖𝑐𝑘 𝑣 = 𝑛∙𝑣 𝑛∙𝑣 1−𝑘 +𝑘 • 𝑘 = 𝛼 2 𝜋 • 考慮 masking 和 shadowing • 𝐺𝑆𝑚𝑖𝑡ℎ 𝑙, 𝑣, ℎ = 𝐺𝑆𝑐ℎ𝑙𝑖𝑐𝑘 𝑙 𝐺𝑆𝑐ℎ𝑙𝑖𝑐𝑘 𝑣 • 𝑙 ∶ 𝑙𝑖𝑔ℎ𝑡 𝑣𝑒𝑐𝑡𝑜𝑟 • 𝑣: 𝑣𝑖𝑒𝑤 𝑣𝑒𝑐𝑡𝑜𝑟
  • 18. 單一方向光源 PBR Metallic = 0 時, roughness 由左至右遞增 Metallic = 1 時, roughness 由左至右遞增
  • 19. 補充(1) • Cook-Torrance Model • 𝑓𝑟𝑠 𝑥, 𝜔𝑖, 𝜔 𝑜 = 𝐹 𝜋 𝐷𝐺 (𝑛∙𝜔 𝑜)(𝑛∙𝜔 𝑖) [Cook and Torrance 1982] • 𝑓𝑟𝑠 𝑥, 𝜔𝑖, 𝜔 𝑜 = 𝐷𝐺𝐹 4(𝑛∙𝜔 𝑜)(𝑛∙𝜔 𝑖) [Walter et al. 2007]
  • 20. 補充(2) • 𝑓𝑟𝑠(𝑥, 𝜔𝑖, 𝜔 𝑜) = 𝐷𝑉𝐹 • 𝑉 = 𝐺 4(𝑛∙ 𝑙)(𝑛∙𝑣)
  • 21. 間接光 • 𝛺 𝑓𝑟(𝑥, 𝜔𝑖, 𝜔 𝑜)𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔 • 計算龐大,不適合run-time處理
  • 22. Image Based Lighting • 實現環境光照的一種作法 • 將環境光源資料儲存在一張影像內(通常為 Cubemap),在 渲染時從影像取得光線資料做處理 • 參考 [Karis 2013] 內容實作
  • 23. Requirements • Spherical Coordinates • Monte Carlo method • Importance sampling • Low-discrepancy sequence • Tone Mapping
  • 24. Spherical Coordinates • 使用三個參數代表座標 (𝛾, 𝜃, 𝜑) • 𝛾 表示原點到座標的距離, 𝛾 ≥ 0 ,因為反射光使用單位向量, 可省略。 • 𝜃 表示和 Z 軸的夾角,0 ≤ 𝜃 ≤ 𝜋,但反射光在 hemisphere 內, 0 ≤ 𝜃 ≤ 𝜋 2 • 𝜑 表示在 X-Y 平面上和 X 軸的夾角,0 ≤ 𝜑 ≤ 2𝜋 • 對應到三維座標 𝑋, 𝑌, 𝑍 為 • X = 𝛾 ∗ sin 𝜃 ∗ cos 𝜑 • Y = 𝛾 ∗ sin 𝜃 ∗ sin 𝜑 • Z = 𝛾 ∗ cos 𝜃
  • 25. Monte Carlo Method • 求 f(𝑥) 積分
  • 26. Monte Carlo Estimator (1) • 𝑎 𝑏 𝑓(𝑥) ⅆ𝑥 ≈ 𝑏−𝑎 𝑁 𝑖=1 𝑁 𝑓(𝑥𝑖) • 證明 • 計算期望值 • E 𝑏−𝑎 𝑁 𝑖=1 𝑁 𝑓(𝑥𝑖) • = 𝑏−𝑎 𝑁 𝑖=1 𝑁 𝐸 𝑓(𝑥𝑖) • = 𝑏 − 𝑎 𝑎 𝑏 𝑓 𝑥 𝑝ⅆ𝑓 𝑥 ⅆ𝑥 • = 𝑏 − 𝑎 𝑎 𝑏 𝑓 𝑥 𝑏−𝑎 ⅆ𝑥 = 𝑎 𝑏 𝑓 𝑥 ⅆ𝑥 • pdf(x) : x 點上的 probability density function • 當每個樣本的 pdf 都一樣,算式成立 • Law of large numbers • 取樣數越多,結果越接近期望值
  • 27. Monte Carlo Estimator (2) • 𝑎 𝑏 𝑓(𝑥) ⅆ𝑥 ≈ 1 𝑁 𝑖=1 𝑁 𝑓(𝑥 𝑖) 𝑝𝑑𝑓(𝑥 𝑖) • 證明 • 計算期望值 • E 1 𝑁 𝑖=1 𝑁 𝑓(𝑥) 𝑝𝑑𝑓(𝑥 𝑖) • = 1 𝑁 𝐸 𝑖=1 𝑁 𝑓(𝑥 𝑖) 𝑝𝑑𝑓(𝑥 𝑖) • = 1 𝑁 𝑖=1 𝑁 𝑎 𝑏 𝑓 𝑥 𝑝𝑑𝑓 𝑥 𝑝ⅆ𝑓 𝑥 ⅆ𝑥 • = 1 𝑁 𝑖=1 𝑁 𝑎 𝑏 𝑓(𝑥) ⅆ𝑥 = 𝑎 𝑏 𝑓(𝑥) ⅆ𝑥 • 多元積分 • 𝑓(𝑥, 𝑦) ⅆ𝑥 ⅆ𝑦 ≈ 1 𝑁 𝑖=1 𝑁 𝑓(𝑥 𝑖,𝑦 𝑖) 𝑝𝑑𝑓 𝑥 𝑖 𝑝𝑑𝑓(𝑦 𝑖)
  • 28. Importance sampling (1) • Monte Carlo Method • 𝑎 𝑏 𝑓(𝑥) ⅆ𝑥 ≈ 1 𝑁 𝑖=1 𝑁 𝑓 𝑥 𝑖 𝑝𝑑𝑓 𝑥 𝑖 = 1 𝑁 ( 𝑓 𝑥1 𝑝𝑑𝑓 𝑥1 + 𝑓 𝑥2 𝑝𝑑𝑓 𝑥2 + ⋯ + 𝑓(𝑥 𝑁) 𝑝𝑑𝑓(𝑥 𝑁) ) • 𝑓(𝑥 𝑖) 𝑝𝑑𝑓(𝑥 𝑖) → 0 • 忽略影響低的樣本,只取影響高的樣本 • 𝑓(𝑥)和 𝑝ⅆ𝑓(𝑥) 分布形狀越接近,可使用越少的樣本數逼 近真實結果。 圖片來源 : Wojciech Jarosz's Dissertation Appendix A
  • 29. Importance sampling (2) • 找出影響最大的反射光,作為積分樣本
  • 30. Importance sampling GGX • 𝑓𝑟𝑠 𝑥, 𝜔𝑖, 𝜔 𝑜 = 𝐷𝐺𝐹 4(𝑛∙𝜔 𝑜)(𝑛∙𝜔 𝑖) • 可從 D 項計算出法線分布,求得反射光方向 • 找出 D 項的 Importance sampling function • Inverse transform sampling
  • 31. Inversion method • 𝐷 ℎ = 𝛼2 cos 𝜃 sin 𝜃 𝜋 (𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2 • 𝑝ⅆ𝑓: 𝑝ℎ 𝜃, 𝜑 = 𝛼2 cos 𝜃 sin 𝜃 𝜋( 𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2 [Walter et al. 2007] • 𝑚ⅆ𝑓: 𝑝ℎ 𝜃 = 0 2𝜋 𝑝ℎ(𝜃, 𝜑) ⅆ𝜑 = 2𝛼2 cos 𝜃 sin 𝜃 ( 𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2 • 𝑝ℎ 𝜑 𝜃 = 𝑝ℎ(𝜃,𝜑) 𝑝ℎ(𝜃) = 𝛼2 cos 𝜃 sin 𝜃 𝜋( 𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2 2𝛼2 cos 𝜃 sin 𝜃 ( 𝛼2−1 𝑐𝑜𝑠2 𝜃+1)2 = 1 2𝜋 • 𝑐ⅆ𝑓 𝑃ℎ 𝜃 = 0 𝜃 2𝛼2 cos 𝑡 sin 𝑡 (𝑐𝑜𝑠2 𝑡 𝛼2−1 +1)2 ⅆ𝑡 • = 𝛼2 𝑐𝑜𝑠2 𝜃(𝛼2−1)2+(𝛼2−1) − 1 𝛼2−1 = 𝜉1 • 𝑐ⅆ𝑓 𝑝ℎ 𝜑 𝜃 = 0 𝜑 1 2𝜋 ⅆ𝑡 = 𝜑 2𝜋 = 𝜉2 • 𝜃 = cos−1 1−𝜉1 𝜉1 𝛼2−1 +1 • 𝜑 = 2𝜋𝜉2
  • 33. Low-discrepancy sequence • 需要一個二維變數 (ξ1, ξ2) 做 Importance Sampling 樣本,求 得法線的(𝜃, 𝜑) • • Monte Carlo Method 使用亂數取 N 個樣本 • 收斂速度 O(𝑁−0.5) [Asmussen and Glynn 2007] • 提升兩倍精度須提供四倍樣本數 • Quasi Monte Carlo Method 使用 Low-discrepancy sequence 取 N 個樣本 • 收斂數度 O log 𝑁 𝐷𝑖𝑚 𝑁 • 在二維空間,提升兩倍精度只需兩倍樣本數 • 使用 Hammersley Sequence
  • 34. Hammersley sequency • 0.1 = 1 ∗ 2−1 = 0.5 • 0.01 = 0 ∗ 2−1 + 1 ∗ 2−2 = 0.25 • 0.11 = 1 ∗ 2−1 + 1 ∗ 2−2 = 0.75 • 0.001 = 0 ∗ 2−1 + 0 ∗ 2−2 + 1 ∗ 2−3 = 0.125 • ⋮ 圖片來源 : Physically Based Rendering - 7.4 The Halton Sampler
  • 36. Image Based Lighting • 𝛺 𝑓𝑟 𝑥, 𝜔𝑖, 𝜔 𝑜 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 • = 𝛺 (𝑓𝑟𝑑 + 𝑓𝑟𝑠)𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 • = 𝛺 𝑓𝑟𝑑 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 + 𝛺 𝑓𝑟𝑠 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 • 拆分成 Diffuse 和 Specular 處理 • Off-line 計算結果,run-time 直接取用 • 使用 HDR 的 Environment map 作為環境光源 • 𝐿𝑖(𝑥, 𝜔𝑖) 來源
  • 37. IBL - Diffuse • 使用 Lambert • 𝛺 𝑓𝑑 𝐿𝑖 𝑥, 𝜔𝑖 𝜔𝑖 ∙ 𝑛 ⅆ𝜔𝑖 • = 𝛺 𝑘 𝑑 𝑐 𝜋 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 • = 𝑘 𝑑 𝑐 𝜋 𝜑=0 2𝜋 𝜃=0 𝜋 2 𝐿𝑖(𝑥, 𝜔𝑖) cos 𝜃 sin 𝜃 ⅆ𝜑 ⅆ𝜃 • 積分使用 Riemann Sum 圖片來源 LearnOpenGL
  • 38. IBL - Specular • 使用 Cook-Torrance Model • 𝛺 𝑓𝑟𝑠 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 • = 𝛺 𝑘 𝑠 𝐷𝐹𝐺 4 𝜔 𝑜∙𝑛 𝜔𝑖∙𝑛 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 • 兩個變數 𝜔𝑖、𝜔 𝑜,複雜度高。
  • 39. Split sun approximation • Monte Carlo Method + importance sampling GGX • 𝛺 𝑓𝑟𝑠 𝐿𝑖(𝑥, 𝜔𝑖)(𝜔𝑖 ∙ 𝑛) ⅆ𝜔𝑖 • ≈ 1 𝑁 𝑘=1 𝑁 𝑓𝑟𝑠 𝑙 𝑘 𝐿 𝑖 𝑙 𝑘 𝑝𝑑𝑓 𝑙 𝑘 (𝑙 𝑘 ∙ 𝑛) • 𝑙 𝑘 使用 importance sampling 取得的反射光樣本 • pdf 𝑙 𝑘 = 𝐷(𝑛∙ℎ) 4(𝑣∙ℎ) [Karis 2013] • 1 𝑁 𝑘=1 𝑁 𝑓𝑟𝑠 𝑙 𝑘 𝐿 𝑖 𝑙 𝑘 𝑝𝑑𝑓 𝑙 𝑘 𝑙 𝑘 ∙ 𝑛 • = 1 𝑁 𝑘=1 𝑁 𝐷𝐹𝐺 4 𝑛∙𝑙 𝑘 𝑛∙𝑣 1 𝑝𝑑𝑓 𝑙 𝑘 𝐿𝑖(𝑙 𝑘)(𝑛 ∙ 𝑙 𝑘) • = 1 𝑁 𝑘=1 𝑁 𝐹𝐺 𝑛∙𝑣 𝑛∙ℎ (𝑣 ∙ ℎ)𝐿𝑖(𝑙 𝑘) • ≈ ( 1 𝑁 𝑘=1 𝑁 𝐹𝐺 𝑛∙𝑣 𝑛∙ℎ 𝑣 ∙ ℎ ) ∗ ( 1 𝑘=1 𝑁 𝑛∙𝑙 𝑘 𝑘=1 𝑁 𝐿𝑖 𝑙 𝑘 𝑛 ∙ 𝑙 𝑘 )
  • 40. Integral of BRDF (1) • 𝐺 𝑣𝑖𝑠 = 𝐺 (𝑛∙𝑣)(𝑛∙ℎ) • 1 𝑁 𝑘=1 𝑁 𝐹𝐺 𝑛∙𝑣 𝑛∙ℎ (𝑣 ∙ ℎ) = 1 𝑁 𝑘=1 𝑁 𝐹𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ) • F : Fresnel • 𝐹𝑐 = (1 − (𝑣 ∙ ℎ))5 • 𝐹 ≈ 𝐹0 + 1 − 𝐹0 1 − 𝑣 ∙ ℎ 5 = 𝐹0 + (1 − 𝐹0)𝐹𝑐 • 1 𝑁 𝑘=1 𝑁 𝐹𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ) = 1 𝑁 𝑘=1 𝑁 (𝐹0 + (1 − 𝐹0)𝐹𝑐)𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ) • = 1 𝑁 𝑘=1 𝑁 (𝐹0 1 − 𝐹𝑐 + 𝐹𝑐)𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ) • = 1 𝑁 𝑘=1 𝑁 𝐹0(1 − 𝐹𝑐)𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ) + 1 𝑁 𝑘=1 𝑁 𝐹𝑐 𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ) • = 𝐹0 1 𝑁 𝑘=1 𝑁 1 − 𝐹𝑐 𝐺 𝑣𝑖𝑠 𝑣 ∙ ℎ + ( 1 𝑁 𝑘=1 𝑁 𝐹𝑐 𝐺 𝑣𝑖𝑠(𝑣 ∙ ℎ))
  • 41. Integral of BRDF (2) • 𝐺𝑠𝑐ℎ𝑙𝑖𝑐𝑘 𝑣 = 𝑛∙𝑣 𝑛∙𝑣 1−𝑘 +𝑘 • 𝑘 = 𝛼 2 𝜋 • 𝑘 = 𝛼 2 [Karis 2013] 𝑛 ∙ 𝑣 roughness
  • 42. Integral of lighting • 1 𝑘 𝑁 (𝑛∙𝑙 𝑘) 𝑘 𝑁 𝐿𝑖(𝑙 𝑘)(𝑛 ∙ 𝑙 𝑘) • 使用 importance sampling GGX 取樣 • 需要從 法線 取得 Environment Map 內的光源資料 • Environment Map 使用 Cubemap,需要反射向量 • 令 normal = view = reflect • 新增 cos 項作為權重可提升效果 • 將不同 roughness 結果用 mipmap 分開儲存[GPU Gems 3] 圖片來源 LearnOpenGL
  • 43. 效果比較 • 和 Unity standard shader 在 Unity 編輯器做比較 • 比對 metallic = 0 和 = 1 的效果 • Roughness 從左到右遞增 • Unity 使用 smoothness ,smoothness = 1 - roughness • Prefilter Enviorment map : 512 x 512 Cubmap, 5 mipmap • BRDF integrate map : 512 x 512 texture2D RGB24 • Diffuse irradiance : 32 x 32 Cubemap • Environment Map 素材來源 HDRIHaven
  • 46. Mobile 展示視頻 • 使用 Sony L3 • ApowerRec 錄製
  • 47. Future work • Dual Paraboloid Environment Map • Cloth

Editor's Notes

  1. 什麼是 PBR?這其實很難去說明,原因是文獻上對於 PBR 有很多不同觀點的解釋。 在本篇文章,我狹義並侷限定義 PBR 滿足以上要點
  2. 這是 Kajiya, James T. 於 1986 在 Siggraph提出的論文,也是現代電腦渲染的基礎。 剛看到可能會對這個算式感到複雜而無法理解,但是可以嘗試簡化這個算式,方便去理解數式內容 Kajiya, James T., The rendering equation (PDF), Siggraph 1986, 1986: 143–150, ISBN 978-0-89791-196-2, doi:10.1145/15922.15902 Immel, David S.; Cohen, Michael F.; Greenberg, Donald P., A radiosity method for non-diffuse environments (PDF), Siggraph 1986, 1986: 133, ISBN 978-0-89791-196-2, doi:10.1145/15922.15901
  3. 假設 x 是渲染物體的某個位置,這個物體表面可能不是很平滑。 用顯微鏡放大 x 點,會發現 x 在一 個平面上(不論這個物體表面多崎嶇)。 半球積分就是考慮 x 點的所有受光影響。
  4. 簡化後的渲染方程式只考慮到單一方向來源光的反射。 BRDF 是計算反射光行為的一個機率統計函式。 Li 是光源的 radiant(輻射度),可想像成光的能量。 當入射光源和平面不是垂直時,光的能量不會完全作用在平面上,因此需要計算和平面的法線夾角。
  5. Reflectance 是垂直反射率,在渲染計算上習慣用 F0 表示 n 為 material 的  index of Refraction (折射率, 簡稱 IOR) 。 光線的 Reflectance 是根據傳輸的兩個 material 間的 IOR 來計算
  6. Metallic 應該是個二元值(i.e. 不是0就是1),若物體發生變質(ex.生鏽) 才有可能是 非0並非1的值。
  7. 非垂直光線必須要用 Schlick’s Approximation 去求得非直角的反射率
  8. 在這裡,整理之前的討論,可以將一個只考慮單一來源方向的渲染方程式改寫成上列算式
  9. Diffuse 的影響不如 Specular 來的大,因此選擇高效能的 Lambert 作為 Diffuse BRDF。
  10. - K.E.Torrance & E.M.Sparrow, "Theory for Off-Specular Reflection From Roughened Surfaces", 1966 - James F. Blinn, "Models of Light Reflection for Computer Synthesized Pictures", 1977 - Robert L. Cook&Kenneth E. Torrance, "A Reflectance Model for Computer Graphics", 1982 - Walter et al. 2007, "Microfacet Models for Refraction through Rough Surfaces"
  11. Burley, B., 2012. Physically-based shading at Disney. http://selfshadow.com/s2012-shading/.
  12. Walter et al. 2007, "Microfacet Models for Refraction through Rough Surfaces"
  13. - [SMITH, B. 1967] Geometrical shadowing of a random rough surface. IEEE Trans. on Antennas and Propagation 15, 668–671. - Christophe Schlick, "An Inexpensive BRDF Model for Physically based Rendering", 1994
  14. 因為光線接觸到其他物體產生間接光,所以單一方向光源的渲染很難接近真實效果。
  15. Brian Karis, "Real Shading in Unreal Engine 4" SIGGRAPH 2013
  16. 這裡的三維座標(x,y,z)是在 tangent-space
  17. Wojciech Jarosz‘s Dissertation Appendix A ,https://www.cs.dartmouth.edu/~wjarosz/publications/dissertation/appendixA.pdf
  18. mdf = marginal density function cdf = cumulative distribution function 由於 ξ1 和 ξ2 的範圍都在 0 ~ 1 之間, 因此我可以用一個 2 維的參數 (ξ1 , ξ2) 來取得一個 GGX 分布的法線向量。
  19. Wolframalpha,https://www.wolframalpha.com/ 輸入 integral((a^2*cos(theta)*sin(theta))/(pi((a^2-1)*cos(theta)^2+1)^2),phi,0,2pi)
  20. Søren Asmussen and Peter W. Glynn, Stochastic Simulation: Algorithms and Analysis, Springer, 2007, 476 pages
  21. Physically Based Rendering - 7.4 The Halton Sampler,http://www.pbr-book.org/3ed-2018/Sampling_and_Reconstruction/The_Halton_Sampler.html
  22. LearnOpenGL,https://learnopengl.com/
  23. LearnOpenGL,https://learnopengl.com/
  24. HDRIHaven,https://hdrihaven.com/hdris/?c=outdoor