ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
react_x_xor_gradient.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file react_x_xor_gradient.frag
5 * @brief Vulkan fragment shader: react x xor gradient.
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 iResolution ext.u0.zw
24#define iamp ext.u1.z
25#define time_f ext.u2.y
26
27layout(location = 0) out vec4 color;
28layout(location = 0) in vec2 tc;
29layout(set = 0, binding = 0) uniform sampler2D samp;
30
31
32
33
34
35
36
37
38
39
40/**
41 * @brief Evaluates xor RGB for this shader effect.
42 * @param icolor Input value for the calculation.
43 * @param source Input value for the calculation.
44 * @return Computed vec4 value.
45 */
46vec4 xor_RGB(vec4 icolor, vec4 source) {
47 ivec3 int_color;
48 ivec4 isource = ivec4(source * 255);
49 for (int i = 0; i < 3; ++i) {
50 int_color[i] = int(255 * icolor[i]);
51 int_color[i] = int_color[i] ^ isource[i];
52 if (int_color[i] > 255)
53 int_color[i] = int_color[i] % 255;
54 icolor[i] = float(int_color[i]) / 255;
55 }
56 icolor.a = 1.0;
57 return icolor;
58}
59
60/**
61 * @brief Evaluates pingPong for this shader effect.
62 * @param x Input value for the calculation.
63 * @param length Input value for the calculation.
64 * @return Computed float value.
65 */
66float pingPong(float x, float length) {
67 float modVal = mod(x, length * 2.0);
68 return modVal <= length ? modVal : length * 2.0 - modVal;
69}
70
71/**
72 * @brief Evaluates blur5 for this shader effect.
73 * @param image Input value for the calculation.
74 * @param uv Input value for the calculation.
75 * @param resolution Input value for the calculation.
76 * @param strength Input value for the calculation.
77 * @return Computed vec4 value.
78 */
79vec4 blur5(sampler2D image, vec2 uv, vec2 resolution, float strength) {
80 vec2 texelSize = strength / resolution;
81 vec4 result = vec4(0.0);
82 float total = 0.0;
83 for (int x = -2; x <= 2; ++x) {
84 for (int y = -2; y <= 2; ++y) {
85 float w = 1.0 / (1.0 + float(x * x + y * y));
86 result += texture(image, uv + vec2(float(x), float(y)) * texelSize) * w;
87 total += w;
88 }
89 }
90 return result / total;
91}
92
93/**
94 * @brief Executes the fragment shader entry point.
95 */
96void main(void) {
97 float aLow = clamp(amp_low, 0.0, 1.0);
98 float aMid = clamp(amp_mid, 0.0, 1.0);
99 float aHigh = clamp(amp_high, 0.0, 1.0);
100 float aPk = clamp(amp_peak, 0.0, 1.0);
101 float aRms = clamp(amp_rms, 0.0, 1.0);
102
103 float amplitude = aRms * 0.8 + 0.1;
104 vec3 gradLow = vec3(0.0, 0.2, 1.0) * (0.5 + aLow * 0.5);
105 vec3 gradHigh = vec3(1.0, 0.1, 0.2) * (0.5 + aHigh * 0.5);
106 vec3 gradientColor = mix(gradLow, gradHigh, amplitude);
107
108 float blurStr = 1.0 + aPk * 3.0;
109 vec4 texColor = blur5(samp, tc, iResolution, blurStr);
110
111 vec2 uv = tc / iResolution;
112 float gradMix = 0.5 * sin(time_f * (1.0 + aMid * 2.0) + uv.y * 3.14159) + 0.5;
113 gradMix *= 0.3 + aMid * 0.4;
114 vec3 finalColor = mix(texColor.rgb, gradientColor, gradMix);
115
116 color = vec4(finalColor, texColor.a);
117 float time_t = pingPong(time_f, 10.0) + 0.5;
118 vec4 blurred = blur5(samp, tc, iResolution, 1.0 + aLow * 2.0);
119 color = xor_RGB(color, blurred * time_t);
120
121 color.rgb *= 1.0 + aPk * 0.5;
122 color.rgb = mix(color.rgb,
123 color.rgb * vec3(1.0 + aLow * 0.3, 1.0, 1.0 + aHigh * 0.3),
124 aPk);
125}
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
#define amp_mid
#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
vec4 xor_RGB(vec4 a, vec4 b)
Evaluates xor RGB for this shader effect.
#define amp_rms
Definition breathe.frag:21
#define strength
Definition ol.frag:16
vec4 blur5(sampler2D image, vec2 uv, vec2 resolution, float strength)
Evaluates blur5 for this shader effect.