ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
ant_spectrum_gradient_kaleidoscope.frag
Go to the documentation of this file.
1#version 450
2
3layout(set = 0, binding = 1, std140) uniform SpriteExtended {
4 vec4 mouse;
5 vec4 u0;
6 vec4 u1;
7 vec4 u2;
8 vec4 u3;
9 vec4 custom_uniforms[16];
10 vec4 audio_bands;
11 vec4 audio_history;
13#define amp_peak ext.u2.w
14#define amp_smooth ext.u3.w
15#define iResolution ext.u0.zw
16#define iTime ext.u0.y
17
18/**
19 * @file ant_spectrum_gradient_kaleidoscope.frag
20 * @brief Vulkan fragment shader: ant spectrum gradient kaleidoscope.
21 */
22// ant_spectrum_gradient_kaleidoscope
23// Gradient-mapped kaleidoscope with smooth color bands, echo layers, and hue cycling
24layout(location = 0) in vec2 tc;
25layout(location = 0) out vec4 color;
26layout(set = 0, binding = 0) uniform sampler2D samp;
27
28
29
30
31layout(set = 0, binding = 3) uniform sampler1D spectrum;
32
33const float PI = 3.14159265;
34
35/**
36 * @brief Evaluates rainbow for this shader effect.
37 * @param t Input value for the calculation.
38 * @return Computed vec3 value.
39 */
40vec3 rainbow(float t) {
41 return 0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67)));
42}
43
44/**
45 * @brief Evaluates kaleidoscope for this shader effect.
46 * @param p Input value for the calculation.
47 * @param seg Input value for the calculation.
48 * @return Computed vec2 value.
49 */
50vec2 kaleidoscope(vec2 p, float seg) {
51 float ang = atan(p.y, p.x);
52 float r = length(p);
53 float s = 2.0 * PI / seg;
54 ang = mod(ang, s);
55 ang = abs(ang - s * 0.5);
56 return vec2(cos(ang), sin(ang)) * r;
57}
58
59/**
60 * @brief Evaluates mirror for this shader effect.
61 * @param uv Input value for the calculation.
62 * @return Computed vec2 value.
63 */
64vec2 mirror(vec2 uv) {
65 vec2 m = mod(uv, 2.0);
66 return mix(m, 2.0 - m, step(1.0, m));
67}
68
69/**
70 * @brief Executes the fragment shader entry point.
71 */
72void main() {
73 float bass = texture(spectrum, 0.04).r;
74 float mid = texture(spectrum, 0.22).r;
75 float hiMid = texture(spectrum, 0.38).r;
76 float treble = texture(spectrum, 0.55).r;
77 float air = texture(spectrum, 0.80).r;
78
79 float aspect = iResolution.x / iResolution.y;
80 vec2 uv = (tc - 0.5) * vec2(aspect, 1.0);
81
82 float dist = length(uv);
83 float angle = atan(uv.y, uv.x);
84
85 // Kaleidoscope
86 float seg = floor(8.0 + bass * 8.0);
87 vec2 kUV = kaleidoscope(uv, seg);
88 kUV = abs(kUV);
89
90 // Gradient mapping: use kUV position to drive color bands
91 float gradVal = length(kUV) * 3.0 + kUV.x * 2.0;
92 gradVal += iTime * 0.5;
93 vec3 gradColor = rainbow(gradVal + bass);
94
95 // Texture with gradient modulation
96 vec2 texUV = mirror(kUV * 0.6 + 0.5);
97 vec3 tex = texture(samp, texUV).rgb;
98
99 // Smooth color band overlay
100 float bands = sin(gradVal * 5.0 + mid * PI) * 0.5 + 0.5;
101 tex = mix(tex, tex * gradColor * 1.4, 0.35 * bands);
102
103 // Echo layers with different gradient phases
104 vec3 echo = vec3(0.0);
105 for (float e = 1.0; e < 5.0; e++) {
106 vec2 eKUV = kaleidoscope(uv * (1.0 + e * 0.04), seg + e);
107 eKUV = abs(eKUV);
108 vec3 s = texture(samp, mirror(eKUV * 0.6 + 0.5)).rgb;
109 float eGrad = length(eKUV) * 3.0 + eKUV.x * 2.0 + iTime * 0.5 + e * 0.5;
110 s *= rainbow(eGrad + hiMid);
111 echo += s * (0.25 / e);
112 }
113
114 vec3 result = tex + echo;
115
116 // Hue cycling
117 float hueShift = iTime * 0.4 + dist;
118 result = mix(result, result.gbr, sin(hueShift) * 0.4 + 0.4);
119 result = mix(result, result.brg, sin(hueShift * 0.7) * 0.2 + 0.2);
120
121 // Air glow
122 result += air * 0.06 * rainbow(iTime * 0.3 + dist);
123
124 result *= 0.9 + amp_smooth * 0.25;
125 result = mix(result, vec3(1.0) - result, smoothstep(0.9, 1.0, amp_peak));
126
127 color = vec4(result, 1.0);
128}
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
vec2 kaleidoscope(vec2 point, float sides)
Evaluates kaleidoscope for this shader effect.
#define amp_smooth
#define amp_peak
vec2 mirror(vec2 uv)
Evaluates mirror for this shader effect.
vec3 rainbow(float t)
Evaluates rainbow for this shader effect.
#define PI
vec3 hueShift(vec3 col, float hue)
Evaluates hueShift for this shader effect.
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.