ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
ant_texture_cache_spectrum_scale_cosmic_web.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_peak ext.u2.w
14#define amp_smooth ext.u3.w
15#define history_head int(ext.u3.x)
16#define iResolution ext.u0.zw
17#define spectrum_history_head int(ext.audio_history.x)
18#define spectrum_history_size int(ext.audio_history.y)
19#define time_f ext.u2.y
20
21/**
22 * @file ant_texture_cache_spectrum_scale_cosmic_web.frag
23 * @brief Vulkan fragment shader: ant texture cache spectrum scale cosmic web.
24 */
25// ant_texture_cache_spectrum_scale_cosmic_web
26// Trail-cache shader scaled by SIZE (--texture-cache-size).
27// Uses textures[0..SIZE-1] for cached frames and spectrum0..7 for audio.
28
29#ifndef SIZE
30#define SIZE 8
31#endif
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
55const float TAU = 6.28318530718;
56
57/**
58 * @brief Evaluates specHist for this shader effect.
59 * @param i Input value for the calculation.
60 * @param f Input value for the calculation.
61 * @return Computed float value.
62 */
63float specHist(int i, float f) {
64 int j = i & 7;
65 if (j == 0) return texture(spectrum0, f).r;
66 if (j == 1) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(1)))).r;
67 if (j == 2) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(2)))).r;
68 if (j == 3) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(3)))).r;
69 if (j == 4) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(4)))).r;
70 if (j == 5) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(5)))).r;
71 if (j == 6) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(6)))).r;
72 return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(7)))).r;
73}
74
75/**
76 * @brief Evaluates rot for this shader effect.
77 * @param p Input value for the calculation.
78 * @param a Input value for the calculation.
79 * @return Computed vec2 value.
80 */
81vec2 rot(vec2 p, float a) {
82 float c = cos(a); float s = sin(a);
83 return vec2(c * p.x - s * p.y, s * p.x + c * p.y);
84}
85
86/**
87 * @brief Evaluates hash12 for this shader effect.
88 * @param p Input value for the calculation.
89 * @return Computed float value.
90 */
91float hash12(vec2 p) {
92 p = fract(p * vec2(123.34, 456.21));
93 p += dot(p, p + 45.32);
94 return fract(p.x * p.y);
95}
96
97/**
98 * @brief Evaluates palette for this shader effect.
99 * @param t Input value for the calculation.
100 * @param a Input value for the calculation.
101 * @param b Input value for the calculation.
102 * @param c Input value for the calculation.
103 * @param d Input value for the calculation.
104 * @return Computed vec3 value.
105 */
106vec3 palette(float t, vec3 a, vec3 b, vec3 c, vec3 d) {
107 return a + b * cos(TAU * (c * t + d));
108}
109
110
111/**
112 * @brief Evaluates styleDrift for this shader effect.
113 * @param uv Input value for the calculation.
114 * @param layer Input value for the calculation.
115 * @param age Input value for the calculation.
116 * @param hB Input value for the calculation.
117 * @param hM Input value for the calculation.
118 * @param hT Input value for the calculation.
119 * @param hA Input value for the calculation.
120 * @param oldest Input value for the calculation.
121 * @return Computed vec2 value.
122 */
123vec2 styleDrift(vec2 uv, float layer, float age, float hB, float hM, float hT, float hA, vec3 oldest) {
124 float n = hash12(floor(uv * (10.0 + age * 8.0)) + layer);
125 return (vec2(n, fract(n * 7.13)) - 0.5) * (0.006 + age * 0.015 + hT * 0.012);
126
127}
128
129/**
130 * @brief Evaluates styleColor for this shader effect.
131 * @param cached Input value for the calculation.
132 * @param layer Input value for the calculation.
133 * @param age Input value for the calculation.
134 * @param hB Input value for the calculation.
135 * @param hT Input value for the calculation.
136 * @return Computed vec3 value.
137 */
138vec3 styleColor(vec3 cached, float layer, float age, float hB, float hT) {
139 vec3 web = mix(cached, cached * vec3(0.6, 0.7, 1.4), age * 0.6);
140 return web;
141
142}
143
144/**
145 * @brief Executes the fragment shader entry point.
146 */
147void main() {
148 float aspect = iResolution.x / iResolution.y;
149 vec2 uv = (tc - 0.5) * vec2(aspect, 1.0);
150
151 float bass = texture(spectrum0, 0.03).r;
152 float mid = texture(spectrum0, 0.18).r;
153 float treble = texture(spectrum0, 0.52).r;
154 float air = texture(spectrum0, 0.86).r;
155
156 float histBass = 0.0;
157 float histMid = 0.0;
158 float histTreble = 0.0;
159 float histAir = 0.0;
160 for (int i = 0; i < 8; ++i) {
161 histBass += specHist(i, 0.03);
162 histMid += specHist(i, 0.18);
163 histTreble += specHist(i, 0.52);
164 histAir += specHist(i, 0.86);
165 }
166 histBass /= 8.0; histMid /= 8.0; histTreble /= 8.0; histAir /= 8.0;
167
168 vec3 oldest = texture(history, vec3(tc, float(CACHE_HISTORY_LAYER(SIZE - 1)))).rgb;
169
170 vec3 live = texture(samp, tc + styleDrift(uv, 0.0, 0.0, bass, mid, treble, air, oldest)).rgb;
171
172 // Soften decay for larger caches so distant frames remain visible.
173 float decay = mix(0.81, 0.94, clamp(float(SIZE - 8) / 24.0, 0.0, 1.0));
174
175 vec3 accum = live;
176 float wsum = 1.0;
177 for (int i = 0; i < SIZE; ++i) {
178 float layer = float(i + 1);
179 float age = layer / float(SIZE);
180 float hB = specHist(i, 0.03);
181 float hM = specHist(i, 0.18);
182 float hT = specHist(i, 0.52);
183 float hA = specHist(i, 0.86);
184
185 vec2 drift = styleDrift(uv, layer, age, hB, hM, hT, hA, oldest);
186 vec3 cached = texture(history, vec3(tc + drift, float(CACHE_HISTORY_LAYER(i)))).rgb;
187 cached = styleColor(cached, layer, age, hB, hT);
188
189 float w = pow(decay, layer) * (1.0 + hT * 0.9 + hA * 0.3);
190 accum += cached * w;
191 wsum += w;
192 }
193 accum /= wsum;
194
195 accum *= 0.96 + amp_smooth * 0.10;
196
197
198 color = vec4(clamp(accum, 0.0, 1.0), 1.0);
199}
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 amp_smooth
#define CACHE_HISTORY_LAYER(index)
#define SIZE
vec3 palette(float phase)
Evaluates palette for this shader effect.
#define SPECTRUM_HISTORY_LAYER(index)
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
float specHist(int i, float f)
Evaluates specHist for this shader effect.
vec2 styleDrift(vec2 uv, float layer, float age, float hB, float hM, float hT, float hA, vec3 oldest)
Evaluates styleDrift for this shader effect.
float hash12(vec2 p)
Evaluates hash12 for this shader effect.
vec3 styleColor(vec3 cached, float layer, float age, float hB, float hT)
Evaluates styleColor for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
#define TAU