i
i
i
i
i
i
i
i
25.5. Rough Layered Model 649
compute the exponent, so the specular BRDF can be written:
ρ(k
1
, k
2
)=
(n
u
+1)(n
v
+1)
8π
(n · h)
(n
u
(h·u)
2
+n
v
(h·v)
2
)/(1−(hn)
2
)
(h·k
i
)max(cos θ
i
,cos θ
o
)
F (k
i
·h).
(25.9)
In a Monte Carlo setting, we are interested in the following problem: given k
1
,
generate samples of k
2
with a distribution whose shape is similar to the cosine-
weighted BRDF. Note that greatly undersampling a large value of the integrand is
a serious error, while greatly oversampling a small value is acceptable in practice.
The reader can verify that the densities suggested below have this property.
A suitable way to construct a pdf for sampling is to consider the distribution
of half vectors that would give rise to our BRDF. Such a function is
p
h
(h)=
(n
u
+1)(n
v
+1)
2π
(nh)
n
u
cos
2
φ+n
v
sin
2
φ
, (25.10)
where the constants are chosen to ensure it is a valid pdf.
We can just use the probability density function p
h
(h) of Equation (25.10) to
generate a random h. However, to evaluate the rendering equation, we need both
areflected vector k
o
and a probability density function p(k
o
). It is important to
note that if you generate h according to p
h
(h) and then transform to the resulting
k
o
:
k
o
= −k
i
+2(k
i
·h)h, (25.11)
the density of the resulting k
o
is not p
h
(k
o
). This is because of the difference in
measures in h and k
o
. So the actual density p(k
o
) is
p(k
o
)=
p
h
(h)
4(k
i
h)
. (25.12)
Note that in an implementation where the BRDF is known to be this model, the
estimate of the rendering equation is quite simple as many terms cancel out.
It is possible to generate an h vector whose corresponding vector k
o
will point
inside the surface, i.e., cos θ
o
< 0. The weight of such a sample should be set
to zero. This situation corresponds to the specular lobe going below the horizon
and is the main source of energy loss in the model. Clearly, this problem becomes
progressively less severe as n
u
, n
v
become larger.
The only thing left now is to describe how to generate h vectors with the pdf
of Equation (25.10). We will start by generating h with its spherical angles in
the range (θ, φ) ∈ [0,
π
2
] × [0,
π
2
]. Note that this is only the first quadrant of the
hemisphere. Given two random numbers (ξ
1
,ξ
2
) uniformly distributed in [0, 1],
we can choose
φ =arctan
n
u
+1
n
v
+1
tan
πξ
1
2
, (25.13)