Compiler2 min read

Sampling Module

Low-discrepancy sequences, disk/sphere/hemisphere sampling, and GGX sampling PDFs.

Reading Time
2 min
Word Count
220
Sections
6
Try It Live

Turn the guide into code

Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.

Open Playground

Low-discrepancy sequences, disk/sphere/hemisphere sampling, and GGX sampling PDFs.

Import

bwsl
import Sampling

This module imports: Math, Random, Spaces.

Constants

const float INV_UINT_MAX = 2.3283064365386963e-10

Structs

No structs found.

Enums

No enums found.

Functions

radical_inverse_vdc

Reference: https://en.wikipedia.org/wiki/Van_der_Corput_sequence

bwsl
radical_inverse_vdc :: (uint bits) -> float

hammersley

Reference: https://en.wikipedia.org/wiki/Low-discrepancy_sequence

bwsl
hammersley :: (uint index, uint count) -> float2

seeded_2d

Returns a deterministic random 2D sample from a seed and sequence index.

bwsl
seeded_2d :: (uint seed, uint index) -> float2

uniform_disk

Reference: https://en.wikipedia.org/wiki/Polar_coordinate_system

bwsl
uniform_disk :: (float2 xi) -> float2

uniform_circle

Maps a scalar sample to a point on the unit circle.

bwsl
uniform_circle :: (float xi) -> float2

uniform_sphere

Reference: https://en.wikipedia.org/wiki/Sphere#Spherical_coordinates

bwsl
uniform_sphere :: (float2 xi) -> float3

uniform_hemisphere_z

Maps a uniform square sample to a local +Z hemisphere direction.

bwsl
uniform_hemisphere_z :: (float2 xi) -> float3

cosine_hemisphere_z

Reference: https://www.pbr-book.org/4ed/Sampling_Algorithms/Sampling_Multidimensional_Functions

bwsl
cosine_hemisphere_z :: (float2 xi) -> float3

uniform_hemisphere

Maps a uniform square sample to a world-space hemisphere direction around normal.

bwsl
uniform_hemisphere :: (float2 xi, float3 normal) -> float3

cosine_hemisphere

Maps a uniform square sample to a cosine-weighted world-space hemisphere direction around normal.

bwsl
cosine_hemisphere :: (float2 xi, float3 normal) -> float3

ggx_half_vector_z

Background: https://pharr.org/matt/blog/2022/05/06/trowbridge-reitz.html

bwsl
ggx_half_vector_z :: (float2 xi, float roughness) -> float3

ggx_half_vector

Reference: https://en.wikipedia.org/wiki/Specular_highlight#Microfacet_models

bwsl
ggx_half_vector :: (float2 xi, float roughness, float3 normal) -> float3

cosine_hemisphere_pdf

Returns the PDF for cosine-weighted hemisphere sampling.

bwsl
cosine_hemisphere_pdf :: (float cosTheta) -> float

uniform_sphere_pdf

Returns the constant PDF for uniform sphere sampling.

bwsl
uniform_sphere_pdf :: () -> float

uniform_hemisphere_pdf

Returns the constant PDF for uniform hemisphere sampling.

bwsl
uniform_hemisphere_pdf :: () -> float

ggx_ndf

Reference: https://en.wikipedia.org/wiki/Specular_highlight#Microfacet_models

bwsl
ggx_ndf :: (float NdotH, float roughness) -> float

ggx_reflection_pdf

Returns the reflected-direction PDF for GGX half-vector sampling.

bwsl
ggx_reflection_pdf :: (float NdotH, float VdotH, float roughness) -> float

Source

Generated from compiler-reference/modules/Sampling.bwsl.