Skip to content

Commit

Permalink
Adjust style
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubidumdu committed Mar 23, 2024
1 parent 195dde5 commit 98a4a37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pages/visualizer/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,16 @@ const init = async () => {
uniforms.addUniform('particleCount', 1);
uniforms.addUniform('time', 1);
uniforms.addUniform('high', 1);
uniforms.addUniform('mid', 1);
uniforms.addUniform('low', 1);

uniforms.updateFloat('deltaTime', 0.001);
uniforms.updateFloat('radius', RADIUS);
uniforms.updateInt('particleCount', PARTICLE_NUMS);
uniforms.updateFloat('time', 0);
uniforms.updateFloat('high', 0);
uniforms.updateFloat('mid', 0);
uniforms.updateFloat('low', 0);
uniforms.update();

const particleBuffer = new StorageBuffer(
Expand Down Expand Up @@ -219,6 +223,8 @@ const init = async () => {
uniforms.updateFloat('deltaTime', deltaTime);
uniforms.updateFloat('time', time);
uniforms.updateFloat('high', dataArray[12]);
uniforms.updateFloat('mid', dataArray[8]);
uniforms.updateFloat('low', dataArray[4]);
uniforms.update();
camera.alpha += deltaTime * 0.00025;
computeShader.dispatch(Math.ceil(PARTICLE_NUMS / 64));
Expand Down
6 changes: 5 additions & 1 deletion pages/visualizer/shaders/compute.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ struct Uniforms {
particleCount: u32,
time: f32,
high: f32,
mid: f32,
low: f32,
}

struct Particle {
Expand All @@ -29,11 +31,13 @@ const core = vec3(0., 0., 0.);

let time = uniforms.time * 0.02;
let high = uniforms.high / 255.;
let mid = uniforms.mid / 255.;
let low = uniforms.low / 255.;
let speed = uniforms.deltaTime * 0.002;
let rotateYMatrix = mat3x3(vec3(cos(speed), 0, -sin(speed)), vec3(0., 1., 0.), vec3(sin(speed), 0, cos(speed)));
let radius = uniforms.radius;
let position = particles[index].position;
let noise = fbm3d((position.xyz * (.4 + .2 * high) + vec3(0, time, 0)) * .3);
let noise = fbm3d((vec3(1. + .2 * low, 1. + .2 * mid, 1. + .2 * high) * position.xyz * .4 + vec3(0, time, 0)) * .3);
let nPosition = normalize(position - core);
let velocity = (rotateYMatrix * (nPosition * radius) - position) * .05;

Expand Down
2 changes: 1 addition & 1 deletion pages/visualizer/shaders/vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ void main() {
float nMid = mid / 255.;
float nLow = low / 255.;
float nHigh = high / 255.;
gl_Position = worldViewProjection * vec4(((.8 + .2 * nLow ) * position + (4. + nMid * 20. + nHigh * 20.) * noise * outer), 1.);
gl_Position = worldViewProjection * vec4(((.8 + .2 * nLow ) * position + (4. + nLow * 10. + nMid * 20. + nHigh * 20.) * noise * outer), 1.);
}

0 comments on commit 98a4a37

Please sign in to comment.