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