ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
trail-cache-code-aurora-drift.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file trail-cache-code-aurora-drift.frag
5 * @brief Vulkan fragment shader: trail-cache-code-aurora-drift.
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// Slow aurora curtains drift across softly stretched temporal layers.
30#define EFFECT_ID 47
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.19, 0.46, 0.68)));
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 aurora 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 middle Input value for the calculation.
106 * @return Computed vec2 value.
107 */
108vec2 aurora_warp(vec2 uv, float depth, float bass, float middle) {
109 float curtain = sin(uv.y * 8.0 + time_f * 0.7 + depth * 4.0);
110 curtain += 0.5 * sin(uv.y * 17.0 - time_f * 0.43 + depth * TAU);
111 uv.x += curtain * depth * (0.012 + middle * 0.045);
112 uv.y += sin(uv.x * 6.0 - time_f * 0.3) * bass * depth * 0.02;
113 uv = (uv - 0.5) / vec2(1.0 + depth * 0.15, 1.0 + depth * (0.28 + bass * 0.5)) + 0.5;
114 return uv;
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.035);
128 float middle = sample_history(index, 0.22);
129 vec2 uv = aurora_warp(tc, depth, bass, middle);
130 float curtain = pow(abs(sin(uv.x * 10.0 + sin(uv.y * 8.0) + time_f * 0.4)), 3.0);
131 float weight = mix(0.08, 0.52, depth) * (0.6 + curtain * 0.55);
132 accumulated += sample_cache(index, uv).rgb * palette(depth * 0.6 + middle + tc.y * 0.25) * weight;
133 total_weight += weight;
134 }
135
136 vec3 result = accumulated / total_weight;
137 result += palette(tc.y * 0.4 + time_f * 0.03) * amp_peak * 0.08;
138 result = (result - 0.5) * (1.06 + amp_smooth * 0.23) + 0.5;
139 color = vec4(clamp(result, 0.0, 1.0), live.a);
140}
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 aurora_warp(vec2 uv, float depth, float bass, float middle)
Evaluates aurora warp for this shader effect.