ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
darkstar_trail_cache.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file darkstar_trail_cache.frag
5 * @brief Vulkan fragment shader: darkstar trail cache.
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 history_head int(ext.u3.x)
18#define iMouse ext.mouse
19#define iResolution ext.u0.zw
20#define spectrum_history_head int(ext.audio_history.x)
21#define spectrum_history_size int(ext.audio_history.y)
22#define time_f ext.u2.y
23
24// af_kaleido-cache-acid-star
25// Merges spectrum-driven fractal folds with a dynamic, frequency-historical trail.
26layout(location = 0) in vec2 tc;
27layout(location = 0) out vec4 color;
28
29// --- CORE UNIFORMS ---
30layout(set = 0, binding = 0) uniform sampler2D samp;
31
32
33
34
35// --- HISTORY CACHE UNIFORMS ---
36layout(set = 0, binding = 2) uniform sampler2DArray history;
37
38#ifndef SIZE
39#define SIZE 8
40#endif
41#ifndef CACHE_HISTORY_LAYER
42#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
43#endif
44
45// --- AUDIO SPECTRUM UNIFORMS ---
46layout(set = 0, binding = 3) uniform sampler1D spectrum0;
47layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
48
49
50#ifndef SPECTRUM_HISTORY_LAYER
51#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
52#endif
53
54const float PI = 3.14159265359;
55const float TAU = 6.28318530718;
56
57// --- UTILITIES & MATH ---
58
59/**
60 * @brief Evaluates pingPong for this shader effect.
61 * @param x Input value for the calculation.
62 * @param length Input value for the calculation.
63 * @return Computed float value.
64 */
65float pingPong(float x, float length) {
66 float m = mod(x, length * 2.0);
67 return m <= length ? m : length * 2.0 - m;
68}
69
70/**
71 * @brief Evaluates rotate 2d for this shader effect.
72 * @param angle Input value for the calculation.
73 * @return Computed mat2 value.
74 */
75mat2 rotate_2d(float angle) {
76 float c = cos(angle);
77 float s = sin(angle);
78 return mat2(c, -s, s, c);
79}
80
81/**
82 * @brief Evaluates rotateUV for this shader effect.
83 * @param uv Input value for the calculation.
84 * @param angle Input value for the calculation.
85 * @param c Input value for the calculation.
86 * @param aspect Input value for the calculation.
87 * @return Computed vec2 value.
88 */
89vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect) {
90 float s = sin(angle), cc = cos(angle);
91 vec2 p = uv - c;
92 p.x *= aspect;
93 p = mat2(cc, -s, s, cc) * p;
94 p.x /= aspect;
95 return p + c;
96}
97
98/**
99 * @brief Evaluates mirror repeat for this shader effect.
100 * @param point Input value for the calculation.
101 * @return Computed vec2 value.
102 */
103vec2 mirror_repeat(vec2 point) {
104 return 1.0 - abs(mod(point, 2.0) - 1.0);
105}
106
107/**
108 * @brief Evaluates palette for this shader effect.
109 * @param phase Input value for the calculation.
110 * @return Computed vec3 value.
111 */
112vec3 palette(float phase) {
113 return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.02, 0.35, 0.69)));
114}
115
116/**
117 * @brief Evaluates reflectUV for this shader effect.
118 * @param uv Input value for the calculation.
119 * @param segments Input value for the calculation.
120 * @param c Input value for the calculation.
121 * @param aspect Input value for the calculation.
122 * @return Computed vec2 value.
123 */
124vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect) {
125 vec2 p = uv - c;
126 p.x *= aspect;
127 float ang = atan(p.y, p.x);
128 float rad = length(p);
129 float stepA = TAU / segments;
130 ang = mod(ang, stepA);
131 ang = abs(ang - stepA * 0.5);
132 vec2 r = vec2(cos(ang), sin(ang)) * rad;
133 r.x /= aspect;
134 return r + c;
135}
136
137/**
138 * @brief Evaluates diamondFold for this shader effect.
139 * @param uv Input value for the calculation.
140 * @param c Input value for the calculation.
141 * @param aspect Input value for the calculation.
142 * @return Computed vec2 value.
143 */
144vec2 diamondFold(vec2 uv, vec2 c, float aspect) {
145 vec2 p = (uv - c) * vec2(aspect, 1.0);
146 p = abs(p);
147 if (p.y > p.x) p = p.yx;
148 p.x /= aspect;
149 return p + c;
150}
151
152/**
153 * @brief Evaluates diamondRadius for this shader effect.
154 * @param p Input value for the calculation.
155 * @return Computed float value.
156 */
157float diamondRadius(vec2 p) {
158 p = sin(abs(p));
159 return max(p.x, p.y);
160}
161
162/**
163 * @brief Evaluates fractalFold for this shader effect.
164 * @param uv Input value for the calculation.
165 * @param zoom Input value for the calculation.
166 * @param t Input value for the calculation.
167 * @param c Input value for the calculation.
168 * @param aspect Input value for the calculation.
169 * @param bass Input value for the calculation.
170 * @return Computed vec2 value.
171 */
172vec2 fractalFold(vec2 uv, float zoom, float t, vec2 c, float aspect, float bass) {
173 vec2 p = uv;
174 for (int i = 0; i < 3; i++) {
175 p = abs((p - c) * (zoom + 0.15 * sin(t * (0.35 + bass * 0.2) + float(i)))) - 0.5 + c;
176 p = rotateUV(p, t * 0.12 + float(i) * 0.07, c, aspect);
177 }
178 return p;
179}
180
181/**
182 * @brief Evaluates tentBlur3 for this shader effect.
183 * @param img Input value for the calculation.
184 * @param uv Input value for the calculation.
185 * @param res Input value for the calculation.
186 * @return Computed vec3 value.
187 */
188vec3 tentBlur3(sampler2D img, vec2 uv, vec2 res) {
189 vec2 ts = 1.0 / res;
190 vec3 s00 = textureGrad(img, uv + ts * vec2(-1.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
191 vec3 s10 = textureGrad(img, uv + ts * vec2(0.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
192 vec3 s20 = textureGrad(img, uv + ts * vec2(1.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
193 vec3 s01 = textureGrad(img, uv + ts * vec2(-1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
194 vec3 s11 = textureGrad(img, uv, dFdx(uv), dFdy(uv)).rgb;
195 vec3 s21 = textureGrad(img, uv + ts * vec2(1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
196 vec3 s02 = textureGrad(img, uv + ts * vec2(-1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
197 vec3 s12 = textureGrad(img, uv + ts * vec2(0.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
198 vec3 s22 = textureGrad(img, uv + ts * vec2(1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
199 return (s00 + 2.0 * s10 + s20 + 2.0 * s01 + 4.0 * s11 + 2.0 * s21 + s02 + 2.0 * s12 + s22) / 16.0;
200}
201
202// --- OPTIMIZED SAMPLERS ---
203
204/**
205 * @brief Evaluates sample cache for this shader effect.
206 * @param index Input value for the calculation.
207 * @param uv Input value for the calculation.
208 * @return Computed vec4 value.
209 */
210vec4 sample_cache(int index, vec2 uv) {
211 uv = mirror_repeat(uv);
212 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(index))));
213}
214
215/**
216 * @brief Evaluates sample history for this shader effect.
217 * @param index Input value for the calculation.
218 * @param frequency Input value for the calculation.
219 * @return Computed float value.
220 */
221float sample_history(int index, float frequency) {
222 return texture(spectrum_history, vec2(frequency, float(SPECTRUM_HISTORY_LAYER(index + 1)))).r;
223}
224
225// --- CORE GENERATORS ---
226
227/**
228 * @brief Evaluates dynamic trail transform for this shader effect.
229 * @param uv Input value for the calculation.
230 * @param center Input value for the calculation.
231 * @param index Input value for the calculation.
232 * @param total_layers Input value for the calculation.
233 * @param bass Input value for the calculation.
234 * @param treble Input value for the calculation.
235 * @param time Input value for the calculation.
236 * @return Computed vec2 value.
237 */
238vec2 dynamic_trail_transform(vec2 uv, vec2 center, int index, int total_layers, float bass, float treble, float time) {
239 float progress = float(index) / float(max(total_layers - 1, 1));
240 float shrink_factor = 1.0 + (bass * 1.5);
241 float current_scale = mix(1.0, 1.0 / shrink_factor, progress);
242
243 float max_angle = progress * (treble * PI) * sin(time * 0.5);
244 mat2 rot = rotate_2d(max_angle);
245
246 vec2 point = uv - center;
247 point = rot * (point / current_scale);
248
249 return mirror_repeat(point + center);
250}
251
252/**
253 * @brief Evaluates generate live frame for this shader effect.
254 * @param uv Input value for the calculation.
255 * @param res Input value for the calculation.
256 * @param aspect Input value for the calculation.
257 * @param m Input value for the calculation.
258 * @param bass Input value for the calculation.
259 * @param mid Input value for the calculation.
260 * @param treble Input value for the calculation.
261 * @param rms Input value for the calculation.
262 * @param peak Input value for the calculation.
263 * @return Computed vec3 value.
264 */
265vec3 generate_live_frame(vec2 uv, vec2 res, float aspect, vec2 m, float bass, float mid, float treble, float rms, float peak) {
266 float void_presence = 1.0 - smoothstep(0.0, 0.15, rms);
267 float jam_build = smoothstep(0.05, 0.6, rms);
268
269 vec2 mapped_uv = uv * 2.0 - 1.0;
270 mapped_uv.x *= aspect;
271
272 float r = pingPong(sin(length(mapped_uv) * time_f), 5.0);
273 float radius = sqrt(aspect * aspect + 1.0) + 0.5;
274 float glow = smoothstep(radius, radius - (0.5 + bass * 0.3), r);
275 vec2 ar = vec2(aspect, 1.0);
276
277 float seg = 4.0 + (2.0 + mid * 2.0 * jam_build) * sin(time_f * 0.33);
278 vec2 kUV = reflectUV(uv, seg, m, aspect);
279 kUV = diamondFold(kUV, m, aspect);
280
281 float foldZoom = 1.15 + (0.2 * void_presence + bass * jam_build * 0.8) * sin(time_f * (0.42 + jam_build * 0.5));
282
283 kUV = fractalFold(kUV, foldZoom, time_f, m, aspect, bass);
284 kUV = rotateUV(kUV, time_f * (0.23 + bass * 0.15), m, aspect);
285 kUV = diamondFold(kUV, m, aspect);
286
287 vec2 p = (kUV - m) * ar;
288 vec2 q = abs(p);
289 if (q.y > q.x) q = q.yx;
290
291 float base_val = 1.82 + 0.18 * pingPong(sin(time_f * 0.2) * (PI * time_f), 5.0);
292 float period = log(base_val) * pingPong(time_f * PI, 5.0);
293 float tz = time_f * (0.65 + bass * 0.3 * jam_build);
294
295 float rD = diamondRadius(p) + 1e-6;
296 float ang = atan(q.y, q.x) + tz * 0.35 + 0.35 * sin(rD * 18.0 + time_f * 0.6);
297
298 float k = fract((log(rD) - tz) / period);
299 float rw = exp(k * period);
300
301 vec2 pwrap = vec2(cos(ang), sin(ang)) * rw * 0.5;
302 vec2 u0 = fract(pwrap / ar + m);
303 vec2 u1 = fract((pwrap * 1.045) / ar + m);
304 vec2 u2 = fract((pwrap * 0.955) / ar + m);
305
306 vec2 dir = normalize(pwrap + 1e-6);
307 float chromatic_drift = (0.004 * void_presence * sin(time_f * 0.4)) + (treble * 0.008 * jam_build);
308 vec2 off = dir * chromatic_drift * vec2(1.0, 1.0 / aspect);
309
310 float vign = 1.0 - smoothstep(0.75, 1.2, length((uv - m) * ar));
311 vign = mix(0.9, (1.15 + rms * 0.2), vign);
312
313 vec3 rC = tentBlur3(samp, u0 + off, res) * 0.7;
314 vec3 gC = tentBlur3(samp, u1, res) * 0.7;
315 vec3 bC = tentBlur3(samp, u2 - off, res) * 0.7;
316 vec3 kaleidoRGB = vec3(rC.r, gC.g, bC.b);
317
318 float ring = smoothstep(0.0, 0.7, sin(log(rD + 1e-3) * 9.5 + time_f * 1.2));
319 ring = ring * pingPong((time_f * PI), 5.0) * (1.0 + mid * 0.3 * jam_build);
320
321 float pulse = 0.5 + (0.5 + rms * 0.3 * jam_build) * sin(time_f * 2.0 + rD * 28.0 + k * 12.0);
322
323 vec3 outCol = clamp(kaleidoRGB * (0.6 + 0.4 * pulse) * vign, 0.0, 1.0);
324 vec4 baseTex = texture(samp, uv);
325 vec3 finalRGB = mix(baseTex.rgb * 0.8, outCol, pingPong(glow * PI, 5.0) * (0.5 + 0.5 * jam_build));
326
327 finalRGB = mix(finalRGB, finalRGB * vec3(0.7, 0.8, 1.2), void_presence);
328 finalRGB *= 1.0 + (peak * 1.5 * jam_build) + (void_presence * 0.2);
329
330 vec3 eqColor = vec3(1.0 + bass * 0.4, 1.0 - bass * 0.2, 1.0 + clamp(treble, 0.0, 1.0) * 0.4);
331 finalRGB = mix(finalRGB, finalRGB * eqColor, peak * jam_build);
332
333 return finalRGB;
334}
335
336/**
337 * @brief Executes the fragment shader entry point.
338 */
339void main() {
340 vec2 res = max(iResolution, vec2(1.0));
341 float aspect = res.x / res.y;
342 vec2 m = (iMouse.z > 0.0) ? (iMouse.xy / res) : vec2(0.5);
343
344 // Fetch live audio directly from the spectrum texture mapping (approximate bands)
345 float bass = texture(spectrum0, 0.05).r;
346 float mid = texture(spectrum0, 0.25).r;
347 float treble = texture(spectrum0, 0.70).r;
348
349 float rms = (bass + mid + treble) / 3.0;
350 float peak = max(bass, max(mid, treble));
351
352 // 1. GENERATE KALEIDOSCOPIC LIVE FRAME
353 vec3 live = generate_live_frame(tc, res, aspect, m, bass, mid, treble, rms, peak);
354
355 // 2. CALCULATE AUDIO HISTORICAL TRAIL
356 vec3 trail_accum = vec3(0.0);
357 float trail_weight = 0.0;
358
359 for (int index = 0; index < SIZE; ++index) {
360 float old_bass = sample_history(index, 0.05);
361 float old_treble = sample_history(index, 0.70);
362
363 vec2 history_uv = dynamic_trail_transform(tc, m, index, SIZE, old_bass, old_treble, time_f);
364 vec3 cached = sample_cache(index, history_uv).rgb;
365
366 float progress = float(index) / float(max(SIZE - 1, 1));
367 float weight = exp(-progress * 3.5);
368
369 vec3 trail_tint = mix(vec3(1.0), palette(time_f * 0.2 + progress + old_bass), progress * 0.8);
370
371 trail_accum += (cached * trail_tint) * weight;
372 trail_weight += weight;
373 }
374
375 vec3 trail = trail_accum / max(trail_weight, 0.001);
376 trail *= 0.65;
377
378 // 3. COMPOSITE (Screen Blend)
379 vec3 result = live + trail - (live * trail);
380
381 // Final contrast and pumping
382 result = (result - 0.5) * (1.1 + rms * 0.2) + 0.5;
383 result = mix(result, vec3(1.0) - result, smoothstep(0.9, 1.0, peak));
384
385 color = vec4(clamp(result, 0.0, 1.0), texture(samp, tc).a);
386}
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 CACHE_HISTORY_LAYER(index)
mat2 rotate_2d(float angle)
Evaluates rotate 2d for this shader effect.
float sample_history(int index, float frequency)
Evaluates sample history for this shader effect.
#define SIZE
vec3 palette(float phase)
Evaluates palette for this shader effect.
#define SPECTRUM_HISTORY_LAYER(index)
vec2 mirror_repeat(vec2 point)
Evaluates mirror repeat for this shader effect.
vec4 sample_cache(int index, vec2 uv)
Evaluates sample cache for this shader effect.
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
vec2 fractalFold(vec2 p, float zoom, float t, int i)
Evaluates fractalFold 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
vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect)
Evaluates reflectUV for this shader effect.
Definition aura2.frag:76
float diamondRadius(vec2 p)
Evaluates diamondRadius for this shader effect.
Definition aura2.frag:182
vec3 generate_live_frame(vec2 uv, vec2 res, float aspect, vec2 m, float bass, float mid, float treble, float rms, float peak)
Evaluates generate live frame for this shader effect.
vec2 dynamic_trail_transform(vec2 uv, vec2 center, int index, int total_layers, float bass, float treble, float time)
Evaluates dynamic trail transform for this shader effect.
#define TAU
#define PI
#define frequency
Definition ol.frag:13