[Bf-cycles] Why is PDF's normalized by fraction of PI instead of one?

storm kartochka22 at yandex.ru
Sun Nov 6 23:59:31 CET 2011

Most ( if not all) angle samplers use sample_cos_hemisphere(),
sample_uniform_sphere(), etc. functions from
intern/cycles/kernel/kernel_montecarlo.h. I use them too in volumetric
patch blindly copying by analogy from svn_diffuse.c.

They all take as agrument random values (u,v) and return normalized 3d
vector and pdf.

I have always been puzzled by the fact that pdf equation based on some
fraction of PI, for example:

__device_inline void sample_cos_hemisphere(const float3 N,
float randu, float randv, float3 *omega_in, float *pdf)
{
// Default closure BSDF implementation: uniformly sample
// cosine-weighted hemisphere above the point.
to_unit_disk(&randu, &randv);
float costheta = sqrtf(max(1.0f - randu * randu - randv * randv,
0.0f));
float3 T, B;
make_orthonormals(N, &T, &B);
*omega_in = randu * T + randv * B + costheta * N;
*pdf = costheta *M_1_PI_F;
}

Why pdf = costheta *M_1_PI_F instead of costheta * 1.0f ?

It make sense if our input random values (u,v) are actual angles and
have range [-PI,PI] or [0, 2*PI] but we use uniform random values in
rande [0..1] as input, so as result we have scaled pdf. If we sample
uniform sphere, it is 4*PI steradians and PDF is 1/(4*M_PI). Same for
half sphere, 2*PI steradians, but our random samples [0..1] isn't we
must treat area as 0.5 in our measurement domain ?

As I understend, MC integrator goal (if we use uniform sampling
probability) is just sum all sample values and divide by number of
samples. Imagine (u,v) as 2d square, PDF actually 1*1 = 1. Why it is
different for angles?