ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
acidcam_003_combine_pixels.comp
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file acidcam_003_combine_pixels.comp
5 * @brief Vulkan compute shader: acidcam 003 combine pixels.
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
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
24
25const float INV_255 = 1.0 / 255.0;
26
27/**
28 * @brief Evaluates clampPos for this shader effect.
29 * @param p Input value for the calculation.
30 * @param size Input value for the calculation.
31 * @return Computed ivec2 value.
32 */
33ivec2 clampPos(ivec2 p, ivec2 size) {
34 return clamp(p, ivec2(0), size - ivec2(1));
35}
36
37/**
38 * @brief Evaluates pixelUv for this shader effect.
39 * @param p Input value for the calculation.
40 * @param size Input value for the calculation.
41 * @return Computed vec2 value.
42 */
43vec2 pixelUv(ivec2 p, ivec2 size) {
44 return (vec2(clampPos(p, size)) + 0.5) / vec2(size);
45}
46
47/**
48 * @brief Evaluates sampleSource for this shader effect.
49 * @param p Input value for the calculation.
50 * @param size Input value for the calculation.
51 * @return Computed vec3 value.
52 */
53vec3 sampleSource(ivec2 p, ivec2 size) {
54 return textureLod(samp, pixelUv(p, size), 0.0).rgb;
55}
56
57/**
58 * @brief Evaluates toU8 for this shader effect.
59 * @param color Input value for the calculation.
60 * @return Computed uvec3 value.
61 */
62uvec3 toU8(vec3 color) {
63 return uvec3(clamp(color * 255.0 + 0.5, 0.0, 255.0));
64}
65
66/**
67 * @brief Evaluates toRGB for this shader effect.
68 * @param color Input value for the calculation.
69 * @return Computed vec3 value.
70 */
71vec3 toRGB(uvec3 color) {
72 return vec3(color) * INV_255;
73}
74
75/**
76 * @brief Evaluates sampleSourceU8 for this shader effect.
77 * @param p Input value for the calculation.
78 * @param size Input value for the calculation.
79 * @return Computed uvec3 value.
80 */
81uvec3 sampleSourceU8(ivec2 p, ivec2 size) {
82 return toU8(sampleSource(p, size));
83}
84
85/**
86 * @brief Evaluates mul8 for this shader effect.
87 * @param value Input value for the calculation.
88 * @param scale Input value for the calculation.
89 * @return Computed uvec3 value.
90 */
91uvec3 mul8(uvec3 value, int scale) {
92 return (value * uint(max(scale, 1))) & uvec3(255u);
93}
94
95/**
96 * @brief Evaluates effectBlockSize for this shader effect.
97 * @return Computed int value.
98 */
100 return max(int(round(mix(2.0, 64.0, clamp(alpha, 0.0, 1.0)))), 1);
101}
102
103/**
104 * @brief Evaluates combinePixels for this shader effect.
105 * @param p Input value for the calculation.
106 * @param size Input value for the calculation.
107 * @return Computed vec3 value.
108 */
109vec3 combinePixels(ivec2 p, ivec2 size) {
110 uvec3 current = sampleSourceU8(p, size);
111 uvec3 neighbors = sampleSourceU8(p + ivec2(1, 0), size) +
112 sampleSourceU8(p + ivec2(0, 1), size) +
113 sampleSourceU8(p + ivec2(1, 1), size);
114 uvec3 scaled = mul8(current ^ neighbors, effectBlockSize());
115 return toRGB((scaled >> 1) + (current >> 1));
116}
117
118/**
119 * @brief Executes the compute shader entry point.
120 */
121void main() {
122 ivec2 p = ivec2(gl_GlobalInvocationID.xy);
123 ivec2 size = imageSize(outputImage);
124 if (any(greaterThanEqual(p, size)))
125 return;
126 vec3 color = combinePixels(p, size);
127 imageStore(outputImage, p, vec4(clamp(color, 0.0, 1.0), 1.0));
128}
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
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 combinePixels(ivec2 p, ivec2 size)
Evaluates combinePixels for this shader effect.
#define alpha
Definition color_g.frag:17