ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
laetralus_cache.comp
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file laetralus_cache.comp
5 * @brief Vulkan compute shader: laetralus 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
21
22// Lateralus / Fibonacci Spiral Compute Shader
23// Based on the provided block-history buffer shader.
24
25layout(local_size_x = 16, local_size_y = 16) in;
26layout(set = 0, binding = 5, rgba8) writeonly uniform image2D outputImage;
27layout(set = 0, binding = 0) uniform sampler2D samp;
28// Alpha uniform used to modulate the depth of the spiral effect/color
29
30// iFrame used for animation and driving the spiral growth/rotation
31
32
33// Original utility functions
34/**
35 * @brief Evaluates clampPos for this shader effect.
36 * @param p Input value for the calculation.
37 * @param size Input value for the calculation.
38 * @return Computed ivec2 value.
39 */
40ivec2 clampPos(ivec2 p, ivec2 size) {
41 return clamp(p, ivec2(0), size - ivec2(1));
42}
43
44/**
45 * @brief Evaluates pixelUv for this shader effect.
46 * @param p Input value for the calculation.
47 * @param size Input value for the calculation.
48 * @return Computed vec2 value.
49 */
50vec2 pixelUv(ivec2 p, ivec2 size) {
51 return (vec2(clampPos(p, size)) + 0.5) / vec2(size);
52}
53
54/**
55 * @brief Evaluates sampleSource for this shader effect.
56 * @param p Input value for the calculation.
57 * @param size Input value for the calculation.
58 * @return Computed vec3 value.
59 */
60vec3 sampleSource(ivec2 p, ivec2 size) {
61 return textureLod(samp, pixelUv(p, size), 0.0).rgb;
62}
63
64// Creative modification: effectBlockSize now steps through Fibonacci numbers
65/**
66 * @brief Evaluates effectBlockSize for this shader effect.
67 * @return Computed int value.
68 */
70 int fib[10] = int[](2, 3, 5, 8, 13, 21, 34, 55, 89, 144);
71 // Use alpha to select which Fibonacci number defines the block size/frequency
72 int idx = int(clamp(alpha, 0.0, 1.0) * 9.0);
73 return fib[idx];
74}
75
76#ifndef SIZE
77#define SIZE 8
78#endif
79
80// Retaining history texture logic for the "spiral through time" feel
81#ifndef USE_HISTORY_TEXTURE_ARRAY
82#define USE_HISTORY_TEXTURE_ARRAY 1
83#endif
84
85#if USE_HISTORY_TEXTURE_ARRAY
86layout(set = 0, binding = 2) uniform sampler2DArray history;
87
88#else
89uniform sampler2D textures[SIZE];
90#endif
91
92/**
93 * @brief Evaluates sampleHistory for this shader effect.
94 * @param index Input value for the calculation.
95 * @param p Input value for the calculation.
96 * @param size Input value for the calculation.
97 * @return Computed vec3 value.
98 */
99vec3 sampleHistory(int index, ivec2 p, ivec2 size) {
100 vec2 uv = pixelUv(p, size);
101 index = clamp(index, 0, SIZE - 1);
102#if USE_HISTORY_TEXTURE_ARRAY
103 int layer = (history_head + index) % SIZE;
104 return textureLod(history, vec3(uv, float(layer)), 0.0).rgb;
105#else
106 return textureLod(textures[index], uv, 0.0).rgb;
107#endif
108}
109
110// Function to generate the Fibonacci spiral mask/pattern
111// phi (Golden Ratio) = (1 + sqrt(5)) / 2 approx 1.618
112/**
113 * @brief Evaluates getSpiral for this shader effect.
114 * @param uv Input value for the calculation.
115 * @param time Input value for the calculation.
116 * @param frequency Input value for the calculation.
117 * @return Computed float value.
118 */
119float getSpiral(vec2 uv, float time, float frequency) {
120 vec2 centeredUv = uv - 0.5;
121 float r = length(centeredUv);
122 float angle = atan(centeredUv.y, centeredUv.x);
123
124 // Fibonacci spiral equation: r = a * e^(b * theta)
125 // We use a simplified version: r = a * angle^(1/phi) or modulating angle
126 // In shaders, we map radius to expected angle for a spiral look.
127
128 // A spiral based on the Golden Angle (360 / phi^2) approx 137.5 degrees
129 // Logarithmic spiral approximation:
130 float phi = 1.61803398875;
131 float goldenAngle = 2.0 * 3.14159 / (phi * phi);
132
133 // Calculate expected angle at this radius based on the spiral properties
134 // We also use time for slow rotation and frequency (Fibonacci number) for density
135 float targetAngle = (r * frequency * 20.0) + angle - (time * 0.5);
136
137 // Modulo the targetAngle by the golden angle to create distinct arms
138 float spiralMask = mod(targetAngle, goldenAngle);
139
140 // Smoothstep to create a line/arm effect
141 float thickness = 0.05 + alpha * 0.1;
142 spiralMask = smoothstep(thickness, 0.0, abs(spiralMask - thickness * 0.5));
143
144 // Fade the spiral out at the edges and center
145 spiralMask *= smoothstep(0.5, 0.4, r) * smoothstep(0.0, 0.1, r);
146
147 return spiralMask;
148}
149
150// Main processing function retaining the structure but modifying the concept
151/**
152 * @brief Evaluates creativeSpiralHistory for this shader effect.
153 * @param p Input value for the calculation.
154 * @param size Input value for the calculation.
155 * @return Computed vec3 value.
156 */
157vec3 creativeSpiralHistory(ivec2 p, ivec2 size) {
158 vec2 uv = pixelUv(p, size);
159 float time = float(iFrame) * 0.01;
160
161 // Frequency of the spiral is determined by the Fibonacci step in alpha
162 float frequency = float(effectBlockSize());
163
164 // Original history blending logic
165 int block = effectBlockSize();
166 int blocksPerRow = (size.x + block - 1) / block;
167 int blockIndex = (p.y / block) * blocksPerRow + p.x / block;
168 int maximum = SIZE - 1;
169 int cycle = max(maximum * 2, 1);
170 int stepIndex = (iFrame + blockIndex) % cycle;
171 int textureIndex = stepIndex <= maximum ? stepIndex : cycle - stepIndex;
172
173 // Sample history as the base color
174 vec3 historyCol = sampleHistory(textureIndex, p, size);
175
176 // Creative part: Generate the spiral mask
177 float spiral = getSpiral(uv, time, frequency);
178
179 // Define Lateralus-inspired colors: Deep blues, silvers, and hints of red/orange
180 vec3 spiralColor1 = vec3(0.0, 0.2, 0.4); // Deep Blue
181 vec3 spiralColor2 = vec3(0.7, 0.7, 0.8); // Silver/Grey
182 vec3 currentSpiralColor = mix(spiralColor1, spiralColor2, sin(time + frequency * 0.1) * 0.5 + 0.5);
183
184 // Sample source image to integrate into the spiral effect (perhaps in the 'negative' space)
185 vec3 sourceCol = sampleSource(p, size);
186
187 // Mix the spiral color with the source based on the mask
188 vec3 colorEffect = mix(sourceCol, currentSpiralColor * 1.5, spiral);
189
190 // We add a subtle glow/pulse effect synced to the 'time' and spiral frequency
191 float pulse = sin(time * 2.0 + length(uv - 0.5) * frequency * 0.5) * 0.5 + 0.5;
192 colorEffect *= (1.0 + alpha * pulse);
193
194 // Finally blend the new generated effect with the historical average
195 return mix(colorEffect, historyCol, 0.5);
196}
197
198/**
199 * @brief Executes the compute shader entry point.
200 */
201void main() {
202 ivec2 p = ivec2(gl_GlobalInvocationID.xy);
203 ivec2 size = imageSize(outputImage);
204 if (any(greaterThanEqual(p, size)))
205 return;
206
207 // Use the new creative spiral history function
208 vec3 color = creativeSpiralHistory(p, size);
209
210 // Store the resulting color
211 imageStore(outputImage, p, vec4(clamp(color, 0.0, 1.0), 1.0));
212}
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 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.
vec3 sampleSource(ivec2 p, ivec2 size)
Evaluates sampleSource for this shader effect.
#define iFrame
Definition auraXi1.frag:18
#define alpha
Definition color_g.frag:17
float sampleHistory(int index, float frequency)
Evaluates sampleHistory for this shader effect.
float getSpiral(vec2 uv, float time, float frequency)
Evaluates getSpiral for this shader effect.
vec3 creativeSpiralHistory(ivec2 p, ivec2 size)
Evaluates creativeSpiralHistory for this shader effect.
#define frequency
Definition ol.frag:13