☰ Navigation
Beckmann Distribution
The normals of the microfacets are distributed according to the Beckmann distribution:
D ( ω ) = 1 π a b 2 cos 4 θ exp − tan 2 θ a b 2 D ( θ , ϕ ) = sin θ π a b 2 cos 4 θ exp − tan 2 θ a b 2 \begin{aligned}
\operatorname{D}(\omega) &= \frac{1}{\pi a_b^2\cos^4\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}}\\
\operatorname{D}(\theta,\phi) &= \frac{\sin\theta}{\pi a_b^2\cos^4\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}}
\end{aligned} D ( ω ) D ( θ , ϕ ) = π a b 2 cos 4 θ 1 exp a b 2 − tan 2 θ = π a b 2 cos 4 θ sin θ exp a b 2 − tan 2 θ
Here is the result:
function sample_beckmann ( a ) {
const u_1 = Math. random ( ) ;
const u_2 = Math. random ( ) ;
const theta = Math. atan ( Math. sqrt ( - a * a * Math. log ( 1.0 - u_1) ) ) ;
const phi = u_2 * 2.0 * Math. PI ;
return [ theta, phi] ;
}
Algorithm
Sample microfacet normal according to the Beckmann distribution:
Choose uniform numbers u 1 , u 2 u_1, u_2 u 1 , u 2 in [ 0 , 1 ] [0,1] [ 0 , 1 ]
Calculate θ = tan − 1 ( − a b 2 log ( 1 − u 1 ) ) \theta = \tan^{-1}( \sqrt{-a_b^2\log (1-u_1)}) θ = tan − 1 ( − a b 2 log ( 1 − u 1 ) ) or θ = tan − 1 ( − a b 2 log ( u 1 ) ) \theta = \tan^{-1}( \sqrt{-a_b^2\log (u_1)}) θ = tan − 1 ( − a b 2 log ( u 1 ) )
Calculate ϕ = 2 π u 2 \phi = 2\pi u_2 ϕ = 2 π u 2
Optionally convert to cartesian coordinates with:
x = sin θ cos ϕ x = \sin\theta\cos\phi
x = sin θ cos ϕ
y = sin θ sin ϕ y = \sin\theta\sin\phi
y = sin θ sin ϕ
z = cos θ z = \cos\theta
z = cos θ
PDF Used In Monte Carlo Integration
p m ( ω ) = cos θ π a b 2 cos 4 θ exp − tan 2 θ a b 2 = 1 π a b 2 cos 3 θ exp − tan 2 θ a b 2 p_m(\omega) = \frac{\cos\theta}{\pi a_b^2\cos^4\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}} = \frac{1}{\pi a_b^2\cos^3\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}}
p m ( ω ) = π a b 2 cos 4 θ cos θ exp a b 2 − tan 2 θ = π a b 2 cos 3 θ 1 exp a b 2 − tan 2 θ
p m ( θ , ϕ ) = cos θ sin θ π a b 2 cos 4 θ exp − tan 2 θ a b 2 = tan θ π a b 2 cos 2 θ exp − tan 2 θ a b 2 p_m(\theta,\phi) = \frac{\cos\theta\sin\theta}{\pi a_b^2\cos^4\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}} = \frac{\tan\theta}{\pi a_b^2\cos^2\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}}
p m ( θ , ϕ ) = π a b 2 cos 4 θ cos θ sin θ exp a b 2 − tan 2 θ = π a b 2 cos 2 θ tan θ exp a b 2 − tan 2 θ
Derivation
Due to normalization, the densities are given as follows:
p ( ω ) = D ( ω ) cos θ p ( θ , ϕ ) = p ( ω ) sin θ = sin θ cos θ π a b 2 cos 4 θ exp − tan 2 θ a b 2 = tan θ π a b 2 cos 2 θ exp − tan 2 θ a b 2 \begin{aligned}
p(\omega) &= D(\omega)\cos\theta\\
p(\theta,\phi) &= p(\omega)\sin\theta\\
&= \frac{\sin\theta\cos\theta}{\pi a_b^2\cos^4\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}} \\
&= \frac{\tan\theta}{\pi a_b^2\cos^2\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}}
\end{aligned} p ( ω ) p ( θ , ϕ ) = D ( ω ) cos θ = p ( ω ) sin θ = π a b 2 cos 4 θ sin θ cos θ exp a b 2 − tan 2 θ = π a b 2 cos 2 θ tan θ exp a b 2 − tan 2 θ
Marginal And Conditional Densities:
p θ ( θ ) = ∫ 0 2 π p ( θ , ϕ ) d ϕ = ∫ 0 2 π tan θ π a b 2 cos 2 θ exp − tan 2 θ a b 2 d ϕ = 2 π tan θ π a b 2 cos 2 θ exp − tan 2 θ a b 2 = 2 tan θ a b 2 cos 2 θ exp − tan 2 θ a b 2 = 2 π p ( θ , ϕ ) \begin{aligned}
p_\theta(\theta) &= \int_0^{2\pi}p(\theta,\phi)d\phi \\
&=\int_0^{2\pi}\frac{\tan\theta}{\pi a_b^2\cos^2\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}} d\phi \\
&= 2\pi\frac{\tan\theta}{\pi a_b^2\cos^2\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}} \\
&= 2\frac{\tan\theta}{ a_b^2\cos^2\theta}\exp{\frac{-\tan^{2}\theta}{a_b^2}} \\
&= 2\pi p(\theta, \phi)
\end{aligned} p θ ( θ ) = ∫ 0 2 π p ( θ , ϕ ) d ϕ = ∫ 0 2 π π a b 2 cos 2 θ tan θ exp a b 2 − tan 2 θ d ϕ = 2 π π a b 2 cos 2 θ tan θ exp a b 2 − tan 2 θ = 2 a b 2 cos 2 θ tan θ exp a b 2 − tan 2 θ = 2 π p ( θ , ϕ )
p ( ϕ ∣ θ ) = p ( θ , ϕ ) p θ ( θ ) = p ( θ , ϕ ) 2 π p ( θ , ϕ ) = 1 2 π p(\phi \vert \theta) = \frac{p(\theta,\phi)}{p_\theta(\theta)} = \frac{p(\theta,\phi)}{2\pi p(\theta,\phi)} = \frac{1}{2\pi}
p ( ϕ ∣ θ ) = p θ ( θ ) p ( θ , ϕ ) = 2 π p ( θ , ϕ ) p ( θ , ϕ ) = 2 π 1
Compute CDFs
P θ ( θ ) = ∫ 0 θ 2 tan θ ′ a b 2 cos 2 θ ′ exp − tan 2 θ ′ a b 2 d θ ′ P_\theta(\theta) = \int_{0}^{\theta}2\frac{\tan\theta'}{ a_b^2\cos^2\theta'}\exp{\frac{-\tan^{2}\theta'}{a_b^2}}d\theta'
P θ ( θ ) = ∫ 0 θ 2 a b 2 cos 2 θ ′ tan θ ′ exp a b 2 − tan 2 θ ′ d θ ′
To solve this integral, we change variables and introduce u = tan θ ′ u = \tan\theta' u = tan θ ′ . That gives us d u = ( tan θ ′ ) ′ d θ ′ = 1 cos 2 θ ′ d θ ′ du = (\tan\theta')'d\theta' = \frac{1}{\cos^2\theta'}d\theta' d u = ( tan θ ′ ) ′ d θ ′ = c o s 2 θ ′ 1 d θ ′ . Solving for d u du d u (with the usual slight abuse of notation): d θ ′ = cos 2 θ ′ d u d\theta' = \cos^2\theta' du d θ ′ = cos 2 θ ′ d u .
As we will resubstitute later, for now let's disregard the limits:
P θ ( θ ) = ∫ 2 tan θ ′ a b 2 cos 2 θ ′ exp ( − tan 2 θ ′ a b 2 ) d θ ′ = 2 a b 2 ∫ u cos 2 θ ′ exp ( − u 2 a b 2 ) cos 2 θ ′ d u = 2 a b 2 ∫ u exp ( − u 2 a b 2 ) d u \begin{aligned}
P_\theta(\theta) &= \int 2\frac{\tan\theta'}{ a_b^2\cos^2\theta'}\exp{(\frac{-\tan^{2}\theta'}{a_b^2})} d\theta' \\
&= \frac{2}{a_b^2} \int \frac{u}{ \cos^2\theta'}\exp{(\frac{-u^{2}}{a_b^2})}\cos^2\theta' du\\
&= \frac{2}{a_b^2} \int u\exp{(\frac{-u^{2}}{a_b^2})} du
\end{aligned} P θ ( θ ) = ∫ 2 a b 2 cos 2 θ ′ tan θ ′ exp ( a b 2 − tan 2 θ ′ ) d θ ′ = a b 2 2 ∫ cos 2 θ ′ u exp ( a b 2 − u 2 ) cos 2 θ ′ d u = a b 2 2 ∫ u exp ( a b 2 − u 2 ) d u
The integral can now be solved by basic means by considering the derivative of the exponential.
P θ ( θ ) = 2 a b 2 ∫ u exp ( − u 2 a b 2 ) d u = 2 a b 2 [ − 1 2 a b 2 exp ( − u 2 a b 2 ) ] = − [ exp ( − u 2 a b 2 ) ] \begin{aligned}
P_\theta(\theta) &= \frac{2}{a_b^2} \int u\exp{(\frac{-u^{2}}{a_b^2})} du\\
&= \frac{2}{a_b^2} [-\frac{1}{2}a_b^2\exp(\frac{-u^2}{a_b^2})] \\
&= -[\exp(\frac{-u^2}{a_b^2})]
\end{aligned} P θ ( θ ) = a b 2 2 ∫ u exp ( a b 2 − u 2 ) d u = a b 2 2 [ − 2 1 a b 2 exp ( a b 2 − u 2 )] = − [ exp ( a b 2 − u 2 )]
Resubstituting u = tan θ ′ u = \tan\theta' u = tan θ ′ :
P θ ( θ ) = 2 a b 2 ∫ u exp ( − u 2 a b 2 ) d u = − [ exp ( − tan 2 θ ′ a b 2 ) ] 0 θ = − ( exp ( − tan 2 θ a b 2 ) − exp ( − tan 2 0 a b 2 ) ) = − ( exp ( − tan 2 θ a b 2 ) − 1 ) = 1 − exp ( − tan 2 θ a b 2 ) \begin{aligned}
P_\theta(\theta) &= \frac{2}{a_b^2} \int u\exp{(\frac{-u^{2}}{a_b^2})} du\\
&= -[\exp(\frac{-\tan^2\theta'}{a_b^2})]_0^{\theta}\\
&= -(\exp(\frac{-\tan^2\theta}{a_b^2}) - \exp(\frac{-\tan^20}{a_b^2}) ) \\
&= -(\exp(\frac{-\tan^2\theta}{a_b^2}) - 1 ) \\
&= 1- \exp(\frac{-\tan^2\theta}{a_b^2})
\end{aligned} P θ ( θ ) = a b 2 2 ∫ u exp ( a b 2 − u 2 ) d u = − [ exp ( a b 2 − tan 2 θ ′ ) ] 0 θ = − ( exp ( a b 2 − tan 2 θ ) − exp ( a b 2 − tan 2 0 )) = − ( exp ( a b 2 − tan 2 θ ) − 1 ) = 1 − exp ( a b 2 − tan 2 θ )
P ( ϕ ∣ θ ) = ∫ 0 ϕ p ( ϕ ′ ∣ θ ) d ϕ ′ = ∫ 0 ϕ 1 2 π d ϕ ′ = ϕ 2 π P(\phi \vert \theta) = \int_{0}^{\phi}p(\phi ' \vert \theta)d\phi' = \int_{0}^{\phi} \frac{1}{2\pi }d\phi' =\frac{\phi}{2\pi}
P ( ϕ ∣ θ ) = ∫ 0 ϕ p ( ϕ ′ ∣ θ ) d ϕ ′ = ∫ 0 ϕ 2 π 1 d ϕ ′ = 2 π ϕ
Invert CDFs
u 1 = P θ ( θ ) = 1 − exp ( − tan 2 θ a b 2 ) u 1 − 1 = − exp ( − tan 2 θ a b 2 ) 1 − u 1 = exp ( − tan 2 θ a b 2 ) log ( 1 − u 1 ) = − tan 2 θ a b 2 − a b 2 log ( 1 − u 1 ) = tan 2 θ − a b 2 log ( 1 − u 1 ) = tan θ tan − 1 ( − a b 2 log ( 1 − u 1 ) ) = θ θ = tan − 1 ( − a b 2 log ( 1 − u 1 ) ) \begin{aligned}
u_1 &= P_\theta(\theta)\\
&= 1- \exp(\frac{-\tan^2\theta}{a_b^2}) \\
u_1 - 1 &=- \exp(\frac{-\tan^2\theta}{a_b^2}) \\
1- u_1 &= \exp(\frac{-\tan^2\theta}{a_b^2}) \\
\log (1-u_1) &= \frac{-\tan^2\theta}{a_b^2} \\
-a_b^2\log (1-u_1)&= \tan^2\theta \\
\sqrt{-a_b^2\log (1-u_1)}&= \tan\theta \\
\tan^{-1}( \sqrt{-a_b^2\log (1-u_1)}) &= \theta\\
\theta &=\tan^{-1}( \sqrt{-a_b^2\log (1-u_1)})
\end{aligned} u 1 u 1 − 1 1 − u 1 log ( 1 − u 1 ) − a b 2 log ( 1 − u 1 ) − a b 2 log ( 1 − u 1 ) tan − 1 ( − a b 2 log ( 1 − u 1 ) ) θ = P θ ( θ ) = 1 − exp ( a b 2 − tan 2 θ ) = − exp ( a b 2 − tan 2 θ ) = exp ( a b 2 − tan 2 θ ) = a b 2 − tan 2 θ = tan 2 θ = tan θ = θ = tan − 1 ( − a b 2 log ( 1 − u 1 ) )
Since u 1 u_1 u 1 is uniformly distributed in [ 0 , 1 ] [0,1] [ 0 , 1 ] , so is 1 − u 1 1-u_1 1 − u 1 , so we can use either of them for the generation.
u 2 = P ( ϕ ∣ θ ) = ϕ 2 π ϕ = u 2 2 π \begin{aligned}
u_2 &= P(\phi \vert \theta) \\
&= \frac{\phi}{2\pi}\\
\phi &= u_22\pi
\end{aligned} u 2 ϕ = P ( ϕ ∣ θ ) = 2 π ϕ = u 2 2 π