// ShaderToy conversion template for 64k demo project // TODO: Paste ShaderToy mainImage() function below and adapt @group(0) @binding(0) var smplr: sampler; @group(0) @binding(1) var txt: texture_2d; #include "common_uniforms" @group(0) @binding(2) var uniforms: CommonUniforms; // TODO: Define your effect parameters (must match C++ struct) struct ShaderToyParams { param1: f32, param2: f32, _pad0: f32, _pad1: f32, } @group(0) @binding(3) var params: ShaderToyParams; // Standard fullscreen triangle vertex shader @vertex fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4 { var pos = array, 3>( vec2(-1.0, -1.0), vec2(3.0, -1.0), vec2(-1.0, 3.0) ); return vec4(pos[i], 0.0, 1.0); } // ============================================================================ // PASTE SHADERTOY CODE HERE // ============================================================================ // ShaderToy → WGSL conversion notes: // // 1. Replace ShaderToy uniforms: // iResolution.xy → uniforms.resolution // iTime → uniforms.time // fragCoord → p.xy (from @builtin(position)) // fragColor → return value // // 2. Coordinate conversion: // vec2 uv = fragCoord / iResolution.xy; // becomes: // let uv = p.xy / uniforms.resolution; // // 3. Type syntax changes: // float → f32 // vec2/vec3/vec4 → vec2, vec3, vec4 // mat2/mat3/mat4 → mat2x2, mat3x3, mat4x4 // // 4. Function syntax: // float foo(vec2 p) → fn foo(p: vec2) -> f32 // // 5. Common functions (mostly same): // mix, sin, cos, length, normalize, dot, cross, etc. // fract() → fract() // mod(x, y) → x % y OR x - y * floor(x / y) // // 6. Texture sampling: // texture(iChannel0, uv) → textureSample(txt, smplr, uv) // // 7. Variable declarations: // float x = 1.0; → var x: f32 = 1.0; OR let x = 1.0; // const float x = 1.0; → const x: f32 = 1.0; // // 8. Swizzling is the same: col.rgb, uv.xy, etc. // // ============================================================================ @fragment fn fs_main(@builtin(position) p: vec4) -> @location(0) vec4 { // TODO: Paste and adapt ShaderToy mainImage() body here // Example coordinate setup (typical ShaderToy pattern): let uv = p.xy / uniforms.resolution; // TODO: Your effect code here var col = vec3(uv.x, uv.y, 0.5); // Optional: Sample previous frame // var prev_col = textureSample(txt, smplr, uv); // Optional: Audio reactivity // col *= 1.0 + uniforms.audio_intensity * 0.2; // Optional: Beat sync // col *= 1.0 + uniforms.beat * 0.1; return vec4(col, 1.0); }