From 1258ea8f61955e4adc200ea910294197aadbf5d0 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Sat, 11 Apr 2026 15:57:09 +0200 Subject: [PATCH] chore: format shaders --- assets/shaders/basic.vs | 5 ++--- assets/shaders/distance_field.fs | 35 +++++++++++++++----------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/assets/shaders/basic.vs b/assets/shaders/basic.vs index 98634a0..55f765b 100644 --- a/assets/shaders/basic.vs +++ b/assets/shaders/basic.vs @@ -9,10 +9,9 @@ uniform mat4 mvp; out vec2 fragTexCoord; out vec4 fragColor; -void main() -{ +void main() { fragTexCoord = vertexTexCoord; fragColor = vertexColor; gl_Position = mvp * vec4(vertexPosition, 1.0); -} \ No newline at end of file +} diff --git a/assets/shaders/distance_field.fs b/assets/shaders/distance_field.fs index 2fb2da4..0f3a8f1 100644 --- a/assets/shaders/distance_field.fs +++ b/assets/shaders/distance_field.fs @@ -13,8 +13,8 @@ uniform float shapeInfluence; out vec4 finalColor; float getBallInfluence(vec2 pos, vec2 center, float radius) { - vec2 diff = pos - center; - float distSq = dot(diff, diff); + vec2 diff = pos - center; + float distSq = dot(diff, diff); float radiusSq = radius * radius; if (distSq > radiusSq) return 0.0; float dist = sqrt(distSq); @@ -24,37 +24,34 @@ float getBallInfluence(vec2 pos, vec2 center, float radius) { float getShapeInfluence(vec2 pos) { vec2 uv = pos / resolution; uv.y = 1.0 - uv.y; - - if (any(lessThan(uv, vec2(0.0))) || any(greaterThan(uv, vec2(1.0)))) { - return 0.0; - } - + + if (any(lessThan(uv, vec2(0.0))) || any(greaterThan(uv, vec2(1.0)))) return 0.0; + float signedDistance = texture(distanceFieldTex, uv).r * 255.0 - 128.0; - - float isInside = step(signedDistance, 0.0); + + float isInside = step(signedDistance, 0.0); float isOutside = 1.0 - isInside; - + // inside calculation - float normalizedDist = abs(signedDistance) * 0.015625; // 1/64 + float normalizedDist = abs(signedDistance) * 0.015625; // 1/64 float insideInfluence = shapeInfluence * exp(-normalizedDist * 0.5) * 3.0; - + // outside calculation float adjustedDistance = signedDistance * 0.5; float shapeInfluenceSq = shapeInfluence * shapeInfluence; - float outsideInfluence = shapeInfluenceSq / (adjustedDistance * adjustedDistance + shapeInfluence) + + float outsideInfluence = shapeInfluenceSq / (adjustedDistance * adjustedDistance + shapeInfluence) + shapeInfluence * 0.8 * exp(-signedDistance * 0.025); // 1/40 - + return isInside * insideInfluence + isOutside * outsideInfluence; } -void main() -{ +void main() { vec2 pixelPos = fragTexCoord * resolution; - - float ballValue = getBallInfluence(pixelPos, mousePos, ballRadius); + + float ballValue = getBallInfluence(pixelPos, mousePos, ballRadius); float shapeValue = getShapeInfluence(pixelPos); float totalValue = ballValue + shapeValue * 0.01; float mask = step(0.75, totalValue); finalColor = vec4(mask, mask, mask, 1.0); -} \ No newline at end of file +}