ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
acidcam_032_twirl.comp
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file acidcam_032_twirl.comp
5 * @brief Vulkan compute shader: acidcam 032 twirl.
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 iTime ext.u0.y
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
25/**
26 * @brief Evaluates clampPos for this shader effect.
27 * @param p Input value for the calculation.
28 * @param size Input value for the calculation.
29 * @return Computed ivec2 value.
30 */
31ivec2 clampPos(ivec2 p, ivec2 size) {
32 return clamp(p, ivec2(0), size - ivec2(1));
33}
34
35/**
36 * @brief Evaluates pixelUv for this shader effect.
37 * @param p Input value for the calculation.
38 * @param size Input value for the calculation.
39 * @return Computed vec2 value.
40 */
41vec2 pixelUv(ivec2 p, ivec2 size) {
42 return (vec2(clampPos(p, size)) + 0.5) / vec2(size);
43}
44
45/**
46 * @brief Evaluates sampleSource for this shader effect.
47 * @param p Input value for the calculation.
48 * @param size Input value for the calculation.
49 * @return Computed vec3 value.
50 */
51vec3 sampleSource(ivec2 p, ivec2 size) {
52 return textureLod(samp, pixelUv(p, size), 0.0).rgb;
53}
54
55/**
56 * @brief Evaluates rot2 for this shader effect.
57 * @param p Input value for the calculation.
58 * @param angle Input value for the calculation.
59 * @return Computed vec2 value.
60 */
61vec2 rot2(vec2 p, float angle) {
62 float sine = sin(angle);
63 float cosine = cos(angle);
64 return mat2(cosine, -sine, sine, cosine) * p;
65}
66
67/**
68 * @brief Evaluates twirl for this shader effect.
69 * @param p Input value for the calculation.
70 * @param size Input value for the calculation.
71 * @return Computed vec3 value.
72 */
73vec3 twirl(ivec2 p, ivec2 size) {
74 vec2 center = vec2(size) * 0.5;
75 vec2 delta = vec2(p) - center;
76 float distanceFromCenter = length(delta) / max(length(center), 1.0);
77 return sampleSource(ivec2(center + rot2(delta, distanceFromCenter * 2.8 + iTime * 0.25)), size);
78}
79
80/**
81 * @brief Executes the compute shader entry point.
82 */
83void main() {
84 ivec2 p = ivec2(gl_GlobalInvocationID.xy);
85 ivec2 size = imageSize(outputImage);
86 if (any(greaterThanEqual(p, size)))
87 return;
88 vec3 color = twirl(p, size);
89 imageStore(outputImage, p, vec4(clamp(color, 0.0, 1.0), 1.0));
90}
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.
vec2 pixelUv(ivec2 p, ivec2 size)
Evaluates pixelUv for this shader effect.
vec3 sampleSource(ivec2 p, ivec2 size)
Evaluates sampleSource for this shader effect.
vec3 twirl(ivec2 p, ivec2 size)
Evaluates twirl for this shader effect.
vec2 rot2(vec2 p, float a)
Evaluates rot2 for this shader effect.