ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
trail-cache-code-chromatic-comet.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file trail-cache-code-chromatic-comet.frag
5 * @brief Vulkan fragment shader: trail-cache-code-chromatic-comet.
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// Directional RGB comet tails accelerated by bass and peak energy.
30#define EFFECT_ID 33
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 TAU = 6.28318530718;
59
60/**
61 * @brief Evaluates mirror repeat for this shader effect.
62 * @param point Input value for the calculation.
63 * @return Computed vec2 value.
64 */
65vec2 mirror_repeat(vec2 point) {
66 return 1.0 - abs(mod(point, 2.0) - 1.0);
67}
68
69/**
70 * @brief Evaluates palette for this shader effect.
71 * @param phase Input value for the calculation.
72 * @return Computed vec3 value.
73 */
74vec3 palette(float phase) {
75 return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.00, 0.36, 0.70)));
76}
77
78/**
79 * @brief Evaluates sample cache for this shader effect.
80 * @param index Input value for the calculation.
81 * @param uv Input value for the calculation.
82 * @return Computed vec4 value.
83 */
84vec4 sample_cache(int index, vec2 uv) {
85 return texture(history, vec3(mirror_repeat(uv), float(CACHE_HISTORY_LAYER(index))));
86}
87
88/**
89 * @brief Evaluates sample history for this shader effect.
90 * @param index Input value for the calculation.
91 * @param frequency Input value for the calculation.
92 * @return Computed float value.
93 */
94float sample_history(int index, float frequency) {
95 int max_age = max(min(SIZE, spectrum_history_size) - 1, 0);
96 int age = min(index + 1, max_age);
97 return texture(spectrum_history, vec2(frequency, float(SPECTRUM_HISTORY_LAYER(age)))).r;
98}
99
100/**
101 * @brief Evaluates comet warp for this shader effect.
102 * @param uv Input value for the calculation.
103 * @param depth Input value for the calculation.
104 * @param bass Input value for the calculation.
105 * @param high Input value for the calculation.
106 * @return Computed vec2 value.
107 */
108vec2 comet_warp(vec2 uv, float depth, float bass, float high) {
109 float direction = time_f * 0.23 + sin(time_f * 0.11) * 1.4;
110 vec2 velocity = vec2(cos(direction), sin(direction));
111 uv -= velocity * depth * (0.035 + bass * 0.16);
112 vec2 normal = vec2(-velocity.y, velocity.x);
113 uv += normal * sin(dot(uv, normal) * 20.0 + time_f * 3.0 - depth * TAU) * high * 0.025;
114 return (uv - 0.5) / (1.0 + depth * 0.22) + 0.5;
115}
116
117/**
118 * @brief Executes the fragment shader entry point.
119 */
120void main() {
121 vec4 live = texture(samp, tc);
122 vec3 accumulated = live.rgb;
123 float total_weight = 1.0;
124
125 for (int index = 0; index < SIZE; ++index) {
126 float depth = float(index) / float(max(SIZE - 1, 1));
127 float bass = sample_history(index, 0.03);
128 float high = sample_history(index, 0.65);
129 vec2 uv = comet_warp(tc, depth, bass, high);
130 float spread = (0.002 + high * 0.008) * depth;
131 vec3 cached;
132 cached.r = sample_cache(index, uv + vec2(spread, 0.0)).r;
133 cached.g = sample_cache(index, uv).g;
134 cached.b = sample_cache(index, uv - vec2(spread, 0.0)).b;
135 float weight = mix(0.08, 0.64, depth) * (1.0 - depth * 0.25);
136 accumulated += cached * palette(depth * 0.7 + time_f * 0.04) * weight;
137 total_weight += weight;
138 }
139
140 vec3 result = accumulated / total_weight;
141 result += max(result - result.gbr, 0.0) * amp_peak * 0.3;
142 result = (result - 0.5) * (1.08 + amp_smooth * 0.26) + 0.5;
143 color = vec4(clamp(result, 0.0, 1.0), live.a);
144}
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
#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 frequency
Definition ol.frag:13
vec2 comet_warp(vec2 uv, float depth, float bass, float high)
Evaluates comet warp for this shader effect.