samplers


class sampler_t : public wt::scene::scene_element_t

Samplers handle generating random numbers. Generators are expected to be thread-safe.

Subclassed by wt::sampler::sobolld_t, wt::sampler::uniform_t

Public Functions

inline sampler_t(std::string id)
virtual ~sampler_t() noexcept = default
sampler_t(sampler_t&&) = default
sampler_t(const sampler_t&) = default
virtual f_t r() noexcept = 0

Draws samples from the sampler.

Returns:

f_t a single sample

virtual vec2_t r2() noexcept = 0

Draws samples from the sampler.

Returns:

vec2_t two sample

virtual vec3_t r3() noexcept = 0

Draws samples from the sampler.

Returns:

vec3_t three samples sample

virtual vec4_t r4() noexcept = 0

Draws samples from the sampler.

Returns:

vec4_t four sample

template<bool normalized = false, std::regular_invocable<int> PF>
inline constexpr std::pair<f_t, std::size_t> discrete(std::size_t count, PF pb) noexcept

Samples a value from a discrete distribution.

Parameters:

pb – lambda giving the probability of an event index (may be unnormalized)

Template Parameters:

normalized – are the pb-s normalized

Returns:

probability and drawn event index pair

template<int N, bool normalized = false, typename T = f_t>
inline constexpr std::pair<f_t, std::size_t> discrete(const std::array<T, N> &ps) noexcept

Samples a value from a discrete distribution.

Parameters:

ps – array of probabilities (may be unnormalized)

Template Parameters:

normalized – are the ps-s normalized

Returns:

probability and drawn event index pair

inline constexpr f_t uniform_int_interval(int start, int end) noexcept

Samples a random integer in [start,end)

inline auto uniform_hemisphere() noexcept

Samples a point on the unit hemisphere uniformly w.r.t. solid angle.

inline auto uniform_sphere() noexcept

Samples a point on the unit sphere uniformly w.r.t. solid angle.

inline auto concentric_disk() noexcept

Samples a point on the unit disk uniformly w.r.t. area.

inline auto cosine_hemisphere() noexcept

Samples a point on the unit sphere uniformly w.r.t. cosine-weighted solid angle.

inline auto uniform_cone(f_t solid_angle) noexcept

Samples a point on a spherical cap uniformly w.r.t. solid angle.

Parameters:

solid_angle – solid angle of spherical cap

inline auto normal2d() noexcept

Samples a point from the 2D normal distribution (Box-Mueller)

inline auto uniform_triangle() noexcept

Samples at uniform a random point on a triangle.

Returns:

the barycentric coordinates

Public Static Functions

static inline constexpr std::string scene_element_class() noexcept
static inline auto uniform_hemisphere(vec2_t u) noexcept

Transforms a unit square into the unit hemisphere with uniform solid angle density.

Parameters:

u – ∈[0,1]² random unit square point

static inline constexpr auto uniform_hemisphere_pdf() noexcept

PDF of a point on the uniform unit hemisphere.

static inline auto uniform_sphere(const vec2_t &u) noexcept

Transforms a unit square into the unit sphere with uniform solid angle density.

Parameters:

u – ∈[0,1]² random unit square point

static inline constexpr auto uniform_sphere_pdf() noexcept

PDF of a point on the uniform unit sphere.

static inline constexpr auto concentric_disk(const vec2_t &u) noexcept

Transforms a unit square into a “concentric”-mapped unit disk with uniform area density.

Parameters:

u – ∈[0,1]² random unit square point

static inline constexpr auto concentric_disk_pdf() noexcept

PDF of a point on the uniform unit disk.

static inline auto cosine_hemisphere(const vec2_t &u) noexcept

Transforms a unit square into the unit sphere with cosine-weighted solid angle density.

Parameters:

u – ∈[0,1]² random unit square point

static inline constexpr auto cosine_hemisphere_pdf(const f_t cosine) noexcept

PDF of a point on the cosine-weighted unit sphere.

static inline auto uniform_cone(f_t solid_angle, const vec2_t &u) noexcept

Transforms a unit square into a spherical cap of some solid angle.

Parameters:
  • solid_angle – solid angle of spherical cap

  • u – ∈[0,1]² random unit square point

static inline constexpr auto uniform_cone_pdf(f_t solid_angle) noexcept

PDF of a point on a spherical cap.

Parameters:

solid_angle – solid angle of spherical cap

static inline constexpr auto normal2d(const vec2_t &u) noexcept

Transforms a unit square into the 2D normal distribution (Box-Mueller)

Parameters:

u – ∈[0,1]² random unit square point

static inline constexpr auto normal2d_pdf(const vec2_t &pt) noexcept

PDF of a normally-distributed point.

Parameters:

pt – normally-distributed point

static inline constexpr auto uniform_triangle(vec2_t u) noexcept

Transforms a unit square into a triangle.

Parameters:

u – ∈[0,1]² random unit square point

Returns:

the barycentric coordinates

static std::shared_ptr<sampler_t> load(std::string id, scene::loader::loader_t *loader, const scene::loader::node_t &node, const wt::wt_context_t &context)