4
votes

I'm attempting to implement soft shadows in my raytracer. To do so, I plan to shoot multiple shadow rays from the intersection point towards the area light source. I'm aiming to use a spherical area light--this means I need to generate random points on the sphere for the direction vector of my ray (recall that ray's are specified with a origin and direction).

I've looked around for ways to generate a uniform distribution of random points on a sphere, but they seem a bit more complicated than what I'm looking for. Does anyone know of any methods for generating these points on a sphere? I believe my sphere area light source will simply be defined by its XYZ world coordinates, RGB color value, and r radius.

Thanks and I appreciate the help!

2
I believe you are solving the wrong problem here; you don't actually want uniform points on a sphere (which would put most of the intensity near the edge of the sphere) but rather uniform points on a the circle seen by the point.tjltjl

2 Answers

5
votes

Graphics Gems III, page 126:

void random_unit_vector(double v[3]) {    
    double theta = random_double(2.0 * PI);
    double x = random_double(2.0) - 1.0;
    double s = sqrt(1.0 - x * x);
    v[0] = x;
    v[1] = s * cos(theta);
    v[2] = s * sin(theta);
}

(This is the second of four methods given in MathWorld's Sphere Point Picking article.)

ETA: If a sphere of radius r is centred at O, and u is a random unit vector, then a random point on the surface of the sphere is given by O + r u.

0
votes

A lot of good formulae for random distributions are found in the Global Illumination Compendium. Part 4.B. has formulae for generating points on a (hemi) sphere. It's a great reference for sampling, integration, etc.