ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
frac_star1.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file frac_star1.frag
5 * @brief Vulkan fragment shader: frac star1.
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
42const float PI = 3.1415926535897932384626433832795;
43
44/**
45 * @brief Evaluates hash1 for this shader effect.
46 * @param p Input value for the calculation.
47 * @return Computed float value.
48 */
49float hash1(vec2 p){ return fract(sin(dot(p, vec2(127.1,311.7))) * 43758.5453); }
50/**
51 * @brief Evaluates hash2 for this shader effect.
52 * @param p Input value for the calculation.
53 * @return Computed vec2 value.
54 */
55vec2 hash2(vec2 p){ return fract(sin(vec2(dot(p, vec2(127.1,311.7)), dot(p, vec2(269.5,183.3)))) * 43758.5453); }
56/**
57 * @brief Evaluates pingPong for this shader effect.
58 * @param x Input value for the calculation.
59 * @param l Input value for the calculation.
60 * @return Computed float value.
61 */
62float pingPong(float x,float l){ float m=mod(x,l*2.0); return m<=l?m:l*2.0-m; }
63
64/**
65 * @brief Evaluates hsv2rgb for this shader effect.
66 * @param c Input value for the calculation.
67 * @return Computed vec3 value.
68 */
69vec3 hsv2rgb(vec3 c){
70 vec4 K=vec4(1.0,2.0/3.0,1.0/3.0,3.0);
71 vec3 p=abs(fract(c.xxx+K.xyz)*6.0-K.www);
72 return c.z*mix(K.xxx,clamp(p-K.xxx,0.0,1.0),c.y);
73}
74/**
75 * @brief Evaluates neonPalette for this shader effect.
76 * @param t Input value for the calculation.
77 * @return Computed vec3 value.
78 */
79vec3 neonPalette(float t){
80 vec3 a=vec3(1.0,0.15,0.75), b=vec3(0.10,0.55,1.0), c=vec3(0.10,1.0,0.45);
81 float ph=fract(t*0.08);
82 vec3 k1=mix(a,b,smoothstep(0.00,0.33,ph));
83 vec3 k2=mix(b,c,smoothstep(0.33,0.66,ph));
84 vec3 k3=mix(c,a,smoothstep(0.66,1.00,ph));
85 float A=step(ph,0.33), B=step(0.33,ph)*step(ph,0.66), C=step(0.66,ph);
86 return normalize(A*k1+B*k2+C*k3)*1.05;
87}
88
89/**
90 * @brief Evaluates tentBlur3 for this shader effect.
91 * @param img Input value for the calculation.
92 * @param uv Input value for the calculation.
93 * @param res Input value for the calculation.
94 * @return Computed vec3 value.
95 */
96vec3 tentBlur3(sampler2D img, vec2 uv, vec2 res){
97 vec2 ts=1.0/res;
98 vec3 s00=textureGrad(img, uv+ts*vec2(-1,-1), dFdx(uv), dFdy(uv)).rgb;
99 vec3 s10=textureGrad(img, uv+ts*vec2( 0,-1), dFdx(uv), dFdy(uv)).rgb;
100 vec3 s20=textureGrad(img, uv+ts*vec2( 1,-1), dFdx(uv), dFdy(uv)).rgb;
101 vec3 s01=textureGrad(img, uv+ts*vec2(-1, 0), dFdx(uv), dFdy(uv)).rgb;
102 vec3 s11=textureGrad(img, uv, dFdx(uv), dFdy(uv)).rgb;
103 vec3 s21=textureGrad(img, uv+ts*vec2( 1, 0), dFdx(uv), dFdy(uv)).rgb;
104 vec3 s02=textureGrad(img, uv+ts*vec2(-1, 1), dFdx(uv), dFdy(uv)).rgb;
105 vec3 s12=textureGrad(img, uv+ts*vec2( 0, 1), dFdx(uv), dFdy(uv)).rgb;
106 vec3 s22=textureGrad(img, uv+ts*vec2( 1, 1), dFdx(uv), dFdy(uv)).rgb;
107 return (s00+2.0*s10+s20+2.0*s01+4.0*s11+2.0*s21+s02+2.0*s12+s22)/16.0;
108}
109/**
110 * @brief Evaluates softTone for this shader effect.
111 * @param c Input value for the calculation.
112 * @return Computed vec3 value.
113 */
114vec3 softTone(vec3 c){
115 c=pow(max(c,0.0), vec3(0.95));
116 float l=dot(c, vec3(0.299,0.587,0.114));
117 c=mix(vec3(l), c, 0.9);
118 return clamp(c,0.0,1.0);
119}
120
121/**
122 * @brief Evaluates sitePos for this shader effect.
123 * @param id Input value for the calculation.
124 * @param grid Input value for the calculation.
125 * @return Computed vec2 value.
126 */
127vec2 sitePos(vec2 id, float grid){
128 vec2 j=(hash2(id)*2.0-1.0)*(0.33+0.10*sin(time_f*0.37+6.2831*hash1(id+3.71)));
129 return (id+0.5+j)/grid;
130}
131
132/**
133 * @brief Evaluates starMetric for this shader effect.
134 * @param d Input value for the calculation.
135 * @param n Input value for the calculation.
136 * @param amp Input value for the calculation.
137 * @return Computed float value.
138 */
139float starMetric(vec2 d, float n, float amp){
140 float ang=atan(d.y,d.x);
141 float r=length(d);
142 float mod=1.0+amp*cos(n*ang);
143 return r/max(0.001,mod);
144}
145
146/**
147 * @brief Executes the fragment shader entry point.
148 */
149void main(){
150 vec2 res=iResolution;
151 float aspect=res.x/res.y;
152 vec2 focus=(iMouse.z>0.5)?(iMouse.xy/res):vec2(0.5);
153
154 float t=pingPong(time_f*0.35,1.0);
155 float zoom=mix(0.7,2.6,t);
156 vec2 uvZ=(tc-focus)*zoom+focus;
157
158 float grid=mix(18.0,28.0,0.5+0.5*sin(time_f*0.11));
159
160 vec2 gtc=uvZ*grid;
161 vec2 gid0=floor(gtc);
162
163 float best1=1e9,best2=1e9;
164 vec2 bestId=vec2(0.0), bestSite=vec2(0.0);
165 float bestN=7.0, bestA=0.3;
166
167 for(int j=-1;j<=1;j++){
168 for(int i=-1;i<=1;i++){
169 vec2 nid=gid0+vec2(i,j);
170 vec2 s=sitePos(nid,grid);
171 vec2 d=uvZ-s; d.x*=aspect;
172 float nPts=floor(7.0+5.0*hash1(nid+7.7));
173 float amp=0.28+0.22*hash1(nid+4.2);
174 float dist=starMetric(d,nPts,amp);
175 if(dist<best1){
176 best2=best1;
177 best1=dist;
178 bestId=nid;
179 bestSite=s;
180 bestN=nPts;
181 bestA=amp;
182 }else if(dist<best2){
183 best2=dist;
184 }
185 }
186 }
187
188 float edge=0.5*(best2-best1);
189 float px=1.0/min(res.x,res.y);
190 float border=1.0-smoothstep(px*0.75, px*0.75+fwidth(edge), edge);
191
192 vec2 rel=uvZ-bestSite; rel.x*=aspect;
193
194 float rot=6.2831853*hash1(bestId+11.9)+time_f*(0.10+0.08*hash1(bestId+2.2));
195 float cs=cos(rot), sn=sin(rot);
196 vec2 rrel=mat2(cs,-sn,sn,cs)*rel;
197
198 vec2 pieceUV=rrel; pieceUV.x/=aspect; pieceUV+=bestSite;
199
200 vec4 texCol=texture(samp,pieceUV);
201
202 float ang=atan(rrel.y,rrel.x);
203 float flare=pow(0.5+0.5*cos(bestN*ang+time_f*0.7+6.2831*hash1(bestId+3.4)),3.0);
204 vec3 glow=hsv2rgb(vec3(fract(hash1(bestId+9.3)+time_f*0.05),0.85,1.0));
205 vec3 neon=neonPalette(time_f+hash1(bestId+1.1)*8.0);
206 vec3 tint=mix(neon,glow,0.45)*(0.55+0.45*flare);
207 float rad=length(rrel);
208 float vign=smoothstep(0.9,0.2,rad/(0.55+0.05*sin(time_f*0.5+hash1(bestId+5.5))));
209 vec3 pieceCol=mix(texCol.rgb, texCol.rgb*tint, 0.25*vign);
210
211 vec3 pre=tentBlur3(samp, tc, res);
212 vec3 inside=mix(pre, pieceCol, 0.85);
213
214 vec3 borderCol=mix(vec3(0.02,0.02,0.03), neonPalette(time_f*0.5), 0.15);
215 vec3 outRGB=mix(inside, sin(borderCol * (time_f * PI)), border);
216 outRGB=softTone(outRGB);
217
218
219 // --- Audio Reactivity: direct output modulation ---
220 float _ab = clamp(amp_peak, 0.0, 1.0);
221 float _abass = clamp(amp_low, 0.0, 1.0);
222 outRGB *= 1.0 + _ab * 0.6;
223 outRGB = mix(outRGB, outRGB * vec3(1.0 + _abass * 0.3, 1.0 - _abass * 0.15, 1.0 + clamp(amp_high, 0.0, 1.0) * 0.25), _ab);
224 // --- End Audio Reactivity ---
225
226 color=vec4(outRGB, texCol.a);
227}
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
Definition abc.frag:17
#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 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
vec2 hash2(vec2 p)
Evaluates hash2 for this shader effect.
vec3 neon(float t)
Evaluates neon for this shader effect.
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
vec3 softTone(vec3 c)
Evaluates softTone for this shader effect.
Definition aura2.frag:131
vec3 hsv2rgb(vec3 c)
Evaluates hsv2rgb for this shader effect.
Definition aura.frag:43
float n(vec2 p)
Evaluates n for this shader effect.
vec4 C(int i, vec2 u)
Evaluates C for this shader effect.
#define PI
float hash1(float n)
Evaluates hash1 for this shader effect.
vec2 sitePos(vec2 id, float grid)
Evaluates sitePos for this shader effect.
float starMetric(vec2 d, float n, float amp)
Evaluates starMetric for this shader effect.