ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
xorblend_cache.comp
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file xorblend_cache.comp
5 * @brief Vulkan compute shader: xorblend cache.
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 history_head int(ext.u3.x)
18
19
20layout(local_size_x = 16, local_size_y = 16) in;
21layout(set = 0, binding = 5, rgba8) writeonly uniform image2D outputImage;
22layout(set = 0, binding = 0) uniform sampler2D samp;
23
24const float INV_255 = 1.0 / 255.0;
25
26/**
27 * @brief Evaluates clampPos for this shader effect.
28 * @param p Input value for the calculation.
29 * @param size Input value for the calculation.
30 * @return Computed ivec2 value.
31 */
32ivec2 clampPos(ivec2 p, ivec2 size) {
33 return clamp(p, ivec2(0), size - ivec2(1));
34}
35
36/**
37 * @brief Evaluates pixelUv for this shader effect.
38 * @param p Input value for the calculation.
39 * @param size Input value for the calculation.
40 * @return Computed vec2 value.
41 */
42vec2 pixelUv(ivec2 p, ivec2 size) {
43 return (vec2(clampPos(p, size)) + 0.5) / vec2(size);
44}
45
46/**
47 * @brief Evaluates sampleSource for this shader effect.
48 * @param p Input value for the calculation.
49 * @param size Input value for the calculation.
50 * @return Computed vec3 value.
51 */
52vec3 sampleSource(ivec2 p, ivec2 size) {
53 return textureLod(samp, pixelUv(p, size), 0.0).rgb;
54}
55
56/**
57 * @brief Evaluates toU8 for this shader effect.
58 * @param color Input value for the calculation.
59 * @return Computed uvec3 value.
60 */
61uvec3 toU8(vec3 color) {
62 return uvec3(clamp(color * 255.0 + 0.5, 0.0, 255.0));
63}
64
65/**
66 * @brief Evaluates toRGB for this shader effect.
67 * @param color Input value for the calculation.
68 * @return Computed vec3 value.
69 */
70vec3 toRGB(uvec3 color) {
71 return vec3(color) * INV_255;
72}
73
74/**
75 * @brief Evaluates sampleSourceU8 for this shader effect.
76 * @param p Input value for the calculation.
77 * @param size Input value for the calculation.
78 * @return Computed uvec3 value.
79 */
80uvec3 sampleSourceU8(ivec2 p, ivec2 size) {
81 return toU8(sampleSource(p, size));
82}
83
84#ifndef SIZE
85#define SIZE 8
86#endif
87
88#ifndef USE_HISTORY_TEXTURE_ARRAY
89#define USE_HISTORY_TEXTURE_ARRAY 1
90#endif
91
92#if USE_HISTORY_TEXTURE_ARRAY
93layout(set = 0, binding = 2) uniform sampler2DArray history;
94
95#else
96uniform sampler2D textures[SIZE];
97#endif
98
99/**
100 * @brief Evaluates sampleHistory for this shader effect.
101 * @param index Input value for the calculation.
102 * @param p Input value for the calculation.
103 * @param size Input value for the calculation.
104 * @return Computed vec3 value.
105 */
106vec3 sampleHistory(int index, ivec2 p, ivec2 size) {
107 vec2 uv = pixelUv(p, size);
108 index = clamp(index, 0, SIZE - 1);
109#if USE_HISTORY_TEXTURE_ARRAY
110 int layer = (history_head + index) % SIZE;
111 return textureLod(history, vec3(uv, float(layer)), 0.0).rgb;
112#else
113 return textureLod(textures[index], uv, 0.0).rgb;
114#endif
115}
116
117/**
118 * @brief Evaluates sampleHistoryU8 for this shader effect.
119 * @param index Input value for the calculation.
120 * @param p Input value for the calculation.
121 * @param size Input value for the calculation.
122 * @return Computed uvec3 value.
123 */
124uvec3 sampleHistoryU8(int index, ivec2 p, ivec2 size) {
125 return toU8(sampleHistory(index, p, size));
126}
127
128/**
129 * @brief Evaluates xorHistory for this shader effect.
130 * @param p Input value for the calculation.
131 * @param size Input value for the calculation.
132 * @return Computed vec3 value.
133 */
134vec3 xorHistory(ivec2 p, ivec2 size) {
135 uvec3 accumulated = uvec3(0u);
136 for (int index = 0; index < SIZE; ++index)
137 accumulated += sampleHistoryU8(index, p, size);
138 uvec3 value = (accumulated + uvec3(1u)) & uvec3(255u);
139 return toRGB(sampleSourceU8(p, size) ^ value);
140}
141
142/**
143 * @brief Executes the compute shader entry point.
144 */
145void main() {
146 ivec2 p = ivec2(gl_GlobalInvocationID.xy);
147 ivec2 size = imageSize(outputImage);
148 if (any(greaterThanEqual(p, size)))
149 return;
150 vec3 color = xorHistory(p, size);
151 imageStore(outputImage, p, vec4(clamp(color, 0.0, 1.0), 1.0));
152}
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 history_head
#define SIZE
ivec2 clampPos(ivec2 p, ivec2 size)
Evaluates clampPos for this shader effect.
vec2 pixelUv(ivec2 p, ivec2 size)
Evaluates pixelUv for this shader effect.
vec3 sampleSource(ivec2 p, ivec2 size)
Evaluates sampleSource for this shader effect.
const float INV_255
uvec3 toU8(vec3 color)
Evaluates toU8 for this shader effect.
vec3 toRGB(uvec3 color)
Evaluates toRGB for this shader effect.
uvec3 sampleSourceU8(ivec2 p, ivec2 size)
Evaluates sampleSourceU8 for this shader effect.
uvec3 sampleHistoryU8(int index, ivec2 p, ivec2 size)
Evaluates sampleHistoryU8 for this shader effect.
float sampleHistory(int index, float frequency)
Evaluates sampleHistory for this shader effect.
vec3 xorHistory(ivec2 p, ivec2 size)
Evaluates xorHistory for this shader effect.