ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
halluc_gem2.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file halluc_gem2.frag
5 * @brief Vulkan fragment shader: halluc gem2.
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 Helpers ---
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 * @brief Evaluates applyColorAdjustments for this shader effect.
81 * @param col Input value for the calculation.
82 * @return Computed vec3 value.
83 */
84vec3 applyColorAdjustments(vec3 col) {
85 col = adjustBrightness(col, iBrightness);
86 col = adjustContrast(col, iContrast);
87 col = adjustSaturation(col, iSaturation);
88 col = rotateHue(col, iHueShift);
89 return clamp(col, 0.0, 1.0);
90}
91
92// --- Coordinate Helpers ---
93
94/**
95 * @brief Evaluates applyZoomRotation for this shader effect.
96 * @param uv Input value for the calculation.
97 * @param center Input value for the calculation.
98 * @return Computed vec2 value.
99 */
100vec2 applyZoomRotation(vec2 uv, vec2 center) {
101 vec2 p = uv - center;
102 float c = cos(iRotation); float s = sin(iRotation);
103 p = mat2(c, -s, s, c) * p;
104 float z = max(abs(iZoom), 0.001);
105 p /= z;
106 return p + center;
107}
108
109/**
110 * @brief Evaluates wrapUV for this shader effect.
111 * @param tc Input value for the calculation.
112 * @return Computed vec2 value.
113 */
114vec2 wrapUV(vec2 tc) {
115 return 1.0 - abs(1.0 - 2.0 * fract(tc * 0.5));
116}
117
118/**
119 * @brief Evaluates mxTexture for this shader effect.
120 * @param tex Input value for the calculation.
121 * @param tc Input value for the calculation.
122 * @return Computed vec4 value.
123 */
124vec4 mxTexture(sampler2D tex, vec2 tc) {
125 vec2 ts = vec2(textureSize(tex, 0));
126 vec2 eps = 0.5 / ts;
127 vec2 uv = wrapUV(tc);
128 vec2 sampleUV = clamp(uv, eps, 1.0 - eps);
129 float lod = 0.0;
130 vec2 deriv = fwidth(tc);
131 if (deriv.x > 0.0 || deriv.y > 0.0) lod = log2(max(max(deriv.x, deriv.y) * max(ts.x, ts.y), 1.0));
132 return textureLod(tex, sampleUV, lod);
133}
134
135// --- NOISE Functions (Restored for Liquid Effect) ---
136
137/**
138 * @brief Evaluates hash for this shader effect.
139 * @param p Input value for the calculation.
140 * @return Computed float value.
141 */
142float hash(vec2 p) {
143 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
144}
145
146/**
147 * @brief Evaluates noise for this shader effect.
148 * @param p Input value for the calculation.
149 * @return Computed float value.
150 */
151float noise(vec2 p) {
152 vec2 i = floor(p);
153 vec2 f = fract(p);
154 vec2 u = f * f * (3.0 - 2.0 * f);
155 float a = hash(i + vec2(0.0, 0.0));
156 float b = hash(i + vec2(1.0, 0.0));
157 float c = hash(i + vec2(0.0, 1.0));
158 float d = hash(i + vec2(1.0, 1.0));
159 return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
160}
161
162/**
163 * @brief Evaluates fbm for this shader effect.
164 * @param p Input value for the calculation.
165 * @return Computed float value.
166 */
167float fbm(vec2 p) {
168 float v = 0.0;
169 float a = 0.5;
170 for (int i = 0; i < 4; i++) { // Reduced iterations slightly for speed
171 v += a * noise(p);
172 p *= 2.0;
173 a *= 0.5;
174 }
175 return v;
176}
177
178// --- Fractal Logic ---
179
180/**
181 * @brief Evaluates rotate2D for this shader effect.
182 * @param p Input value for the calculation.
183 * @param a Input value for the calculation.
184 * @return Computed vec2 value.
185 */
186vec2 rotate2D(vec2 p, float a) {
187 float c = cos(a); float s = sin(a);
188 return mat2(c, -s, s, c) * p;
189}
190
191/**
192 * @brief Evaluates kaleido for this shader effect.
193 * @param p Input value for the calculation.
194 * @param slices Input value for the calculation.
195 * @return Computed vec2 value.
196 */
197vec2 kaleido(vec2 p, float slices) {
198 float pi = 3.14159265359;
199 float r = length(p);
200 float a = atan(p.y, p.x);
201 float sector = pi * 2.0 / slices;
202 a = mod(a, sector);
203 a = abs(a - sector * 0.5);
204 return vec2(cos(a), sin(a)) * r;
205}
206
207// Hybird: Liquid movement + Geometric Folding
208/**
209 * @brief Evaluates sampleLiquidFractal for this shader effect.
210 * @param uv Input value for the calculation.
211 * @param t Input value for the calculation.
212 * @param strength Input value for the calculation.
213 * @param center Input value for the calculation.
214 * @param res Input value for the calculation.
215 * @return Computed vec3 value.
216 */
217vec3 sampleLiquidFractal(vec2 uv, float t, float strength, vec2 center, vec2 res) {
218 float aspect = res.x / res.y;
219
220 float ampControl = clamp(iAmplitude, 0.0, 2.0);
221 float freqControl = clamp(iFrequency, 0.0, 2.0);
222
223 vec2 p = (uv - center) * vec2(aspect, 1.0);
224
225 // --- LIQUID INJECTION ---
226 // We calculate a flow field based on noise
227 // We disturb 'p' BEFORE it enters the kaleidoscope/fractal loop
228 float n1 = fbm(p * 3.0 + t * 0.4);
229 float n2 = fbm(p * 2.0 - t * 0.3);
230
231 vec2 flow = vec2(cos(n1 * 6.0), sin(n2 * 6.0));
232
233 // Add liquid wobble to the coordinates
234 // strength * 0.1 ensures it doesn't destroy the shape, just ripples it
235 p += flow * (0.05 + 0.1 * strength);
236
237 // --- GEOMETRIC FRACTAL ---
238
239 // 1. Kaleidoscope
240 float slices = 6.0 + floor(ampControl * 4.0);
241 p = kaleido(p, slices);
242
243 // 2. Iterative Folding
244 int iterations = 4 + int(ampControl * 2.0);
245 float scale = 1.2 + (freqControl * 0.5);
246 float shift = 0.1 * strength;
247 float angle = t * 0.1;
248
249 for(int i = 0; i < iterations; i++) {
250 p = abs(p);
251 p -= shift;
252 p *= scale;
253 p = rotate2D(p, angle + float(i)*0.5 + n1*0.2); // Add noise to rotation too
254 }
255
256 // 3. Map back to Texture
257 // We add the flow again at the end for "surface water" feel
258 vec2 finalUV = p * 0.5 + center + (flow * 0.02);
259
260 // Chromatic aberration based on flow intensity
261 float chroma = 0.005 * strength * (1.0 + n1);
262
263 float r = mxTexture(samp, finalUV + vec2(chroma, 0.0)).r;
264 float g = mxTexture(samp, finalUV).g;
265 float b = mxTexture(samp, finalUV - vec2(chroma, 0.0)).b;
266
267 return vec3(r, g, b);
268}
269
270/**
271 * @brief Executes the fragment shader entry point.
272 */
273void main() {
274 vec2 uv = tc;
275 uv = wrapUV(uv);
276 uv = applyZoomRotation(uv, vec2(0.5));
277
278 float ampControl = clamp(iAmplitude, 0.0, 2.0);
279
280 float tSpeed = 0.3;
281 float t = time_f * tSpeed;
282 float strength = 0.5 + (ampControl * 0.5);
283
284 vec2 center = vec2(0.5);
285 if (iMouse.z > 0.0) {
286 center = iMouse.xy / iResolution;
287 }
288
289 vec3 col = sampleLiquidFractal(uv, t, strength, center, iResolution);
290
291 color.rgb = applyColorAdjustments(col);
292 color.a = 1.0;
293}
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.
vec3 applyColorAdjustments(vec3 col)
Evaluates applyColorAdjustments 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
float fbm(vec2 point)
Evaluates fbm 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.
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.
float n2(vec2 p)
Evaluates n2 for this shader effect.
vec2 applyZoomRotation(vec2 uv, vec2 center)
Evaluates applyZoomRotation for this shader effect.
vec3 sampleLiquidFractal(vec2 uv, float t, float strength, vec2 center, vec2 res)
Evaluates sampleLiquidFractal for this shader effect.
#define strength
Definition ol.frag:16