ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
rainbow_cd_curtain.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file rainbow_cd_curtain.frag
5 * @brief Vulkan fragment shader: rainbow cd curtain.
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 iResolution ext.u0.zw
18#define time_f ext.u2.y
19#define value_alpha_r ext.custom_uniforms[1].y
20
21layout(location = 0) in vec2 tc;
22layout(location = 0) out vec4 color;
23layout(set = 0, binding = 0) uniform sampler2D samp;
24
25
26
27
28/**
29 * @brief Evaluates hash for this shader effect.
30 * @param n Input value for the calculation.
31 * @return Computed float value.
32 */
33float hash(float n) {
34 return fract(sin(n) * 43758.5453123);
35}
36
37/**
38 * @brief Evaluates random2 for this shader effect.
39 * @param st Input value for the calculation.
40 * @return Computed vec2 value.
41 */
42vec2 random2(vec2 st) {
43 st = vec2(dot(st, vec2(127.1, 311.7)),
44 dot(st, vec2(269.5, 183.3)));
45 return -1.0 + 2.0 * fract(sin(st) * 43758.5453123);
46}
47
48/**
49 * @brief Evaluates smoothRandom2 for this shader effect.
50 * @param t Input value for the calculation.
51 * @return Computed vec2 value.
52 */
53vec2 smoothRandom2(float t) {
54 float t0 = floor(t);
55 float t1 = t0 + 1.0;
56 vec2 rand0 = random2(vec2(t0));
57 vec2 rand1 = random2(vec2(t1));
58 float mix_factor = fract(t);
59 return mix(rand0, rand1, smoothstep(0.0, 1.0, mix_factor));
60}
61
62/**
63 * @brief Evaluates rainbow for this shader effect.
64 * @param t Input value for the calculation.
65 * @param seed Input value for the calculation.
66 * @return Computed vec3 value.
67 */
68vec3 rainbow(float t, float seed) {
69 t = fract(t + seed);
70 float r = abs(t * 6.0 - 3.0) - 1.0;
71 float g = 2.0 - abs(t * 6.0 - 2.0);
72 float b = 2.0 - abs(t * 6.0 - 4.0);
73 return clamp(vec3(r, g, b), 0.0, 1.0);
74}
75
76/**
77 * @brief Evaluates pingPong for this shader effect.
78 * @param x Input value for the calculation.
79 * @param length Input value for the calculation.
80 * @return Computed float value.
81 */
82float pingPong(float x, float length) {
83 float modVal = mod(x, length * 2.0);
84 return modVal <= length ? modVal : length * 2.0 - modVal;
85}
86
87/**
88 * @brief Executes the fragment shader entry point.
89 */
90void main(void) {
91 vec2 uv = tc * 2.0 - 1.0;
92 uv.y *= iResolution.y / iResolution.x;
93
94 float pingPongTime = pingPong(time_f, 9.0);
95 float rotations = floor(pingPongTime / 3.0);
96 float direction = mod(rotations, 2.0) == 0.0 ? 1.0 : -1.0;
97 float localTime = mod(pingPongTime, 3.0);
98 float rotationAngle = localTime * 2.0 * 3.14159 * direction;
99
100 float cosAngle = cos(rotationAngle);
101 float sinAngle = sin(rotationAngle);
102
103 vec2 rotatedUV = vec2(
104 cosAngle * uv.x - sinAngle * uv.y,
105 sinAngle * uv.x + cosAngle * uv.y
106 );
107
108 uv = rotatedUV;
109
110 float time_t = pingPong(time_f, 15.0) + 1.0;
111 float wave = sin(uv.x * 10.0 + time_t * 2.0) * 0.1;
112 vec2 random_direction = smoothRandom2(time_t) * 0.5;
113 float expand = 0.5 + 0.5 * sin(time_t * 2.0);
114 vec2 spiral_uv = uv * expand + random_direction;
115 float angle = atan(spiral_uv.y + wave, spiral_uv.x) + time_t * 2.0;
116
117 float curtain_wave = sin(uv.y * 10.0 + time_f * 2.0) * 0.1;
118 vec3 rainbow_color = rainbow((angle / (2.0 * 3.14159)) + curtain_wave, value_alpha_r);
119
120 vec4 original_color = texture(samp, (rotatedUV + 1.0) / 2.0);
121 vec3 blended_color = mix(original_color.rgb, rainbow_color, 0.5);
122 color = vec4(sin(blended_color * time_t), original_color.a);
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
#define iResolution
Definition 3high.frag:18
#define time_f
Definition 3high.frag:19
vec3 wave(ivec2 p, ivec2 size)
Evaluates wave for this shader effect.
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
#define seed
Definition air-bowl.frag:20
float hash(vec2 p)
Evaluates hash for this shader effect.
vec3 rainbow(float t)
Evaluates rainbow for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
float rand1(float x)
Evaluates rand1 for this shader effect.
vec2 expand(vec2 pos, vec2 center)
Evaluates expand for this shader effect.
#define value_alpha_r
vec2 random2(vec2 st)
Evaluates random2 for this shader effect.
vec2 smoothRandom2(float t)
Evaluates smoothRandom2 for this shader effect.