From ae810e1a9c68d05bee254ef570fbb0e783e25931 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 10 Feb 2026 17:47:15 +0100 Subject: feat: Add ShaderToy conversion tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tools/shadertoy/template.wgsl | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tools/shadertoy/template.wgsl (limited to 'tools/shadertoy/template.wgsl') 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; + +#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); +} -- cgit v1.2.3