ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
Liquid_Crystal.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file Liquid_Crystal.frag
5 * @brief Vulkan fragment shader: Liquid Crystal.
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;
30const float iFrequency = 1.0;
31const float iBrightness = 1.0;
32const float iContrast = 1.0;
33const float iSaturation = 1.0;
34const float iHueShift = 0.0;
35const float iZoom = 1.0;
36const float iRotation = 0.0;
37
38// --- COLOR HELPER FUNCTIONS ---
39
40/**
41 * @brief Evaluates adjustBrightness for this shader effect.
42 * @param col Input value for the calculation.
43 * @param b Input value for the calculation.
44 * @return Computed vec3 value.
45 */
46vec3 adjustBrightness(vec3 col, float b) { return col * b; }
47/**
48 * @brief Evaluates adjustContrast for this shader effect.
49 * @param col Input value for the calculation.
50 * @param c Input value for the calculation.
51 * @return Computed vec3 value.
52 */
53vec3 adjustContrast(vec3 col, float c) { return (col - 0.5) * c + 0.5; }
54/**
55 * @brief Evaluates adjustSaturation for this shader effect.
56 * @param col Input value for the calculation.
57 * @param s Input value for the calculation.
58 * @return Computed vec3 value.
59 */
60vec3 adjustSaturation(vec3 col, float s) {
61 float gray = dot(col, vec3(0.299, 0.587, 0.114));
62 return mix(vec3(gray), col, s);
63}
64/**
65 * @brief Evaluates rotateHue for this shader effect.
66 * @param col Input value for the calculation.
67 * @param angle Input value for the calculation.
68 * @return Computed vec3 value.
69 */
70vec3 rotateHue(vec3 col, float angle) {
71 float U = cos(angle); float W = sin(angle);
72 mat3 R = mat3(
73 0.299+0.701*U+0.168*W, 0.587-0.587*U+0.330*W, 0.114-0.114*U-0.497*W,
74 0.299-0.299*U-0.328*W, 0.587+0.413*U+0.035*W, 0.114-0.114*U+0.292*W,
75 0.299-0.300*U+1.250*W, 0.587-0.588*U-1.050*W, 0.114+0.886*U-0.203*W
76 );
77 return clamp(R * col, 0.0, 1.0);
78}
79
80// IQ Cosine Palette (from Shader 2)
81/**
82 * @brief Evaluates palette for this shader effect.
83 * @param t Input value for the calculation.
84 * @return Computed vec3 value.
85 */
86vec3 palette(float t) {
87 vec3 a = vec3(0.5, 0.5, 0.5);
88 vec3 b = vec3(0.5, 0.5, 0.5);
89 vec3 c = vec3(1.0, 1.0, 1.0);
90 vec3 d = vec3(0.263, 0.416, 0.557);
91 return a + b * cos(6.28318 * (c * t + d + iHueShift));
92}
93
94// --- COORDINATE HELPERS ---
95
96/**
97 * @brief Evaluates wrapUV for this shader effect.
98 * @param tc Input value for the calculation.
99 * @return Computed vec2 value.
100 */
101vec2 wrapUV(vec2 tc) {
102 return 1.0 - abs(1.0 - 2.0 * fract(tc * 0.5));
103}
104
105/**
106 * @brief Evaluates mxTexture for this shader effect.
107 * @param tex Input value for the calculation.
108 * @param tc Input value for the calculation.
109 * @return Computed vec4 value.
110 */
111vec4 mxTexture(sampler2D tex, vec2 tc) {
112 vec2 ts = vec2(textureSize(tex, 0));
113 vec2 eps = 0.5 / ts;
114 vec2 uv = wrapUV(tc);
115 vec2 sampleUV = clamp(uv, eps, 1.0 - eps);
116 float lod = 0.0;
117 return textureLod(tex, sampleUV, lod);
118}
119
120/**
121 * @brief Evaluates rotate2D for this shader effect.
122 * @param p Input value for the calculation.
123 * @param a Input value for the calculation.
124 * @return Computed vec2 value.
125 */
126vec2 rotate2D(vec2 p, float a) {
127 float c = cos(a); float s = sin(a);
128 return mat2(c, -s, s, c) * p;
129}
130
131// --- NOISE & WARP FUNCTIONS ---
132
133/**
134 * @brief Evaluates hash for this shader effect.
135 * @param p Input value for the calculation.
136 * @return Computed float value.
137 */
138float hash(vec2 p) {
139 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
140}
141
142/**
143 * @brief Evaluates noise for this shader effect.
144 * @param p Input value for the calculation.
145 * @return Computed float value.
146 */
147float noise(vec2 p) {
148 vec2 i = floor(p);
149 vec2 f = fract(p);
150 vec2 u = f * f * (3.0 - 2.0 * f);
151 float a = hash(i + vec2(0.0, 0.0));
152 float b = hash(i + vec2(1.0, 0.0));
153 float c = hash(i + vec2(0.0, 1.0));
154 float d = hash(i + vec2(1.0, 1.0));
155 return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
156}
157
158// Combined FBM: Can do smooth liquid or sharp ridges
159/**
160 * @brief Evaluates fbm for this shader effect.
161 * @param p Input value for the calculation.
162 * @param ridges Input value for the calculation.
163 * @return Computed float value.
164 */
165float fbm(vec2 p, bool ridges) {
166 float v = 0.0;
167 float a = 0.5;
168 for (int i = 0; i < 4; i++) {
169 float n = noise(p);
170 if (ridges) n = 1.0 - abs(n * 2.0 - 1.0);
171 v += a * n;
172 p *= 2.05;
173 a *= 0.5;
174 }
175 return v;
176}
177
178/**
179 * @brief Evaluates kaleido for this shader effect.
180 * @param p Input value for the calculation.
181 * @param slices Input value for the calculation.
182 * @return Computed vec2 value.
183 */
184vec2 kaleido(vec2 p, float slices) {
185 float pi = 3.14159265359;
186 float r = length(p);
187 float a = atan(p.y, p.x);
188 float sector = pi * 2.0 / slices;
189 a = mod(a, sector);
190 a = abs(a - sector * 0.5);
191 return vec2(cos(a), sin(a)) * r;
192}
193
194// --- HYBRID RENDER LOGIC ---
195
196/**
197 * @brief Evaluates sampleHybrid for this shader effect.
198 * @param uv Input value for the calculation.
199 * @param t Input value for the calculation.
200 * @param strength Input value for the calculation.
201 * @param center Input value for the calculation.
202 * @param res Input value for the calculation.
203 * @return Computed vec3 value.
204 */
205vec3 sampleHybrid(vec2 uv, float t, float strength, vec2 center, vec2 res) {
206 float aspect = res.x / res.y;
207 vec2 p = (uv - center) * vec2(aspect, 1.0);
208
209 // 1. Initial Zoom/Rot (Shader 1 style)
210 p = rotate2D(p, iRotation);
211 float zoom = max(iZoom, 0.01);
212 p /= zoom;
213
214 // 2. DOMAIN WARPING (The "Electric" part from Shader 2)
215 // We use this to distort the space BEFORE the fractal folding
216 vec2 q = vec2(0.0);
217 q.x = fbm(p + vec2(0.0, 0.0) + t * 0.1, false);
218 q.y = fbm(p + vec2(5.2, 1.3) - t * 0.1, false);
219
220 vec2 r = vec2(0.0);
221 r.x = fbm(p + 4.0 * q + vec2(t * 0.2, 9.2), true); // Ridges = True for electric feel
222 r.y = fbm(p + 4.0 * q + vec2(8.3, 2.8), false);
223
224 // Apply the warp to p
225 // strength controls how much the "electricity" melts the geometry
226 p += r * (0.1 * strength);
227
228 // 3. FRACTAL FOLDING (The "Structure" part from Shader 1)
229
230 // Kaleidoscope Step
231 float slices = 6.0 + floor(iAmplitude * 4.0);
232 p = kaleido(p, slices);
233
234 // Iterative Box Folding
235 int iterations = 4 + int(iAmplitude * 1.5);
236 float scale = 1.1 + (iFrequency * 0.3);
237 float shift = 0.1 * strength;
238 float angle = t * 0.2;
239
240 // We inject the noise value 'r.x' into the rotation to make the shape vibrate
241 for(int i = 0; i < iterations; i++) {
242 p = abs(p);
243 p -= shift;
244 p *= scale;
245 p = rotate2D(p, angle + float(i)*0.5 + (r.x * 0.2));
246 }
247
248 // 4. TEXTURE & COLOR COMPOSITION
249
250 // Map back to UV space
251 vec2 finalUV = p * 0.5 + center;
252
253 // Sample Texture
254 vec3 texCol = mxTexture(samp, finalUV).rgb;
255
256 // Generate Electric Glow (Shader 2 Logic)
257 // We use the magnitude of the warp 'r' to create glowing lines
258 float electric = pow(length(r), 3.0) * iContrast;
259
260 // Generate Palette
261 vec3 pal = palette(length(p) + length(q) + t);
262
263 // Mix: Texture provides the base, Palette provides the neon energy
264 vec3 finalCol = mix(texCol, pal, 0.4 * iSaturation);
265
266 // Additive glow on top
267 finalCol += pal * electric * strength;
268
269 return finalCol;
270}
271
272/**
273 * @brief Executes the fragment shader entry point.
274 */
275void main() {
276 vec2 uv = tc;
277 uv = wrapUV(uv);
278
279 float t = time_f * (0.2 + iFrequency * 0.2);
280 float ampControl = clamp(iAmplitude, 0.0, 2.0);
281 float strength = 0.5 + (ampControl * 1.0);
282
283 vec2 center = vec2(0.5);
284 if (iMouse.z > 0.0) {
285 center = iMouse.xy / iResolution;
286 }
287
288 // Chromatic Aberration applied to the Hybrid function
289 // We offset the start position for each channel
290 vec2 offset = vec2(0.003 * strength, 0.0);
291
292 vec3 col;
293 col.r = sampleHybrid(uv + offset, t, strength, center, iResolution).r;
294 col.g = sampleHybrid(uv, t, strength, center, iResolution).g;
295 col.b = sampleHybrid(uv - offset, t, strength, center, iResolution).b;
296
297 // Post Processing
298 col = adjustBrightness(col, iBrightness);
299 col = adjustContrast(col, iContrast);
300 col = adjustSaturation(col, iSaturation);
301
302 // Vignette (from Shader 2)
303 vec2 vUV = uv * (1.0 - uv.yx);
304 float vig = vUV.x * vUV.y * 15.0;
305 vig = pow(vig, 0.15); // Softer vignette
306 col *= vig;
307
308 color = vec4(col, 1.0);
309}
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 sampleHybrid(vec2 uv, float t, float strength, vec2 center, vec2 res)
Evaluates sampleHybrid for this shader effect.
float fbm(vec2 point)
Evaluates fbm for this shader effect.
vec3 palette(float phase)
Evaluates palette for this shader effect.
float hash(vec2 p)
Evaluates hash for this shader effect.
float noise(vec2 p)
Evaluates noise for this shader effect.
vec2 kaleido(vec2 p, float seg)
Evaluates kaleido for this shader effect.
vec3 pal(float t)
Evaluates pal for this shader effect.
mat2 R(float a)
Evaluates R for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
float W(vec2 p)
Evaluates W for this shader effect.
mat2 rotate2D(float a)
Evaluates rotate2D for this shader effect.
#define strength
Definition ol.frag:16