# Microfacet模型采样下的brdf

### 为什么默认的抽样方法是低效的

$p_h(ω)=\frac{cos(θ)}{π}$

$L_o\omega _o=\int{L_i\left( \omega _i \right) *f\left( \omega _i,\omega _o \right) *\cos \left( \theta _i \right) d\omega _i}$

### 微表面模型

Microfacet Model是这几年在实时渲染中比较热门的，它是基于物理的着色算法的基本原理。一般来说，它的基本形式是这样的。

$f(ω_i,ω_o,x)=\frac{F(ω_i,h)G(ω_i,ω_o,h)D(h)}{4cos(θ_i)cos(θ_o)}$

• GGX
• Beckmann
• Blinn

$\int_{\varOmega}{D\left( m \right) \cos \left( \theta _m \right) d\omega =1}$

### NDF（补充）

NDF详细的定义可了解这篇文章（How Is The NDF Really Defined），文章中有对上述规则的说明

NDF遵循公式

$dA_h=D(h)d\omega_hA\,\,\,\,\,(1)$

$\int_{\varOmega}{D\left( m \right) \cos \left( \theta _m \right) d\omega =1} \,\,\,\,\,(2)$

### GGX采样

$D\left( h \right) =\frac{\alpha ^2}{\pi \left( \left( \alpha ^2-1 \right) \cos ^2\theta +1 \right) ^2}$

$p_h(ω) =\frac{\alpha ^2\cos \theta}{\pi \left( \left( \alpha ^2-1 \right) \cos ^2\theta +1 \right) ^2}$

$p_h\left( \theta ,\phi \right) =sinθp_h(\omega)=\frac{\alpha ^2\cos \theta \sin \theta}{\pi \left( \left( \alpha ^2-1 \right) \cos ^2\theta +1 \right) ^2}$

$p_h\left( \theta \right) =\int_0^{2\pi}{p_h\left( \theta ,\phi \right) d\phi}=\frac{2\alpha ^2\cos \theta \sin \theta}{\left( \left( \alpha ^2-1 \right) \cos ^2\theta +1 \right) ^2}$

$p_h\left( \theta \right) =\int_0^{\theta}{\frac{2\alpha ^2\cos t\sin t}{\left( \left( \alpha ^2-1 \right) \cos ^2t+1 \right) ^2}dt}$

$=\int_\theta^{0}{\frac{2\alpha ^2\cos t}{\left( \left( \alpha ^2-1 \right) \cos ^2t+1 \right) ^2}d\left( \cos t \right)}$

$=\int_\theta^{0}{\frac{\alpha ^2}{\left( \left( \alpha ^2-1 \right) \cos ^2t+1 \right) ^2}d\left( \cos ^2t \right)}$

$=-\frac{\alpha ^2}{\alpha ^2-1}\int_\theta^{0}{d\frac{1}{\cos ^2t\left( \alpha ^2-1 \right) +1}}$

$=\frac{\alpha ^2}{\alpha ^2-1}\int_0^{\theta}{d\frac{1}{\cos ^2t\left( \alpha ^2-1 \right) +1}}$

$=\frac{\alpha ^2}{\alpha ^2-1}\left( \frac{1}{\cos ^2\theta \left( \alpha ^2-1 \right) +1}-\frac{1}{\alpha ^2} \right)$

$=\frac{\alpha ^2}{\cos ^2\theta \left( \alpha ^2-1 \right) ^2+\left( \alpha ^2-1 \right)}-\frac{1}{\alpha ^2-1}$

$\epsilon =\frac{\alpha ^2}{\cos ^2\theta \left( \alpha ^2-1 \right) ^2+\left( \alpha ^2-1 \right)}-\frac{1}{\alpha ^2-1}$

$$\theta =\mathrm{arc}\cos \sqrt{\frac{1-\epsilon}{\epsilon \left( \alpha ^2-1 \right) +1}}$$ or $$\theta =\mathrm{arc}\tan \left( \alpha \sqrt{\frac{\epsilon}{1-\epsilon}} \right)$$

### Beckmann采样

Beckmann抽样法的推导过程与上述过程十分相似。这是Beckmann分布：

$D\left( h \right) =\frac{1}{\pi \alpha ^2\cos ^4\theta}e^{-\frac{\tan ^2\theta}{\alpha ^2}}$

