From 58bfabe4b60e650a82020341a81245287565666d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 13 Jun 2026 14:37:04 +0100 Subject: [PATCH] Project Bokusho canvas with swept tuft contact --- .../Render/BokushoBrushSimulation.cs | 24 +++++++++++++++---- .../Render/Shaders/D3D12HeightField.hlsl | 20 ++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs b/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs index 52a316a..8b15da1 100644 --- a/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs +++ b/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs @@ -395,19 +395,35 @@ public static class BokushoBrushSimulation { var tuftIndex = Math.Clamp(centerTuft + tuftDelta, 0, tuftCount - 1); var index = ((strokeIndex * tuftCount) + tuftIndex) * sampleCount + sampleIndex; + var previousIndex = ((strokeIndex * tuftCount) + tuftIndex) * sampleCount + Math.Max(sampleIndex - 1, 0); var tip = tips[index]; - var delta = world - new Vector2(tip.X, tip.Y); + var previousTip = tips[previousIndex]; + var tipPoint = new Vector2(tip.X, tip.Y); + var previousTipPoint = new Vector2(previousTip.X, previousTip.Y); + var sweep = tipPoint - previousTipPoint; + var sweepLengthSquared = sweep.LengthSquared(); + var sweepT = sweepLengthSquared <= 0.000001f + ? 1.0f + : Saturate(Vector2.Dot(world - previousTipPoint, sweep) / sweepLengthSquared); + var contactPoint = previousTipPoint + sweep * sweepT; + var sweepDistance = MathF.Sqrt(Vector2.DistanceSquared(world, contactPoint)); + var sweepContact = SmoothStep(1.0f, 0.0f, sweepDistance / MathF.Max(MathF.Max(tip.Z, previousTip.Z) * 1.04f, 0.001f)); + var delta = world - contactPoint; var normalDistance = Vector2.Dot(delta, sampleNormal) / MathF.Max(tip.Z, 0.001f); var tangentDistance = Vector2.Dot(delta, sampleTangent) / MathF.Max(tip.W, 0.001f); var ellipse = MathF.Sqrt(normalDistance * normalDistance + tangentDistance * tangentDistance); - var tipContact = SmoothStep(1.0f, 0.0f, ellipse); - var contribution = canvas[index] * tipContact * (1.0f - MathF.Abs(sampleDelta) * 0.045f); + var tipContact = MathF.Max(SmoothStep(1.0f, 0.0f, ellipse), sweepContact * 0.86f); + var contribution = canvas[index] + * tipContact + * (0.20f + contact * 0.80f) + * (1.0f - MathF.Abs(sampleDelta) * 0.045f) + * (0.82f + sweepContact * 0.24f); pigmentPeak = MathF.Max(pigmentPeak, contribution); pigmentFlow += contribution; } } - return Saturate(pigmentPeak * 0.92f + pigmentFlow * 0.035f) * hold * (0.20f + pressure * 0.28f + Saturate(frame.InkLoad * 0.5f) * 0.12f); + return Saturate(pigmentPeak * 1.14f + pigmentFlow * 0.026f) * hold * (0.30f + pressure * 0.38f + Saturate(frame.InkLoad * 0.5f) * 0.18f); } private static float StrokeTaper(float t, float entryTaper, float exitTaper) diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl index a6dbd8c..f2d650d 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl @@ -305,19 +305,31 @@ float bokushoStrokePageHeight(float2 world, BokushoBrushStroke stroke, uint stro { uint tuftIndex = min((uint)max((int)centerTuft + tuftDelta, 0), tuftCount - 1u); float4 tip = bokushoTipSample(strokeIndex, sampleIndex, tuftIndex); - float2 delta = world - tip.xy; + uint previousSampleIndex = min((uint)max((int)sampleIndex - 1, 0), sampleCount - 1u); + float4 previousTip = bokushoTipSample(strokeIndex, previousSampleIndex, tuftIndex); + float2 sweep = tip.xy - previousTip.xy; + float sweepLengthSquared = dot(sweep, sweep); + float sweepT = sweepLengthSquared <= 0.000001 ? 1.0 : saturate(dot(world - previousTip.xy, sweep) / sweepLengthSquared); + float2 contactPoint = previousTip.xy + sweep * sweepT; + float sweepDistance = length(world - contactPoint); + float sweepContact = smoothstep(1.0, 0.0, sweepDistance / max(max(tip.z, previousTip.z) * 1.04, 0.001)); + float2 delta = world - contactPoint; float normalDistance = dot(delta, sampleNormal) / max(tip.z, 0.001); float tangentDistance = dot(delta, sampleTangent) / max(tip.w, 0.001); float ellipse = sqrt(normalDistance * normalDistance + tangentDistance * tangentDistance); - float tipContact = smoothstep(1.0, 0.0, ellipse); + float tipContact = max(smoothstep(1.0, 0.0, ellipse), sweepContact * 0.86); float pigment = BokushoCanvasField[((strokeIndex * tuftCount) + tuftIndex) * sampleCount + sampleIndex]; - float contribution = pigment * tipContact * (1.0 - abs((float)sampleDelta) * 0.045); + float contribution = pigment + * tipContact + * (0.20 + contact * 0.80) + * (1.0 - abs((float)sampleDelta) * 0.045) + * (0.82 + sweepContact * 0.24); pigmentPeak = max(pigmentPeak, contribution); pigmentFlow += contribution; } } - return saturate(pigmentPeak * 0.92 + pigmentFlow * 0.035) * hold * (0.20 + pressure * 0.28 + saturate(bokushoMaterial.z * 0.5) * 0.12); + return saturate(pigmentPeak * 1.14 + pigmentFlow * 0.026) * hold * (0.30 + pressure * 0.38 + saturate(bokushoMaterial.z * 0.5) * 0.18); } float bokushoPageHeight(float2 world)