ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
code-frac-x-julia-wormhole.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_high ext.audio_bands.z
14#define amp_low ext.audio_bands.x
15#define amp_mid ext.audio_bands.y
16#define amp_peak ext.u2.w
17#define amp_rms ext.u3.z
18#define amp_smooth ext.u3.w
19#define iMouse ext.mouse
20#define iResolution ext.u0.zw
21#define iamp ext.u1.z
22#define time_f ext.u2.y
23
24/**
25 * @file code-frac-x-julia-wormhole.frag
26 * @brief Vulkan fragment shader: code-frac-x-julia-wormhole.
27 */
28// code-frac-x-julia-wormhole: 4K+ derivative-filtered remix of the Acid Cam frac shader family.
29// Domain engine: log-polar singularity recursion. Detail engine: smooth Julia escape field.
30layout(location = 0) out vec4 color;
31layout(location = 0) in vec2 tc;
32layout(set = 0, binding = 0) uniform sampler2D samp;
33
34
35
36
37
38
39
40
41
42
43
44const float PI = 3.14159265358979323846;
45const float TAU = 6.28318530717958647692;
46const float SEGMENTS = 6.0;
47const float FOLD_GAIN = 1.340;
48const float SPIN_RATE = 0.274;
49const float WARP_STRENGTH = 0.700;
50const float TEXTURE_MIX = 0.770;
51const float EXPOSURE = 1.092;
52const float HUE_SHIFT = 0.463;
53
54/**
55 * @brief Evaluates rot for this shader effect.
56 * @param a Input value for the calculation.
57 * @return Computed mat2 value.
58 */
59mat2 rot(float a) {
60 float s = sin(a), c = cos(a);
61 return mat2(c, -s, s, c);
62}
63
64/**
65 * @brief Evaluates saturate for this shader effect.
66 * @param x Input value for the calculation.
67 * @return Computed float value.
68 */
69float saturate(float x) { return clamp(x, 0.0, 1.0); }
70/**
71 * @brief Evaluates saturate for this shader effect.
72 * @param x Input value for the calculation.
73 * @return Computed vec2 value.
74 */
75vec2 saturate(vec2 x) { return clamp(x, 0.0, 1.0); }
76/**
77 * @brief Evaluates saturate for this shader effect.
78 * @param x Input value for the calculation.
79 * @return Computed vec3 value.
80 */
81vec3 saturate(vec3 x) { return clamp(x, 0.0, 1.0); }
82
83/**
84 * @brief Evaluates hash22 for this shader effect.
85 * @param p Input value for the calculation.
86 * @return Computed vec2 value.
87 */
88vec2 hash22(vec2 p) {
89 vec3 q = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
90 q += dot(q, q.yzx + 33.33);
91 return fract((q.xx + q.yz) * q.zy);
92}
93
94/**
95 * @brief Evaluates valueNoise for this shader effect.
96 * @param p Input value for the calculation.
97 * @return Computed float value.
98 */
99float valueNoise(vec2 p) {
100 vec2 i = floor(p);
101 vec2 f = fract(p);
102 vec2 u = f * f * (3.0 - 2.0 * f);
103 float a = hash22(i).x;
104 float b = hash22(i + vec2(1.0, 0.0)).x;
105 float c = hash22(i + vec2(0.0, 1.0)).x;
106 float d = hash22(i + vec2(1.0, 1.0)).x;
107 return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
108}
109
110/**
111 * @brief Evaluates fbm6 for this shader effect.
112 * @param p Input value for the calculation.
113 * @return Computed float value.
114 */
115float fbm6(vec2 p) {
116 float sum = 0.0;
117 float weight = 0.5;
118 mat2 octave = rot(0.53) * 2.03;
119 for (int i = 0; i < 6; ++i) {
120 sum += weight * valueNoise(p);
121 p = octave * p + vec2(17.13, 9.71);
122 weight *= 0.5;
123 }
124 return sum / 0.984375;
125}
126
127/**
128 * @brief Evaluates flowNoise for this shader effect.
129 * @param p Input value for the calculation.
130 * @return Computed vec2 value.
131 */
132vec2 flowNoise(vec2 p) {
133 return vec2(fbm6(p + vec2(7.1, 1.7)),
134 fbm6(rot(1.57) * p + vec2(3.8, 11.3))) * 2.0 - 1.0;
135}
136
137/**
138 * @brief Evaluates complexMul for this shader effect.
139 * @param a Input value for the calculation.
140 * @param b Input value for the calculation.
141 * @return Computed vec2 value.
142 */
143vec2 complexMul(vec2 a, vec2 b) {
144 return vec2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
145}
146
147/**
148 * @brief Evaluates complexDiv for this shader effect.
149 * @param a Input value for the calculation.
150 * @param b Input value for the calculation.
151 * @return Computed vec2 value.
152 */
153vec2 complexDiv(vec2 a, vec2 b) {
154 float d = max(dot(b, b), 1e-4);
155 return vec2(a.x * b.x + a.y * b.y, a.y * b.x - a.x * b.y) / d;
156}
157
158/**
159 * @brief Evaluates kaleido for this shader effect.
160 * @param p Input value for the calculation.
161 * @param segments Input value for the calculation.
162 * @return Computed vec2 value.
163 */
164vec2 kaleido(vec2 p, float segments) {
165 float radius = length(p);
166 float slice = TAU / max(segments, 2.0);
167 float angle = atan(p.y, p.x);
168 angle = abs(mod(angle + 0.5 * slice, slice) - 0.5 * slice);
169 return radius * vec2(cos(angle), sin(angle));
170}
171
172/**
173 * @brief Evaluates mirrorWrap for this shader effect.
174 * @param uv Input value for the calculation.
175 * @return Computed vec2 value.
176 */
177vec2 mirrorWrap(vec2 uv) {
178 return 1.0 - abs(mod(uv, 2.0) - 1.0);
179}
180
181/**
182 * @brief Evaluates boundedFold for this shader effect.
183 * @param p Input value for the calculation.
184 * @return Computed vec2 value.
185 */
186vec2 boundedFold(vec2 p) {
187 p = abs(p);
188 if (p.y > p.x) p = p.yx;
189 return clamp(p, vec2(-3.0), vec2(3.0));
190}
191
192/**
193 * @brief Evaluates aaLine for this shader effect.
194 * @param distanceToLine Input value for the calculation.
195 * @param halfWidth Input value for the calculation.
196 * @return Computed float value.
197 */
198float aaLine(float distanceToLine, float halfWidth) {
199 float aa = max(fwidth(distanceToLine), 1.0 / max(min(iResolution.x, iResolution.y), 1.0));
200 return 1.0 - smoothstep(halfWidth - aa, halfWidth + aa, abs(distanceToLine));
201}
202
203/**
204 * @brief Evaluates aaPulse for this shader effect.
205 * @param phase Input value for the calculation.
206 * @param width Input value for the calculation.
207 * @return Computed float value.
208 */
209float aaPulse(float phase, float width) {
210 float wave = abs(fract(phase) - 0.5);
211 float aa = max(fwidth(phase), 1.0 / max(min(iResolution.x, iResolution.y), 1.0));
212 return 1.0 - smoothstep(width - aa, width + aa, wave);
213}
214
215/**
216 * @brief Evaluates cosinePalette for this shader effect.
217 * @param x Input value for the calculation.
218 * @return Computed vec3 value.
219 */
220vec3 cosinePalette(float x) {
221 vec3 base = vec3(0.52, 0.48, 0.50);
222 vec3 amplitude = vec3(0.48, 0.46, 0.50);
223 vec3 frequency = vec3(1.00, 1.04, 0.96);
224 vec3 phase = vec3(HUE_SHIFT, HUE_SHIFT + 0.21, HUE_SHIFT + 0.43);
225 return saturate(base + amplitude * cos(TAU * (frequency * x + phase)));
226}
227
228// A bounded twelve-generation inversion IFS. Besides its final coordinate it
229// carries three orbit traps, so later lighting is tied to real fractal history.
230/**
231 * @brief Evaluates deepOrbit for this shader effect.
232 * @param seed Input value for the calculation.
233 * @param t Input value for the calculation.
234 * @param audio Input value for the calculation.
235 * @return Computed vec4 value.
236 */
237vec4 deepOrbit(vec2 seed, float t, vec4 audio) {
238 vec2 z = seed;
239 float lineTrap = 10.0;
240 float pointTrap = 10.0;
241 float energy = 0.0;
242 for (int i = 0; i < 12; ++i) {
243 float fi = float(i);
244 z = rot(0.37 + SPIN_RATE * 0.17 + 0.025 * sin(t * 0.21 + fi)) * z;
245 z = abs(z) - vec2(0.42 + 0.035 * sin(fi * 1.7 + t * 0.13),
246 0.31 + 0.040 * cos(fi * 1.3 - t * 0.16));
247 float inverseRadius = clamp(dot(z, z), 0.16, 1.45);
248 z = z * (FOLD_GAIN / inverseRadius) - vec2(0.36, 0.24);
249 z += 0.025 * audio.xy * vec2(sin(fi + t), cos(fi - t));
250 lineTrap = min(lineTrap, min(abs(z.x), abs(z.y)));
251 pointTrap = min(pointTrap, length(z - vec2(0.22, -0.18)));
252 energy += exp(-2.8 * abs(dot(z, normalize(vec2(0.8, 0.6))))) / 12.0;
253 }
254 return vec4(lineTrap, pointTrap, energy, atan(z.y, z.x) / TAU + 0.5);
255}
256
257// Seven-tap explicit-gradient sampling: texture detail remains stable across
258// nonlinear folds, while all chromatic offsets are specified in source pixels.
259/**
260 * @brief Evaluates sampleTextureHQ for this shader effect.
261 * @param uv Input value for the calculation.
262 * @param direction Input value for the calculation.
263 * @param splitPixels Input value for the calculation.
264 * @return Computed vec3 value.
265 */
266vec3 sampleTextureHQ(vec2 uv, vec2 direction, float splitPixels) {
267 vec2 texSize = max(vec2(textureSize(samp, 0)), vec2(1.0));
268 vec2 texel = 1.0 / texSize;
269 uv = mirrorWrap(uv);
270 vec2 gx = dFdx(uv);
271 vec2 gy = dFdy(uv);
272 vec2 axis = normalize(direction + vec2(1e-5));
273 vec2 tangent = vec2(-axis.y, axis.x);
274 vec2 tapA = axis * texel * 0.72;
275 vec2 tapB = tangent * texel * 0.72;
276 vec3 center = textureGrad(samp, uv, gx, gy).rgb;
277 vec3 filtered = center * 0.40;
278 filtered += textureGrad(samp, mirrorWrap(uv + tapA), gx, gy).rgb * 0.15;
279 filtered += textureGrad(samp, mirrorWrap(uv - tapA), gx, gy).rgb * 0.15;
280 filtered += textureGrad(samp, mirrorWrap(uv + tapB), gx, gy).rgb * 0.15;
281 filtered += textureGrad(samp, mirrorWrap(uv - tapB), gx, gy).rgb * 0.15;
282 vec2 split = axis * texel * splitPixels;
283 float red = textureGrad(samp, mirrorWrap(uv + split), gx, gy).r;
284 float blue = textureGrad(samp, mirrorWrap(uv - split), gx, gy).b;
285 return mix(filtered, vec3(red, filtered.g, blue), 0.68);
286}
287
288// Log-polar singularity: reciprocal tunnel projection followed by nine
289// mirrored scale recursions, remixed from the zoom and wormhole frac shaders.
290/**
291 * @brief Evaluates remixDomain for this shader effect.
292 * @param p Input value for the calculation.
293 * @param t Input value for the calculation.
294 * @param audio Input value for the calculation.
295 * @return Computed vec2 value.
296 */
297vec2 remixDomain(vec2 p, float t, vec4 audio) {
298 float radius = max(length(p), 0.0015);
299 float angle = atan(p.y, p.x) + WARP_STRENGTH / (0.18 + radius);
300 p = vec2(log(radius) * 0.72 - t * (0.08 + audio.x * 0.04),
301 angle / TAU * SEGMENTS);
302 for (int i = 0; i < 9; ++i) {
303 float fi = float(i);
304 p = abs(fract(p * (1.36 + 0.018 * fi) + 0.5) - 0.5) * 2.0 - 0.48;
305 p = rot(0.18 + SPIN_RATE * 0.5 + fi * 0.021) * p;
306 p += 0.045 * vec2(sin(p.y * 5.0 + t + fi), cos(p.x * 4.0 - t));
307 }
308 return p * (1.25 + 0.15 * audio.w);
309}
310
311// Forty-iteration Julia escape field with smooth iteration bands and dual
312// orbit traps. The parameter drifts slowly and responds to bass/mouse centering.
313/**
314 * @brief Evaluates remixDetail for this shader effect.
315 * @param p Input value for the calculation.
316 * @param original Input value for the calculation.
317 * @param t Input value for the calculation.
318 * @param audio Input value for the calculation.
319 * @param orbit Input value for the calculation.
320 * @return Computed vec3 value.
321 */
322vec3 remixDetail(vec2 p, vec2 original, float t, vec4 audio, vec4 orbit) {
323 vec2 z = p * (1.28 + audio.x * 0.12);
324 vec2 c = vec2(-0.745 + 0.055 * sin(t * 0.071 + HUE_SHIFT * TAU),
325 0.113 + 0.060 * cos(t * 0.093 - HUE_SHIFT * TAU));
326 float escapedAt = 40.0;
327 float circleTrap = 10.0;
328 float crossTrap = 10.0;
329 for (int i = 0; i < 40; ++i) {
330 circleTrap = min(circleTrap, abs(length(z) - 0.52));
331 crossTrap = min(crossTrap, min(abs(z.x), abs(z.y)));
332 z = complexMul(z, z) + c;
333 if (dot(z, z) > 256.0) {
334 escapedAt = float(i);
335 break;
336 }
337 }
338 float smoothIteration = escapedAt;
339 if (escapedAt < 40.0) {
340 smoothIteration += 1.0 - log2(max(log2(max(dot(z, z), 2.0)), 1e-4));
341 }
342 float bands = aaPulse(smoothIteration * 0.082 + orbit.w * 0.7 - t * 0.025, 0.16);
343 float orbitGlow = exp(-18.0 * circleTrap) + 0.55 * exp(-24.0 * crossTrap);
344 float interior = smoothstep(38.0, 40.0, smoothIteration);
345 return vec3(saturate(bands), saturate(orbitGlow), saturate(interior + orbit.z * 0.2));
346}
347
348/**
349 * @brief Evaluates screenBlend for this shader effect.
350 * @param a Input value for the calculation.
351 * @param b Input value for the calculation.
352 * @return Computed vec3 value.
353 */
354vec3 screenBlend(vec3 a, vec3 b) {
355 return 1.0 - (1.0 - a) * (1.0 - b);
356}
357
358/**
359 * @brief Evaluates filmicToneMap for this shader effect.
360 * @param x Input value for the calculation.
361 * @return Computed vec3 value.
362 */
363vec3 filmicToneMap(vec3 x) {
364 x = max(x, vec3(0.0));
365 return saturate((x * (2.51 * x + 0.03)) /
366 (x * (2.43 * x + 0.59) + 0.14));
367}
368
369/**
370 * @brief Executes the fragment shader entry point.
371 */
372void main() {
373 vec2 resolution = max(iResolution, vec2(1.0));
374 float aspect = resolution.x / resolution.y;
375 vec2 aspectScale = vec2(aspect, 1.0);
376 vec4 source = texture(samp, tc);
377 vec2 center = (iMouse.z > 0.5) ? saturate(iMouse.xy / resolution) : vec2(0.5);
378
379 float bass = saturate(amp_low);
380 float mids = saturate(amp_mid);
381 float highs = saturate(amp_high);
382 float peak = saturate(max(amp_peak, iamp));
383 vec4 audio = vec4(bass, mids, highs, peak);
384 float t = time_f;
385
386 vec2 original = (tc - center) * aspectScale;
387 float breathingZoom = 1.0 + 0.07 * sin(t * 0.19) + bass * 0.10;
388 original = rot(t * SPIN_RATE * 0.11) * original * breathingZoom;
389
390 vec2 domain = remixDomain(original, t, audio);
391 vec4 orbit = deepOrbit(domain, t, audio);
392 vec3 detail = remixDetail(domain, original, t, audio, orbit);
393
394 float radius = length(domain);
395 float angle = atan(domain.y, domain.x);
396 float logPhase = log(radius + 0.025) * (1.7 + WARP_STRENGTH) - t * (0.075 + bass * 0.045);
397 vec2 textureDomain = rot(angle * 0.08 + orbit.w * 0.35) * domain;
398 textureDomain += 0.075 * vec2(sin(logPhase * 2.3 + t * 0.11),
399 cos(logPhase * 1.9 - t * 0.09));
400 vec2 warpedUV = center + textureDomain / aspectScale * (0.34 + 0.04 * sin(logPhase));
401 warpedUV = mirrorWrap(warpedUV);
402
403 vec2 sampleDirection = normalize(vec2(cos(angle + orbit.w * TAU),
404 sin(angle + orbit.w * TAU)) + vec2(1e-5));
405 float splitPixels = 0.8 + highs * 5.5 + detail.y * 1.4;
406 vec3 warpedTexture = sampleTextureHQ(warpedUV, sampleDirection, splitPixels);
407
408 float palettePhase = orbit.w + detail.x * 0.19 + detail.y * 0.13
409 + detail.z * 0.11 + logPhase * 0.075 + t * 0.018;
410 vec3 palette = cosinePalette(palettePhase);
411 vec3 companion = cosinePalette(palettePhase + 0.31 + orbit.z * 0.12);
412
413 float geometry = saturate(0.28 + detail.x * 0.48 + detail.y * 0.30);
414 float luminosity = 0.68 + orbit.z * 0.38 + detail.z * 0.34;
415 vec3 coloredTexture = warpedTexture * mix(vec3(1.0), palette * 1.34, 0.54 + mids * 0.14);
416 vec3 luminousLayer = screenBlend(coloredTexture, companion * geometry * 0.82);
417 vec3 fractalColor = mix(coloredTexture, luminousLayer, 0.58 + peak * 0.18);
418 fractalColor *= luminosity;
419 fractalColor += palette * (detail.x * 0.15 + detail.y * 0.10 + orbit.z * 0.08);
420
421 float sourceLuma = dot(source.rgb, vec3(0.2126, 0.7152, 0.0722));
422 fractalColor = mix(fractalColor, fractalColor * (0.72 + sourceLuma * 0.56), 0.34);
423 float blendAmount = saturate(TEXTURE_MIX + geometry * 0.10 + peak * 0.06);
424 vec3 outputColor = mix(source.rgb, fractalColor, blendAmount);
425
426 vec2 vignettePoint = (tc - center) * aspectScale;
427 float vignette = 1.0 - smoothstep(0.58, 1.42, length(vignettePoint));
428 outputColor *= 0.82 + vignette * 0.18;
429 outputColor *= EXPOSURE * (1.0 + peak * 0.24);
430 outputColor = mix(outputColor / (1.0 + outputColor), filmicToneMap(outputColor), 0.72);
431
432 color = vec4(saturate(outputColor), source.a);
433}
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_mid
vec3 palette(float phase)
Evaluates palette for this shader effect.
#define amp_low
#define amp_high
#define amp_peak
vec3 wave(ivec2 p, ivec2 size)
Evaluates wave for this shader effect.
#define seed
Definition air-bowl.frag:20
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
float energy()
Evaluates energy for this shader effect.
vec2 kaleido(vec2 p, float seg)
Evaluates kaleido for this shader effect.
#define iamp
Definition breathe.frag:24
const float SEGMENTS
vec3 sampleTextureHQ(vec2 uv, vec2 direction, float splitPixels)
Evaluates sampleTextureHQ for this shader effect.
vec3 screenBlend(vec3 a, vec3 b)
Evaluates screenBlend for this shader effect.
vec2 hash22(vec2 p)
Evaluates hash22 for this shader effect.
float fbm6(vec2 p)
Evaluates fbm6 for this shader effect.
float aaPulse(float phase, float width)
Evaluates aaPulse for this shader effect.
vec2 complexDiv(vec2 a, vec2 b)
Evaluates complexDiv for this shader effect.
vec2 complexMul(vec2 a, vec2 b)
Evaluates complexMul for this shader effect.
const float FOLD_GAIN
vec3 filmicToneMap(vec3 x)
Evaluates filmicToneMap for this shader effect.
float valueNoise(vec2 p)
Evaluates valueNoise for this shader effect.
float aaLine(float distanceToLine, float halfWidth)
Evaluates aaLine for this shader effect.
float saturate(float x)
Evaluates saturate for this shader effect.
vec2 remixDomain(vec2 p, float t, vec4 audio)
Evaluates remixDomain for this shader effect.
const float SPIN_RATE
vec3 remixDetail(vec2 p, vec2 original, float t, vec4 audio, vec4 orbit)
Evaluates remixDetail for this shader effect.
vec2 mirrorWrap(vec2 uv)
Evaluates mirrorWrap for this shader effect.
vec4 deepOrbit(vec2 seed, float t, vec4 audio)
Evaluates deepOrbit for this shader effect.
vec2 flowNoise(vec2 p)
Evaluates flowNoise for this shader effect.
const float HUE_SHIFT
vec2 boundedFold(vec2 p)
Evaluates boundedFold for this shader effect.
const float WARP_STRENGTH
const float TEXTURE_MIX
vec3 cosinePalette(float x)
Evaluates cosinePalette for this shader effect.
#define TAU
#define PI
vec4 fractalColor(vec2 uv)
Evaluates fractalColor for this shader effect.
Definition deeps1.frag:66
#define frequency
Definition ol.frag:13