From 51bf15e5527ebc7e4e99ded9251e4d52ec742075 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 14 Jun 2026 03:19:38 +0100 Subject: [PATCH] Carry Bokusho ink through swept contact --- .../Render/BokushoBrushSimulation.cs | 21 +++++++++++-------- .../Render/Shaders/D3D12BokushoBrush.hlsl | 21 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs b/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs index 238553f..7066ae3 100644 --- a/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs +++ b/src/Aquarium.Engine.Contracts/Render/BokushoBrushSimulation.cs @@ -55,7 +55,7 @@ public static class BokushoBrushSimulation } var wetness = Saturate(frame.Wetness / 1.6f); - var load = Saturate(frame.InkLoad / 2.0f); + var load = Math.Clamp(frame.InkLoad / 1.25f, 0.0f, 1.8f); var splay = Saturate(frame.Splay / 2.0f); var bend = Saturate(frame.Bend / 2.4f); var friction = Saturate(frame.Friction); @@ -85,12 +85,12 @@ public static class BokushoBrushSimulation var seedPressure = Saturate(frame.Pressure * seedStroke.PressureScale * 0.5f) * 2.0f; var seedRadius = MathF.Max(frame.BrushRadius * seedStroke.RadiusScale, 0.0001f); var seedNormalRadius = MathF.Max(seedRadius * seedStroke.NormalScale, 0.0001f); - var seedSplit = Saturate((0.20f - LaneHash(chainStart, tuft, 53)) * 4.0f) * Saturate((edge - 0.18f) * 1.7f) * seedStroke.SplitScale; + var seedSplit = Saturate((0.28f - LaneHash(chainStart, tuft, 53)) * 3.0f) * Saturate((edge - 0.20f) * 1.5f) * seedStroke.SplitScale; var initialCohesion = LaneCohesion(edge, seedSplit, wetness, seedPressure); var tip = StrokePoint(seedStroke, 0.0f); var poseBias = seedStroke.ShaftTilt * 0.18f + seedStroke.ShaftRotation * 0.08f; var offset = (restOffset + poseBias * (1.0f - edge * 0.35f)) * seedNormalRadius * (0.42f + splay * 0.38f) + (laneHash - 0.5f) * seedNormalRadius * 0.05f; - var stateLoad = load * (0.62f + initialCohesion * 0.46f) * (1.0f - edge * 0.18f) * laneLoad * (1.0f - seedSplit * 0.36f); + var stateLoad = load * (0.86f + initialCohesion * 0.48f) * (1.0f - edge * 0.08f) * laneLoad * (1.0f - seedSplit * 0.18f); var stateWet = wetness * (0.74f + initialCohesion * 0.24f - seedSplit * 0.08f); for (var replayStrokeIndex = chainStart; replayStrokeIndex < strokeIndex; replayStrokeIndex++) @@ -162,7 +162,10 @@ public static class BokushoBrushSimulation var velocity = slip.Length() * physicsHz * segmentVelocityScale / MathF.Max(radius, 0.001f); var contact = Saturate(localPressure * stateLoad * (0.24f + stateWet * 0.62f + laneCore * 0.18f)); var drag = contact * friction * (0.28f + stateWet * 0.34f); + var previousTip = tip; tip += slip * (0.18f + recovery * 0.82f) * (1.0f - drag * 0.52f); + var sweptDistance = (tip - previousTip).Length(); + var sweptPatch = Saturate(sweptDistance / MathF.Max(localTangentRadius, 0.001f) * 0.42f); var tension = Saturate(velocity * 0.014f + MathF.Abs(targetOffset - offset) / MathF.Max(localNormalRadius, 0.001f) * 0.22f + edge * 0.12f); var separation = Saturate(split * 0.34f + tension * 0.46f + edge * 0.20f - cohesion * 0.24f); @@ -170,23 +173,23 @@ public static class BokushoBrushSimulation var dryMemory = Saturate((1.0f - stateWet) * 0.62f + separation * 0.32f + velocity * 0.004f); var fiberNoise = LaneHash(laneKey + sample * 13, tuft, 101); var continuity = 1.0f - SmoothStep(0.18f + dryMemory * 0.28f, 0.96f, fiberNoise) * dryMemory * (0.38f + edge * 0.22f); - var contactTransfer = contact * stateLoad * (0.12f + stateWet * 0.88f) * (0.24f + drag * 0.62f + localPressure * 0.18f) * (0.62f + laneCore * 0.48f - separation * 0.18f) * continuity; + var contactTransfer = contact * stateLoad * (0.16f + stateWet * 0.92f) * (0.30f + drag * 0.64f + localPressure * 0.22f + sweptPatch * 0.18f) * (0.68f + laneCore * 0.50f - separation * 0.14f) * continuity; var airborneRelease = (1.0f - contact) * stateLoad * stateWet * Saturate(velocity * 0.010f - adhesion * 0.16f) * (0.20f + separation * 0.42f + edge * 0.18f); var consumedPigment = contactTransfer + airborneRelease; - stateLoad = MathF.Max(0.0f, stateLoad - consumedPigment * segmentSpan * (0.028f + localPressure * 0.018f)); - stateWet = MathF.Max(0.0f, stateWet - consumedPigment * segmentSpan * (0.012f + dryMemory * 0.006f)); + stateLoad = MathF.Max(0.0f, stateLoad - consumedPigment * segmentSpan * (0.010f + localPressure * 0.006f)); + stateWet = MathF.Max(0.0f, stateWet - consumedPigment * segmentSpan * (0.006f + dryMemory * 0.003f)); if (writeOutput) { var index = ((strokeIndex * tuftCount) + tuft) * sampleCount + sample; - var pigment = (contactTransfer * (1.8f + localPressure * 0.6f) + airborneRelease * (2.8f + velocity * 0.003f)) * stroke.PigmentScale; + var pigment = (contactTransfer * (0.95f + localPressure * 0.34f + sweptPatch * 0.24f) + airborneRelease * (1.6f + velocity * 0.002f)) * stroke.PigmentScale; canvas[index] = Saturate(pigment); trace[index] = Saturate(contact * 0.70f + airborneRelease * 2.0f + stateLoad * 0.18f); tips[index] = new Vector4( tip.X, tip.Y, - localNormalRadius * (0.72f + laneCore * 0.18f + localPressure * 0.12f - separation * 0.12f), - localTangentRadius * (0.82f + bend * 0.20f + drag * 0.14f)); + localNormalRadius * (0.84f + laneCore * 0.20f + localPressure * 0.14f + sweptPatch * 0.08f - separation * 0.10f), + localTangentRadius * (0.92f + bend * 0.22f + drag * 0.16f) + sweptDistance * 0.36f); } } } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12BokushoBrush.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12BokushoBrush.hlsl index 81cc99c..0a41138 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12BokushoBrush.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12BokushoBrush.hlsl @@ -159,7 +159,10 @@ void SimulateBokushoTuftSegment( float velocity = length(slip) * brushShape.z * segmentVelocityScale / max(radius, 0.001); float contact = saturate(localPressure * stateLoad * (0.24 + stateWet * 0.62 + laneCore * 0.18)); float drag = contact * friction * (0.28 + stateWet * 0.34); + float2 previousTip = tip; tip = tip + slip * (0.18 + recovery * 0.82) * (1.0 - drag * 0.52); + float sweptDistance = length(tip - previousTip); + float sweptPatch = saturate(sweptDistance / max(localTangentRadius, 0.001) * 0.42); float tension = saturate(velocity * 0.014 + abs(targetOffset - offset) / max(localNormalRadius, 0.001) * 0.22 + edge * 0.12); float separation = saturate(split * 0.34 + tension * 0.46 + edge * 0.20 - cohesion * 0.24); @@ -167,24 +170,24 @@ void SimulateBokushoTuftSegment( float dryMemory = saturate((1.0 - stateWet) * 0.62 + separation * 0.32 + velocity * 0.004); float fiberNoise = LaneHash(laneKey + sample * 13u, tuft, 101u); float continuity = 1.0 - smoothstep(0.18 + dryMemory * 0.28, 0.96, fiberNoise) * dryMemory * (0.38 + edge * 0.22); - float contactTransfer = contact * stateLoad * (0.12 + stateWet * 0.88) * (0.24 + drag * 0.62 + localPressure * 0.18) * (0.62 + laneCore * 0.48 - separation * 0.18) * continuity; + float contactTransfer = contact * stateLoad * (0.16 + stateWet * 0.92) * (0.30 + drag * 0.64 + localPressure * 0.22 + sweptPatch * 0.18) * (0.68 + laneCore * 0.50 - separation * 0.14) * continuity; float airborneRelease = (1.0 - contact) * stateLoad * stateWet * saturate(velocity * 0.010 - adhesion * 0.16) * (0.20 + separation * 0.42 + edge * 0.18); float consumedPigment = contactTransfer + airborneRelease; - stateLoad = max(0.0, stateLoad - consumedPigment * segmentSpan * (0.028 + localPressure * 0.018)); - stateWet = max(0.0, stateWet - consumedPigment * segmentSpan * (0.012 + dryMemory * 0.006)); + stateLoad = max(0.0, stateLoad - consumedPigment * segmentSpan * (0.010 + localPressure * 0.006)); + stateWet = max(0.0, stateWet - consumedPigment * segmentSpan * (0.006 + dryMemory * 0.003)); if (writeOutput) { uint index = ((outputStrokeIndex * tuftCount) + tuft) * sampleCount + sample; - float pigment = (contactTransfer * (1.8 + localPressure * 0.6) + airborneRelease * (2.8 + velocity * 0.003)) * stroke.dynamics.z; + float pigment = (contactTransfer * (0.95 + localPressure * 0.34 + sweptPatch * 0.24) + airborneRelease * (1.6 + velocity * 0.002)) * stroke.dynamics.z; float localPigment = saturate(pigment); float trace = saturate(contact * 0.70 + airborneRelease * 2.0 + stateLoad * 0.18); BokushoTraceField[index] = trace; BokushoCanvasField[index] = localPigment; BokushoTipField[index] = float4( tip, - localNormalRadius * (0.72 + laneCore * 0.18 + localPressure * 0.12 - separation * 0.12), - localTangentRadius * (0.82 + bend * 0.20 + drag * 0.14)); + localNormalRadius * (0.84 + laneCore * 0.20 + localPressure * 0.14 + sweptPatch * 0.08 - separation * 0.10), + localTangentRadius * (0.92 + bend * 0.22 + drag * 0.16) + sweptDistance * 0.36); } } } @@ -213,16 +216,16 @@ void D3D12BokushoBrushCS(uint3 dispatchThreadId : SV_DispatchThreadID) float laneLoad = 0.76 + laneHash * 0.34; float seedPressure = saturate(brushMaterial.y * seedStroke.profile.y * 0.5) * 2.0; float wetness = saturate(brushMaterial.w / 1.6); - float load = saturate(brushMaterial.z / 2.0); + float load = clamp(brushMaterial.z / 1.25, 0.0, 1.8); float splay = saturate(brushDynamics.x / 2.0); float seedRadius = max(brushMaterial.x * seedStroke.profile.x, 0.0001); float seedNormalRadius = max(seedRadius * seedStroke.profile.z, 0.0001); - float seedSplit = saturate((0.20 - LaneHash(chainStart, tuft, 53u)) * 4.0) * saturate((edge - 0.18) * 1.7) * seedStroke.dynamics.w; + float seedSplit = saturate((0.28 - LaneHash(chainStart, tuft, 53u)) * 3.0) * saturate((edge - 0.20) * 1.5) * seedStroke.dynamics.w; float initialCohesion = LaneCohesion(edge, seedSplit, wetness, seedPressure); float2 tip = StrokePoint(seedStroke, 0.0); float poseBias = seedStroke.pose.x * 0.18 + seedStroke.pose.y * 0.08; float offset = (restOffset + poseBias * (1.0 - edge * 0.35)) * seedNormalRadius * (0.42 + splay * 0.38) + (laneHash - 0.5) * seedNormalRadius * 0.05; - float stateLoad = load * (0.62 + initialCohesion * 0.46) * (1.0 - edge * 0.18) * laneLoad * (1.0 - seedSplit * 0.36); + float stateLoad = load * (0.86 + initialCohesion * 0.48) * (1.0 - edge * 0.08) * laneLoad * (1.0 - seedSplit * 0.18); float stateWet = wetness * (0.74 + initialCohesion * 0.24 - seedSplit * 0.08); [loop]