ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
trail-cache-code-orbital-rings.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file trail-cache-code-orbital-rings.frag
5 * @brief Vulkan fragment shader: trail-cache-code-orbital-rings.
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// Independent temporal layers ride precessing elliptical orbital rings.
30#define EFFECT_ID 38
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 rotate 2d for this shader effect.
62 * @param angle Input value for the calculation.
63 * @return Computed mat2 value.
64 */
65mat2 rotate_2d(float angle) {
66 float c = cos(angle);
67 float s = sin(angle);
68 return mat2(c, -s, s, c);
69}
70
71/**
72 * @brief Evaluates mirror repeat for this shader effect.
73 * @param point Input value for the calculation.
74 * @return Computed vec2 value.
75 */
76vec2 mirror_repeat(vec2 point) {
77 return 1.0 - abs(mod(point, 2.0) - 1.0);
78}
79
80/**
81 * @brief Evaluates palette for this shader effect.
82 * @param phase Input value for the calculation.
83 * @return Computed vec3 value.
84 */
85vec3 palette(float phase) {
86 return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.05, 0.42, 0.79)));
87}
88
89/**
90 * @brief Evaluates sample cache for this shader effect.
91 * @param index Input value for the calculation.
92 * @param uv Input value for the calculation.
93 * @return Computed vec4 value.
94 */
95vec4 sample_cache(int index, vec2 uv) {
96 return texture(history, vec3(mirror_repeat(uv), float(CACHE_HISTORY_LAYER(index))));
97}
98
99/**
100 * @brief Evaluates sample history for this shader effect.
101 * @param index Input value for the calculation.
102 * @param frequency Input value for the calculation.
103 * @return Computed float value.
104 */
105float sample_history(int index, float frequency) {
106 int max_age = max(min(SIZE, spectrum_history_size) - 1, 0);
107 int age = min(index + 1, max_age);
108 return texture(spectrum_history, vec2(frequency, float(SPECTRUM_HISTORY_LAYER(age)))).r;
109}
110
111/**
112 * @brief Evaluates orbital warp for this shader effect.
113 * @param uv Input value for the calculation.
114 * @param center Input value for the calculation.
115 * @param depth Input value for the calculation.
116 * @param bass Input value for the calculation.
117 * @param middle Input value for the calculation.
118 * @return Computed vec2 value.
119 */
120vec2 orbital_warp(vec2 uv, vec2 center, float depth, float bass, float middle) {
121 vec2 point = uv - center;
122 float phase = depth * TAU + time_f * (0.18 + middle * 0.3);
123 vec2 orbit = vec2(cos(phase), sin(phase) * 0.55) * depth * (0.025 + bass * 0.08);
124 point -= orbit;
125 point = rotate_2d(phase * 0.35 + sin(time_f * 0.2) * depth) * point;
126 point.x *= 1.0 + depth * 0.18;
127 point.y /= 1.0 + depth * (0.28 + bass * 0.7);
128 return point + center;
129}
130
131/**
132 * @brief Executes the fragment shader entry point.
133 */
134void main() {
135 vec2 resolution = max(iResolution, vec2(1.0));
136 vec2 center = iMouse.z > 0.0 ? iMouse.xy / resolution : vec2(0.5);
137 vec4 live = texture(samp, tc);
138 vec3 accumulated = live.rgb;
139 float total_weight = 1.0;
140
141 for (int index = 0; index < SIZE; ++index) {
142 float depth = float(index) / float(max(SIZE - 1, 1));
143 float bass = sample_history(index, 0.035);
144 float middle = sample_history(index, 0.25);
145 vec2 uv = orbital_warp(tc, center, depth, bass, middle);
146 float ring = 1.0 - smoothstep(0.0, 0.035, abs(length(tc - center) - (0.1 + depth * 0.38)));
147 float weight = mix(0.08, 0.56, depth) * (0.68 + ring * 0.6);
148 accumulated += sample_cache(index, uv).rgb * mix(vec3(1.0), palette(depth + middle), 0.7) * weight;
149 total_weight += weight;
150 }
151
152 vec3 result = accumulated / total_weight;
153 result = mix(result, result.brg, amp_peak * 0.25);
154 result = (result - 0.5) * (1.08 + amp_smooth * 0.27) + 0.5;
155 color = vec4(clamp(result, 0.0, 1.0), live.a);
156}
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)
mat2 rotate_2d(float angle)
Evaluates rotate 2d for this shader effect.
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 orbital_warp(vec2 uv, vec2 center, float depth, float bass, float middle)
Evaluates orbital warp for this shader effect.