ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
frac_shader_dmd4_glass.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file frac_shader_dmd4_glass.frag
5 * @brief Vulkan fragment shader: frac shader dmd4 glass.
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
43const float PI = 3.1415926535897932384626433832795;
44
45/**
46 * @brief Evaluates pingPong for this shader effect.
47 * @param x Input value for the calculation.
48 * @param length Input value for the calculation.
49 * @return Computed float value.
50 */
51float pingPong(float x, float length) {
52 float m = mod(x, length * 2.0);
53 return m <= length ? m : length * 2.0 - m;
54}
55
56/**
57 * @brief Evaluates hash21 for this shader effect.
58 * @param p Input value for the calculation.
59 * @return Computed float value.
60 */
61float hash21(vec2 p){
62 p=fract(p*vec2(123.34,456.21));
63 p+=dot(p,p+45.32);
64 return fract(p.x*p.y);
65}
66
67/**
68 * @brief Evaluates hash22 for this shader effect.
69 * @param p Input value for the calculation.
70 * @return Computed vec2 value.
71 */
72vec2 hash22(vec2 p){
73 float n=hash21(p);
74 float m=hash21(p+17.7);
75 return vec2(n,m);
76}
77
78/**
79 * @brief Evaluates hsv2rgb for this shader effect.
80 * @param c Input value for the calculation.
81 * @return Computed vec3 value.
82 */
83vec3 hsv2rgb(vec3 c){
84 vec4 K=vec4(1.0,2.0/3.0,1.0/3.0,3.0);
85 vec3 p=abs(fract(c.xxx+K.xyz)*6.0-K.www);
86 return c.z*mix(K.xxx,clamp(p-K.xxx,0.0,1.0),c.y);
87}
88
89/**
90 * @brief Evaluates n2 for this shader effect.
91 * @param p Input value for the calculation.
92 * @return Computed float value.
93 */
94float n2(vec2 p){
95 vec2 i=floor(p),f=fract(p);
96 vec2 u=f*f*(3.0-2.0*f);
97 float a=hash21(i);
98 float b=hash21(i+vec2(1,0));
99 float c=hash21(i+vec2(0,1));
100 float d=hash21(i+vec2(1,1));
101 return mix(mix(a,b,u.x),mix(c,d,u.x),u.y);
102}
103
104/**
105 * @brief Evaluates fbm for this shader effect.
106 * @param p Input value for the calculation.
107 * @return Computed float value.
108 */
109float fbm(vec2 p){
110 float s=0.0,a=0.5;
111 for(int i=0;i<5;i++){
112 s+=a*n2(p); p*=2.02; a*=0.5;
113 }
114 return s;
115}
116
117struct VOut{ float d; vec2 id; vec2 gv; vec2 nearest; };
118/**
119 * @brief Evaluates voronoi for this shader effect.
120 * @param p Input value for the calculation.
121 * @return Computed VOut value.
122 */
123VOut voronoi(vec2 p){
124 vec2 i=floor(p), f=fract(p);
125 float md=1e9; vec2 mid=vec2(0.0), mcell=vec2(0.0), mpt=vec2(0.0);
126 for(int y=-1;y<=1;y++){
127 for(int x=-1;x<=1;x++){
128 vec2 g=vec2(x,y);
129 vec2 id=i+g;
130 vec2 rnd=hash22(id);
131 vec2 o=sin((rnd*2.0-1.0)*6.28318 + vec2(time_f*0.35, time_f*0.27))*0.25 + rnd*0.5;
132 vec2 r=g+o-f;
133 float d=dot(r,r);
134 if(d<md){md=d; mid=id; mcell=g; mpt=r;}
135 }
136 }
137 float edge=1e9;
138 for(int y=-1;y<=1;y++){
139 for(int x=-1;x<=1;x++){
140 vec2 g=vec2(x,y);
141 if(all(equal(g,mcell))) continue;
142 vec2 id=i+g;
143 vec2 rnd=hash22(id);
144 vec2 o=sin((rnd*2.0-1.0)*6.28318 + vec2(time_f*0.35, time_f*0.27))*0.25 + rnd*0.5;
145 vec2 r=g+o-f;
146 vec2 dif=0.5*(mpt+r);
147 float d=(dot(dif,dif)-dot(0.5*(r-mpt),0.5*(r-mpt)))/max(length(dif),1e-4);
148 edge=min(edge,abs(d));
149 }
150 }
151 VOut v; v.d=sqrt(md); v.id=mid; v.gv=f; v.nearest=mpt; return VOut(edge,mid,f,mpt);
152}
153
154/**
155 * @brief Executes the fragment shader entry point.
156 */
157void main(){
158 vec2 res=iResolution;
159 float aspect=res.x/res.y;
160 vec2 m=(iMouse.z>0.5)?iMouse.xy/res:vec2(0.5);
161 vec2 uv=(tc-m)*vec2(aspect,1.0);
162
163 float gzoom=exp(sin(time_f*0.6)*1.1);
164 float zt=mix(0.65,1.85,0.5+0.5*sin(time_f*0.43));
165 vec2 warp=vec2(fbm(uv*0.9+time_f*0.15), fbm(uv*0.9-vec2(3.1,1.7)+time_f*0.12));
166 float localScale=mix(0.75,2.4,fbm(uv*0.6 + warp*0.8));
167 vec2 p=uv*(gzoom*zt*localScale);
168
169 vec2 flow=vec2(sin(time_f*0.23),cos(time_f*0.19))*0.6;
170 p+=flow*fbm(uv*0.8+warp*0.5);
171
172 VOut v=voronoi(p);
173
174 float px=length(vec2(dFdx(tc.x),dFdy(tc.y)));
175 float lead=0.006/(gzoom*localScale);
176 float edge=1.0 - smoothstep(lead - px, lead + px, v.d);
177
178 vec2 pid=v.id;
179 float hue=fract(hash21(pid)*0.97 + 0.15*sin(time_f*0.2+hash21(pid+7.3)));
180 float sat=mix(0.6,0.95,hash21(pid+3.7));
181 float val=mix(0.7,1.0,hash21(pid+11.1));
182 vec3 pane=hsv2rgb(vec3(hue,sat,val));
183
184 vec2 nrm=normalize(v.nearest+1e-6);
185 float gloss=0.55+0.45*pow(max(dot(nrm,normalize(vec2(cos(time_f*0.27),sin(time_f*0.31)))),0.0),1.2);
186 pane*=gloss;
187
188 vec3 base=texture(samp,tc).rgb;
189 float baseMix=pingPong(0.12+0.15*hash21(pid+2.1) * (time_f * PI), 5.0);
190 vec3 glass=mix(pane,base,baseMix);
191
192 vec3 leadCol=vec3(0.08,0.09,0.10);
193 vec3 col=mix(glass,leadCol,edge);
194
195 float b=0.18;
196 col+=pow(max(col-0.72,0.0),vec3(2.0))*b;
197
198 float vign=1.0 - smoothstep(0.78,1.18,length((tc-m)*vec2(aspect,1.0)));
199 col*=mix(0.92,1.12,vign);
200
201
202 // --- Audio Reactivity: direct output modulation ---
203 float _ab = clamp(amp_peak, 0.0, 1.0);
204 float _abass = clamp(amp_low, 0.0, 1.0);
205 col *= 1.0 + _ab * 0.6;
206 col = mix(col, col * vec3(1.0 + _abass * 0.3, 1.0 - _abass * 0.15, 1.0 + clamp(amp_high, 0.0, 1.0) * 0.25), _ab);
207 // --- End Audio Reactivity ---
208
209 color=vec4(clamp(col,0.0,1.0),1.0);
210}
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 fbm(vec2 point)
Evaluates fbm for this shader effect.
#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 voronoi(vec2 p)
Evaluates voronoi for this shader effect.
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
vec2 hash22(vec2 p)
Evaluates hash22 for this shader effect.
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
vec2 warp(vec2 p, vec2 o, float k)
Evaluates warp for this shader effect.
#define PI
float n2(vec2 p)
Evaluates n2 for this shader effect.