ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
frac_shader04_julia.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file frac_shader04_julia.frag
5 * @brief Vulkan fragment shader: frac shader04 julia.
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/**
43 * @brief Evaluates pingPong for this shader effect.
44 * @param x Input value for the calculation.
45 * @param length Input value for the calculation.
46 * @return Computed float value.
47 */
48float pingPong(float x, float length){
49 float m = mod(x, length*2.0);
50 return m <= length ? m : length*2.0 - m;
51}
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 c 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 c, float aspect){
62 float s = sin(angle), cc = cos(angle);
63 vec2 p = uv - c;
64 p.x *= aspect;
65 p = mat2(cc, -s, s, cc) * p;
66 p.x /= aspect;
67 return p + c;
68}
69
70/**
71 * @brief Evaluates hsv2rgb for this shader effect.
72 * @param c Input value for the calculation.
73 * @return Computed vec3 value.
74 */
75vec3 hsv2rgb(vec3 c){
76 vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
77 vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
78 return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
79}
80
81/**
82 * @brief Evaluates movingGradient for this shader effect.
83 * @param uv Input value for the calculation.
84 * @param c Input value for the calculation.
85 * @param t Input value for the calculation.
86 * @param aspect Input value for the calculation.
87 * @return Computed vec3 value.
88 */
89vec3 movingGradient(vec2 uv, vec2 c, float t, float aspect){
90 vec2 ar = vec2(aspect, 1.0);
91 vec2 p = (uv - c) * ar;
92 vec2 d = normalize(vec2(cos(t*0.27), sin(t*0.31)));
93 float s = dot(p, d);
94 float band = 0.5 + 0.5*sin(s*6.28318530718*0.35 + t*0.9);
95 float h = fract(s*0.22 + t*0.07 + 0.15*sin(t*0.33));
96 float S = 0.75 + 0.25*sin(t*0.21 + s*2.0);
97 float V = 0.75 + 0.25*band;
98 vec3 base = hsv2rgb(vec3(h, S, V));
99 float edge = smoothstep(0.2, 0.8, band);
100 return mix(base*0.6, base, edge);
101}
102
103/**
104 * @brief Evaluates rot2 for this shader effect.
105 * @param a Input value for the calculation.
106 * @return Computed mat2 value.
107 */
108mat2 rot2(float a){ float s=sin(a), c=cos(a); return mat2(c,-s,s,c); }
109
110/**
111 * @brief Evaluates juliaEval for this shader effect.
112 * @param z0 Input value for the calculation.
113 * @param cJ Input value for the calculation.
114 * @param[out] iterCount Output value produced by the calculation.
115 * @param[out] smoothIter Output value produced by the calculation.
116 * @param[out] orbitTrapVal Output value produced by the calculation.
117 */
118void juliaEval(vec2 z0, vec2 cJ, out float iterCount, out float smoothIter, out float orbitTrapVal){
119 vec2 z = z0;
120 float i = 0.0;
121 orbitTrapVal = 1e9;
122 const int MAX_IT = 120;
123 for(int k=0;k<MAX_IT;k++){
124 orbitTrapVal = min(orbitTrapVal, length(z));
125 vec2 z2 = vec2(z.x*z.x - z.y*z.y, 2.0*z.x*z.y) + cJ;
126 z = z2;
127 i += 1.0;
128 if(dot(z,z) > 256.0) break;
129 }
130 float rl = length(z);
131 smoothIter = i - log2(max(0.000001, log(max(rl, 1e-6))));
132 iterCount = i;
133}
134
135/**
136 * @brief Evaluates juliaScore for this shader effect.
137 * @param z0 Input value for the calculation.
138 * @param cJ Input value for the calculation.
139 * @return Computed float value.
140 */
141float juliaScore(vec2 z0, vec2 cJ){
142 vec2 z = z0;
143 const int MAX_S = 28;
144 float i = 0.0;
145 for(int k=0;k<MAX_S;k++){
146 vec2 z2 = vec2(z.x*z.x - z.y*z.y, 2.0*z.x*z.y) + cJ;
147 z = z2;
148 i += 1.0;
149 if(dot(z,z) > 256.0) break;
150 }
151 float rl = length(z);
152 float sI = i - log2(max(0.000001, log(max(rl, 1e-6))));
153 float tgt = 18.0;
154 float score = 1.0/(1.0 + abs(sI - tgt));
155 return score;
156}
157
158/**
159 * @brief Evaluates findAnchor for this shader effect.
160 * @param base Input value for the calculation.
161 * @param cJ Input value for the calculation.
162 * @param rad Input value for the calculation.
163 * @return Computed vec2 value.
164 */
165vec2 findAnchor(vec2 base, vec2 cJ, float rad){
166 float best = -1.0;
167 vec2 bestOff = vec2(0.0);
168 for(int k=0;k<8;k++){
169 float a = (6.28318530718/8.0)*float(k) + time_f*0.11;
170 vec2 off = vec2(cos(a), sin(a)) * rad;
171 float s = juliaScore(base + off, cJ);
172 if(s > best){ best = s; bestOff = off; }
173 }
174 return bestOff;
175}
176
177/**
178 * @brief Executes the fragment shader entry point.
179 */
180void main(){
181 float aspect = iResolution.x / iResolution.y;
182 vec2 ar = vec2(aspect, 1.0);
183 vec2 m = (iMouse.z > 0.5) ? (iMouse.xy / iResolution) : vec2(0.5);
184 vec2 uv = tc;
185 vec4 originalTexture = texture(samp, tc);
186
187 float t = time_f;
188 float zoomSpeed = 0.28;
189 float spin = 0.23;
190 float scale = exp(-t * zoomSpeed);
191 vec2 p = (uv - m) * ar;
192 p = rot2(t*spin) * p;
193
194 vec2 cJ = (iMouse.z > 0.5)
195 ? ((iMouse.xy/iResolution)*2.0-1.0) * vec2(aspect,1.0) * 0.6
196 : vec2(0.285 + 0.15*sin(t*0.17), 0.01 + 0.15*cos(t*0.21));
197
198 float probeRad = 0.75 * scale;
199 vec2 anchor = findAnchor(vec2(0.0), cJ, probeRad);
200 vec2 z0 = (p + anchor) * scale * 2.0;
201
202 float iterCount, smoothIter, orbitTrapVal;
203 juliaEval(z0, cJ, iterCount, smoothIter, orbitTrapVal);
204
205 float rD = length(p);
206 float hue = fract(0.12*smoothIter + 0.07*t + 0.15*sin(orbitTrapVal*3.0));
207 float sat = 0.65 + 0.25*sin(0.7*t + orbitTrapVal*5.0);
208 float val = 0.80 + 0.20*sin(0.9*t + smoothIter*0.35);
209 vec3 tint = hsv2rgb(vec3(hue, sat, val));
210
211 float ring = smoothstep(0.0, 0.7, sin(log(rD*scale+1e-3)*9.5 + t*1.2));
212 float pulse = 0.5 + 0.5*sin(t*2.0 + rD*28.0 + smoothIter*0.6);
213
214 float vign = 1.0 - smoothstep(0.75, 1.2, length((tc - m)*ar));
215 vign = mix(0.85, 1.2, vign);
216
217 vec2 pr = z0;
218 vec2 dir = normalize(pr + 1e-6);
219 vec2 off = dir * (0.0015 + 0.001 * sin(t*1.3)) * vec2(1.0, 1.0/aspect);
220
221 vec2 u0 = fract(pr/ar + m);
222 vec2 u1 = fract((pr*1.045)/ar + m);
223 vec2 u2 = fract((pr*0.955)/ar + m);
224
225 float rC = texture(samp, u0 + off).r;
226 float gC = texture(samp, u1).g;
227 float bC = texture(samp, u2 - off).b;
228 vec3 texRGB = vec3(rC, gC, bC);
229
230 float shade = smoothstep(0.0, 1.0, 1.0 - clamp(orbitTrapVal*0.5, 0.0, 1.0));
231 vec3 fractRGB = mix(texRGB, texRGB*tint, 0.65) * mix(0.7, 1.25, shade);
232 vec4 fractalColor = vec4(fractRGB * tint, 1.0);
233
234 float blendFactor = 0.58;
235 vec4 merged = mix(fractalColor, originalTexture, blendFactor);
236 merged.rgb *= (0.75 + 0.25*ring) * (0.85 + 0.15*pulse) * vign;
237
238 vec3 bloom = merged.rgb * merged.rgb * 0.18 + pow(max(merged.rgb-0.6,0.0), vec3(2.0))*0.12;
239 vec3 outCol = merged.rgb + bloom;
240
241 float wob = 0.9 + 0.1*sin(t + rD*14.0 + smoothIter*0.5);
242 outCol *= wob;
243
244 vec3 grad = movingGradient(tc, m, t, aspect);
245 float gradAmt = 0.35 + 0.25*sin(t*0.5 + rD*7.0 + smoothIter*0.35);
246 vec3 screenBlend = 1.0 - (1.0 - outCol) * (1.0 - grad);
247 outCol = mix(outCol, screenBlend, gradAmt);
248
249 vec4 tcol = texture(samp, tc);
250 outCol = mix(outCol, outCol*tcol.rgb, 0.8);
251
252 outCol = sin(outCol * (0.5 + 0.5*pingPong(t, 12.0)));
253 outCol = clamp(outCol, vec3(0.08), vec3(0.96));
254
255
256 // --- Audio Reactivity: direct output modulation ---
257 float _ab = clamp(amp_peak, 0.0, 1.0);
258 float _abass = clamp(amp_low, 0.0, 1.0);
259 outCol *= 1.0 + _ab * 0.6;
260 outCol = mix(outCol, outCol * vec3(1.0 + _abass * 0.3, 1.0 - _abass * 0.15, 1.0 + clamp(amp_high, 0.0, 1.0) * 0.25), _ab);
261 // --- End Audio Reactivity ---
262
263 color = vec4(outCol, 1.0);
264}
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_low
#define amp_high
#define amp_peak
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
vec2 rot2(vec2 p, float a)
Evaluates rot2 for this shader effect.
vec3 bloom(float t)
Evaluates bloom 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 hue(float t)
Evaluates hue for this shader effect.
Definition auraXi1.frag:65
vec3 hsv2rgb(vec3 c)
Evaluates hsv2rgb for this shader effect.
Definition aura.frag:43
float sat(float x)
Evaluates sat for this shader effect.
Definition blue_2.frag:52
vec3 screenBlend(vec3 a, vec3 b)
Evaluates screenBlend for this shader effect.
float h(vec2 p)
Evaluates h for this shader effect.
float V(vec2 p, out vec2 id)
Evaluates V for this shader effect.
float S(int i, float f)
Evaluates S for this shader effect.
vec4 fractalColor(vec2 uv)
Evaluates fractalColor for this shader effect.
Definition deeps1.frag:66
vec3 movingGradient(vec2 uv, vec2 c, float t, float aspect)
Evaluates movingGradient for this shader effect.
vec2 findAnchor(vec2 base, vec2 cJ, float rad)
Evaluates findAnchor for this shader effect.
float juliaScore(vec2 z0, vec2 cJ)
Evaluates juliaScore for this shader effect.
void juliaEval(vec2 z0, vec2 cJ, out float iterCount, out float smoothIter, out float orbitTrapVal)
Evaluates juliaEval for this shader effect.
vec3 shade(vec3 albedo, vec3 n, vec2 p, float rough)
Evaluates shade for this shader effect.
vec2 spin(vec2 p, float a)
Evaluates spin for this shader effect.