Use new fast hash for base-4 Owen scrambling.
This commit is contained in:
parent
c603e24633
commit
b305471090
|
@ -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);
|
||||||
|
|
|
@ -16,7 +16,22 @@ 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.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] = [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user