ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
auraXi3.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file auraXi3.frag
5 * @brief Vulkan fragment shader: auraXi3.
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 ext.u1.y
18#define iFrame int(ext.u2.x)
19#define iMouse ext.mouse
20#define iMouseClick ext.mouse.xy
21#define iResolution ext.u0.zw
22#define iSampleRate ext.u2.z
23#define iTime ext.u0.y
24#define time_f ext.u2.y
25#define uamp ext.u1.y
26
27layout(location = 0) out vec4 color;
28layout(location = 0) in vec2 tc;
29layout(set = 0, binding = 0) uniform sampler2D samp;
30
31
32
33
34
35
36
37
38
39
40/**
41 * @brief Evaluates pingPong for this shader effect.
42 * @param x Input value for the calculation.
43 * @param length Input value for the calculation.
44 * @return Computed float value.
45 */
46float pingPong(float x, float length){
47 float m = mod(x, length*2.0);
48 return m <= length ? m : length*2.0 - m;
49}
50
51/**
52 * @brief Evaluates luma for this shader effect.
53 * @param c Input value for the calculation.
54 * @return Computed float value.
55 */
56float luma(vec3 c){ return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
57
58/**
59 * @brief Evaluates hue for this shader effect.
60 * @param t Input value for the calculation.
61 * @return Computed vec3 value.
62 */
63vec3 hue(float t){
64 return clamp(vec3(abs(t*6.0-3.0)-1.0, 2.0-abs(t*6.0-2.0), 2.0-abs(t*6.0-4.0)),0.0,1.0);
65}
66
67/**
68 * @brief Evaluates rotateUV for this shader effect.
69 * @param uv Input value for the calculation.
70 * @param angle Input value for the calculation.
71 * @param c Input value for the calculation.
72 * @param aspect Input value for the calculation.
73 * @return Computed vec2 value.
74 */
75vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect){
76 float s = sin(angle), cc = cos(angle);
77 vec2 p = uv - c;
78 p.x *= aspect;
79 p = mat2(cc, -s, s, cc) * p;
80 p.x /= aspect;
81 return p + c;
82}
83
84/**
85 * @brief Evaluates rippleDisplace for this shader effect.
86 * @param uv Input value for the calculation.
87 * @param center Input value for the calculation.
88 * @param aspect Input value for the calculation.
89 * @param t Input value for the calculation.
90 * @param drive Input value for the calculation.
91 * @return Computed vec2 value.
92 */
93vec2 rippleDisplace(vec2 uv, vec2 center, float aspect, float t, float drive){
94 vec2 d = uv - center;
95 float dist = length(d);
96 vec2 dir = d / max(dist, 1e-6);
97 float baseWave = 0.055;
98 float baseAmp = 0.018;
99 float speed = 1.2;
100 vec3 tx = textureGrad(samp, uv, dFdx(uv), dFdy(uv)).rgb;
101 float waveLength = baseWave * (0.9 + 0.5*luma(tx));
102 float amplitude = baseAmp * (0.75 + 0.5*drive);
103 float ripple = sin((dist / max(waveLength,1e-4) - t * speed) * 6.2831853);
104 ripple *= smoothstep(0.95, 0.22, dist);
105 return uv + dir * ripple * amplitude;
106}
107
108/**
109 * @brief Evaluates spiralTwist for this shader effect.
110 * @param uv Input value for the calculation.
111 * @param center Input value for the calculation.
112 * @param aspect Input value for the calculation.
113 * @param t Input value for the calculation.
114 * @param drive Input value for the calculation.
115 * @return Computed vec2 value.
116 */
117vec2 spiralTwist(vec2 uv, vec2 center, float aspect, float t, float drive){
118 vec2 p = uv - center;
119 p.x *= aspect;
120 float r = length(p)+1e-6;
121 float a = atan(p.y, p.x);
122 float swirl = (0.5 + 0.45*drive) / (1.0 + 8.0*r);
123 float spin = (0.18 + 0.16*drive) * t;
124 a += spin + swirl;
125 float pull = 0.09 / (1.0 + 6.0*r);
126 r = max(r - pull, 0.0);
127 vec2 q = vec2(cos(a), sin(a)) * r;
128 q.x /= aspect;
129 return q + center;
130}
131
132/**
133 * @brief Evaluates spiralEcho for this shader effect.
134 * @param uv Input value for the calculation.
135 * @param center Input value for the calculation.
136 * @param aspect Input value for the calculation.
137 * @param t Input value for the calculation.
138 * @param drive Input value for the calculation.
139 * @return Computed vec3 value.
140 */
141vec3 spiralEcho(vec2 uv, vec2 center, float aspect, float t, float drive){
142 const int TAPS = 6;
143 vec3 acc = vec3(0.0);
144 float wsum = 0.0;
145 for(int i=0;i<TAPS;i++){
146 float k = float(i);
147 float radScale = 1.0 + 0.085*k;
148 float timeLag = 0.11*k;
149 vec2 u = spiralTwist(uv, center, aspect, t - timeLag, drive);
150 u = rotateUV(u, (0.10+0.04*drive)*k, center, aspect);
151 vec3 s = textureGrad(samp, fract(u / radScale), dFdx(uv), dFdy(uv)).rgb;
152 float w = 1.0 / (1.0 + 0.85*k);
153 acc += s * w;
154 wsum += w;
155 }
156 return acc / max(wsum, 1e-6);
157}
158
159/**
160 * @brief Evaluates reinhard for this shader effect.
161 * @param x Input value for the calculation.
162 * @return Computed vec3 value.
163 */
164vec3 reinhard(vec3 x){ return x/(1.0+x); }
165
166/**
167 * @brief Evaluates softLimit for this shader effect.
168 * @param c Input value for the calculation.
169 * @param maxY Input value for the calculation.
170 * @return Computed vec3 value.
171 */
172vec3 softLimit(vec3 c, float maxY){
173 float Y = luma(c);
174 if(Y > maxY) c *= maxY/(Y+1e-6);
175 return c;
176}
177
178/**
179 * @brief Evaluates satBoost for this shader effect.
180 * @param c Input value for the calculation.
181 * @param s Input value for the calculation.
182 * @return Computed vec3 value.
183 */
184vec3 satBoost(vec3 c, float s){
185 float Y = luma(c);
186 return mix(vec3(Y), c, 1.0 + s);
187}
188
189/**
190 * @brief Executes the fragment shader entry point.
191 */
192void main(void){
193 vec2 mouseN = iMouse.xy / iResolution;
194 vec2 clickN = iMouseClick / iResolution;
195 bool hasClick = max(iMouseClick.x, iMouseClick.y) > 0.0;
196 vec2 center = (iMouse.z > 0.5) ? mouseN : (hasClick ? clickN : vec2(0.5));
197
198 float t = (time_f + iTime*0.6) + float(iFrame)*0.00025;
199 float aMix = clamp(amp*0.7 + uamp*0.3, 0.0, 12.0);
200 float drive = tanh(aMix*0.07);
201 float aspect = iResolution.x / iResolution.y;
202
203 vec2 uvRipple = rippleDisplace(tc, center, aspect, t, drive);
204 vec3 echoCol = spiralEcho(uvRipple, center, aspect, t, drive);
205 vec3 texCol = textureGrad(samp, uvRipple, dFdx(uvRipple), dFdy(uvRipple)).rgb;
206 vec3 mixed = mix(texCol, echoCol, 0.62);
207
208 float a = time_f*0.12;
209 vec2 dir = normalize(vec2(cos(a), sin(a)));
210 float span = 0.30;
211 vec2 startP = center - dir*span;
212 vec2 endP = center + dir*span;
213 vec2 ab = endP - startP;
214 float L = max(length(ab), 1e-4);
215 vec2 u = ab / L;
216 float g = clamp(dot(tc - startP, u) / L, 0.0, 1.0);
217
218 float slowHue = fract(0.08*time_f);
219 float slowHue2 = fract(0.08*time_f + 0.33);
220 vec3 g0 = hue(slowHue);
221 vec3 g1 = hue(slowHue2);
222 vec3 gradCol = mix(g0, g1, smoothstep(0.0,1.0,g));
223
224 float ring = smoothstep(0.9, 0.2, length((tc-center)*vec2(aspect,1.0)));
225 float colorAmt = 0.45 + 0.25*drive;
226 vec3 colored = mix(mixed, mixed*(gradCol*(0.85+0.15*ring)), colorAmt);
227
228 colored = satBoost(colored, 0.35 + 0.25*drive);
229 colored *= 1.08 + 0.12*drive;
230
231 colored = softLimit(colored, 0.88);
232 colored = reinhard(colored);
233 colored = pow(clamp(colored,0.0,1.0), vec3(0.96));
234
235 color = vec4(colored, 1.0);
236}
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 uamp
Definition abc.frag:21
#define amp
Definition abc.frag:17
vec3 ripple(ivec2 p, ivec2 size)
Evaluates ripple for this shader effect.
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
vec2 swirl(vec2 uv, float centerRadius, float swirlAmount)
Evaluates swirl for this shader effect.
vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect)
Evaluates rotateUV for this shader effect.
Definition aura2.frag:59
vec2 rippleDisplace(vec2 uv, vec2 center, float aspect, float t, float drive)
Evaluates rippleDisplace for this shader effect.
Definition auraXi1.frag:95
vec3 hue(float t)
Evaluates hue for this shader effect.
Definition auraXi1.frag:65
vec2 spiralTwist(vec2 uv, vec2 center, float aspect, float t, float drive)
Evaluates spiralTwist for this shader effect.
Definition auraXi1.frag:119
#define iMouseClick
Definition auraXi1.frag:20
float luma(vec3 c)
Evaluates luma for this shader effect.
Definition auraXi1.frag:58
vec3 spiralEcho(vec2 uv, vec2 center, float aspect, float t, float drive)
Evaluates spiralEcho for this shader effect.
Definition auraXi1.frag:143
#define iFrame
Definition auraXi1.frag:18
vec3 reinhard(vec3 x)
Evaluates reinhard for this shader effect.
Definition auraXi2.frag:166
vec3 softLimit(vec3 c, float maxY)
Evaluates softLimit for this shader effect.
Definition auraXi2.frag:174
vec3 satBoost(vec3 c, float s)
Evaluates satBoost for this shader effect.
Definition auraXi3.frag:184
vec2 spin(vec2 p, float a)
Evaluates spin for this shader effect.