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.014 + 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 vec2
cell = floor((q + 1.0) * 4.0);
183 vec2 local = fract((q + 1.0) * 4.0) - 0.5;
184 local *= 1.0 + dot(local, local) * (0.8 + old_bass);
185 q = (
cell + local + 0.5) / 4.0 - 1.0;
198float concept_field(vec2 q,
float age,
float bass,
float middle,
float high) {
199 vec2
diamond = abs(fract(q * (7.0 + middle * 4.0)) - 0.5);
200 return exp(-abs(
diamond.x +
diamond.y - 0.33) * (36.0 + high * 18.0));
213 vec3 split = vec3(memory.r, live.g, memory.b);
222 vec2 aspect_scale = vec2(resolution.x / resolution.y, 1.0);
223 vec2 center =
iMouse.z > 0.0 ?
iMouse.xy / resolution : vec2(0.5);
224 vec2 point = (tc - center) * aspect_scale;
225 float bass = max(texture(spectrum0, 0.045).r,
amp_low);
226 float middle = max(texture(spectrum0, 0.32).r,
amp_mid);
227 float high = max(texture(spectrum0, 0.82).r,
amp_high);
228 vec3 current_audio = vec3(bass, middle, high);
230 vec2 live_q =
concept_space(point, 0.0, current_audio, bass, middle, high);
231 float live_field =
concept_field(live_q, 0.0, bass, middle, high);
232 vec3 live = texture(samp,
mirror_repeat(live_q / aspect_scale + center)).rgb;
233 vec3 accumulated = live * 1.2;
234 float total_weight = 1.2;
236 for (
int index = 0; index <
SIZE; ++index) {
237 float age = float(index + 1) / float(max(
SIZE, 1));
241 vec2 cache_q =
concept_space(point, age, old_audio, bass, middle, high);
243 vec3 memory =
sample_cache(index, cache_q / aspect_scale + center);
245 float weight = pow(1.0 - age * 0.8, 1.5) * (0.35 +
field * 0.75);
246 accumulated += treated * weight;
247 total_weight += weight;
250 vec3 result = accumulated / max(total_weight, 0.001);
251 result +=
palette(length(live_q) +
time_f * 0.04) * pow(live_field, 2.0) * 0.22;
252 result = (result - 0.5) * (1.04 +
amp_smooth * 0.18) + 0.5;
253 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 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.
float diamond(vec2 p)
Evaluates diamond for this shader effect.