ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
energy-cache-code-quantum-surge.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file energy-cache-code-quantum-surge.frag
5 * @brief Vulkan fragment shader: energy-cache-code-quantum-surge.
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_peak ext.u2.w
18#define amp_smooth ext.u3.w
19#define history_head int(ext.u3.x)
20#define iResolution ext.u0.zw
21#define spectrum_history_head int(ext.audio_history.x)
22#define spectrum_history_size int(ext.audio_history.y)
23#define time_f ext.u2.y
24
25// Energy cache code: quantum wavefronts surge with peak inversion flashes.
26layout(location = 0) in vec2 tc;
27layout(location = 0) out vec4 color;
28layout(set = 0, binding = 0) uniform sampler2D samp;
29layout(set = 0, binding = 2) uniform sampler2DArray history;
30
31#ifndef SIZE
32#define SIZE 8
33#endif
34#ifndef CACHE_HISTORY_LAYER
35#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
36#endif
37layout(set = 0, binding = 3) uniform sampler1D spectrum0;
38layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
39
40
41#ifndef SPECTRUM_HISTORY_LAYER
42#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
43#endif
44
45
46
47
48const float TAU = 6.28318530718;
49
50/**
51 * @brief Evaluates mirror repeat for this shader effect.
52 * @param point Input value for the calculation.
53 * @return Computed vec2 value.
54 */
55vec2 mirror_repeat(vec2 point) { return 1.0 - abs(mod(point, 2.0) - 1.0); }
56/**
57 * @brief Evaluates palette for this shader effect.
58 * @param phase Input value for the calculation.
59 * @return Computed vec3 value.
60 */
61vec3 palette(float phase) { return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.01, 0.28, 0.64))); }
62/**
63 * @brief Evaluates sample cache for this shader effect.
64 * @param index Input value for the calculation.
65 * @param uv Input value for the calculation.
66 * @return Computed vec3 value.
67 */
68vec3 sample_cache(int index, vec2 uv) { return texture(history, vec3(mirror_repeat(uv), float(CACHE_HISTORY_LAYER(index)))).rgb; }
69/**
70 * @brief Evaluates history fft for this shader effect.
71 * @param index Input value for the calculation.
72 * @param frequency Input value for the calculation.
73 * @return Computed float value.
74 */
75float history_fft(int index, float frequency) {
76 int maximum_age = max(min(SIZE, spectrum_history_size) - 1, 0);
77 int age = min(index + 1, maximum_age);
78 return texture(spectrum_history, vec2(frequency, float(SPECTRUM_HISTORY_LAYER(age)))).r;
79}
80
81/**
82 * @brief Evaluates surge for this shader effect.
83 * @param point Input value for the calculation.
84 * @param bass Input value for the calculation.
85 * @param middle Input value for the calculation.
86 * @param high Input value for the calculation.
87 * @return Computed float value.
88 */
89float surge(vec2 point, float bass, float middle, float high) {
90 vec2 source_a = vec2(sin(time_f * 0.43), cos(time_f * 0.37)) * 0.31;
91 vec2 source_b = vec2(cos(time_f * 0.29), -sin(time_f * 0.53)) * 0.39;
92 vec2 source_c = vec2(-cos(time_f * 0.61), sin(time_f * 0.31)) * 0.26;
93 float a = sin(length(point - source_a) * (24.0 + bass * 16.0) - time_f * 6.0);
94 float b = sin(length(point - source_b) * (29.0 + middle * 14.0) - time_f * 5.0);
95 float c = sin(length(point - source_c) * (35.0 + high * 12.0) - time_f * 8.0);
96 return (a + b + c) / 3.0;
97}
98
99/**
100 * @brief Executes the fragment shader entry point.
101 */
102void main() {
103 vec2 resolution = max(iResolution, vec2(1.0));
104 vec2 aspect = vec2(resolution.x / resolution.y, 1.0);
105 vec2 point = (tc - 0.5) * aspect;
106 float bass = texture(spectrum0, 0.03).r;
107 float middle = texture(spectrum0, 0.23).r;
108 float high = texture(spectrum0, 0.67).r;
109 float wave = surge(point, bass, middle, high);
110 float crest = pow(max(wave, 0.0), 6.0) + pow(max(-wave, 0.0), 9.0) * 0.55;
111 vec2 warp = vec2(wave, surge(point.yx * 1.07 + 0.19, high, bass, middle)) * (0.035 + bass * 0.06);
112 vec3 live;
113 float chroma = crest * (0.018 + high * 0.045);
114 live.r = texture(samp, mirror_repeat(tc + warp + vec2(chroma, 0.0))).r;
115 live.g = texture(samp, mirror_repeat(tc + warp)).g;
116 live.b = texture(samp, mirror_repeat(tc + warp - vec2(chroma, 0.0))).b;
117 live *= 0.68 + palette(wave * 0.3 + time_f * 0.08) * 0.95;
118 live += palette(length(point) * 0.5 - time_f * 0.17) * crest * (0.9 + high * 2.7);
119
120 vec3 accumulated = live * 1.2;
121 float total_weight = 1.2;
122 for (int index = 0; index < SIZE; ++index) {
123 float generation = float(index + 1);
124 float age = generation / float(max(SIZE, 1));
125 vec3 old_audio = vec3(history_fft(index, 0.03), history_fft(index, 0.23), history_fft(index, 0.67));
126 float angle = generation * (0.02 + old_audio.z * 0.1) * sin(time_f * 0.35 + age * TAU);
127 float cosine = cos(angle);
128 float sine = sin(angle);
129 vec2 cache_point = mat2(cosine, -sine, sine, cosine) * point;
130 cache_point *= 1.0 - age * (0.09 + old_audio.x * 0.11);
131 cache_point += warp * age * (0.8 + old_audio.y);
132 vec3 memory = sample_cache(index, cache_point / aspect + 0.5);
133 memory *= palette(age * 0.7 + old_audio.y * 0.5 - time_f * 0.03);
134 float weight = pow(0.8, generation) * (0.72 + old_audio.x * 0.55);
135 accumulated += memory * weight;
136 total_weight += weight;
137 }
138 vec3 result = accumulated / total_weight;
139 result += palette(wave + time_f * 0.09) * crest * (0.4 + amp_peak * 1.6);
140 result = (result - 0.5) * (1.31 + amp_smooth * 0.3) + 0.5;
141 result = mix(result, vec3(1.0) - result, smoothstep(0.86, 1.0, amp_peak));
142 color = vec4(clamp(result, 0.0, 1.0), 1.0);
143}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
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 SIZE
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 amp_peak
#define spectrum_history_size
vec3 wave(ivec2 p, ivec2 size)
Evaluates wave for this shader effect.
vec2 warp(vec2 p, vec2 o, float k)
Evaluates warp for this shader effect.
float history_fft(int index, float frequency)
Evaluates history fft for this shader effect.
#define TAU
float surge(vec2 point, float bass, float middle, float high)
Evaluates surge for this shader effect.
#define frequency
Definition ol.frag:13