ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
psyche-cache-code-neon-dream-weave.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file psyche-cache-code-neon-dream-weave.frag
5 * @brief Vulkan fragment shader: psyche-cache-code-neon-dream-weave.
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// Interlaced neon waves braid live video with spectral memory.
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.08, 0.45, 0.79)));
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 weave_field(vec2 point, float bass, float middle, float treble,
112 float age) {
113 float horizontal = sin(point.x * (17.0 + treble * 9.0) +
114 sin(point.y * 8.0 - time_f * 2.0 - age * 7.0) *
115 (3.0 + bass * 5.0));
116 float vertical = cos(point.y * (19.0 + middle * 8.0) +
117 sin(point.x * 7.0 + time_f * 1.7 + age * 9.0) *
118 (3.0 + treble * 4.0));
119 return horizontal * vertical;
120}
121
122/**
123 * @brief Executes the fragment shader entry point.
124 */
125void main() {
126 vec2 resolution = max(iResolution, vec2(1.0));
127 float aspect = resolution.x / resolution.y;
128 vec2 center = iMouse.z > 0.0 ? iMouse.xy / resolution : vec2(0.5);
129 vec2 point = (tc - center) * vec2(aspect, 1.0);
130 float bass = max(texture(spectrum0, 0.055).r, amp_low);
131 float middle = max(texture(spectrum0, 0.38).r, amp_mid);
132 float treble = max(texture(spectrum0, 0.86).r, amp_high);
133 float field = weave_field(point, bass, middle, treble, 0.0);
134 vec2 flow = vec2(cos(field * TAU), sin(field * TAU));
135 vec2 live_uv = tc + flow * field * (0.012 + bass * 0.04);
136 vec3 live = texture(samp, mirror_repeat(live_uv)).rgb;
137 float threads = pow(1.0 - abs(field), 9.0);
138 live += palette(field * 0.35 + time_f * 0.05) * threads *
139 (0.18 + treble * 0.38);
140
141 vec3 accumulated = live * 1.2;
142 float total_weight = 1.2;
143 for (int index = 0; index < SIZE; ++index) {
144 float age = float(index + 1) / float(max(SIZE, 1));
145 float old_bass = history_fft(index, 0.055);
146 float old_middle = history_fft(index, 0.38);
147 float old_treble = history_fft(index, 0.86);
148 float old_field = weave_field(point, old_bass, old_middle,
149 old_treble, age);
150 vec2 cache_uv = tc - center;
151 cache_uv = rotate_2d((old_middle - old_treble) * age * 0.7) * cache_uv;
152 cache_uv *= 1.0 - age * (0.07 + old_bass * 0.08);
153 cache_uv += vec2(old_field, -old_field) * age * 0.025;
154 cache_uv += center;
155 vec3 memory = sample_cache(index, cache_uv);
156 memory *= 0.65 + palette(old_field * 0.3 + age) * 0.62;
157 float old_threads = pow(1.0 - abs(old_field), 6.0);
158 memory += palette(age - time_f * 0.03) * old_threads * 0.12;
159 float weight = exp(-age * 2.5) * (0.7 + old_middle * 0.5);
160 accumulated += memory * weight;
161 total_weight += weight;
162 }
163
164 vec3 result = accumulated / total_weight;
165 result = mix(result, result.rbg, smoothstep(0.88, 1.0, amp_peak) * 0.65);
166 result = (result - 0.5) * (1.1 + amp_smooth * 0.28) + 0.5;
167 color = vec4(clamp(result, 0.0, 1.0), texture(samp, tc).a);
168}
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 weave_field(vec2 point, float bass, float middle, float treble, float age)