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