ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
auraXi2.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file auraXi2.frag
5 * @brief Vulkan fragment shader: auraXi2.
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
40const float PI = 3.1415926535897932384626433832795;
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 luma for this shader effect.
55 * @param c Input value for the calculation.
56 * @return Computed float value.
57 */
58float luma(vec3 c){ return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
59
60/**
61 * @brief Evaluates hue for this shader effect.
62 * @param t Input value for the calculation.
63 * @return Computed vec3 value.
64 */
65vec3 hue(float t){
66 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);
67}
68
69/**
70 * @brief Evaluates rotateUV for this shader effect.
71 * @param uv Input value for the calculation.
72 * @param angle Input value for the calculation.
73 * @param c Input value for the calculation.
74 * @param aspect Input value for the calculation.
75 * @return Computed vec2 value.
76 */
77vec2 rotateUV(vec2 uv, float angle, vec2 c, float aspect){
78 float s = sin(angle), cc = cos(angle);
79 vec2 p = uv - c;
80 p.x *= aspect;
81 p = mat2(cc, -s, s, cc) * p;
82 p.x /= aspect;
83 return p + c;
84}
85
86/**
87 * @brief Evaluates rippleDisplace for this shader effect.
88 * @param uv Input value for the calculation.
89 * @param center Input value for the calculation.
90 * @param aspect Input value for the calculation.
91 * @param t Input value for the calculation.
92 * @param drive Input value for the calculation.
93 * @return Computed vec2 value.
94 */
95vec2 rippleDisplace(vec2 uv, vec2 center, float aspect, float t, float drive){
96 vec2 d = uv - center;
97 float dist = length(d);
98 vec2 dir = d / max(dist, 1e-6);
99 float baseWave = 0.055;
100 float baseAmp = 0.018;
101 float speed = 1.35;
102 vec3 tx = textureGrad(samp, uv, dFdx(uv), dFdy(uv)).rgb;
103 float waveLength = baseWave * (0.9 + 0.5*luma(tx));
104 float amplitude = baseAmp * (0.75 + 0.5*drive);
105 float ripple = sin((dist / max(waveLength,1e-4) - t * speed) * 6.2831853);
106 ripple *= smoothstep(0.95, 0.2, dist);
107 return uv + dir * ripple * amplitude;
108}
109
110/**
111 * @brief Evaluates spiralTwist for this shader effect.
112 * @param uv Input value for the calculation.
113 * @param center Input value for the calculation.
114 * @param aspect Input value for the calculation.
115 * @param t Input value for the calculation.
116 * @param drive Input value for the calculation.
117 * @return Computed vec2 value.
118 */
119vec2 spiralTwist(vec2 uv, vec2 center, float aspect, float t, float drive){
120 vec2 p = uv - center;
121 p.x *= aspect;
122 float r = length(p)+1e-6;
123 float a = atan(p.y, p.x);
124 float swirl = (0.55 + 0.5*drive) / (1.0 + 8.0*r);
125 float spin = (0.22 + 0.18*drive) * t;
126 a += spin + swirl;
127 float pull = 0.10 / (1.0 + 6.0*r);
128 r = max(r - pull, 0.0);
129 vec2 q = vec2(cos(a), sin(a)) * r;
130 q.x /= aspect;
131 return q + center;
132}
133
134/**
135 * @brief Evaluates spiralEcho for this shader effect.
136 * @param uv Input value for the calculation.
137 * @param center Input value for the calculation.
138 * @param aspect Input value for the calculation.
139 * @param t Input value for the calculation.
140 * @param drive Input value for the calculation.
141 * @return Computed vec3 value.
142 */
143vec3 spiralEcho(vec2 uv, vec2 center, float aspect, float t, float drive){
144 const int TAPS = 6;
145 vec3 acc = vec3(0.0);
146 float wsum = 0.0;
147 for(int i=0;i<TAPS;i++){
148 float k = float(i);
149 float radScale = 1.0 + 0.085*k;
150 float timeLag = 0.11*k;
151 vec2 u = spiralTwist(uv, center, aspect, t - timeLag, drive);
152 u = rotateUV(u, (0.12+0.04*drive)*k, center, aspect);
153 vec3 s = textureGrad(samp, fract(u / radScale), dFdx(uv), dFdy(uv)).rgb;
154 float w = 1.0 / (1.0 + 0.85*k);
155 acc += s * w;
156 wsum += w;
157 }
158 return acc / max(wsum, 1e-6);
159}
160
161/**
162 * @brief Evaluates reinhard for this shader effect.
163 * @param x Input value for the calculation.
164 * @return Computed vec3 value.
165 */
166vec3 reinhard(vec3 x){ return x/(1.0+x); }
167
168/**
169 * @brief Evaluates softLimit for this shader effect.
170 * @param c Input value for the calculation.
171 * @param maxY Input value for the calculation.
172 * @return Computed vec3 value.
173 */
174vec3 softLimit(vec3 c, float maxY){
175 float Y = luma(c);
176 if(Y > maxY) c *= maxY/(Y+1e-6);
177 return c;
178}
179
180/**
181 * @brief Executes the fragment shader entry point.
182 */
183void main(void){
184 vec2 mouseN = iMouse.xy / iResolution;
185 vec2 clickN = iMouseClick / iResolution;
186 bool hasClick = max(iMouseClick.x, iMouseClick.y) > 0.0;
187 vec2 center = (iMouse.z > 0.5) ? mouseN : (hasClick ? clickN : vec2(0.5));
188
189 float t = (time_f + iTime*0.6) + float(iFrame)*0.0003;
190 float aMix = clamp(amp*0.7 + uamp*0.3, 0.0, 12.0);
191 float drive = tanh(aMix*0.07);
192 float aspect = iResolution.x / iResolution.y;
193
194 vec2 uvRipple = rippleDisplace(tc, center, aspect, t, drive);
195 vec3 echoCol = spiralEcho(uvRipple, center, aspect, t, drive);
196
197 vec2 m = (iMouse.z > 0.0) ? (iMouse.xy / iResolution.xy) : vec2(0.5);
198 float a = time_f*0.45;
199 vec2 dir = normalize(vec2(cos(a), sin(a)));
200 float span = 0.22 + 0.10*sin(time_f*0.35);
201 vec2 startP = m - dir*span;
202 vec2 endP = m + dir*span;
203 vec2 ab = endP - startP;
204 float L = max(length(ab), 1e-4);
205 vec2 u = ab / L;
206 float gradT = clamp(dot(tc - startP, u) / L, 0.0, 1.0);
207 vec3 c0 = hue(fract(time_f*0.08));
208 vec3 c1 = hue(fract(time_f*0.08 + 0.5));
209 vec3 grad = mix(c0, c1, gradT);
210
211 vec3 tex = textureGrad(samp, uvRipple, dFdx(uvRipple), dFdy(uvRipple)).rgb;
212 vec3 mixed = mix(tex, echoCol, 0.6);
213 float colorMix = 0.55*clamp(amp, 0.0, 1.0);
214 mixed = mix(mixed, mixed * grad, colorMix);
215
216 float satAmt = 1.08 + 0.18*drive;
217 float Y = luma(mixed);
218 mixed = mix(vec3(Y), mixed, satAmt);
219
220 mixed *= 1.08 + 0.15*drive;
221 mixed = softLimit(mixed, 0.9);
222 mixed = reinhard(mixed);
223 mixed = pow(clamp(mixed,0.0,1.0), vec3(0.95));
224
225 color = vec4(mixed, 1.0);
226}
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
#define PI
vec2 spin(vec2 p, float a)
Evaluates spin for this shader effect.