From 91fa161db9088efbdc8e0f55bc4e9bf02625f11f Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 29 Dec 2024 20:32:37 +0300 Subject: [PATCH] Mix frame ID into the RNG --- src/bin/minitracer/main.rs | 19 +++++++++++-------- src/bin/minitracer/trace.rs | 1 + src/bin/minitracer/trace.wgsl | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/bin/minitracer/main.rs b/src/bin/minitracer/main.rs index 229a4d0..b99d12a 100644 --- a/src/bin/minitracer/main.rs +++ b/src/bin/minitracer/main.rs @@ -52,14 +52,6 @@ fn main() { let format = wgpu::TextureFormat::Bgra8UnormSrgb; let mut tracer = Tracer::new(&device, format); - tracer.set_params( - &queue, - trace::Params { - max_reflections: 3, - min_strength: 0.1, - sphere_count: N_SPHERES, - }, - ); let sphere_params: Vec<_> = { let mut rng = rand_pcg::Pcg32::new(42, 0); let distr = anim::SphereParamsDistribution::default(); @@ -69,6 +61,7 @@ fn main() { let presenter = Presenter::new(&device, format); + let mut frame = 0; let mut time = 0.0; let mut surface_configured = false; @@ -100,8 +93,18 @@ fn main() { return; } time += 1. / 60.; + frame += 1; let spheres: Vec<_> = sphere_params.iter().map(|p| p.to_sphere(time)).collect(); let data = TracerData::new(&device, &tracer, &spheres); + tracer.set_params( + &queue, + trace::Params { + max_reflections: 3, + min_strength: 0.1, + sphere_count: N_SPHERES, + seed: frame, + }, + ); let output = surface.get_current_texture().unwrap(); let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/src/bin/minitracer/trace.rs b/src/bin/minitracer/trace.rs index 8066eee..cc32337 100644 --- a/src/bin/minitracer/trace.rs +++ b/src/bin/minitracer/trace.rs @@ -10,6 +10,7 @@ pub struct Params { pub max_reflections: u32, pub min_strength: f32, pub sphere_count: u32, + pub seed: u32, } #[derive(Debug, Clone, Copy)] diff --git a/src/bin/minitracer/trace.wgsl b/src/bin/minitracer/trace.wgsl index d8de6d9..57b1fb7 100644 --- a/src/bin/minitracer/trace.wgsl +++ b/src/bin/minitracer/trace.wgsl @@ -2,6 +2,7 @@ struct Params { max_reflections: i32, min_strength: f32, sphere_count: i32, + seed: u32, } struct Sphere { @@ -113,7 +114,7 @@ var rand_state: u32; fn seed(key: vec4f) { let x = bitcast(key.x); let y = bitcast(key.y); - rand_state = hash(hash(x) ^ y); + rand_state = hash(hash(hash(params.seed) ^ x) ^ y); } fn rand_next() -> u32 {