Use source stroke ids for Bokusho tuft replay

This commit is contained in:
Meta Vens 2026-06-13 15:22:10 +01:00
commit 5d550f4ade
5 changed files with 81 additions and 1 deletions

View file

@ -622,6 +622,8 @@ public sealed class AquariumBokushoBrushStroke
public float SegmentEnd { get; init; } = 1.0f;
public int SourceStrokeId { get; init; } = -1;
public AquariumBokushoBrushStroke Normalized() => new()
{
StrokeP0 = StrokeP0,
@ -642,6 +644,7 @@ public sealed class AquariumBokushoBrushStroke
SplitScale = Math.Clamp(SplitScale, 0.0f, 4.0f),
SegmentStart = Math.Clamp(SegmentStart, 0.0f, 1.0f),
SegmentEnd = Math.Clamp(SegmentEnd, 0.0f, 1.0f),
SourceStrokeId = SourceStrokeId,
};
}

View file

@ -286,6 +286,7 @@ public static class BokushoBrushSimulation
SplitScale = 1.0f,
SegmentStart = 0.0f,
SegmentEnd = 1.0f,
SourceStrokeId = 0,
}.Normalized()
];
}
@ -293,10 +294,16 @@ public static class BokushoBrushSimulation
private static int ChainStart(IReadOnlyList<AquariumBokushoBrushStroke> strokes, int strokeIndex)
{
var chainStart = strokeIndex;
var sourceStrokeId = strokes[strokeIndex].SourceStrokeId;
var expectedStart = Math.Clamp(strokes[strokeIndex].SegmentStart, 0.0f, 1.0f);
while (chainStart > 0 && expectedStart > 0.0001f)
{
var previous = strokes[chainStart - 1];
if (sourceStrokeId >= 0 && previous.SourceStrokeId != sourceStrokeId)
{
break;
}
var previousEnd = Math.Clamp(previous.SegmentEnd, 0.0f, 1.0f);
if (MathF.Abs(previousEnd - expectedStart) > 0.001f)
{

View file

@ -4815,7 +4815,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
new Vector4(stroke.StrokeP0.X, stroke.StrokeP0.Y, stroke.SegmentStart, stroke.SegmentEnd),
stroke.StrokeP1,
stroke.StrokeP2,
stroke.StrokeP3);
new Vector4(stroke.StrokeP3.X, stroke.StrokeP3.Y, stroke.StrokeP3.Z, stroke.SourceStrokeId));
}
private void AppendFieldEvidenceGpuSensorInputs()

View file

@ -156,9 +156,15 @@ uint StrokeChainStart(uint strokeIndex)
{
uint chainStart = strokeIndex;
float expectedStart = saturate(BokushoBrushStrokes[strokeIndex].p0.z);
float sourceStrokeId = BokushoBrushStrokes[strokeIndex].p3.w;
[loop]
while (chainStart > 0u && expectedStart > 0.0001)
{
if (sourceStrokeId >= 0.0 && abs(BokushoBrushStrokes[chainStart - 1u].p3.w - sourceStrokeId) > 0.5)
{
break;
}
float previousEnd = saturate(BokushoBrushStrokes[chainStart - 1u].p0.w);
if (abs(previousEnd - expectedStart) > 0.001)
{

View file

@ -361,6 +361,21 @@ public sealed class BokushoBrushSimulationTests
Assert.True(edgeDryBreaks > result.SampleCount / 2);
}
[Fact]
public void CpuBrushSourceStrokeIdPreventsAccidentalSegmentReplay()
{
var shared = SourceIdentityFrame(sameSourceId: true);
var split = SourceIdentityFrame(sameSourceId: false);
var sharedResult = BokushoBrushSimulation.Evaluate(shared);
var splitResult = BokushoBrushSimulation.Evaluate(split);
var secondStrokeOffset = sharedResult.SampleCount * sharedResult.TuftCount;
var sharedSecond = sharedResult.Canvas.Skip(secondStrokeOffset).Sum();
var splitSecond = splitResult.Canvas.Skip(secondStrokeOffset).Sum();
Assert.True(MathF.Abs(sharedSecond - splitSecond) > 0.05f);
}
[Fact]
public void CpuBrushGeometryEnrichesCurvedStrokePressureAndWidth()
{
@ -539,6 +554,55 @@ public sealed class BokushoBrushSimulationTests
};
}
private static AquariumBokushoBrushFrame SourceIdentityFrame(bool sameSourceId)
{
var secondId = sameSourceId ? 7 : 8;
return new AquariumBokushoBrushFrame
{
TuftCount = 9,
SampleCount = 48,
PhysicsHz = 500.0f,
BrushRadius = 1.35f,
Pressure = 0.92f,
InkLoad = 1.28f,
Wetness = 1.02f,
Splay = 0.82f,
Bend = 0.74f,
Friction = 0.68f,
Strokes =
[
new AquariumBokushoBrushStroke
{
StrokeP0 = new Vector4(-3.0f, 0.2f, 0.0f, 0.0f),
StrokeP1 = new Vector4(-2.0f, 0.0f, 0.0f, 0.0f),
StrokeP2 = new Vector4(-0.6f, 0.0f, 0.0f, 0.0f),
StrokeP3 = new Vector4(0.0f, 0.1f, 0.0f, 0.0f),
RadiusScale = 0.90f,
PressureScale = 1.0f,
NormalScale = 0.70f,
TangentScale = 1.08f,
SegmentStart = 0.0f,
SegmentEnd = 0.5f,
SourceStrokeId = 7,
},
new AquariumBokushoBrushStroke
{
StrokeP0 = new Vector4(-0.1f, 0.1f, 0.0f, 0.0f),
StrokeP1 = new Vector4(0.0f, 0.0f, 0.0f, 0.0f),
StrokeP2 = new Vector4(1.8f, 0.0f, 0.0f, 0.0f),
StrokeP3 = new Vector4(3.0f, -0.2f, 0.0f, 0.0f),
RadiusScale = 1.0f,
PressureScale = 1.0f,
NormalScale = 0.70f,
TangentScale = 1.08f,
SegmentStart = 0.5f,
SegmentEnd = 1.0f,
SourceStrokeId = secondId,
},
],
};
}
private static float TuftSum(float[] canvas, int sampleCount, int tuft)
{
return canvas.Skip(tuft * sampleCount).Take(sampleCount).Sum();