Made the hilbert spiral order a little more pleasant.

This commit is contained in:
Nathan Vegdahl 2022-08-03 10:55:51 -07:00
parent 15cd261026
commit 167d70b8df
2 changed files with 13 additions and 14 deletions

View File

@ -19,7 +19,7 @@ use crate::{
ray::Ray, ray::Ray,
scene::{Scene, SceneLightSample}, scene::{Scene, SceneLightSample},
scramble::owen4, scramble::owen4,
space_fill::{hilbert, morton}, space_fill::{hilbert_spiral, morton},
timer::Timer, timer::Timer,
tracer::Tracer, tracer::Tracer,
}; };
@ -128,16 +128,15 @@ impl<'a> Renderer<'a> {
let pow2 = upper_power_of_two(larger); let pow2 = upper_power_of_two(larger);
let buffer = hilbert_count; // For hilbert spiral. let buffer = hilbert_count; // For hilbert spiral.
( (
(bucket_count_x / 2, bucket_count_y / 2), (bucket_count_x as i32 / 2 - 1, bucket_count_y as i32 / 2 - 1),
(pow2 + buffer) * (pow2 + buffer), (pow2 + buffer) * (pow2 + buffer),
) )
}; };
for hilbert_spiral_i in 0..bucket_n { for hilbert_spiral_i in 0..bucket_n {
let (bx, by) = let (bx, by) = hilbert_spiral::decode(hilbert_spiral_i, hilbert_count);
crate::space_fill::hilbert_spiral::decode(hilbert_spiral_i, hilbert_count);
let bx = middle_bucket.0 as i32 + bx; let bx = middle_bucket.0 + bx;
let by = middle_bucket.1 as i32 + by; let by = middle_bucket.1 + by;
if bx < 0 || by < 0 { if bx < 0 || by < 0 {
continue; continue;
} }

View File

@ -148,10 +148,10 @@ pub mod hilbert_spiral {
let (hx, hy) = super::hilbert::decode(hilbert_i, hilbert_size); let (hx, hy) = super::hilbert::decode(hilbert_i, hilbert_size);
let a = hilbert_size - 1; let a = hilbert_size - 1;
match section { match section {
0 => (hx, a - hy), 0 => (hy, hx),
1 => (a - hy, hx), 1 => (a - hx, a - hy),
2 => (a - hx, hy), 2 => (a - hy, a - hx),
3 => (hy, a - hx), 3 => (hx, hy),
_ => unreachable!(), _ => unreachable!(),
} }
}; };
@ -179,10 +179,10 @@ pub mod hilbert_spiral {
let d = -(size as i32 / 2) + 1 + arm_n as i32; let d = -(size as i32 / 2) + 1 + arm_n as i32;
match arm { match arm {
0 => (d, -radius, 0), 0 => (radius, d, 0),
1 => (radius, d, if arm_n == (size - 2) { 2 } else { 1 }), 1 => (-d, radius, if arm_n == (size - 2) { 2 } else { 1 }),
2 => (-d, radius, 2), 2 => (-radius, -d, 2),
3 => (-radius, -d, 3), 3 => (d, -radius, 3),
_ => unreachable!(), _ => unreachable!(),
} }
} }