ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
liquid_code_chrome_nautilus.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file liquid_code_chrome_nautilus.frag
5 * @brief Vulkan fragment shader: liquid code chrome nautilus.
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
36const float PI = 3.14159265359;
37const float TAU = 6.28318530718;
38
39/**
40 * @brief Evaluates hash21 for this shader effect.
41 * @param p Input value for the calculation.
42 * @return Computed float value.
43 */
44float hash21(vec2 p) {
45 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
46}
47
48/**
49 * @brief Evaluates valueNoise for this shader effect.
50 * @param p Input value for the calculation.
51 * @return Computed float value.
52 */
53float valueNoise(vec2 p) {
54 vec2 i = floor(p);
55 vec2 f = fract(p);
56 f = f * f * (3.0 - 2.0 * f);
57 return mix(mix(hash21(i), hash21(i + vec2(1.0, 0.0)), f.x),
58 mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0)), f.x), f.y);
59}
60
61/**
62 * @brief Evaluates ridgedFbm for this shader effect.
63 * @param p Input value for the calculation.
64 * @return Computed float value.
65 */
66float ridgedFbm(vec2 p) {
67 float sum = 0.0;
68 float amplitude = 0.52;
69 mat2 basis = mat2(0.707, -0.707, 0.707, 0.707);
70 for (int i = 0; i < 6; ++i) {
71 float ridge = 1.0 - abs(valueNoise(p) * 2.0 - 1.0);
72 sum += ridge * ridge * amplitude;
73 p = basis * p * 2.08 + vec2(-3.7, 1.9);
74 amplitude *= 0.48;
75 }
76 return sum;
77}
78
79/**
80 * @brief Evaluates rotate2 for this shader effect.
81 * @param p Input value for the calculation.
82 * @param a Input value for the calculation.
83 * @return Computed vec2 value.
84 */
85vec2 rotate2(vec2 p, float a) {
86 float c = cos(a);
87 float s = sin(a);
88 return mat2(c, -s, s, c) * p;
89}
90
91/**
92 * @brief Evaluates mirrorUV for this shader effect.
93 * @param uv Input value for the calculation.
94 * @return Computed vec2 value.
95 */
96vec2 mirrorUV(vec2 uv) {
97 return 1.0 - abs(mod(uv, 2.0) - 1.0);
98}
99
100/**
101 * @brief Evaluates thinFilm for this shader effect.
102 * @param phase Input value for the calculation.
103 * @return Computed vec3 value.
104 */
105vec3 thinFilm(float phase) {
106 vec3 wave = vec3(1.0, 0.79, 0.58);
107 return 0.5 + 0.5 * cos(TAU * (phase * wave + vec3(0.00, 0.17, 0.39)));
108}
109
110/**
111 * @brief Evaluates shellHeight for this shader effect.
112 * @param p Input value for the calculation.
113 * @return Computed float value.
114 */
115float shellHeight(vec2 p) {
116 float t = time_f;
117 float r = max(length(p), 0.018);
118 float a = atan(p.y, p.x);
119 float logarithmic = log(r + 0.045);
120 float chamberPhase = a * 7.0 - logarithmic * 15.0 - t * 1.75;
121 chamberPhase += sin(a * 2.0 + t * 0.35) * amp_mid * 0.85;
122 float ribs = cos(chamberPhase) * exp(-r * 0.34);
123
124 // Keep angular domain warping periodic across atan's -PI/PI branch cut.
125 float angularCurl = sin(a * 3.0 - t * 0.18) * 0.22;
126 vec2 curled = rotate2(p, angularCurl - logarithmic * 0.7 + t * 0.07);
127 float liquid = ridgedFbm(curled * 4.8 + vec2(t * 0.11, -t * 0.08));
128 float rings = sin(r * 69.0 - a * 2.0 - t * 4.4 + liquid * 3.0);
129 float membrane = cos(a * 2.0 + r * 18.0 + sin(a * 5.0 - t) * 1.4);
130 float centralPool = exp(-r * 8.0) * sin(a * 4.0 - t * 3.0);
131 return ribs * 0.32 + rings * 0.08 + membrane * 0.11 + liquid * 0.58 + centralPool * 0.32;
132}
133
134/**
135 * @brief Evaluates shellNormal for this shader effect.
136 * @param p Input value for the calculation.
137 * @param e Input value for the calculation.
138 * @return Computed vec3 value.
139 */
140vec3 shellNormal(vec2 p, float e) {
141 float center = shellHeight(p);
142 float right = shellHeight(p + vec2(e, 0.0));
143 float up = shellHeight(p + vec2(0.0, e));
144 vec2 gradient = vec2(right - center, up - center) / e;
145 return normalize(vec3(-gradient * 0.12, 1.0));
146}
147
148/**
149 * @brief Evaluates textureAlongShell for this shader effect.
150 * @param uv Input value for the calculation.
151 * @param curl Input value for the calculation.
152 * @param normalFlow Input value for the calculation.
153 * @param dispersion Input value for the calculation.
154 * @return Computed vec3 value.
155 */
156vec3 textureAlongShell(vec2 uv, vec2 curl, vec2 normalFlow, float dispersion) {
157 vec2 axis = normalize(curl + normalFlow * 0.5 + vec2(0.0001));
158 vec2 across = vec2(-axis.y, axis.x);
159 vec2 center = mirrorUV(uv);
160 vec3 axialBlur = texture(samp, center).rgb * 0.42;
161 axialBlur += texture(samp, mirrorUV(uv + axis * 0.0045)).rgb * 0.2;
162 axialBlur += texture(samp, mirrorUV(uv - axis * 0.0045)).rgb * 0.2;
163 axialBlur += texture(samp, mirrorUV(uv + across * 0.003)).rgb * 0.09;
164 axialBlur += texture(samp, mirrorUV(uv - across * 0.003)).rgb * 0.09;
165 return vec3(texture(samp, mirrorUV(uv + across * dispersion)).r,
166 axialBlur.g,
167 texture(samp, mirrorUV(uv - across * dispersion)).b);
168}
169
170/**
171 * @brief Evaluates ggx for this shader effect.
172 * @param nh Input value for the calculation.
173 * @param roughness Input value for the calculation.
174 * @return Computed float value.
175 */
176float ggx(float nh, float roughness) {
177 float a = roughness * roughness;
178 float a2 = a * a;
179 float denominator = nh * nh * (a2 - 1.0) + 1.0;
180 return a2 / max(PI * denominator * denominator, 0.0001);
181}
182
183/**
184 * @brief Evaluates chromeLighting for this shader effect.
185 * @param base Input value for the calculation.
186 * @param n Input value for the calculation.
187 * @param p Input value for the calculation.
188 * @param phase Input value for the calculation.
189 * @param roughness Input value for the calculation.
190 * @return Computed vec3 value.
191 */
192vec3 chromeLighting(vec3 base, vec3 n, vec2 p, float phase, float roughness) {
193 vec3 view = normalize(vec3(-p * 0.12, 1.45));
194 vec3 light0 = normalize(vec3(-0.72, 0.38, 0.68));
195 vec3 light1 = normalize(vec3(0.56, 0.66, 0.51));
196 vec3 light2 = normalize(vec3(0.25, -0.72, 0.65));
197 vec3 lights[3] = vec3[3](light0, light1, light2);
198 vec3 colors[3] = vec3[3](vec3(1.0, 0.58, 0.28),
199 vec3(0.30, 0.62, 1.0),
200 vec3(0.72, 0.25, 1.0));
201 vec3 f0 = mix(vec3(0.68), base, 0.52);
202 vec3 result = base * 0.04;
203
204 for (int i = 0; i < 3; ++i) {
205 vec3 halfVector = normalize(view + lights[i]);
206 float nl = max(dot(n, lights[i]), 0.0);
207 float nh = max(dot(n, halfVector), 0.0);
208 float vh = max(dot(view, halfVector), 0.0);
209 vec3 fresnel = f0 + (1.0 - f0) * pow(1.0 - vh, 5.0);
210 result += colors[i] * nl *
211 (base * 0.065 + fresnel * ggx(nh, roughness) * 0.2);
212 }
213
214 float nv = max(dot(n, view), 0.0);
215 vec3 reflection = reflect(-view, n);
216 vec3 environment = mix(vec3(0.025, 0.035, 0.065),
217 thinFilm(sin(phase) * 0.18 + reflection.y * 0.14 + time_f * 0.013),
218 smoothstep(-0.65, 0.75, reflection.z));
219 vec3 fresnel = f0 + (1.0 - f0) * pow(1.0 - nv, 5.0);
220 return result + environment * fresnel * 1.5;
221}
222
223/**
224 * @brief Evaluates toneMap for this shader effect.
225 * @param value Input value for the calculation.
226 * @return Computed vec3 value.
227 */
228vec3 toneMap(vec3 value) {
229 value = max(value, 0.0);
230 return value / (1.0 + value * 0.72);
231}
232
233/**
234 * @brief Executes the fragment shader entry point.
235 */
236void main(void) {
237 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
238 vec2 p = (tc - 0.5) * vec2(aspect, 1.0);
239 float e = 1.6 / max(max(iResolution.x, iResolution.y), 320.0);
240 float radius = max(length(p), 0.018);
241 float angle = atan(p.y, p.x);
242 float phase = angle * 7.0 - log(radius + 0.045) * 15.0 - time_f * 1.75;
243 float height = shellHeight(p);
244 vec3 n = shellNormal(p, e);
245
246 vec2 radial = p / radius;
247 vec2 tangent = vec2(-radial.y, radial.x);
248 float curlStrength = 0.018 + 0.045 * exp(-radius * 2.2) + amp_low * 0.022;
249 vec2 curl = tangent * curlStrength;
250 curl += radial * sin(phase + height * 2.0) * 0.009;
251 vec2 normalFlow = n.xy * (0.018 + amp_smooth * 0.014);
252 vec2 uv = mirrorUV(tc + (curl + normalFlow) / vec2(aspect, 1.0));
253
254 float dispersion = 0.0015 + amp_high * 0.006 + abs(sin(phase)) * 0.0015;
255 vec3 source = textureAlongShell(uv, curl, normalFlow, dispersion);
256 float luminance = dot(source, vec3(0.299, 0.587, 0.114));
257 vec3 chrome = mix(vec3(luminance) * vec3(0.83, 0.89, 1.0), source, 0.38);
258 float roughness = mix(0.07, 0.3, ridgedFbm(p * 3.6 + time_f * 0.035));
259 vec3 result = chromeLighting(chrome, n, p, phase + height, roughness);
260
261 float ribHighlight = pow(0.5 + 0.5 * cos(phase), 18.0);
262 result += thinFilm(sin(phase) * 0.15 + height * 0.09) * ribHighlight *
263 (0.35 + amp_peak * 1.25);
264 result = mix(result, result * (0.55 + source * 1.1), 0.2);
265 color = vec4(toneMap(result * (1.0 + amp_smooth * 0.3)), texture(samp, uv).a);
266}
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
vec3 wave(ivec2 p, ivec2 size)
Evaluates wave for this shader effect.
vec3 chrome(float t)
Evaluates chrome for this shader effect.
vec2 mirrorUV(vec2 uv)
Evaluates mirrorUV for this shader effect.
float valueNoise(vec2 p)
Evaluates valueNoise for this shader effect.
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
float luminance(vec3 c)
Evaluates luminance for this shader effect.
#define TAU
#define PI
vec2 curl(vec2 p, float t)
Evaluates curl for this shader effect.
vec2 rotate2(vec2 p, float angle)
Evaluates rotate2 for this shader effect.
vec3 toneMap(vec3 value)
Evaluates toneMap for this shader effect.
vec3 chromeLighting(vec3 base, vec3 n, vec2 p, float phase, float roughness)
Evaluates chromeLighting for this shader effect.
float ridgedFbm(vec2 p)
Evaluates ridgedFbm for this shader effect.
vec3 shellNormal(vec2 p, float e)
Evaluates shellNormal for this shader effect.
float shellHeight(vec2 p)
Evaluates shellHeight for this shader effect.
vec3 thinFilm(float phase)
Evaluates thinFilm for this shader effect.
float ggx(float nh, float roughness)
Evaluates ggx for this shader effect.
vec3 textureAlongShell(vec2 uv, vec2 curl, vec2 normalFlow, float dispersion)
Evaluates textureAlongShell for this shader effect.