summaryrefslogtreecommitdiff
path: root/assets/final/shaders/main_shader.wgsl
blob: 7011159a541bc8cc4bc019d61d94781c728d81b1 (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
struct Uniforms {
    audio_peak: f32,
    aspect_ratio: f32,
    time: f32,
};

@group(0) @binding(0) var<uniform> uniforms: Uniforms;

@vertex fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4<f32> {
    let PI = 3.14159265;
    let num_sides = 7.0;
    let scale = 0.5 + 0.3 * uniforms.audio_peak;
    let tri_idx = f32(i / 3u);
    let sub_idx = i % 3u;
    if (sub_idx == 0u) {
        return vec4<f32>(0.0, 0.0, 0.0, 1.0);
    }
    let angle = (tri_idx + f32(sub_idx - 1u)) * 2.0 * PI / num_sides + uniforms.time * 0.5;
    return vec4<f32>(scale * cos(angle) / uniforms.aspect_ratio, scale * sin(angle), 0.0, 1.0);
}

@fragment fn fs_main() -> @location(0) vec4<f32> {
    let h = uniforms.time * 2.0 + uniforms.audio_peak * 3.0;
    let r = sin(h) * 0.5 + 0.5;
    let g = sin(h + 2.0) * 0.9 + 0.3;
    let b = sin(h + 4.0) * 0.5 + 0.5;
    let boost = uniforms.audio_peak * 0.5;
    return vec4<f32>(r + boost, g + boost, b + boost, 1.0);
}