Cosine-weighted hemisphere sample, used for diffuse direction sampling. `rand` is two uniform samples in [0, 1)².
(rand: Vec2)
| 1183 | /// Cosine-weighted hemisphere sample, used for diffuse direction |
| 1184 | /// sampling. `rand` is two uniform samples in [0, 1)². |
| 1185 | fn 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 |