ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
energy-cache-code-electric-tempest.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file energy-cache-code-electric-tempest.frag
5 * @brief Vulkan fragment shader: energy-cache-code-electric-tempest.
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: room-filling electric interference with audio-aged lightning trails.
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
48
49const float TAU = 6.28318530718;
50
51/**
52 * @brief Evaluates mirror repeat for this shader effect.
53 * @param point Input value for the calculation.
54 * @return Computed vec2 value.
55 */
56vec2 mirror_repeat(vec2 point) {
57 return 1.0 - abs(mod(point, 2.0) - 1.0);
58}
59
60/**
61 * @brief Evaluates palette for this shader effect.
62 * @param phase Input value for the calculation.
63 * @return Computed vec3 value.
64 */
65vec3 palette(float phase) {
66 return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.02, 0.31, 0.67)));
67}
68
69/**
70 * @brief Evaluates sample cache for this shader effect.
71 * @param index Input value for the calculation.
72 * @param uv Input value for the calculation.
73 * @return Computed vec3 value.
74 */
75vec3 sample_cache(int index, vec2 uv) {
76 return texture(history, vec3(mirror_repeat(uv), float(CACHE_HISTORY_LAYER(index)))).rgb;
77}
78
79/**
80 * @brief Evaluates history fft for this shader effect.
81 * @param index Input value for the calculation.
82 * @param frequency Input value for the calculation.
83 * @return Computed float value.
84 */
85float history_fft(int index, float frequency) {
86 int maximum_age = max(min(SIZE, spectrum_history_size) - 1, 0);
87 int age = min(index + 1, maximum_age);
88 return texture(spectrum_history, vec2(frequency, float(SPECTRUM_HISTORY_LAYER(age)))).r;
89}
90
91/**
92 * @brief Evaluates tempest for this shader effect.
93 * @param point Input value for the calculation.
94 * @param bass Input value for the calculation.
95 * @param high Input value for the calculation.
96 * @return Computed float value.
97 */
98float tempest(vec2 point, float bass, float high) {
99 float first = sin(length(point - vec2(sin(time_f * 0.41), cos(time_f * 0.33)) * 0.38) * (25.0 + bass * 18.0) - time_f * 7.0);
100 float second = sin(length(point + vec2(cos(time_f * 0.29), sin(time_f * 0.47)) * 0.42) * (31.0 + high * 15.0) + time_f * 5.0);
101 float crossing = sin(point.x * 42.0 + sin(point.y * 13.0 - time_f * 4.0) * 4.0);
102 return (first + second + crossing) / 3.0;
103}
104
105/**
106 * @brief Executes the fragment shader entry point.
107 */
108void main() {
109 vec2 resolution = max(iResolution, vec2(1.0));
110 vec2 aspect = vec2(resolution.x / resolution.y, 1.0);
111 vec2 point = (tc - 0.5) * aspect;
112 float bass = texture(spectrum0, 0.035).r;
113 float middle = texture(spectrum0, 0.28).r;
114 float high = texture(spectrum0, 0.76).r;
115 float field = tempest(point, bass, high);
116 vec2 distortion = vec2(field, tempest(point.yx + 0.17, middle, bass)) * (0.025 + bass * 0.045);
117 vec3 live = texture(samp, mirror_repeat(tc + distortion)).rgb;
118 float bolt = pow(1.0 - abs(field), 14.0);
119 live += palette(field * 0.3 + time_f * 0.08) * bolt * (1.2 + high * 3.0);
120
121 vec3 accumulated = live * 1.25;
122 float total_weight = 1.25;
123 for (int index = 0; index < SIZE; ++index) {
124 float generation = float(index + 1);
125 float age = generation / float(max(SIZE, 1));
126 vec3 old_audio = vec3(history_fft(index, 0.035), history_fft(index, 0.28), history_fft(index, 0.76));
127 float angle = generation * (0.018 + old_audio.z * 0.11) * sin(time_f * 0.23 + age * TAU);
128 float cosine = cos(angle);
129 float sine = sin(angle);
130 mat2 rotation = mat2(cosine, -sine, sine, cosine);
131 vec2 cache_point = rotation * point * (1.0 - age * (0.055 + old_audio.x * 0.09));
132 cache_point += distortion * generation * 0.28 + vec2(sine, cosine) * old_audio.y * 0.018;
133 vec2 cache_uv = cache_point / aspect + 0.5;
134 vec3 memory = sample_cache(index, cache_uv) * palette(age * 0.62 + old_audio.y * 0.4);
135 float weight = exp(-age * (1.8 - amp_smooth * 0.4));
136 accumulated += memory * weight;
137 total_weight += weight;
138 }
139
140 vec3 result = accumulated / total_weight;
141 result += palette(length(point) - time_f * 0.12) * bolt * (0.45 + amp_peak);
142 result = (result - 0.5) * (1.25 + amp_smooth * 0.3) + 0.5;
143 result = mix(result, 1.0 - result, smoothstep(0.88, 1.0, amp_peak));
144 color = vec4(clamp(result, 0.0, 1.0), 1.0);
145}
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
float field(vec2 p, float tm)
Evaluates field for this shader effect.
float history_fft(int index, float frequency)
Evaluates history fft for this shader effect.
#define TAU
float tempest(vec2 point, float bass, float high)
Evaluates tempest for this shader effect.
#define frequency
Definition ol.frag:13
mat2 rotation(float angle)
Evaluates rotation for this shader effect.