Mix frame ID into the RNG

This commit is contained in:
numzero 2024-12-29 20:32:37 +03:00
parent 211c0b921e
commit 91fa161db9
3 changed files with 14 additions and 9 deletions

View File

@ -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());

View File

@ -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)]

View File

@ -2,6 +2,7 @@ struct Params {
max_reflections: i32,
min_strength: f32,
sphere_count: i32,
seed: u32,
}
struct Sphere {
@ -113,7 +114,7 @@ var<private> rand_state: u32;
fn seed(key: vec4f) {
let x = bitcast<u32>(key.x);
let y = bitcast<u32>(key.y);
rand_state = hash(hash(x) ^ y);
rand_state = hash(hash(hash(params.seed) ^ x) ^ y);
}
fn rand_next() -> u32 {