ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
ant_cache_spectrum8_caustic_storm.frag
Go to the documentation of this file.
1#version 450
2
3layout(set = 0, binding = 1, std140) uniform SpriteExtended {
4 vec4 mouse;
5 vec4 u0;
6 vec4 u1;
7 vec4 u2;
8 vec4 u3;
9 vec4 custom_uniforms[16];
10 vec4 audio_bands;
11 vec4 audio_history;
13#define amp_peak ext.u2.w
14#define amp_smooth ext.u3.w
15#define history_head int(ext.u3.x)
16#define iResolution ext.u0.zw
17#define iTime ext.u0.y
18#define spectrum_history_head int(ext.audio_history.x)
19#define spectrum_history_size int(ext.audio_history.y)
20
21/**
22 * @file ant_cache_spectrum8_caustic_storm.frag
23 * @brief Vulkan fragment shader: ant cache spectrum8 caustic storm.
24 */
25// ant_cache_spectrum8_caustic_storm
26// Underwater caustics with each layer warped by an older spectrum
27// Audio history (spectrum0..7) + Frame cache history (samp,samp1..samp8) - EXTREME
28layout(location = 0) in vec2 tc;
29layout(location = 0) out vec4 color;
30layout(set = 0, binding = 0) uniform sampler2D samp;
31layout(set = 0, binding = 2) uniform sampler2DArray history;
32
33#ifndef SIZE
34#define SIZE 8
35#endif
36#ifndef CACHE_HISTORY_LAYER
37#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
38#endif
39layout(set = 0, binding = 3) uniform sampler1D spectrum0;
40layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
41
42
43#ifndef SPECTRUM_HISTORY_LAYER
44#define SPECTRUM_HISTORY_LAYER(index) ((spectrum_history_head - ((index) % max(spectrum_history_size, 1)) + max(spectrum_history_size, 1)) % max(spectrum_history_size, 1))
45#endif
46
47
48
49
50
51const float TAU = 6.28318530718;
52const float PI = 3.14159265359;
53
54/**
55 * @brief Evaluates specHist for this shader effect.
56 * @param i Input value for the calculation.
57 * @param f Input value for the calculation.
58 * @return Computed float value.
59 */
60float specHist(int i, float f) {
61 if (i == 0) return texture(spectrum0, f).r;
62 if (i == 1) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(1)))).r;
63 if (i == 2) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(2)))).r;
64 if (i == 3) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(3)))).r;
65 if (i == 4) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(4)))).r;
66 if (i == 5) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(5)))).r;
67 if (i == 6) return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(6)))).r;
68 return texture(spectrum_history, vec2(f, float(SPECTRUM_HISTORY_LAYER(7)))).r;
69}
70
71/**
72 * @brief Evaluates cacheHist for this shader effect.
73 * @param i Input value for the calculation.
74 * @param uv Input value for the calculation.
75 * @return Computed vec4 value.
76 */
77vec4 cacheHist(int i, vec2 uv) {
78 if (i == 0) return texture(samp, uv);
79 if (i == 1) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(0))));
80 if (i == 2) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(1))));
81 if (i == 3) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(2))));
82 if (i == 4) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(3))));
83 if (i == 5) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(4))));
84 if (i == 6) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(5))));
85 if (i == 7) return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(6))));
86 return texture(history, vec3(uv, float(CACHE_HISTORY_LAYER(7))));
87}
88
89/**
90 * @brief Evaluates palette for this shader effect.
91 * @param t Input value for the calculation.
92 * @param d Input value for the calculation.
93 * @return Computed vec3 value.
94 */
95vec3 palette(float t, vec3 d) {
96 return 0.5 + 0.5 * cos(TAU * (vec3(1.0, 1.0, 1.0) * t + d));
97}
98
99/**
100 * @brief Evaluates hash for this shader effect.
101 * @param p Input value for the calculation.
102 * @return Computed float value.
103 */
104float hash(vec2 p) {
105 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
106}
107
108/**
109 * @brief Evaluates energy for this shader effect.
110 * @return Computed float value.
111 */
112float energy() {
113 float e = 0.0;
114 for (int i = 0; i < 8; i++) {
115 e += specHist(i, 0.05) + specHist(i, 0.25) + specHist(i, 0.6);
116 }
117 return e / 24.0;
118}
119
120/**
121 * @brief Executes the fragment shader entry point.
122 */
123void main() {
124 float aspect = iResolution.x / iResolution.y;
125 vec2 uv = (tc - 0.5) * vec2(aspect, 1.0);
126 float bass = texture(spectrum0, 0.03).r;
127 float mid = texture(spectrum0, 0.22).r;
128 float treble = texture(spectrum0, 0.58).r;
129 float air = texture(spectrum0, 0.85).r;
130 float e = energy();
131
132 vec3 acc = vec3(0.0);
133 for (int i = 0; i < 8; i++) {
134 float h = specHist(i, 0.1 + float(i) * 0.06);
135 vec2 p = uv;
136 for (int j = 0; j < 3; j++) {
137 float fj = float(j) + float(i) * 0.3;
138 p += 0.04 * vec2(sin(p.y * (5.0 + h * 20.0) + iTime + fj),
139 cos(p.x * (4.0 + h * 18.0) - iTime + fj));
140 }
141 float caustic = pow(max(sin(p.x * 10.0) + sin(p.y * 11.0) + sin((p.x + p.y) * 9.0), 0.0), 3.0);
142 vec2 suv = p / vec2(aspect, 1.0) + 0.5;
143 vec3 c = cacheHist(i, suv).rgb;
144 vec3 tint = palette(float(i) * 0.13 + h * 2.0, vec3(0.0, 0.4, 0.7));
145 acc += (tint * caustic + c * 0.5) * (1.0 + h * 5.0) * pow(0.83, float(i));
146 }
147 acc /= 3.0;
148 acc *= 1.3 + amp_smooth * 1.5;
149 color = vec4(clamp(acc, 0.0, 1.0), 1.0);
150}
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 amp_smooth
#define CACHE_HISTORY_LAYER(index)
vec3 palette(float phase)
Evaluates palette for this shader effect.
#define SPECTRUM_HISTORY_LAYER(index)
float hash(vec2 p)
Evaluates hash for this shader effect.
float specHist(int i, float f)
Evaluates specHist for this shader effect.
vec4 cacheHist(int i, vec2 uv)
Evaluates cacheHist for this shader effect.
float energy()
Evaluates energy for this shader effect.
float h(vec2 p)
Evaluates h for this shader effect.
#define TAU
#define PI
float caustic(vec2 p)
Evaluates caustic for this shader effect.