-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { WGSLCanvas } from "@wgsl-canvas/core"; | ||
import shaderFragment from "./Example04Noise.wgsl?raw"; | ||
|
||
export const Example04Noise = async (canvas: HTMLCanvasElement) => { | ||
const wgslCanvas = new WGSLCanvas({ canvas }); | ||
await wgslCanvas.init(); | ||
wgslCanvas.shaderFragment = shaderFragment; | ||
wgslCanvas.uniformsKeys = ["time"]; | ||
wgslCanvas.uniforms.time = 0.0; | ||
|
||
const frame: FrameRequestCallback = (timeElapsedMilliseconds) => { | ||
const timeElapsed = timeElapsedMilliseconds * 0.001; | ||
wgslCanvas.uniforms.time = timeElapsed; | ||
wgslCanvas.render(); | ||
|
||
requestAnimationFrame(frame); | ||
}; | ||
|
||
requestAnimationFrame(frame); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@group(0) @binding(0) var<uniform> uniforms: Uniforms; | ||
|
||
struct Uniforms { | ||
time: f32, | ||
} | ||
|
||
struct FragmentInput { | ||
@location(0) coord: vec2<f32>, | ||
} | ||
|
||
struct FragmentOutput { | ||
@location(0) color: vec4<f32>, | ||
} | ||
|
||
@fragment | ||
fn fragment_main(input: FragmentInput) -> FragmentOutput { | ||
var output: FragmentOutput; | ||
var xy: vec2<f32> = input.coord.xy * 0.5 + 0.5; | ||
var blend: f32 = noise(xy); | ||
output.color = vec4<f32>(vec3<f32>(blend), 1.0); | ||
return output; | ||
} | ||
|
||
fn noise(xy: vec2<f32>) -> f32 { | ||
return fract(sin(dot(xy, vec2<f32>(12.9898, 78.233))) * 1567.5453 * uniforms.time); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters