Graphics Reference
In-Depth Information
Example 2: Cosine-weighted sampling on a hemisphere. Now suppose that
we want to sample from a hemisphere, but we want the probability of picking a
point in the neighborhood of
n , where n = 010 T
is the unit normal to the xz -plane that bounds the hemisphere. If we write
v ·
v
to be proportional to
=
v
xyz , then
n is simply y .
The function ( x , y , z )
v ·
y is not a probability density on the hemisphere y
0,
y
π
because its integral is
is a pdf. We'd now like
to sample from this pdf (i.e., we'd like to create a random-point Y whose distribu-
tion is this pdf). Because of the area-preserving property of the radial projection
map, we can instead choose a random point on the half-cylinder, with density
π
rather than 1.0. Thus, ( x , y , z )
y
π
,
and then project to the hemisphere.
Because the density is independent of the angular coordinate on the cylinder,
all we need to do is to generate values of y
[ 0, 1 ] whose density is proportional
to y . The computation following E quation 30.26 shows that if U is uniformly
distributed on [ 0, 1 ] , then W = U is linearly distributed, that is, the probability
density for W at t
[ 0, 1 ] is 2 t .
Listing 30.3 shows the resultant code.
Listing 30.3: Producing a cosine-distributed random sample on a hemisphere.
1
2
3
4
5
6
point3 = randhemi()
θ = uniform(0, 2 * M_PI)
s = uniform(0, 1)
y = sqrt(s)
r = sqrt(1 - y 2 )
return Point3( r
cos( θ ) , y , r
sin( θ ) )
So certain distributions, like the uniform and the cosine-weighted ones, are
easy to sample from. More general distributions are often not. When we design
reflectance models (i.e., families of BRDFs that can be fit to observed data), one
of the criteria, naturally, is goodness of fit: “Is our family rich enough to contain
functions that match the observed data decently?” Another criterion is, “Once we
fit our data, will we be able to sample from the resultant distributions effectively?”
The two criteria are somewhat related, as described by Lawrence et al. [LRR04],
who propose a factored BRDF model from which it's easy to do effective impor-
tance sampling.
30.4 Continuum Probability, Continued
We're now going to talk about ways to estimate the expected value of a continuum
random variable, and using these to evaluate integrals. This is important because
in rendering, we're going to want to evaluate the reflectance integral,
v o )=
v i S +
L ref ( P ,
L ( P ,
v i ) f s ( P ,
v i ,
v o )
v i ·
n d
v i ,
(30.47)
for various values of P and
v o . Knowing how to build a random variable whose
expected value is exactly this integral will be a big help in this evaluation.
We saw that code that generated a random number uniformly distributed on
[ 0, 1 ] and took its square root produced a value between 0 and 1 whose e xpected
value was
3 . This also happens to be the average value of f ( x )= x on that
interval. This wasn't just a coincidence, as the following theorem shows.
2
 
 
 
Search WWH ::




Custom Search