MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / sample_cosine_hemisphere

Function sample_cosine_hemisphere

tools/bloom-reference/src/main.rs:1185–1192  ·  view source on GitHub ↗

Cosine-weighted hemisphere sample, used for diffuse direction sampling. `rand` is two uniform samples in [0, 1)².

(rand: Vec2)

Source from the content-addressed store, hash-verified

1183/// Cosine-weighted hemisphere sample, used for diffuse direction
1184/// sampling. `rand` is two uniform samples in [0, 1)².
1185fn sample_cosine_hemisphere(rand: Vec2) -> Vec3 {
1186 let r = rand.x.sqrt();
1187 let theta = 2.0 * std::f32::consts::PI * rand.y;
1188 let x = r * theta.cos();
1189 let y = r * theta.sin();
1190 let z = (1.0 - rand.x).max(0.0).sqrt();
1191 Vec3::new(x, y, z)
1192}
1193
1194/// GGX VNDF sample — Heitz 2018 "Sampling the GGX Distribution of
1195/// Visible Normals". Gives better low-variance estimates than sampling

Callers 1

sample_brdfFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected