Fix Bokusho ink depletion timestep
This commit is contained in:
parent
b2946a8910
commit
cc73fab705
3 changed files with 60 additions and 8 deletions
|
|
@ -253,6 +253,7 @@ public static class BokushoBrushSimulation
|
|||
var normalRadius = MathF.Max(radius * stroke.NormalScale, 0.0001f);
|
||||
var tangentRadius = MathF.Max(radius * stroke.TangentScale, 0.0001f);
|
||||
var segmentSpan = SegmentSpan(stroke, sampleCount);
|
||||
var integrationSpan = segmentSpan / MathF.Max(sampleCount - 1.0f, 1.0f);
|
||||
var segmentVelocityScale = 1.0f / segmentSpan;
|
||||
var split = Saturate((0.28f - LaneHash(laneKey, tuft, 53)) * 3.0f) * Saturate((edge - 0.20f) * 1.5f) * stroke.SplitScale;
|
||||
for (var sample = 0; sample < sampleCount; sample++)
|
||||
|
|
@ -297,8 +298,8 @@ public static class BokushoBrushSimulation
|
|||
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) * bristleTooth;
|
||||
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.014f + localPressure * 0.009f + dryMemory * 0.004f));
|
||||
stateWet = MathF.Max(0.0f, stateWet - consumedPigment * segmentSpan * (0.006f + dryMemory * 0.003f));
|
||||
stateLoad = MathF.Max(0.0f, stateLoad - consumedPigment * integrationSpan * (0.014f + localPressure * 0.009f + dryMemory * 0.004f));
|
||||
stateWet = MathF.Max(0.0f, stateWet - consumedPigment * integrationSpan * (0.006f + dryMemory * 0.003f));
|
||||
|
||||
if (writeOutput)
|
||||
{
|
||||
|
|
@ -351,6 +352,7 @@ public static class BokushoBrushSimulation
|
|||
var tangentRadius = MathF.Max(radius * stroke.TangentScale, 0.0001f);
|
||||
var segmentSpan = SegmentSpan(stroke, sampleCount);
|
||||
var stepCount = Math.Clamp((int)MathF.Ceiling(segmentSpan * physicsHz), 2, 4096);
|
||||
var integrationSpan = segmentSpan / MathF.Max(stepCount - 1.0f, 1.0f);
|
||||
var segmentVelocityScale = 1.0f / segmentSpan;
|
||||
var split = Saturate((0.28f - LaneHash(laneKey, tuft, 53)) * 3.0f) * Saturate((edge - 0.20f) * 1.5f) * stroke.SplitScale;
|
||||
|
||||
|
|
@ -397,8 +399,8 @@ public static class BokushoBrushSimulation
|
|||
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) * bristleTooth;
|
||||
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.014f + localPressure * 0.009f + dryMemory * 0.004f));
|
||||
stateWet = MathF.Max(0.0f, stateWet - consumedPigment * segmentSpan * (0.006f + dryMemory * 0.003f));
|
||||
stateLoad = MathF.Max(0.0f, stateLoad - consumedPigment * integrationSpan * (0.014f + localPressure * 0.009f + dryMemory * 0.004f));
|
||||
stateWet = MathF.Max(0.0f, stateWet - consumedPigment * integrationSpan * (0.006f + dryMemory * 0.003f));
|
||||
|
||||
if (writeOutput && (writeInitialStep || step > 0))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -437,6 +437,7 @@ void SimulateBokushoTuftSegment(
|
|||
float normalRadius = max(radius * stroke.profile.z, 0.0001);
|
||||
float tangentRadius = max(radius * stroke.profile.w, 0.0001);
|
||||
float segmentSpan = StrokeSegmentSpan(stroke, sampleCount);
|
||||
float integrationSpan = segmentSpan / max((float)sampleCount - 1.0, 1.0);
|
||||
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;
|
||||
|
||||
|
|
@ -483,8 +484,8 @@ void SimulateBokushoTuftSegment(
|
|||
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) * bristleTooth;
|
||||
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.014 + localPressure * 0.009 + dryMemory * 0.004));
|
||||
stateWet = max(0.0, stateWet - consumedPigment * segmentSpan * (0.006 + dryMemory * 0.003));
|
||||
stateLoad = max(0.0, stateLoad - consumedPigment * integrationSpan * (0.014 + localPressure * 0.009 + dryMemory * 0.004));
|
||||
stateWet = max(0.0, stateWet - consumedPigment * integrationSpan * (0.006 + dryMemory * 0.003));
|
||||
|
||||
if (writeOutput)
|
||||
{
|
||||
|
|
@ -528,6 +529,7 @@ void SimulateBokushoTuftSegmentToPage(
|
|||
float tangentRadius = max(radius * stroke.profile.w, 0.0001);
|
||||
float segmentSpan = StrokeSegmentSpan(stroke, sampleCount);
|
||||
uint stepCount = min(max((uint)ceil(segmentSpan * brushShape.z), 2u), 4096u);
|
||||
float integrationSpan = segmentSpan / max((float)stepCount - 1.0, 1.0);
|
||||
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;
|
||||
|
||||
|
|
@ -575,8 +577,8 @@ void SimulateBokushoTuftSegmentToPage(
|
|||
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) * bristleTooth;
|
||||
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.014 + localPressure * 0.009 + dryMemory * 0.004));
|
||||
stateWet = max(0.0, stateWet - consumedPigment * segmentSpan * (0.006 + dryMemory * 0.003));
|
||||
stateLoad = max(0.0, stateLoad - consumedPigment * integrationSpan * (0.014 + localPressure * 0.009 + dryMemory * 0.004));
|
||||
stateWet = max(0.0, stateWet - consumedPigment * integrationSpan * (0.006 + dryMemory * 0.003));
|
||||
|
||||
if (writeOutput && (writeInitialStep || step > 0u))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -184,6 +184,54 @@ public sealed class BokushoBrushSimulationTests
|
|||
Assert.True(longestRun > width / 4, $"longest continuous contact run={longestRun}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CpuBrushPageEvaluationDoesNotDryOutWhenPhysicsRateIncreases()
|
||||
{
|
||||
AquariumBokushoBrushFrame Frame(float physicsHz) => new()
|
||||
{
|
||||
TuftCount = 32,
|
||||
SampleCount = 72,
|
||||
PhysicsHz = physicsHz,
|
||||
BrushRadius = 0.78f,
|
||||
Pressure = 1.02f,
|
||||
InkLoad = 1.20f,
|
||||
Wetness = 1.04f,
|
||||
Splay = 0.74f,
|
||||
Bend = 0.70f,
|
||||
Friction = 0.64f,
|
||||
Strokes =
|
||||
[
|
||||
new AquariumBokushoBrushStroke
|
||||
{
|
||||
StrokeP0 = new Vector4(-3.20f, 0.18f, 0.0f, 0.0f),
|
||||
StrokeP1 = new Vector4(-2.10f, -0.12f, 0.0f, 0.0f),
|
||||
StrokeP2 = new Vector4(1.80f, -0.08f, 0.0f, 0.0f),
|
||||
StrokeP3 = new Vector4(3.20f, 0.12f, 0.0f, 0.0f),
|
||||
RadiusScale = 0.96f,
|
||||
PressureScale = 1.04f,
|
||||
NormalScale = 0.60f,
|
||||
TangentScale = 1.16f,
|
||||
ShaftTilt = 0.10f,
|
||||
ShaftRotation = 0.18f,
|
||||
GripHeight = 0.86f,
|
||||
Compliance = 1.08f,
|
||||
EntryTaper = 0.05f,
|
||||
ExitTaper = 0.18f,
|
||||
PigmentScale = 1.22f,
|
||||
SplitScale = 0.88f,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
var lowRate = BokushoBrushSimulation.EvaluatePage(Frame(125.0f), 144, 72, Vector2.Zero, 4.2f);
|
||||
var highRate = BokushoBrushSimulation.EvaluatePage(Frame(500.0f), 144, 72, Vector2.Zero, 4.2f);
|
||||
var lowMass = lowRate.Sum();
|
||||
var highMass = highRate.Sum();
|
||||
|
||||
Assert.True(lowMass > 0.0f);
|
||||
Assert.True(highMass >= lowMass * 0.80f, $"500 Hz integration dried the brush out: low={lowMass} high={highMass}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PageDensityEncodingMatchesMultiplicativeInkComposition()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue