ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
halluc_liquid.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file halluc_liquid.frag
5 * @brief Vulkan fragment shader: halluc liquid.
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// --- Helper Functions ---
39
40// IQ's Cosine Palette - standard for psychedelic shaders
41/**
42 * @brief Evaluates palette for this shader effect.
43 * @param t Input value for the calculation.
44 * @return Computed vec3 value.
45 */
46vec3 palette(float t) {
47 vec3 a = vec3(0.5, 0.5, 0.5);
48 vec3 b = vec3(0.5, 0.5, 0.5);
49 vec3 c = vec3(1.0, 1.0, 1.0);
50 vec3 d = vec3(0.263, 0.416, 0.557); // Trippy Blue/Purple/Cyan offset
51 return a + b * cos(6.28318 * (c * t + d + iHueShift));
52}
53
54/**
55 * @brief Evaluates adjustBrightness for this shader effect.
56 * @param col Input value for the calculation.
57 * @param b Input value for the calculation.
58 * @return Computed vec3 value.
59 */
60vec3 adjustBrightness(vec3 col, float b) { return col * b; }
61/**
62 * @brief Evaluates adjustContrast for this shader effect.
63 * @param col Input value for the calculation.
64 * @param c Input value for the calculation.
65 * @return Computed vec3 value.
66 */
67vec3 adjustContrast(vec3 col, float c) { return (col - 0.5) * c + 0.5; }
68/**
69 * @brief Evaluates adjustSaturation for this shader effect.
70 * @param col Input value for the calculation.
71 * @param s Input value for the calculation.
72 * @return Computed vec3 value.
73 */
74vec3 adjustSaturation(vec3 col, float s) {
75 float gray = dot(col, vec3(0.299, 0.587, 0.114));
76 return mix(vec3(gray), col, s);
77}
78
79// Triangle wave wrap function
80/**
81 * @brief Evaluates wrapUV for this shader effect.
82 * @param tc Input value for the calculation.
83 * @return Computed vec2 value.
84 */
85vec2 wrapUV(vec2 tc) {
86 return 1.0 - abs(1.0 - 2.0 * fract(tc * 0.5));
87}
88
89/**
90 * @brief Evaluates mxTexture for this shader effect.
91 * @param tex Input value for the calculation.
92 * @param tc Input value for the calculation.
93 * @return Computed vec4 value.
94 */
95vec4 mxTexture(sampler2D tex, vec2 tc) {
96 vec2 ts = vec2(textureSize(tex, 0));
97 vec2 eps = 0.5 / ts;
98 vec2 uv = wrapUV(tc);
99 vec2 sampleUV = clamp(uv, eps, 1.0 - eps);
100 float lod = 0.0; // Simplified for performance in complex loops
101 return textureLod(tex, sampleUV, lod);
102}
103
104// --- Procedural Logic ---
105
106/**
107 * @brief Evaluates hash for this shader effect.
108 * @param p Input value for the calculation.
109 * @return Computed float value.
110 */
111float hash(vec2 p) {
112 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
113}
114
115// 2D Noise
116/**
117 * @brief Evaluates noise for this shader effect.
118 * @param p Input value for the calculation.
119 * @return Computed float value.
120 */
121float noise(vec2 p) {
122 vec2 i = floor(p);
123 vec2 f = fract(p);
124 vec2 u = f * f * (3.0 - 2.0 * f);
125 float a = hash(i + vec2(0.0, 0.0));
126 float b = hash(i + vec2(1.0, 0.0));
127 float c = hash(i + vec2(0.0, 1.0));
128 float d = hash(i + vec2(1.0, 1.0));
129 return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
130}
131
132// FBM with "Ridge" option for electricity
133/**
134 * @brief Evaluates fbm for this shader effect.
135 * @param p Input value for the calculation.
136 * @param ridges Input value for the calculation.
137 * @return Computed float value.
138 */
139float fbm(vec2 p, bool ridges) {
140 float v = 0.0;
141 float a = 0.5;
142 for (int i = 0; i < 4; i++) { // Reduced iterations for perf, increased visual complexity elsewhere
143 float n = noise(p);
144 if (ridges) n = 1.0 - abs(n * 2.0 - 1.0); // Create sharp valleys
145 v += a * n;
146 p *= 2.05;
147 a *= 0.5;
148 }
149 return v;
150}
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// Rotator
169/**
170 * @brief Evaluates rot for this shader effect.
171 * @param a Input value for the calculation.
172 * @return Computed mat2 value.
173 */
174mat2 rot(float a) {
175 float c = cos(a), s = sin(a);
176 return mat2(c, -s, s, c);
177}
178
179/**
180 * @brief Evaluates renderEnergy for this shader effect.
181 * @param uv Input value for the calculation.
182 * @param t Input value for the calculation.
183 * @param strength Input value for the calculation.
184 * @param center Input value for the calculation.
185 * @param res Input value for the calculation.
186 * @return Computed vec3 value.
187 */
188vec3 renderEnergy(vec2 uv, float t, float strength, vec2 center, vec2 res) {
189 float aspect = res.x / res.y;
190 vec2 p = (uv - center) * vec2(aspect, 1.0);
191
192 // Zoom/Rotate Pre-pass
193 p *= rot(iRotation + t * 0.1);
194 float zoomLvl = max(iZoom, 0.1);
195 p /= zoomLvl;
196
197 // --- Domain Warping (The Psychedelic Melt) ---
198 vec2 q = vec2(0.0);
199 q.x = fbm(p + vec2(0.0, 0.0) + t * 0.2, false);
200 q.y = fbm(p + vec2(5.2, 1.3) - t * 0.15, false);
201
202 vec2 r = vec2(0.0);
203 r.x = fbm(p + 4.0 * q + vec2(t * 0.5, 9.2), true); // Ridged noise here for electricity
204 r.y = fbm(p + 4.0 * q + vec2(8.3, 2.8), false);
205
206 // Distort the UVs heavily for the kaleidoscope
207 vec2 warpedUV = p + strength * r;
208
209 // Dynamic Kaleidoscope slices
210 float slices = 6.0 + 10.0 * sin(t * 0.1) * iAmplitude;
211 vec2 k = kaleido(warpedUV, max(3.0, slices));
212
213 // --- Texture Sampling ---
214 // We sample the texture using the chaotic warped coordinates
215 vec2 texUV = k / vec2(aspect, 1.0) + center;
216 texUV += r * 0.1; // Add noise offset
217
218 vec3 texCol = mxTexture(samp, texUV).rgb;
219
220 // --- Energy Injection ---
221 // Create a "glow" mask based on the magnitude of the distortion
222 float warpLen = length(r);
223
224 // 1. Electric ridges: High values in 'r' create bright lines
225 float electric = pow(warpLen, 3.0) * iContrast;
226
227 // 2. Color Palette injection
228 // Mix the texture color with a procedural palette based on noise
229 vec3 pal = palette(length(q) + t * 0.4);
230
231 // Composition
232 vec3 finalCol = mix(texCol, pal, 0.5 * iSaturation); // Blend texture and palette
233
234 // Additive mixing for "Light" effect
235 finalCol += pal * electric * strength;
236
237 // Sharp white hot core
238 finalCol += vec3(smoothstep(0.8, 1.0, electric)) * 2.0;
239
240 return finalCol;
241}
242
243/**
244 * @brief Executes the fragment shader entry point.
245 */
246void main() {
247 vec2 uv = tc;
248 uv = wrapUV(uv); // Keep your mirror wrap, it's good for seamlessness
249
250 float t = time_f * (0.2 + iFrequency * 0.5);
251 float strength = iAmplitude * 1.5;
252
253 vec2 center = vec2(0.5);
254 if (iMouse.z > 0.0) {
255 center = iMouse.xy / iResolution;
256 }
257
258 // Single pass is usually enough with this level of complexity,
259 // but we add a slight chromatic aberration for extra trippiness
260 vec3 col;
261 vec2 offset = vec2(0.005 * strength, 0.0);
262
263 col.r = renderEnergy(uv + offset, t, strength, center, iResolution).r;
264 col.g = renderEnergy(uv, t, strength, center, iResolution).g;
265 col.b = renderEnergy(uv - offset, t, strength, center, iResolution).b;
266
267 // Global adjustments
268 col = adjustBrightness(col, iBrightness);
269 // Contrast is handled partly inside renderEnergy for the glow lines
270
271 // Vignette (darkens corners to focus on the energy)
272 vec2 vUV = uv * (1.0 - uv.yx);
273 float vig = vUV.x * vUV.y * 15.0;
274 vig = pow(vig, 0.25);
275 col *= vig;
276
277 color = vec4(col, 1.0);
278}
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
const float iContrast
const float iHueShift
const float iZoom
float fbm(vec2 point)
Evaluates fbm for this shader effect.
vec3 palette(float phase)
Evaluates palette for this shader effect.
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.
vec2 kaleido(vec2 p, float seg)
Evaluates kaleido for this shader effect.
vec3 pal(float t)
Evaluates pal for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
vec3 renderEnergy(vec2 uv, float t, float strength, vec2 center, vec2 res)
Evaluates renderEnergy for this shader effect.
#define strength
Definition ol.frag:16