Phong Distribution
The normals of the microfacets are distributed according to the Phong Distribution:
D(ω)D(θ,ϕ)=2πap+2cosapθ=2πap+2cosapθsinθ
Walter et al. recommend a relation between the Beckmann ab and the phong ap:
ap=2ab−2−2
Here is the result:
function pow_cos_hemisphere_cap(theta_max,n){
const u_1 = Math.random();
const u_2 = Math.random();
const theta = Math.acos(Math.pow(
1.0 - u_1 * (1.0 - Math.pow(Math.cos(theta_max),n+1)),
1.0/(n+1)));
const phi = u_2 * 2.0 * Math.PI;
return [theta,phi];
}
function beckmann_width_to_phong(a) {
return 2.0 / (a*a) - 2.0;
}
function sample_phong_normal(a) {
return pow_cos_hemisphere_cap(Math.PI / 2.0, a + 1);
}
Algorithm
Sample microfacet normal according to the Phong distribution:
- Choose uniform numbers u1,u2 in [0,1]
- Calculate θ=cos−1(ap+21−u1) or θ=cos−1(ap+2u1)
- Calculate ϕ=2πu2
Optionally convert to cartesian coordinates with:
x=sinθcosϕ
y=sinθsinϕ
z=cosθ
PDF Used In Monte Carlo Integration
pm(ω)=2πap+2cosapθcosθ=2πap+2cosap+1θ
pm(θ,ϕ)=2πap+2cosapθcosθsinθ=2πap+2cosap+1θsinθ
Derivation
This distribution is just a special case of the power cosine hemisphere cap above, but with
θmax=2π,n=ap+1
p(ω)=2π(1−cosn+1θmax)n+1cosnθ=2πn+1cosnθ=2πap+2cosap+1θ
The formula given by Walter et al. comes from replacing 1−u1 by u1, since both are uniformly distributed within [0,1].