diff --git a/js/webgpu_main.js b/js/webgpu_main.js index 97331ff..bef3073 100644 --- a/js/webgpu_main.js +++ b/js/webgpu_main.js @@ -91,8 +91,7 @@ export default async (canvas, config) => { msdfStructLayout.build([config.glyphTextureColumns, config.glyphSequenceLength], msdfBuffer.getMappedRange()); msdfBuffer.unmap(); - // prettier-ignore - const timeStructLayout = std140(["i32", "i32"]); + const timeStructLayout = std140(["f32", "i32"]); const timeBuffer = device.createBuffer({ size: timeStructLayout.size, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.VERTEX | GPUBufferUsage.FRAGMENT | GPUBufferUsage.COMPUTE | GPUBufferUsage.COPY_DST, // Which of these are necessary? @@ -221,7 +220,7 @@ export default async (canvas, config) => { updateCameraBuffer(); } - queue.writeBuffer(timeBuffer, 0, timeStructLayout.build([now, frame])); + queue.writeBuffer(timeBuffer, 0, timeStructLayout.build([now / 1000, frame])); frame++; renderPassConfig.colorAttachments[0].view = canvasContext.getCurrentTexture().createView(); @@ -233,7 +232,7 @@ export default async (canvas, config) => { const commandBuffer = encoder.finish(); queue.submit([commandBuffer]); - // requestAnimationFrame(renderLoop); + requestAnimationFrame(renderLoop); }; requestAnimationFrame(renderLoop); diff --git a/shaders/rainRenderPass.wgsl b/shaders/rainRenderPass.wgsl index 98a9f3e..a80f665 100644 --- a/shaders/rainRenderPass.wgsl +++ b/shaders/rainRenderPass.wgsl @@ -18,8 +18,8 @@ let TWO_PI:f32 = 6.28318530718; [[group(0), binding(3)]] var msdfTexture: texture_2d; [[block]] struct Time { - now: i32; - frame: i32; + seconds:f32; + frames:i32; }; [[group(0), binding(4)]] var time:Time; @@ -63,7 +63,12 @@ struct VertexOutput { // position = position * scene.screenSize; var depth:f32 = 0.0; - var pos: vec4 = vec4(position, depth, 1.0); + + // depth = -0.5 + // + sin(time.seconds * 2.0 + f32(cellPosition.x) / f32(config.numColumns) * 10.0) * 0.2 + // + sin(time.seconds * 2.0 + f32(cellPosition.y) / f32(config.numColumns) * 10.0) * 0.2; + + var pos:vec4 = vec4(position, depth, 1.0); pos.x = pos.x / config.glyphHeightToWidth; pos = scene.camera * scene.transform * pos; @@ -77,9 +82,8 @@ struct VertexOutput { [[stage(fragment)]] fn fragMain([[location(0)]] UV:vec2) -> [[location(0)]] vec4 { var color:vec4 = textureSample(msdfTexture, msdfSampler, UV / f32(msdf.glyphTextureColumns)); - // color.b = color.b * (sin(f32(time.now) / 1000.0 * TWO_PI) * 0.5 + 0.5); - color.b = color.b * f32(time.frame / 60 % 2); - var now = time.now; + // color.b = color.b * (sin(time.seconds * TWO_PI) * 0.5 + 0.5); + color.b = color.b * f32(time.frames / 60 % 2); return color; }