ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
random_x_audio_hexgrid.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file random_x_audio_hexgrid.frag
5 * @brief Vulkan fragment shader: random x audio hexgrid.
6 */
7layout(set = 0, binding = 1, std140) uniform SpriteExtended {
8 vec4 mouse;
9 vec4 u0;
10 vec4 u1;
11 vec4 u2;
12 vec4 u3;
13 vec4 custom_uniforms[16];
14 vec4 audio_bands;
15 vec4 audio_history;
17#define amp_high ext.audio_bands.z
18#define amp_low ext.audio_bands.x
19#define amp_mid ext.audio_bands.y
20#define amp_peak ext.u2.w
21#define amp_rms ext.u3.z
22#define amp_smooth ext.u3.w
23#define iResolution ext.u0.zw
24#define iamp ext.u1.z
25#define time_f ext.u2.y
26
27layout(location = 0) out vec4 color;
28layout(location = 0) in vec2 tc;
29layout(set = 0, binding = 0) uniform sampler2D samp;
30
31
32
33
34
35
36
37
38
39
40// Hexagonal grid helper
41/**
42 * @brief Evaluates hexCoord for this shader effect.
43 * @param uv Input value for the calculation.
44 * @return Computed vec4 value.
45 */
46vec4 hexCoord(vec2 uv) {
47 vec2 r = vec2(1.0, 1.732);
48 vec2 h = r * 0.5;
49 vec2 a = mod(uv, r) - h;
50 vec2 b = mod(uv - h, r) - h;
51 vec2 gv = dot(a, a) < dot(b, b) ? a : b;
52 vec2 id = uv - gv;
53 return vec4(gv, id);
54}
55
56/**
57 * @brief Executes the fragment shader entry point.
58 */
59void main(void) {
60 float aspect = iResolution.x / iResolution.y;
61 vec2 uv = tc * vec2(aspect, 1.0);
62
63 // Bass drives hexagon scale (bigger on beat)
64 float hexScale = 8.0 + amp_low * 20.0;
65 vec4 hex = hexCoord(uv * hexScale);
66 vec2 hexCenter = hex.zw / hexScale / vec2(aspect, 1.0);
67
68 // Sample from hex center
69 vec3 tex = texture(samp, clamp(hexCenter, 0.0, 1.0)).rgb;
70
71 // Mids rotate hex pattern
72 float rot = time_f * (0.1 + amp_mid * 0.5);
73 vec2 ruv = uv - 0.5 * vec2(aspect, 1.0);
74 float c = cos(rot), s = sin(rot);
75 ruv = vec2(c * ruv.x - s * ruv.y, s * ruv.x + c * ruv.y);
76 ruv += 0.5 * vec2(aspect, 1.0);
77 vec4 hex2 = hexCoord(ruv * hexScale);
78 vec2 hexCenter2 = hex2.zw / hexScale / vec2(aspect, 1.0);
79 vec3 tex2 = texture(samp, clamp(hexCenter2, 0.0, 1.0)).rgb;
80
81 // Blend rotated and non-rotated
82 tex = mix(tex, tex2, amp_mid * 0.5);
83
84 // Hex edge highlight from treble
85 float hexDist = length(hex.xy);
86 float hexEdge = smoothstep(0.45, 0.5, hexDist);
87 tex += hexEdge * amp_high * 0.4 * vec3(0.5, 0.8, 1.0);
88
89 // RMS brightness
90 tex *= 1.0 + amp_rms * 0.3;
91
92 // Peak flash
93 tex += smoothstep(0.6, 1.0, amp_peak) * 0.2;
94
95 color = vec4(clamp(tex, 0.0, 1.0), 1.0);
96}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
ext
Definition 3high.frag:16
void main(void)
Executes the fragment shader entry point.
Definition 3high.frag:47
#define iResolution
Definition 3high.frag:18
#define time_f
Definition 3high.frag:19
#define amp_mid
#define amp_low
#define amp_high
#define amp_peak
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
#define amp_rms
Definition breathe.frag:21
float h(vec2 p)
Evaluates h for this shader effect.
vec2 hex(vec2 p)
Evaluates hex for this shader effect.
vec4 hexCoord(vec2 uv)
Evaluates hexCoord for this shader effect.