ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
eyes.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file eyes.frag
5 * @brief Vulkan fragment shader: eyes.
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 time_f ext.u2.y
18
19layout(location = 0) in vec2 tc;
20layout(location = 0) out vec4 color;
21layout(set = 0, binding = 0) uniform sampler2D samp;
22
23
24/**
25 * @brief Evaluates sampleRipple for this shader effect.
26 * @param uv Input value for the calculation.
27 * @return Computed vec4 value.
28 */
29vec4 sampleRipple(vec2 uv) {
30 float speedR = 5.0, amplitudeR = 0.03, wavelengthR = 10.0;
31 float speedG = 6.5, amplitudeG = 0.025, wavelengthG = 12.0;
32 float speedB = 4.0, amplitudeB = 0.035, wavelengthB = 8.0;
33
34 float rR = sin(uv.x * wavelengthR + time_f * speedR) * amplitudeR;
35 rR += sin(uv.y * wavelengthR * 0.8 + time_f * speedR * 1.2) * amplitudeR;
36 vec2 uvR = uv + vec2(rR, rR);
37
38 float rG = sin(uv.x * wavelengthG * 1.5 + time_f * speedG) * amplitudeG;
39 rG += sin(uv.y * wavelengthG * 0.3 + time_f * speedG * 0.7) * amplitudeG;
40 vec2 uvG = uv + vec2(rG, -rG * 0.5);
41
42 float rB = sin(uv.x * wavelengthB * 0.5 + time_f * speedB) * amplitudeB;
43 rB += sin(uv.y * wavelengthB * 1.7 + time_f * speedB * 1.3) * amplitudeB;
44 vec2 uvB = uv + vec2(rB * 0.3, rB);
45
46 vec4 c = texture(samp, uv);
47 c.r = texture(samp, uvR).r;
48 c.g = texture(samp, uvG).g;
49 c.b = texture(samp, uvB).b;
50 return c;
51}
52
53/**
54 * @brief Evaluates lens for this shader effect.
55 * @param uv Input value for the calculation.
56 * @param center Input value for the calculation.
57 * @param radius Input value for the calculation.
58 * @param k Input value for the calculation.
59 * @return Computed vec4 value.
60 */
61vec4 lens(vec2 uv, vec2 center, float radius, float k) {
62 vec2 d = (uv - center) / radius;
63 float r = length(d);
64 if (r > 1.0) return vec4(0.0);
65 float r2 = r * r;
66 float s = 1.0 - k * r2;
67 vec2 suv = center + d * s * radius;
68 float v = 1.0 - smoothstep(0.82, 1.0, r);
69 vec4 c = sampleRipple(suv);
70 c.rgb *= v;
71 c.a = v;
72 return c;
73}
74
75/**
76 * @brief Executes the fragment shader entry point.
77 */
78void main() {
79 const vec2 centers[8] = vec2[](
80 vec2(0.35, 0.45),
81 vec2(0.65, 0.45),
82 vec2(0.25, 0.35),
83 vec2(0.50, 0.30),
84 vec2(0.75, 0.35),
85 vec2(0.25, 0.65),
86 vec2(0.50, 0.70),
87 vec2(0.75, 0.65)
88 );
89 const float radii[8] = float[](
90 0.18, 0.18, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12
91 );
92 const float k = 0.35;
93
94 vec3 acc = vec3(0.0);
95 float w = 0.0;
96 for (int i = 0; i < 8; ++i) {
97 vec4 c = lens(tc, centers[i], radii[i], k);
98 acc += c.rgb;
99 w += c.a;
100 }
101 if (w > 0.0) acc /= w;
102 else acc = sampleRipple(tc).rgb;
103
104 color = vec4(acc, 1.0);
105}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
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
vec2 lens(vec2 p, float z)
Evaluates lens for this shader effect.
vec4 sampleRipple(vec2 uv)
Evaluates sampleRipple for this shader effect.
Definition eye2.frag:50