ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
fractal-code-large-aurora-veil.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file fractal-code-large-aurora-veil.frag
5 * @brief Vulkan fragment shader: fractal-code-large-aurora-veil.
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
42// Transparent large-form fractal distortion: aurora veil.
43const float PI = 3.14159265358979323846;
44const int STYLE = 0;
45const float SEGMENTS = 4.000;
46const float FOLD_ZOOM = 1.120;
47const float MOTION = 0.720;
48const float DISTORTION = 0.020;
49const float EFFECT_MIX = 0.500;
50const vec3 TINT_A = vec3(0.820, 1.080, 1.180);
51const vec3 TINT_B = vec3(1.100, 0.860, 1.040);
52
53/**
54 * @brief Evaluates rotateUV for this shader effect.
55 * @param uv Input value for the calculation.
56 * @param angle Input value for the calculation.
57 * @param center Input value for the calculation.
58 * @param aspect Input value for the calculation.
59 * @return Computed vec2 value.
60 */
61vec2 rotateUV(vec2 uv, float angle, vec2 center, float aspect) {
62 float s = sin(angle);
63 float c = cos(angle);
64 vec2 p = (uv - center) * vec2(aspect, 1.0);
65 p = mat2(c, -s, s, c) * p;
66 return p / vec2(aspect, 1.0) + center;
67}
68
69/**
70 * @brief Evaluates mirrorUV for this shader effect.
71 * @param uv Input value for the calculation.
72 * @return Computed vec2 value.
73 */
74vec2 mirrorUV(vec2 uv) {
75 vec2 tile = mod(uv, 2.0);
76 return 1.0 - abs(1.0 - tile);
77}
78
79/**
80 * @brief Evaluates kaleidoFold for this shader effect.
81 * @param uv Input value for the calculation.
82 * @param center Input value for the calculation.
83 * @param aspect Input value for the calculation.
84 * @param segments Input value for the calculation.
85 * @return Computed vec2 value.
86 */
87vec2 kaleidoFold(vec2 uv, vec2 center, float aspect, float segments) {
88 vec2 p = (uv - center) * vec2(aspect, 1.0);
89 float radius = length(p);
90 float wedge = 2.0 * PI / max(segments, 3.0);
91 float angle = abs(mod(atan(p.y, p.x) + 0.5 * wedge, wedge) - 0.5 * wedge);
92 p = radius * vec2(cos(angle), sin(angle));
93 return p / vec2(aspect, 1.0) + center;
94}
95
96/**
97 * @brief Evaluates largeFractalFold for this shader effect.
98 * @param uv Input value for the calculation.
99 * @param center Input value for the calculation.
100 * @param aspect Input value for the calculation.
101 * @param t Input value for the calculation.
102 * @return Computed vec2 value.
103 */
104vec2 largeFractalFold(vec2 uv, vec2 center, float aspect, float t) {
105 vec2 p = uv;
106 for (int i = 0; i < 3; ++i) {
107 float fi = float(i);
108 float scale = FOLD_ZOOM + 0.055 * sin(t * (0.43 + fi * 0.08) + fi * 2.1);
109 p = abs((p - center) * scale) - vec2(0.47 - fi * 0.025) + center;
110 p = rotateUV(p, 0.08 * sin(t * 0.31 + fi * 1.7), center, aspect);
111 }
112 return p;
113}
114
115/**
116 * @brief Evaluates sampleHQ for this shader effect.
117 * @param uv Input value for the calculation.
118 * @return Computed vec3 value.
119 */
120vec3 sampleHQ(vec2 uv) {
121 uv = mirrorUV(uv);
122 vec2 dx = dFdx(uv);
123 vec2 dy = dFdy(uv);
124 vec2 px = 1.0 / max(iResolution, vec2(1.0));
125 vec3 center = textureGrad(samp, uv, dx, dy).rgb;
126 vec3 axial = textureGrad(samp, mirrorUV(uv + vec2(px.x, 0.0)), dx, dy).rgb;
127 axial += textureGrad(samp, mirrorUV(uv - vec2(px.x, 0.0)), dx, dy).rgb;
128 axial += textureGrad(samp, mirrorUV(uv + vec2(0.0, px.y)), dx, dy).rgb;
129 axial += textureGrad(samp, mirrorUV(uv - vec2(0.0, px.y)), dx, dy).rgb;
130 return center * 0.60 + axial * 0.10;
131}
132
133/**
134 * @brief Executes the fragment shader entry point.
135 */
136void main(void) {
137 float aspect = iResolution.x / max(iResolution.y, 1.0);
138 float bass = clamp(amp_low, 0.0, 1.0);
139 float mids = clamp(amp_mid, 0.0, 1.0);
140 float highs = clamp(amp_high, 0.0, 1.0);
141 float energy = clamp(amp_smooth, 0.0, 1.0);
142 float t = time_f * MOTION;
143 vec2 center = iMouse.z > 0.5 ? iMouse.xy / max(iResolution, vec2(1.0)) : vec2(0.5);
144 vec2 ar = vec2(aspect, 1.0);
145 vec2 local = (tc - center) * ar;
146 float radius = length(local);
147 float angle = atan(local.y, local.x);
148
149 vec2 folded = kaleidoFold(tc, center, aspect, SEGMENTS + floor(mids * 3.0));
150 folded = largeFractalFold(folded, center, aspect, t);
151 vec2 fp = (folded - center) * ar;
152 float diamond = max(abs(fp.x), abs(fp.y));
153 float ring = sin(diamond * (12.0 + SEGMENTS) - t * 1.7);
154 float spiral = sin(angle * (2.0 + 0.25 * SEGMENTS) + radius * 18.0 - t * 2.2);
155 float lattice = sin(fp.x * (18.0 + SEGMENTS)) * cos(fp.y * (16.0 + SEGMENTS) + t);
156 float wave = ring;
157
158 if (STYLE == 1) {
159 wave = 0.62 * ring + 0.38 * sin(radius * 28.0 - t * 2.6);
160 } else if (STYLE == 2) {
161 wave = 0.68 * spiral + 0.32 * ring;
162 } else if (STYLE == 3) {
163 wave = 0.58 * lattice + 0.42 * spiral;
164 } else if (STYLE == 4) {
165 wave = 0.45 * ring + 0.35 * lattice + 0.20 * spiral;
166 }
167
168 vec2 normalField = vec2(dFdx(wave), dFdy(wave));
169 float normalLength = max(length(normalField), 1e-4);
170 normalField /= normalLength;
171 vec2 radial = local / max(radius, 1e-4) / ar;
172 vec2 tangent = vec2(-radial.y, radial.x / max(aspect, 1e-4));
173 float envelope = smoothstep(1.15, 0.05, radius);
174 float audioPush = 1.0 + bass * 0.28 + energy * 0.16;
175 vec2 displacement = (normalField * 0.58 + radial * wave * 0.30 + tangent * spiral * 0.12);
176 displacement *= DISTORTION * envelope * audioPush;
177 displacement.x /= max(aspect, 1.0);
178
179 vec2 warpedUV = tc + displacement;
180 vec2 chroma = normalField * (0.0007 + highs * 0.0013) * envelope;
181 chroma.x /= max(aspect, 1.0);
182 vec3 warped;
183 warped.r = sampleHQ(warpedUV + chroma).r;
184 warped.g = sampleHQ(warpedUV).g;
185 warped.b = sampleHQ(warpedUV - chroma).b;
186
187 // A direct folded copy makes the large fractal readable as a texture overlap.
188 vec2 foldDetail = folded + normalField * DISTORTION * 0.22;
189 vec3 foldedLayer;
190 foldedLayer.r = sampleHQ(foldDetail + chroma * 1.5).r;
191 foldedLayer.g = sampleHQ(foldDetail).g;
192 foldedLayer.b = sampleHQ(foldDetail - chroma * 1.5).b;
193
194 vec3 original = texture(samp, tc).rgb;
195 float detail = 0.5 + 0.5 * wave;
196 float aa = max(fwidth(wave), 0.001);
197 float facet = smoothstep(0.42 - aa, 0.42 + aa, detail);
198 vec3 tint = mix(TINT_A, TINT_B, facet);
199 vec3 fractalOverlap = mix(warped, foldedLayer, 0.58 + 0.08 * mids);
200 vec3 treated = mix(fractalOverlap, fractalOverlap * tint, 0.30 + 0.12 * energy);
201 float facetEdge = 1.0 - smoothstep(0.0, 0.10 + aa * 2.0, abs(detail - 0.42));
202 treated += tint * facetEdge * (0.035 + 0.025 * energy);
203 treated += (fractalOverlap - original) * (0.14 + 0.07 * mids);
204
205 float centerFade = smoothstep(0.015, 0.13, radius);
206 float blendAmount = EFFECT_MIX * centerFade * (0.92 + 0.08 * sin(t + radius * 5.0));
207 blendAmount *= 1.0 + 0.10 * clamp(amp_peak, 0.0, 1.0);
208 // Soft-light-style compositing keeps source detail while visibly layering the fold.
209 vec3 lowOverlay = 2.0 * original * treated;
210 vec3 highOverlay = 1.0 - 2.0 * (1.0 - original) * (1.0 - treated);
211 vec3 overlay = mix(lowOverlay, highOverlay, step(vec3(0.5), original));
212 vec3 layered = mix(treated, overlay, 0.24);
213 vec3 finalRGB = mix(original, layered, clamp(blendAmount, 0.0, 0.68));
214 color = vec4(clamp(finalRGB, 0.0, 1.0), texture(samp, tc).a);
215}
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.
float energy()
Evaluates energy for this shader effect.
vec2 mirrorUV(vec2 uv)
Evaluates mirrorUV for this shader effect.
vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect)
Evaluates rotateUV for this shader effect.
Definition aura2.frag:59
shared vec4 tile[10][10]
const int STYLE
const float SEGMENTS
const float EFFECT_MIX
vec2 kaleidoFold(vec2 uv, vec2 center, float aspect, float segments)
Evaluates kaleidoFold for this shader effect.
vec2 largeFractalFold(vec2 uv, vec2 center, float aspect, float t, float foldZoom, float seed, float bass, float mids)
#define PI
float diamond(vec2 p)
Evaluates diamond for this shader effect.
Definition dmd_gpt.frag:29
float lattice(vec2 point, float bass, float middle, float high)
Evaluates lattice for this shader effect.
vec3 sampleHQ(vec2 uv)
Evaluates sampleHQ for this shader effect.
const float DISTORTION
const float FOLD_ZOOM