Clean up the sampling code a little.

All of the samplers were using the same scramble value, so I
factored it out and documented its intent.
This commit is contained in:
Nathan Vegdahl 2020-03-16 10:11:14 +09:00
parent 5114d428da
commit d49a1c4921

View File

@ -692,7 +692,10 @@ impl LightPath {
/// LDS samples aren't available. /// LDS samples aren't available.
#[inline(always)] #[inline(always)]
fn get_sample(dimension: u32, i: u32, pixel_co: (u32, u32), seed: u32) -> f32 { fn get_sample(dimension: u32, i: u32, pixel_co: (u32, u32), seed: u32) -> f32 {
let pixel_id = pixel_co.0 ^ (pixel_co.1 << 16); // A unique random scramble value for every pixel coordinate up to
// a resolution of 65536 x 65536. Also further randomized by a seed.
let scramble = hash_u32(pixel_co.0 ^ (pixel_co.1 << 16), seed);
match dimension { match dimension {
0 => { 0 => {
// Golden ratio sampling. // Golden ratio sampling.
@ -700,19 +703,17 @@ fn get_sample(dimension: u32, i: u32, pixel_co: (u32, u32), seed: u32) -> f32 {
// due to the nature of hero wavelength sampling this ends up // due to the nature of hero wavelength sampling this ends up
// being crazily more efficient than pretty much any other sampler, // being crazily more efficient than pretty much any other sampler,
// and reduces variance by a huge amount. // and reduces variance by a huge amount.
let scramble = hash_u32(pixel_id, seed);
let n = i.wrapping_add(scramble).wrapping_mul(2654435769); let n = i.wrapping_add(scramble).wrapping_mul(2654435769);
n as f32 * (1.0 / (1u64 << 32) as f32) n as f32 * (1.0 / (1u64 << 32) as f32)
} }
n if (n - 1) < sobol::MAX_DIMENSION as u32 => { n if (n - 1) < sobol::MAX_DIMENSION as u32 => {
// Sobol sampling. // Sobol sampling.
let scramble = hash_u32(pixel_id, seed);
sobol::sample_owen(dimension - 1, i, hash_u32(dimension, scramble)) sobol::sample_owen(dimension - 1, i, hash_u32(dimension, scramble))
} }
_ => { _ => {
// Random sampling. // Random sampling.
use crate::hash::hash_u32_to_f32; use crate::hash::hash_u32_to_f32;
hash_u32_to_f32(dimension ^ (i << 16), hash_u32(pixel_id, seed)) hash_u32_to_f32(dimension ^ (i << 16), scramble)
} }
} }
} }