ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
aura2.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file aura2.frag
5 * @brief Vulkan fragment shader: aura2.
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 iMouse ext.mouse
18#define iResolution ext.u0.zw
19#define time_f ext.u2.y
20
21layout(location = 0) out vec4 color;
22layout(location = 0) in vec2 tc;
23layout(set = 0, binding = 0) uniform sampler2D samp;
24
25
26
27const float PI = 3.1415926535897932384626433832795;
28
29/**
30 * @brief Evaluates pingPong for this shader effect.
31 * @param x Input value for the calculation.
32 * @param length Input value for the calculation.
33 * @return Computed float value.
34 */
35float pingPong(float x, float length){
36 float m = mod(x, length*2.0);
37 return m <= length ? m : length*2.0 - m;
38}
39
40/**
41 * @brief Evaluates hsv2rgb for this shader effect.
42 * @param c Input value for the calculation.
43 * @return Computed vec3 value.
44 */
45vec3 hsv2rgb(vec3 c){
46 vec4 K=vec4(1.0,2.0/3.0,1.0/3.0,3.0);
47 vec3 p=abs(fract(c.xxx+K.xyz)*6.0-K.www);
48 return c.z*mix(K.xxx,clamp(p-K.xxx,0.0,1.0),c.y);
49}
50
51/**
52 * @brief Evaluates rotateUV for this shader effect.
53 * @param uv Input value for the calculation.
54 * @param angle Input value for the calculation.
55 * @param c Input value for the calculation.
56 * @param aspect Input value for the calculation.
57 * @return Computed vec2 value.
58 */
59vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect){
60 float s = sin(angle), cc = cos(angle);
61 vec2 p = uv - c;
62 p.x *= aspect;
63 p = mat2(cc, -s, s, cc) * p;
64 p.x /= aspect;
65 return p + c;
66}
67
68/**
69 * @brief Evaluates reflectUV for this shader effect.
70 * @param uv Input value for the calculation.
71 * @param segments Input value for the calculation.
72 * @param c Input value for the calculation.
73 * @param aspect Input value for the calculation.
74 * @return Computed vec2 value.
75 */
76vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect){
77 vec2 p = uv - c;
78 p.x *= aspect;
79 float ang = atan(p.y, p.x);
80 float rad = length(p);
81 float stepA = 6.28318530718 / segments;
82 ang = mod(ang, stepA);
83 ang = abs(ang - stepA * 0.5);
84 vec2 r = vec2(cos(ang), sin(ang)) * rad;
85 r.x /= aspect;
86 return r + c;
87}
88
89/**
90 * @brief Evaluates fractalFold for this shader effect.
91 * @param uv Input value for the calculation.
92 * @param zoom Input value for the calculation.
93 * @param t Input value for the calculation.
94 * @param c Input value for the calculation.
95 * @param aspect Input value for the calculation.
96 * @return Computed vec2 value.
97 */
98vec2 fractalFold(vec2 uv, float zoom, float t, vec2 c, float aspect){
99 vec2 p = uv;
100 for(int i=0;i<6;i++){
101 p = abs((p - c) * (zoom + 0.15*sin(t*0.35+float(i)))) - 0.5 + c;
102 p = rotateUV(p, t*0.12 + float(i)*0.07, c, aspect);
103 }
104 return p;
105}
106
107/**
108 * @brief Evaluates neonPalette for this shader effect.
109 * @param t Input value for the calculation.
110 * @return Computed vec3 value.
111 */
112vec3 neonPalette(float t){
113 vec3 pink = vec3(1.0, 0.15, 0.75);
114 vec3 blue = vec3(0.10, 0.55, 1.0);
115 vec3 green = vec3(0.10, 1.00, 0.45);
116 float ph = fract(t*0.08);
117 vec3 k1 = mix(pink, blue, smoothstep(0.00, 0.33, ph));
118 vec3 k2 = mix(blue, green, smoothstep(0.33, 0.66, ph));
119 vec3 k3 = mix(green, pink, smoothstep(0.66, 1.00, ph));
120 float a = step(ph, 0.33);
121 float b = step(0.33, ph) * step(ph, 0.66);
122 float c = step(0.66, ph);
123 return normalize(a*k1 + b*k2 + c*k3) * 1.05;
124}
125
126/**
127 * @brief Evaluates softTone for this shader effect.
128 * @param c Input value for the calculation.
129 * @return Computed vec3 value.
130 */
131vec3 softTone(vec3 c){
132 c = pow(max(c, 0.0), vec3(0.95));
133 float l = dot(c, vec3(0.299,0.587,0.114));
134 c = mix(vec3(l), c, 0.9);
135 return clamp(c, 0.0, 1.0);
136}
137
138/**
139 * @brief Evaluates tentBlur3 for this shader effect.
140 * @param img Input value for the calculation.
141 * @param uv Input value for the calculation.
142 * @param res Input value for the calculation.
143 * @return Computed vec3 value.
144 */
145vec3 tentBlur3(sampler2D img, vec2 uv, vec2 res){
146 vec2 ts = 1.0 / res;
147 vec3 s00 = textureGrad(img, uv + ts*vec2(-1.0,-1.0), dFdx(uv), dFdy(uv)).rgb;
148 vec3 s10 = textureGrad(img, uv + ts*vec2( 0.0,-1.0), dFdx(uv), dFdy(uv)).rgb;
149 vec3 s20 = textureGrad(img, uv + ts*vec2( 1.0,-1.0), dFdx(uv), dFdy(uv)).rgb;
150 vec3 s01 = textureGrad(img, uv + ts*vec2(-1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
151 vec3 s11 = textureGrad(img, uv, dFdx(uv), dFdy(uv)).rgb;
152 vec3 s21 = textureGrad(img, uv + ts*vec2( 1.0, 0.0), dFdx(uv), dFdy(uv)).rgb;
153 vec3 s02 = textureGrad(img, uv + ts*vec2(-1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
154 vec3 s12 = textureGrad(img, uv + ts*vec2( 0.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
155 vec3 s22 = textureGrad(img, uv + ts*vec2( 1.0, 1.0), dFdx(uv), dFdy(uv)).rgb;
156 return (s00 + 2.0*s10 + s20 + 2.0*s01 + 4.0*s11 + 2.0*s21 + s02 + 2.0*s12 + s22) / 16.0;
157}
158
159/**
160 * @brief Evaluates preBlendColor for this shader effect.
161 * @param uv Input value for the calculation.
162 * @return Computed vec3 value.
163 */
164vec3 preBlendColor(vec2 uv){
165 vec3 tex = tentBlur3(samp, uv, iResolution);
166 vec2 gdir = normalize(vec2(cos(time_f*0.27), sin(time_f*0.31)));
167 float s = dot((uv-0.5)*vec2(iResolution.x/iResolution.y,1.0), gdir);
168 float w = max(fwidth(s)*4.0, 0.002);
169 float band = smoothstep(-0.5-w, -0.5+w, sin(s*2.2 + time_f*0.9));
170 vec3 neon = neonPalette(time_f);
171 vec3 grad = mix(tex, mix(tex, neon, 0.6), 0.35 + 0.25*band);
172 grad = mix(grad, tex, 0.10);
173 grad = softTone(grad);
174 return grad;
175}
176
177/**
178 * @brief Evaluates diamondRadius for this shader effect.
179 * @param p Input value for the calculation.
180 * @return Computed float value.
181 */
182float diamondRadius(vec2 p){
183 p = abs(p);
184 return max(p.x, p.y);
185}
186
187/**
188 * @brief Evaluates diamondFold for this shader effect.
189 * @param uv Input value for the calculation.
190 * @param c Input value for the calculation.
191 * @param aspect Input value for the calculation.
192 * @return Computed vec2 value.
193 */
194vec2 diamondFold(vec2 uv, vec2 c, float aspect){
195 vec2 p = (uv - c) * vec2(aspect, 1.0);
196 p = abs(p);
197 if(p.y > p.x) p = p.yx;
198 p.x /= aspect;
199 return p + c;
200}
201
202/**
203 * @brief Executes the fragment shader entry point.
204 */
205void main(void){
206 vec4 baseTex = texture(samp, tc);
207
208 vec2 uv = tc * 2.0 - 1.0;
209 uv.x *= iResolution.x / iResolution.y;
210 float radius = mix(0.8, 1.2, 0.5 + 0.5 * sin(time_f * 1.3));
211 radius *= 2.0;
212 float r = length(uv);
213 float glow = smoothstep(radius, radius - 0.25, r);
214
215 float aspect = iResolution.x / iResolution.y;
216 vec2 m = (iMouse.z > 0.5) ? (iMouse.xy / iResolution) : vec2(0.5);
217 vec2 ar = vec2(aspect, 1.0);
218
219 vec3 baseCol = preBlendColor(tc);
220
221 float seg = 4.0 + 2.0*sin(time_f*0.33);
222 vec2 kUV = reflectUV(tc, seg, m, aspect);
223 kUV = diamondFold(kUV, m, aspect);
224 float foldZoom = 1.45 + 0.55 * sin(time_f * 0.42);
225 kUV = fractalFold(kUV, foldZoom, time_f, m, aspect);
226 kUV = rotateUV(kUV, time_f * 0.23, m, aspect);
227 kUV = diamondFold(kUV, m, aspect);
228
229 vec2 p = (kUV - m) * ar;
230 vec2 q = abs(p); if(q.y > q.x) q = q.yx;
231
232 float base = 1.82 + 0.18*sin(time_f*0.2);
233 float period = log(base);
234 float tz = time_f * 0.65;
235 float rD = diamondRadius(p) + 1e-6;
236 float ang = atan(q.y, q.x) + tz * 0.35 + 0.35*sin(rD*18.0 + time_f*0.6);
237 float k = fract((log(rD) - tz) / period);
238 float rw = exp(k * period);
239 vec2 pwrap = vec2(cos(ang), sin(ang)) * rw;
240
241 vec2 u0 = fract(pwrap / ar + m);
242 vec2 u1 = fract((pwrap*1.045) / ar + m);
243 vec2 u2 = fract((pwrap*0.955) / ar + m);
244
245 vec2 dir = normalize(pwrap + 1e-6);
246 vec2 off = dir * (0.0015 + 0.001 * sin(time_f*1.3)) * vec2(1.0, 1.0/aspect);
247
248 float vign = 1.0 - smoothstep(0.75, 1.2, length((tc - m)*ar));
249 vign = mix(0.9, 1.15, vign);
250
251 vec3 rC = preBlendColor(u0 + off);
252 vec3 gC = preBlendColor(u1);
253 vec3 bC = preBlendColor(u2 - off);
254 vec3 kaleidoRGB = vec3(rC.r, gC.g, bC.b);
255
256 float ring = smoothstep(0.0, 0.7, sin(log(rD+1e-3)*9.5 + time_f*1.2));
257 float pulse = 0.5 + 0.5*sin(time_f*2.0 + rD*28.0 + k*12.0);
258
259 vec3 outCol = kaleidoRGB;
260 outCol *= (0.75 + 0.25*ring) * (0.85 + 0.15*pulse) * vign;
261 vec3 bloom = outCol*outCol*0.18 + pow(max(outCol-0.6,0.0), vec3(2.0))*0.12;
262 outCol += bloom;
263 outCol = mix(outCol, baseCol, 0.18);
264 outCol = clamp(outCol, vec3(0.05), vec3(0.97));
265
266 vec3 finalRGB = mix(baseTex.rgb, outCol, pingPong(glow * PI, 5.0) * 0.8);
267 color = vec4(finalRGB, baseTex.a);
268}
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
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
vec2 fractalFold(vec2 p, float zoom, float t, int i)
Evaluates fractalFold for this shader effect.
vec3 neon(float t)
Evaluates neon for this shader effect.
vec3 bloom(float t)
Evaluates bloom 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
vec3 neonPalette(float t)
Evaluates neonPalette for this shader effect.
Definition aura2.frag:112
vec2 reflectUV(vec2 uv, float segments, vec2 c, float aspect)
Evaluates reflectUV for this shader effect.
Definition aura2.frag:76
vec3 softTone(vec3 c)
Evaluates softTone for this shader effect.
Definition aura2.frag:131
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
vec3 hsv2rgb(vec3 c)
Evaluates hsv2rgb for this shader effect.
Definition aura.frag:43
#define PI