BlueGit

timfa kwin-marble

Files

kwin-marble / kwin6_effect_marble_minimize / contents / shaders / marble.frag

marble.frag

marble.frag 40.8 KiB Download Raw
1#define KWIN_LEGACY
2#define PLASMA6
3
4// This file is automatically generated during the build process.
5
6//////////////////////////////////////////////////////////////////////////////////////////
7// ) ( //
8// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
9// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
10// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
11// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
12// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
13// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
14// |__/ //
15//////////////////////////////////////////////////////////////////////////////////////////
16
17// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
18// SPDX-License-Identifier: GPL-3.0-or-later
19
20//////////////////////////////////////////////////////////////////////////////////////////
21// This file is automatically included in each shader. //
22//////////////////////////////////////////////////////////////////////////////////////////
23
24// --------------------------------------------------------------------- standard uniforms
25
26// Each shader can access these standard input values:
27
28// vec2 iTexCoord: Texture coordinates for retrieving the window input color.
29// bool uIsFullscreen: True if the window is maximized or in fullscreen mode.
30// bool uForOpening: True if a window-open animation is ongoing, false otherwise.
31// float uProgress: A value which transitions from 0 to 1 during the animation.
32// float uDuration: The duration of the current animation in seconds.
33// vec2 uSize: The size of uTexture in pixels.
34// float uPadding: The empty area around the actual window (e.g. where the shadow
35// is drawn). For now, this will only be set on GNOME.
36
37// Furthermore, there are two global methods for reading the window input color and
38// setting the shader output color. Both methods assume straight alpha:
39
40// vec4 getInputColor(vec2 coords)
41// void setOutputColor(vec4 outColor)
42
43uniform bool uForOpening;
44uniform bool uIsFullscreen;
45uniform float uProgress;
46uniform float uDuration;
47
48#if defined(KWIN) // --------------------------------------------------------------------
49
50#if defined(PLASMA6)
51#include "colormanagement.glsl"
52#endif
53
54uniform sampler2D sampler;
55uniform int textureWidth;
56uniform int textureHeight;
57
58in vec2 texcoord0;
59out vec4 fragColor;
60
61// Using defines here as OpenGL ES forbids non-constant global initializers.
62#define uSize vec2(textureWidth, textureHeight)
63#define iTexCoord vec2(texcoord0.x, texcoord0.y)
64float uPadding = 0.0;
65
66vec4 getInputColor(vec2 coords) {
67 vec4 color = texture2D(sampler, coords);
68
69 if (color.a > 0.0) {
70 color.rgb /= color.a;
71 }
72
73 return color;
74}
75
76void setOutputColor(vec4 outColor) {
77
78 // If a uniform is not used, it will be optimized away. This condition is always
79 // false, but it will prevent the compiler from optimizing away the uniforms uForOpening
80 // and uIsFullscreen. On KWin, we need to do this as we do not have a way to check if a
81 // uniform is used in the shader.
82 if (outColor.a > 1000.0 && uForOpening && uIsFullscreen) {
83 outColor = vec4(0.0);
84 }
85
86 fragColor = vec4(outColor.rgb * outColor.a, outColor.a);
87
88#if defined(PLASMA6)
89 fragColor = sourceEncodingToNitsInDestinationColorspace(fragColor);
90 fragColor = nitsToDestinationEncoding(fragColor);
91#endif
92}
93
94#elif defined(KWIN_LEGACY) // -----------------------------------------------------------
95
96#if defined(PLASMA6)
97#include "colormanagement.glsl"
98#endif
99
100uniform sampler2D sampler;
101uniform int textureWidth;
102uniform int textureHeight;
103
104varying vec2 texcoord0;
105
106vec2 uSize = vec2(textureWidth, textureHeight);
107vec2 iTexCoord = vec2(texcoord0.x, texcoord0.y);
108float uPadding = 0.0;
109
110vec4 getInputColor(vec2 coords) {
111 vec4 color = texture2D(sampler, coords);
112
113 if (color.a > 0.0) {
114 color.rgb /= color.a;
115 }
116
117 return color;
118}
119
120void setOutputColor(vec4 outColor) {
121 // If a uniform is not used, it will be optimized away. This condition is always
122 // false, but it will prevent the compiler from optimizing away the uniforms uForOpening
123 // and uIsFullscreen. On KWin, we need to do this as we do not have a way to check if a
124 // uniform is used in the shader.
125 if (outColor.a > 1000.0 && uForOpening && uIsFullscreen) {
126 outColor = vec4(0.0);
127 }
128
129 gl_FragColor = vec4(outColor.rgb * outColor.a, outColor.a);
130
131#if defined(PLASMA6)
132 fragColor = sourceEncodingToNitsInDestinationColorspace(fragColor);
133 fragColor = nitsToDestinationEncoding(fragColor);
134#endif
135}
136
137#else // GNOME --------------------------------------------------------------------------
138
139// On GNOME, the uniforms are just normal uniforms.
140uniform sampler2D uTexture;
141uniform vec2 uSize;
142uniform float uPadding;
143
144// On GNOME, we set iTexCoord to be an alias for the cogl variables.
145#define iTexCoord vec2(cogl_tex_coord_in[0])
146
147// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
148vec4 getInputColor(vec2 coords) {
149 vec4 color = texture2D(uTexture, coords);
150
151 if (color.a > 0.0) {
152 color.rgb /= color.a;
153 }
154
155 return color;
156}
157
158void setOutputColor(vec4 outColor) { cogl_color_out = outColor; }
159
160#endif // -------------------------------------------------------------------------------
161
162// A simple blur function
163vec4 getBlurredInputColor(vec2 uv, float radius, float samples) {
164 // Initialize the color accumulator to zero.
165 vec4 color = vec4(0.0);
166
167 // Define a constant for 2 * PI (tau), which represents a full circle in radians.
168 const float tau = 6.28318530718;
169
170 // Number of directions for sampling around the circle.
171 const float directions = 15.0;
172
173 // Outer loop iterates over multiple directions evenly spaced around a circle.
174 for (float d = 0.0; d < tau; d += tau / directions) {
175 // Inner loop samples along each direction, with decreasing intensity.
176 for (float s = 0.0; s < 1.0; s += 1.0 / samples) {
177 // Calculate the offset for this sample based on direction, radius, and step.
178 // The (1.0 - s) term ensures more sampling occurs closer to the center.
179 vec2 offset = vec2(cos(d), sin(d)) * radius * (1.0 - s) / uSize;
180
181 // Add the sampled color at the offset position to the accumulator.
182 color += getInputColor(uv + offset);
183 }
184 }
185
186 // Normalize the accumulated color by dividing by the total number of samples
187 // and directions to ensure the result is averaged.
188 return color / samples / directions;
189}
190
191// ----------------------------------------------------------------- compositing operators
192
193// The Shell.GLSLEffect uses straight alpha blending. This helper method allows
194// compositing color values in the shader in the same way.
195vec4 alphaOver(vec4 under, vec4 over) {
196 if (under.a == 0.0 && over.a == 0.0) {
197 return vec4(0.0);
198 }
199
200 float alpha = mix(under.a, 1.0, over.a);
201 return vec4(mix(under.rgb * under.a, over.rgb, over.a) / alpha, alpha);
202}
203
204// ------------------------------------------------------------------------- color helpers
205
206// Maps the given value from [0..1] to the given colors.
207vec3 tritone(float val, vec3 shadows, vec3 midtones, vec3 highlights) {
208 if (val < 0.5) {
209 return mix(shadows, midtones, smoothstep(0.0, 1.0, val * 2.0));
210 }
211
212 return mix(midtones, highlights, smoothstep(0.0, 1.0, val * 2.0 - 1.0));
213}
214
215// Darkens the given color. If fac is zero, the color will not change, if fac is one, the
216// color will be black.
217vec3 darken(vec3 color, float fac) { return color * (1.0 - fac); }
218
219// Lightens the given color. If fac is zero, the color will not change, if fac is one, the
220// color will be white.
221vec3 lighten(vec3 color, float fac) { return color + (vec3(1.0) - color) * fac; }
222
223// change the color based on an offset amount
224vec3 offsetHue(vec3 color, float hueOffset) {
225 // Convert RGB to HSV
226 float maxC = max(max(color.r, color.g), color.b);
227 float minC = min(min(color.r, color.g), color.b);
228 float delta = maxC - minC;
229
230 float hue = 0.0;
231 if (delta > 0.0) {
232 if (maxC == color.r) {
233 hue = mod((color.g - color.b) / delta, 6.0);
234 } else if (maxC == color.g) {
235 hue = (color.b - color.r) / delta + 2.0;
236 } else {
237 hue = (color.r - color.g) / delta + 4.0;
238 }
239 }
240 hue /= 6.0;
241
242 float saturation = (maxC > 0.0) ? (delta / maxC) : 0.0;
243 float value = maxC;
244
245 // Offset the hue
246 hue = mod(hue + hueOffset, 1.0);
247
248 // Convert HSV back to RGB
249 float c = value * saturation;
250 float x = c * (1.0 - abs(mod(hue * 6.0, 2.0) - 1.0));
251 float m = value - c;
252
253 vec3 rgb;
254 if (hue < 1.0 / 6.0) {
255 rgb = vec3(c, x, 0.0);
256 } else if (hue < 2.0 / 6.0) {
257 rgb = vec3(x, c, 0.0);
258 } else if (hue < 3.0 / 6.0) {
259 rgb = vec3(0.0, c, x);
260 } else if (hue < 4.0 / 6.0) {
261 rgb = vec3(0.0, x, c);
262 } else if (hue < 5.0 / 6.0) {
263 rgb = vec3(x, 0.0, c);
264 } else {
265 rgb = vec3(c, 0.0, x);
266 }
267
268 return rgb + m;
269}
270
271// ---------------------------------------------------------------------- easing functions
272
273// Here are some basic easing function. More can be added if required!
274// Taken from here:
275// https://gitlab.gnome.org/GNOME/mutter/-/blob/main/clutter/clutter/clutter-easing.c
276
277float easeOutQuad(float x) { return -1.0 * x * (x - 2.0); }
278
279float easeInQuad(float x) { return x * x; }
280
281float easeInBack(float x, float e) { return x * x * ((e + 1.0) * x - e); }
282
283float easeOutBack(float x, float e) {
284 float p = x - 1.0;
285 return p * p * ((e + 1.0) * p + e) + 1.0;
286}
287
288// https://easings.net/
289/*
290Easing functions define the rate of change of a parameter over time, commonly used in
291animations, UI transitions, and game development. They provide a way to make movements
292more natural or visually appealing rather than linear and mechanical. Popular categories
293of easing functions include:
294
295Linear: Constant speed from start to finish.
296Quadratic (Ease In, Ease Out, Ease In Out): Changes at varying rates, with smoother starts
297or stops. Cubic: Similar to quadratic but allows for even more nuanced transitions.
298Exponential: Drastic changes at the start or end, often used for dramatic effects.
299Bounce: Mimics a bouncing object with oscillations.
300Elastic: Simulates the behavior of a spring, with overshooting and oscillations.
301Below are text-based "graphs" of some easing functions, where the horizontal axis
302represents time and the vertical axis represents progress.
303*/
304
305// Quadratic Easing
306// Smooth acceleration and deceleration using quadratic (t^2) curves.
307
308float easeInOutQuad(float t) {
309 // Accelerates for the first half, decelerates for the second half.
310 return t < 0.5 ? 2.0 * t * t : -1.0 + (4.0 - 2.0 * t) * t;
311}
312
313// Cubic Easing
314// Smoother transitions compared to quadratic easing using cubic (t^3) curves.
315
316float easeInCubic(float t) {
317 // Starts slow and accelerates as t increases.
318 return t * t * t;
319}
320
321float easeOutCubic(float t) {
322 // Starts fast and decelerates as t approaches 1.0.
323 float f = t - 1.0;
324 return f * f * f + 1.0;
325}
326
327float easeInOutCubic(float t) {
328 // Combines easeIn and easeOut cubic behavior for smooth transitions.
329 return t < 0.5 ? 4.0 * t * t * t : (t - 1.0) * (2.0 * t - 2.0) * (2.0 * t - 2.0) + 1.0;
330}
331
332// Quartic Easing
333// Even smoother transitions than cubic, using quartic (t^4) curves.
334
335float easeInQuart(float t) {
336 // Starts very slow and accelerates steeply.
337 return t * t * t * t;
338}
339
340float easeOutQuart(float t) {
341 // Starts steeply and slows down dramatically.
342 float f = t - 1.0;
343 return 1.0 - f * f * f * f;
344}
345
346float easeInOutQuart(float t) {
347 // Combines easeIn and easeOut quartic behavior for very smooth transitions.
348 return t < 0.5 ? 8.0 * t * t * t * t
349 : 1.0 - 8.0 * (t - 1.0) * (t - 1.0) * (t - 1.0) * (t - 1.0);
350}
351
352// Sine Easing
353// Smooth, wave-like acceleration and deceleration using sine curves.
354
355float easeInSine(float t) {
356 // Starts very slow, following a sine wave curve.
357 return 1.0 - cos((t * 3.141592653589793) / 2.0);
358}
359
360float easeOutSine(float t) {
361 // Starts fast and slows down following a sine wave curve.
362 return sin((t * 3.141592653589793) / 2.0);
363}
364
365float easeInOutSine(float t) {
366 // Smooth start and end, mimicking half a sine wave.
367 return -0.5 * (cos(3.141592653589793 * t) - 1.0);
368}
369
370// Exponential Easing
371// Sharp transitions with rapid acceleration and deceleration.
372
373float easeInExpo(float t) {
374 // Very slow start, accelerates exponentially.
375 return t == 0.0 ? 0.0 : pow(2.0, 10.0 * (t - 1.0));
376}
377
378float easeOutExpo(float t) {
379 // Starts fast and slows down exponentially.
380 return t == 1.0 ? 1.0 : 1.0 - pow(2.0, -10.0 * t);
381}
382
383float easeInOutExpo(float t) {
384 // Combines easeIn and easeOut exponential for sharp transitions.
385 if (t == 0.0) return 0.0;
386 if (t == 1.0) return 1.0;
387 return t < 0.5 ? 0.5 * pow(2.0, 20.0 * t - 10.0)
388 : 1.0 - 0.5 * pow(2.0, -20.0 * t + 10.0);
389}
390
391// Back Easing
392// Creates an overshooting effect for more dynamic animations.
393
394float easeInOutBack(float t) {
395 // Uses constants to define the overshooting magnitude.
396 const float c1 = 1.70158;
397 const float c2 = c1 * 1.525;
398 return t < 0.5
399 ? (pow(2.0 * t, 2.0) * ((c2 + 1.0) * 2.0 * t - c2)) / 2.0
400 : (pow(2.0 * t - 2.0, 2.0) * ((c2 + 1.0) * (t * 2.0 - 2.0) + c2) + 2.0) / 2.0;
401}
402
403// --------------------------------------------------------------------- edge mask helpers
404
405// This method returns a mask which smoothly transitions towards zero when approaching
406// the window's borders. If the window is currently maximized or in fullscreen mode, this
407// will return 1.0 everywhere. There is a variant which takes the transition area width in
408// pixels and one which takes this as a percentage.
409float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) {
410 float mask = 1.0;
411
412 if (!uIsFullscreen) {
413 mask *= smoothstep(0.0, 1.0, clamp(uv.x / fadeWidth, 0.0, 1.0));
414 mask *= smoothstep(0.0, 1.0, clamp(uv.y / fadeWidth, 0.0, 1.0));
415 mask *= smoothstep(0.0, 1.0, clamp((maxUV.x - uv.x) / fadeWidth, 0.0, 1.0));
416 mask *= smoothstep(0.0, 1.0, clamp((maxUV.y - uv.y) / fadeWidth, 0.0, 1.0));
417 }
418
419 return mask;
420}
421
422// Returns an edge mask which fades to zero at the boundaries of the actor. The width of
423// the fade zone is given in pixels. This uses the standard uniforms uSize and uPadding.
424// This means that the fading zone is not actually at the actors boundaries but at the
425// position of the window border in the texture.
426// The offset parameter controls whether the fading is placed inside the window borders
427// (offset = 0), ontop the window borders (offset = 0.5) or outside the window borders
428// (offset = 1).
429float getAbsoluteEdgeMask(float fadePixels, float offset) {
430 float padding = max(0.0, uPadding - fadePixels * offset);
431 vec2 uv = iTexCoord.st * uSize - padding;
432 return getEdgeMask(uv, uSize - 2.0 * padding, fadePixels);
433}
434
435// Returns an edge mask which fades to zero at the boundaries of the actor. The width of
436// the fade zone is given relative to the actor size. This neither uses uSize and
437// uPadding.
438float getRelativeEdgeMask(float fadeAmount) {
439 vec2 uv = iTexCoord.st;
440 return getEdgeMask(uv, vec2(1.0), fadeAmount);
441}
442
443// ------------------------------------------------------------------------------- 2D math
444
445// The math for the whirling is inspired by this post:
446// http://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl
447vec2 whirl(vec2 coords, float warping, float rotation) {
448 float angle = pow(1.0 - length(coords), 2.0) * warping + rotation;
449 float s = sin(angle);
450 float c = cos(angle);
451 return vec2(dot(coords, vec2(c, -s)), dot(coords, vec2(s, c)));
452}
453
454// Returns the shortest distance between the given point and the line defined by "origin"
455// and "direction".
456float distToLine(vec2 origin, vec2 direction, vec2 point) {
457 vec2 perpendicular = vec2(direction.y, -direction.x);
458 return abs(dot(normalize(perpendicular), origin - point));
459}
460
461// Returns a positive number if a -> b forms a clockwise corner, or a negative number if
462// the corner is counter-clockwise.
463float getWinding(vec2 a, vec2 b) { return cross(vec3(a, 0.0), vec3(b, 0.0)).z; }
464
465// Rotates the given 2D vector a clockwise by the angle alpha (given in radians).
466vec2 rotate(vec2 a, float angle) {
467 return vec2(a.x * cos(angle) - a.y * sin(angle), a.x * sin(angle) + a.y * cos(angle));
468}
469
470// rotates a given 2d vector, around a given center (angle is in radians)
471vec2 rotate(vec2 a, float angle, vec2 center) {
472 return vec2(cos(angle) * (a.x - center.x) + sin(angle) * (a.y - center.y) + center.x,
473 cos(angle) * (a.y - center.y) - sin(angle) * (a.x - center.x) + center.y);
474}
475
476// --------------------------------------------------------------------------------- noise
477
478// These noise algorithms are based on implementations by various authors from
479// shadertoy.com, which are all available under the MIT License. See the respective links
480// in the comments below.
481
482// Hash functions
483// MIT License, https://www.shadertoy.com/view/4djSRW
484// Copyright (c) 2014 David Hoskins.
485
486// 1 out, 1 in...
487float hash11(float p) {
488 p = fract(p * .1031);
489 p *= p + 33.33;
490 p *= p + p;
491 return fract(p);
492}
493
494// 1 out, 2 in...
495float hash12(vec2 p) {
496 vec3 p3 = fract(vec3(p.xyx) * .1031);
497 p3 += dot(p3, p3.yzx + 33.33);
498 return fract((p3.x + p3.y) * p3.z);
499}
500
501// 1 out, 3 in...
502float hash13(vec3 p3) {
503 p3 = fract(p3 * .1031);
504 p3 += dot(p3, p3.zyx + 31.32);
505 return fract((p3.x + p3.y) * p3.z);
506}
507
508// 2 out, 1 in...
509vec2 hash21(float p) {
510 vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
511 p3 += dot(p3, p3.yzx + 33.33);
512 return fract((p3.xx + p3.yz) * p3.zy);
513}
514
515// 2 out, 2 in...
516vec2 hash22(vec2 p) {
517 vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
518 p3 += dot(p3, p3.yzx + 33.33);
519 return fract((p3.xx + p3.yz) * p3.zy);
520}
521
522// 2 out, 3 in...
523vec2 hash23(vec3 p3) {
524 p3 = fract(p3 * vec3(.1031, .1030, .0973));
525 p3 += dot(p3, p3.yzx + 33.33);
526 return fract((p3.xx + p3.yz) * p3.zy);
527}
528
529// 3 out, 1 in...
530vec3 hash31(float p) {
531 vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
532 p3 += dot(p3, p3.yzx + 33.33);
533 return fract((p3.xxy + p3.yzz) * p3.zyx);
534}
535
536// 3 out, 2 in...
537vec3 hash32(vec2 p) {
538 vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
539 p3 += dot(p3, p3.yxz + 33.33);
540 return fract((p3.xxy + p3.yzz) * p3.zyx);
541}
542
543// 3 out, 3 in...
544vec3 hash33(vec3 p3) {
545 p3 = fract(p3 * vec3(.1031, .1030, .0973));
546 p3 += dot(p3, p3.yxz + 33.33);
547 return fract((p3.xxy + p3.yxx) * p3.zyx);
548}
549
550// 4 out, 1 in...
551vec4 hash41(float p) {
552 vec4 p4 = fract(vec4(p) * vec4(.1031, .1030, .0973, .1099));
553 p4 += dot(p4, p4.wzxy + 33.33);
554 return fract((p4.xxyz + p4.yzzw) * p4.zywx);
555}
556
557// 4 out, 2 in...
558vec4 hash42(vec2 p) {
559 vec4 p4 = fract(vec4(p.xyxy) * vec4(.1031, .1030, .0973, .1099));
560 p4 += dot(p4, p4.wzxy + 33.33);
561 return fract((p4.xxyz + p4.yzzw) * p4.zywx);
562}
563
564// 4 out, 3 in...
565vec4 hash43(vec3 p) {
566 vec4 p4 = fract(vec4(p.xyzx) * vec4(.1031, .1030, .0973, .1099));
567 p4 += dot(p4, p4.wzxy + 33.33);
568 return fract((p4.xxyz + p4.yzzw) * p4.zywx);
569}
570
571// 4 out, 4 in...
572vec4 hash44(vec4 p4) {
573 p4 = fract(p4 * vec4(.1031, .1030, .0973, .1099));
574 p4 += dot(p4, p4.wzxy + 33.33);
575 return fract((p4.xxyz + p4.yzzw) * p4.zywx);
576}
577
578// 2D Simplex Noise
579// MIT License, https://www.shadertoy.com/view/Msf3WH
580// Copyright © 2013 Inigo Quilez
581float simplex2D(vec2 p) {
582 const float K1 = 0.366025404; // (sqrt(3)-1)/2;
583 const float K2 = 0.211324865; // (3-sqrt(3))/6;
584
585 vec2 i = floor(p + (p.x + p.y) * K1);
586 vec2 a = p - i + (i.x + i.y) * K2;
587 float m = step(a.y, a.x);
588 vec2 o = vec2(m, 1.0 - m);
589 vec2 b = a - o + K2;
590 vec2 c = a - 1.0 + 2.0 * K2;
591 vec3 h = max(0.5 - vec3(dot(a, a), dot(b, b), dot(c, c)), 0.0);
592 vec3 n = h * h * h * h *
593 vec3(dot(a, -1.0 + 2.0 * hash22(i + 0.0)), dot(b, -1.0 + 2.0 * hash22(i + o)),
594 dot(c, -1.0 + 2.0 * hash22(i + 1.0)));
595 return 0.5 + 0.5 * dot(n, vec3(70.0));
596}
597
598float simplex2DFractal(vec2 p) {
599 mat2 m = mat2(1.6, 1.2, -1.2, 1.6);
600 float f = 0.5000 * simplex2D(p);
601 p = m * p;
602 f += 0.2500 * simplex2D(p);
603 p = m * p;
604 f += 0.1250 * simplex2D(p);
605 p = m * p;
606 f += 0.0625 * simplex2D(p);
607 p = m * p;
608
609 return f;
610}
611
612// 3D Simplex Noise
613// MIT License, https://www.shadertoy.com/view/XsX3zB
614// Copyright © 2013 Nikita Miropolskiy
615float simplex3D(vec3 p) {
616
617 // skew constants for 3D simplex functions
618 const float F3 = 0.3333333;
619 const float G3 = 0.1666667;
620
621 // 1. find current tetrahedron T and it's four vertices
622 // s, s+i1, s+i2, s+1.0 - absolute skewed (integer) coordinates of T vertices
623 // x, x1, x2, x3 - unskewed coordinates of p relative to each of T vertice
624
625 // calculate s and x
626 vec3 s = floor(p + dot(p, vec3(F3)));
627 vec3 x = p - s + dot(s, vec3(G3));
628
629 // calculate i1 and i2
630 vec3 e = step(vec3(0.0), x - x.yzx);
631 vec3 i1 = e * (1.0 - e.zxy);
632 vec3 i2 = 1.0 - e.zxy * (1.0 - e);
633
634 // x1, x2, x3
635 vec3 x1 = x - i1 + G3;
636 vec3 x2 = x - i2 + 2.0 * G3;
637 vec3 x3 = x - 1.0 + 3.0 * G3;
638
639 // 2. find four surflets and store them in d
640 vec4 w, d;
641
642 // calculate surflet weights
643 w.x = dot(x, x);
644 w.y = dot(x1, x1);
645 w.z = dot(x2, x2);
646 w.w = dot(x3, x3);
647
648 // w fades from 0.6 at the center of the surflet to 0.0 at the margin
649 w = max(0.6 - w, 0.0);
650
651 // calculate surflet components
652 d.x = dot(-0.5 + hash33(s), x);
653 d.y = dot(-0.5 + hash33(s + i1), x1);
654 d.z = dot(-0.5 + hash33(s + i2), x2);
655 d.w = dot(-0.5 + hash33(s + 1.0), x3);
656
657 // multiply d by w^4
658 w *= w;
659 w *= w;
660 d *= w;
661
662 // 3. return the sum of the four surflets
663 return dot(d, vec4(52.0)) * 0.5 + 0.5;
664}
665
666// Directional artifacts can be reduced by rotating each octave
667float simplex3DFractal(vec3 m) {
668
669 // const matrices for 3D rotation
670 const mat3 rot1 = mat3(-0.37, 0.36, 0.85, -0.14, -0.93, 0.34, 0.92, 0.01, 0.4);
671 const mat3 rot2 = mat3(-0.55, -0.39, 0.74, 0.33, -0.91, -0.24, 0.77, 0.12, 0.63);
672 const mat3 rot3 = mat3(-0.71, 0.52, -0.47, -0.08, -0.72, -0.68, -0.7, -0.45, 0.56);
673
674 return 0.5333333 * simplex3D(m * rot1) + 0.2666667 * simplex3D(2.0 * m * rot2) +
675 0.1333333 * simplex3D(4.0 * m * rot3) + 0.0666667 * simplex3D(8.0 * m);
676}
677
678// --------------------------------------------------------------------------------- remap
679
680/*
681These functions remap a given value from one range to another.
682The remap operation is particularly useful in shader programming
683to scale or normalize data, ensuring compatibility across various
684input ranges. Each version of the remap function supports a
685different data type:
686
6871. float: Remap a single scalar value.
6882. vec2: Remap a 2D vector.
6893. vec3: Remap a 3D vector.
6904. vec4: Remap a 4D vector.
691
692The general formula used is:
693 newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin)
694
695This ensures a linear transformation from the old range to the new range.
696*/
697
698// Remap for float
699// Maps a float value from one range [oldMin, oldMax] to another range [newMin, newMax].
700// This is useful for normalizing or scaling scalar values to fit within a desired range.
701float remap(float value, float oldMin, float oldMax, float newMin, float newMax) {
702 return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
703 newMax);
704}
705
706// Remap for vec2
707// Maps a 2D vector (vec2) from one range [oldMin, oldMax] to another range [newMin,
708// newMax]. Each component of the vec2 is individually scaled and transformed.
709vec2 remap(vec2 value, vec2 oldMin, vec2 oldMax, vec2 newMin, vec2 newMax) {
710 return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
711 newMax);
712}
713
714// Remap for vec3
715// Maps a 3D vector (vec3) from one range [oldMin, oldMax] to another range [newMin,
716// newMax]. Each component of the vec3 is individually scaled and transformed.
717vec3 remap(vec3 value, vec3 oldMin, vec3 oldMax, vec3 newMin, vec3 newMax) {
718 return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
719 newMax);
720}
721
722// Remap for vec4
723// Maps a 4D vector (vec4) from one range [oldMin, oldMax] to another range [newMin,
724// newMax]. Each component of the vec4 is individually scaled and transformed.
725vec4 remap(vec4 value, vec4 oldMin, vec4 oldMax, vec4 newMin, vec4 newMax) {
726 return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
727 newMax);
728}
729//////////////////////////////////////////////////////////////////////////////////////////
730// ) ( //
731// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
732// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
733// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
734// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
735// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
736// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
737// |__/ //
738//////////////////////////////////////////////////////////////////////////////////////////
739
740// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
741// SPDX-License-Identifier: GPL-3.0-or-later
742
743// The content from common.glsl is automatically prepended to each shader effect.
744
745// Marble [Burn-My-Windows variant] v8: window morphs into a glossy 2D marble (black-glass look).
746// The fall happens in main.js (Translation, constant gravity) after the marble is done.
747uniform float uCrumpleEnd;
748uniform float uMixOuter; // 0..1 black mix, outer/bottom zone
749uniform float uTintR; uniform float uTintG; uniform float uTintB; // mix target colour
750uniform float uMarbleSize; // marble diameter in px
751uniform float uDebug; // 2 = show the raw window texture inside the marble
752uniform float uMixCenter; // 0..1 black mix, centre/top zone
753
754void main() {
755 // Per-window state in one float (setUniform is global; animate() values are per-window):
756 // uProgress = tintId + morph01*0.999, tintId 0..10 named or 1000..1359 hue.
757 // morph01 runs 0→1 over the full ShaderUniform animation; uCrumpleEnd scales so c hits 1
758 // at the morph boundary (same timing as the old overshoot encoding, without a huge offset).
759 float tk = floor(uProgress);
760 float raw = uProgress - tk; // 0..0.999
761 float c = clamp(raw / max(uCrumpleEnd * 0.999, 1e-6), 0.0, 1.0);
762 if (uCrumpleEnd < -1.0) c = 0.0; // keep alive + guard
763 // Precomputed RGB for hue 0..359 at S=1 V=0.6667 (same formula as old per-fragment HSV).
764 // Indexed by tk-1000; avoids HSV ALU every fragment while keeping per-window tint in uProgress.
765 const vec3 HUE_RGB[360] = vec3[](
766 vec3(0.6667, 0.0, 0.0), vec3(0.6667, 0.011112, 0.0), vec3(0.6667, 0.022223, 0.0), vec3(0.6667, 0.033335, 0.0),
767 vec3(0.6667, 0.044447, 0.0), vec3(0.6667, 0.055558, 0.0), vec3(0.6667, 0.06667, 0.0), vec3(0.6667, 0.077782, 0.0),
768 vec3(0.6667, 0.088893, 0.0), vec3(0.6667, 0.100005, 0.0), vec3(0.6667, 0.111117, 0.0), vec3(0.6667, 0.122228, 0.0),
769 vec3(0.6667, 0.13334, 0.0), vec3(0.6667, 0.144452, 0.0), vec3(0.6667, 0.155563, 0.0), vec3(0.6667, 0.166675, 0.0),
770 vec3(0.6667, 0.177787, 0.0), vec3(0.6667, 0.188898, 0.0), vec3(0.6667, 0.20001, 0.0), vec3(0.6667, 0.211122, 0.0),
771 vec3(0.6667, 0.222233, 0.0), vec3(0.6667, 0.233345, 0.0), vec3(0.6667, 0.244457, 0.0), vec3(0.6667, 0.255568, 0.0),
772 vec3(0.6667, 0.26668, 0.0), vec3(0.6667, 0.277792, 0.0), vec3(0.6667, 0.288903, 0.0), vec3(0.6667, 0.300015, 0.0),
773 vec3(0.6667, 0.311127, 0.0), vec3(0.6667, 0.322238, 0.0), vec3(0.6667, 0.33335, 0.0), vec3(0.6667, 0.344462, 0.0),
774 vec3(0.6667, 0.355573, 0.0), vec3(0.6667, 0.366685, 0.0), vec3(0.6667, 0.377797, 0.0), vec3(0.6667, 0.388908, 0.0),
775 vec3(0.6667, 0.40002, 0.0), vec3(0.6667, 0.411132, 0.0), vec3(0.6667, 0.422243, 0.0), vec3(0.6667, 0.433355, 0.0),
776 vec3(0.6667, 0.444467, 0.0), vec3(0.6667, 0.455578, 0.0), vec3(0.6667, 0.46669, 0.0), vec3(0.6667, 0.477802, 0.0),
777 vec3(0.6667, 0.488913, 0.0), vec3(0.6667, 0.500025, 0.0), vec3(0.6667, 0.511137, 0.0), vec3(0.6667, 0.522248, 0.0),
778 vec3(0.6667, 0.53336, 0.0), vec3(0.6667, 0.544472, 0.0), vec3(0.6667, 0.555583, 0.0), vec3(0.6667, 0.566695, 0.0),
779 vec3(0.6667, 0.577807, 0.0), vec3(0.6667, 0.588918, 0.0), vec3(0.6667, 0.60003, 0.0), vec3(0.6667, 0.611142, 0.0),
780 vec3(0.6667, 0.622253, 0.0), vec3(0.6667, 0.633365, 0.0), vec3(0.6667, 0.644477, 0.0), vec3(0.6667, 0.655588, 0.0),
781 vec3(0.6667, 0.6667, 0.0), vec3(0.655588, 0.6667, 0.0), vec3(0.644477, 0.6667, 0.0), vec3(0.633365, 0.6667, 0.0),
782 vec3(0.622253, 0.6667, 0.0), vec3(0.611142, 0.6667, 0.0), vec3(0.60003, 0.6667, 0.0), vec3(0.588918, 0.6667, 0.0),
783 vec3(0.577807, 0.6667, 0.0), vec3(0.566695, 0.6667, 0.0), vec3(0.555583, 0.6667, 0.0), vec3(0.544472, 0.6667, 0.0),
784 vec3(0.53336, 0.6667, 0.0), vec3(0.522248, 0.6667, 0.0), vec3(0.511137, 0.6667, 0.0), vec3(0.500025, 0.6667, 0.0),
785 vec3(0.488913, 0.6667, 0.0), vec3(0.477802, 0.6667, 0.0), vec3(0.46669, 0.6667, 0.0), vec3(0.455578, 0.6667, 0.0),
786 vec3(0.444467, 0.6667, 0.0), vec3(0.433355, 0.6667, 0.0), vec3(0.422243, 0.6667, 0.0), vec3(0.411132, 0.6667, 0.0),
787 vec3(0.40002, 0.6667, 0.0), vec3(0.388908, 0.6667, 0.0), vec3(0.377797, 0.6667, 0.0), vec3(0.366685, 0.6667, 0.0),
788 vec3(0.355573, 0.6667, 0.0), vec3(0.344462, 0.6667, 0.0), vec3(0.33335, 0.6667, 0.0), vec3(0.322238, 0.6667, 0.0),
789 vec3(0.311127, 0.6667, 0.0), vec3(0.300015, 0.6667, 0.0), vec3(0.288903, 0.6667, 0.0), vec3(0.277792, 0.6667, 0.0),
790 vec3(0.26668, 0.6667, 0.0), vec3(0.255568, 0.6667, 0.0), vec3(0.244457, 0.6667, 0.0), vec3(0.233345, 0.6667, 0.0),
791 vec3(0.222233, 0.6667, 0.0), vec3(0.211122, 0.6667, 0.0), vec3(0.20001, 0.6667, 0.0), vec3(0.188898, 0.6667, 0.0),
792 vec3(0.177787, 0.6667, 0.0), vec3(0.166675, 0.6667, 0.0), vec3(0.155563, 0.6667, 0.0), vec3(0.144452, 0.6667, 0.0),
793 vec3(0.13334, 0.6667, 0.0), vec3(0.122228, 0.6667, 0.0), vec3(0.111117, 0.6667, 0.0), vec3(0.100005, 0.6667, 0.0),
794 vec3(0.088893, 0.6667, 0.0), vec3(0.077782, 0.6667, 0.0), vec3(0.06667, 0.6667, 0.0), vec3(0.055558, 0.6667, 0.0),
795 vec3(0.044447, 0.6667, 0.0), vec3(0.033335, 0.6667, 0.0), vec3(0.022223, 0.6667, 0.0), vec3(0.011112, 0.6667, 0.0),
796 vec3(0.0, 0.6667, 0.0), vec3(0.0, 0.6667, 0.011112), vec3(0.0, 0.6667, 0.022223), vec3(0.0, 0.6667, 0.033335),
797 vec3(0.0, 0.6667, 0.044447), vec3(0.0, 0.6667, 0.055558), vec3(0.0, 0.6667, 0.06667), vec3(0.0, 0.6667, 0.077782),
798 vec3(0.0, 0.6667, 0.088893), vec3(0.0, 0.6667, 0.100005), vec3(0.0, 0.6667, 0.111117), vec3(0.0, 0.6667, 0.122228),
799 vec3(0.0, 0.6667, 0.13334), vec3(0.0, 0.6667, 0.144452), vec3(0.0, 0.6667, 0.155563), vec3(0.0, 0.6667, 0.166675),
800 vec3(0.0, 0.6667, 0.177787), vec3(0.0, 0.6667, 0.188898), vec3(0.0, 0.6667, 0.20001), vec3(0.0, 0.6667, 0.211122),
801 vec3(0.0, 0.6667, 0.222233), vec3(0.0, 0.6667, 0.233345), vec3(0.0, 0.6667, 0.244457), vec3(0.0, 0.6667, 0.255568),
802 vec3(0.0, 0.6667, 0.26668), vec3(0.0, 0.6667, 0.277792), vec3(0.0, 0.6667, 0.288903), vec3(0.0, 0.6667, 0.300015),
803 vec3(0.0, 0.6667, 0.311127), vec3(0.0, 0.6667, 0.322238), vec3(0.0, 0.6667, 0.33335), vec3(0.0, 0.6667, 0.344462),
804 vec3(0.0, 0.6667, 0.355573), vec3(0.0, 0.6667, 0.366685), vec3(0.0, 0.6667, 0.377797), vec3(0.0, 0.6667, 0.388908),
805 vec3(0.0, 0.6667, 0.40002), vec3(0.0, 0.6667, 0.411132), vec3(0.0, 0.6667, 0.422243), vec3(0.0, 0.6667, 0.433355),
806 vec3(0.0, 0.6667, 0.444467), vec3(0.0, 0.6667, 0.455578), vec3(0.0, 0.6667, 0.46669), vec3(0.0, 0.6667, 0.477802),
807 vec3(0.0, 0.6667, 0.488913), vec3(0.0, 0.6667, 0.500025), vec3(0.0, 0.6667, 0.511137), vec3(0.0, 0.6667, 0.522248),
808 vec3(0.0, 0.6667, 0.53336), vec3(0.0, 0.6667, 0.544472), vec3(0.0, 0.6667, 0.555583), vec3(0.0, 0.6667, 0.566695),
809 vec3(0.0, 0.6667, 0.577807), vec3(0.0, 0.6667, 0.588918), vec3(0.0, 0.6667, 0.60003), vec3(0.0, 0.6667, 0.611142),
810 vec3(0.0, 0.6667, 0.622253), vec3(0.0, 0.6667, 0.633365), vec3(0.0, 0.6667, 0.644477), vec3(0.0, 0.6667, 0.655588),
811 vec3(0.0, 0.6667, 0.6667), vec3(0.0, 0.655588, 0.6667), vec3(0.0, 0.644477, 0.6667), vec3(0.0, 0.633365, 0.6667),
812 vec3(0.0, 0.622253, 0.6667), vec3(0.0, 0.611142, 0.6667), vec3(0.0, 0.60003, 0.6667), vec3(0.0, 0.588918, 0.6667),
813 vec3(0.0, 0.577807, 0.6667), vec3(0.0, 0.566695, 0.6667), vec3(0.0, 0.555583, 0.6667), vec3(0.0, 0.544472, 0.6667),
814 vec3(0.0, 0.53336, 0.6667), vec3(0.0, 0.522248, 0.6667), vec3(0.0, 0.511137, 0.6667), vec3(0.0, 0.500025, 0.6667),
815 vec3(0.0, 0.488913, 0.6667), vec3(0.0, 0.477802, 0.6667), vec3(0.0, 0.46669, 0.6667), vec3(0.0, 0.455578, 0.6667),
816 vec3(0.0, 0.444467, 0.6667), vec3(0.0, 0.433355, 0.6667), vec3(0.0, 0.422243, 0.6667), vec3(0.0, 0.411132, 0.6667),
817 vec3(0.0, 0.40002, 0.6667), vec3(0.0, 0.388908, 0.6667), vec3(0.0, 0.377797, 0.6667), vec3(0.0, 0.366685, 0.6667),
818 vec3(0.0, 0.355573, 0.6667), vec3(0.0, 0.344462, 0.6667), vec3(0.0, 0.33335, 0.6667), vec3(0.0, 0.322238, 0.6667),
819 vec3(0.0, 0.311127, 0.6667), vec3(0.0, 0.300015, 0.6667), vec3(0.0, 0.288903, 0.6667), vec3(0.0, 0.277792, 0.6667),
820 vec3(0.0, 0.26668, 0.6667), vec3(0.0, 0.255568, 0.6667), vec3(0.0, 0.244457, 0.6667), vec3(0.0, 0.233345, 0.6667),
821 vec3(0.0, 0.222233, 0.6667), vec3(0.0, 0.211122, 0.6667), vec3(0.0, 0.20001, 0.6667), vec3(0.0, 0.188898, 0.6667),
822 vec3(0.0, 0.177787, 0.6667), vec3(0.0, 0.166675, 0.6667), vec3(0.0, 0.155563, 0.6667), vec3(0.0, 0.144452, 0.6667),
823 vec3(0.0, 0.13334, 0.6667), vec3(0.0, 0.122228, 0.6667), vec3(0.0, 0.111117, 0.6667), vec3(0.0, 0.100005, 0.6667),
824 vec3(0.0, 0.088893, 0.6667), vec3(0.0, 0.077782, 0.6667), vec3(0.0, 0.06667, 0.6667), vec3(0.0, 0.055558, 0.6667),
825 vec3(0.0, 0.044447, 0.6667), vec3(0.0, 0.033335, 0.6667), vec3(0.0, 0.022223, 0.6667), vec3(0.0, 0.011112, 0.6667),
826 vec3(0.0, 0.0, 0.6667), vec3(0.011112, 0.0, 0.6667), vec3(0.022223, 0.0, 0.6667), vec3(0.033335, 0.0, 0.6667),
827 vec3(0.044447, 0.0, 0.6667), vec3(0.055558, 0.0, 0.6667), vec3(0.06667, 0.0, 0.6667), vec3(0.077782, 0.0, 0.6667),
828 vec3(0.088893, 0.0, 0.6667), vec3(0.100005, 0.0, 0.6667), vec3(0.111117, 0.0, 0.6667), vec3(0.122228, 0.0, 0.6667),
829 vec3(0.13334, 0.0, 0.6667), vec3(0.144452, 0.0, 0.6667), vec3(0.155563, 0.0, 0.6667), vec3(0.166675, 0.0, 0.6667),
830 vec3(0.177787, 0.0, 0.6667), vec3(0.188898, 0.0, 0.6667), vec3(0.20001, 0.0, 0.6667), vec3(0.211122, 0.0, 0.6667),
831 vec3(0.222233, 0.0, 0.6667), vec3(0.233345, 0.0, 0.6667), vec3(0.244457, 0.0, 0.6667), vec3(0.255568, 0.0, 0.6667),
832 vec3(0.26668, 0.0, 0.6667), vec3(0.277792, 0.0, 0.6667), vec3(0.288903, 0.0, 0.6667), vec3(0.300015, 0.0, 0.6667),
833 vec3(0.311127, 0.0, 0.6667), vec3(0.322238, 0.0, 0.6667), vec3(0.33335, 0.0, 0.6667), vec3(0.344462, 0.0, 0.6667),
834 vec3(0.355573, 0.0, 0.6667), vec3(0.366685, 0.0, 0.6667), vec3(0.377797, 0.0, 0.6667), vec3(0.388908, 0.0, 0.6667),
835 vec3(0.40002, 0.0, 0.6667), vec3(0.411132, 0.0, 0.6667), vec3(0.422243, 0.0, 0.6667), vec3(0.433355, 0.0, 0.6667),
836 vec3(0.444467, 0.0, 0.6667), vec3(0.455578, 0.0, 0.6667), vec3(0.46669, 0.0, 0.6667), vec3(0.477802, 0.0, 0.6667),
837 vec3(0.488913, 0.0, 0.6667), vec3(0.500025, 0.0, 0.6667), vec3(0.511137, 0.0, 0.6667), vec3(0.522248, 0.0, 0.6667),
838 vec3(0.53336, 0.0, 0.6667), vec3(0.544472, 0.0, 0.6667), vec3(0.555583, 0.0, 0.6667), vec3(0.566695, 0.0, 0.6667),
839 vec3(0.577807, 0.0, 0.6667), vec3(0.588918, 0.0, 0.6667), vec3(0.60003, 0.0, 0.6667), vec3(0.611142, 0.0, 0.6667),
840 vec3(0.622253, 0.0, 0.6667), vec3(0.633365, 0.0, 0.6667), vec3(0.644477, 0.0, 0.6667), vec3(0.655588, 0.0, 0.6667),
841 vec3(0.6667, 0.0, 0.6667), vec3(0.6667, 0.0, 0.655588), vec3(0.6667, 0.0, 0.644477), vec3(0.6667, 0.0, 0.633365),
842 vec3(0.6667, 0.0, 0.622253), vec3(0.6667, 0.0, 0.611142), vec3(0.6667, 0.0, 0.60003), vec3(0.6667, 0.0, 0.588918),
843 vec3(0.6667, 0.0, 0.577807), vec3(0.6667, 0.0, 0.566695), vec3(0.6667, 0.0, 0.555583), vec3(0.6667, 0.0, 0.544472),
844 vec3(0.6667, 0.0, 0.53336), vec3(0.6667, 0.0, 0.522248), vec3(0.6667, 0.0, 0.511137), vec3(0.6667, 0.0, 0.500025),
845 vec3(0.6667, 0.0, 0.488913), vec3(0.6667, 0.0, 0.477802), vec3(0.6667, 0.0, 0.46669), vec3(0.6667, 0.0, 0.455578),
846 vec3(0.6667, 0.0, 0.444467), vec3(0.6667, 0.0, 0.433355), vec3(0.6667, 0.0, 0.422243), vec3(0.6667, 0.0, 0.411132),
847 vec3(0.6667, 0.0, 0.40002), vec3(0.6667, 0.0, 0.388908), vec3(0.6667, 0.0, 0.377797), vec3(0.6667, 0.0, 0.366685),
848 vec3(0.6667, 0.0, 0.355573), vec3(0.6667, 0.0, 0.344462), vec3(0.6667, 0.0, 0.33335), vec3(0.6667, 0.0, 0.322238),
849 vec3(0.6667, 0.0, 0.311127), vec3(0.6667, 0.0, 0.300015), vec3(0.6667, 0.0, 0.288903), vec3(0.6667, 0.0, 0.277792),
850 vec3(0.6667, 0.0, 0.26668), vec3(0.6667, 0.0, 0.255568), vec3(0.6667, 0.0, 0.244457), vec3(0.6667, 0.0, 0.233345),
851 vec3(0.6667, 0.0, 0.222233), vec3(0.6667, 0.0, 0.211122), vec3(0.6667, 0.0, 0.20001), vec3(0.6667, 0.0, 0.188898),
852 vec3(0.6667, 0.0, 0.177787), vec3(0.6667, 0.0, 0.166675), vec3(0.6667, 0.0, 0.155563), vec3(0.6667, 0.0, 0.144452),
853 vec3(0.6667, 0.0, 0.13334), vec3(0.6667, 0.0, 0.122228), vec3(0.6667, 0.0, 0.111117), vec3(0.6667, 0.0, 0.100005),
854 vec3(0.6667, 0.0, 0.088893), vec3(0.6667, 0.0, 0.077782), vec3(0.6667, 0.0, 0.06667), vec3(0.6667, 0.0, 0.055558),
855 vec3(0.6667, 0.0, 0.044447), vec3(0.6667, 0.0, 0.033335), vec3(0.6667, 0.0, 0.022223), vec3(0.6667, 0.0, 0.011112)
856 );
857 vec3 tint;
858 if (tk >= 999.5) {
859 int hi = int(clamp(tk - 1000.0, 0.0, 359.0));
860 tint = HUE_RGB[hi];
861 } else {
862 tint = tk < 0.5 ? vec3(0.0) : tk < 1.5 ? vec3(0.0, 0.0, 0.6667) : tk < 2.5 ? vec3(0.6667, 0.0, 0.0)
863 : tk < 3.5 ? vec3(0.0, 0.6667, 0.0) : tk < 4.5 ? vec3(0.4, 0.0, 0.6667) : tk < 5.5 ? vec3(0.6667, 0.6667, 0.0)
864 : tk < 6.5 ? vec3(0.6667, 0.3333, 0.0) : tk < 7.5 ? vec3(0.0, 0.6667, 0.6667) : tk < 8.5 ? vec3(0.6667, 0.0, 0.4)
865 : tk < 9.5 ? vec3(0.3333) : vec3(0.3333, 0.2, 0.0);
866 }
867 if (uTintR < -1.0 || uTintG < -1.0 || uTintB < -1.0) tint = vec3(0.0); // keep uniforms alive
868 if (uDuration < -1.0) c = 0.0; // keep uDuration alive
869 float e = c * c * c * (c * (c * 6.0 - 15.0) + 10.0); // smootherstep
870
871 vec2 hs = 0.5 * uSize;
872 vec2 p = iTexCoord * uSize - hs;
873 float R0 = min(0.5 * uMarbleSize, 0.45 * min(uSize.x, uSize.y)); // fixed px diameter, capped for tiny windows
874 vec2 b = mix(hs, vec2(R0), e); // half size of the morphing shape
875 float rad = mix(0.0, R0, e * e); // corner radius grows to a full circle
876 vec2 dq = max(abs(p) - (b - rad), 0.0);
877 float d = length(dq) - rad + min(max(abs(p).x - (b - rad).x, abs(p).y - (b - rad).y), 0.0);
878
879 // soft drop shadow (bottom-right), drawn where the marble is not
880 vec2 ps = p - vec2(0.12, 0.22) * R0 * e;
881 float sh = 0.35 * e * (1.0 - smoothstep(-0.2 * R0, 0.25 * R0, length(ps) - R0 * 0.9 * e + (1.0 - e) * 1e5));
882 if (d > 0.0) { setOutputColor(vec4(0.0, 0.0, 0.0, sh * step(0.5, e))); return; }
883
884 vec2 q = p / b; // -1..1 inside
885 float r2 = min(dot(q, q), 1.0);
886 float z = sqrt(1.0 - r2 * e); // sphere height (flat at e=0)
887 vec2 uv = 0.5 + 0.5 * q * mix(1.0, 0.75 + 0.45 * (1.0 - z), e);
888 vec4 col = getInputColor(clamp(uv, 0.0, 1.0));
889 col.a = step(0.97, col.a); // ignore the window shadow
890 col.a = mix(col.a, 1.0, e); // marble is solid
891 col.rgb = clamp(col.rgb, 0.0, 1.0);
892 // KWin gives an empty snapshot when this effect was already busy with another window:
893 // then draw a plain glass marble (no window image) instead of a black/invisible one
894 if (getInputColor(vec2(0.5)).a < 0.004) col = vec4(vec3(0.16), e);
895
896 if (uDebug > 1.5) { setOutputColor(vec4(col.rgb, col.a * clamp(-d, 0.0, 1.0))); return; }
897 // glossy marble shading
898 vec3 n = vec3(q * e, z);
899 float diff = clamp(dot(n, vec3(-0.45, -0.55, 0.70)), 0.0, 1.0);
900 // "window seen through black glass": centre/top (blue zone) barely mixed with black,
901 // outer/bottom (red zone) strongly; soft elliptic gradient around a point above centre
902 vec2 bz = (q - vec2(0.05, -0.22)) * vec2(1.0, 1.45);
903 float outer = smoothstep(0.2, 0.85, length(bz));
904 col.rgb = mix(col.rgb, tint, e * mix(uMixCenter, uMixOuter, outer));
905 // bent rounded-square shine top-left (superellipse in a rotated, curved frame), sharp edge
906 vec2 sv = q - vec2(-0.40, -0.47);
907 vec2 sr = vec2(0.766 * sv.x - 0.643 * sv.y, 0.643 * sv.x + 0.766 * sv.y); // rotate -40deg
908 sr.y -= 1.6 * sr.x * sr.x; // bend towards the centre
909 vec2 s4 = sr / vec2(0.19, 0.115); s4 *= s4; s4 *= s4;
910 float spot = 1.0 - smoothstep(0.75, 1.0, s4.x + s4.y);
911 vec2 hv = q - vec2(-0.38, -0.42);
912 float glow = 0.1 * (1.0 - smoothstep(0.0, 0.3, dot(hv, hv)));
913 float fres = 1.0 - z; fres *= fres; // rim light
914 float bottom = 1.0 - 0.55 * clamp(q.y * 0.9 + 0.2, 0.0, 1.0) * (1.0 - z * 0.5);
915 float lit = mix(1.0, (0.45 + 0.65 * diff) * bottom, e);
916 col.rgb = col.rgb * lit + e * (vec3(glow) + fres * vec3(0.18, 0.2, 0.24));
917 col.rgb = mix(col.rgb, vec3(1.0), e * spot); // opaque, strong shine
918 col.rgb = min(col.rgb, vec3(1.0));
919 col.a *= clamp(-d, 0.0, 1.0); // 1px anti-aliased edge
920 setOutputColor(col);
921}