ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
metal-code-liquid-tessera.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file metal-code-liquid-tessera.frag
5 * @brief Vulkan fragment shader: metal-code-liquid-tessera.
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_high ext.audio_bands.z
18#define amp_low ext.audio_bands.x
19#define amp_mid ext.audio_bands.y
20#define amp_peak ext.u2.w
21#define amp_smooth ext.u3.w
22#define iResolution ext.u0.zw
23#define time_f ext.u2.y
24
25layout(location = 0) in vec2 tc;
26layout(location = 0) out vec4 color;
27layout(set = 0, binding = 0) uniform sampler2D samp;
28
29
30
31
32
33
34
35
36/**
37 * @brief Evaluates hash21 for this shader effect.
38 * @param p Input value for the calculation.
39 * @return Computed float value.
40 */
41float hash21(vec2 p) {
42 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
43}
44/**
45 * @brief Evaluates hash22 for this shader effect.
46 * @param p Input value for the calculation.
47 * @return Computed vec2 value.
48 */
49vec2 hash22(vec2 p) {
50 return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);
51}
52/**
53 * @brief Evaluates voronoi for this shader effect.
54 * @param p Input value for the calculation.
55 * @return Computed vec3 value.
56 */
57vec3 voronoi(vec2 p) {
58 vec2 n = floor(p), f = fract(p);
59 float d1 = 9.0, d2 = 9.0, id = 0.0;
60 for (int y = -1; y <= 1; ++y)
61 for (int x = -1; x <= 1; ++x) {
62 vec2 g = vec2(x, y), o = 0.5 + 0.38 * sin(6.2831 * hash22(n + g) + time_f * 0.35);
63 float d = length(g + o - f);
64 if (d < d1) {
65 d2 = d1;
66 d1 = d;
67 id = hash21(n + g);
68 } else if (d < d2)
69 d2 = d;
70 }
71 return vec3(d1, d2 - d1, id);
72}
73/**
74 * @brief Evaluates mirrorUV for this shader effect.
75 * @param p Input value for the calculation.
76 * @return Computed vec2 value.
77 */
78vec2 mirrorUV(vec2 p) {
79 return 1.0 - abs(mod(p, 2.0) - 1.0);
80}
81/**
82 * @brief Evaluates spectral for this shader effect.
83 * @param t Input value for the calculation.
84 * @return Computed vec3 value.
85 */
86vec3 spectral(float t) {
87 return 0.52 + 0.48 * cos(6.2831853 * (t + vec3(0.0, 0.3, 0.66)));
88}
89/**
90 * @brief Evaluates tone for this shader effect.
91 * @param x Input value for the calculation.
92 * @return Computed vec3 value.
93 */
94vec3 tone(vec3 x) {
95 return 1.0 - exp(-max(x, 0.0) * 1.12);
96}
97
98/**
99 * @brief Evaluates tiles for this shader effect.
100 * @param p Input value for the calculation.
101 * @return Computed float value.
102 */
103float tiles(vec2 p) {
104 p += vec2(sin(p.y * 3.0 + time_f * 0.7), cos(p.x * 3.0 - time_f * 0.6)) * 0.16;
105 vec3 v = voronoi(p * (5.0 + amp_low * 2.0));
106 float edge = exp(-v.y * 12.0);
107 float bowl = 1.0 - smoothstep(0.05, 0.75, v.x);
108 return bowl * 0.45 - edge * 0.24 + sin(v.x * 22.0 - time_f * 4.0) * 0.1 + v.z * 0.08;
109}
110/**
111 * @brief Evaluates normalAt for this shader effect.
112 * @param p Input value for the calculation.
113 * @param e Input value for the calculation.
114 * @return Computed vec3 value.
115 */
116vec3 normalAt(vec2 p, float e) {
117 float h = tiles(p);
118 vec2 g = vec2(tiles(p + vec2(e, 0)) - h, tiles(p + vec2(0, e)) - h) / e;
119 return normalize(vec3(-g * 0.18, 1));
120}
121/**
122 * @brief Executes the fragment shader entry point.
123 */
124void main(void) {
125 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
126 vec2 p = (tc - 0.5) * vec2(aspect, 1.0);
127 float e = 2.0 / max(max(iResolution.x, iResolution.y), 320.0);
128 vec3 cell =
129 voronoi((p + vec2(sin(p.y * 3.0 + time_f * 0.7), cos(p.x * 3.0 - time_f * 0.6)) * 0.16) *
130 (5.0 + amp_low * 2.0));
131 float h = tiles(p);
132 vec3 n = normalAt(p, e);
133 vec2 uv = mirrorUV(tc + n.xy * (0.027 + amp_mid * 0.018));
134 float split = 0.002 + amp_high * 0.007;
135 vec3 tex = vec3(texture(samp, mirrorUV(uv + n.xy * split)).r, texture(samp, uv).g,
136 texture(samp, mirrorUV(uv - n.xy * split)).b);
137 float y = dot(tex, vec3(0.299, 0.587, 0.114));
138 vec3 base = mix(vec3(y) * spectral(cell.z * 0.35), tex, 0.34);
139 vec3 v = normalize(vec3(-p * 0.08, 1.5));
140 vec3 l0 = normalize(vec3(-0.65, 0.55, 0.68)), l1 = normalize(vec3(0.75, -0.25, 0.61));
141 float nv = max(dot(n, v), 0.0);
142 vec3 f0 = mix(vec3(0.58), base, 0.62);
143 vec3 F = f0 + (1.0 - f0) * pow(1.0 - nv, 5.0);
144 float s0 = pow(max(dot(n, normalize(v + l0)), 0.0), 150.0),
145 s1 = pow(max(dot(n, normalize(v + l1)), 0.0), 35.0);
146 vec3 env = spectral(dot(reflect(-v, n), vec3(0.42, 0.3, 0.28)) * 0.3 + time_f * 0.02 + cell.z);
147 vec3 col = base * (0.05 + 0.15 * max(dot(n, l0), 0.0)) +
148 F * (env * 0.85 + s0 * vec3(1.0, 0.85, 0.7) * 2.2 + s1 * vec3(0.3, 0.55, 1.0) * 0.9);
149 float edge = exp(-cell.y * 20.0);
150 col += spectral(cell.z + time_f * 0.03) * edge * (0.55 + amp_peak * 1.4);
151 col *= 0.82 + 0.25 * cell.x;
152 color = vec4(tone(col * (1.0 + amp_smooth * 0.25)), texture(samp, uv).a);
153}
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
#define amp_smooth
#define amp_mid
#define amp_low
#define amp_high
#define amp_peak
vec2 mirrorUV(vec2 uv)
Evaluates mirrorUV for this shader effect.
vec2 voronoi(vec2 p)
Evaluates voronoi for this shader effect.
vec3 spectral(float t)
Evaluates spectral for this shader effect.
vec2 hash22(vec2 p)
Evaluates hash22 for this shader effect.
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
float h(vec2 p)
Evaluates h for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
float F(vec2 p)
Evaluates F for this shader effect.
vec3 tone(vec3 x)
Evaluates tone for this shader effect.
vec2 cell(vec2 p)
Evaluates cell for this shader effect.
vec3 normalAt(vec2 p, float e, vec2 origin, float bass, float mid)
Evaluates normalAt for this shader effect.
float tiles(vec2 p)
Evaluates tiles for this shader effect.