fix(glass): define signed coverage square (#642)

This commit is contained in:
InfinityPacer
2026-08-04 19:48:44 +08:00
committed by GitHub
parent 872d46132e
commit 487e567d4c
2 changed files with 15 additions and 10 deletions

View File

@@ -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)')
})
})

View File

@@ -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(