$p_h\left( \theta ,\phi \right) =\frac{\sin \theta}{\pi \alpha ^2\cos ^3\theta}e^{-\frac{\tan ^2\theta}{\alpha ^2}}$

$p_h\left( \theta \right) =\frac{2\sin \theta}{\alpha ^2\cos ^3\theta}e^{-\frac{\tan ^2\theta}{\alpha ^2}}$

$$\theta$$的CDF可以这样计算:

$P_h\left( \theta \right) =\int_0^{\theta}{\frac{2\sin \left( t \right)}{\alpha ^2\cos ^3t}e^{-\frac{\tan ^2t}{\alpha ^2}}}dt \\ =\int_0^{\theta}{\frac{-2}{\alpha ^2\cos ^3t}e^{-\frac{\tan ^2t}{\alpha ^2}}}d\left( \cos \left( t \right) \right) \\ =\int_0^{\theta}{\frac{1}{\alpha ^2}e^{-\frac{\tan ^2t}{\alpha ^2}}}d\left( \frac{1}{\cos ^2\left( t \right)} \right) \\ =\int_0^{\theta}{\frac{1}{\alpha ^2}e^{\frac{1}{\alpha ^2}\left( 1-\frac{1}{\cos ^2t} \right)}}d\left( \frac{1}{\cos ^2\left( t \right)} \right) \\ =\int_0^{\theta}{\frac{1}{\alpha ^2}e^{\frac{1}{\alpha ^2}\left( 1-\frac{1}{\cos ^2t} \right)}}d\left( \frac{1}{\cos ^2\left( t \right)} \right) \\ =\int_{\theta}^0{d\left( e^{\frac{1}{\alpha ^2}\left( 1-\frac{1}{\cos ^2t} \right)} \right)} \\ =1-e^{\frac{1}{\alpha ^2}\left( 1-\frac{1}{\cos ^2\theta} \right)}$

$$\theta =\mathrm{arc}\cos \sqrt{\frac{1}{1-\alpha ^2\ln \left( 1-\epsilon \right)}}$$ or $$\theta =\mathrm{arc}\tan \sqrt{-\alpha ^2\ln \left( 1-\epsilon \right)}$$

### Blinn采样

$D\left( h \right) =\frac{\alpha +2}{2\pi}\left( \cos \theta \right) ^{\alpha}$

$p_h\left( \theta ,\phi \right) =\frac{\alpha +2}{2\pi}\left( \cos \theta \right) ^{\alpha +1}\sin \theta$

$p_h\left( \theta \right) =\left( \alpha +2 \right) \left( \cos \theta \right) ^{\alpha +1}\sin \theta$

$P_h\left( \theta \right) =\int_0^{\theta}{\left( \alpha +2 \right) \cos \left( t \right) ^{\alpha +1}\sin \left( t \right) d\left( t \right)} \\ =\int_{\theta}^0{\left( \alpha +2 \right) \cos \left( t \right) ^{\alpha +1}d\left( \cos \left( t \right) \right)} \\ =\int_{\theta}^0{d\left( \cos \left( t \right) ^{\alpha +2} \right)} \\ =1-\cos \left( \theta \right) ^{\alpha +2}$

$\theta =\mathrm{arc}\cos \left( \left( 1-\epsilon \right) ^{\frac{1}{\alpha +2}} \right)$

$\theta =\mathrm{arc}\cos \left( \epsilon^{\frac{1}{\alpha +2}} \right)$

$\theta =\mathrm{arc}\cos \left( \epsilon^{\frac{1}{\alpha +1}} \right)$

### 一个额外的步骤

$p\left( \theta \right) =p_h\left( \theta \right) \frac{d\omega _h}{d\omega _i}=\frac{p_h\left( \theta \right)}{4\left( \omega _o·\omega _h \right)}$

### 结论

64spp，GGX被选为NDF，三只猴子的粗糙度值不同（0.0,0.5,1.0）。从图中我们可以看到，最左边的猴子得到的结果比默认的采样方法好得多。对于其他两只猴子，我们用余弦-pdf取样方法得到了类似的结果。

### 引用

posted @ 2021-09-27 14:11  shadow_lr  阅读(499)  评论(0编辑  收藏  举报