ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
frac_shader02_dmd2_amp.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file frac_shader02_dmd2_amp.frag
5 * @brief Vulkan fragment shader: frac shader02 dmd2 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
48/**
49 * @brief Evaluates pingPong for this shader effect.
50 * @param x Input value for the calculation.
51 * @param length Input value for the calculation.
52 * @return Computed float value.
53 */
54float pingPong(float x, float length) {
55 float m = mod(x, length * 2.0);
56 return m <= length ? m : length * 2.0 - m;
57}
58
59/**
60 * @brief Evaluates hsv2rgb for this shader effect.
61 * @param c Input value for the calculation.
62 * @return Computed vec3 value.
63 */
64vec3 hsv2rgb(vec3 c) {
65 vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
66 vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
67 return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
68}
69
70/**
71 * @brief Evaluates rotateUV for this shader effect.
72 * @param uv Input value for the calculation.
73 * @param angle Input value for the calculation.
74 * @param c Input value for the calculation.
75 * @param aspect Input value for the calculation.
76 * @return Computed vec2 value.
77 */
78vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect) {
79 float s = sin(angle), cc = cos(angle);
80 vec2 p = uv - c;
81 p.x *= aspect;
82 p = mat2(cc, -s, s, cc) * p;
83 p.x /= aspect;
84 return p + c;
85}
86
87/**
88 * @brief Evaluates reflectUV for this shader effect.
89 * @param uv Input value for the calculation.
90 * @param segments Input value for the calculation.
91 * @param c Input value for the calculation.
92 * @param aspect Input value for the calculation.
93 * @return Computed vec2 value.
94 */
95vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect) {
96 vec2 p = uv - c;
97 p.x *= aspect;
98 float ang = atan(p.y, p.x);
99 float rad = length(p);
100 float stepA = 6.28318530718 / segments;
101 ang = mod(ang, stepA);
102 ang = abs(ang - stepA * 0.5);
103 vec2 r = vec2(cos(ang), sin(ang)) * rad;
104 r.x /= aspect;
105 return r + c;
106}
107
108/**
109 * @brief Evaluates fractalFold for this shader effect.
110 * @param uv Input value for the calculation.
111 * @param zoom Input value for the calculation.
112 * @param t Input value for the calculation.
113 * @param c Input value for the calculation.
114 * @param aspect Input value for the calculation.
115 * @return Computed vec2 value.
116 */
117vec2 fractalFold(vec2 uv, float zoom, float t, vec2 c, float aspect) {
118 vec2 p = uv;
119 for (int i = 0; i < 6; i++) {
120 p = abs((p - c) * (zoom + 0.15 * sin(t * (0.35 + amp_low * 0.2) + float(i)))) - 0.5 + c;
121 p = rotateUV(p, t * 0.12 + float(i) * 0.07, c, aspect);
122 }
123 return p;
124}
125
126/**
127 * @brief Evaluates neonPalette for this shader effect.
128 * @param t Input value for the calculation.
129 * @return Computed vec3 value.
130 */
131vec3 neonPalette(float t) {
132 vec3 pink = vec3(1.0, 0.15, 0.75);
133 vec3 blue = vec3(0.10, 0.55, 1.0);
134 vec3 green = vec3(0.10, 1.00, 0.45);
135 float ph = fract(t * 0.08);
136 vec3 k1 = mix(pink, blue, smoothstep(0.00, 0.33, ph));
137 vec3 k2 = mix(blue, green, smoothstep(0.33, 0.66, ph));
138 vec3 k3 = mix(green, pink, smoothstep(0.66, 1.00, ph));
139 float a = step(ph, 0.33);
140 float b = step(0.33, ph) * step(ph, 0.66);
141 float c = step(0.66, ph);
142 return normalize(a * k1 + b * k2 + c * k3) * 1.05;
143}
144
145/**
146 * @brief Evaluates softTone for this shader effect.
147 * @param c Input value for the calculation.
148 * @return Computed vec3 value.
149 */
150vec3 softTone(vec3 c) {
151 c = pow(max(c, 0.0), vec3(0.95));
152 float l = dot(c, vec3(0.299, 0.587, 0.114));
153 c = mix(vec3(l), c, 0.9);
154 return clamp(c, 0.0, 1.0);
155}
156
157/**
158 * @brief Evaluates tentBlur3 for this shader effect.
159 * @param img Input value for the calculation.
160 * @param uv Input value for the calculation.
161 * @param res Input value for the calculation.
162 * @return Computed vec3 value.
163 */
164vec3 tentBlur3(sampler2D img, vec2 uv, vec2 res) {
165 vec2 ts = 1.0 / res;
166 vec3 s00 = textureGrad(img, uv + ts * vec2(-1.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
167 vec3 s10 = textureGrad(img, uv + ts * vec2(0.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
168 vec3 s20 = textureGrad(img, uv + ts * vec2(1.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
169 vec3 s01 = textureGrad(img, uv + ts * vec2(-1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
170 vec3 s11 = textureGrad(img, uv, dFdx(uv), dFdy(uv)).rgb;
171 vec3 s21 = textureGrad(img, uv + ts * vec2(1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
172 vec3 s02 = textureGrad(img, uv + ts * vec2(-1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
173 vec3 s12 = textureGrad(img, uv + ts * vec2(0.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
174 vec3 s22 = textureGrad(img, uv + ts * vec2(1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
175 return (s00 + 2.0 * s10 + s20 + 2.0 * s01 + 4.0 * s11 + 2.0 * s21 + s02 + 2.0 * s12 + s22) / 16.0;
176}
177
178/**
179 * @brief Evaluates preBlendColor for this shader effect.
180 * @param uv Input value for the calculation.
181 * @param t Input value for the calculation.
182 * @return Computed vec3 value.
183 */
184vec3 preBlendColor(vec2 uv, float t) {
185 float aspect = iResolution.x / iResolution.y;
186 vec3 tex = tentBlur3(samp, uv, iResolution);
187 vec2 gdir = normalize(vec2(cos(t * 0.27), sin(t * 0.31)));
188 float s = dot((uv - 0.5) * vec2(aspect, 1.0), gdir);
189 float w = max(fwidth(s) * 4.0, 0.002);
190 float band = smoothstep(-0.5 - w, -0.5 + w, sin(s * 2.2 + t * 0.9));
191 vec3 neon = neonPalette(t);
192 vec3 grad = mix(tex, mix(tex, neon, 0.6), 0.35 + 0.25 * band);
193 grad = mix(grad, tex, 0.10);
194 grad = softTone(grad);
195 return grad;
196}
197
198/**
199 * @brief Evaluates diamondRadius for this shader effect.
200 * @param p Input value for the calculation.
201 * @return Computed float value.
202 */
203float diamondRadius(vec2 p) {
204 p = abs(p);
205 return max(p.x, p.y);
206}
207
208/**
209 * @brief Evaluates diamondFold for this shader effect.
210 * @param uv Input value for the calculation.
211 * @param c Input value for the calculation.
212 * @param aspect Input value for the calculation.
213 * @return Computed vec2 value.
214 */
215vec2 diamondFold(vec2 uv, vec2 c, float aspect) {
216 vec2 p = (uv - c) * vec2(aspect, 1.0);
217 p = abs(p);
218 if (p.y > p.x) p = p.yx;
219 p.x /= aspect;
220 return p + c;
221}
222
223/**
224 * @brief Evaluates limitHighlights for this shader effect.
225 * @param c Input value for the calculation.
226 * @return Computed vec3 value.
227 */
228vec3 limitHighlights(vec3 c) {
229 float m = max(c.r, max(c.g, c.b));
230 if (m > 0.95) c *= 0.95 / m;
231 return c;
232}
233
234/**
235 * @brief Executes the fragment shader entry point.
236 */
237void main(void) {
238 float aAcc = clamp(amp, 0.0, 20.0);
239 float aInst = clamp(uamp, 0.0, 20.0);
240 float aMix = clamp(aAcc * 0.5 + aInst * 1.0, 0.0, 20.0);
241 float a01 = clamp(aMix / 6.0, 0.0, 1.0);
242
243 float aspect = iResolution.x / iResolution.y;
244 vec2 center = (iMouse.z > 0.5) ? (iMouse.xy / iResolution) : vec2(0.5, 0.5);
245
246 float tSpin = time_f * mix(0.3, 1.8, a01);
247 float tSlow = time_f * mix(0.2, 0.9, a01);
248 float tFast = time_f * mix(0.8, 3.2, a01);
249
250 vec2 offset = tc - center;
251 float maxRadius = length(vec2(0.5, 0.5));
252 float radius = length(offset);
253 float normalizedRadius = radius / maxRadius;
254 float angle = atan(offset.y, offset.x);
255
256 float distortion = 0.25 + 0.75 * a01;
257 float distortedRadius = normalizedRadius + distortion * normalizedRadius * normalizedRadius;
258 distortedRadius = clamp(distortedRadius, 0.0, 1.0);
259 distortedRadius *= maxRadius;
260
261 vec2 distortedCoords = center + distortedRadius * vec2(cos(angle), sin(angle));
262
263 float modulatedTime = pingPong(tSpin, 5.0);
264 angle += modulatedTime;
265
266 vec2 rotatedTC;
267 rotatedTC.x = cos(angle) * (distortedCoords.x - center.x)
268 - sin(angle) * (distortedCoords.y - center.y) + center.x;
269 rotatedTC.y = sin(angle) * (distortedCoords.x - center.x)
270 + cos(angle) * (distortedCoords.y - center.y) + center.y;
271
272 float warpSpeed = 0.05 + 0.25 * a01 + 0.2 * (aInst / (aInst + 1.0));
273 vec2 warpedCoords;
274 warpedCoords.x = pingPong(rotatedTC.x + tSpin * warpSpeed, 1.0);
275 warpedCoords.y = pingPong(rotatedTC.y + tSpin * warpSpeed, 1.0);
276
277 vec2 uvGlow = warpedCoords * 2.0 - 1.0;
278 uvGlow.x *= aspect;
279 float rGlow = length(uvGlow);
280 float radiusMax = sqrt(aspect * aspect + 1.0) + 0.5;
281 float glow = smoothstep(radiusMax, radiusMax - 0.25, rGlow);
282
283 vec2 m = center;
284 vec2 ar = vec2(aspect, 1.0);
285
286 vec3 baseColBlur = preBlendColor(warpedCoords, tSlow);
287 float seg = 4.0 + 2.0 * sin(tSlow * 0.33 + a01 * 2.0);
288
289 vec2 kUV = reflectUV(warpedCoords, seg, m, aspect);
290 kUV = diamondFold(kUV, m, aspect);
291
292 float foldZoom = 1.45 + 0.55 * sin(tSlow * 0.42 + a01 * 3.0);
293 kUV = fractalFold(kUV, foldZoom, tFast, m, aspect);
294 kUV = rotateUV(kUV, tSlow * 0.23 + a01 * 1.1, m, aspect);
295 kUV = diamondFold(kUV, m, aspect);
296
297 vec2 p = (kUV - m) * ar;
298 vec2 q = abs(p);
299 if (q.y > q.x) q = q.yx;
300
301 float base = 1.82 + 0.18 * sin(tSlow * 0.2);
302 float period = log(base);
303 float tz = tSlow * 0.65;
304 float rD = diamondRadius(p) + 1e-6;
305
306 float ang = atan(q.y, q.x) + tz * 0.35 + 0.35 * sin(rD * 18.0 + tFast * 0.6);
307 float k = fract((log(rD) - tz) / period);
308 float rw = exp(k * period);
309 vec2 pwrap = vec2(cos(ang), sin(ang)) * rw;
310
311 vec2 u0 = fract(pwrap / ar + m);
312 vec2 u1 = fract((pwrap * 1.045) / ar + m);
313 vec2 u2 = fract((pwrap * 0.955) / ar + m);
314
315 vec2 dir = normalize(pwrap + 1e-6);
316 vec2 off = dir * (0.0015 + 0.001 * sin(tFast * 1.3)) * vec2(1.0, 1.0 / aspect);
317
318 float vign = 1.0 - smoothstep(0.75, 1.2, length((warpedCoords - m) * ar));
319 vign = mix(0.9, (1.15 + amp_smooth * 0.2), vign);
320
321 vec3 rC = preBlendColor(u0 + off, tFast);
322 vec3 gC = preBlendColor(u1, tFast);
323 vec3 bC = preBlendColor(u2 - off, tFast);
324 vec3 kaleidoRGB = vec3(rC.r, gC.g, bC.b);
325
326 float ring = smoothstep(0.0, 0.7, sin(log(rD + 1e-3) * 9.5 + tFast * 1.2));
327 float pulse = 0.5 + 0.5 * sin(tFast * 2.0 + rD * 28.0 + k * 12.0);
328 pulse *= mix(0.4, 1.4, a01);
329
330 vec3 outCol = kaleidoRGB;
331 outCol *= (0.75 + 0.25 * ring) * (0.85 + 0.15 * pulse) * vign;
332
333 vec3 bloom = outCol * outCol * 0.10
334 + pow(max(outCol - 0.6, 0.0), vec3(2.0)) * 0.06;
335 outCol += bloom;
336
337 outCol = mix(outCol, baseColBlur, 0.18 + 0.3 * a01);
338 outCol = limitHighlights(outCol);
339 outCol = clamp(outCol, 0.0, 1.0);
340
341 vec4 baseTex = texture(samp, warpedCoords);
342 float mixAmt = pingPong(glow * PI, 5.0) * mix(0.4, 0.9, a01);
343 vec3 finalRGB = mix(baseTex.rgb, outCol, mixAmt);
344 finalRGB = limitHighlights(finalRGB);
345 finalRGB = clamp(finalRGB, 0.0, 1.0);
346
347
348 // --- Audio Reactivity: direct output modulation ---
349 float _ab = clamp(amp_peak, 0.0, 1.0);
350 float _abass = clamp(amp_low, 0.0, 1.0);
351 finalRGB *= 1.0 + _ab * 0.6;
352 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);
353 // --- End Audio Reactivity ---
354
355 color = vec4(finalRGB, baseTex.a);
356}
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_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 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