Move seed hashing into the lk_scramble function.

This commit is contained in:
Nathan Vegdahl 2020-04-23 13:36:04 +09:00
parent c0a8c955c4
commit 29fcc69ae1
2 changed files with 9 additions and 7 deletions

View File

@ -15,7 +15,6 @@ use crate::{
accel::ACCEL_NODE_RAY_TESTS, accel::ACCEL_NODE_RAY_TESTS,
color::{map_0_1_to_wavelength, SpectralSample, XYZ}, color::{map_0_1_to_wavelength, SpectralSample, XYZ},
fp_utils::robust_ray_origin, fp_utils::robust_ray_origin,
hash::hash_u32,
hilbert, hilbert,
image::Image, image::Image,
math::{probit, upper_power_of_two}, math::{probit, upper_power_of_two},
@ -703,7 +702,7 @@ impl LightPath {
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 {
// A unique seed for every pixel coordinate up to a resolution of // A unique seed for every pixel coordinate up to a resolution of
// 65536 x 65536. Also incorperating the seed. // 65536 x 65536. Also incorperating the seed.
let seed = hash_u32(pixel_co.0 ^ (pixel_co.1 << 16), seed); let seed = pixel_co.0 ^ (pixel_co.1 << 16) ^ seed.wrapping_mul(0x736caf6f);
match dimension { match dimension {
d if d < sobol::MAX_DIMENSION as u32 => { d if d < sobol::MAX_DIMENSION as u32 => {

View File

@ -17,11 +17,14 @@ include!(concat!(env!("OUT_DIR"), "/vectors.inc"));
pub fn sample(dimension: u32, index: u32, seed: u32) -> f32 { pub fn sample(dimension: u32, index: u32, seed: u32) -> f32 {
// This index shuffling approach is due to Brent Burley, and is // This index shuffling approach is due to Brent Burley, and is
// what allows us to create statistically independent Sobol sequences. // what allows us to create statistically independent Sobol sequences.
let shuffled_rev_index = lk_scramble(index.reverse_bits(), hash(seed, 2)); let shuffled_rev_index = lk_scramble(index.reverse_bits(), seed);
let scramble = hash(dimension ^ seed, 2); let sobol = lk_scramble(
sobol_u32_rev(dimension, shuffled_rev_index),
dimension ^ seed,
)
.reverse_bits();
let sobol = lk_scramble(sobol_u32_rev(dimension, shuffled_rev_index), scramble).reverse_bits();
u32_to_0_1_f32(sobol) u32_to_0_1_f32(sobol)
} }
@ -77,7 +80,7 @@ fn lk_scramble(mut n: u32, scramble: u32) -> u32 {
// process to maximize low-bias avalanche between bits. // process to maximize low-bias avalanche between bits.
const PERMS: [u32; 3] = [0x97b756bc, 0x4b0a8a12, 0x75c77e36]; const PERMS: [u32; 3] = [0x97b756bc, 0x4b0a8a12, 0x75c77e36];
n = n.wrapping_add(scramble); n = n.wrapping_add(hash(scramble, 2));
for &p in PERMS.iter() { for &p in PERMS.iter() {
n ^= n.wrapping_mul(p); n ^= n.wrapping_mul(p);
n += n << 1; n += n << 1;
@ -94,7 +97,7 @@ fn lk_scramble(mut n: u32, scramble: u32) -> u32 {
#[allow(dead_code)] #[allow(dead_code)]
#[inline] #[inline]
fn lk_scramble_slow(mut n: u32, scramble: u32) -> u32 { fn lk_scramble_slow(mut n: u32, scramble: u32) -> u32 {
n = n.wrapping_add(scramble); n = n.wrapping_add(hash(scramble, 3));
for i in 0..31 { for i in 0..31 {
let low_mask = (1u32 << i).wrapping_sub(1); let low_mask = (1u32 << i).wrapping_sub(1);
let low_bits_hash = hash((n & low_mask) ^ hash(i, 3), 3); let low_bits_hash = hash((n & low_mask) ^ hash(i, 3), 3);