Search code examples
c++graphicsgeometryraytracing

Soft Shadows: Spherical Area Light Source


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!


Solution

  • 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.