summaryrefslogtreecommitdiff
path: root/tools/shadertoy/template.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-10 17:47:15 +0100
committerskal <pascal.massimino@gmail.com>2026-02-10 17:47:15 +0100
commitae810e1a9c68d05bee254ef570fbb0e783e25931 (patch)
tree407f3d7d8e03da07d8f7995df78d37be7d1f32c1 /tools/shadertoy/template.wgsl
parentf3c7ef8cd612f5ac908f39310c4c11566879313f (diff)
feat: Add ShaderToy conversion tools
Add automated conversion pipeline for ShaderToy shaders to demo effects: - convert_shadertoy.py: Automated code generation script - Manual templates: Header, implementation, and WGSL boilerplate - Example shader: Test case for conversion workflow - README: Complete conversion guide with examples Handles basic GLSL→WGSL conversion (types, uniforms, mainImage extraction). Manual fixes needed for fragColor returns and complex type inference. Organized under tools/shadertoy/ for maintainability. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/shadertoy/template.wgsl')
-rw-r--r--tools/shadertoy/template.wgsl90
1 files changed, 90 insertions, 0 deletions
diff --git a/tools/shadertoy/template.wgsl b/tools/shadertoy/template.wgsl
new file mode 100644
index 0000000..37e7def
--- /dev/null
+++ b/tools/shadertoy/template.wgsl
@@ -0,0 +1,90 @@
+// 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<f32>;
+
+#include "common_uniforms"
+
+@group(0) @binding(2) var<uniform> 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<uniform> params: ShaderToyParams;
+
+// Standard fullscreen triangle vertex shader
+@vertex fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4<f32> {
+ var pos = array<vec2<f32>, 3>(
+ vec2<f32>(-1.0, -1.0),
+ vec2<f32>(3.0, -1.0),
+ vec2<f32>(-1.0, 3.0)
+ );
+ return vec4<f32>(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<f32>, vec3<f32>, vec4<f32>
+// mat2/mat3/mat4 → mat2x2<f32>, mat3x3<f32>, mat4x4<f32>
+//
+// 4. Function syntax:
+// float foo(vec2 p) → fn foo(p: vec2<f32>) -> 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<f32>) -> @location(0) vec4<f32> {
+ // 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<f32>(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<f32>(col, 1.0);
+}