ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
HyperFcousAmp.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file HyperFcousAmp.frag
5 * @brief Vulkan fragment shader: HyperFcousAmp.
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 ext.u1.y
18#define iMouse ext.mouse
19#define iResolution ext.u0.zw
20#define time_f ext.u2.y
21#define uamp ext.u1.y
22
23layout(location = 0) out vec4 color;
24layout(location = 0) in vec2 tc;
25layout(set = 0, binding = 0) uniform sampler2D samp;
26
27
28
29
30// --- AUDIO UNIFORMS ---
31// Ensure your host program passes these, or the simulation below will take over
32
33
34
35// --- UTILITIES ---
36const float PI = 3.14159265359;
37
38/**
39 * @brief Evaluates rotX for this shader effect.
40 * @param a Input value for the calculation.
41 * @return Computed mat3 value.
42 */
43mat3 rotX(float a){float s=sin(a),c=cos(a);return mat3(1,0,0, 0,c,-s, 0,s,c);}
44/**
45 * @brief Evaluates rotY for this shader effect.
46 * @param a Input value for the calculation.
47 * @return Computed mat3 value.
48 */
49mat3 rotY(float a){float s=sin(a),c=cos(a);return mat3(c,0,s, 0,1,0, -s,0,c);}
50/**
51 * @brief Evaluates rotZ for this shader effect.
52 * @param a Input value for the calculation.
53 * @return Computed mat3 value.
54 */
55mat3 rotZ(float a){float s=sin(a),c=cos(a);return mat3(c,-s,0, s,c,0, 0,0,1);}
56
57// --- NOISE ---
58/**
59 * @brief Evaluates hash for this shader effect.
60 * @param p Input value for the calculation.
61 * @return Computed float value.
62 */
63float hash(vec2 p) {
64 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
65}
66
67/**
68 * @brief Evaluates noise for this shader effect.
69 * @param p Input value for the calculation.
70 * @return Computed float value.
71 */
72float noise(vec2 p) {
73 vec2 i = floor(p);
74 vec2 f = fract(p);
75 vec2 u = f * f * (3.0 - 2.0 * f);
76 return mix(mix(hash(i + vec2(0.0, 0.0)), hash(i + vec2(1.0, 0.0)), u.x),
77 mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
78}
79
80/**
81 * @brief Evaluates fbm for this shader effect.
82 * @param p Input value for the calculation.
83 * @return Computed float value.
84 */
85float fbm(vec2 p) {
86 float v = 0.0;
87 float a = 0.5;
88 for (int i = 0; i < 3; i++) {
89 v += a * noise(p);
90 p *= 2.0;
91 a *= 0.5;
92 }
93 return v;
94}
95
96// --- PALETTE ---
97/**
98 * @brief Evaluates electricPalette for this shader effect.
99 * @param t Input value for the calculation.
100 * @return Computed vec3 value.
101 */
102vec3 electricPalette(float t) {
103 vec3 a = vec3(0.5, 0.5, 0.5);
104 vec3 b = vec3(0.5, 0.5, 0.5);
105 vec3 c = vec3(1.0, 1.0, 1.0);
106 vec3 d = vec3(0.00, 0.33, 0.67);
107 return a + b * cos(6.28318 * (c * t + d));
108}
109
110// --- MAIN RENDER FUNCTION ---
111/**
112 * @brief Evaluates renderLayer for this shader effect.
113 * @param uv Input value for the calculation.
114 * @param t Input value for the calculation.
115 * @param bassStr Input value for the calculation.
116 * @param trebleStr Input value for the calculation.
117 * @return Computed vec3 value.
118 */
119vec3 renderLayer(vec2 uv, float t, float bassStr, float trebleStr) {
120 float aspect = iResolution.x / iResolution.y;
121 vec2 ar = vec2(aspect, 1.0);
122 vec2 center = vec2(0.5);
123
124 // Mouse Interaction: If mouse is pressed, move the vortex center
125 if (iMouse.z > 0.5) {
126 center = iMouse.xy / iResolution;
127 }
128
129 vec2 p = (uv - center) * ar;
130
131 // 1. AUDIO-REACTIVE TWIST
132 // The vortex tightens and spins faster when the BASS hits
133 float len = length(p);
134 float twistBase = 3.0 + (bassStr * 4.0); // Expands on beat
135 float angle = atan(p.y, p.x) + twistBase / (len + 0.1) + t * (0.5 + bassStr);
136 vec2 twistedP = vec2(cos(angle), sin(angle)) * len;
137
138 // 2. AUDIO-REACTIVE RIPPLE
139 // The glitch jitter increases when the TREBLE hits
140 float rippleWavelength = 8.0;
141 float rippleSpeed = 4.0 + (trebleStr * 10.0); // Fast jitter on highs
142 float noiseVal = fbm(twistedP * 5.0 + t);
143
144 float rippleX = sin(twistedP.x * rippleWavelength + t * rippleSpeed + noiseVal * 2.0);
145 float rippleY = cos(twistedP.y * rippleWavelength + t * rippleSpeed - noiseVal * 2.0);
146
147 // Treble makes the ripples sharper/deeper
148 float rippleAmp = 0.05 + 0.05 * noiseVal * (1.0 + trebleStr * 2.0);
149 vec2 rippledP = twistedP + vec2(rippleX, rippleY) * rippleAmp;
150
151 // 3. 3D PROJECTION
152 vec3 p3 = vec3(rippledP, 1.0);
153 // BASS shakes the camera slightly
154 float shake = bassStr * 0.1 * sin(t * 20.0);
155 mat3 R = rotX(t * 0.2 + shake) * rotY(t * 0.15) * rotZ(t * 0.1);
156 vec3 r = R * p3;
157 float zScale = 1.0 / (1.0 + r.z * 0.5);
158 vec2 projUV = r.xy * zScale;
159
160 // 4. MIRROR TILING
161 vec2 tiledUV = 1.0 - abs(1.0 - 2.0 * (projUV + 0.5));
162 tiledUV = tiledUV - floor(tiledUV);
163
164 // 5. CHROMATIC ABERRATION (Reacts to Bass)
165 // Heavy bass = huge color split
166 float aberrationStr = 0.01 + (0.04 + bassStr * 0.05) * (1.0 / (len + 0.5));
167 vec2 offset = vec2(aberrationStr, 0.0);
168
169 vec3 texR = texture(samp, clamp(tiledUV - offset, 0.0, 1.0)).rgb;
170 vec3 texG = texture(samp, clamp(tiledUV, 0.0, 1.0)).rgb;
171 vec3 texB = texture(samp, clamp(tiledUV + offset, 0.0, 1.0)).rgb;
172 vec3 layerColor = vec3(texR.r, texG.g, texB.b);
173
174 // 6. GLOW
175 float glowMask = smoothstep(0.6, 0.95, abs(rippleX * rippleY));
176 vec3 palette = electricPalette(len - t);
177
178 // Flash brighter on beat
179 return mix(layerColor, layerColor + palette, glowMask * (0.8 + bassStr * 0.5));
180}
181
182/**
183 * @brief Executes the fragment shader entry point.
184 */
185void main(void) {
186 // --- SIMULATE AUDIO (If uniforms are 0.0) ---
187 // If your app isn't sending audio data yet, this creates a fake "beat"
188 // using sine waves so the shader doesn't look static.
189 float simBass = (amp <= 0.001) ? abs(sin(time_f * 4.0)) * 0.5 : amp;
190 float simTreble = (uamp <= 0.001) ? abs(cos(time_f * 8.0)) * 0.5 : uamp;
191
192 // PASS 1: Current Frame
193 vec3 col0 = renderLayer(tc, time_f, simBass, simTreble);
194
195 // PASS 2: Echo 1
196 vec3 col1 = renderLayer(tc, time_f - 0.1, simBass * 0.8, simTreble * 0.8);
197
198 // PASS 3: Echo 2
199 vec3 col2 = renderLayer(tc, time_f - 0.2, simBass * 0.6, simTreble * 0.6);
200
201 vec3 finalColor = col0 + (col1 * 0.5) + (col2 * 0.25);
202 finalColor = finalColor / (1.0 + finalColor * 0.4);
203
204 color = vec4(finalColor, 1.0);
205}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
#define iMouse
Definition 3high.frag:17
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
vec3 electricPalette(float t)
Evaluates electricPalette for this shader effect.
vec3 renderLayer(vec2 uv, float t, float bassStr, float trebleStr)
Evaluates renderLayer for this shader effect.
#define uamp
Definition abc.frag:21
#define amp
Definition abc.frag:17
float fbm(vec2 point)
Evaluates fbm for this shader effect.
vec3 palette(float phase)
Evaluates palette for this shader effect.
float hash(vec2 p)
Evaluates hash for this shader effect.
float noise(vec2 p)
Evaluates noise for this shader effect.
mat3 rotY(float a)
Evaluates rotY for this shader effect.
mat3 rotZ(float a)
Evaluates rotZ for this shader effect.
mat3 rotX(float a)
Evaluates rotX for this shader effect.
mat2 R(float a)
Evaluates R for this shader effect.
#define PI