summaryrefslogtreecommitdiff
path: root/tools/shadertoy/template.wgsl
blob: 573fa974c8a9d43541d9cbe4a3e697de011bd159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ShaderToy conversion template for 64k demo project
// TODO: Paste ShaderToy mainImage() function below and adapt

#include "sequence_uniforms"
#include "render/fullscreen_uv_vs"  // <- VertexOutput + vs_main

// 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
// ============================================================================
// ShaderToy → WGSL conversion notes:
//
// 1. Replace ShaderToy uniforms:
//    iResolution.xy        → uniforms.resolution
//    iTime                 → uniforms.time
//    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 = 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        → vec2f, vec3f, vec4f
//    mat2/mat3/mat4        → mat2x2f, mat3x3f, mat4x4f
//
// 4. Function syntax:
//    float foo(vec2 p)     → fn foo(p: vec2f) -> f32
//
// 5. Common functions (mostly same):
//    mix, sin, cos, length, normalize, dot, cross, fract(), etc.
//    mod(x, y)             → x % y
//
// 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. Beat / audio:
//    uniforms.beat_time    → absolute musical beats
//    uniforms.beat_phase   → fractional beat [0..1]
//    uniforms.audio_intensity → audio reactivity
//
// ============================================================================

@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f {
    // TODO: Paste and adapt ShaderToy mainImage() body here

    // 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 = vec3f(uv.x, uv.y, 0.5);

    // 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_phase * 0.1;

    return vec4f(col, 1.0);
}