ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
trail-cache-code-diamond-rain.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file trail-cache-code-diamond-rain.frag
5 * @brief Vulkan fragment shader: trail-cache-code-diamond-rain.
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_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
28
29// Falling diamond cells refract and stagger temporal color trails.
30#define EFFECT_ID 46
31layout(location = 0) in vec2 tc;
32layout(location = 0) out vec4 color;
33layout(set = 0, binding = 0) uniform sampler2D samp;
34layout(set = 0, binding = 2) uniform sampler2DArray history;
35
36#ifndef SIZE
37#define SIZE 8
38#endif
39#ifndef CACHE_HISTORY_LAYER
40#define CACHE_HISTORY_LAYER(index) ((history_head + (index)) % SIZE)
41#endif
42layout(set = 0, binding = 3) uniform sampler1D spectrum0;
43layout(set = 0, binding = 4) uniform sampler1DArray spectrum_history;
44
45
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))
48#endif
49
50
51
52
53
54
55
56
57
58const float TAU = 6.28318530718;
59
60/**
61 * @brief Evaluates mirror repeat for this shader effect.
62 * @param point Input value for the calculation.
63 * @return Computed vec2 value.
64 */
65vec2 mirror_repeat(vec2 point) {
66 return 1.0 - abs(mod(point, 2.0) - 1.0);
67}
68
69/**
70 * @brief Evaluates hash 1d for this shader effect.
71 * @param value Input value for the calculation.
72 * @return Computed float value.
73 */
74float hash_1d(float value) {
75 return fract(sin(value * 127.1) * 43758.5453);
76}
77
78/**
79 * @brief Evaluates palette for this shader effect.
80 * @param phase Input value for the calculation.
81 * @return Computed vec3 value.
82 */
83vec3 palette(float phase) {
84 return 0.5 + 0.5 * cos(TAU * (phase + vec3(0.13, 0.47, 0.81)));
85}
86
87/**
88 * @brief Evaluates sample cache for this shader effect.
89 * @param index Input value for the calculation.
90 * @param uv Input value for the calculation.
91 * @return Computed vec4 value.
92 */
93vec4 sample_cache(int index, vec2 uv) {
94 return texture(history, vec3(mirror_repeat(uv), float(CACHE_HISTORY_LAYER(index))));
95}
96
97/**
98 * @brief Evaluates sample history for this shader effect.
99 * @param index Input value for the calculation.
100 * @param frequency Input value for the calculation.
101 * @return Computed float value.
102 */
103float sample_history(int index, float frequency) {
104 int max_age = max(min(SIZE, spectrum_history_size) - 1, 0);
105 int age = min(index + 1, max_age);
106 return texture(spectrum_history, vec2(frequency, float(SPECTRUM_HISTORY_LAYER(age)))).r;
107}
108
109/**
110 * @brief Evaluates diamond warp for this shader effect.
111 * @param uv Input value for the calculation.
112 * @param depth Input value for the calculation.
113 * @param bass Input value for the calculation.
114 * @param high Input value for the calculation.
115 * @return Computed vec2 value.
116 */
117vec2 diamond_warp(vec2 uv, float depth, float bass, float high) {
118 float column = floor(uv.x * 12.0);
119 float speed = 0.18 + hash_1d(column) * 0.35 + bass * 0.5;
120 uv.y += time_f * speed * depth;
121 vec2 cell = fract(uv * vec2(12.0, 8.0)) - 0.5;
122 float diamond = abs(cell.x) + abs(cell.y);
123 uv.x += sign(cell.x) * (1.0 - smoothstep(0.0, 0.5, diamond)) * high * depth * 0.025;
124 uv.y -= depth * (0.02 + bass * 0.08);
125 return uv;
126}
127
128/**
129 * @brief Executes the fragment shader entry point.
130 */
131void main() {
132 vec4 live = texture(samp, tc);
133 vec3 accumulated = live.rgb;
134 float total_weight = 1.0;
135
136 for (int index = 0; index < SIZE; ++index) {
137 float depth = float(index) / float(max(SIZE - 1, 1));
138 float bass = sample_history(index, 0.03);
139 float high = sample_history(index, 0.61);
140 vec2 uv = diamond_warp(tc, depth, bass, high);
141 vec2 cell = abs(fract(uv * vec2(12.0, 8.0)) - 0.5);
142 float gem = 1.0 - smoothstep(0.28, 0.55, cell.x + cell.y);
143 float weight = mix(0.06, 0.5, depth) * (0.5 + gem * 0.8);
144 vec3 cached = sample_cache(index, uv).rgb;
145 accumulated += mix(cached, cached.rbg * palette(depth + high), 0.56) * weight;
146 total_weight += weight;
147 }
148
149 vec3 result = accumulated / total_weight;
150 result += palette(tc.y + time_f * 0.08) * amp_peak * 0.1;
151 result = (result - 0.5) * (1.12 + amp_smooth * 0.24) + 0.5;
152 color = vec4(clamp(result, 0.0, 1.0), live.a);
153}
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 time_f
Definition 3high.frag:19
#define amp_smooth
#define CACHE_HISTORY_LAYER(index)
float sample_history(int index, float frequency)
Evaluates sample history for this shader effect.
#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 gem(float t)
Evaluates gem for this shader effect.
vec2 cell(vec2 p)
Evaluates cell for this shader effect.
#define TAU
float diamond(vec2 p)
Evaluates diamond for this shader effect.
Definition dmd_gpt.frag:29
#define frequency
Definition ol.frag:13
float hash_1d(float value)
Evaluates hash 1d for this shader effect.
vec2 diamond_warp(vec2 uv, float depth, float bass, float high)
Evaluates diamond warp for this shader effect.