7layout(set = 0, binding = 1, std140) uniform SpriteExtended {
13 vec4 custom_uniforms[16];
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
32layout(location = 0) out vec4 color;
33layout(set = 0, binding = 0) uniform sampler2D samp;
34layout(set = 0, binding = 2) uniform sampler2DArray history;
39#ifndef CACHE_HISTORY_LAYER
40#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
42layout(set = 0, binding = 3) uniform sampler1D spectrum0;
43layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
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))
58const float TAU = 6.28318530718;
66 float cosine = cos(angle);
67 float sine = sin(angle);
68 return mat2(cosine, -sine, sine, cosine);
77 return 1.0 - abs(mod(point, 2.0) - 1.0);
86 return fract(sin(dot(point, vec2(127.1, 311.7))) * 43758.5453123);
95 vec2
cell = floor(point);
96 vec2 part = fract(point);
97 part = part * part * (3.0 - 2.0 * part);
109 vec2
cell = floor(point);
110 vec2 part = fract(point);
112 float second_nearest = 4.0;
113 float identity = 0.0;
114 for (
int y = -1; y <= 1; ++y) {
115 for (
int x = -1; x <= 1; ++x) {
116 vec2 offset = vec2(
float(x),
float(y));
118 float distance_to_seed = length(offset +
seed - part);
119 if (distance_to_seed < nearest) {
120 second_nearest = nearest;
121 nearest = distance_to_seed;
123 }
else if (distance_to_seed < second_nearest) {
124 second_nearest = distance_to_seed;
128 return vec3(nearest, second_nearest, identity);
137 const vec2 SCALE = vec2(1.0, 1.7320508);
138 vec2 first = mod(point, SCALE) - SCALE * 0.5;
139 vec2 second = mod(point - SCALE * 0.5, SCALE) - SCALE * 0.5;
140 return dot(first, first) < dot(second, second) ? first : second;
149 return 0.5 + 0.5 * cos(
TAU * (phase + 0.685 + vec3(0.04, 0.37, 0.69)));
171 int spectrum_age = min(index + 1, maximum_age);
172 return texture(spectrum_history,
177 float bass,
float middle,
float high) {
179 float old_bass = old_audio.x;
180 float old_mid = old_audio.y;
181 float old_high = old_audio.z;
182 q = abs(q) - vec2(0.22 + bass * 0.04);
183 q = abs(
rotate_2d(0.785 + age * 0.13) * q) - vec2(0.11);
184 q =
rotate_2d(old_mid * 0.4 - age * 0.25) * q;
197float concept_field(vec2 q,
float age,
float bass,
float middle,
float high) {
199 return exp(-abs(max(abs(
h.x), dot(abs(
h), vec2(0.5, 0.866))) - 0.42) * (34.0 + high * 18.0));
212 return memory * mix(vec3(0.65),
palette(old_audio.y + age), 0.72) +
213 abs(memory - live) *
field * 0.35;
221 vec2 aspect_scale = vec2(resolution.x / resolution.y, 1.0);
222 vec2 center =
iMouse.z > 0.0 ?
iMouse.xy / resolution : vec2(0.5);
223 vec2 point = (tc - center) * aspect_scale;
224 float bass = max(texture(spectrum0, 0.045).r,
amp_low);
225 float middle = max(texture(spectrum0, 0.32).r,
amp_mid);
226 float high = max(texture(spectrum0, 0.82).r,
amp_high);
227 vec3 current_audio = vec3(bass, middle, high);
229 vec2 live_q =
concept_space(point, 0.0, current_audio, bass, middle, high);
230 float live_field =
concept_field(live_q, 0.0, bass, middle, high);
231 vec3 live = texture(samp,
mirror_repeat(live_q / aspect_scale + center)).rgb;
232 vec3 accumulated = live * 1.2;
233 float total_weight = 1.2;
235 for (
int index = 0; index <
SIZE; ++index) {
236 float age = float(index + 1) / float(max(
SIZE, 1));
240 vec2 cache_q =
concept_space(point, age, old_audio, bass, middle, high);
242 vec3 memory =
sample_cache(index, cache_q / aspect_scale + center);
244 float weight = exp(-age * 2.8) * (0.72 + old_audio.x * 0.5 + old_audio.z * 0.2);
245 accumulated += treated * weight;
246 total_weight += weight;
249 vec3 result = accumulated / max(total_weight, 0.001);
250 result = mix(result, 1.0 - result.brg, live_field *
amp_peak * 0.18);
251 result = (result - 0.5) * (1.04 +
amp_smooth * 0.18) + 0.5;
252 color = vec4(clamp(result, 0.0, 1.0), texture(samp, tc).a);
layout(set=0, binding=1, std140) uniform SpriteExtended
void main(void)
Executes the fragment shader entry point.
#define CACHE_HISTORY_LAYER(index)
mat2 rotate_2d(float angle)
Evaluates rotate 2d for this shader effect.
float hash_21(vec2 point)
Evaluates hash 21 for this shader effect.
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 spectrum_history_size
float h(vec2 p)
Evaluates h for this shader effect.
float field(vec2 p, float tm)
Evaluates field for this shader effect.
vec2 hex_coord(vec2 point)
Evaluates hex coord for this shader effect.
float concept_field(vec2 q, float age, float bass, float middle, float high)
Evaluates concept field for this shader effect.
vec3 blend_memory(vec3 memory, vec3 live, float field, float age, vec3 old_audio)
Evaluates blend memory for this shader effect.
float noise_2d(vec2 point)
Evaluates noise 2d for this shader effect.
vec2 concept_space(vec2 point, float age, vec3 old_audio, float bass, float middle, float high)
vec3 voronoi_data(vec2 point)
Evaluates voronoi data for this shader effect.
float history_fft(int index, float frequency)
Evaluates history fft for this shader effect.
vec2 cell(vec2 p)
Evaluates cell for this shader effect.