ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
ant_texture_cache_spectrum_scale_vortex.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_vortex.frag
23 * @brief Vulkan fragment shader: ant texture cache spectrum scale vortex.
24 */
25// ant_texture_cache_spectrum_scale_vortex
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 r = length(uv) + 1e-3;
125 float ang = atan(uv.y, uv.x);
126 float twist = age * 1.4 + hM * 1.2 + time_f * 0.4;
127 vec2 q = vec2(cos(ang + twist), sin(ang + twist)) * r;
128 return (q - uv) * 0.10;
129
130}
131
132/**
133 * @brief Evaluates styleColor for this shader effect.
134 * @param cached Input value for the calculation.
135 * @param layer Input value for the calculation.
136 * @param age Input value for the calculation.
137 * @param hB Input value for the calculation.
138 * @param hT Input value for the calculation.
139 * @return Computed vec3 value.
140 */
141vec3 styleColor(vec3 cached, float layer, float age, float hB, float hT) {
142 return cached * (0.92 + 0.12 * sin(layer * 0.5 + hT * 4.0));
143
144}
145
146/**
147 * @brief Executes the fragment shader entry point.
148 */
149void main() {
150 float aspect = iResolution.x / iResolution.y;
151 vec2 uv = (tc - 0.5) * vec2(aspect, 1.0);
152
153 float bass = texture(spectrum0, 0.03).r;
154 float mid = texture(spectrum0, 0.18).r;
155 float treble = texture(spectrum0, 0.52).r;
156 float air = texture(spectrum0, 0.86).r;
157
158 float histBass = 0.0;
159 float histMid = 0.0;
160 float histTreble = 0.0;
161 float histAir = 0.0;
162 for (int i = 0; i < 8; ++i) {
163 histBass += specHist(i, 0.03);
164 histMid += specHist(i, 0.18);
165 histTreble += specHist(i, 0.52);
166 histAir += specHist(i, 0.86);
167 }
168 histBass /= 8.0; histMid /= 8.0; histTreble /= 8.0; histAir /= 8.0;
169
170 vec3 oldest = texture(history, vec3(tc, float(CACHE_HISTORY_LAYER(SIZE - 1)))).rgb;
171
172 vec3 live = texture(samp, tc + styleDrift(uv, 0.0, 0.0, bass, mid, treble, air, oldest)).rgb;
173
174 // Soften decay for larger caches so distant frames remain visible.
175 float decay = mix(0.81, 0.94, clamp(float(SIZE - 8) / 24.0, 0.0, 1.0));
176
177 vec3 accum = live;
178 float wsum = 1.0;
179 for (int i = 0; i < SIZE; ++i) {
180 float layer = float(i + 1);
181 float age = layer / float(SIZE);
182 float hB = specHist(i, 0.03);
183 float hM = specHist(i, 0.18);
184 float hT = specHist(i, 0.52);
185 float hA = specHist(i, 0.86);
186
187 vec2 drift = styleDrift(uv, layer, age, hB, hM, hT, hA, oldest);
188 vec3 cached = texture(history, vec3(tc + drift, float(CACHE_HISTORY_LAYER(i)))).rgb;
189 cached = styleColor(cached, layer, age, hB, hT);
190
191 float w = pow(decay, layer) * (1.0 + hT * 0.9 + hA * 0.3);
192 accum += cached * w;
193 wsum += w;
194 }
195 accum /= wsum;
196
197 accum *= 0.95 + amp_smooth * 0.10;
198
199
200 color = vec4(clamp(accum, 0.0, 1.0), 1.0);
201}
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
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.
#define TAU
vec2 twist(vec2 coord, float twistAmount, float time, float direction)
Evaluates twist for this shader effect.