ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
energy-cache-code-ion-web.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file energy-cache-code-ion-web.frag
5 * @brief Vulkan fragment shader: energy-cache-code-ion-web.
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_peak ext.u2.w
18#define amp_smooth ext.u3.w
19#define history_head int(ext.u3.x)
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// Energy cache code: a charged web binds live video to spectral memory.
26layout(location = 0) in vec2 tc;
27layout(location = 0) out vec4 color;
28layout(set = 0, binding = 0) uniform sampler2D samp;
29layout(set = 0, binding = 2) uniform sampler2DArray history;
30
31#ifndef SIZE
32#define SIZE 8
33#endif
34#ifndef CACHE_HISTORY_LAYER
35#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
36#endif
37layout(set = 0, binding = 3) uniform sampler1D spectrum0;
38layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
39
40
41#ifndef SPECTRUM_HISTORY_LAYER
42#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
43#endif
44
45
46
47
48const float TAU = 6.28318530718;
49
50/**
51 * @brief Evaluates mirror repeat for this shader effect.
52 * @param point Input value for the calculation.
53 * @return Computed vec2 value.
54 */
55vec2 mirror_repeat(vec2 point) { return 1.0 - abs(mod(point, 2.0) - 1.0); }
56/**
57 * @brief Evaluates hash 21 for this shader effect.
58 * @param point Input value for the calculation.
59 * @return Computed float value.
60 */
61float hash_21(vec2 point) { return fract(sin(dot(point, vec2(127.1, 311.7))) * 43758.5453123); }
62/**
63 * @brief Evaluates palette for this shader effect.
64 * @param phase Input value for the calculation.
65 * @return Computed vec3 value.
66 */
67vec3 palette(float phase) { return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.06, 0.41, 0.78))); }
68/**
69 * @brief Evaluates sample cache for this shader effect.
70 * @param index Input value for the calculation.
71 * @param uv Input value for the calculation.
72 * @return Computed vec3 value.
73 */
74vec3 sample_cache(int index, vec2 uv) { return texture(history, vec3(mirror_repeat(uv), float(CACHE_HISTORY_LAYER(index)))).rgb; }
75/**
76 * @brief Evaluates history fft for this shader effect.
77 * @param index Input value for the calculation.
78 * @param frequency Input value for the calculation.
79 * @return Computed float value.
80 */
81float history_fft(int index, float frequency) {
82 int maximum_age = max(min(SIZE, spectrum_history_size) - 1, 0);
83 int age = min(index + 1, maximum_age);
84 return texture(spectrum_history, vec2(frequency, float(SPECTRUM_HISTORY_LAYER(age)))).r;
85}
86
87/**
88 * @brief Evaluates ion cells for this shader effect.
89 * @param point Input value for the calculation.
90 * @param scale Input value for the calculation.
91 * @return Computed float value.
92 */
93float ion_cells(vec2 point, float scale) {
94 vec2 grid = point * scale;
95 vec2 cell = floor(grid);
96 vec2 local = fract(grid) - 0.5;
97 float nearest = 2.0;
98 for (int y = -1; y <= 1; ++y) {
99 for (int x = -1; x <= 1; ++x) {
100 vec2 offset = vec2(float(x), float(y));
101 vec2 seed = vec2(hash_21(cell + offset), hash_21(cell + offset + 17.3)) - 0.5;
102 seed += 0.28 * vec2(sin(time_f + seed.x * TAU), cos(time_f * 0.8 + seed.y * TAU));
103 nearest = min(nearest, length(local - offset - seed));
104 }
105 }
106 return nearest;
107}
108
109/**
110 * @brief Executes the fragment shader entry point.
111 */
112void main() {
113 vec2 resolution = max(iResolution, vec2(1.0));
114 vec2 aspect = vec2(resolution.x / resolution.y, 1.0);
115 vec2 point = (tc - 0.5) * aspect;
116 float bass = texture(spectrum0, 0.04).r;
117 float middle = texture(spectrum0, 0.27).r;
118 float high = texture(spectrum0, 0.73).r;
119 float cells = ion_cells(point, 7.0 + middle * 4.0);
120 float web = exp(-abs(cells - 0.43) * (38.0 + high * 20.0));
121 vec2 warp = vec2(sin(point.y * 23.0 + time_f * 4.0), cos(point.x * 21.0 - time_f * 3.0)) * web * (0.025 + bass * 0.04);
122 vec3 live = texture(samp, mirror_repeat(tc + warp)).rgb;
123 live *= 0.75 + palette(cells + time_f * 0.06) * 0.8;
124 live += palette(cells * 0.8 - time_f * 0.13) * web * (0.9 + high * 2.7);
125
126 vec3 accumulated = live;
127 float total_weight = 1.0;
128 for (int index = 0; index < SIZE; ++index) {
129 float generation = float(index + 1);
130 float age = generation / float(max(SIZE, 1));
131 vec3 old_audio = vec3(history_fft(index, 0.04), history_fft(index, 0.27), history_fft(index, 0.73));
132 vec2 cache_point = point * (1.0 - age * (0.055 + old_audio.x * 0.075));
133 cache_point += vec2(sin(cache_point.y * 14.0 + generation), cos(cache_point.x * 13.0 - generation)) * old_audio.z * age * 0.035;
134 vec3 memory = sample_cache(index, cache_point / aspect + 0.5);
135 float old_web = exp(-abs(ion_cells(cache_point + age * 0.11, 7.0 + old_audio.y * 4.0) - 0.43) * 30.0);
136 memory *= mix(vec3(0.65), palette(age + old_audio.y), 0.55 + old_web * 0.35);
137 float weight = pow(0.79, generation) * (0.8 + old_web * 0.6);
138 accumulated += memory * weight;
139 total_weight += weight;
140 }
141 vec3 result = accumulated / total_weight;
142 result += palette(web + time_f * 0.08) * web * (0.55 + amp_peak * 1.3);
143 result = (result - 0.5) * (1.27 + amp_smooth * 0.28) + 0.5;
144 color = vec4(clamp(result, 0.0, 1.0), 1.0);
145}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
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 amp_smooth
#define CACHE_HISTORY_LAYER(index)
#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 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
#define spectrum_history_size
#define seed
Definition air-bowl.frag:20
shared uint cells[10][10]
vec2 warp(vec2 p, vec2 o, float k)
Evaluates warp for this shader effect.
float history_fft(int index, float frequency)
Evaluates history fft for this shader effect.
vec2 cell(vec2 p)
Evaluates cell for this shader effect.
#define TAU
float ion_cells(vec2 point, float scale)
Evaluates ion cells for this shader effect.
#define frequency
Definition ol.frag:13