ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
frac_shader03_worm4_amp.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file frac_shader03_worm4_amp.frag
5 * @brief Vulkan fragment shader: frac shader03 worm4 amp.
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 amp_high ext.audio_bands.z
19#define amp_low ext.audio_bands.x
20#define amp_mid ext.audio_bands.y
21#define amp_peak ext.u2.w
22#define amp_rms ext.u3.z
23#define amp_smooth ext.u3.w
24#define iMouse ext.mouse
25#define iResolution ext.u0.zw
26#define iamp ext.u1.z
27#define time_f ext.u2.y
28#define uamp ext.u1.y
29
30layout(location = 0) out vec4 color;
31layout(location = 0) in vec2 tc;
32layout(set = 0, binding = 0) uniform sampler2D samp;
33
34
35
36
37
38
39
40
41
42
43
44
45
46const float PI = 3.1415926535897932384626433832795;
47
48float gAmp01;
50float gSlow;
51float gFast;
52float gDetail;
53
54/**
55 * @brief Evaluates pingPong for this shader effect.
56 * @param x Input value for the calculation.
57 * @param length Input value for the calculation.
58 * @return Computed float value.
59 */
60float pingPong(float x, float length) {
61 float m = mod(x, length * 2.0);
62 return m <= length ? m : length * 2.0 - m;
63}
64
65/**
66 * @brief Evaluates hsv2rgb for this shader effect.
67 * @param c Input value for the calculation.
68 * @return Computed vec3 value.
69 */
70vec3 hsv2rgb(vec3 c) {
71 vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
72 vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
73 return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
74}
75
76/**
77 * @brief Evaluates rotateUV for this shader effect.
78 * @param uv Input value for the calculation.
79 * @param angle Input value for the calculation.
80 * @param c Input value for the calculation.
81 * @param aspect Input value for the calculation.
82 * @return Computed vec2 value.
83 */
84vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect) {
85 float s = sin(angle), cc = cos(angle);
86 vec2 p = uv - c;
87 p.x *= aspect;
88 p = mat2(cc, -s, s, cc) * p;
89 p.x /= aspect;
90 return p + c;
91}
92
93/**
94 * @brief Evaluates reflectUV for this shader effect.
95 * @param uv Input value for the calculation.
96 * @param segments Input value for the calculation.
97 * @param c Input value for the calculation.
98 * @param aspect Input value for the calculation.
99 * @return Computed vec2 value.
100 */
101vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect) {
102 vec2 p = uv - c;
103 p.x *= aspect;
104 float ang = atan(p.y, p.x);
105 float rad = length(p);
106 float stepA = 6.28318530718 / segments;
107 ang = mod(ang, stepA);
108 ang = abs(ang - stepA * 0.5);
109 vec2 r = vec2(cos(ang), sin(ang)) * rad;
110 r.x /= aspect;
111 return r + c;
112}
113
114/**
115 * @brief Evaluates fractalFold for this shader effect.
116 * @param uv Input value for the calculation.
117 * @param zoom Input value for the calculation.
118 * @param t Input value for the calculation.
119 * @param c Input value for the calculation.
120 * @param aspect Input value for the calculation.
121 * @return Computed vec2 value.
122 */
123vec2 fractalFold(vec2 uv, float zoom, float t, vec2 c, float aspect) {
124 vec2 p = uv;
125 for (int i = 0; i < 6; i++) {
126 p = abs((p - c) * (zoom + 0.15 * sin(t * (0.35 + amp_low * 0.2) + float(i)))) - 0.5 + c;
127 p = rotateUV(p, t * 0.12 + float(i) * 0.07, c, aspect);
128 }
129 return p;
130}
131
132/**
133 * @brief Evaluates neonPalette for this shader effect.
134 * @param t Input value for the calculation.
135 * @return Computed vec3 value.
136 */
137vec3 neonPalette(float t) {
138 vec3 pink = vec3(1.0, 0.15, 0.75);
139 vec3 blue = vec3(0.10, 0.55, 1.0);
140 vec3 green = vec3(0.10, 1.00, 0.45);
141 float ph = fract(t * 0.08);
142 vec3 k1 = mix(pink, blue, smoothstep(0.00, 0.33, ph));
143 vec3 k2 = mix(blue, green, smoothstep(0.33, 0.66, ph));
144 vec3 k3 = mix(green, pink, smoothstep(0.66, 1.00, ph));
145 float a = step(ph, 0.33);
146 float b = step(0.33, ph) * step(ph, 0.66);
147 float c = step(0.66, ph);
148 return normalize(a * k1 + b * k2 + c * k3) * 1.05;
149}
150
151/**
152 * @brief Evaluates softTone for this shader effect.
153 * @param c Input value for the calculation.
154 * @return Computed vec3 value.
155 */
156vec3 softTone(vec3 c) {
157 c = pow(max(c, 0.0), vec3(0.95));
158 float l = dot(c, vec3(0.299, 0.587, 0.114));
159 c = mix(vec3(l), c, 0.9);
160 return clamp(c, 0.0, 1.0);
161}
162
163/**
164 * @brief Evaluates tentBlur3 for this shader effect.
165 * @param img Input value for the calculation.
166 * @param uv Input value for the calculation.
167 * @param res Input value for the calculation.
168 * @return Computed vec3 value.
169 */
170vec3 tentBlur3(sampler2D img, vec2 uv, vec2 res) {
171 vec2 ts = 1.0 / res;
172 vec3 s00 = textureGrad(img, uv + ts * vec2(-1.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
173 vec3 s10 = textureGrad(img, uv + ts * vec2(0.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
174 vec3 s20 = textureGrad(img, uv + ts * vec2(1.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
175 vec3 s01 = textureGrad(img, uv + ts * vec2(-1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
176 vec3 s11 = textureGrad(img, uv, dFdx(uv), dFdy(uv)).rgb;
177 vec3 s21 = textureGrad(img, uv + ts * vec2(1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
178 vec3 s02 = textureGrad(img, uv + ts * vec2(-1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
179 vec3 s12 = textureGrad(img, uv + ts * vec2(0.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
180 vec3 s22 = textureGrad(img, uv + ts * vec2(1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
181 return (s00 + 2.0 * s10 + s20 + 2.0 * s01 + 4.0 * s11 + 2.0 * s21 + s02 + 2.0 * s12 + s22) / 16.0;
182}
183
184/**
185 * @brief Evaluates preBlendColor for this shader effect.
186 * @param uv Input value for the calculation.
187 * @return Computed vec3 value.
188 */
189vec3 preBlendColor(vec2 uv) {
190 vec3 tex = tentBlur3(samp, uv, iResolution);
191 float aspect = iResolution.x / iResolution.y;
192 vec2 p = (uv - 0.5) * vec2(aspect, 1.0);
193 float r = length(p);
194 float t = time_f;
195 vec3 neon = neonPalette(t + r * 1.3);
196 float neonAmt = smoothstep(0.1, 0.8, r);
197 neonAmt = (0.3 + amp_mid * 0.15) + 0.4 * (1.0 - neonAmt);
198 vec3 grad = mix(tex, neon, neonAmt);
199 grad = mix(grad, tex, 0.2);
200 grad = softTone(grad);
201 return grad;
202}
203
204/**
205 * @brief Evaluates diamondRadius for this shader effect.
206 * @param p Input value for the calculation.
207 * @return Computed float value.
208 */
209float diamondRadius(vec2 p) {
210 float f = mix(0.6, 2.0, gAmp01);
211 p = sin(abs(p * f));
212 return max(p.x, p.y);
213}
214
215/**
216 * @brief Evaluates diamondFold for this shader effect.
217 * @param uv Input value for the calculation.
218 * @param c Input value for the calculation.
219 * @param aspect Input value for the calculation.
220 * @return Computed vec2 value.
221 */
222vec2 diamondFold(vec2 uv, vec2 c, float aspect) {
223 vec2 p = (uv - c) * vec2(aspect, 1.0);
224 p = abs(p);
225 if (p.y > p.x) p = p.yx;
226 p.x /= aspect;
227 return p + c;
228}
229
230/**
231 * @brief Evaluates wormholeUV for this shader effect.
232 * @param uv Input value for the calculation.
233 * @param c Input value for the calculation.
234 * @param aspect Input value for the calculation.
235 * @param t Input value for the calculation.
236 * @return Computed vec2 value.
237 */
238vec2 wormholeUV(vec2 uv, vec2 c, float aspect, float t) {
239 vec2 ar = vec2(aspect, 1.0);
240 vec2 p = (uv - c) * ar;
241 float r = length(p) + 1e-6;
242 float a = atan(p.y, p.x);
243 float swirl = 0.22 / r;
244 float spinBase = 0.15 + 0.35 * gAmp01;
245 float spinHit = 0.2 + 2.0 * gInstAmp;
246 a += t * (spinBase + spinHit) + swirl;
247 float z = 0.65 + 0.35 * sin(t * 0.6) + 0.15 * sin(r * 12.0 - t * (2.5 + 1.5 * gAmp01 + 1.5 * gInstAmp));
248 float rr = 1.0 / (r * 3.5 + 0.06) + 0.08 * z;
249 vec2 q = vec2(cos(a), sin(a)) * rr;
250 q /= ar;
251 return fract(q + c);
252}
253
254/**
255 * @brief Evaluates limitHighlights for this shader effect.
256 * @param c Input value for the calculation.
257 * @return Computed vec3 value.
258 */
259vec3 limitHighlights(vec3 c) {
260 float m = max(c.r, max(c.g, c.b));
261 if (m > 0.9) c *= 0.9 / m;
262 return c;
263}
264
265/**
266 * @brief Executes the fragment shader entry point.
267 */
268void main(void) {
269 float aAcc = clamp(amp, 0.0, 4.0);
270 float aInst = clamp(uamp, 0.0, 4.0);
271 float ampMix = clamp(aAcc * 0.6 + aInst * 1.4, 0.0, 4.0);
272 gAmp01 = clamp(ampMix / 2.5, 0.0, 1.0);
273 gInstAmp = clamp(aInst / 2.5, 0.0, 1.0);
274
275 gSlow = time_f * mix(0.15, 0.7, gAmp01);
276 gFast = time_f * mix(0.6, 3.5, gAmp01);
277 gDetail = time_f * mix(0.3, 2.0, gAmp01);
278
279 vec4 baseTex = texture(samp, tc);
280 float aspect = iResolution.x / iResolution.y;
281
282 vec2 uv = tc * 2.0 - 1.0;
283 uv.x *= aspect;
284 float rLen = length(uv);
285 float r = pingPong(sin(rLen * gSlow), 5.0);
286 float radius = sqrt(aspect * aspect + 1.0) + 0.5;
287 float glow = smoothstep(radius, radius - (0.25 + amp_low * 0.3), r);
288
289 vec2 m = (iMouse.z > 0.5) ? (iMouse.xy / iResolution) : vec2(0.5);
290 vec2 ar = vec2(aspect, 1.0);
291
292 vec3 baseCol = preBlendColor(tc);
293
294 float seg = 4.0 + 2.0 * sin(gSlow * 0.33 + gAmp01 * 2.0);
295 vec2 kUV = reflectUV(tc, seg, m, aspect);
296 kUV = diamondFold(kUV, m, aspect);
297
298 float foldZoom = 1.45 + 0.55 * sin(gSlow * 0.42 + gAmp01 * 3.0);
299 kUV = fractalFold(kUV, foldZoom, gDetail, m, aspect);
300 kUV = rotateUV(kUV, gSlow * 0.23 + gAmp01 * 1.1, m, aspect);
301 kUV = diamondFold(kUV, m, aspect);
302
303 vec2 p = (kUV - m) * ar;
304 vec2 q = abs(p);
305 if (q.y > q.x) q = q.yx;
306
307 float base = 1.82 + 0.18 * pingPong(sin(gSlow * 0.2) * (PI * gSlow), 5.0);
308 float period = log(base) * pingPong(gSlow * PI, 5.0);
309 float tz = gSlow * 0.65;
310 float rD = diamondRadius(p) + 1e-6;
311
312 float ang = atan(q.y, q.x) + tz * 0.35 + 0.35 * sin(rD * 18.0 + gFast * 0.6);
313 float k = fract((log(rD) - tz) / period);
314 float rw = exp(k * period);
315 vec2 pwrap = vec2(cos(ang), sin(ang)) * rw;
316
317 vec2 u0 = fract(pwrap / ar + m);
318 vec2 u1 = fract((pwrap * 1.045) / ar + m);
319 vec2 u2 = fract((pwrap * 0.955) / ar + m);
320 vec2 dir = normalize(pwrap + 1e-6);
321 vec2 off = dir * (0.0015 + 0.001 * sin(gFast * 1.3)) * vec2(1.0, 1.0 / aspect);
322
323 float vign = 1.0 - smoothstep(0.75, 1.2, length((tc - m) * ar));
324 vign = mix(0.9, (1.15 + amp_smooth * 0.2), vign);
325
326 vec3 rC = preBlendColor(u0 + off);
327 vec3 gC = preBlendColor(u1);
328 vec3 bC = preBlendColor(u2 - off);
329
330 float oscK = pingPong(gSlow * PI, 3.0 + gAmp01 * 2.0);
331 vec3 kaleidoRGB = vec3(
332 sin(rC.r * oscK),
333 sin(gC.g * oscK * 1.05),
334 sin(bC.b * oscK * 1.1)
335 );
336
337 float ring = smoothstep(0.0, 0.7, sin(log(rD + 1e-3) * 9.5 + gFast * 1.2));
338 ring = ring * pingPong(gSlow * PI, 5.0);
339
340 float pulse = 0.5 + 0.5 * sin(gFast * 2.0 + rD * 28.0 + k * 12.0);
341 pulse *= mix(0.4, 1.4, gAmp01);
342
343 vec3 outCol = kaleidoRGB;
344 outCol *= (0.75 + 0.25 * ring) * (0.85 + 0.15 * pulse) * vign;
345
346 vec3 bloom = outCol * outCol * 0.10 + pow(max(outCol - 0.6, 0.0), vec3(2.0)) * 0.07;
347
348 vec2 wh0 = wormholeUV(tc, m, aspect, gSlow);
349 vec2 wh1 = wormholeUV(tc + vec2(0.0009, 0.0), m, aspect, gSlow + 0.03);
350 vec2 wh2 = wormholeUV(tc - vec2(0.0009, 0.0), m, aspect, gSlow - 0.03);
351
352 vec3 whR = preBlendColor(wh0 + off);
353 vec3 whG = preBlendColor(wh1);
354 vec3 whB = preBlendColor(wh2 - off);
355
356 float oscW = pingPong(gFast * PI, 1.3 + gAmp01 * 1.2);
357 vec3 wormRGB = vec3(
358 sin(whR.r * oscW),
359 sin(whG.g * oscW * 1.05),
360 sin(whB.b * oscW * 1.1)
361 );
362
363 float rCenter = length((tc - m) * ar);
364 float throat = sin(smoothstep(0.38, 0.06, rCenter) * pingPong(gSlow * PI, 5.0));
365
366 float swirlGate = smoothstep(0.9, 1.6, gSlow * 0.25 + 0.35 * sin(gSlow * 0.7))
367 * pingPong(gSlow * PI, 4.0);
368
369 float gateBase = clamp(throat * (0.65 + 0.35 * pingPong(gSlow * PI, 5.0))
370 + pingPong(swirlGate * PI, 8.0) * 0.15, 0.0, 1.0);
371
372 float hitBoost = clamp(aInst * 0.6, 0.0, 1.2);
373 float gate = clamp(gateBase * (0.6 + 0.9 * gAmp01) + hitBoost, 0.0, 1.0);
374
375 outCol += bloom;
376 outCol = mix(outCol, baseCol, pingPong(pulse * PI, 5.0) * 0.18);
377 outCol = mix(outCol, wormRGB, gate * 0.85);
378 outCol = clamp(outCol, vec3(0.05), vec3(0.97));
379 outCol *= mix(0.85, 1.20, gAmp01);
380
381 vec3 finalRGB = mix(baseTex.rgb, outCol, pingPong(glow * PI, 5.0) * 0.8);
382 finalRGB = limitHighlights(finalRGB);
383 finalRGB = clamp(finalRGB, 0.0, 1.0);
384
385
386 // --- Audio Reactivity: direct output modulation ---
387 float _ab = clamp(amp_peak, 0.0, 1.0);
388 float _abass = clamp(amp_low, 0.0, 1.0);
389 finalRGB *= 1.0 + _ab * 0.6;
390 finalRGB = mix(finalRGB, finalRGB * vec3(1.0 + _abass * 0.3, 1.0 - _abass * 0.15, 1.0 + clamp(amp_high, 0.0, 1.0) * 0.25), _ab);
391 // --- End Audio Reactivity ---
392
393 color = vec4(finalRGB, baseTex.a);
394}
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 limitHighlights(vec3 c)
Evaluates limitHighlights for this shader effect.
#define uamp
Definition abc.frag:21
#define amp
Definition abc.frag:17
#define amp_smooth
#define amp_mid
#define amp_low
#define amp_high
#define amp_peak
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
vec2 fractalFold(vec2 p, float zoom, float t, int i)
Evaluates fractalFold for this shader effect.
vec3 neon(float t)
Evaluates neon for this shader effect.
vec3 bloom(float t)
Evaluates bloom for this shader effect.
vec2 diamondFold(vec2 p)
Evaluates diamondFold for this shader effect.
vec2 swirl(vec2 uv, float centerRadius, float swirlAmount)
Evaluates swirl for this shader effect.
vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect)
Evaluates rotateUV for this shader effect.
Definition aura2.frag:59
vec3 tentBlur3(sampler2D img, vec2 uv, vec2 res)
Evaluates tentBlur3 for this shader effect.
Definition aura2.frag:145
vec3 neonPalette(float t)
Evaluates neonPalette for this shader effect.
Definition aura2.frag:112
vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect)
Evaluates reflectUV for this shader effect.
Definition aura2.frag:76
vec3 softTone(vec3 c)
Evaluates softTone for this shader effect.
Definition aura2.frag:131
float diamondRadius(vec2 p)
Evaluates diamondRadius for this shader effect.
Definition aura2.frag:182
vec3 preBlendColor(vec2 uv)
Evaluates preBlendColor for this shader effect.
Definition aura2.frag:164
vec3 hsv2rgb(vec3 c)
Evaluates hsv2rgb for this shader effect.
Definition aura.frag:43
#define PI
vec2 wormholeUV(vec2 uv, vec2 c, float aspect, float t)
Evaluates wormholeUV for this shader effect.