ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
psyche-cache-code-aurora-mobius.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file psyche-cache-code-aurora-mobius.frag
5 * @brief Vulkan fragment shader: psyche-cache-code-aurora-mobius.
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// An audio-twisted Mobius ribbon drags luminous cache echoes around itself.
30layout(location = 0) in vec2 tc;
31layout(location = 0) out vec4 color;
32layout(set = 0, binding = 0) uniform sampler2D samp;
33layout(set = 0, binding = 2) uniform sampler2DArray history;
34
35#ifndef SIZE
36#define SIZE 8
37#endif
38#ifndef CACHE_HISTORY_LAYER
39#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
40#endif
41layout(set = 0, binding = 3) uniform sampler1D spectrum0;
42layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
43
44
45#ifndef SPECTRUM_HISTORY_LAYER
46#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
47#endif
48
49
50
51
52
53
54
55
56
57const float TAU = 6.28318530718;
58
59/**
60 * @brief Evaluates rotate 2d for this shader effect.
61 * @param angle Input value for the calculation.
62 * @return Computed mat2 value.
63 */
64mat2 rotate_2d(float angle) {
65 float cosine = cos(angle);
66 float sine = sin(angle);
67 return mat2(cosine, -sine, sine, cosine);
68}
69
70/**
71 * @brief Evaluates mirror repeat for this shader effect.
72 * @param point Input value for the calculation.
73 * @return Computed vec2 value.
74 */
75vec2 mirror_repeat(vec2 point) {
76 return 1.0 - abs(mod(point, 2.0) - 1.0);
77}
78
79/**
80 * @brief Evaluates palette for this shader effect.
81 * @param phase Input value for the calculation.
82 * @return Computed vec3 value.
83 */
84vec3 palette(float phase) {
85 return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.13, 0.46, 0.8)));
86}
87
88/**
89 * @brief Evaluates sample cache for this shader effect.
90 * @param index Input value for the calculation.
91 * @param uv Input value for the calculation.
92 * @return Computed vec3 value.
93 */
94vec3 sample_cache(int index, vec2 uv) {
95 return texture(history, vec3(mirror_repeat(uv),
96 float(CACHE_HISTORY_LAYER(index)))).rgb;
97}
98
99/**
100 * @brief Evaluates history fft 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 history_fft(int index, float frequency) {
106 int age = min(index + 1, max(spectrum_history_size - 1, 0));
107 return texture(spectrum_history,
108 vec2(frequency, float(SPECTRUM_HISTORY_LAYER(age)))).r;
109}
110
111float ribbon_field(vec2 point, float bass, float middle, float treble,
112 float age) {
113 float radius = length(point) + 0.0001;
114 float angle = atan(point.y, point.x);
115 float orbit_phase = time_f * 0.8 + age * 4.0;
116 float orbit_wave = sin(angle + orbit_phase);
117 float cross_twist = sin(angle * 2.0 - orbit_phase * 0.7);
118 float center_line = 0.34 + orbit_wave * (0.075 + middle * 0.045) +
119 cross_twist * (0.025 + middle * 0.015);
120 float twist = sin(angle * 3.0 - time_f * 1.6 - age * 9.0) *
121 (0.055 + treble * 0.045);
122 return radius - center_line - twist - bass * 0.025;
123}
124
125/**
126 * @brief Executes the fragment shader entry point.
127 */
128void main() {
129 vec2 resolution = max(iResolution, vec2(1.0));
130 float aspect = resolution.x / resolution.y;
131 vec2 center = iMouse.z > 0.0 ? iMouse.xy / resolution : vec2(0.5);
132 vec2 point = (tc - center) * vec2(aspect, 1.0);
133 float bass = max(texture(spectrum0, 0.04).r, amp_low);
134 float middle = max(texture(spectrum0, 0.36).r, amp_mid);
135 float treble = max(texture(spectrum0, 0.79).r, amp_high);
136 float field = ribbon_field(point, bass, middle, treble, 0.0);
137 float angle = atan(point.y, point.x);
138 vec2 normal = normalize(point + vec2(0.0001));
139 vec2 tangent = vec2(-normal.y, normal.x);
140 vec2 live_uv = tc - normal * field * (0.16 + bass * 0.12) +
141 tangent * sin(angle * 3.0 - time_f) * treble * 0.018;
142 vec3 live = texture(samp, mirror_repeat(live_uv)).rgb;
143 float ribbon = exp(-abs(field) * (38.0 + treble * 25.0));
144 live += palette(angle / TAU + time_f * 0.04) * ribbon *
145 (0.2 + treble * 0.42);
146
147 vec3 accumulated = live * 1.2;
148 float total_weight = 1.2;
149 for (int index = 0; index < SIZE; ++index) {
150 float age = float(index + 1) / float(max(SIZE, 1));
151 float old_bass = history_fft(index, 0.04);
152 float old_middle = history_fft(index, 0.36);
153 float old_treble = history_fft(index, 0.79);
154 float old_field = ribbon_field(point, old_bass, old_middle,
155 old_treble, age);
156 vec2 cache_point = rotate_2d(age * (0.25 + old_middle * 0.7)) * point;
157 cache_point -= normalize(cache_point + vec2(0.0001)) * old_field *
158 (0.11 + old_bass * 0.1);
159 cache_point *= 1.0 - age * 0.075;
160 vec2 cache_uv = cache_point / vec2(aspect, 1.0) + center;
161 vec3 memory = sample_cache(index, cache_uv);
162 memory *= 0.66 + palette(angle / TAU + age + old_treble) * 0.6;
163 float old_ribbon = exp(-abs(old_field) * 30.0);
164 memory += palette(age - time_f * 0.025) * old_ribbon * 0.1;
165 float weight = exp(-age * 2.4) * (0.68 + old_middle * 0.5);
166 accumulated += memory * weight;
167 total_weight += weight;
168 }
169
170 vec3 result = accumulated / total_weight;
171 result = mix(result, result.gbr, smoothstep(0.87, 1.0, amp_peak) * 0.6);
172 result = (result - 0.5) * (1.1 + amp_smooth * 0.32) + 0.5;
173 color = vec4(clamp(result, 0.0, 1.0), texture(samp, tc).a);
174}
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)
#define amp_mid
mat2 rotate_2d(float angle)
Evaluates rotate 2d for this shader effect.
#define SIZE
vec3 palette(float phase)
Evaluates palette for this shader effect.
#define amp_low
#define amp_high
#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
float field(vec2 p, float tm)
Evaluates field for this shader effect.
float history_fft(int index, float frequency)
Evaluates history fft for this shader effect.
#define TAU
#define frequency
Definition ol.frag:13
float ribbon_field(vec2 point, float bass, float middle, float treble, float age)
vec2 twist(vec2 coord, float twistAmount, float time, float direction)
Evaluates twist for this shader effect.