ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
darkstar-spectrum-trail-cache-aurora-crucible.frag
Go to the documentation of this file.
1#version 450
2
3layout(set = 0, binding = 1, std140) uniform SpriteExtended {
4 vec4 mouse;
5 vec4 u0;
6 vec4 u1;
7 vec4 u2;
8 vec4 u3;
9 vec4 custom_uniforms[16];
10 vec4 audio_bands;
11 vec4 audio_history;
13#define history_head int(ext.u3.x)
14#define iMouse ext.mouse
15#define iResolution ext.u0.zw
16#define spectrum_history_head int(ext.audio_history.x)
17#define spectrum_history_size int(ext.audio_history.y)
18#define time_f ext.u2.y
19
20/**
21 * @file darkstar-spectrum-trail-cache-aurora-crucible.frag
22 * @brief Vulkan fragment shader: darkstar-spectrum-trail-cache-aurora-crucible.
23 */
24// darkstar-spectrum-trail-cache-aurora-crucible
25// Aurora ribbons melted into a bass-heavy diamond crucible.
26#define STYLE_ID 6
27layout(location = 0) in vec2 tc;
28layout(location = 0) out vec4 color;
29layout(set = 0, binding = 0) uniform sampler2D samp;
30layout(set = 0, binding = 2) uniform sampler2DArray history;
31
32#ifndef SIZE
33#define SIZE 8
34#endif
35#ifndef CACHE_HISTORY_LAYER
36#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
37#endif
38layout(set = 0, binding = 3) uniform sampler1D spectrum0;
39layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
40
41
42#ifndef SPECTRUM_HISTORY_LAYER
43#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
44#endif
45
46
47
48
49const float PI = 3.14159265359;
50const float TAU = 6.28318530718;
51
52/**
53 * @brief Evaluates rotate 2d for this shader effect.
54 * @param angle Input value for the calculation.
55 * @return Computed mat2 value.
56 */
57mat2 rotate_2d(float angle) {
58 float cosine = cos(angle);
59 float sine = sin(angle);
60 return mat2(cosine, -sine, sine, cosine);
61}
62
63/**
64 * @brief Evaluates mirror repeat for this shader effect.
65 * @param point Input value for the calculation.
66 * @return Computed vec2 value.
67 */
68vec2 mirror_repeat(vec2 point) {
69 return 1.0 - abs(mod(point, 2.0) - 1.0);
70}
71
72/**
73 * @brief Evaluates mirror gradient for this shader effect.
74 * @param uv Input value for the calculation.
75 * @param screen_gradient Input value for the calculation.
76 * @return Computed vec2 value.
77 */
78vec2 mirror_gradient(vec2 uv, vec2 screen_gradient) {
79 vec2 periodic_gradient = screen_gradient - round(screen_gradient * 0.5) * 2.0;
80 vec2 direction = vec2(1.0) - 2.0 * step(vec2(1.0), mod(uv, 2.0));
81 return periodic_gradient * direction;
82}
83
84/**
85 * @brief Evaluates sample live for this shader effect.
86 * @param uv Input value for the calculation.
87 * @return Computed vec4 value.
88 */
89vec4 sample_live(vec2 uv) {
90 vec2 gradient_x = mirror_gradient(uv, dFdx(uv));
91 vec2 gradient_y = mirror_gradient(uv, dFdy(uv));
92 return textureGrad(samp, mirror_repeat(uv), gradient_x, gradient_y);
93}
94
95/**
96 * @brief Evaluates sample cache for this shader effect.
97 * @param uv Input value for the calculation.
98 * @param index Input value for the calculation.
99 * @return Computed vec4 value.
100 */
101vec4 sample_cache(vec2 uv, int index) {
102 vec2 gradient_x = mirror_gradient(uv, dFdx(uv));
103 vec2 gradient_y = mirror_gradient(uv, dFdy(uv));
104 float layer = float(CACHE_HISTORY_LAYER(index));
105 return textureGrad(history, vec3(mirror_repeat(uv), layer), gradient_x, gradient_y);
106}
107
108/**
109 * @brief Evaluates spectrum band for this shader effect.
110 * @param center Input value for the calculation.
111 * @param width Input value for the calculation.
112 * @return Computed float value.
113 */
114float spectrum_band(float center, float width) {
115 float left = texture(spectrum0, clamp(center - width, 0.0, 1.0)).r;
116 float middle = texture(spectrum0, clamp(center, 0.0, 1.0)).r;
117 float right = texture(spectrum0, clamp(center + width, 0.0, 1.0)).r;
118 return (left + middle * 2.0 + right) * 0.25;
119}
120
121/**
122 * @brief Evaluates history band for this shader effect.
123 * @param index Input value for the calculation.
124 * @param center Input value for the calculation.
125 * @param width Input value for the calculation.
126 * @return Computed float value.
127 */
128float history_band(int index, float center, float width) {
129 float layer = float(SPECTRUM_HISTORY_LAYER(index + 1));
130 float left = texture(spectrum_history, vec2(clamp(center - width, 0.0, 1.0), layer)).r;
131 float middle = texture(spectrum_history, vec2(clamp(center, 0.0, 1.0), layer)).r;
132 float right = texture(spectrum_history, vec2(clamp(center + width, 0.0, 1.0), layer)).r;
133 return (left + middle * 2.0 + right) * 0.25;
134}
135
136/**
137 * @brief Evaluates palette for this shader effect.
138 * @param phase Input value for the calculation.
139 * @return Computed vec3 value.
140 */
141vec3 palette(float phase) {
142 float style_hue = float(STYLE_ID) * 0.083;
143 return 0.5 + 0.5 * cos(TAU * (phase + style_hue + vec3(0.02, 0.35, 0.68)));
144}
145
146/**
147 * @brief Evaluates tone map for this shader effect.
148 * @param value Input value for the calculation.
149 * @return Computed vec3 value.
150 */
151vec3 tone_map(vec3 value) {
152 value = max(value, 0.0);
153 return clamp((value * (2.51 * value + 0.03)) /
154 (value * (2.43 * value + 0.59) + 0.14),
155 0.0, 1.0);
156}
157
158/**
159 * @brief Evaluates rotate uv for this shader effect.
160 * @param uv Input value for the calculation.
161 * @param angle Input value for the calculation.
162 * @param center Input value for the calculation.
163 * @param aspect Input value for the calculation.
164 * @return Computed vec2 value.
165 */
166vec2 rotate_uv(vec2 uv, float angle, vec2 center, float aspect) {
167 vec2 point = (uv - center) * vec2(aspect, 1.0);
168 point = rotate_2d(angle) * point;
169 return point / vec2(aspect, 1.0) + center;
170}
171
172/**
173 * @brief Evaluates kaleidoscope uv for this shader effect.
174 * @param uv Input value for the calculation.
175 * @param segments Input value for the calculation.
176 * @param center Input value for the calculation.
177 * @param aspect Input value for the calculation.
178 * @return Computed vec2 value.
179 */
180vec2 kaleidoscope_uv(vec2 uv, float segments, vec2 center, float aspect) {
181 vec2 point = (uv - center) * vec2(aspect, 1.0);
182 float radius = length(point);
183 float sector = TAU / segments;
184 float angle = abs(mod(atan(point.y, point.x) + sector * 0.5, sector) - sector * 0.5);
185 point = vec2(cos(angle), sin(angle)) * radius;
186 return point / vec2(aspect, 1.0) + center;
187}
188
189/**
190 * @brief Evaluates diamond fold for this shader effect.
191 * @param uv Input value for the calculation.
192 * @param center Input value for the calculation.
193 * @param aspect Input value for the calculation.
194 * @return Computed vec2 value.
195 */
196vec2 diamond_fold(vec2 uv, vec2 center, float aspect) {
197 vec2 point = abs((uv - center) * vec2(aspect, 1.0));
198 if (point.y > point.x) point = point.yx;
199 return point / vec2(aspect, 1.0) + center;
200}
201
202vec2 fractal_fold(vec2 uv, vec2 center, float aspect, float zoom,
203 float bass, float middle) {
204 vec2 point = uv;
205 for (int iteration = 0; iteration < 3; ++iteration) {
206 float phase = time_f * (0.23 + bass * 0.24) + float(iteration) * 1.7;
207 point = abs((point - center) * (zoom + sin(phase) * (0.08 + middle * 0.13))) -
208 0.5 + center;
209 point = rotate_uv(point, time_f * 0.07 + float(iteration) * 0.11,
210 center, aspect);
211 }
212 return point;
213}
214
215vec2 style_warp(vec2 uv, vec2 center, float aspect, float sub, float bass,
216 float low_mid, float middle, float presence, float high,
217 float air, float flux) {
218 vec2 point = (uv - center) * vec2(aspect, 1.0);
219 float radius = length(point) + 0.0001;
220 float angle = atan(point.y, point.x);
221
222#if STYLE_ID == 0
223 point = abs(point);
224 if (point.y > point.x) point = point.yx;
225 point *= 1.0 + sin(radius * (12.0 + bass * 15.0) - time_f * 2.7) *
226 (0.08 + sub * 0.18);
227#elif STYLE_ID == 1
228 float petals = 7.0 + floor(middle * 7.0);
229 float sector = TAU / petals;
230 float folded_angle = abs(mod(angle + sector * 0.5, sector) - sector * 0.5);
231 radius *= 1.0 + cos(folded_angle * petals * 2.0 + time_f) *
232 (0.12 + low_mid * 0.2);
233 point = vec2(cos(folded_angle), sin(folded_angle)) * radius;
234#elif STYLE_ID == 2
235 point = rotate_2d(PI * 0.25 + presence * 0.2) * point;
236 point = abs(point);
237 point = vec2(point.x + point.y, abs(point.x - point.y)) * 0.72;
238 point += sin(point.yx * (9.0 + high * 12.0) + time_f) * (0.015 + flux * 0.06);
239#elif STYLE_ID == 3
240 point = rotate_2d(log(radius + 0.035) * (0.45 + bass * 0.8) -
241 time_f * (0.12 + low_mid * 0.16)) * point;
242 point *= 1.0 + sin(log(radius + 0.02) * 13.0 - time_f * 2.0) *
243 (0.06 + sub * 0.14);
244#elif STYLE_ID == 4
245 float jet = pow(abs(cos(angle * 2.0)), 9.0);
246 point.x += sign(point.x) * jet * (0.08 + presence * 0.22);
247 point.y += sin(point.x * (11.0 + high * 9.0) - time_f * 3.0) *
248 (0.025 + air * 0.08);
249#elif STYLE_ID == 5
250 for (int iteration = 0; iteration < 4; ++iteration) {
251 point = abs(point) / max(dot(point, point), 0.12) -
252 vec2(0.72 + bass * 0.12, 0.54 + middle * 0.11);
253 point = rotate_2d(0.31 + presence * 0.14) * point;
254 }
255 point *= 0.17 + flux * 0.05;
256#elif STYLE_ID == 6
257 point.x += sin(point.y * (10.0 + middle * 11.0) - time_f * 1.7) *
258 (0.035 + low_mid * 0.1);
259 point.y += cos(point.x * (9.0 + high * 13.0) + time_f * 1.3) *
260 (0.03 + air * 0.09);
261 point = rotate_2d(sin(radius * 8.0 - time_f) * (0.08 + bass * 0.16)) * point;
262#elif STYLE_ID == 7
263 float petals = 8.0 + floor(presence * 6.0);
264 float sector = TAU / petals;
265 float folded_angle = abs(mod(angle + sector * 0.5, sector) - sector * 0.5);
266 float lotus = sin(radius * (17.0 + high * 15.0) - time_f * 3.4);
267 radius *= 1.0 + lotus * (0.07 + bass * 0.12);
268 point = vec2(cos(folded_angle), sin(folded_angle)) * radius;
269#elif STYLE_ID == 8
270 float shock = sin(radius * (24.0 + bass * 18.0) - time_f * (4.0 + flux * 3.0));
271 point *= 1.0 + shock * (0.04 + sub * 0.16);
272 point = rotate_2d(shock * (0.05 + presence * 0.12)) * point;
273#else
274 vec2 chamber = abs(fract(point * (3.0 + floor(middle * 5.0))) - 0.5);
275 point += (chamber.yx - 0.25) * (0.08 + high * 0.16);
276 point = rotate_2d(floor(radius * (8.0 + bass * 6.0)) * PI * 0.25 +
277 time_f * 0.04) * point;
278#endif
279
280 return point / vec2(aspect, 1.0) + center;
281}
282
283vec2 darkstar_wrap(vec2 uv, vec2 center, float aspect, float sub, float bass,
284 float middle, float high, float flux) {
285 vec2 point = (uv - center) * vec2(aspect, 1.0);
286 vec2 diamond = abs(point);
287 if (diamond.y > diamond.x) diamond = diamond.yx;
288
289 float radius = max(diamond.x, diamond.y) + 0.006;
290 float period = 0.32 + bass * 0.26 + middle * 0.12;
291 float travel = time_f * (0.28 + sub * 0.34 + flux * 0.18);
292 float shell = fract((log(radius) - travel) / period);
293 float wrapped_radius = exp(shell * period) * (0.32 + bass * 0.09);
294 float angle = atan(diamond.y, diamond.x) + travel * 0.37 +
295 sin(radius * (17.0 + high * 13.0) + time_f) *
296 (0.16 + middle * 0.2);
297 vec2 wrapped = vec2(cos(angle), sin(angle)) * wrapped_radius;
298 return wrapped / vec2(aspect, 1.0) + center;
299}
300
301/**
302 * @brief Evaluates soft live for this shader effect.
303 * @param uv Input value for the calculation.
304 * @param texel Input value for the calculation.
305 * @param spread Input value for the calculation.
306 * @return Computed vec3 value.
307 */
308vec3 soft_live(vec2 uv, vec2 texel, float spread) {
309 vec3 result = sample_live(uv).rgb * 4.0;
310 result += sample_live(uv + vec2(texel.x, 0.0) * spread).rgb * 2.0;
311 result += sample_live(uv - vec2(texel.x, 0.0) * spread).rgb * 2.0;
312 result += sample_live(uv + vec2(0.0, texel.y) * spread).rgb * 2.0;
313 result += sample_live(uv - vec2(0.0, texel.y) * spread).rgb * 2.0;
314 return result / 12.0;
315}
316
317vec2 trail_transform(vec2 uv, vec2 center, float aspect, float progress,
318 float old_sub, float old_bass, float old_middle,
319 float old_high, float old_air) {
320 vec2 point = (uv - center) * vec2(aspect, 1.0);
321 float shrink = 1.0 + progress * (0.38 + old_sub * 1.4 + old_bass * 0.8);
322 point *= shrink;
323
324#if STYLE_ID % 5 == 0
325 point = rotate_2d(progress * (0.08 + old_high * 0.7) * sin(time_f * 0.4)) * point;
326 point += normalize(point + vec2(0.001)) * old_bass * progress * 0.08;
327#elif STYLE_ID % 5 == 1
328 point.x += sin(point.y * (8.0 + old_middle * 12.0) + progress * TAU) *
329 progress * (0.025 + old_air * 0.08);
330 point.y += cos(point.x * 7.0 - progress * TAU) * old_high * progress * 0.05;
331#elif STYLE_ID % 5 == 2
332 float radius = length(point) + 0.001;
333 point = rotate_2d(sin(radius * 14.0 - time_f) * progress *
334 (0.08 + old_middle * 0.2)) * point;
335#elif STYLE_ID % 5 == 3
336 point.x *= 1.0 + progress * old_middle * 0.25;
337 point.y *= 1.0 - progress * old_high * 0.12;
338 point += vec2(old_air, old_bass) * progress * 0.045;
339#else
340 float radius = length(point) + 0.001;
341 vec2 tangent = vec2(-point.y, point.x) / radius;
342 point += tangent * progress * (0.035 + old_high * 0.16);
343 point += normalize(point + vec2(0.001)) * sin(radius * 19.0 + time_f) *
344 old_bass * progress * 0.05;
345#endif
346
347 return point / vec2(aspect, 1.0) + center;
348}
349
350/**
351 * @brief Executes the fragment shader entry point.
352 */
353void main() {
354 vec2 resolution = max(iResolution, vec2(1.0));
355 vec2 texel = 1.0 / resolution;
356 float aspect = resolution.x / resolution.y;
357 vec2 center = iMouse.z > 0.5 ? iMouse.xy / resolution : vec2(0.5);
358
359 float sub = spectrum_band(0.018, 0.012);
360 float bass = spectrum_band(0.055, 0.025);
361 float low_mid = spectrum_band(0.14, 0.04);
362 float middle = spectrum_band(0.29, 0.055);
363 float presence = spectrum_band(0.47, 0.06);
364 float high = spectrum_band(0.68, 0.055);
365 float air = spectrum_band(0.87, 0.045);
366
367 float previous_sub = history_band(0, 0.018, 0.012);
368 float previous_mid = history_band(0, 0.29, 0.055);
369 float previous_high = history_band(0, 0.68, 0.055);
370 float flux = clamp(abs(sub - previous_sub) * 1.5 +
371 abs(middle - previous_mid) +
372 abs(high - previous_high) * 0.8, 0.0, 1.5);
373 float energy = sub * 0.24 + bass * 0.22 + low_mid * 0.17 +
374 middle * 0.15 + presence * 0.1 + high * 0.08 + air * 0.04;
375
376 float segments = 4.0 + float(STYLE_ID % 5) + floor(middle * 7.0);
377 vec2 warped_uv = kaleidoscope_uv(tc, segments, center, aspect);
378 warped_uv = diamond_fold(warped_uv, center, aspect);
379 float fold_zoom = 1.08 + sub * 0.38 + bass * 0.28 + flux * 0.11;
380 warped_uv = fractal_fold(warped_uv, center, aspect, fold_zoom, bass, middle);
381 warped_uv = style_warp(warped_uv, center, aspect, sub, bass, low_mid,
382 middle, presence, high, air, flux);
383 warped_uv = darkstar_wrap(warped_uv, center, aspect, sub, bass, middle,
384 high, flux);
385
386 vec2 direction = normalize((warped_uv - center) * vec2(aspect, 1.0) + vec2(0.001));
387 vec2 chroma_offset = direction * vec2(1.0 / aspect, 1.0) *
388 (0.002 + presence * 0.008 + air * 0.016 + flux * 0.006);
389 float blur_spread = 1.0 + low_mid * 2.5;
390 vec3 red_sample = soft_live(warped_uv + chroma_offset, texel, blur_spread);
391 vec3 green_sample = soft_live(warped_uv, texel, blur_spread);
392 vec3 blue_sample = soft_live(warped_uv - chroma_offset, texel, blur_spread);
393 vec3 kaleido = vec3(red_sample.r, green_sample.g, blue_sample.b);
394
395 vec3 base = sample_live(tc).rgb;
396 float radial = length((tc - center) * vec2(aspect, 1.0));
397 float spectral_ring = 0.5 + 0.5 * sin(log(radial + 0.025) *
398 (10.0 + middle * 13.0) - time_f *
399 (2.0 + bass * 3.0));
400 float live_mix = clamp(0.52 + energy * 0.32 + flux * 0.22, 0.0, 0.94);
401 vec3 live = mix(base, kaleido, live_mix);
402 live *= 0.72 + spectral_ring * (0.28 + presence * 0.32);
403 live += palette(spectral_ring * 0.18 + time_f * 0.035 + high) *
404 pow(spectral_ring, 8.0) * (0.04 + flux * 0.3);
405
406 vec3 trail_accum = vec3(0.0);
407 float trail_weight = 0.0;
408 for (int index = 0; index < SIZE; ++index) {
409 float progress = float(index + 1) / float(max(SIZE, 1));
410 float old_sub = history_band(index, 0.018, 0.012);
411 float old_bass = history_band(index, 0.055, 0.025);
412 float old_middle = history_band(index, 0.29, 0.055);
413 float old_high = history_band(index, 0.68, 0.055);
414 float old_air = history_band(index, 0.87, 0.045);
415 vec2 history_uv = trail_transform(warped_uv, center, aspect, progress,
416 old_sub, old_bass, old_middle,
417 old_high, old_air);
418 vec3 cached = sample_cache(history_uv, index).rgb;
419 float old_energy = old_sub * 0.32 + old_bass * 0.25 +
420 old_middle * 0.22 + old_high * 0.13 + old_air * 0.08;
421 vec3 tint = palette(float(STYLE_ID) * 0.07 + progress * 0.62 +
422 old_middle * 0.5 + old_high * 0.28);
423 float weight = exp(-progress * (2.6 + high * 0.8)) *
424 (0.72 + old_energy * 0.5);
425 trail_accum += mix(cached, cached * tint, 0.42 + progress * 0.4) * weight;
426 trail_weight += weight;
427 }
428
429 vec3 trail = trail_accum / max(trail_weight, 0.001);
430 trail *= 0.45 + bass * 0.22 + middle * 0.13;
431 vec3 result = live + trail - live * trail;
432 result += palette(energy * 0.6 + time_f * 0.06) * flux * 0.18;
433 result = (result - 0.5) * (1.04 + presence * 0.2 + flux * 0.1) + 0.5;
434
435 color = vec4(tone_map(result), sample_live(tc).a);
436}
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.
#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.
vec3 tone_map(vec3 value)
Evaluates tone map for this shader effect.
float energy()
Evaluates energy for this shader effect.
vec2 kaleido(vec2 p, float seg)
Evaluates kaleido for this shader effect.
vec2 style_warp(vec2 uv, vec2 center, float aspect, float sub, float bass, float low_mid, float middle, float presence, float high, float air, float flux)
vec2 mirror_gradient(vec2 uv, vec2 screen_gradient)
Evaluates mirror gradient for this shader effect.
vec2 darkstar_wrap(vec2 uv, vec2 center, float aspect, float sub, float bass, float middle, float high, float flux)
vec2 fractal_fold(vec2 uv, vec2 center, float aspect, float zoom, float bass, float middle)
vec2 rotate_uv(vec2 uv, float angle, vec2 center, float aspect)
Evaluates rotate uv for this shader effect.
vec2 kaleidoscope_uv(vec2 uv, float segments, vec2 center, float aspect)
Evaluates kaleidoscope uv for this shader effect.
float spectrum_band(float center, float width)
Evaluates spectrum band for this shader effect.
float history_band(int index, float center, float width)
Evaluates history band for this shader effect.
vec2 diamond_fold(vec2 uv, vec2 center, float aspect)
Evaluates diamond fold for this shader effect.
vec4 sample_live(vec2 uv)
Evaluates sample live for this shader effect.
vec2 trail_transform(vec2 uv, vec2 center, float aspect, float progress, float old_sub, float old_bass, float old_middle, float old_high, float old_air)
vec3 soft_live(vec2 uv, vec2 texel, float spread)
Evaluates soft live for this shader effect.
#define TAU
#define PI
float diamond(vec2 p)
Evaluates diamond for this shader effect.
Definition dmd_gpt.frag:29