Graphics Reference
In-Depth Information
In code, we might see this:
x = uniform(0, 1);
y = uniform(0, 1); // U = (x, y)
x =2 * π
1
2
3
4
5
* x;
y =y;
// V= (x', y')
x ,
y )
(
return
There's no mention of the pdf in the code, but it matters nonetheless when we
want to analyze the code.
30.3.8 Application to Scattering
The ability to easily draw samples from a distribution (i.e., to produce many inde-
pendent random variables all having the same specified pdf) will be critical in
rendering. In estimating the reflectance integral, we sometimes want to pick a ran-
dom direction
in the positive hemisphere with probability density proportional
to the bidirectional reflectance distribution function (BRDF), with the first argu-
ment held constant at the incoming direction, that is, the function
v
) .
(Notice that this function is not in general a probability density on the hemisphere:
Its integral is not 1.) Unfortunately, sampling in proportion to a general function
on the hemisphere is not often easy.
We now examine two examples where such direct sampling is possible.
Example 1: The Lambertian BRDF. We need to choose a direction on the
hemisphere uniformly at random (i.e., the probability that the direction lies in any
solid angle Ω
v
f r (
v i ,
v
S + is proportional to the measure of Ω .) In fact, since the total
area of the hemisphere is 2
, we need the probability that the direction lies in a
solid angle Ω to be exactly m (Ω)
2 π
π
.
Fortunately, as we saw in Section 26.6.4, the map
( x 1
y 2 , y , z 1
g :( x , y , z )
y 2 )
(30.44)
from the unit cylinder around the y -axis to the unit sphere is area-preserving
(although it's not length- or angle-preserving). By restricting our attention to the
half-cylinder
( x , y , z ): x 2 + z 2 = 1, 0
H =
{
y
1
}
,
(30.45)
we get an area-preserving map from H to S + . And the map
f :[ 0, 1 ]
×
[ 0, 1 ]
H :( u , v )
(cos( 2
π
u ) , v , sin( 2
π
u ))
(30.46)
multiplies areas by exactly 2
π
, as you can check by computing its Jacobian. So
the composition Y = g
f of the two gives us a map from the unit square to
S + that multiplies areas by 2
π
. The density for Y is therefore the constant function
on S + .
In the program shown in Listing 30.2, the returned point is a random point on
the hemisphere with density
1
2 π
1
.
π
2
Listing 30.2: Producing a uniformly distributed random sample on a hemisphere.
1
2
3
4
5
Point3 randhemi()
u = uniform(0, 1)
v = uniform(0, 1)
r = sqrt(1 - y * y)
return Point3( r cos( 2 π u ) , y , r sin( 2 π u ) );
 
 
 
Search WWH ::




Custom Search