summaryrefslogtreecommitdiff
path: root/common/shaders/heptagon.wgsl
blob: a8a450ffe48e81a8dc0d8d945cba9e7491a6ee12 (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
// Heptagon shader for Sequence v2
#include "sequence_uniforms"
#include "render/fullscreen_uv_vs"  // <- VertexOutput + vs_main

// Standard v2 post-process layout (bindings 0,1 unused for scene effects)
@group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams;

fn sdf_heptagon(p: vec2f, r: f32) -> f32 {
    let an = 3.141593 / 7.0;  // PI/7 for heptagon
    let acs = vec2f(cos(an), sin(an));
    let bn = (atan2(p.x, p.y) % (2.0 * an)) - an;
    let q = length(p) * vec2f(cos(bn), abs(sin(bn)));
    return length(q - r * acs) * sign(q.x - r * acs.x);
}

@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f {
    let aspect = uniforms.aspect_ratio;
    let uv = (in.uv * 2.0 - 1.0) * vec2f(aspect, 1.0);

    let rotation = uniforms.beat_time * 0.5;
    let c = cos(rotation);
    let s = sin(rotation);
    let rot_uv = vec2f(
        uv.x * c - uv.y * s,
        uv.x * s + uv.y * c
    );

    let dist = sdf_heptagon(rot_uv, 0.3);
    let color = mix(vec3f(0.2, 0.4, 0.8), vec3f(1.0, 0.8, 0.2),
                    smoothstep(0.01, -0.01, dist));

    return vec4f(color, 1.0);
}