Skip to content

Commit

Permalink
Write seed properly into UBO buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Oct 28, 2024
1 parent f371d0e commit ca21d60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions sample/particles/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ const simulationParams = {
const simulationUBOBufferSize =
1 * 4 + // deltaTime
1 * 4 + // brightnessFactor
3 * 4 + // padding
2 * 4 + // padding
4 * 4 + // seed
0;
const simulationUBOBuffer = device.createBuffer({
Expand Down Expand Up @@ -411,7 +411,6 @@ function frame() {
simulationParams.simulate ? simulationParams.deltaTime : 0.0,
simulationParams.brightnessFactor,
0.0,
0.0,
0.0, // padding
Math.random() * 100,
Math.random() * 100, // seed.xy
Expand Down
4 changes: 2 additions & 2 deletions sample/particles/particle.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var<private> rand_seed : vec2f;

fn init_rand(invocation_id : u32, seed : vec4f) {
rand_seed = seed.xz;
rand_seed = fract(rand_seed * cos(35.456+f32(invocation_id) * seed.yw * 0.01f));
rand_seed = fract(rand_seed * cos(41.235+f32(invocation_id) * seed.xw * 0.01f));
rand_seed = fract(rand_seed * cos(35.456+f32(invocation_id) * seed.yw));
rand_seed = fract(rand_seed * cos(41.235+f32(invocation_id) * seed.xw));
}

fn rand() -> f32 {
Expand Down

0 comments on commit ca21d60

Please sign in to comment.