From 487e567d4c7161e8a152d5781be52a949bf4518e Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Tue, 4 Aug 2026 19:48:44 +0800 Subject: [PATCH] fix(glass): define signed coverage square (#642) --- .../__tests__/glassFluidDynamics.spec.ts | 22 +++++++++++-------- src/rendering/glass/glassFluidDynamics.ts | 3 ++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/rendering/glass/__tests__/glassFluidDynamics.spec.ts b/src/rendering/glass/__tests__/glassFluidDynamics.spec.ts index 5d9e4d59..b933f399 100644 --- a/src/rendering/glass/__tests__/glassFluidDynamics.spec.ts +++ b/src/rendering/glass/__tests__/glassFluidDynamics.spec.ts @@ -195,17 +195,21 @@ describe('glass fluid dynamics', () => { }) it('narrows directional material coverage without replacing fluid refraction energy', () => { - expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).toContain( - 'smoothstep(0.001, 0.012, length(uPointerVelocity))', - ) + expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).toContain('smoothstep(0.001, 0.012, length(uPointerVelocity))') expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).toContain('directionalCoverageShape') expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).toContain('pointerCoverageEnergy') - expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).toContain( - 'pow(clamp(pointerCoverageShape * uMotion, 0.0, 1.0), 1.15)', - ) - expect(GLASS_FLUID_FRAGMENT_SURFACE_REFRACTION).toContain( - 'pointerDelta * pointerEnergy * pointerStrength', - ) + expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).toContain('pow(clamp(pointerCoverageShape * uMotion, 0.0, 1.0), 1.15)') + expect(GLASS_FLUID_FRAGMENT_SURFACE_REFRACTION).toContain('pointerDelta * pointerEnergy * pointerStrength') expect(GLASS_FLUID_FRAGMENT_SURFACE_REFRACTION).not.toContain('pointerCoverageEnergy') }) + + it('squares the signed coverage offset without GLSL pow', () => { + expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).toContain( + 'float directionalCoverageAlong = pointerAlong + coverageWakeTravel * 0.45;', + ) + expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).toContain( + 'directionalCoverageAlong * directionalCoverageAlong * pointerSpread * 0.55', + ) + expect(GLASS_FLUID_FRAGMENT_SURFACE_SHAPE).not.toContain('pow(pointerAlong + coverageWakeTravel * 0.45, 2.0)') + }) }) diff --git a/src/rendering/glass/glassFluidDynamics.ts b/src/rendering/glass/glassFluidDynamics.ts index 67bd4df3..fb837c22 100644 --- a/src/rendering/glass/glassFluidDynamics.ts +++ b/src/rendering/glass/glassFluidDynamics.ts @@ -223,8 +223,9 @@ export const GLASS_FLUID_FRAGMENT_SURFACE_SHAPE = ` vec2 pointerDelta = uPoin ); float coverageWakeTravel = 0.08 * coverageDirectionality * mix(0.86, 1.18, uMotionExpansion); + float directionalCoverageAlong = pointerAlong + coverageWakeTravel * 0.45; float directionalCoverageShape = exp(-( - pow(pointerAlong + coverageWakeTravel * 0.45, 2.0) * pointerSpread * 0.55 + + directionalCoverageAlong * directionalCoverageAlong * pointerSpread * 0.55 + pointerAcross * pointerAcross * pointerSpread * 2.8 )); float pointerCoverageShape = mix(