Use new fast hash for base-4 Owen scrambling.

This commit is contained in:
Nathan Vegdahl 2022-08-13 13:02:47 -07:00
parent c603e24633
commit 76781eb639
2 changed files with 19 additions and 3 deletions

View File

@ -18,7 +18,7 @@ use crate::{
mis::power_heuristic, mis::power_heuristic,
ray::Ray, ray::Ray,
scene::{Scene, SceneLightSample}, scene::{Scene, SceneLightSample},
scramble::owen4, scramble::owen4_fast,
space_fill::{hilbert_spiral, morton}, space_fill::{hilbert_spiral, morton},
timer::Timer, timer::Timer,
tracer::Tracer, tracer::Tracer,
@ -233,7 +233,7 @@ impl<'a> Renderer<'a> {
// and golden ratio sampling, we do this up-front here rather than in // and golden ratio sampling, we do this up-front here rather than in
// the samplers themselves. // the samplers themselves.
let si_offset = let si_offset =
owen4(morton::encode(x, y), self.seed).wrapping_mul(self.spp as u32); owen4_fast(morton::encode(x, y), self.seed).wrapping_mul(self.spp as u32);
for si in 0..(self.spp as u32) { for si in 0..(self.spp as u32) {
let mut sample_gen = SampleGen::new(si_offset + si, self.seed); let mut sample_gen = SampleGen::new(si_offset + si, self.seed);

View File

@ -16,7 +16,23 @@ pub fn owen2(n: u32, seed: u32) -> u32 {
result result
} }
/// Performs a base-4 Owen scramble on an integer. #[inline(always)]
pub fn owen4_fast(mut n: u32, seed: u32) -> u32 {
let scramble = hash(seed);
n = n.reverse_bits();
n ^= n.wrapping_mul(0x3d20adea);
n ^= (n >> 1) & (n << 1) & 0x55555555;
n = n.wrapping_add(scramble);
n = n.wrapping_mul((scramble >> 16) | 1);
n ^= (n >> 1) & (n << 1) & 0x55555555;
n ^= n.wrapping_mul(0x05526c56);
n ^= n.wrapping_mul(0x53a22864);
n.reverse_bits()
}
pub fn owen4(n: u32, seed: u32) -> u32 { pub fn owen4(n: u32, seed: u32) -> u32 {
// Bit-packed permutation table. // Bit-packed permutation table.
const PERMUTATION_TABLE: [u8; 24] = [ const PERMUTATION_TABLE: [u8; 24] = [