圆面、球面上的采样方法

(本文内容主要来自《pbrt》13.5、13.6)
如果 y y y满足概率密度分布 p ( y ) p(y) p(y),如果要随机地获取一个 y y y的话,可以先获取一个随机数 t t t,然后代入它的累积概率密度 P ( y ) = t P(y)=t P(y)=t,然后求解出 y y y即可。
但是很多情况需要的不仅是对单个变量做采样,往往需要对多个维度下的多个变量进行采样,而这些多个变量之间很有可能有互相关联,并且直接采样也不容易,可以考虑做一些变换来进行采样。

一切推导从一个最基本的式子出发, y y y x x x的累积概率密度 C D F CDF CDF相同, P { Y < = y ( x ) } = P { X < = x } P\{ Y<=y(x)\}=P\{ X <= x\} P{Y<=y(x)}=P{X<=x}
因此 P y ( Y ) = P x ( X ) P_y(Y) = P_x(X) Py(Y)=Px(X)
两边做一下微分即可得: p ( y ) d y / d x = p ( x ) p(y)dy/dx =p(x) p(y)dy/dx=p(x)
那么如果y和x都是多维的情况,很容易就可以得到 p ( y ) J y ( x ) = p ( x ) p(y)J_y(x)=p(x) p(y)Jy(x)=p(x) J y ( x ) J_y(x) Jy(x) y y y关于 x x x的雅克比行列式。

具体的例子:
1.圆面上进行均匀采样。
圆面上的任何一点可以由直角坐标系下的 ( x , y ) (x,y) (x,y)表达,也可以由极坐标系下的 ( r , θ ) (r,\theta) (r,θ)来表达,并且存在关系: x = r c o s θ , y = r s i n θ x=rcos\theta,y=rsin\theta x=rcosθy=rsinθ J = ∣ c o s θ − r s i n θ s i n θ r c o s θ ∣ = r J =\begin{vmatrix} cos\theta & -rsin\theta \\ sin\theta & rcos\theta \\ \end{vmatrix} =r J=cosθsinθrsinθrcosθ=r
因此可以得到关系 r p ( x , y ) = p ( r , θ ) rp(x,y)=p(r,\theta) rp(x,y)=p(r,θ)
由于要求在圆面上进行均匀采样,也就是说每一点被采到的概率都应该相同, p ( x , y ) = 1 / π p(x,y)=1/\pi p(x,y)=1/π,那么 p ( r , θ ) = r π p(r,\theta)=\frac{r}{\pi} p(r,θ)=πr,进一步可以得到 p ( r ) = ∫ 0 2 π r π d θ = 2 r p(r)=\int_{0}^{2\pi}\frac{r}{\pi}d\theta=2r p(r)=02ππrdθ=2r
由此 p ( θ ∣ r ) = p ( r , θ ) / p ( r ) = 1 2 π p(\theta|r)=p(r,\theta)/p(r)=\frac{1}{2\pi} p(θr)=p(r,θ)/p(r)=2π1
这个结果可以看出 θ \theta θ r r r是互相独立的,因此可以分别获取两个随机数 a , b a,b a,b,最终的采样结果为: r = a , θ = 2 π b r=\sqrt{a},\theta=2\pi b r=a ,θ=2πb

2.半球面上对立体角做均匀采样
立体角被定义为单位球面上的单位面积,于是 d w = d A = s i n θ d θ d ϕ dw=dA=sin\theta d\theta d\phi dw=dA=sinθdθdϕ(dA为单位球上的微元面积),因此 p ( w ) s i n θ = p ( θ , ϕ ) p(w)sin\theta=p(\theta,\phi) p(w)sinθ=p(θ,ϕ)
而要求对立体角做均匀采样,于是 p ( w ) = 1 2 π p(w)=\frac{1}{2\pi} p(w)=2π1
p ( θ , ϕ ) = s i n θ / 2 π p(\theta,\phi)=sin\theta/2\pi p(θ,ϕ)=sinθ/2π
进一步 p ( θ ) = ∫ 0 2 π s i n θ / 2 π d ϕ = s i n θ p(\theta)=\int_{0}^{2\pi}sin\theta/2\pi d \phi=sin\theta p(θ)=02πsinθ/2πdϕ=sinθ
于是 p ( ϕ ∣ θ ) = 1 2 π p(\phi|\theta)=\frac{1}{2\pi} p(ϕθ)=2π1
可取两个随机数 a , b a,b a,b,这样可以得到 ϕ \phi ϕ θ \theta θ ϕ = 2 π a , θ = c o s − 1 b \phi = 2\pi a,\theta=cos^{-1}b ϕ=2πa,θ=cos1b
进一步代入直角坐标系可以得到 x , y , z x,y,z x,y,z

3.半球面上对立体角做Cosine-Weighted采样
Cosine-Weighted采样指的是立体角方向与竖直方向夹角的余弦值越高,那么该立体角被采样得到的概率就越大的一种采样方式。
也就是说 p ( w ) = c o s θ ⋅ c p(w)=cos\theta·c p(w)=cosθc,其中 c c c是一个常系数
由于对整个半球面做积分,得到值应该为1: ∫ H 2 c ⋅ c o s θ d w = 1 \int_{H^2}c·cos\theta dw=1 H2ccosθdw=1
代入计算可以得到 c = 1 π c=\frac{1}{\pi} c=π1,直接使用2的推导可以得到 p ( θ , ϕ ) = p ( w ) s i n θ = s i n θ c o s θ π p(\theta,\phi)=p(w)sin\theta=\frac{sin\theta cos\theta}{\pi} p(θ,ϕ)=p(w)sinθ=πsinθcosθ
继续往后推导就可以得到具体采样的公式。

但是这里有一个更加简单的方法圆面、球面上的采样方法_第1张图片
如图所示,只需要现在圆面上进行一次采样得到黑色的点,然后把它往上投影到球面上即可。
下面来证明其正确性,也就是要证明通过这样的采样方式是符合 p ( θ , ϕ ) = s i n θ c o s θ π p(\theta,\phi)=\frac{sin\theta cos\theta}{\pi} p(θ,ϕ)=πsinθcosθ的。
在二维球面上采样可以获得 p ( r , ϕ ) = r π p(r,\phi)=\frac{r}{\pi} p(r,ϕ)=πr,不难发现 r = s i n θ r=sin\theta r=sinθ,于是 p ( s i n θ , ϕ ) = r π p(sin\theta,\phi)=\frac{r}{\pi} p(sinθ,ϕ)=πr
考虑将 p ( s i n θ , ϕ ) p(sin\theta,\phi) p(sinθ,ϕ)变换至 p ( θ , ϕ ) p(\theta,\phi) p(θ,ϕ),可得雅克比行列式 J = ∣ c o s θ 0 0 1 ∣ = c o s θ J=\begin{vmatrix} cos\theta & 0 \\ 0 & 1 \\ \end{vmatrix}=cos\theta J=cosθ001=cosθ
因此 p ( θ , ϕ ) = J p ( sin ⁡ θ , ϕ ) = s i n θ c o s θ π p(\theta,\phi)=Jp(\sin\theta,\phi)=\frac{sin\theta cos\theta}{\pi} p(θ,ϕ)=Jp(sinθ,ϕ)=πsinθcosθ
这说明这种方法采样得到的结果是符合Cosine-Weighted采样要求的。

你可能感兴趣的:(计算机图形学)