ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
DigitalLightStorm.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file DigitalLightStorm.frag
5 * @brief Vulkan fragment shader: DigitalLightStorm.
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 ext.u1.y
18#define iMouse ext.mouse
19#define iResolution ext.u0.zw
20#define time_f ext.u2.y
21#define uamp ext.u1.y
22
23layout(location = 0) out vec4 color;
24layout(location = 0) in vec2 tc;
25
26// STRICT UNIFORM LIST
27layout(set = 0, binding = 0) uniform sampler2D samp;
28
29
30
31
32
33float seed = 1.0;
34
35const float PI = 3.1415926535897932384626433832795;
36
37// --- UTILS: XOR BLENDING ---
38/**
39 * @brief Evaluates xor RGB for this shader effect.
40 * @param icolor Input value for the calculation.
41 * @param source Input value for the calculation.
42 * @return Computed vec4 value.
43 */
44vec4 xor_RGB(vec4 icolor, vec4 source){
45 ivec3 int_color;
46 ivec4 isource = ivec4(source * 255.0);
47 for(int i=0;i<3;++i){
48 int_color[i] = int(255.0*icolor[i]);
49 int_color[i] = int_color[i] ^ isource[i];
50 if(int_color[i]>255) int_color[i] = int_color[i] % 255;
51 icolor[i] = float(int_color[i]) / 255.0;
52 }
53 icolor.a = 1.0;
54 return icolor;
55}
56
57// --- UTILS: MATH & GEOMETRY ---
58/**
59 * @brief Evaluates pingPong for this shader effect.
60 * @param x Input value for the calculation.
61 * @param length Input value for the calculation.
62 * @return Computed float value.
63 */
64float pingPong(float x, float length) {
65 float m = mod(x, length * 2.0);
66 return m <= length ? m : length * 2.0 - m;
67}
68
69/**
70 * @brief Evaluates rotateUV for this shader effect.
71 * @param uv Input value for the calculation.
72 * @param angle Input value for the calculation.
73 * @param c Input value for the calculation.
74 * @param aspect Input value for the calculation.
75 * @return Computed vec2 value.
76 */
77vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect) {
78 float s = sin(angle), cc = cos(angle);
79 vec2 p = uv - c;
80 p.x *= aspect;
81 p = mat2(cc, -s, s, cc) * p;
82 p.x /= aspect;
83 return p + c;
84}
85
86/**
87 * @brief Evaluates reflectUV for this shader effect.
88 * @param uv Input value for the calculation.
89 * @param segments Input value for the calculation.
90 * @param c Input value for the calculation.
91 * @param aspect Input value for the calculation.
92 * @return Computed vec2 value.
93 */
94vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect) {
95 vec2 p = uv - c;
96 p.x *= aspect;
97 float ang = atan(p.y, p.x);
98 float rad = length(p);
99 float stepA = 6.28318530718 / segments;
100 ang = mod(ang, stepA);
101 ang = abs(ang - stepA * 0.5);
102 vec2 r = vec2(cos(ang), sin(ang)) * rad;
103 r.x /= aspect;
104 return r + c;
105}
106
107// Combined electrical fold with audio-reactive zoom
108/**
109 * @brief Evaluates electricalFold for this shader effect.
110 * @param uv Input value for the calculation.
111 * @param zoom Input value for the calculation.
112 * @param t Input value for the calculation.
113 * @param c Input value for the calculation.
114 * @param aspect Input value for the calculation.
115 * @return Computed vec2 value.
116 */
117vec2 electricalFold(vec2 uv, float zoom, float t, vec2 c, float aspect) {
118 vec2 p = uv;
119 // 4 iterations to keep it sharp and efficient
120 for (int i = 0; i < 4; i++) {
121 // Use seed to vary the fractal folding structure slightly
122 float iSeed = seed * 0.1 * float(i);
123 p = abs((p - c) * (zoom + 0.1 * sin(t * 1.5 + float(i) + iSeed))) - 0.5 + c;
124 p = rotateUV(p, t * 0.2 + float(i) * 0.1, c, aspect);
125 }
126 return p;
127}
128
129// --- UTILS: COLOR ---
130/**
131 * @brief Evaluates neonPalette for this shader effect.
132 * @param t Input value for the calculation.
133 * @return Computed vec3 value.
134 */
135vec3 neonPalette(float t) {
136 vec3 pink = vec3(1.0, 0.15, 0.75);
137 vec3 electric = vec3(0.10, 0.90, 1.0); // Cyan
138 vec3 purple = vec3(0.60, 0.10, 1.0);
139
140 float ph = fract(t * 0.4);
141 vec3 k1 = mix(pink, electric, smoothstep(0.00, 0.33, ph));
142 vec3 k2 = mix(electric, purple, smoothstep(0.33, 0.66, ph));
143 vec3 k3 = mix(purple, pink, smoothstep(0.66, 1.00, ph));
144
145 return normalize(k1 + k2 + k3) * 1.3;
146}
147
148/**
149 * @brief Evaluates limitHighlights for this shader effect.
150 * @param c Input value for the calculation.
151 * @return Computed vec3 value.
152 */
153vec3 limitHighlights(vec3 c){
154 float m = max(c.r, max(c.g, c.b));
155 if(m > 0.9) c *= 0.9 / m;
156 return c;
157}
158
159/**
160 * @brief Executes the fragment shader entry point.
161 */
162void main(void) {
163 seed = pingPong(time_f * PI, 15.0);
164 // --- STEP 1: SETUP ---
165 float a = clamp(amp, 0.0, 1.0);
166 float ua = clamp(uamp, 0.0, 1.0);
167
168 // Create an aggregate intensity value
169 float intensity = clamp(amp * 0.6 + uamp * 1.2, 0.0, 3.0);
170 float tFast = time_f + intensity;
171
172 float aspect = iResolution.x / iResolution.y;
173 vec2 m = (iMouse.z > 0.5) ? (iMouse.xy / iResolution) : vec2(0.5);
174
175 // --- STEP 2: RGB CHANNEL SPLIT (Glitch) ---
176 // Uses amp/uamp to shake the background planes
177 vec2 uv = tc;
178 float distAmt = 0.02 * intensity;
179
180 // Offset sin waves by seed so the shake pattern isn't identical every time
181 float rR = sin(uv.y * 10.0 + time_f * 5.0 + seed) * distAmt;
182 float rG = sin(uv.x * 12.0 + time_f * 4.0 + seed * 1.3) * distAmt;
183 float rB = sin(uv.y * 8.0 + time_f * 6.0 + seed * 0.7) * distAmt;
184
185 vec2 tcR = uv + vec2(rR, 0.0);
186 vec2 tcG = uv + vec2(0.0, rG);
187 vec2 tcB = uv + vec2(rB, rB * 0.5);
188
189 vec4 texR = texture(samp, tcR);
190 vec4 texG = texture(samp, tcG);
191 vec4 texB = texture(samp, tcB);
192
193 vec4 baseTex = vec4(texR.r, texG.g, texB.b, 1.0);
194
195 // --- STEP 3: KALEIDOSCOPIC LIGHTNING ---
196 vec2 kUV = tc;
197
198 // Number of mirror segments increases with loud audio
199 float segs = 4.0 + floor(intensity * 2.0) * 2.0;
200 kUV = reflectUV(kUV, segs, m, aspect);
201
202 // Zoom pulses with the bass
203 float zoom = 1.1 + 0.3 * sin(time_f) + 0.4 * intensity;
204
205 // Generate Lightning Geometry
206 vec2 electricUV = electricalFold(kUV, zoom, tFast * 0.3, m, aspect);
207
208 // Calculate distance field for the bolt
209 float dist = length(electricUV - m);
210 float bolt = 0.015 / (dist + 0.001);
211 bolt = pow(bolt, 1.2);
212
213 // Pulse the lightning using pingPong
214 float pulse = pingPong(tFast * 4.0, 1.0);
215 bolt *= (0.5 + 0.5 * pulse);
216 bolt *= (0.8 + 0.5 * intensity);
217
218 // --- STEP 4: COLOR & BLENDING ---
219 vec3 boltColor = neonPalette(time_f + dist * 2.0);
220
221 // XOR Interference: Masked to the bolt area
222 vec4 interference = vec4(boltColor, 1.0) * bolt;
223 vec4 xorLayer = xor_RGB(baseTex, interference * 2.5);
224
225 // Mix strategy
226 vec3 finalCol = baseTex.rgb;
227
228 // Mix in the glitch where lightning is strong
229 finalCol = mix(finalCol, xorLayer.rgb, clamp(bolt * 0.6, 0.0, 0.8));
230
231 // Add bloom
232 finalCol += boltColor * bolt * 0.8;
233
234 // Global flash on high intensity beats
235 if (uamp > 0.8) {
236 finalCol += vec3(0.1, 0.1, 0.2) * uamp;
237 }
238
239 // --- STEP 5: FINAL OUTPUT ---
240 finalCol = limitHighlights(finalCol);
241
242 color = vec4(finalCol, 1.0);
243}
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
vec2 electricalFold(vec2 uv, float zoom, float t, vec2 c, float aspect)
Evaluates electricalFold for this shader effect.
vec3 limitHighlights(vec3 c)
Evaluates limitHighlights for this shader effect.
#define uamp
Definition abc.frag:21
#define amp
Definition abc.frag:17
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
#define seed
Definition air-bowl.frag:20
vec4 xor_RGB(vec4 a, vec4 b)
Evaluates xor RGB for this shader effect.
vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect)
Evaluates rotateUV for this shader effect.
Definition aura2.frag:59
vec3 neonPalette(float t)
Evaluates neonPalette for this shader effect.
Definition aura2.frag:112
vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect)
Evaluates reflectUV for this shader effect.
Definition aura2.frag:76
#define PI
vec3 interference(float phase, float thickness)
Evaluates interference for this shader effect.