summaryrefslogtreecommitdiff
path: root/tools/shadertoy/template.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-28 09:25:35 +0100
committerskal <pascal.massimino@gmail.com>2026-02-28 09:25:35 +0100
commitbc1beb58ba259263eb98d43d2aa742307764591c (patch)
treeeae97b1496811ed6f2fde60b1b914f2bcf2d825f /tools/shadertoy/template.wgsl
parent34bee8b09566a52cedced99b7bd13d29907512ce (diff)
fix(tools/shadertoy): sync templates and script to current codebase conventions
- template.h/cc: new Effect constructor/render signatures, RAII wrappers, HEADLESS_RETURN_IF_NULL, #pragma once - template.wgsl: sequence_uniforms + render/fullscreen_uv_vs includes, UniformsSequenceParams at binding 2, VertexOutput in fs_main - convert_shadertoy.py: paths src/effects/ + src/shaders/, new Effect pattern (create_post_process_pipeline, pp_update_bind_group), correct field names (beat_time/beat_phase), updated next-steps instructions - README.md: streamlined to quick-ref; accurate GLSL→WGSL table and uniforms Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'tools/shadertoy/template.wgsl')
-rw-r--r--tools/shadertoy/template.wgsl75
1 files changed, 33 insertions, 42 deletions
diff --git a/tools/shadertoy/template.wgsl b/tools/shadertoy/template.wgsl
index 37e7def..573fa97 100644
--- a/tools/shadertoy/template.wgsl
+++ b/tools/shadertoy/template.wgsl
@@ -1,32 +1,14 @@
// 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 "sequence_uniforms"
+#include "render/fullscreen_uv_vs" // <- VertexOutput + vs_main
-#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);
-}
+// Scene effect: only uniforms (bindings 0,1 unused)
+// For post-process (input texture needed), add:
+// @group(0) @binding(0) var smplr: sampler;
+// @group(0) @binding(1) var txt: texture_2d<f32>;
+@group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams;
// ============================================================================
// PASTE SHADERTOY CODE HERE
@@ -36,55 +18,64 @@ struct ShaderToyParams {
// 1. Replace ShaderToy uniforms:
// iResolution.xy → uniforms.resolution
// iTime → uniforms.time
-// fragCoord → p.xy (from @builtin(position))
+// fragCoord → in.position.xy (pixel coords) or in.uv * uniforms.resolution
// fragColor → return value
//
// 2. Coordinate conversion:
// vec2 uv = fragCoord / iResolution.xy;
// becomes:
-// let uv = p.xy / uniforms.resolution;
+// let uv = in.uv; // [0..1], origin top-left
+// // OR for ShaderToy convention (origin bottom-left):
+// let uv = vec2f(in.uv.x, 1.0 - in.uv.y);
//
// 3. Type syntax changes:
// float → f32
-// vec2/vec3/vec4 → vec2<f32>, vec3<f32>, vec4<f32>
-// mat2/mat3/mat4 → mat2x2<f32>, mat3x3<f32>, mat4x4<f32>
+// vec2/vec3/vec4 → vec2f, vec3f, vec4f
+// mat2/mat3/mat4 → mat2x2f, mat3x3f, mat4x4f
//
// 4. Function syntax:
-// float foo(vec2 p) → fn foo(p: vec2<f32>) -> f32
+// float foo(vec2 p) → fn foo(p: vec2f) -> 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)
+// mix, sin, cos, length, normalize, dot, cross, fract(), etc.
+// mod(x, y) → x % y
//
-// 6. Texture sampling:
+// 6. Texture sampling (requires bindings 0,1 in C++ and shader):
// 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.
+// 8. Beat / audio:
+// uniforms.beat_time → absolute musical beats
+// uniforms.beat_phase → fractional beat [0..1]
+// uniforms.audio_intensity → audio reactivity
//
// ============================================================================
-@fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> {
+@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f {
// TODO: Paste and adapt ShaderToy mainImage() body here
- // Example coordinate setup (typical ShaderToy pattern):
- let uv = p.xy / uniforms.resolution;
+ // Standard UV (origin top-left, [0..1])
+ let uv = in.uv;
+
+ // For ShaderToy convention (origin bottom-left, [-1..1] centered):
+ // let q = vec2f(in.uv.x, 1.0 - in.uv.y);
+ // var coord = q * 2.0 - 1.0;
+ // coord.x *= uniforms.aspect_ratio;
// TODO: Your effect code here
- var col = vec3<f32>(uv.x, uv.y, 0.5);
+ var col = vec3f(uv.x, uv.y, 0.5);
- // Optional: Sample previous frame
+ // Optional: Sample previous frame (requires bindings 0,1)
// 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;
+ // col *= 1.0 + uniforms.beat_phase * 0.1;
- return vec4<f32>(col, 1.0);
+ return vec4f(col, 1.0);
}