ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
code-compute-cache-block-frequency-crush.comp
Go to the documentation of this file.
1// Stateful cooperative compute effect inspired by shaders_new.
2#version 450
3
4/**
5 * @file code-compute-cache-block-frequency-crush.comp
6 * @brief Vulkan compute shader: code-compute-cache-block-frequency-crush.
7 */
8layout(set = 0, binding = 1, std140) uniform SpriteExtended {
9 vec4 mouse;
10 vec4 u0;
11 vec4 u1;
12 vec4 u2;
13 vec4 u3;
14 vec4 custom_uniforms[16];
15 vec4 audio_bands;
16 vec4 audio_history;
18#define alpha ext.u0.x
19#define history_head int(ext.u3.x)
20#define iFrame int(ext.u2.x)
21#define time_f ext.u2.y
22
23layout(local_size_x = 8, local_size_y = 8) in;
24layout(set = 0, binding = 5, rgba8) writeonly uniform image2D outputImage;
25layout(set = 0, binding = 0) uniform sampler2D samp;
26
27
28
29#ifndef SIZE
30#define SIZE 8
31#endif
32#ifndef USE_HISTORY_TEXTURE_ARRAY
33#define USE_HISTORY_TEXTURE_ARRAY 1
34#endif
35#if USE_HISTORY_TEXTURE_ARRAY
36layout(set = 0, binding = 2) uniform sampler2DArray history;
37
38#else
39uniform sampler2D textures[SIZE];
40#endif
41shared vec4 tile[10][10];
42/**
43 * @brief Evaluates clamp position for this shader effect.
44 * @param p Input value for the calculation.
45 * @param s Input value for the calculation.
46 * @return Computed ivec2 value.
47 */
48ivec2 clamp_position(ivec2 p, ivec2 s) { return clamp(p, ivec2(0), s - 1); }
49/**
50 * @brief Evaluates source at for this shader effect.
51 * @param p Input value for the calculation.
52 * @param s Input value for the calculation.
53 * @return Computed vec4 value.
54 */
55vec4 source_at(ivec2 p, ivec2 s) {
56 vec2 uv = (vec2(clamp_position(p, s)) + 0.5) / vec2(s);
57 return textureLod(samp, uv, 0.0);
58}
59/**
60 * @brief Evaluates history at for this shader effect.
61 * @param index Input value for the calculation.
62 * @param p Input value for the calculation.
63 * @param s Input value for the calculation.
64 * @return Computed vec4 value.
65 */
66vec4 history_at(int index, ivec2 p, ivec2 s) {
67 vec2 uv = (vec2(clamp_position(p, s)) + 0.5) / vec2(s);
68 index = clamp(index, 0, min(SIZE, 8) - 1);
69#if USE_HISTORY_TEXTURE_ARRAY
70 return textureLod(history, vec3(uv, float((history_head + index) % SIZE)), 0.0);
71#else
72 if (index == 0) return textureLod(textures[0], uv, 0.0);
73#if SIZE > 1
74 if (index == 1) return textureLod(textures[1], uv, 0.0);
75#endif
76#if SIZE > 2
77 if (index == 2) return textureLod(textures[2], uv, 0.0);
78#endif
79#if SIZE > 3
80 if (index == 3) return textureLod(textures[3], uv, 0.0);
81#endif
82#if SIZE > 4
83 if (index == 4) return textureLod(textures[4], uv, 0.0);
84#endif
85#if SIZE > 5
86 if (index == 5) return textureLod(textures[5], uv, 0.0);
87#endif
88#if SIZE > 6
89 if (index == 6) return textureLod(textures[6], uv, 0.0);
90#endif
91#if SIZE > 7
92 return textureLod(textures[7], uv, 0.0);
93#else
94 return textureLod(textures[0], uv, 0.0);
95#endif
96#endif
97}
98/**
99 * @brief Evaluates luminance for this shader effect.
100 * @param c Input value for the calculation.
101 * @return Computed float value.
102 */
103float luminance(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
104/**
105 * @brief Evaluates acid palette for this shader effect.
106 * @param p Input value for the calculation.
107 * @return Computed vec3 value.
108 */
109vec3 acid_palette(float p) { return 0.5 + 0.5 * cos(6.2831853 * (p + vec3(0.08, 0.42, 0.76))); }
110/**
111 * @brief Evaluates load tile for this shader effect.
112 * @param size Input value for the calculation.
113 */
114void load_tile(ivec2 size) {
115 uint lane = gl_LocalInvocationIndex;
116 ivec2 origin = ivec2(gl_WorkGroupID.xy) * 8 - 1;
117 for (uint index = lane; index < 100u; index += 64u) {
118 ivec2 q = ivec2(int(index % 10u), int(index / 10u));
119 tile[q.y][q.x] = source_at(origin + q, size);
120 }
121 barrier();
122}
123shared vec4 dc_reduction[64];
124shared vec4 checker_reduction[64];
125/**
126 * @brief Executes the compute shader entry point.
127 */
128void main() {
129 ivec2 size = imageSize(outputImage);
130 load_tile(size);
131 uint lane = gl_LocalInvocationIndex;
132 ivec2 local_id = ivec2(gl_LocalInvocationID.xy);
133 ivec2 q = local_id + 1;
134 ivec2 pixel = ivec2(gl_GlobalInvocationID.xy);
135 vec4 value = tile[q.y][q.x];
136 float checker = ((local_id.x + local_id.y) & 1) == 0 ? 1.0 : -1.0;
137 dc_reduction[lane] = value;
138 checker_reduction[lane] = value * checker;
139 barrier();
140 for (uint stride = 32u; stride > 0u; stride >>= 1u) {
141 if (lane < stride) {
142 dc_reduction[lane] += dc_reduction[lane + stride];
143 checker_reduction[lane] += checker_reduction[lane + stride];
144 }
145 barrier();
146 }
147 if (any(greaterThanEqual(pixel, size))) return;
148 vec3 dc = dc_reduction[0].rgb / 64.0;
149 vec3 high_frequency = checker_reduction[0].rgb / 64.0;
150 float quantization = 3.0 + floor(10.0 * alpha);
151 high_frequency = floor(high_frequency * quantization + 0.5) / quantization;
152 vec3 reconstructed = dc + high_frequency * checker * 2.5;
153 vec3 memory = history_at((iFrame / 4) % min(SIZE, 8), pixel, size).rgb;
154 vec3 result = mix(reconstructed, memory, 0.2);
155 result *= 0.7 + 0.5 * acid_palette(luminance(high_frequency) * 3.0 + time_f * 0.03);
156 imageStore(outputImage, pixel, vec4(clamp(result, 0.0, 1.0), 1.0));
157}
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 history_head
#define SIZE
vec3 source_at(vec2 position, ivec2 size)
Evaluates source at for this shader effect.
vec3 acid_palette(float phase, float hue_offset)
Evaluates acid palette for this shader effect.
#define iFrame
Definition auraXi1.frag:18
ivec2 clamp_position(ivec2 p, ivec2 s)
Evaluates clamp position for this shader effect.
vec4 history_at(int index, ivec2 p, ivec2 s)
Evaluates history at for this shader effect.
shared vec4 checker_reduction[64]
shared vec4 tile[10][10]
void load_tile(ivec2 size)
Evaluates load tile for this shader effect.
float luminance(vec3 c)
Evaluates luminance for this shader effect.
#define alpha
Definition color_g.frag:17