ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
rainbow-code-liquid-pearl.frag
Go to the documentation of this file.
1#version 450
2
3layout(set = 0, binding = 1, std140) uniform SpriteExtended {
4 vec4 mouse;
5 vec4 u0;
6 vec4 u1;
7 vec4 u2;
8 vec4 u3;
9 vec4 custom_uniforms[16];
10 vec4 audio_bands;
11 vec4 audio_history;
13#define amp_high ext.audio_bands.z
14#define amp_low ext.audio_bands.x
15#define amp_mid ext.audio_bands.y
16#define amp_peak ext.u2.w
17#define amp_rms ext.u3.z
18#define amp_smooth ext.u3.w
19#define iResolution ext.u0.zw
20#define iamp ext.u1.z
21#define time_f ext.u2.y
22
23/**
24 * @file rainbow-code-liquid-pearl.frag
25 * @brief Vulkan fragment shader: rainbow-code-liquid-pearl.
26 */
27// rainbow-code-liquid-pearl
28// Pearlescent liquid lens with smooth cellular membranes and thin-film reflections.
29layout(location = 0) in vec2 tc;
30layout(location = 0) out vec4 color;
31layout(set = 0, binding = 0) uniform sampler2D samp;
32
33
34
35
36
37
38
39
40
41
42const float TAU = 6.28318530718;
43/**
44 * @brief Evaluates hash21 for this shader effect.
45 * @param p Input value for the calculation.
46 * @return Computed float value.
47 */
48float hash21(vec2 p) {
49 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
50}
51/**
52 * @brief Evaluates noise21 for this shader effect.
53 * @param p Input value for the calculation.
54 * @return Computed float value.
55 */
56float noise21(vec2 p) {
57 vec2 i = floor(p), f = fract(p);
58 f = f * f * (3.0 - 2.0 * f);
59 return mix(mix(hash21(i), hash21(i + vec2(1, 0)), f.x),
60 mix(hash21(i + vec2(0, 1)), hash21(i + 1.0), f.x), f.y);
61}
62/**
63 * @brief Evaluates fbm for this shader effect.
64 * @param p Input value for the calculation.
65 * @return Computed float value.
66 */
67float fbm(vec2 p) {
68 float s = 0.0, a = .5;
69 mat2 m = mat2(.8, -.6, .6, .8);
70 for (int i = 0; i < 5; i++) {
71 s += a * noise21(p);
72 p = m * p * 2.05 + 2.1;
73 a *= .5;
74 }
75 return s;
76}
77/**
78 * @brief Evaluates mirrorUV for this shader effect.
79 * @param p Input value for the calculation.
80 * @return Computed vec2 value.
81 */
82vec2 mirrorUV(vec2 p) {
83 return 1.0 - abs(mod(p, 2.0) - 1.0);
84}
85/**
86 * @brief Evaluates spectral for this shader effect.
87 * @param x Input value for the calculation.
88 * @return Computed vec3 value.
89 */
90vec3 spectral(float x) {
91 return .5 + .5 * cos(TAU * (x + vec3(.0, .33, .67)));
92}
93/**
94 * @brief Evaluates aces for this shader effect.
95 * @param x Input value for the calculation.
96 * @return Computed vec3 value.
97 */
98vec3 aces(vec3 x) {
99 x = max(x, 0.0);
100 return clamp((x * (2.51 * x + .03)) / (x * (2.43 * x + .59) + .14), 0.0, 1.0);
101}
102/**
103 * @brief Evaluates pearl for this shader effect.
104 * @param p Input value for the calculation.
105 * @return Computed float value.
106 */
107float pearl(vec2 p) {
108 float t = time_f * .15;
109 vec2 q = vec2(fbm(p * 2.8 + vec2(t, 0)), fbm(p * 2.8 + vec2(5.2, -t)));
110 p += (q - .5) * .55;
111 return fbm(p * 6.0) - .5 + .14 * sin(p.x * 24.0 - p.y * 9.0 + t * 6.0);
112}
113/**
114 * @brief Executes the fragment shader entry point.
115 */
116void main() {
117 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
118 vec2 p = (tc - .5) * vec2(aspect, 1.0);
119 float e = 1.8 / max(iResolution.y, 360.0);
120 float h = pearl(p), hx = pearl(p + vec2(e, 0)), hy = pearl(p + vec2(0, e));
121 vec3 n = normalize(vec3((h - hx) * 5.0, (h - hy) * 5.0, e));
122 vec2 uv = mirrorUV(tc + n.xy * (.021 + amp_low * .019));
123 float split = .002 + amp_high * .010;
124 vec3 src = vec3(texture(samp, mirrorUV(uv + n.xy * split)).r, texture(samp, uv).g,
125 texture(samp, mirrorUV(uv - n.xy * split)).b);
126 vec3 v = normalize(vec3(-p * .14, 1.25));
127 float fres = pow(1.0 - max(dot(n, v), 0.0), 4.5);
128 vec3 pearlHue = mix(vec3(.93, .91, .86), spectral(h * .38 + n.x * .11 - time_f * .018), .62);
129 float gleam = pow(max(dot(n, normalize(vec3(-.45, .7, .57))), 0.0), 64.0);
130 float membrane = pow(clamp(abs(h) * 3.2, 0.0, 1.0), 8.0);
131 vec3 result = mix(src, src * pearlHue * 1.18, .28) + pearlHue * (.12 + .66 * fres);
132 result +=
133 gleam * vec3(1.0, .9, .78) * (1.0 + amp_peak * .65) + pearlHue * membrane * amp_mid * .16;
134 color = vec4(aces(result * (1.0 + amp_smooth * .12)), texture(samp, uv).a);
135}
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
float fbm(vec2 point)
Evaluates fbm for this shader effect.
#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.
vec3 spectral(float t)
Evaluates spectral 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.
vec3 aces(vec3 x)
Evaluates aces for this shader effect.
float noise21(vec2 p)
Evaluates noise21 for this shader effect.
#define TAU
float pearl(vec2 p)
Evaluates pearl for this shader effect.