ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
all_colors.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file all_colors.frag
5 * @brief Vulkan fragment shader: all colors.
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 alpha_b ext.custom_uniforms[1].x
18#define alpha_g ext.custom_uniforms[0].w
19#define alpha_r ext.custom_uniforms[0].z
20#define iResolution ext.u0.zw
21#define time_f ext.u2.y
22
23layout(location = 0) out vec4 color;
24layout(location = 0) in vec2 tc;
25layout(set = 0, binding = 0) uniform sampler2D samp;
26
27
28
29
30
31
32/**
33 * @brief Evaluates xor RGB for this shader effect.
34 * @param a Input value for the calculation.
35 * @param b Input value for the calculation.
36 * @return Computed vec4 value.
37 */
38vec4 xor_RGB(vec4 a, vec4 b) {
39 ivec3 ai;
40 ivec4 bi = ivec4(clamp(b, 0.0, 1.0) * 255.0 + 0.5);
41 for (int i = 0; i < 3; ++i) {
42 ai[i] = int(clamp(a[i], 0.0, 1.0) * 255.0 + 0.5);
43 ai[i] = ai[i] ^ bi[i];
44 ai[i] = ai[i] % 256;
45 a[i] = float(ai[i]) / 255.0;
46 }
47 a.a = 1.0;
48 return a;
49}
50
51/**
52 * @brief Evaluates blur for this shader effect.
53 * @param image Input value for the calculation.
54 * @param uv Input value for the calculation.
55 * @param res Input value for the calculation.
56 * @return Computed vec4 value.
57 */
58vec4 blur(sampler2D image, vec2 uv, vec2 res) {
59 vec2 ts = 1.0 / res;
60 float k[100];
61 float v[100] = float[](
62 0.5,1.0,1.5,2.0,2.5,2.5,2.0,1.5,1.0,0.5,
63 1.0,2.0,2.5,3.0,3.5,3.5,3.0,2.5,2.0,1.0,
64 1.5,2.5,3.0,3.5,4.0,4.0,3.5,3.0,2.5,1.5,
65 2.0,3.0,3.5,4.0,4.5,4.5,4.0,3.5,3.0,2.0,
66 2.5,3.5,4.0,4.5,5.0,5.0,4.5,4.0,3.5,2.5,
67 2.5,3.5,4.0,4.5,5.0,5.0,4.5,4.0,3.5,2.5,
68 2.0,3.0,3.5,4.0,4.5,4.5,4.0,3.5,3.0,2.0,
69 1.5,2.5,3.0,3.5,4.0,4.0,3.5,3.0,2.5,1.5,
70 1.0,2.0,2.5,3.0,3.5,3.5,3.0,2.5,2.0,1.0,
71 0.5,1.0,1.5,2.0,2.5,2.5,2.0,1.5,1.0,0.5
72 );
73 for (int i = 0; i < 100; ++i) k[i] = v[i];
74 float s = 0.0;
75 for (int i = 0; i < 100; ++i) s += k[i];
76 vec4 r = vec4(0.0);
77 for (int y = -5; y <= 4; ++y) {
78 for (int x = -5; x <= 4; ++x) {
79 int idx = (y + 5) * 10 + (x + 5);
80 r += texture(image, uv + vec2(float(x), float(y)) * ts) * k[idx];
81 }
82 }
83 return r / s;
84}
85
86/**
87 * @brief Evaluates pingPong for this shader effect.
88 * @param x Input value for the calculation.
89 * @param len Input value for the calculation.
90 * @return Computed float value.
91 */
92float pingPong(float x, float len) {
93 float m = mod(x, len * 2.0);
94 return m <= len ? m : (len * 2.0 - m);
95}
96
97/**
98 * @brief Executes the fragment shader entry point.
99 */
100void main(void) {
101 vec3 col = blur(samp, tc, iResolution).rgb;
102
103 float t = mod(time_f, 6.0);
104 float mcv = 1.0;
105
106 if (t < 1.0) {
107 col.r = mix(0.0, mcv, t);
108 } else if (t < 2.0) {
109 col.r = mcv;
110 col.g = mix(0.0, mcv, t - 1.0);
111 } else if (t < 3.0) {
112 col.r = mcv;
113 col.g = mcv;
114 col.b = mix(0.0, mcv, t - 2.0);
115 } else if (t < 4.0) {
116 col = vec3(mcv);
117 col.b = mix(mcv, alpha_b, t - 3.0);
118 } else if (t < 5.0) {
119 col = vec3(mcv, mcv, alpha_b);
120 col.g = mix(mcv, alpha_g, t - 4.0);
121 } else {
122 col = vec3(mcv, alpha_g, alpha_b);
123 col.r = mix(mcv, alpha_r, t - 5.0);
124 }
125
126 vec4 cyc = vec4(col, 1.0);
127 vec4 xr = xor_RGB(blur(samp, tc, iResolution), cyc);
128
129 float tt = pingPong(time_f, 20.0) + 2.0;
130 vec3 s1 = 0.5 + 0.5 * sin(xr.rgb * tt);
131 vec3 s2 = 0.5 + 0.5 * sin((xr.rgb * 6.28318) + vec3(0.0, 2.0943951, 4.1887902));
132
133 vec3 allColors = mix(s1, s2, 0.65);
134 color = vec4(clamp(allColors, 0.0, 1.0), 1.0);
135}
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 iResolution
Definition 3high.frag:18
#define time_f
Definition 3high.frag:19
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
vec4 blur(sampler2D image, vec2 uv, vec2 resolution)
Evaluates blur for this shader effect.
Definition af_scale.frag:44
#define alpha_r
#define alpha_g
vec4 xor_RGB(vec4 a, vec4 b)
Evaluates xor RGB for this shader effect.
#define alpha_b
float s2(float x)
Evaluates s2 for this shader effect.