wrap around blobs

This commit is contained in:
flickowoa
2025-02-18 11:12:50 +05:30
parent bad7c9a83e
commit 9ac7c79166
5 changed files with 155 additions and 75 deletions

View File

@@ -7,12 +7,14 @@ layout(location = 0) out vec4 fragColor;
layout(binding = 1) uniform sampler2D source;
layout(std140, binding = 0) uniform buf {
mat4 qt_Matrix;
float qt_Opacity;
uniform int gheight;
uniform int gwidth;
uniform float treshold;
uniform float strength;
uniform float pointA_x;
uniform float pointA_y;
@@ -26,16 +28,55 @@ layout(std140, binding = 0) uniform buf {
uniform float radiusC;
} ubuf;
float wrappedDistance(float x1, float y1, float x2, float y2, float width, float height) {
float dx = abs(x1 - x2);
float dy = abs(y1 - y2);
if(dx > width / 2) {
dx = width - dx;
}
if(dy > height / 2) {
dy = height - dy;
}
return sqrt(dx * dx + dy * dy);
}
float squareDistance(float x1, float y1, float x2, float y2) {
float dx = x1 - x2;
float dy = y1 - y2;
return dx * dx + dy * dy;
}
void main() {
float x = qt_TexCoord0.x * ubuf.gwidth;
float y = qt_TexCoord0.y * ubuf.gheight;
float influenceBg = 0.0;
float influenceFg = 0.0;
float A = (x - ubuf.pointA_x) * (x - ubuf.pointA_x) + (y - ubuf.pointA_y) * (y - ubuf.pointA_y);
float B = (x - ubuf.pointB_x) * (x - ubuf.pointB_x) + (y - ubuf.pointB_y) * (y - ubuf.pointB_y);
float C = (x - ubuf.pointC_x) * (x - ubuf.pointC_x) + (y - ubuf.pointC_y) * (y - ubuf.pointC_y);
// influence wraps around edges
float A = squareDistance(x, y, ubuf.pointA_x, ubuf.pointA_y);
float B = squareDistance(x, y, ubuf.pointB_x, ubuf.pointB_y);
float C = squareDistance(x, y, ubuf.pointC_x, ubuf.pointC_y);
A *= squareDistance(x, y, ubuf.pointA_x + ubuf.gwidth, ubuf.pointA_y);
B *= squareDistance(x, y, ubuf.pointB_x + ubuf.gwidth, ubuf.pointB_y);
C *= squareDistance(x, y, ubuf.pointC_x + ubuf.gwidth, ubuf.pointC_y);
A *= squareDistance(x, y, ubuf.pointA_x - ubuf.gwidth, ubuf.pointA_y);
B *= squareDistance(x, y, ubuf.pointB_x - ubuf.gwidth, ubuf.pointB_y);
C *= squareDistance(x, y, ubuf.pointC_x - ubuf.gwidth, ubuf.pointC_y);
// A *= squareDistance(x, y, ubuf.pointA_x, ubuf.pointA_y + ubuf.gheight);
// B *= squareDistance(x, y, ubuf.pointB_x, ubuf.pointB_y + ubuf.gheight);
// C *= squareDistance(x, y, ubuf.pointC_x, ubuf.pointC_y + ubuf.gheight);
// A *= squareDistance(x, y, ubuf.pointA_x, ubuf.pointA_y - ubuf.gheight);
// B *= squareDistance(x, y, ubuf.pointB_x, ubuf.pointB_y - ubuf.gheight);
// C *= squareDistance(x, y, ubuf.pointC_x, ubuf.pointC_y - ubuf.gheight);
// float influenceA = ubuf.radiusA * ubuf.radiusA / A;
// float influenceB = ubuf.radiusB * ubuf.radiusB / B;
// float influenceC = ubuf.radiusC * ubuf.radiusC / C;
float influenceA = ubuf.radiusA * ubuf.radiusA / A;
float influenceB = ubuf.radiusB * ubuf.radiusB / B;
@@ -44,21 +85,30 @@ void main() {
vec4 colorA = vec4(0.95, 0.59, 1.0, 1.0);
vec4 colorB = vec4(0.95, 0.42, 1.0, 1.0);
vec4 colorC = vec4(1.0, 0.58, 0.78, 1.0);
vec4 colorD = vec4(1.0, 0.47, 0.47, 1.0);
vec4 colorE = vec4(0.49, 0.42, 1.0, 1.0);
vec4 colorF = vec4(1.0, 0.94, 0.46, 1.0);
influenceBg = influenceA + influenceB + influenceC;
fragColor = texture(source, qt_TexCoord0) * ubuf.qt_Opacity;
if(influenceA > ubuf.treshold) {
fragColor = mix(fragColor, colorA, influenceA * (ubuf.radiusA / 2) / influenceBg) * ubuf.qt_Opacity;
fragColor = mix(fragColor, colorA, influenceA * (ubuf.radiusA / ubuf.strength) / influenceBg) * ubuf.qt_Opacity;
}
if(influenceB > ubuf.treshold) {
fragColor = mix(fragColor, colorB, influenceB * (ubuf.radiusB / 2) / influenceBg) * ubuf.qt_Opacity;
fragColor = mix(fragColor, colorB, influenceB * (ubuf.radiusB / ubuf.strength) / influenceBg) * ubuf.qt_Opacity;
}
if(influenceC > ubuf.treshold) {
fragColor = mix(fragColor, colorC, influenceC * (ubuf.radiusC / 2) / influenceBg) * ubuf.qt_Opacity;
fragColor = mix(fragColor, colorC, influenceC * (ubuf.radiusC / ubuf.strength) / influenceBg) * ubuf.qt_Opacity;
}
// if(distance(vec2(x, y), vec2(ubuf.pointA_x, ubuf.pointA_y)) < 3) {
// fragColor = vec4(1, 0, 0, 1) * ubuf.qt_Opacity;
// }
// if(distance(vec2(x, y), vec2(ubuf.pointB_x, ubuf.pointB_y)) < 3) {
// fragColor = vec4(0, 1, 0, 1) * ubuf.qt_Opacity;
// }
// if(distance(vec2(x, y), vec2(ubuf.pointC_x, ubuf.pointC_y)) < 3) {
// fragColor = vec4(0, 0, 1, 1) * ubuf.qt_Opacity;
// }
}

Binary file not shown.

View File

@@ -9,8 +9,12 @@ import "root:"
Rectangle {
id: island
height: Config.pillHeight
width: Config.pillWidth * 4 + 20
property int pillWidth: Config.pillWidth * 6
property int pillHeight: Config.pillHeight
height: pillHeight
width: pillWidth + 20
color: "transparent"
@@ -24,26 +28,26 @@ Rectangle {
radius: 30
samples: 16
anchors.centerIn: parent
height: Config.pillHeight
width: Config.pillWidth * 4
height: pillHeight
width: pillWidth
transparentBorder: true
}
BrightnessContrast {
id: bright
anchors.centerIn: parent
height: Config.pillHeight
width: Config.pillWidth * 4
height: pillHeight
width: pillWidth
source: cava
brightness: 0.5
brightness: -0.5
contrast: 1
}
ShaderEffectSource {
id: cava
visible: false
height: Config.pillHeight
width: Config.pillWidth * 4
height: pillHeight
width: pillWidth
mipmap: true
anchors {
horizontalCenter: parent.horizontalCenter
@@ -53,12 +57,13 @@ Rectangle {
wrapMode: ShaderEffectSource.ClampToEdge
// hideSource: true
}
Item {
id: contentwrap
// visible: false
anchors.centerIn: parent
width: Config.pillWidth * 4
height: Config.pillHeight
width: pillWidth
height: pillHeight
ClippingRectangle {
id: contentclip
@@ -70,11 +75,11 @@ Rectangle {
verticalCenter: parent.verticalCenter
}
width: Config.pillWidth * 4
height: Config.pillHeight
width: pillWidth
height: pillHeight
implicitWidth: content.width
implicitHeight: Config.pillHeight * 0.5
// implicitWidth: content.width
// implicitHeight: pillHeight
radius: content.radius
@@ -83,13 +88,13 @@ Rectangle {
Pill {
id: content
// visible: false
color: "white"
color: "black"
// radius: 0
y: 0
width: childrenRect.width ? childrenRect.width + Config.pillHPadding : Config.pillWidth * 4 + 5
height: Config.pillHeight
width: pillWidth
height: pillHeight
anchors {
horizontalCenter: parent.horizontalCenter
@@ -102,13 +107,14 @@ Rectangle {
property int gwidth: parent.width
property real treshold: 0
property real strength: 5
property real pointA_x: 10
property real pointA_y: 10
property real pointB_x: 0
property real pointB_y: 0
property real pointC_x: 0
property real pointC_y: 0
property real pointA_x: 0
property real pointA_y: gheight / 2
property real pointB_x: gwidth / 2
property real pointB_y: gheight / 2
property real pointC_x: gwidth
property real pointC_y: gheight / 2
property real pointA_vx: 0
property real pointA_vy: 0
@@ -125,14 +131,6 @@ Rectangle {
fragmentShader: "root:shaders/pill.frag.qsb"
NumberAnimation on t {
from: 0
to: 0.5
duration: 1000
loops: Animation.Infinite
running: true
}
function distance(x1, y1, x2, y2) {
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
@@ -144,9 +142,11 @@ Rectangle {
let avg_t = Cava.values.reduce((a, b) => a + b, 0) / Cava.values.length;
blur.radius = 30 * avg_t;
blur.samples = 16 * avg_t;
bright.brightness = 0.5 + 0.5 * avg_t;
strength = 5 - 3 * avg_t;
blur.radius = 50 * avg_t;
blur.samples = 16 + 16 * (1 - avg_t);
bright.brightness = -0.5 + 1 * avg_t;
bright.contrast = 0.5 + 0.5 * avg_t;
points.forEach(function (point, index) {
let x = point[0];
@@ -162,51 +162,69 @@ Rectangle {
let t = Cava.values[index];
vx += gwidth * (Math.random() - 0.5);
vy += gheight * (Math.random() - 0.5);
// vx += -25 * avg_t;
vx *= 0.999 * t;
vy *= 0.999 * t;
vx += (gwidth / 2) * (Math.random() - 0.5);
vy += (gheight / 2) * (Math.random() - 0.5);
vx += dcx * 0.01;
vy += dcy * 0.01;
// vx += dcx * 0.01;
// vy += dcy * 0.01;
// if (x < 0) {
// x = r;
// vx = -vx;
// }
// if (x > gwidth) {
// x = gwidth - r;
// vx = -vx;
// }
// if (y < 0) {
// y = r;
// vy = -vy;
// }
// if (y > gheight) {
// y = gheight - r;
// vy = -vy;
// }
if (x < 0) {
x = r;
vx = -vx;
x = gwidth;
}
if (x > gwidth) {
x = gwidth - r;
vx = -vx;
x = 0;
}
if (y < 0) {
y = r;
vy = -vy;
y = gheight;
}
if (y > gheight) {
y = gheight - r;
vy = -vy;
y = 0;
}
points.forEach(function (other, other_index) {
if (index !== other_index) {
let ox = other[0];
let oy = other[1];
let or = other[2];
let ovx = other[3];
let ovy = other[4];
// points.forEach(function (other, other_index) {
// if (index !== other_index && other_index !== 1) {
// let ox = other[0];
// let oy = other[1];
// let or = other[2];
// let ovx = other[3];
// let ovy = other[4];
let d = distance(x, y, ox, oy);
// let d = distance(x, y, ox, oy);
if (d < r + or) {
vx = -vx;
vy = -vy;
}
}
});
// if ((d / 2) < r + or) {
// vx = -vx * (r / or);
// vy = -vy * (r / or);
// ovx = -ovx * (or / r);
// ovy = -ovy * (or / r);
// }
// }
// });
// if (vx > 100) {
// vx = 100;
@@ -224,16 +242,28 @@ Rectangle {
// vy = -100;
// }
vx *= 0.99 * t;
vy *= 0.99 * t;
x += vx * 0.01;
y += vy * 0.01;
// console.log("point", point);
// nan check
if (isNaN(x) || isNaN(y) || isNaN(vx) || isNaN(vy)) {
x = 0;
y = 0;
vx = 0;
vy = 0;
}
point[0] = x;
point[1] = y;
point[2] = 10 * Cava.values[index];
point[3] = vx;
point[4] = vy;
});
pointA_x = points[0][0];
pointA_y = points[0][1];
pointB_x = points[1][0];

View File

@@ -20,7 +20,7 @@ Rectangle {
Repeater {
model: 10
delegate: Pill {
color: "blue"
color: "black"
width: Config.pillWidth * 0.7
height: Config.pillHeight

BIN
wallpapers/rocket.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB