From b40531508aeea97eed21f35c600cf4d2ec8a5700 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 16 Jun 2026 07:14:10 +0100 Subject: [PATCH] Sweep Bokusho contact patch radii --- .../Render/BokushoBrushSimulation.cs | 18 ++++++++++++++-- .../Render/Shaders/D3D12BokushoBrush.hlsl | 21 +++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs b/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs index 249aa41..71f6aeb 100644 --- a/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs +++ b/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs @@ -341,6 +341,8 @@ public static class BokushoBrushSimulation var stepCount = Math.Clamp((int)MathF.Ceiling(segmentSpan * physicsHz), 2, 4096); var segmentVelocityScale = 1.0f / segmentSpan; var split = Saturate((0.28f - LaneHash(laneKey, tuft, 53)) * 3.0f) * Saturate((edge - 0.20f) * 1.5f) * stroke.SplitScale; + var previousPatchNormalRadius = 0.0f; + var previousPatchTangentRadius = 0.0f; for (var step = 0; step < stepCount; step++) { @@ -392,8 +394,13 @@ public static class BokushoBrushSimulation var pigment = (contactTransfer * (0.95f + localPressure * 0.34f + sweptPatch * 0.24f) + airborneRelease * (1.6f + velocity * 0.002f)) * stroke.PigmentScale; var patchNormalRadius = localNormalRadius * (0.74f + inkFilm * 0.10f + laneCore * 0.20f + localPressure * 0.14f + sweptPatch * 0.08f - separation * 0.10f); var patchTangentRadius = localTangentRadius * (0.86f + inkFilm * 0.06f + bend * 0.22f + drag * 0.16f) + sweptDistance * 0.36f; - DepositSweptPatch(densityPage, width, height, viewCenter, viewRadius, previousTip, tip, patchNormalRadius, patchTangentRadius, pigment, paperTooth); + var sweepStartNormalRadius = previousPatchNormalRadius > 0.0f ? previousPatchNormalRadius : patchNormalRadius; + var sweepStartTangentRadius = previousPatchTangentRadius > 0.0f ? previousPatchTangentRadius : patchTangentRadius; + DepositSweptPatch(densityPage, width, height, viewCenter, viewRadius, previousTip, tip, sweepStartNormalRadius, sweepStartTangentRadius, patchNormalRadius, patchTangentRadius, pigment, paperTooth); } + + previousPatchNormalRadius = localNormalRadius * (0.74f + inkFilm * 0.10f + laneCore * 0.20f + localPressure * 0.14f + sweptPatch * 0.08f - separation * 0.10f); + previousPatchTangentRadius = localTangentRadius * (0.86f + inkFilm * 0.06f + bend * 0.22f + drag * 0.16f) + sweptDistance * 0.36f; } } @@ -653,6 +660,8 @@ public static class BokushoBrushSimulation float viewRadius, Vector2 previousTip, Vector2 tip, + float previousNormalRadius, + float previousTangentRadius, float normalRadius, float tangentRadius, float pigment, @@ -666,13 +675,18 @@ public static class BokushoBrushSimulation previousTip = Quantize(previousTip, PagePatchWorldQuantum); tip = Quantize(tip, PagePatchWorldQuantum); + previousNormalRadius = QuantizePositive(previousNormalRadius, PagePatchWorldQuantum); + previousTangentRadius = QuantizePositive(previousTangentRadius, PagePatchWorldQuantum); normalRadius = QuantizePositive(normalRadius, PagePatchWorldQuantum); tangentRadius = QuantizePositive(tangentRadius, PagePatchWorldQuantum); var sweep = tip - previousTip; var sweepLength = sweep.Length(); var tangent = sweepLength > 0.000001f ? sweep / sweepLength : Vector2.UnitX; var normal = new Vector2(-tangent.Y, tangent.X); - var (patchTangentRadius, patchNormalRadius) = PagePatchRadii(tangentRadius, normalRadius, sweepLength); + var (previousPatchTangentRadius, previousPatchNormalRadius) = PagePatchRadii(previousTangentRadius, previousNormalRadius, sweepLength); + var (currentPatchTangentRadius, currentPatchNormalRadius) = PagePatchRadii(tangentRadius, normalRadius, sweepLength); + var patchTangentRadius = MathF.Max(previousPatchTangentRadius, currentPatchTangentRadius); + var patchNormalRadius = MathF.Max(previousPatchNormalRadius, currentPatchNormalRadius); var center = (previousTip + tip) * 0.5f; var halfSweepLength = sweepLength * 0.5f; var extents = new Vector2( diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12BokushoBrush.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12BokushoBrush.hlsl index 1a5843f..86a32fd 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12BokushoBrush.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12BokushoBrush.hlsl @@ -162,7 +162,7 @@ float PageToothHash(uint x, uint y) return (float)(value & 0x00FFFFFFu) / 16777215.0; } -void DepositSweptPatch(float2 previousTip, float2 tip, float normalRadius, float tangentRadius, float pigment, float paperTooth) +void DepositSweptPatch(float2 previousTip, float2 tip, float previousNormalRadius, float previousTangentRadius, float normalRadius, float tangentRadius, float pigment, float paperTooth) { uint inkUnits = QuantizePositiveUnits(pigment, BOKUSHO_PAGE_PATCH_INK_UNITS); if (inkUnits == 0u) @@ -172,14 +172,20 @@ void DepositSweptPatch(float2 previousTip, float2 tip, float normalRadius, float previousTip = QuantizeFloat2(previousTip, BOKUSHO_PAGE_PATCH_WORLD_QUANTUM); tip = QuantizeFloat2(tip, BOKUSHO_PAGE_PATCH_WORLD_QUANTUM); + previousNormalRadius = QuantizePositive(previousNormalRadius, BOKUSHO_PAGE_PATCH_WORLD_QUANTUM); + previousTangentRadius = QuantizePositive(previousTangentRadius, BOKUSHO_PAGE_PATCH_WORLD_QUANTUM); normalRadius = QuantizePositive(normalRadius, BOKUSHO_PAGE_PATCH_WORLD_QUANTUM); tangentRadius = QuantizePositive(tangentRadius, BOKUSHO_PAGE_PATCH_WORLD_QUANTUM); float2 sweep = tip - previousTip; float sweepLength = length(sweep); float2 tangent = sweepLength > 0.000001 ? sweep / sweepLength : float2(1.0, 0.0); float2 normal = float2(-tangent.y, tangent.x); - float patchTangentRadius = max(tangentRadius * BOKUSHO_PAGE_PATCH_TANGENT_RADIUS_SCALE, BOKUSHO_PAGE_PATCH_MINIMUM_RADIUS); - float patchNormalRadius = max(normalRadius * BOKUSHO_PAGE_PATCH_NORMAL_RADIUS_SCALE, BOKUSHO_PAGE_PATCH_MINIMUM_RADIUS); + float previousPatchTangentRadius = max(previousTangentRadius * BOKUSHO_PAGE_PATCH_TANGENT_RADIUS_SCALE, BOKUSHO_PAGE_PATCH_MINIMUM_RADIUS); + float previousPatchNormalRadius = max(previousNormalRadius * BOKUSHO_PAGE_PATCH_NORMAL_RADIUS_SCALE, BOKUSHO_PAGE_PATCH_MINIMUM_RADIUS); + float currentPatchTangentRadius = max(tangentRadius * BOKUSHO_PAGE_PATCH_TANGENT_RADIUS_SCALE, BOKUSHO_PAGE_PATCH_MINIMUM_RADIUS); + float currentPatchNormalRadius = max(normalRadius * BOKUSHO_PAGE_PATCH_NORMAL_RADIUS_SCALE, BOKUSHO_PAGE_PATCH_MINIMUM_RADIUS); + float patchTangentRadius = max(previousPatchTangentRadius, currentPatchTangentRadius); + float patchNormalRadius = max(previousPatchNormalRadius, currentPatchNormalRadius); float2 center = (previousTip + tip) * 0.5; float halfSweepLength = sweepLength * 0.5; float2 extents = float2( @@ -375,6 +381,8 @@ void SimulateBokushoTuftSegmentToPage( uint stepCount = min(max((uint)ceil(segmentSpan * brushShape.z), 2u), 4096u); float segmentVelocityScale = 1.0 / segmentSpan; float split = saturate((0.28 - LaneHash(laneKey, tuft, 53u)) * 3.0) * saturate((edge - 0.20) * 1.5) * stroke.dynamics.w; + float previousPatchNormalRadius = 0.0; + float previousPatchTangentRadius = 0.0; [loop] for (uint step = 0u; step < stepCount; step += 1u) @@ -427,8 +435,13 @@ void SimulateBokushoTuftSegmentToPage( float pigment = (contactTransfer * (0.95 + localPressure * 0.34 + sweptPatch * 0.24) + airborneRelease * (1.6 + velocity * 0.002)) * stroke.dynamics.z; float patchNormalRadius = localNormalRadius * (0.74 + inkFilm * 0.10 + laneCore * 0.20 + localPressure * 0.14 + sweptPatch * 0.08 - separation * 0.10); float patchTangentRadius = localTangentRadius * (0.86 + inkFilm * 0.06 + bend * 0.22 + drag * 0.16) + sweptDistance * 0.36; - DepositSweptPatch(previousTip, tip, patchNormalRadius, patchTangentRadius, pigment, paperTooth); + float sweepStartNormalRadius = previousPatchNormalRadius > 0.0 ? previousPatchNormalRadius : patchNormalRadius; + float sweepStartTangentRadius = previousPatchTangentRadius > 0.0 ? previousPatchTangentRadius : patchTangentRadius; + DepositSweptPatch(previousTip, tip, sweepStartNormalRadius, sweepStartTangentRadius, patchNormalRadius, patchTangentRadius, pigment, paperTooth); } + + previousPatchNormalRadius = localNormalRadius * (0.74 + inkFilm * 0.10 + laneCore * 0.20 + localPressure * 0.14 + sweptPatch * 0.08 - separation * 0.10); + previousPatchTangentRadius = localTangentRadius * (0.86 + inkFilm * 0.06 + bend * 0.22 + drag * 0.16) + sweptDistance * 0.36; } }