ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
Liquid_Heat.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file Liquid_Heat.frag
5 * @brief Vulkan fragment shader: Liquid Heat.
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 iMouse ext.mouse
18#define iResolution ext.u0.zw
19#define time_f ext.u2.y
20
21layout(set = 0, binding = 0) uniform sampler2D samp;
22
23
24
25layout(location = 0) out vec4 color;
26layout(location = 0) in vec2 tc;
27
28// Controls
29const float iAmplitude = 1.0; // Controls Liquid Intensity
30const float iFrequency = 1.0; // Controls Fractal/Kaleidoscope Complexity
31const float iBrightness = 1.0;
32const float iContrast = 1.1;
33const float iSaturation = 1.3;
34const float iHueShift = 0.0;
35const float iZoom = 1.0;
36const float iRotation = 0.0;
37
38// --- UTILITY FUNCTIONS ---
39
40/**
41 * @brief Evaluates pingPong for this shader effect.
42 * @param x Input value for the calculation.
43 * @param length Input value for the calculation.
44 * @return Computed float value.
45 */
46float pingPong(float x, float length) {
47 float modVal = mod(x, length * 2.0);
48 return modVal <= length ? modVal : length * 2.0 - modVal;
49}
50
51/**
52 * @brief Evaluates adjustBrightness for this shader effect.
53 * @param col Input value for the calculation.
54 * @param b Input value for the calculation.
55 * @return Computed vec3 value.
56 */
57vec3 adjustBrightness(vec3 col, float b) { return col * b; }
58/**
59 * @brief Evaluates adjustContrast for this shader effect.
60 * @param col Input value for the calculation.
61 * @param c Input value for the calculation.
62 * @return Computed vec3 value.
63 */
64vec3 adjustContrast(vec3 col, float c) { return (col - 0.5) * c + 0.5; }
65/**
66 * @brief Evaluates adjustSaturation for this shader effect.
67 * @param col Input value for the calculation.
68 * @param s Input value for the calculation.
69 * @return Computed vec3 value.
70 */
71vec3 adjustSaturation(vec3 col, float s) {
72 float gray = dot(col, vec3(0.299, 0.587, 0.114));
73 return mix(vec3(gray), col, s);
74}
75/**
76 * @brief Evaluates rotateHue for this shader effect.
77 * @param col Input value for the calculation.
78 * @param angle Input value for the calculation.
79 * @return Computed vec3 value.
80 */
81vec3 rotateHue(vec3 col, float angle) {
82 float U = cos(angle); float W = sin(angle);
83 mat3 R = mat3(
84 0.299+0.701*U+0.168*W, 0.587-0.587*U+0.330*W, 0.114-0.114*U-0.497*W,
85 0.299-0.299*U-0.328*W, 0.587+0.413*U+0.035*W, 0.114-0.114*U+0.292*W,
86 0.299-0.300*U+1.250*W, 0.587-0.588*U-1.050*W, 0.114+0.886*U-0.203*W
87 );
88 return clamp(R * col, 0.0, 1.0);
89}
90
91// --- NEON PALETTE (Pink/Purple/Blue) ---
92/**
93 * @brief Evaluates getNeonPalette for this shader effect.
94 * @param t Input value for the calculation.
95 * @return Computed vec3 value.
96 */
97vec3 getNeonPalette(float t) {
98 float x = fract(t); // Note: Hue shift handled in post-process now
99 vec3 colBlue = vec3(0.05, 0.2, 1.0);
100 vec3 colPurple = vec3(0.7, 0.0, 1.0);
101 vec3 colPink = vec3(1.0, 0.05, 0.5);
102
103 if (x < 0.33) return mix(colBlue, colPurple, x * 3.0);
104 else if (x < 0.66) return mix(colPurple, colPink, (x - 0.33) * 3.0);
105 else return mix(colPink, colBlue, (x - 0.66) * 3.0);
106}
107
108// --- COORDINATE HELPERS ---
109
110/**
111 * @brief Evaluates wrapUV for this shader effect.
112 * @param tc Input value for the calculation.
113 * @return Computed vec2 value.
114 */
115vec2 wrapUV(vec2 tc) {
116 return 1.0 - abs(1.0 - 2.0 * fract(tc * 0.5));
117}
118
119// Robust texture sampler from Shader 2
120/**
121 * @brief Evaluates mxTexture for this shader effect.
122 * @param tex Input value for the calculation.
123 * @param tc Input value for the calculation.
124 * @return Computed vec4 value.
125 */
126vec4 mxTexture(sampler2D tex, vec2 tc) {
127 vec2 ts = vec2(textureSize(tex, 0));
128 vec2 eps = 0.5 / ts;
129 vec2 uv = wrapUV(tc);
130 vec2 sampleUV = clamp(uv, eps, 1.0 - eps);
131 float lod = 0.0;
132 vec2 deriv = fwidth(tc);
133 if (deriv.x > 0.0 || deriv.y > 0.0) {
134 lod = log2(max(max(deriv.x, deriv.y) * max(ts.x, ts.y), 1.0));
135 }
136 return textureLod(tex, sampleUV, lod);
137}
138
139/**
140 * @brief Evaluates rotate2D for this shader effect.
141 * @param p Input value for the calculation.
142 * @param a Input value for the calculation.
143 * @return Computed vec2 value.
144 */
145vec2 rotate2D(vec2 p, float a) {
146 float c = cos(a); float s = sin(a);
147 return mat2(c, -s, s, c) * p;
148}
149
150// --- FRACTAL & GEOMETRY FUNCTIONS ---
151
152/**
153 * @brief Evaluates kaleido for this shader effect.
154 * @param p Input value for the calculation.
155 * @param slices Input value for the calculation.
156 * @return Computed vec2 value.
157 */
158vec2 kaleido(vec2 p, float slices) {
159 float pi = 3.14159265359;
160 float r = length(p);
161 float a = atan(p.y, p.x);
162 float sector = pi * 2.0 / slices;
163 a = mod(a, sector);
164 a = abs(a - sector * 0.5);
165 return vec2(cos(a), sin(a)) * r;
166}
167
168// --- NOISE ---
169/**
170 * @brief Evaluates hash for this shader effect.
171 * @param p Input value for the calculation.
172 * @return Computed float value.
173 */
174float hash(vec2 p) {
175 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
176}
177
178/**
179 * @brief Evaluates noise for this shader effect.
180 * @param p Input value for the calculation.
181 * @return Computed float value.
182 */
183float noise(vec2 p) {
184 vec2 i = floor(p);
185 vec2 f = fract(p);
186 vec2 u = f * f * (3.0 - 2.0 * f);
187 return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),
188 mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
189}
190
191/**
192 * @brief Evaluates fbm for this shader effect.
193 * @param p Input value for the calculation.
194 * @return Computed float value.
195 */
196float fbm(vec2 p) {
197 float v = 0.0;
198 float a = 0.5;
199 mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.5));
200 for (int i = 0; i < 4; i++) {
201 v += a * noise(p);
202 p = rot * p * 2.0 + vec2(100.0);
203 a *= 0.5;
204 }
205 return v;
206}
207
208// --- COMBINED RENDER LOGIC ---
209
210/**
211 * @brief Evaluates sampleSuperShader for this shader effect.
212 * @param uv Input value for the calculation.
213 * @param t Input value for the calculation.
214 * @param center Input value for the calculation.
215 * @param res Input value for the calculation.
216 * @return Computed vec3 value.
217 */
218vec3 sampleSuperShader(vec2 uv, float t, vec2 center, vec2 res) {
219 float aspect = res.x / res.y;
220 vec2 p = (uv - center) * vec2(aspect, 1.0);
221
222 // 1. Zoom & Rotation
223 p = rotate2D(p, iRotation);
224 float zoom = max(iZoom, 0.01);
225 p /= zoom;
226
227 // 2. The PingPong Wave (From Shader 3)
228 // We apply this early so the fractal/liquid logic acts ON the wave
229 float time_t = pingPong(time_f, 10.0) + 1.0;
230 float time_s = pingPong(time_f, 5.0);
231 float waveFreq = 2.0 + iFrequency * 2.0;
232 float waveAmp = 0.1 * sin(0.2 * time_t) * iAmplitude;
233 float waveSpd = sin(0.3 * time_s);
234
235 p.y += sin(p.x * waveFreq + time_f * waveSpd) * waveAmp;
236
237 // 3. Fractal Geometry (From Shader 2)
238 // Only activates if iFrequency is > 0.2 to allow pure liquid looks
239 if (iFrequency > 0.2) {
240 float slices = 4.0 + floor(iFrequency * 6.0);
241 p = kaleido(p, slices);
242
243 int iterations = 2 + int(iFrequency * 2.0);
244 float scale = 1.1;
245 float shift = 0.1;
246 for(int i = 0; i < iterations; i++) {
247 p = abs(p);
248 p -= shift;
249 p *= scale;
250 p = rotate2D(p, t * 0.05 + float(i));
251 }
252 }
253
254 // 4. Liquid Domain Warping (From Shader 1)
255 // Warps the geometric result into a fluid
256 vec2 q = vec2(0.0);
257 q.x = fbm(p + vec2(0.0, 0.0) + 0.05*t);
258 q.y = fbm(p + vec2(5.2, 1.3) + 0.05*t);
259
260 vec2 r = vec2(0.0);
261 r.x = fbm(p + 4.0*q + vec2(t * 0.1));
262 r.y = fbm(p + 4.0*q + vec2(t * 0.05, 2.8));
263
264 // Calculate final distortion
265 // Strength depends on amplitude
266 float liquidStrength = 0.2 + (iAmplitude * 0.5);
267 vec2 distortion = r * liquidStrength;
268
269 // 5. Texture Sampling
270 // Use the warped coordinates to sample
271 vec2 finalUV = uv + distortion;
272
273 // Apply the wave again to the lookup for consistency
274 finalUV.y += sin(finalUV.x * waveFreq + time_f * waveSpd) * waveAmp;
275
276 vec3 texCol = mxTexture(samp, finalUV).rgb;
277
278 // 6. Color Blending (Texture Mapped Neon)
279
280 // Generate Neon Palette based on warp intensity
281 float pattern = length(q) + length(r) + t * 0.1;
282 vec3 neon = getNeonPalette(pattern);
283
284 // Blend: Multiply Texture * Neon * Brightness Boost
285 // This tints the texture while keeping the "light" look
286 vec3 col = texCol * neon * 2.0;
287
288 // Restore some original texture color in the "calm" areas
289 float turbulence = length(r);
290 col = mix(col, texCol, max(0.0, 1.0 - turbulence * 2.0));
291
292 return col;
293}
294
295/**
296 * @brief Executes the fragment shader entry point.
297 */
298void main() {
299 vec2 uv = tc;
300 uv = wrapUV(uv);
301
302 float t = time_f * 0.2;
303
304 vec2 center = vec2(0.5);
305 if (iMouse.z > 0.0) {
306 center = iMouse.xy / iResolution;
307 }
308
309 // Chromatic Aberration
310 // We offset the lookup for each channel slightly
311 float caStrength = 0.003 * (1.0 + iAmplitude);
312
313 vec3 col;
314 col.r = sampleSuperShader(uv + vec2(caStrength, 0.0), t, center, iResolution).r;
315 col.g = sampleSuperShader(uv, t, center, iResolution).g;
316 col.b = sampleSuperShader(uv - vec2(caStrength, 0.0), t, center, iResolution).b;
317
318 // Post Processing (Hue Rotate, Brightness, etc)
319 col = adjustBrightness(col, iBrightness);
320 col = adjustContrast(col, iContrast);
321 col = adjustSaturation(col, iSaturation);
322 col = rotateHue(col, iHueShift);
323
324 // Vignette
325 vec2 vUV = uv * (1.0 - uv.yx);
326 float vig = vUV.x * vUV.y * 15.0;
327 vig = pow(vig, 0.2);
328 col *= vig;
329
330 color = vec4(col, 1.0);
331}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
#define iMouse
Definition 3high.frag:17
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
vec4 mxTexture(sampler2D tex, vec2 tc)
Evaluates mxTexture for this shader effect.
const float iFrequency
const float iRotation
vec3 adjustBrightness(vec3 col, float b)
Evaluates adjustBrightness for this shader effect.
const float iBrightness
vec2 wrapUV(vec2 tc)
Evaluates wrapUV for this shader effect.
vec3 adjustSaturation(vec3 col, float s)
Evaluates adjustSaturation for this shader effect.
vec3 adjustContrast(vec3 col, float c)
Evaluates adjustContrast for this shader effect.
const float iAmplitude
const float iSaturation
vec3 rotateHue(vec3 col, float angle)
Evaluates rotateHue for this shader effect.
const float iContrast
const float iHueShift
const float iZoom
vec3 getNeonPalette(float t)
Evaluates getNeonPalette for this shader effect.
vec3 sampleSuperShader(vec2 uv, float t, vec2 center, vec2 res)
Evaluates sampleSuperShader for this shader effect.
float fbm(vec2 point)
Evaluates fbm for this shader effect.
float pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
float hash(vec2 p)
Evaluates hash for this shader effect.
float noise(vec2 p)
Evaluates noise for this shader effect.
vec3 neon(float t)
Evaluates neon for this shader effect.
vec2 kaleido(vec2 p, float seg)
Evaluates kaleido for this shader effect.
mat2 R(float a)
Evaluates R for this shader effect.
float W(vec2 p)
Evaluates W for this shader effect.
mat2 rotate2D(float a)
Evaluates rotate2D for this shader effect.