ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
rainbow-trail-cache-aurora.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file rainbow-trail-cache-aurora.frag
5 * @brief Vulkan fragment shader: rainbow-trail-cache-aurora.
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_high ext.audio_bands.z
18#define amp_low ext.audio_bands.x
19#define amp_mid ext.audio_bands.y
20#define amp_peak ext.u2.w
21#define amp_smooth ext.u3.w
22#define history_head int(ext.u3.x)
23#define iMouse ext.mouse
24#define iResolution ext.u0.zw
25#define time_f ext.u2.y
26
27// rainbow_trail_aurora
28// Sheared history waves stretch the RGB strobe into an aurora curtain.
29#define TRAIL_MODE 9
30layout(location = 0) in vec2 tc;
31layout(location = 0) out vec4 color;
32layout(set = 0, binding = 0) uniform sampler2D samp;
33layout(set = 0, binding = 2) uniform sampler2DArray history;
34
35#ifndef SIZE
36#define SIZE 8
37#endif
38#ifndef CACHE_HISTORY_LAYER
39#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
40#endif
41layout(set = 0, binding = 3) uniform sampler1D spectrum0;
42
43
44
45
46
47
48
49
50
51const float TAU = 6.28318530718;
52const int MODE = TRAIL_MODE;
53
54/**
55 * @brief Evaluates rotate2D for this shader effect.
56 * @param angle Input value for the calculation.
57 * @return Computed mat2 value.
58 */
59mat2 rotate2D(float angle) {
60 float c = cos(angle);
61 float s = sin(angle);
62 return mat2(c, -s, s, c);
63}
64
65/**
66 * @brief Evaluates mirrorUV for this shader effect.
67 * @param uv Input value for the calculation.
68 * @return Computed vec2 value.
69 */
70vec2 mirrorUV(vec2 uv) {
71 return 1.0 - abs(mod(uv, 2.0) - 1.0);
72}
73
74/**
75 * @brief Evaluates seamlessUV for this shader effect.
76 * @param uv Input value for the calculation.
77 * @return Computed vec2 value.
78 */
79vec2 seamlessUV(vec2 uv) {
80 vec2 mirrored = mirrorUV(uv);
81 vec2 cosineFold = 0.5 - 0.5 * cos(3.14159265359 * uv);
82 vec2 edgeDistance = min(mirrored, 1.0 - mirrored);
83 vec2 feather = 1.0 - smoothstep(vec2(0.015), vec2(0.08), edgeDistance);
84 return mix(mirrored, cosineFold, feather);
85}
86
87/**
88 * @brief Evaluates kaleido for this shader effect.
89 * @param p Input value for the calculation.
90 * @param sides Input value for the calculation.
91 * @return Computed vec2 value.
92 */
93vec2 kaleido(vec2 p, float sides) {
94 float radius = length(p);
95 float sector = TAU / sides;
96 float angle = abs(mod(atan(p.y, p.x) + sector * 0.5, sector) - sector * 0.5);
97 return vec2(cos(angle), sin(angle)) * radius;
98}
99
100/**
101 * @brief Evaluates rainbow for this shader effect.
102 * @param x Input value for the calculation.
103 * @return Computed vec3 value.
104 */
105vec3 rainbow(float x) {
106 float offset = float(MODE) * 0.087;
107 return 0.52 + 0.48 * cos(TAU * (x + offset + vec3(0.0, 0.333, 0.667)));
108}
109
110/**
111 * @brief Evaluates hueRotate for this shader effect.
112 * @param c Input value for the calculation.
113 * @param angle Input value for the calculation.
114 * @return Computed vec3 value.
115 */
116vec3 hueRotate(vec3 c, float angle) {
117 const mat3 toYIQ = mat3(0.299, 0.587, 0.114, 0.596, -0.274, -0.322, 0.211, -0.523, 0.312);
118 const mat3 toRGB = mat3(1.0, 0.956, 0.621, 1.0, -0.272, -0.647, 1.0, -1.106, 1.703);
119 vec3 yiq = toYIQ * c;
120 float hue = atan(yiq.z, yiq.y) + angle;
121 float chroma = length(yiq.yz);
122 return clamp(toRGB * vec3(yiq.x, chroma * cos(hue), chroma * sin(hue)), 0.0, 1.0);
123}
124
125/**
126 * @brief Evaluates sampleCache for this shader effect.
127 * @param index Input value for the calculation.
128 * @param uv Input value for the calculation.
129 * @return Computed vec4 value.
130 */
131vec4 sampleCache(int index, vec2 uv) {
132 uv = seamlessUV(uv);
133 if (index == 0)
134 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(0))));
135 if (index == 1)
136 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(1))));
137 if (index == 2)
138 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(2))));
139 if (index == 3)
140 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(3))));
141 if (index == 4)
142 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(4))));
143 if (index == 5)
144 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(5))));
145 if (index == 6)
146 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(6))));
147 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(7))));
148}
149
150/**
151 * @brief Evaluates trailUV for this shader effect.
152 * @param uv Input value for the calculation.
153 * @param age Input value for the calculation.
154 * @param bass Input value for the calculation.
155 * @param mid Input value for the calculation.
156 * @param treble Input value for the calculation.
157 * @return Computed vec2 value.
158 */
159vec2 trailUV(vec2 uv, float age, float bass, float mid, float treble) {
160 vec2 center = iMouse.z > 0.0 ? iMouse.xy / max(iResolution, vec2(1.0)) : vec2(0.5);
161 vec2 p = uv - center;
162 float strength = 0.006 + amp_smooth * 0.018;
163
164 if (MODE == 0) {
165 p += vec2(age * strength * (1.0 + bass), -age * strength * 0.35);
166 } else if (MODE == 1) {
167 p = rotate2D(age * (0.035 + treble * 0.12)) * p;
168 p *= pow(max(0.985 - bass * 0.045, 0.5), age);
169 } else if (MODE == 2) {
170 p.x += sin(p.y * 15.0 - time_f * 2.0 + age) * strength * age;
171 p.y += cos(p.x * 11.0 + time_f * 1.4 - age) * strength * 0.6 * age;
172 } else if (MODE == 3) {
173 p = kaleido(rotate2D(age * 0.025) * p, 6.0 + floor(treble * 5.0));
174 p *= 1.0 - age * 0.012;
175 } else if (MODE == 4) {
176 p *= pow(max(0.955 - bass * 0.07, 0.35), age);
177 p = rotate2D(sin(time_f * 0.4) * 0.018 * age) * p;
178 } else if (MODE == 5) {
179 vec2 direction = normalize(vec2(cos(time_f * 0.35), sin(time_f * 0.27)));
180 p -= direction * age * strength * (1.5 + bass * 2.0);
181 p += vec2(-direction.y, direction.x) * sin(age + time_f) * strength;
182 } else if (MODE == 6) {
183 float cells = 10.0 + floor(treble * 12.0);
184 vec2 cell = floor((uv + age * 0.003) * cells) / cells;
185 vec2 local = uv - cell;
186 p = cell - center + rotate2D(age * 0.07) * local;
187 } else if (MODE == 7) {
188 float plasma = sin(p.x * 18.0 + time_f + age) * cos(p.y * 16.0 - time_f * 1.3);
189 p += vec2(plasma, -plasma) * strength * age * (1.0 + mid);
190 } else if (MODE == 8) {
191 float radius = length(p) + 0.001;
192 p = rotate2D(log(radius + 0.08) * 0.06 * age + treble * 0.08 * age) * p;
193 p *= pow(max(0.965 - bass * 0.06, 0.4), age);
194 } else {
195 p.x += sin(p.y * 9.0 + time_f * 0.8) * strength * age;
196 p.y *= 1.0 + age * (0.008 + mid * 0.02);
197 p = rotate2D(sin(p.x * 7.0 - time_f) * 0.018 * age) * p;
198 }
199
200 return p + center;
201}
202
203/**
204 * @brief Evaluates rgbStrobeCore for this shader effect.
205 * @param bass Input value for the calculation.
206 * @param mid Input value for the calculation.
207 * @param treble Input value for the calculation.
208 * @param[out] ageDifference Output value produced by the calculation.
209 * @return Computed vec3 value.
210 */
211vec3 rgbStrobeCore(float bass, float mid, float treble, out vec3 ageDifference) {
212 // MatrixCollection frames[1], frames[4], frames[7] map to samp2, samp5, samp8.
213 vec2 uv1 = trailUV(tc, 2.0, bass, mid, treble);
214 vec2 uv4 = trailUV(tc, 5.0, bass, mid, treble);
215 vec2 uv7 = trailUV(tc, 8.0, bass, mid, treble);
216 vec3 frame1 = sampleCache(1, uv1).rgb;
217 vec3 frame4 = sampleCache(4, uv4).rgb;
218 vec3 frame7 = sampleCache(7, uv7).rgb;
219
220 float strobeRate = 7.0 + float(MODE % 4) * 1.75 + amp_peak * 5.0;
221 bool strobe = mod(floor(time_f * strobeRate), 2.0) > 0.5;
222
223 // Same temporal channel permutation as the OpenCV loop.
224 vec3 forwardRoute = vec3(frame1.r, frame4.g, frame7.b);
225 vec3 reverseRoute = vec3(frame7.r, frame4.g, frame1.b);
226 ageDifference = abs(frame1 - frame7);
227 return strobe ? forwardRoute : reverseRoute;
228}
229
230/**
231 * @brief Executes the fragment shader entry point.
232 */
233void main() {
234 float bass = texture(spectrum0, 0.03).r;
235 float mid = texture(spectrum0, 0.22).r;
236 float treble = texture(spectrum0, 0.58).r;
237 float air = texture(spectrum0, 0.80).r;
238
239 vec3 ageDifference;
240 vec3 routed = rgbStrobeCore(bass, mid, treble, ageDifference);
241 vec3 live = texture(samp, seamlessUV(tc)).rgb;
242
243 // Use all eight cache layers as faint rainbow persistence behind the exact 1/4/7 routing.
244 vec3 persistence = vec3(0.0);
245 float persistenceWeight = 0.0;
246 for (int i = 0; i < 8; ++i) {
247 float age = float(i + 1);
248 float weight = pow(0.69 + float(MODE % 3) * 0.025, age);
249 vec3 echo = sampleCache(i, trailUV(tc, age, bass, mid, treble)).rgb;
250 persistence += echo * rainbow(age * 0.075 + time_f * 0.04) * weight;
251 persistenceWeight += weight;
252 }
253 persistence /= max(persistenceWeight, 0.001);
254
255 float motion = dot(ageDifference, vec3(0.333));
256 vec3 result = mix(live, routed, 0.68 + motion * 0.25);
257 result = mix(result, persistence * 1.45, 0.24 + amp_smooth * 0.2);
258
259 float huePhase = time_f * (0.22 + treble * 0.2) + motion * 2.0 + float(MODE) * 0.17;
260 result = hueRotate(result, huePhase);
261 result += rainbow(huePhase * 0.16 + length(tc - 0.5)) * motion * (0.45 + air * 1.8);
262
263 // AddInvert equivalent: alternating complement, with peak inversion layered on top.
264 float invertClock = mod(floor(time_f * (3.5 + float(MODE % 5))), 2.0);
265 float invertMix = mix(0.12, 0.82, invertClock);
266 result = mix(result, vec3(1.0) - result, invertMix);
267 result = mix(result, vec3(1.0) - result, smoothstep(0.88, 1.0, amp_peak));
268 result = (result - 0.5) * (1.32 + amp_smooth * 0.28) + 0.5;
269
270 color = vec4(clamp(result, 0.0, 1.0), 1.0);
271}
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 amp_smooth
#define CACHE_HISTORY_LAYER(index)
#define amp_peak
vec3 toRGB(uvec3 color)
Evaluates toRGB for this shader effect.
vec3 hueRotate(vec3 color, float angle)
Evaluates hueRotate for this shader effect.
vec3 rainbow(float t)
Evaluates rainbow for this shader effect.
vec2 mirrorUV(vec2 uv)
Evaluates mirrorUV for this shader effect.
vec2 kaleido(vec2 p, float seg)
Evaluates kaleido for this shader effect.
vec3 hue(float t)
Evaluates hue for this shader effect.
Definition auraXi1.frag:65
shared uint cells[10][10]
mat2 rotate2D(float a)
Evaluates rotate2D for this shader effect.
vec4 sampleCache(int index, vec2 uv)
Evaluates sampleCache for this shader effect.
vec2 cell(vec2 p)
Evaluates cell for this shader effect.
#define TAU
vec3 plasma(float t)
Evaluates plasma for this shader effect.
#define strength
Definition ol.frag:16
vec2 seamlessUV(vec2 uv)
Evaluates seamlessUV for this shader effect.
vec3 rgbStrobeCore(float bass, float mid, float treble, out vec3 ageDifference)
Evaluates rgbStrobeCore for this shader effect.
vec2 trailUV(vec2 uv, float age, float bass, float mid, float treble)
Evaluates trailUV for this shader effect.