ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
acidcam_011_dynamic_kaleidoscope.comp
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file acidcam_011_dynamic_kaleidoscope.comp
5 * @brief Vulkan compute shader: acidcam 011 dynamic kaleidoscope.
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 iFrame int(ext.u2.x)
19
20
21layout(local_size_x = 16, local_size_y = 16) in;
22layout(set = 0, binding = 5, rgba8) writeonly uniform image2D outputImage;
23layout(set = 0, binding = 0) uniform sampler2D samp;
24
25
26
27const float TAU = 6.28318530718;
28
29/**
30 * @brief Evaluates clampPos for this shader effect.
31 * @param p Input value for the calculation.
32 * @param size Input value for the calculation.
33 * @return Computed ivec2 value.
34 */
35ivec2 clampPos(ivec2 p, ivec2 size) {
36 return clamp(p, ivec2(0), size - ivec2(1));
37}
38
39/**
40 * @brief Evaluates pixelUv for this shader effect.
41 * @param p Input value for the calculation.
42 * @param size Input value for the calculation.
43 * @return Computed vec2 value.
44 */
45vec2 pixelUv(ivec2 p, ivec2 size) {
46 return (vec2(clampPos(p, size)) + 0.5) / vec2(size);
47}
48
49/**
50 * @brief Evaluates sampleSource for this shader effect.
51 * @param p Input value for the calculation.
52 * @param size Input value for the calculation.
53 * @return Computed vec3 value.
54 */
55vec3 sampleSource(ivec2 p, ivec2 size) {
56 return textureLod(samp, pixelUv(p, size), 0.0).rgb;
57}
58
59/**
60 * @brief Evaluates effectDirection for this shader effect.
61 * @return Computed int value.
62 */
64 return ((iFrame / 8) & 1) == 0 ? 1 : -1;
65}
66
67/**
68 * @brief Evaluates hueRotate for this shader effect.
69 * @param color Input value for the calculation.
70 * @param angle Input value for the calculation.
71 * @return Computed vec3 value.
72 */
73vec3 hueRotate(vec3 color, float angle) {
74 vec3 axis = normalize(vec3(1.0));
75 float sine = sin(angle);
76 float cosine = cos(angle);
77 return clamp(color * cosine + cross(axis, color) * sine +
78 axis * dot(axis, color) * (1.0 - cosine),
79 0.0, 1.0);
80}
81
82/**
83 * @brief Evaluates kaleidoscope for this shader effect.
84 * @param p Input value for the calculation.
85 * @param size Input value for the calculation.
86 * @param segments Input value for the calculation.
87 * @return Computed vec3 value.
88 */
89vec3 kaleidoscope(ivec2 p, ivec2 size, int segments) {
90 vec2 center = vec2(size) * 0.5;
91 vec2 delta = vec2(p) - center;
92 float angle = atan(delta.y, delta.x);
93 float slice = TAU / max(float(segments), 1.0);
94 angle = mod(angle, slice);
95 if (angle > slice * 0.5)
96 angle = slice - angle;
97 return sampleSource(ivec2(center + vec2(cos(angle), sin(angle)) * length(delta)), size);
98}
99
100/**
101 * @brief Evaluates dynamicKaleidoscope for this shader effect.
102 * @param p Input value for the calculation.
103 * @param size Input value for the calculation.
104 * @return Computed vec3 value.
105 */
106vec3 dynamicKaleidoscope(ivec2 p, ivec2 size) {
107 int segments = 4 + abs((iFrame / 8) % 6);
108 vec3 color = kaleidoscope(p, size, segments);
109 return mix(color, hueRotate(color, float(effectDirection()) * 0.7),
110 clamp(alpha, 0.0, 1.0));
111}
112
113/**
114 * @brief Executes the compute shader entry point.
115 */
116void main() {
117 ivec2 p = ivec2(gl_GlobalInvocationID.xy);
118 ivec2 size = imageSize(outputImage);
119 if (any(greaterThanEqual(p, size)))
120 return;
121 vec3 color = dynamicKaleidoscope(p, size);
122 imageStore(outputImage, p, vec4(clamp(color, 0.0, 1.0), 1.0));
123}
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
vec2 kaleidoscope(vec2 point, float sides)
Evaluates kaleidoscope for this shader effect.
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.
int effectDirection()
Evaluates effectDirection for this shader effect.
vec3 hueRotate(vec3 color, float angle)
Evaluates hueRotate for this shader effect.
vec3 dynamicKaleidoscope(ivec2 p, ivec2 size)
Evaluates dynamicKaleidoscope for this shader effect.
#define iFrame
Definition auraXi1.frag:18
#define alpha
Definition color_g.frag:17
#define TAU