ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
psyche-cache-code-fractal-sonar-orchid.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file psyche-cache-code-fractal-sonar-orchid.frag
5 * @brief Vulkan fragment shader: psyche-cache-code-fractal-sonar-orchid.
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// Recursive orchid folds pulse outward as spectrum-shaped sonar.
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.2, 0.5, 0.83)));
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 orchid fold for this shader effect.
113 * @param point Input value for the calculation.
114 * @param middle Input value for the calculation.
115 * @param age Input value for the calculation.
116 * @return Computed vec2 value.
117 */
118vec2 orchid_fold(vec2 point, float middle, float age) {
119 for (int fold = 0; fold < 4; ++fold) {
120 point = abs(point) - vec2(0.22, 0.31);
121 point = rotate_2d(0.61 + middle * 0.3 + float(fold) * 0.17 +
122 age * 0.2) * point;
123 point /= max(dot(point, point), 0.42);
124 point *= 0.66;
125 }
126 return point;
127}
128
129/**
130 * @brief Executes the fragment shader entry point.
131 */
132void main() {
133 vec2 resolution = max(iResolution, vec2(1.0));
134 float aspect = resolution.x / resolution.y;
135 vec2 center = iMouse.z > 0.0 ? iMouse.xy / resolution : vec2(0.5);
136 vec2 point = (tc - center) * vec2(aspect, 1.0);
137 float bass = max(texture(spectrum0, 0.04).r, amp_low);
138 float middle = max(texture(spectrum0, 0.31).r, amp_mid);
139 float treble = max(texture(spectrum0, 0.77).r, amp_high);
140 vec2 orchid = orchid_fold(point, middle, 0.0);
141 float radius = length(orchid) + 0.0001;
142 float angle = atan(orchid.y, orchid.x);
143 float sonar = sin(radius * (45.0 + bass * 28.0) - time_f * 8.0);
144 float petals = pow(abs(cos(angle * (5.0 + floor(treble * 5.0)))), 7.0);
145 vec2 live_uv = tc + normalize(orchid) * sonar * petals *
146 (0.015 + bass * 0.04);
147 vec3 live = texture(samp, mirror_repeat(live_uv)).rgb;
148 live += palette(angle / TAU + radius - time_f * 0.05) * petals *
149 pow(max(sonar, 0.0), 7.0) * (0.16 + treble * 0.34);
150
151 vec3 accumulated = live * 1.2;
152 float total_weight = 1.2;
153 for (int index = 0; index < SIZE; ++index) {
154 float age = float(index + 1) / float(max(SIZE, 1));
155 float old_bass = history_fft(index, 0.04);
156 float old_middle = history_fft(index, 0.31);
157 float old_treble = history_fft(index, 0.77);
158 vec2 old_orchid = orchid_fold(point, old_middle, age);
159 float old_radius = length(old_orchid) + 0.0001;
160 float echo = sin(old_radius * (42.0 + old_bass * 26.0) - age * 19.0);
161 vec2 cache_uv = tc + normalize(old_orchid) * echo *
162 (0.008 + old_bass * 0.025) * age;
163 cache_uv = (rotate_2d(age * old_treble * 0.8) *
164 (cache_uv - center)) * (1.0 - age * 0.08) + center;
165 vec3 memory = sample_cache(index, cache_uv);
166 memory *= 0.65 + palette(old_radius + age) * 0.58;
167 float weight = exp(-age * 2.25) * (0.68 + old_bass * 0.55);
168 accumulated += memory * weight;
169 total_weight += weight;
170 }
171
172 vec3 result = accumulated / total_weight;
173 result += palette(angle / TAU + time_f * 0.04) * amp_peak * petals * 0.18;
174 result = (result - 0.5) * (1.1 + amp_smooth * 0.32) + 0.5;
175 color = vec4(clamp(result, 0.0, 1.0), texture(samp, tc).a);
176}
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
vec2 fold(vec2 uv, float zoom, float t, vec2 c, float aspect)
Evaluates fold for this shader effect.
#define frequency
Definition ol.frag:13
vec2 orchid_fold(vec2 point, float middle, float age)
Evaluates orchid fold for this shader effect.