ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
crystalbend.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file crystalbend.frag
5 * @brief Vulkan fragment shader: crystalbend.
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 amp ext.u1.y
18#define iResolution ext.u0.zw
19#define time_f ext.u2.y
20#define uamp ext.u1.y
21
22layout(location = 0) in vec2 tc;
23layout(location = 0) out vec4 color;
24
25layout(set = 0, binding = 0) uniform sampler2D samp;
26
27
28
29
30float PI = 3.141592653589793;
31
32/**
33 * @brief Evaluates mirror1 for this shader effect.
34 * @param x Input value for the calculation.
35 * @param m Input value for the calculation.
36 * @return Computed float value.
37 */
38float mirror1(float x, float m){
39 float p = mod(x, m*2.0);
40 return p > m ? (2.0*m - p) : p;
41}
42
43/**
44 * @brief Evaluates kaleido for this shader effect.
45 * @param p Input value for the calculation.
46 * @param seg Input value for the calculation.
47 * @return Computed vec2 value.
48 */
49vec2 kaleido(vec2 p, float seg){
50 vec2 c = vec2(0.5);
51 vec2 d = p - c;
52 float a = atan(d.y, d.x);
53 float r = length(d);
54 float m = PI / max(2.0, seg);
55 a = mirror1(a, m);
56 return c + vec2(cos(a), sin(a)) * max(r, 1e-6);
57}
58
59/**
60 * @brief Executes the fragment shader entry point.
61 */
62void main(){
63 vec2 uv = tc;
64 float drive = clamp(amp + uamp, 0.0, 2.0);
65 float seg = floor(mix(5.0, 12.0, clamp(drive*0.5, 0.0, 1.0)));
66 vec2 k = kaleido(uv, seg);
67
68 float r = length(k - 0.5);
69 vec2 dir = normalize(k - 0.5 + vec2(1e-6, 0.0));
70
71 float bend = (0.06 + 0.14 * uamp) / (r + 0.04);
72 vec2 wob = 0.012 * (0.3 + amp) * vec2(sin(32.0*r - 1.7*time_f), cos(28.0*r - 1.3*time_f));
73 vec2 base = k + dir * bend + wob;
74
75 float disp = (0.001 + 0.004 * amp) / (r + 0.04);
76 vec2 tR = base + dir * disp;
77 vec2 tG = base;
78 vec2 tB = base - dir * disp;
79
80 vec3 warped;
81 warped.r = texture(samp, tR).r;
82 warped.g = texture(samp, tG).g;
83 warped.b = texture(samp, tB).b;
84
85 float wedge = PI / max(2.0, seg);
86 float a = atan((k - 0.5).y, (k - 0.5).x);
87 float edge = abs(mod(a + wedge, 2.0*wedge) - wedge) / wedge;
88 float edgeGlow = pow(1.0 - edge, 6.0) * mix(0.10, 0.35, clamp(amp, 0.0, 1.0));
89 warped += edgeGlow;
90
91 vec3 orig = texture(samp, uv).rgb;
92
93 float clarityBias = 0.45;
94 float effectAmt = clamp(clarityBias + 0.4 * clamp(drive*0.5, 0.0, 1.0), 0.0, 1.0);
95 float spatial = smoothstep(0.0, 0.85, r);
96 float mixAmt = clamp(mix(effectAmt*0.7, effectAmt, spatial), 0.0, 1.0);
97
98 vec3 outc = mix(orig, warped, mixAmt);
99 color = vec4(outc, 1.0);
100}
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 time_f
Definition 3high.frag:19
#define uamp
Definition abc.frag:21
#define amp
Definition abc.frag:17
vec2 kaleido(vec2 p, float seg)
Evaluates kaleido for this shader effect.
float mirror1(float x, float m)
Evaluates mirror1 for this shader effect.
#define PI