ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
psyche-cache-code-plasma-time-flower.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file psyche-cache-code-plasma-time-flower.frag
5 * @brief Vulkan fragment shader: psyche-cache-code-plasma-time-flower.
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// Plasma petals open at different times across the audio-aligned cache.
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.17, 0.51, 0.86)));
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
111/**
112 * @brief Evaluates flower map for this shader effect.
113 * @param point Input value for the calculation.
114 * @param bass Input value for the calculation.
115 * @param middle Input value for the calculation.
116 * @param treble Input value for the calculation.
117 * @param age Input value for the calculation.
118 * @return Computed vec2 value.
119 */
120vec2 flower_map(vec2 point, float bass, float middle, float treble, float age) {
121 float radius = length(point) + 0.0001;
122 float angle = atan(point.y, point.x);
123 float petals = 7.0 + floor(treble * 6.0);
124 float envelope = 1.0 + cos(angle * petals - time_f * 1.2 - age * 8.0) *
125 (0.18 + middle * 0.16);
126 radius *= envelope;
127 angle += sin(radius * (11.0 + bass * 7.0) - time_f * 2.0) *
128 (0.15 + treble * 0.22);
129 return vec2(cos(angle), sin(angle)) * radius;
130}
131
132/**
133 * @brief Executes the fragment shader entry point.
134 */
135void main() {
136 vec2 resolution = max(iResolution, vec2(1.0));
137 float aspect = resolution.x / resolution.y;
138 vec2 center = iMouse.z > 0.0 ? iMouse.xy / resolution : vec2(0.5);
139 vec2 point = (tc - center) * vec2(aspect, 1.0);
140 float bass = max(texture(spectrum0, 0.028).r, amp_low);
141 float middle = max(texture(spectrum0, 0.27).r, amp_mid);
142 float treble = max(texture(spectrum0, 0.71).r, amp_high);
143 vec2 flower = flower_map(point, bass, middle, treble, 0.0);
144 float radius = length(flower) + 0.0001;
145 float angle = atan(flower.y, flower.x);
146 float plasma = sin(flower.x * (18.0 + treble * 9.0) + time_f * 2.4) +
147 cos(flower.y * (21.0 + middle * 8.0) - time_f * 1.9) +
148 sin(radius * (32.0 + bass * 20.0) - time_f * 6.0);
149 vec2 live_uv = flower / vec2(aspect, 1.0) + center;
150 live_uv += vec2(cos(plasma), sin(plasma)) * plasma *
151 (0.004 + bass * 0.012);
152 vec3 live = texture(samp, mirror_repeat(live_uv)).rgb;
153 live *= 0.68 + palette(plasma * 0.08 + time_f * 0.035) * 0.62;
154 float glow = pow(clamp(plasma / 3.0, 0.0, 1.0), 5.0);
155 live += palette(angle / TAU + radius) * glow * (0.14 + treble * 0.32);
156
157 vec3 accumulated = live * 1.2;
158 float total_weight = 1.2;
159 for (int index = 0; index < SIZE; ++index) {
160 float age = float(index + 1) / float(max(SIZE, 1));
161 float old_bass = history_fft(index, 0.028);
162 float old_middle = history_fft(index, 0.27);
163 float old_treble = history_fft(index, 0.71);
164 vec2 old_flower = flower_map(point, old_bass, old_middle,
165 old_treble, age);
166 old_flower = rotate_2d(age * (0.25 + old_middle * 0.6)) * old_flower;
167 old_flower *= 1.0 - age * (0.1 + old_bass * 0.07);
168 vec2 cache_uv = old_flower / vec2(aspect, 1.0) + center;
169 vec3 memory = sample_cache(index, cache_uv);
170 memory = mix(memory, abs(memory - live), old_treble * 0.3);
171 memory *= 0.66 + palette(age + length(old_flower)) * 0.59;
172 float weight = exp(-age * 2.2) * (0.7 + old_bass * 0.52);
173 accumulated += memory * weight;
174 total_weight += weight;
175 }
176
177 vec3 result = accumulated / total_weight;
178 result += palette(plasma * 0.06 + 0.5) * glow * amp_peak * 0.2;
179 result = (result - 0.5) * (1.1 + amp_smooth * 0.32) + 0.5;
180 color = vec4(clamp(result, 0.0, 1.0), texture(samp, tc).a);
181}
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 history_fft(int index, float frequency)
Evaluates history fft for this shader effect.
#define TAU
vec3 plasma(float t)
Evaluates plasma for this shader effect.
#define frequency
Definition ol.frag:13
vec2 flower_map(vec2 point, float bass, float middle, float treble, float age)
Evaluates flower map for this shader effect.