ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
ant_cache_spectrum8_fractal_xor_fold.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 iTime ext.u0.y
18#define spectrum_history_head int(ext.audio_history.x)
19#define spectrum_history_size int(ext.audio_history.y)
20
21/**
22 * @file ant_cache_spectrum8_fractal_xor_fold.frag
23 * @brief Vulkan fragment shader: ant cache spectrum8 fractal xor fold.
24 */
25// ant_cache_spectrum8_fractal_xor_fold
26// Holographic fringe x frac_shader02_dmdi6i_zoom_xor_amp fractal-fold + XOR blend
27// Audio history (spectrum0..7) + Frame cache history (samp,samp1..samp8) - EXTREME
28layout(location = 0) in vec2 tc;
29layout(location = 0) out vec4 color;
30layout(set = 0, binding = 0) uniform sampler2D samp;
31layout(set = 0, binding = 2) uniform sampler2DArray history;
32
33#ifndef SIZE
34#define SIZE 8
35#endif
36#ifndef CACHE_HISTORY_LAYER
37#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
38#endif
39layout(set = 0, binding = 3) uniform sampler1D spectrum0;
40layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
41
42
43#ifndef SPECTRUM_HISTORY_LAYER
44#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
45#endif
46
47
48
49
50
51const float TAU = 6.28318530718;
52
53/**
54 * @brief Evaluates specHist for this shader effect.
55 * @param i Input value for the calculation.
56 * @param f Input value for the calculation.
57 * @return Computed float value.
58 */
59float specHist(int i, float f) {
60 if (i == 0) return texture(spectrum0, f).r;
61 if (i == 1) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(1)))).r;
62 if (i == 2) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(2)))).r;
63 if (i == 3) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(3)))).r;
64 if (i == 4) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(4)))).r;
65 if (i == 5) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(5)))).r;
66 if (i == 6) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(6)))).r;
67 return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(7)))).r;
68}
69
70/**
71 * @brief Evaluates cacheHist for this shader effect.
72 * @param i Input value for the calculation.
73 * @param uv Input value for the calculation.
74 * @return Computed vec4 value.
75 */
76vec4 cacheHist(int i, vec2 uv) {
77 if (i == 0) return texture(samp, uv);
78 if (i == 1) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(0))));
79 if (i == 2) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(1))));
80 if (i == 3) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(2))));
81 if (i == 4) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(3))));
82 if (i == 5) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(4))));
83 if (i == 6) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(5))));
84 if (i == 7) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(6))));
85 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(7))));
86}
87
88/**
89 * @brief Evaluates palette for this shader effect.
90 * @param t Input value for the calculation.
91 * @param d Input value for the calculation.
92 * @return Computed vec3 value.
93 */
94vec3 palette(float t, vec3 d) {
95 return 0.5 + 0.5 * cos(TAU * (vec3(1.0) * t + d));
96}
97
98/**
99 * @brief Evaluates rot2 for this shader effect.
100 * @param p Input value for the calculation.
101 * @param a Input value for the calculation.
102 * @return Computed vec2 value.
103 */
104vec2 rot2(vec2 p, float a) {
105 float c = cos(a), s = sin(a);
106 return mat2(c, -s, s, c) * p;
107}
108
109/**
110 * @brief Evaluates fractalFold for this shader effect.
111 * @param p Input value for the calculation.
112 * @param zoom Input value for the calculation.
113 * @param t Input value for the calculation.
114 * @param i Input value for the calculation.
115 * @return Computed vec2 value.
116 */
117vec2 fractalFold(vec2 p, float zoom, float t, int i) {
118 for (int k = 0; k < 5; k++) {
119 p = abs(p * (zoom + 0.15 * sin(t * 0.4 + float(k) + float(i)))) - 0.5;
120 p = rot2(p, t * 0.12 + float(k) * 0.07 + float(i) * 0.2);
121 }
122 return p;
123}
124
125/**
126 * @brief Evaluates xorBlend for this shader effect.
127 * @param a Input value for the calculation.
128 * @param b Input value for the calculation.
129 * @return Computed vec3 value.
130 */
131vec3 xorBlend(vec3 a, vec3 b) {
132 ivec3 ia = ivec3(clamp(a, 0.0, 1.0) * 255.0);
133 ivec3 ib = ivec3(clamp(b, 0.0, 1.0) * 255.0);
134 ivec3 ic = ia ^ ib;
135 return vec3(ic) / 255.0;
136}
137
138/**
139 * @brief Executes the fragment shader entry point.
140 */
141void main() {
142 float aspect = iResolution.x / iResolution.y;
143 vec2 uv = (tc - 0.5) * vec2(aspect, 1.0);
144
145 vec3 acc = vec3(0.0);
146 vec3 prev = vec3(0.0);
147 for (int i = 0; i < 8; i++) {
148 float h = specHist(i, 0.05 + float(i) * 0.06);
149 float h2 = specHist(i, 0.55);
150 float bass = specHist(i, 0.04);
151
152 // Audio-driven fractal fold
153 vec2 p = uv;
154 float zoom = 1.4 + 0.5 * sin(iTime * 0.42 + float(i) + h * 3.0);
155 p = fractalFold(p, zoom, iTime + bass * 4.0, i);
156 vec2 suv = p / vec2(aspect, 1.0) + 0.5;
157 suv = fract(suv);
158
159 // Holographic fringe
160 float ang = float(i) * 0.4 + h2 * 3.0;
161 vec2 dir = vec2(cos(ang), sin(ang));
162 float fringe = sin(dot(uv, dir) * (40.0 + h * 80.0) + iTime * (1.0 + h * 4.0));
163 fringe = pow(fringe * 0.5 + 0.5, 4.0);
164 suv += dir * fringe * 0.04 * (1.0 + h);
165 suv = fract(suv);
166
167 vec3 c;
168 c.r = cacheHist(i, suv + vec2(h * 0.06, 0.0)).r;
169 c.g = cacheHist(i, suv).g;
170 c.b = cacheHist(i, suv - vec2(h * 0.06, 0.0)).b;
171
172 vec3 tint = palette(float(i) * 0.13 + h * 4.0, vec3(0.0, 0.33, 0.66));
173 vec3 layer = (c + tint * fringe * 0.6) * (1.0 + h * 5.0);
174
175 // XOR blend with previous slot every other step
176 if ((i & 1) == 1) {
177 layer = mix(layer, xorBlend(layer, prev), 0.45 + bass * 0.5);
178 }
179 prev = layer;
180 acc += layer * pow(0.83, float(i));
181 }
182 acc /= 3.0;
183 acc *= 1.3 + amp_peak * 1.3;
184 color = vec4(clamp(acc, 0.0, 1.0), 1.0);
185}
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 CACHE_HISTORY_LAYER(index)
vec3 palette(float phase)
Evaluates palette for this shader effect.
#define SPECTRUM_HISTORY_LAYER(index)
#define amp_peak
vec2 h2(vec2 p)
Evaluates h2 for this shader effect.
Definition air-bowl.frag:45
float specHist(int i, float f)
Evaluates specHist for this shader effect.
vec4 cacheHist(int i, vec2 uv)
Evaluates cacheHist for this shader effect.
vec2 rot2(vec2 p, float a)
Evaluates rot2 for this shader effect.
vec3 xorBlend(vec3 a, vec3 b)
Evaluates xorBlend for this shader effect.
vec2 fractalFold(vec2 p, float zoom, float t, int i)
Evaluates fractalFold for this shader effect.
float h(vec2 p)
Evaluates h for this shader effect.
#define TAU