ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
trail-cache-code-kaleido-vortex.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file trail-cache-code-kaleido-vortex.frag
5 * @brief Vulkan fragment shader: trail-cache-code-kaleido-vortex.
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_smooth ext.u3.w
22#define history_head int(ext.u3.x)
23#define iMouse ext.mouse
24#define iResolution ext.u0.zw
25#define spectrum_history_head int(ext.audio_history.x)
26#define spectrum_history_size int(ext.audio_history.y)
27#define time_f ext.u2.y
28
29// Kaleidoscopic polar vortex carrying each cache layer on a different spoke.
30#define EFFECT_ID 28
31layout(location = 0) in vec2 tc;
32layout(location = 0) out vec4 color;
33layout(set = 0, binding = 0) uniform sampler2D samp;
34layout(set = 0, binding = 2) uniform sampler2DArray history;
35
36#ifndef SIZE
37#define SIZE 8
38#endif
39#ifndef CACHE_HISTORY_LAYER
40#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
41#endif
42layout(set = 0, binding = 3) uniform sampler1D spectrum0;
43layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
44
45
46#ifndef SPECTRUM_HISTORY_LAYER
47#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
48#endif
49
50
51
52
53
54
55
56
57
58const float PI = 3.14159265359;
59const float TAU = 6.28318530718;
60
61/**
62 * @brief Evaluates mirror repeat for this shader effect.
63 * @param point Input value for the calculation.
64 * @return Computed vec2 value.
65 */
66vec2 mirror_repeat(vec2 point) {
67 return 1.0 - abs(mod(point, 2.0) - 1.0);
68}
69
70/**
71 * @brief Evaluates palette for this shader effect.
72 * @param phase Input value for the calculation.
73 * @return Computed vec3 value.
74 */
75vec3 palette(float phase) {
76 return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.04, 0.38, 0.72)));
77}
78
79/**
80 * @brief Evaluates sample cache for this shader effect.
81 * @param index Input value for the calculation.
82 * @param uv Input value for the calculation.
83 * @return Computed vec4 value.
84 */
85vec4 sample_cache(int index, vec2 uv) {
86 return texture(history, vec3(mirror_repeat(uv), float(CACHE_HISTORY_LAYER(index))));
87}
88
89/**
90 * @brief Evaluates sample history for this shader effect.
91 * @param index Input value for the calculation.
92 * @param frequency Input value for the calculation.
93 * @return Computed float value.
94 */
95float sample_history(int index, float frequency) {
96 int max_age = max(min(SIZE, spectrum_history_size) - 1, 0);
97 int age = min(index + 1, max_age);
98 return texture(spectrum_history, vec2(frequency, float(SPECTRUM_HISTORY_LAYER(age)))).r;
99}
100
101/**
102 * @brief Evaluates kaleido vortex for this shader effect.
103 * @param uv Input value for the calculation.
104 * @param center Input value for the calculation.
105 * @param depth Input value for the calculation.
106 * @param bass Input value for the calculation.
107 * @param treble Input value for the calculation.
108 * @return Computed vec2 value.
109 */
110vec2 kaleido_vortex(vec2 uv, vec2 center, float depth, float bass, float treble) {
111 vec2 point = uv - center;
112 float radius = length(point);
113 float sectors = 5.0 + floor(treble * 5.0);
114 float sector = TAU / sectors;
115 float angle = atan(point.y, point.x) + radius * (4.0 + bass * 8.0) - time_f * 0.3;
116 angle = abs(mod(angle + sector * 0.5, sector) - sector * 0.5);
117 angle += depth * PI * (0.25 + treble);
118 radius /= 1.0 + depth * (0.45 + bass);
119 return vec2(cos(angle), sin(angle)) * radius + center;
120}
121
122/**
123 * @brief Executes the fragment shader entry point.
124 */
125void main() {
126 vec2 resolution = max(iResolution, vec2(1.0));
127 vec2 center = iMouse.z > 0.0 ? iMouse.xy / resolution : vec2(0.5);
128 vec4 live = texture(samp, tc);
129 vec3 accumulated = live.rgb;
130 float total_weight = 1.0;
131
132 for (int index = 0; index < SIZE; ++index) {
133 float depth = float(index) / float(max(SIZE - 1, 1));
134 float bass = sample_history(index, 0.025);
135 float treble = sample_history(index, 0.66);
136 vec2 uv = kaleido_vortex(tc, center, depth, bass, treble);
137 float spoke = 0.65 + 0.35 * cos(atan(uv.y - center.y, uv.x - center.x) * 10.0);
138 float weight = mix(0.1, 0.6, depth) * spoke;
139 accumulated += sample_cache(index, uv).rgb * palette(depth * 0.8 + treble) * weight;
140 total_weight += weight;
141 }
142
143 vec3 result = accumulated / total_weight;
144 result += palette(time_f * 0.05) * amp_peak * 0.1;
145 result = (result - 0.5) * (1.1 + amp_smooth * 0.28) + 0.5;
146 color = vec4(clamp(result, 0.0, 1.0), live.a);
147}
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 iResolution
Definition 3high.frag:18
#define time_f
Definition 3high.frag:19
#define amp_smooth
#define CACHE_HISTORY_LAYER(index)
float sample_history(int index, float frequency)
Evaluates sample history for this shader effect.
#define SIZE
vec3 palette(float phase)
Evaluates palette for this shader effect.
#define SPECTRUM_HISTORY_LAYER(index)
vec2 mirror_repeat(vec2 point)
Evaluates mirror repeat for this shader effect.
vec4 sample_cache(int index, vec2 uv)
Evaluates sample cache for this shader effect.
#define amp_peak
#define spectrum_history_size
#define TAU
#define PI
#define frequency
Definition ol.frag:13
vec2 kaleido_vortex(vec2 uv, vec2 center, float depth, float bass, float treble)
Evaluates kaleido vortex for this shader effect.