ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
psyche-bubble-cache-mobius-ribbon.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 amp_high ext.audio_bands.z
14#define amp_low ext.audio_bands.x
15#define amp_mid ext.audio_bands.y
16#define amp_peak ext.u2.w
17#define amp_smooth ext.u3.w
18#define history_head int(ext.u3.x)
19#define iMouse ext.mouse
20#define iResolution ext.u0.zw
21#define spectrum_history_head int(ext.audio_history.x)
22#define spectrum_history_size int(ext.audio_history.y)
23#define time_f ext.u2.y
24
25/**
26 * @file psyche-bubble-cache-mobius-ribbon.frag
27 * @brief Vulkan fragment shader: psyche-bubble-cache-mobius-ribbon.
28 */
29// psyche-bubble-cache-mobius-ribbon
30// Cache-recursive bubble psychedelia with live and historical FFT choreography.
31#define PSYCHE_ID 9
32layout(location = 0) in vec2 tc;
33layout(location = 0) out vec4 color;
34layout(set = 0, binding = 0) uniform sampler2D samp;
35layout(set = 0, binding = 2) uniform sampler2DArray history;
36
37#ifndef SIZE
38#define SIZE 8
39#endif
40#ifndef CACHE_HISTORY_LAYER
41#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
42#endif
43layout(set = 0, binding = 3) uniform sampler1D spectrum0;
44layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
45
46
47#ifndef SPECTRUM_HISTORY_LAYER
48#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
49#endif
50
51
52
53
54
55
56
57
58
59const float PI = 3.14159265359;
60const float TAU = 6.28318530718;
61
62/**
63 * @brief Evaluates rotate 2d for this shader effect.
64 * @param angle Input value for the calculation.
65 * @return Computed mat2 value.
66 */
67mat2 rotate_2d(float angle) {
68 float cosine = cos(angle);
69 float sine = sin(angle);
70 return mat2(cosine, -sine, sine, cosine);
71}
72
73/**
74 * @brief Evaluates mirror repeat for this shader effect.
75 * @param point Input value for the calculation.
76 * @return Computed vec2 value.
77 */
78vec2 mirror_repeat(vec2 point) {
79 return 1.0 - abs(mod(point, 2.0) - 1.0);
80}
81
82/**
83 * @brief Evaluates hash 21 for this shader effect.
84 * @param point Input value for the calculation.
85 * @return Computed float value.
86 */
87float hash_21(vec2 point) {
88 return fract(sin(dot(point, vec2(127.1, 311.7))) * 43758.5453123);
89}
90
91/**
92 * @brief Evaluates value noise for this shader effect.
93 * @param point Input value for the calculation.
94 * @return Computed float value.
95 */
96float value_noise(vec2 point) {
97 vec2 cell = floor(point);
98 vec2 part = fract(point);
99 part = part * part * (3.0 - 2.0 * part);
100 float lower = mix(hash_21(cell), hash_21(cell + vec2(1.0, 0.0)), part.x);
101 float upper = mix(hash_21(cell + vec2(0.0, 1.0)), hash_21(cell + 1.0), part.x);
102 return mix(lower, upper, part.y);
103}
104
105/**
106 * @brief Evaluates fbm for this shader effect.
107 * @param point Input value for the calculation.
108 * @return Computed float value.
109 */
110float fbm(vec2 point) {
111 float result = 0.0;
112 float weight = 0.5;
113 for (int octave = 0; octave < 4; ++octave) {
114 result += value_noise(point) * weight;
115 point = rotate_2d(0.73) * point * 2.03 + vec2(1.7, 0.9);
116 weight *= 0.5;
117 }
118 return result;
119}
120
121/**
122 * @brief Evaluates hex cell for this shader effect.
123 * @param point Input value for the calculation.
124 * @return Computed vec2 value.
125 */
126vec2 hex_cell(vec2 point) {
127 vec2 scale = vec2(1.0, 1.7320508);
128 vec2 first = mod(point, scale) - scale * 0.5;
129 vec2 second = mod(point - scale * 0.5, scale) - scale * 0.5;
130 return dot(first, first) < dot(second, second) ? first : second;
131}
132
133/**
134 * @brief Evaluates kaleidoscope for this shader effect.
135 * @param point Input value for the calculation.
136 * @param sides Input value for the calculation.
137 * @return Computed vec2 value.
138 */
139vec2 kaleidoscope(vec2 point, float sides) {
140 float radius = length(point);
141 float sector = TAU / max(sides, 2.0);
142 float angle = abs(mod(atan(point.y, point.x) + sector * 0.5, sector) - sector * 0.5);
143 return vec2(cos(angle), sin(angle)) * radius;
144}
145
146/**
147 * @brief Evaluates recursive fold for this shader effect.
148 * @param point Input value for the calculation.
149 * @param phase Input value for the calculation.
150 * @return Computed vec2 value.
151 */
152vec2 recursive_fold(vec2 point, float phase) {
153 for (int fold = 0; fold < 4; ++fold) {
154 point = abs(point) / max(dot(point, point), 0.18) - 0.72;
155 point = rotate_2d(0.37 + phase * 0.03 + float(fold) * 0.11) * point;
156 }
157 return point;
158}
159
160/**
161 * @brief Evaluates voronoi cell for this shader effect.
162 * @param point Input value for the calculation.
163 * @return Computed vec2 value.
164 */
165vec2 voronoi_cell(vec2 point) {
166 vec2 base = floor(point);
167 vec2 part = fract(point);
168 vec2 nearest = vec2(0.0);
169 float nearest_distance = 8.0;
170 for (int y = -1; y <= 1; ++y) {
171 for (int x = -1; x <= 1; ++x) {
172 vec2 neighbor = vec2(float(x), float(y));
173 vec2 random_point = vec2(hash_21(base + neighbor),
174 hash_21(base + neighbor + 17.31));
175 random_point = 0.5 + 0.42 * sin(time_f * 0.31 + TAU * random_point);
176 vec2 difference = neighbor + random_point - part;
177 float distance_squared = dot(difference, difference);
178 if (distance_squared < nearest_distance) {
179 nearest_distance = distance_squared;
180 nearest = difference;
181 }
182 }
183 }
184 return nearest;
185}
186
187/**
188 * @brief Evaluates palette for this shader effect.
189 * @param phase Input value for the calculation.
190 * @return Computed vec3 value.
191 */
192vec3 palette(float phase) {
193 float identity = float(PSYCHE_ID);
194 vec3 offset = vec3(0.03, 0.34, 0.67) +
195 identity * vec3(0.037, 0.053, 0.071);
196 vec3 frequency = vec3(1.0, 1.13 + mod(identity, 3.0) * 0.09,
197 0.83 + mod(identity, 5.0) * 0.07);
198 return 0.5 + 0.5 * cos(TAU * (phase * frequency + offset));
199}
200
201/**
202 * @brief Evaluates tone map for this shader effect.
203 * @param value Input value for the calculation.
204 * @return Computed vec3 value.
205 */
206vec3 tone_map(vec3 value) {
207 value = max(value, 0.0);
208 return clamp((value * (2.51 * value + 0.03)) /
209 (value * (2.43 * value + 0.59) + 0.14),
210 0.0, 1.0);
211}
212
213/**
214 * @brief Evaluates sample live for this shader effect.
215 * @param uv Input value for the calculation.
216 * @return Computed vec4 value.
217 */
218vec4 sample_live(vec2 uv) {
219 return texture(samp, mirror_repeat(uv));
220}
221
222/**
223 * @brief Evaluates sample cache for this shader effect.
224 * @param index Input value for the calculation.
225 * @param uv Input value for the calculation.
226 * @return Computed vec4 value.
227 */
228vec4 sample_cache(int index, vec2 uv) {
229 return texture(history,
230 vec3(mirror_repeat(uv), float(CACHE_HISTORY_LAYER(index))));
231}
232
233/**
234 * @brief Evaluates sample history for this shader effect.
235 * @param index Input value for the calculation.
236 * @param frequency Input value for the calculation.
237 * @return Computed float value.
238 */
239float sample_history(int index, float frequency) {
240 return texture(spectrum_history,
241 vec2(clamp(frequency, 0.0, 1.0),
242 float(SPECTRUM_HISTORY_LAYER(index + 1)))).r;
243}
244
245// x is displacement phase, y is luminous structure, z is color phase.
246/**
247 * @brief Evaluates psyche field for this shader effect.
248 * @param point Input value for the calculation.
249 * @param bass Input value for the calculation.
250 * @param middle Input value for the calculation.
251 * @param treble Input value for the calculation.
252 * @param age Input value for the calculation.
253 * @return Computed vec3 value.
254 */
255vec3 psyche_field(vec2 point, float bass, float middle, float treble, float age) {
256 float radius = length(point) + 0.0001;
257 float angle = atan(point.y, point.x);
258 float time = time_f;
259
260 float ribbon = sin(angle * 2.0 + sin(radius * 9.0 - time) * 2.0 + age * TAU);
261 float half_twist = cos(angle + radius * 16.0 - time * 2.0);
262 float strip = exp(-abs(ribbon) * (8.0 + treble * 6.0));
263 float color_phase = 0.5 +
264 sin(angle + radius * 3.0 - time * 0.35) * 0.23 +
265 cos(angle * 2.0 - age * TAU) * 0.11;
266 return vec3(half_twist, strip * (0.45 + 0.55 * abs(half_twist)),
267 color_phase + half_twist * 0.2 + age);
268}
269
270vec2 psyche_warp(vec2 uv, vec2 point, vec3 signal, float bass, float middle,
271 float treble, float age) {
272 float radius = length(point) + 0.001;
273 float angle = atan(point.y, point.x);
274 vec2 radial = point / radius;
275 vec2 tangent = vec2(-radial.y, radial.x);
276 float depth = 0.25 + age * 0.75;
277
278 float ribbon_twist = sin(angle + age * TAU) * PI * 0.27 +
279 signal.x * PI * 0.12;
280 vec2 strip = rotate_2d(ribbon_twist) * point;
281 uv = strip / vec2(iResolution.x / max(iResolution.y, 1.0), 1.0) + 0.5;
282 uv += tangent * signal.x * 0.025;
283
284 return uv;
285}
286
287/**
288 * @brief Evaluates layer gate for this shader effect.
289 * @param point Input value for the calculation.
290 * @param signal Input value for the calculation.
291 * @param progress Input value for the calculation.
292 * @param index Input value for the calculation.
293 * @return Computed float value.
294 */
295float layer_gate(vec2 point, vec3 signal, float progress, int index) {
296 float radius = length(point) + 0.0001;
297 float angle = atan(point.y, point.x);
298 float slot = float(index);
299
300 float traveling_fold = sin(angle + progress * TAU);
301 return 0.22 + 0.78 * exp(-abs(traveling_fold) * 9.0);
302}
303
304vec3 memory_blend(vec3 live_color, vec3 memory, vec3 previous, int index,
305 float energy) {
306 int family = PSYCHE_ID % 6;
307 if (family == 0) {
308 return memory;
309 }
310 if (family == 1) {
311 return mix(memory, 1.0 - (1.0 - memory) * (1.0 - live_color),
312 0.35 + energy * 0.25);
313 }
314 if (family == 2) {
315 return mix(memory, abs(memory - live_color) * 1.35, 0.3 + energy * 0.35);
316 }
317 if (family == 3) {
318 return memory * (0.7 + live_color * 0.65);
319 }
320 if (family == 4) {
321 vec3 shifted = (index % 3 == 0) ? memory.gbr :
322 ((index % 3 == 1) ? memory.brg : memory.rgb);
323 return mix(memory, shifted, 0.35 + energy * 0.3);
324 }
325 return mix(memory, abs(memory - previous) + memory * 0.55,
326 0.28 + energy * 0.3);
327}
328
329/**
330 * @brief Executes the fragment shader entry point.
331 */
332void main() {
333 vec2 resolution = max(iResolution, vec2(1.0));
334 float aspect = resolution.x / resolution.y;
335 vec2 center = iMouse.z > 0.0 ? iMouse.xy / resolution : vec2(0.5);
336 vec2 point = (tc - center) * vec2(aspect, 1.0);
337
338 float bass = max(texture(spectrum0, 0.035).r, amp_low);
339 float middle = max(texture(spectrum0, 0.24).r, amp_mid);
340 float treble = max(texture(spectrum0, 0.63).r, amp_high);
341
342 vec3 live_signal = psyche_field(point, bass, middle, treble, 0.0);
343 vec2 live_uv = psyche_warp(tc, point, live_signal, bass, middle, treble, 0.0);
344 float chroma = 0.002 + treble * 0.018 + abs(live_signal.x) * 0.004;
345 vec2 chroma_direction = vec2(cos(live_signal.z * TAU), sin(live_signal.z * TAU));
346
347 vec3 live_color;
348 live_color.r = sample_live(live_uv + chroma_direction * chroma).r;
349 live_color.g = sample_live(live_uv).g;
350 live_color.b = sample_live(live_uv - chroma_direction * chroma).b;
351 live_color += palette(live_signal.z + time_f * 0.035) *
352 live_signal.y * (0.12 + amp_smooth * 0.22);
353
354 vec3 accumulated = live_color * 1.25;
355 float total_weight = 1.25;
356 vec3 previous = live_color;
357
358 for (int index = 0; index < SIZE; ++index) {
359 float progress = float(index + 1) / float(max(SIZE, 1));
360 float old_bass = sample_history(index, 0.035);
361 float old_middle = sample_history(index, 0.24);
362 float old_treble = sample_history(index, 0.63);
363 float frequency_trace = sample_history(index,
364 fract(0.08 + progress * 0.79));
365
366 vec3 signal = psyche_field(point, old_bass, old_middle, old_treble,
367 progress);
368 vec2 history_uv = psyche_warp(tc, point, signal, old_bass, old_middle,
369 old_treble, progress);
370 vec3 memory = sample_cache(index, history_uv).rgb;
371
372 vec3 tint = palette(signal.z + progress * 0.63 +
373 frequency_trace * 0.71);
374 float saturation = 0.45 + old_middle * 0.55 + signal.y * 0.2;
375 memory = mix(vec3(dot(memory, vec3(0.299, 0.587, 0.114))), memory,
376 saturation);
377 memory *= 0.68 + tint * (0.46 + old_treble * 0.34);
378 memory += tint * signal.y * (0.08 + frequency_trace * 0.2);
379 memory = memory_blend(live_color, memory, previous, index,
380 old_bass + old_treble);
381
382 float gate = layer_gate(point, signal, progress, index);
383 float decay = 2.0 + float(PSYCHE_ID % 7) * 0.17;
384 float weight = exp(-progress * decay) * gate *
385 (0.72 + frequency_trace * 0.5);
386 accumulated += memory * weight;
387 total_weight += weight;
388 previous = memory;
389 }
390
391 vec3 result = accumulated / max(total_weight, 0.001);
392 result = (result - 0.5) * (1.08 + amp_smooth * 0.32) + 0.5;
393
394 int peak_mode = PSYCHE_ID % 4;
395 float peak = smoothstep(0.84, 1.0, amp_peak);
396 if (peak_mode == 0) {
397 result = mix(result, 1.0 - result, peak * 0.85);
398 } else if (peak_mode == 1) {
399 result += palette(live_signal.z + 0.5) * peak * 0.28;
400 } else if (peak_mode == 2) {
401 result = mix(result, result.brg, peak * 0.72);
402 } else {
403 result = mix(result, result * result * (3.0 - 2.0 * result),
404 peak * 0.8);
405 }
406
407 color = vec4(tone_map(result), sample_live(tc).a);
408}
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
vec2 kaleidoscope(vec2 point, float sides)
Evaluates kaleidoscope for this shader effect.
float fbm(vec2 point)
Evaluates fbm for this shader effect.
#define amp_smooth
#define CACHE_HISTORY_LAYER(index)
#define amp_mid
float value_noise(vec2 point)
Evaluates value noise for this shader effect.
vec2 hex_cell(vec2 point)
Evaluates hex cell for this shader effect.
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
float hash_21(vec2 point)
Evaluates hash 21 for this shader effect.
vec3 palette(float phase)
Evaluates palette for this shader effect.
#define amp_low
#define amp_high
#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.
#define amp_peak
vec3 tone_map(vec3 value)
Evaluates tone map for this shader effect.
vec3 saturation(vec3 color, float amount)
Evaluates saturation for this shader effect.
float energy()
Evaluates energy for this shader effect.
vec2 cell(vec2 p)
Evaluates cell for this shader effect.
vec4 sample_live(vec2 uv)
Evaluates sample live for this shader effect.
#define TAU
#define PI
vec2 fold(vec2 uv, float zoom, float t, vec2 c, float aspect)
Evaluates fold for this shader effect.
#define frequency
Definition ol.frag:13
vec3 psyche_field(vec2 point, float bass, float middle, float treble, float age)
Evaluates psyche field for this shader effect.
vec3 memory_blend(vec3 live_color, vec3 memory, vec3 previous, int index, float energy)
vec2 voronoi_cell(vec2 point)
Evaluates voronoi cell for this shader effect.
vec2 recursive_fold(vec2 point, float phase)
Evaluates recursive fold for this shader effect.
vec2 psyche_warp(vec2 uv, vec2 point, vec3 signal, float bass, float middle, float treble, float age)
float layer_gate(vec2 point, vec3 signal, float progress, int index)
Evaluates layer gate for this shader effect.