ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
af_scale2_react.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file af_scale2_react.frag
5 * @brief Vulkan fragment shader: af scale2 react.
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 iResolution ext.u0.zw
18#define time_f ext.u2.y
19
20layout(location = 0) out vec4 color;
21layout(location = 0) in vec2 tc;
22layout(set = 0, binding = 0) uniform sampler2D samp;
23layout(set = 0, binding = 3) uniform sampler1D spectrum; // Audio spectrum input
24
25
26
27/**
28 * @brief Evaluates pingPong for this shader effect.
29 * @param x Input value for the calculation.
30 * @param length Input value for the calculation.
31 * @return Computed float value.
32 */
33float pingPong(float x, float length) {
34 float modVal = mod(x, length * 2.0);
35 return modVal <= length ? modVal : length * 2.0 - modVal;
36}
37
38/**
39 * @brief Evaluates blur for this shader effect.
40 * @param image Input value for the calculation.
41 * @param uv Input value for the calculation.
42 * @param resolution Input value for the calculation.
43 * @param intensity Input value for the calculation.
44 * @return Computed vec4 value.
45 */
46vec4 blur(sampler2D image, vec2 uv, vec2 resolution, float intensity) {
47 // We can scale the blur offset based on audio intensity
48 vec2 texelSize = (1.0 / resolution) * intensity;
49 vec4 result = vec4(0.0);
50
51 float kernelVals[100] = float[](0.5, 1.0, 1.5, 2.0, 2.5, 2.5, 2.0, 1.5, 1.0, 0.5,
52 1.0, 2.0, 2.5, 3.0, 3.5, 3.5, 3.0, 2.5, 2.0, 1.0,
53 1.5, 2.5, 3.0, 3.5, 4.0, 4.0, 3.5, 3.0, 2.5, 1.5,
54 2.0, 3.0, 3.5, 4.0, 4.5, 4.5, 4.0, 3.5, 3.0, 2.0,
55 2.5, 3.5, 4.0, 4.5, 5.0, 5.0, 4.5, 4.0, 3.5, 2.5,
56 2.5, 3.5, 4.0, 4.5, 5.0, 5.0, 4.5, 4.0, 3.5, 2.5,
57 2.0, 3.0, 3.5, 4.0, 4.5, 4.5, 4.0, 3.5, 3.0, 2.0,
58 1.5, 2.5, 3.0, 3.5, 4.0, 4.0, 3.5, 3.0, 2.5, 1.5,
59 1.0, 2.0, 2.5, 3.0, 3.5, 3.5, 3.0, 2.5, 2.0, 1.0,
60 0.5, 1.0, 1.5, 2.0, 2.5, 2.5, 2.0, 1.5, 1.0, 0.5);
61
62 float kernelSum = 250.0; // Optimized: sum of kernelVals above
63
64 for (int x = -5; x <= 4; ++x) {
65 for (int y = -5; y <= 4; ++y) {
66 vec2 offset = vec2(float(x), float(y)) * texelSize;
67 result += texture(image, uv + offset) * kernelVals[(y + 5) * 10 + (x + 5)];
68 }
69 }
70
71 return result / kernelSum;
72}
73
74/**
75 * @brief Evaluates colorShift for this shader effect.
76 * @param col Input value for the calculation.
77 * @param audioMod Input value for the calculation.
78 * @return Computed vec4 value.
79 */
80vec4 colorShift(vec4 col, float audioMod) {
81 // Use audioMod to rotate the phase of the cosine wave
82 return vec4(
83 0.5 + 0.5 * cos((col.r + audioMod) * 3.14159265 * 0.5),
84 0.5 + 0.5 * cos((col.g + audioMod) * 3.14159265 * 0.5),
85 0.5 + 0.5 * cos((col.b + audioMod) * 3.14159265 * 0.5),
86 col.a
87 );
88}
89
90/**
91 * @brief Executes the fragment shader entry point.
92 */
93void main(void) {
94 // Sample the spectrum at different frequencies (0.0 = Bass, 0.5 = Mids, 1.0 = Highs)
95 float bass = texture(spectrum, 0.05).r; // Bass hit
96 float mids = texture(spectrum, 0.5).r; // Mid-range activity
97
98 // Smooth the reaction or exaggerate it
99 float pulse = bass * 2.0;
100
101 float time_t = pingPong(time_f, 10.0) + 1.0 + pulse;
102
103 // We pass the bass pulse into the blur to make it "shake" or bloom on beat
104 vec4 pix = blur(samp, tc, iResolution, 1.0 + (pulse * 0.5));
105
106 pix = pix * time_t;
107
108 // Shift colors based on mid-range audio activity
109 pix = colorShift(pix, mids);
110
111 pix.rgb = mix(vec3(1.0), pix.rgb, 0.8);
112 color = pix;
113}
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
vec4 colorShift(vec4 col)
Evaluates colorShift for this shader effect.
Definition af_scale.frag:84
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
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.