Random module

Random number generation, generation of points and directions, Monte Carlo utilities.

The Random module provides a random number generator suitable for ray tracing (based on the PCG32 random number generator), and several functions to generate points and directions useful in path tracing and procedural generation.

Classes

class RNG
Pseudorandom number generator.

Global RNG and rejection sampling

auto randf() -> float
Global random number generator that produces floats between [0,1)
auto random_in_unit_sphere() -> Vec3f
Sample a random point uniformly within a unit sphere (uses the global randf() RNG and rejection sampling)
auto random_in_unit_disk() -> Vec2f
Sample a random point uniformly within a unit disk (uses the global randf() RNG and rejection sampling)

Sampling a circle and disk

auto sample_circle(float rv) -> Vec2f
Uniformly sample a point on a unit circle, centered at the origin.
auto sample_circle_pdf() -> float
Probability density of sample_circle()
auto sample_disk(const Vec2f& rv) -> Vec2f
Uniformly sample a vector on a 2D disk with radius 1, centered around the origin.
auto sample_disk_pdf(const Vec2f& p) -> float
Probability density of sample_disk()

Sampling a sphere or a ball

auto sample_sphere(const Vec2f& rv) -> Vec3f
Uniformly sample a vector on the unit 3D sphere with respect to solid angles.
auto sample_sphere_pdf() -> float
Probability density of sample_sphere()
auto sample_4sphere(const Vec4f& rv) -> Vec4f
Uniformly sample a vector on a unit 4-dimensional hypersphere using Marsaglia's (1972) method.
auto sample_4sphere_pdf() -> float
Probability density of sample_4sphere()

Sampling the hemisphere

auto sample_hemisphere(const Vec2f& rv) -> Vec3f
Uniformly sample a vector on the unit hemisphere around the pole (0,0,1) with respect to solid angles.
auto sample_hemisphere_pdf(const Vec3f& v) -> float
Probability density of sample_hemisphere()
auto sample_hemisphere_cosine(const Vec2f& rv) -> Vec3f
Uniformly sample a vector on the unit hemisphere around the pole (0,0,1) with respect to projected solid angles.
auto sample_hemisphere_cosine_pdf(const Vec3f& v) -> float
Probability density of sample_hemisphere_cosine()
auto sample_hemisphere_cosine_power(float exponent, const Vec2f& rv) -> Vec3f
Sample a vector on the unit hemisphere with a cosine-power density about the pole (0,0,1)
auto sample_hemisphere_cosine_power_pdf(float exponent, float cosine) -> float
Probability density of sample_hemisphere_cosine_power()

Function documentation

float randf()

Global random number generator that produces floats between [0,1)

Vec3f random_in_unit_sphere()

Sample a random point uniformly within a unit sphere (uses the global randf() RNG and rejection sampling)

Vec2f random_in_unit_disk()

Sample a random point uniformly within a unit disk (uses the global randf() RNG and rejection sampling)

Vec2f sample_circle(float rv)

Uniformly sample a point on a unit circle, centered at the origin.

float sample_circle_pdf()

Probability density of sample_circle()

Vec2f sample_disk(const Vec2f& rv)

Uniformly sample a vector on a 2D disk with radius 1, centered around the origin.

float sample_disk_pdf(const Vec2f& p)

Probability density of sample_disk()

Vec3f sample_sphere(const Vec2f& rv)

Uniformly sample a vector on the unit 3D sphere with respect to solid angles.

float sample_sphere_pdf()

Probability density of sample_sphere()

Vec4f sample_4sphere(const Vec4f& rv)

Uniformly sample a vector on a unit 4-dimensional hypersphere using Marsaglia's (1972) method.

float sample_4sphere_pdf()

Probability density of sample_4sphere()

Vec3f sample_hemisphere(const Vec2f& rv)

Uniformly sample a vector on the unit hemisphere around the pole (0,0,1) with respect to solid angles.

float sample_hemisphere_pdf(const Vec3f& v)

Probability density of sample_hemisphere()

Vec3f sample_hemisphere_cosine(const Vec2f& rv)

Uniformly sample a vector on the unit hemisphere around the pole (0,0,1) with respect to projected solid angles.

float sample_hemisphere_cosine_pdf(const Vec3f& v)

Probability density of sample_hemisphere_cosine()

Vec3f sample_hemisphere_cosine_power(float exponent, const Vec2f& rv)

Sample a vector on the unit hemisphere with a cosine-power density about the pole (0,0,1)

float sample_hemisphere_cosine_power_pdf(float exponent, float cosine)

Probability density of sample_hemisphere_cosine_power()