ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
elastic_mouse.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file elastic_mouse.frag
5 * @brief Vulkan fragment shader: elastic mouse.
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 time_f ext.u2.y
19
20layout(location = 0) in vec2 tc;
21layout(location = 0) out vec4 color;
22layout(set = 0, binding = 0) uniform sampler2D samp;
23
24
25
26/**
27 * @brief Evaluates random for this shader effect.
28 * @param st Input value for the calculation.
29 * @return Computed float value.
30 */
31float random(vec2 st){return fract(sin(dot(st,vec2(12.9898,78.233)))*43758.5453);}
32/**
33 * @brief Evaluates noise for this shader effect.
34 * @param p Input value for the calculation.
35 * @return Computed float value.
36 */
37float noise(vec2 p){
38 vec2 ip=floor(p),fp=fract(p);
39 float a=random(ip);
40 float b=random(ip+vec2(1.0,0.0));
41 float c=random(ip+vec2(0.0,1.0));
42 float d=random(ip+vec2(1.0,1.0));
43 fp=fp*fp*(3.0-2.0*fp);
44 return mix(a,b,fp.x)+(c-a)*fp.y*(1.0-fp.x)+(d-b)*fp.x*fp.y;
45}
46/**
47 * @brief Evaluates fractalNoise for this shader effect.
48 * @param p Input value for the calculation.
49 * @return Computed float value.
50 */
51float fractalNoise(vec2 p){
52 float v=0.0;
53 v+=noise(p*1.0)*1.0;
54 v+=noise(p*2.0)*0.5;
55 v+=noise(p*4.0)*0.25;
56 v+=noise(p*8.0)*0.125;
57 return v/1.875;
58}
59
60/**
61 * @brief Executes the fragment shader entry point.
62 */
63void main(){
64 vec2 center=vec2(0.5);
65 vec2 uv=tc;
66 vec2 m=(iMouse.z>0.0)?iMouse.xy:center;
67 float mouseInfluence=1.0-smoothstep(0.0,0.5,length(m-uv));
68 float t=time_f*2.0;
69 vec2 d=uv-center;
70 float dist=length(d);
71 float ang=atan(d.y,d.x);
72 float twirl=10.0*(1.0-smoothstep(0.0,0.8,dist))+t*5.0;
73 ang+=twirl*(0.5+sin(t*0.7)*0.5+mouseInfluence*2.0);
74 vec2 disp=vec2(fractalNoise(uv*10.0+t*2.0)-0.5,fractalNoise(uv*10.0+t*1.5)-0.5)*0.2*(0.5+mouseInfluence*2.0);
75 float radialWave=sin(dist*30.0-t*10.0)*0.1+sin(ang*5.0+t*5.0)*0.05;
76 float radius=dist*(1.0+radialWave*2.0+mouseInfluence);
77 vec2 tc2=center+vec2(cos(ang),sin(ang))*radius;
78 tc2+=disp*(1.0+sin(t*10.0)*0.5);
79 float rgate=random(vec2(floor(t*3.0)));
80 float gInt=(sin(t*3.0)*0.5+0.5)*0.3+mouseInfluence*0.5;
81 if(rgate>0.7){
82 tc2.x+= (random(vec2(t))-0.5)*gInt;
83 tc2.y+= (random(vec2(t*0.7))-0.5)*gInt;
84 }
85 tc2=clamp(tc2,0.0,1.0);
86 vec2 chroma=vec2(fractalNoise(uv*50.0+t)*0.02,fractalNoise(uv*50.0+t*1.2)*0.02);
87 vec4 cR=texture(samp,clamp(tc2+vec2(gInt*0.02,0.0),0.0,1.0));
88 vec4 cG=texture(samp,clamp(tc2-vec2(gInt*0.02,0.0),0.0,1.0));
89 vec3 col=vec3(cR.r,cG.g,cR.b);
90 float scan=sin(uv.y*800.0+t*10.0)*0.1;
91 col+=scan*gInt;
92 col.r=texture(samp,clamp(tc2+chroma,0.0,1.0)).r;
93 col.b=texture(samp,clamp(tc2-chroma,0.0,1.0)).b;
94 col=mix(col,smoothstep(0.0,1.0,col*1.2),0.5);
95 if(random(vec2(floor(t*0.3)))>0.97) col*=0.1;
96 float vignette=1.0-smoothstep(0.4,0.8,dist);
97 color=vec4(col*vignette,1.0);
98}
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 time_f
Definition 3high.frag:19
vec3 twirl(ivec2 p, ivec2 size)
Evaluates twirl for this shader effect.
float noise(vec2 p)
Evaluates noise for this shader effect.
float random(vec2 st)
Evaluates random for this shader effect.
float fractalNoise(vec2 p)
Evaluates fractalNoise for this shader effect.
Definition elastic2.frag:56