ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
liquid_code_molten_helix.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file liquid_code_molten_helix.frag
5 * @brief Vulkan fragment shader: liquid code molten helix.
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 p = fract(p * vec2(443.8975, 397.2973));
46 p += dot(p, p.yx + 19.19);
47 return fract((p.x + p.y) * p.x);
48}
49
50/**
51 * @brief Evaluates noise21 for this shader effect.
52 * @param p Input value for the calculation.
53 * @return Computed float value.
54 */
55float noise21(vec2 p) {
56 vec2 cell = floor(p);
57 vec2 local = fract(p);
58 local = local * local * (3.0 - 2.0 * local);
59 return mix(mix(hash21(cell), hash21(cell + vec2(1.0, 0.0)), local.x),
60 mix(hash21(cell + vec2(0.0, 1.0)), hash21(cell + vec2(1.0)), local.x),
61 local.y);
62}
63
64/**
65 * @brief Evaluates flowFbm for this shader effect.
66 * @param p Input value for the calculation.
67 * @return Computed float value.
68 */
69float flowFbm(vec2 p) {
70 float result = 0.0;
71 float amplitude = 0.52;
72 mat2 twist = mat2(0.64, -0.77, 0.77, 0.64);
73 for (int i = 0; i < 6; ++i) {
74 result += noise21(p) * amplitude;
75 p = twist * p * 2.06 + vec2(1.37, 4.11);
76 amplitude *= 0.49;
77 }
78 return result;
79}
80
81/**
82 * @brief Evaluates mirrorUV for this shader effect.
83 * @param uv Input value for the calculation.
84 * @return Computed vec2 value.
85 */
86vec2 mirrorUV(vec2 uv) {
87 return 1.0 - abs(mod(uv, 2.0) - 1.0);
88}
89
90/**
91 * @brief Evaluates heatPalette for this shader effect.
92 * @param x Input value for the calculation.
93 * @return Computed vec3 value.
94 */
95vec3 heatPalette(float x) {
96 vec3 cold = vec3(0.025, 0.055, 0.11);
97 vec3 copper = vec3(0.92, 0.20, 0.035);
98 vec3 gold = vec3(1.0, 0.68, 0.16);
99 vec3 white = vec3(1.0, 0.94, 0.78);
100 vec3 result = mix(cold, copper, smoothstep(0.05, 0.46, x));
101 result = mix(result, gold, smoothstep(0.42, 0.72, x));
102 return mix(result, white, smoothstep(0.72, 1.0, x));
103}
104
105/**
106 * @brief Evaluates spectral for this shader effect.
107 * @param x Input value for the calculation.
108 * @return Computed vec3 value.
109 */
110vec3 spectral(float x) {
111 return 0.5 + 0.5 * cos(TAU * (x + vec3(0.0, 0.31, 0.65)));
112}
113
114/**
115 * @brief Evaluates helixPotential for this shader effect.
116 * @param p Input value for the calculation.
117 * @return Computed float value.
118 */
119float helixPotential(vec2 p) {
120 float t = time_f;
121 vec2 centers[2] = vec2[2](vec2(-0.22, 0.0), vec2(0.22, 0.0));
122 float field = 0.0;
123 for (int i = 0; i < 2; ++i) {
124 vec2 d = p - centers[i];
125 float r = max(length(d), 0.025);
126 float a = atan(d.y, d.x);
127 float handedness = (i == 0) ? 1.0 : -1.0;
128 float coil = a * 4.0 * handedness + log(r) * 8.5 - t * (1.8 + float(i) * 0.25);
129 field += sin(coil + r * 24.0) * exp(-r * 1.25) * 0.3;
130 field += cos(coil * 2.0 - r * 11.0) * exp(-r * 2.3) * 0.1;
131 }
132
133 vec2 q = p;
134 float warp0 = flowFbm(q * 3.4 + vec2(t * 0.12, -t * 0.1));
135 float warp1 = flowFbm(q * 3.4 + vec2(-t * 0.09, t * 0.13) + 9.7);
136 q += (vec2(warp0, warp1) - 0.5) * 0.23;
137 float viscosity = flowFbm(q * 7.0 + vec2(t * 0.14, -t * 0.11));
138 float crossWave = sin(q.y * 32.0 + sin(q.x * 9.0 - t) * 3.0 - t * 4.6);
139 return field + viscosity * 0.58 + crossWave * 0.075;
140}
141
142/**
143 * @brief Evaluates liquidNormal for this shader effect.
144 * @param p Input value for the calculation.
145 * @param e Input value for the calculation.
146 * @return Computed vec3 value.
147 */
148vec3 liquidNormal(vec2 p, float e) {
149 float left = helixPotential(p - vec2(e, 0.0));
150 float right = helixPotential(p + vec2(e, 0.0));
151 float down = helixPotential(p - vec2(0.0, e));
152 float up = helixPotential(p + vec2(0.0, e));
153 vec2 gradient = vec2(right - left, up - down) / (2.0 * e);
154 return normalize(vec3(-gradient * 0.1, 1.0));
155}
156
157/**
158 * @brief Evaluates helixVelocity for this shader effect.
159 * @param p Input value for the calculation.
160 * @return Computed vec2 value.
161 */
162vec2 helixVelocity(vec2 p) {
163 vec2 centers[2] = vec2[2](vec2(-0.22, 0.0), vec2(0.22, 0.0));
164 vec2 velocity = vec2(0.0);
165 for (int i = 0; i < 2; ++i) {
166 vec2 d = p - centers[i];
167 float r2 = dot(d, d) + 0.025;
168 float handedness = (i == 0) ? 1.0 : -1.0;
169 velocity += vec2(-d.y, d.x) * handedness / r2;
170 }
171 return velocity;
172}
173
174/**
175 * @brief Evaluates advectedTexture for this shader effect.
176 * @param uv Input value for the calculation.
177 * @param velocity Input value for the calculation.
178 * @param normalDirection Input value for the calculation.
179 * @param split Input value for the calculation.
180 * @return Computed vec3 value.
181 */
182vec3 advectedTexture(vec2 uv, vec2 velocity, vec2 normalDirection, float split) {
183 vec2 direction = normalize(velocity + normalDirection * 0.8 + vec2(0.0001));
184 vec2 across = vec2(-direction.y, direction.x);
185 vec3 smear = texture(samp, mirrorUV(uv)).rgb * 0.4;
186 smear += texture(samp, mirrorUV(uv + direction * 0.004)).rgb * 0.24;
187 smear += texture(samp, mirrorUV(uv - direction * 0.004)).rgb * 0.24;
188 smear += texture(samp, mirrorUV(uv + across * 0.0025)).rgb * 0.06;
189 smear += texture(samp, mirrorUV(uv - across * 0.0025)).rgb * 0.06;
190 return vec3(texture(samp, mirrorUV(uv + across * split)).r,
191 smear.g,
192 texture(samp, mirrorUV(uv - across * split)).b);
193}
194
195/**
196 * @brief Evaluates specularLobe for this shader effect.
197 * @param n Input value for the calculation.
198 * @param v Input value for the calculation.
199 * @param l Input value for the calculation.
200 * @param power Input value for the calculation.
201 * @return Computed float value.
202 */
203float specularLobe(vec3 n, vec3 v, vec3 l, float power) {
204 return pow(max(dot(n, normalize(v + l)), 0.0), power);
205}
206
207/**
208 * @brief Evaluates moltenLighting for this shader effect.
209 * @param base Input value for the calculation.
210 * @param n Input value for the calculation.
211 * @param p Input value for the calculation.
212 * @param heat Input value for the calculation.
213 * @return Computed vec3 value.
214 */
215vec3 moltenLighting(vec3 base, vec3 n, vec2 p, float heat) {
216 vec3 view = normalize(vec3(-p * 0.11, 1.4));
217 vec3 key = normalize(vec3(-0.62, 0.48, 0.73));
218 vec3 fill = normalize(vec3(0.71, 0.34, 0.61));
219 vec3 rim = normalize(vec3(0.08, -0.78, 0.62));
220 float nv = max(dot(n, view), 0.0);
221 vec3 f0 = mix(vec3(0.66), base, 0.55);
222 vec3 fresnel = f0 + (1.0 - f0) * pow(1.0 - nv, 5.0);
223 vec3 reflected = reflect(-view, n);
224 vec3 environment = mix(vec3(0.018, 0.028, 0.06),
225 spectral(reflected.y * 0.2 + heat * 0.08 + time_f * 0.018),
226 smoothstep(-0.55, 0.8, reflected.z));
227
228 vec3 result = base * (0.035 + 0.08 * max(dot(n, key), 0.0));
229 result += fresnel * environment * 1.2;
230 result += specularLobe(n, view, key, 150.0) * vec3(1.0, 0.7, 0.36) * 2.6;
231 result += specularLobe(n, view, fill, 55.0) * vec3(0.35, 0.62, 1.0) * 1.2;
232 result += specularLobe(n, view, rim, 24.0) * vec3(0.9, 0.2, 0.08) * 0.75;
233 return result;
234}
235
236/**
237 * @brief Evaluates toneMap for this shader effect.
238 * @param value Input value for the calculation.
239 * @return Computed vec3 value.
240 */
241vec3 toneMap(vec3 value) {
242 value = max(value, 0.0);
243 return 1.0 - exp(-value * (1.03 + value * 0.1));
244}
245
246/**
247 * @brief Executes the fragment shader entry point.
248 */
249void main(void) {
250 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
251 vec2 p = (tc - 0.5) * vec2(aspect, 1.0);
252 float e = 1.6 / max(max(iResolution.x, iResolution.y), 320.0);
253 float height = helixPotential(p);
254 vec3 n = liquidNormal(p, e);
255 vec2 velocity = helixVelocity(p);
256 velocity = velocity / (1.0 + length(velocity) * 2.2);
257
258 float flowStrength = 0.042 + amp_low * 0.025;
259 vec2 flow = velocity * flowStrength + n.xy * (0.017 + amp_smooth * 0.016);
260 flow += vec2(sin(p.y * 12.0 - time_f * 1.8), cos(p.x * 11.0 + time_f * 1.5)) * 0.004;
261 vec2 uv = mirrorUV(tc + flow / vec2(aspect, 1.0));
262
263 float split = 0.0018 + amp_high * 0.006;
264 vec3 source = advectedTexture(uv, velocity, n.xy, split);
265 float luminance = dot(source, vec3(0.299, 0.587, 0.114));
266 vec3 alloy = mix(vec3(luminance) * vec3(0.86, 0.79, 0.72), source, 0.42);
267 float heat = smoothstep(0.36, 0.92, flowFbm(p * 5.0 - vec2(time_f * 0.1, 0.0)));
268 vec3 result = moltenLighting(alloy, n, p, heat);
269
270 float vein = pow(0.5 + 0.5 * sin(height * 12.0 - time_f * 2.8), 12.0);
271 vec3 emission = heatPalette(clamp(heat + vein * 0.35, 0.0, 1.0));
272 result += emission * vein * (0.28 + amp_peak * 1.35);
273 result += heatPalette(heat) * heat * heat * 0.13;
274 result = mix(result, result * (0.6 + source), 0.2);
275 color = vec4(toneMap(result * (1.0 + amp_smooth * 0.27)), texture(samp, uv).a);
276}
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_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 n(vec2 p)
Evaluates n for this shader effect.
float field(vec2 p, float tm)
Evaluates field for this shader effect.
float luminance(vec3 c)
Evaluates luminance for this shader effect.
float noise21(vec2 p)
Evaluates noise21 for this shader effect.
vec2 cell(vec2 p)
Evaluates cell for this shader effect.
#define TAU
#define PI
vec3 toneMap(vec3 value)
Evaluates toneMap for this shader effect.
float flowFbm(vec2 p)
Evaluates flowFbm for this shader effect.
float specularLobe(vec3 n, vec3 v, vec3 l, float power)
Evaluates specularLobe for this shader effect.
vec3 advectedTexture(vec2 uv, vec2 velocity, vec2 normalDirection, float split)
Evaluates advectedTexture for this shader effect.
vec2 helixVelocity(vec2 p)
Evaluates helixVelocity for this shader effect.
vec3 liquidNormal(vec2 p, float e)
Evaluates liquidNormal for this shader effect.
float helixPotential(vec2 p)
Evaluates helixPotential for this shader effect.
vec3 heatPalette(float x)
Evaluates heatPalette for this shader effect.
vec3 moltenLighting(vec3 base, vec3 n, vec2 p, float heat)
Evaluates moltenLighting for this shader effect.
float alloy(vec2 p)
Evaluates alloy for this shader effect.
vec2 twist(vec2 coord, float twistAmount, float time, float direction)
Evaluates twist for this shader effect.