ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
elastic2.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file elastic2.frag
5 * @brief Vulkan fragment shader: elastic2.
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) {
32 return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453);
33}
34
35/**
36 * @brief Evaluates noise for this shader effect.
37 * @param p Input value for the calculation.
38 * @return Computed float value.
39 */
40float noise(vec2 p) {
41 vec2 ip = floor(p);
42 vec2 fp = fract(p);
43 float a = random(ip);
44 float b = random(ip + vec2(1.0, 0.0));
45 float c = random(ip + vec2(0.0, 1.0));
46 float d = random(ip + vec2(1.0, 1.0));
47 fp = fp * fp * (3.0 - 2.0 * fp);
48 return mix(a, b, fp.x) + (c - a)* fp.y * (1.0 - fp.x) + (d - b) * fp.x * fp.y;
49}
50
51/**
52 * @brief Evaluates fractalNoise for this shader effect.
53 * @param p Input value for the calculation.
54 * @return Computed float value.
55 */
56float fractalNoise(vec2 p) {
57 float v = 0.0;
58 v += noise(p*1.0)*1.0;
59 v += noise(p*2.0)*0.5;
60 v += noise(p*4.0)*0.25;
61 v += noise(p*8.0)*0.125;
62 return v / 1.875;
63}
64
65/**
66 * @brief Executes the fragment shader entry point.
67 */
68void main(void) {
69 vec2 center = vec2(0.5, 0.5);
70 vec2 uv = tc;
71
72 // Mouse influence
73 vec2 mouse = iMouse.xy;
74 float mouseInfluence = 0.0;
75 if (iMouse.z > 0.0) {
76 mouseInfluence = 1.0 - smoothstep(0.0, 0.5, length(mouse - uv));
77 }
78
79 // Base distortion
80 float time = time_f * 2.0;
81 vec2 tcFromCenter = uv - center;
82 float distance = length(tcFromCenter);
83 float angle = atan(tcFromCenter.y, tcFromCenter.x);
84
85 // Intense twirl effect
86 float twirl = 10.0 * (1.0 - smoothstep(0.0, 0.8, distance)) + time * 5.0;
87 angle += twirl * (0.5 + sin(time * 0.7) * 0.5 + mouseInfluence * 2.0);
88
89 // Chaotic displacement
90 vec2 displacement = vec2(
91 fractalNoise(uv * 10.0 + time * 2.0) - 0.5,
92 fractalNoise(uv * 10.0 + time * 1.5) - 0.5
93 ) * 0.2 * (0.5 + mouseInfluence * 2.0);
94
95 // Radial wave distortion
96 float radialWave = sin(distance * 30.0 - time * 10.0) * 0.1;
97 radialWave += sin(angle * 5.0 + time * 5.0) * 0.05;
98
99 // Combine distortions
100 float radius = distance * (1.0 + radialWave * 2.0 + mouseInfluence);
101 vec2 distortedTC = center + vec2(cos(angle), sin(angle)) * radius;
102 distortedTC += displacement * (1.0 + sin(time * 10.0) * 0.5);
103
104 // Glitch jumps
105 float glitchIntensity = (sin(time * 3.0) * 0.5 + 0.5) * 0.3 + mouseInfluence * 0.5;
106 if (random(vec2(time)) > 0.7) {
107 distortedTC.x += (random(vec2(time)) - 0.5) * glitchIntensity;
108 distortedTC.y += (random(vec2(time * 0.7)) - 0.5) * glitchIntensity;
109 }
110
111 // Color channel splitting
112 vec4 color1 = texture(samp, distortedTC + vec2(glitchIntensity * 0.02, 0.0));
113 vec4 color2 = texture(samp, distortedTC - vec2(glitchIntensity * 0.02, 0.0));
114 color = vec4(color1.r, color2.g, color1.b, 1.0);
115
116 // Scan line effect
117 float scanLine = sin(uv.y * 800.0 + time * 10.0) * 0.1;
118 color.rgb += scanLine * glitchIntensity;
119
120 // Chromatic aberration
121 vec2 chromaOffset = vec2(
122 fractalNoise(uv * 50.0 + time) * 0.02,
123 fractalNoise(uv * 50.0 + time * 1.2) * 0.02
124 );
125 color.r = texture(samp, distortedTC + chromaOffset).r;
126 color.b = texture(samp, distortedTC - chromaOffset).b;
127
128 // Contrast boost
129 color.rgb = mix(color.rgb, smoothstep(0.0, 1.0, color.rgb * 1.2), 0.5);
130
131 // Random black flashes
132 if (random(vec2(time * 0.3)) > 0.97) {
133 color.rgb *= 0.1;
134 }
135
136 // Vignette
137 float vignette = 1.0 - smoothstep(0.4, 0.8, distance);
138 // color.rgb *= vignette;
139}
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