ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
fractal_diamond_rainbow_overflow.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file fractal_diamond_rainbow_overflow.frag
5 * @brief Vulkan fragment shader: fractal diamond rainbow overflow.
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_rms ext.u3.z
22#define amp_smooth ext.u3.w
23#define iMouse ext.mouse
24#define iResolution ext.u0.zw
25#define iamp ext.u1.z
26#define time_f ext.u2.y
27
28layout(location = 0) out vec4 color;
29layout(location = 0) in vec2 tc;
30layout(set = 0, binding = 0) uniform sampler2D samp;
31
32
33
34
35
36
37
38
39
40
41
42const float PI = 3.1415926535897932384626433832795;
43
44// --- Helper Functions ---
45
46/**
47 * @brief Evaluates rainbow for this shader effect.
48 * @param t Input value for the calculation.
49 * @return Computed vec3 value.
50 */
51vec3 rainbow(float t) {
52 t = fract(t);
53 float r = abs(t * 6.0 - 3.0) - 1.0;
54 float g = 2.0 - abs(t * 6.0 - 2.0);
55 float b = 2.0 - abs(t * 6.0 - 4.0);
56 return clamp(vec3(r, g, b), 0.0, 1.0);
57}
58
59/**
60 * @brief Evaluates rotateUV for this shader effect.
61 * @param uv Input value for the calculation.
62 * @param angle Input value for the calculation.
63 * @param c Input value for the calculation.
64 * @param aspect Input value for the calculation.
65 * @return Computed vec2 value.
66 */
67vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect) {
68 float s = sin(angle), cc = cos(angle);
69 vec2 p = uv - c;
70 p.x *= aspect;
71 p = mat2(cc, -s, s, cc) * p;
72 p.x /= aspect;
73 return p + c;
74}
75
76/**
77 * @brief Evaluates reflectUV for this shader effect.
78 * @param uv Input value for the calculation.
79 * @param segments Input value for the calculation.
80 * @param c Input value for the calculation.
81 * @param aspect Input value for the calculation.
82 * @return Computed vec2 value.
83 */
84vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect) {
85 vec2 p = uv - c;
86 p.x *= aspect;
87 float ang = atan(p.y, p.x);
88 float rad = length(p);
89 float stepA = 6.28318530718 / segments;
90 ang = mod(ang, stepA);
91 ang = abs(ang - stepA * 0.5);
92 vec2 r = vec2(cos(ang), sin(ang)) * rad;
93 r.x /= aspect;
94 return r + c;
95}
96
97/**
98 * @brief Evaluates fractalFold for this shader effect.
99 * @param uv Input value for the calculation.
100 * @param zoom Input value for the calculation.
101 * @param t Input value for the calculation.
102 * @param c Input value for the calculation.
103 * @param aspect Input value for the calculation.
104 * @return Computed vec2 value.
105 */
106vec2 fractalFold(vec2 uv, float zoom, float t, vec2 c, float aspect) {
107 vec2 p = uv;
108 for (int i = 0; i < 3; i++) {
109 p = abs((p - c) * (zoom + 0.15 * sin(t * (0.35 + amp_low * 0.2) + float(i)))) - 0.5 + c;
110 p = rotateUV(p, t * 0.12 + float(i) * 0.07, c, aspect);
111 }
112 return p;
113}
114
115/**
116 * @brief Evaluates tentBlur3 for this shader effect.
117 * @param img Input value for the calculation.
118 * @param uv Input value for the calculation.
119 * @param res Input value for the calculation.
120 * @return Computed vec3 value.
121 */
122vec3 tentBlur3(sampler2D img, vec2 uv, vec2 res) {
123 vec2 ts = 1.0 / res;
124 vec3 s00 = textureGrad(img, uv + ts * vec2(-1.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
125 vec3 s10 = textureGrad(img, uv + ts * vec2(0.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
126 vec3 s20 = textureGrad(img, uv + ts * vec2(1.0, -1.0), dFdx(uv), dFdy(uv)).rgb;
127 vec3 s01 = textureGrad(img, uv + ts * vec2(-1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
128 vec3 s11 = textureGrad(img, uv, dFdx(uv), dFdy(uv)).rgb;
129 vec3 s21 = textureGrad(img, uv + ts * vec2(1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
130 vec3 s02 = textureGrad(img, uv + ts * vec2(-1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
131 vec3 s12 = textureGrad(img, uv + ts * vec2(0.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
132 vec3 s22 = textureGrad(img, uv + ts * vec2(1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
133 return (s00 + 2.0 * s10 + s20 + 2.0 * s01 + 4.0 * s11 + 2.0 * s21 + s02 + 2.0 * s12 + s22) / 16.0;
134}
135
136/**
137 * @brief Evaluates preBlendColor for this shader effect.
138 * @param uv Input value for the calculation.
139 * @return Computed vec3 value.
140 */
141vec3 preBlendColor(vec2 uv) {
142 vec3 tex = tentBlur3(samp, uv, iResolution);
143 vec2 centered = uv * 2.0 - 1.0;
144 float wave = sin(centered.x * 10.0 + time_f * 2.0) * 0.1;
145 float angle = atan(centered.y + wave, centered.x) + time_f * 2.0;
146 vec3 rain = rainbow(angle / (2.0 * PI));
147 return mix(tex, rain, 0.5);
148}
149
150/**
151 * @brief Evaluates diamondRadius for this shader effect.
152 * @param p Input value for the calculation.
153 * @return Computed float value.
154 */
155float diamondRadius(vec2 p) {
156 p = sin(abs(p));
157 return max(p.x, p.y);
158}
159
160/**
161 * @brief Evaluates diamondFold for this shader effect.
162 * @param uv Input value for the calculation.
163 * @param c Input value for the calculation.
164 * @param aspect Input value for the calculation.
165 * @return Computed vec2 value.
166 */
167vec2 diamondFold(vec2 uv, vec2 c, float aspect) {
168 vec2 p = (uv - c) * vec2(aspect, 1.0);
169 p = abs(p);
170 if (p.y > p.x) p = p.yx;
171 p.x /= aspect;
172 return p + c;
173}
174
175// --- NEW: XOR Blending Function ---
176/**
177 * @brief Evaluates xorBlend for this shader effect.
178 * @param colorA Input value for the calculation.
179 * @param colorB Input value for the calculation.
180 * @param s Input value for the calculation.
181 * @return Computed vec3 value.
182 */
183vec3 xorBlend(vec3 colorA, vec3 colorB, float s) {
184 // 1. Scale up to integer range (0-255)
185 ivec3 iA = ivec3(colorA * s * 255.0);
186 ivec3 iB = ivec3(colorB * s * 255.0);
187
188 // 2. Perform Bitwise XOR
189 ivec3 iXor = iA ^ iB;
190
191 // 3. Scale back down to float
192 return vec3(iXor) / 255.0;
193}
194
195/**
196 * @brief Executes the fragment shader entry point.
197 */
198void main(void) {
199 // 1. Original Texture
200 vec4 baseTex = texture(samp, tc);
201
202 // 2. Fractal Geometry
203 vec2 uv = tc * 2.0 - 1.0;
204 float aspect = iResolution.x / iResolution.y;
205 uv.x *= aspect;
206
207 vec2 m = (iMouse.z > 0.5) ? (iMouse.xy / iResolution) : vec2(0.5);
208 vec2 ar = vec2(aspect, 1.0);
209
210 float seg = 4.0 + (2.0 + amp_mid * 2.0) * sin(time_f * 0.33);
211 vec2 kUV = reflectUV(tc, seg, m, aspect);
212 kUV = diamondFold(kUV, m, aspect);
213
214 float foldZoom = 1.3 + (0.3 + amp_low * 0.4) * sin(time_f * 0.42);
215 kUV = fractalFold(kUV, foldZoom, time_f, m, aspect);
216 kUV = rotateUV(kUV, time_f * (0.23 + amp_low * 0.15), m, aspect);
217 kUV = diamondFold(kUV, m, aspect);
218
219 vec2 p = (kUV - m) * ar;
220 vec2 q = abs(p);
221 if (q.y > q.x) q = q.yx;
222
223 float base = 1.82;
224 float period = log(base);
225 float tz = time_f * (0.65 + amp_low * 0.3);
226 float rD = diamondRadius(p) + 1e-6;
227 float ang = atan(q.y, q.x) + tz * 0.35 + 0.35 * sin(rD * 18.0 + time_f * 0.6);
228 float k = fract((log(rD) - tz) / period);
229 float rw = exp(k * period);
230
231 vec2 pwrap = vec2(cos(ang), sin(ang)) * rw;
232 vec2 dir = normalize(pwrap + 1e-6);
233 vec2 off = dir * ((0.0015 + amp_high * 0.002) + 0.001 * sin(time_f * 1.3)) * vec2(1.0, 1.0 / aspect);
234
235 vec2 u0 = fract(pwrap / ar + m);
236 vec2 u1 = fract((pwrap * 1.045) / ar + m);
237 vec2 u2 = fract((pwrap * 0.955) / ar + m);
238
239 vec3 rC = preBlendColor(u0 + off);
240 vec3 gC = preBlendColor(u1);
241 vec3 bC = preBlendColor(u2 - off);
242 vec3 fractalRGB = vec3(rC.r, gC.g, bC.b);
243
244 float vign = 1.0 - smoothstep(0.75, 1.2, length((tc - m) * ar));
245 vign = mix(0.9, (1.15 + amp_smooth * 0.2), vign);
246 float pulse = 0.5 + (0.5 + amp_rms * 0.3) * sin(time_f * 2.0 + rD * 28.0 + k * 12.0);
247 fractalRGB *= (0.8 + 0.2 * pulse) * vign;
248 fractalRGB = clamp(fractalRGB, 0.0, 1.0);
249
250 // 3. Morph Calculation
251 // Same smooth wave as before
252 float wave = sin(time_f * 0.4 + PI * 1.5);
253 float morph = smoothstep(0.0, 1.0, wave * 0.5 + 0.5);
254
255 // 4. THE XOR BLEND
256 // Calculate the pure XOR result between original and fractal
257 vec3 xorResult = xorBlend(baseTex.rgb, fractalRGB, morph);
258
259 // Smoothly fade between Original and the XOR'd Fractal
260 vec3 finalRGB = mix(baseTex.rgb, xorResult, 1.0);
261
262
263 // --- Audio Reactivity: direct output modulation ---
264 float _ab = clamp(amp_peak, 0.0, 1.0);
265 float _abass = clamp(amp_low, 0.0, 1.0);
266 finalRGB *= 1.0 + _ab * 0.6;
267 finalRGB = mix(finalRGB, finalRGB * vec3(1.0 + _abass * 0.3, 1.0 - _abass * 0.15, 1.0 + clamp(amp_high, 0.0, 1.0) * 0.25), _ab);
268 // --- End Audio Reactivity ---
269
270 color = vec4(finalRGB, baseTex.a);
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 amp_mid
#define amp_low
#define amp_high
#define amp_peak
vec3 wave(ivec2 p, ivec2 size)
Evaluates wave 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.
vec3 rainbow(float t)
Evaluates rainbow for this shader effect.
vec2 diamondFold(vec2 p)
Evaluates diamondFold 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 tentBlur3(sampler2D img, vec2 uv, vec2 res)
Evaluates tentBlur3 for this shader effect.
Definition aura2.frag:145
vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect)
Evaluates reflectUV for this shader effect.
Definition aura2.frag:76
float diamondRadius(vec2 p)
Evaluates diamondRadius for this shader effect.
Definition aura2.frag:182
vec3 preBlendColor(vec2 uv)
Evaluates preBlendColor for this shader effect.
Definition aura2.frag:164
#define amp_rms
Definition breathe.frag:21
#define PI