ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
code-frac-x-astral-dream-engine.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-astral-dream-engine.frag
26 * @brief Vulkan fragment shader: code-frac-x-astral-dream-engine.
27 */
28// code-frac-x-astral-dream-engine: 4K+ derivative-filtered remix of the Acid Cam frac shader family.
29// Domain engine: rational Mobius inversion. Detail engine: antialiased log-polar tunnel.
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.300;
49const float WARP_STRENGTH = 0.770;
50const float TEXTURE_MIX = 0.770;
51const float EXPOSURE = 1.056;
52const float HUE_SHIFT = 0.741;
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// Rational Mobius recursion: complex division, sphere inversion, orbiting
289// poles, and nine bounded folds create a zero-gravity fractal manifold.
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 vec2 pole = 0.32 * vec2(cos(t * 0.17), sin(t * 0.13));
299 vec2 numerator = complexMul(p + vec2(0.18, -0.11), p - vec2(0.21, 0.16));
300 p = complexDiv(numerator, p - pole);
301 p *= 0.42 + 0.05 * audio.x;
302 for (int i = 0; i < 9; ++i) {
303 float fi = float(i);
304 p = rot(SPIN_RATE + fi * 0.037 + t * 0.009) * p;
305 p = abs(p) - vec2(0.41, 0.27 + 0.02 * sin(fi + t * 0.2));
306 float radius2 = clamp(dot(p, p), 0.14, 1.32);
307 p *= (1.06 + FOLD_GAIN * 0.23) / radius2;
308 p -= vec2(0.47, 0.31);
309 }
310 return kaleido(p, SEGMENTS + floor(audio.y * 5.0));
311}
312
313// Log-polar tunnel lattice: concentric recursion, angular spokes, and a
314// moving helical interference layer, all filtered through screen derivatives.
315/**
316 * @brief Evaluates remixDetail for this shader effect.
317 * @param p Input value for the calculation.
318 * @param original Input value for the calculation.
319 * @param t Input value for the calculation.
320 * @param audio Input value for the calculation.
321 * @param orbit Input value for the calculation.
322 * @return Computed vec3 value.
323 */
324vec3 remixDetail(vec2 p, vec2 original, float t, vec4 audio, vec4 orbit) {
325 float radius = max(length(p), 0.001);
326 float angle = atan(p.y, p.x) / TAU;
327 float depth = log(radius) * (2.1 + WARP_STRENGTH) - t * (0.16 + audio.x * 0.08);
328 float rings = aaPulse(depth * 1.7 + 0.15 * sin(angle * TAU * 5.0), 0.105);
329 float spokes = aaPulse(angle * (SEGMENTS + floor(audio.y * 5.0)) + depth * 0.13, 0.095);
330 float helixPhase = depth * 2.4 - angle * 7.0 + orbit.w * 1.8 + t * 0.06;
331 float helix = aaLine(sin(TAU * helixPhase), 0.12 + audio.z * 0.03);
332 return vec3(rings, spokes, helix);
333}
334
335/**
336 * @brief Evaluates screenBlend for this shader effect.
337 * @param a Input value for the calculation.
338 * @param b Input value for the calculation.
339 * @return Computed vec3 value.
340 */
341vec3 screenBlend(vec3 a, vec3 b) {
342 return 1.0 - (1.0 - a) * (1.0 - b);
343}
344
345/**
346 * @brief Evaluates filmicToneMap for this shader effect.
347 * @param x Input value for the calculation.
348 * @return Computed vec3 value.
349 */
350vec3 filmicToneMap(vec3 x) {
351 x = max(x, vec3(0.0));
352 return saturate((x * (2.51 * x + 0.03)) /
353 (x * (2.43 * x + 0.59) + 0.14));
354}
355
356/**
357 * @brief Executes the fragment shader entry point.
358 */
359void main() {
360 vec2 resolution = max(iResolution, vec2(1.0));
361 float aspect = resolution.x / resolution.y;
362 vec2 aspectScale = vec2(aspect, 1.0);
363 vec4 source = texture(samp, tc);
364 vec2 center = (iMouse.z > 0.5) ? saturate(iMouse.xy / resolution) : vec2(0.5);
365
366 float bass = saturate(amp_low);
367 float mids = saturate(amp_mid);
368 float highs = saturate(amp_high);
369 float peak = saturate(max(amp_peak, iamp));
370 vec4 audio = vec4(bass, mids, highs, peak);
371 float t = time_f;
372
373 vec2 original = (tc - center) * aspectScale;
374 float breathingZoom = 1.0 + 0.07 * sin(t * 0.19) + bass * 0.10;
375 original = rot(t * SPIN_RATE * 0.11) * original * breathingZoom;
376
377 vec2 domain = remixDomain(original, t, audio);
378 vec4 orbit = deepOrbit(domain, t, audio);
379 vec3 detail = remixDetail(domain, original, t, audio, orbit);
380
381 float radius = length(domain);
382 float angle = atan(domain.y, domain.x);
383 float logPhase = log(radius + 0.025) * (1.7 + WARP_STRENGTH) - t * (0.075 + bass * 0.045);
384 vec2 textureDomain = rot(angle * 0.08 + orbit.w * 0.35) * domain;
385 textureDomain += 0.075 * vec2(sin(logPhase * 2.3 + t * 0.11),
386 cos(logPhase * 1.9 - t * 0.09));
387 vec2 warpedUV = center + textureDomain / aspectScale * (0.34 + 0.04 * sin(logPhase));
388 warpedUV = mirrorWrap(warpedUV);
389
390 vec2 sampleDirection = normalize(vec2(cos(angle + orbit.w * TAU),
391 sin(angle + orbit.w * TAU)) + vec2(1e-5));
392 float splitPixels = 0.8 + highs * 5.5 + detail.y * 1.4;
393 vec3 warpedTexture = sampleTextureHQ(warpedUV, sampleDirection, splitPixels);
394
395 float palettePhase = orbit.w + detail.x * 0.19 + detail.y * 0.13
396 + detail.z * 0.11 + logPhase * 0.075 + t * 0.018;
397 vec3 palette = cosinePalette(palettePhase);
398 vec3 companion = cosinePalette(palettePhase + 0.31 + orbit.z * 0.12);
399
400 float geometry = saturate(0.28 + detail.x * 0.48 + detail.y * 0.30);
401 float luminosity = 0.68 + orbit.z * 0.38 + detail.z * 0.34;
402 vec3 coloredTexture = warpedTexture * mix(vec3(1.0), palette * 1.34, 0.54 + mids * 0.14);
403 vec3 luminousLayer = screenBlend(coloredTexture, companion * geometry * 0.82);
404 vec3 fractalColor = mix(coloredTexture, luminousLayer, 0.58 + peak * 0.18);
405 fractalColor *= luminosity;
406 fractalColor += palette * (detail.x * 0.15 + detail.y * 0.10 + orbit.z * 0.08);
407
408 float sourceLuma = dot(source.rgb, vec3(0.2126, 0.7152, 0.0722));
409 fractalColor = mix(fractalColor, fractalColor * (0.72 + sourceLuma * 0.56), 0.34);
410 float blendAmount = saturate(TEXTURE_MIX + geometry * 0.10 + peak * 0.06);
411 vec3 outputColor = mix(source.rgb, fractalColor, blendAmount);
412
413 vec2 vignettePoint = (tc - center) * aspectScale;
414 float vignette = 1.0 - smoothstep(0.58, 1.42, length(vignettePoint));
415 outputColor *= 0.82 + vignette * 0.18;
416 outputColor *= EXPOSURE * (1.0 + peak * 0.24);
417 outputColor = mix(outputColor / (1.0 + outputColor), filmicToneMap(outputColor), 0.72);
418
419 color = vec4(saturate(outputColor), source.a);
420}
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