ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
lateralus_energy_cache.comp
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file lateralus_energy_cache.comp
5 * @brief Vulkan compute shader: lateralus energy cache.
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 alpha ext.u0.x
18#define history_head int(ext.u3.x)
19#define iFrame int(ext.u2.x)
20#define iMouse ext.mouse
21#define time_f ext.u2.y
22
23
24layout(local_size_x = 16, local_size_y = 16) in;
25layout(set = 0, binding = 5, rgba8) writeonly uniform image2D outputImage;
26layout(set = 0, binding = 0) uniform sampler2D samp;
27#ifndef SIZE
28#define SIZE 8
29#endif
30
31#ifndef USE_HISTORY_TEXTURE_ARRAY
32#define USE_HISTORY_TEXTURE_ARRAY 1
33#endif
34
35#if USE_HISTORY_TEXTURE_ARRAY
36layout(set = 0, binding = 2) uniform sampler2DArray history;
37
38#else
39uniform sampler2D textures[SIZE];
40#endif
41
42
43
44
45
46const float TAU = 6.28318530718;
47const float PHI = 1.61803398875;
48
49
50/**
51 * @brief Evaluates clampPos for this shader effect.
52 * @param p Input value for the calculation.
53 * @param size Input value for the calculation.
54 * @return Computed ivec2 value.
55 */
56ivec2 clampPos(ivec2 p, ivec2 size) {
57 return clamp(p, ivec2(0), size - ivec2(1));
58}
59
60/**
61 * @brief Evaluates pixelUv for this shader effect.
62 * @param p Input value for the calculation.
63 * @param size Input value for the calculation.
64 * @return Computed vec2 value.
65 */
66vec2 pixelUv(ivec2 p, ivec2 size) {
67 return (vec2(clampPos(p, size)) + 0.5) / vec2(size);
68}
69
70
71/**
72 * @brief Evaluates effectBlockSize for this shader effect.
73 * @return Computed int value.
74 */
76 int fib[10] = int[](2, 3, 5, 8, 13, 21, 34, 55, 89, 144);
77 int idx = int(clamp(alpha, 0.0, 1.0) * 9.0);
78 return fib[idx];
79}
80
81
82/**
83 * @brief Evaluates acidPalette for this shader effect.
84 * @param t Input value for the calculation.
85 * @param hueOffset Input value for the calculation.
86 * @return Computed vec3 value.
87 */
88vec3 acidPalette(float t, float hueOffset) {
89 vec3 a = vec3(0.5, 0.5, 0.5);
90 vec3 b = vec3(0.5, 0.5, 0.5);
91 vec3 c = vec3(1.0, 1.0, 0.5);
92 vec3 d = vec3(0.3, 0.2, 0.2) + vec3(hueOffset, hueOffset * 1.2, hueOffset * 0.8);
93 return a + b * cos(TAU * (c * t + d));
94}
95
96
97/**
98 * @brief Evaluates fetchHistory for this shader effect.
99 * @param index Input value for the calculation.
100 * @param uv Input value for the calculation.
101 * @return Computed vec3 value.
102 */
103vec3 fetchHistory(int index, vec2 uv) {
104 index = clamp(index, 0, SIZE - 1);
105 vec2 clampedUv = clamp(uv, 0.0, 1.0);
106#if USE_HISTORY_TEXTURE_ARRAY
107 int layer = (history_head + index) % SIZE;
108 return textureLod(history, vec3(clampedUv, float(layer)), 0.0).rgb;
109#else
110 return textureLod(textures[index], clampedUv, 0.0).rgb;
111#endif
112}
113
114
115/**
116 * @brief Evaluates getGoldenSpiral for this shader effect.
117 * @param uv Input value for the calculation.
118 * @param center Input value for the calculation.
119 * @param time Input value for the calculation.
120 * @param freq Input value for the calculation.
121 * @return Computed float value.
122 */
123float getGoldenSpiral(vec2 uv, vec2 center, float time, float freq) {
124 vec2 p = uv - center;
125 float r = length(p);
126 float angle = atan(p.y, p.x);
127 float goldenAngle = TAU / (PHI * PHI);
128 float targetAngle = (r * freq * 18.0) + angle - (time * 0.618);
129 float spiralMask = mod(targetAngle, goldenAngle);
130
131 float thickness = 0.04 + alpha * 0.12;
132 spiralMask = smoothstep(thickness, 0.0, abs(spiralMask - thickness * 0.5));
133 spiralMask *= smoothstep(0.7, 0.3, r) * smoothstep(0.0, 0.08, r);
134 return spiralMask;
135}
136
137/**
138 * @brief Executes the compute shader entry point.
139 */
140void main() {
141 ivec2 p = ivec2(gl_GlobalInvocationID.xy);
142 ivec2 size = imageSize(outputImage);
143 if (any(greaterThanEqual(p, size)))
144 return;
145
146 vec2 uv = pixelUv(p, size);
147 float aspect = float(size.x) / float(size.y);
148 vec2 aspectUv = (uv - 0.5) * vec2(aspect, 1.0);
149
150 float t = (time_f > 0.0) ? time_f : float(iFrame) * 0.015;
151
152 int block = effectBlockSize();
153 int blocksPerRow = (size.x + block - 1) / block;
154 int blockIndex = (p.y / block) * blocksPerRow + (p.x / block);
155 int maximum = SIZE - 1;
156 int cycle = max(maximum * 2, 1);
157 int stepIndex = (iFrame + blockIndex) % cycle;
158 int primaryHistoryIndex = stepIndex <= maximum ? stepIndex : cycle - stepIndex;
159 vec2 mouseUV = iMouse.xy / vec2(size);
160 float globalHue = 0.0;
161 if (iMouse.w > 0.0) {
162 globalHue = (mouseUV.x - 0.5) * 3.0;
163 }
164 vec2 effectOrigin = vec2(0.0);
165 if (iMouse.z > 0.0) {
166 effectOrigin = (mouseUV - 0.5) * vec2(aspect, 1.0);
167 }
168 vec2 src1 = effectOrigin + vec2(sin(t * 0.35) * 0.25, cos(t * 0.45) * 0.18);
169 vec2 src2 = effectOrigin + vec2(-sin(t * 0.55) * 0.18, sin(t * 0.35) * 0.22);
170 vec2 src3 = effectOrigin + vec2(cos(t * 0.25) * 0.12, -cos(t * 0.65) * 0.12);
171
172 float r1 = length(aspectUv - src1);
173 float r2 = length(aspectUv - src2);
174 float r3 = length(aspectUv - src3);
175
176 float freqMod = float(block);
177 float wave1 = sin(r1 * (16.0 + freqMod * 0.5) - t * 4.0);
178 float wave2 = sin(r2 * (20.0 + freqMod * 0.3) - t * 3.2);
179 float wave3 = sin(r3 * (24.0 + freqMod * 0.4) - t * 5.1);
180 float waveCombined = (wave1 + wave2 + wave3) / 3.0;
181
182 vec2 distort = vec2(
183 waveCombined * 0.04 * (1.0 + alpha),
184 (wave1 - wave2) * 0.03 * (1.0 + alpha)
185 );
186 vec2 sampUv = uv + distort;
187
188 float chroma = abs(waveCombined) * 0.05 + (alpha * 0.02);
189 vec3 liveColor;
190 liveColor.r = textureLod(samp, clamp(sampUv + vec2(chroma, 0.0), 0.0, 1.0), 0.0).r;
191 liveColor.g = textureLod(samp, clamp(sampUv, 0.0, 1.0), 0.0).g;
192 liveColor.b = textureLod(samp, clamp(sampUv - vec2(chroma, 0.0), 0.0, 1.0), 0.0).b;
193
194 float interferenceVal = waveCombined * 0.5 + 0.5;
195 liveColor *= acidPalette(interferenceVal + t * 0.1, globalHue) * 1.4;
196
197
198 float spiralMask = getGoldenSpiral(uv, vec2(0.5) + (effectOrigin / vec2(aspect, 1.0)), t, float(block));
199 vec3 spiralColor = acidPalette(r1 * 0.8 - t * 0.4, globalHue + 0.3);
200 liveColor = mix(liveColor, spiralColor * 1.6, spiralMask * 0.85);
201
202
203 vec3 accum = liveColor;
204 float accWeight = 1.0;
205 vec2 feedbackCenter = (iMouse.z > 0.0) ? mouseUV : (vec2(0.5) + distort * 1.5);
206
207 for (int i = 0; i < 8; i++) {
208 float gen = float(i + 1);
209 int layerIndex = (primaryHistoryIndex + i) % SIZE;
210
211 float zoomFactor = max(0.96 - (alpha * 0.05) + (0.015 * sin(t * 0.5)), 0.02);
212 float rotFactor = (0.025 * sin(t * 0.3)) + (alpha * 0.01);
213
214 float currentZoom = pow(zoomFactor, gen);
215 float currentRot = rotFactor * gen;
216 float c = cos(currentRot);
217 float s = sin(currentRot);
218
219 vec2 centered = uv - feedbackCenter;
220 centered *= currentZoom;
221 centered = vec2(centered.x * c - centered.y * s, centered.x * s + centered.y * c);
222 vec2 fbUv = centered + feedbackCenter;
223
224 vec3 cached = fetchHistory(layerIndex, fbUv);
225
226 float shift = gen * 0.04;
227 cached.r *= 1.0 + shift;
228 cached.g *= 1.0 - shift * 0.5;
229 cached.b *= 1.0 + shift * 0.8;
230
231 float weight = pow(0.80, gen);
232 accum += cached * weight;
233 accWeight += weight;
234 }
235
236 accum /= accWeight;
237 accum = (accum - 0.5) * (1.2 + alpha * 0.3) + 0.5;
238 accum = clamp(accum, 0.0, 1.0);
239
240 imageStore(outputImage, p, vec4(accum, 1.0));
241}
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 time_f
Definition 3high.frag:19
#define history_head
#define SIZE
ivec2 clampPos(ivec2 p, ivec2 size)
Evaluates clampPos for this shader effect.
int effectBlockSize()
Evaluates effectBlockSize for this shader effect.
vec2 pixelUv(ivec2 p, ivec2 size)
Evaluates pixelUv for this shader effect.
#define iFrame
Definition auraXi1.frag:18
#define alpha
Definition color_g.frag:17
#define TAU
const float PHI
float getGoldenSpiral(vec2 uv, vec2 center, float time, float freq)
Evaluates getGoldenSpiral for this shader effect.
vec3 fetchHistory(int index, vec2 uv)
Evaluates fetchHistory for this shader effect.
vec3 acidPalette(float t, float hueOffset)
Evaluates acidPalette for this shader effect.