Add Bokusho stroke pose controls

This commit is contained in:
Meta Vens 2026-06-13 12:11:27 +01:00
commit 7a93ee41e4
6 changed files with 111 additions and 18 deletions

View file

@ -602,6 +602,14 @@ public sealed class AquariumBokushoBrushStroke
public float TangentScale { get; init; } = 1.0f;
public float ShaftTilt { get; init; }
public float ShaftRotation { get; init; }
public float GripHeight { get; init; } = 1.0f;
public float Compliance { get; init; } = 1.0f;
public float EntryTaper { get; init; } = 0.10f;
public float ExitTaper { get; init; } = 0.14f;
@ -620,6 +628,10 @@ public sealed class AquariumBokushoBrushStroke
PressureScale = Math.Clamp(PressureScale, 0.1f, 4.0f),
NormalScale = Math.Clamp(NormalScale, 0.1f, 4.0f),
TangentScale = Math.Clamp(TangentScale, 0.1f, 4.0f),
ShaftTilt = Math.Clamp(ShaftTilt, -1.5f, 1.5f),
ShaftRotation = Math.Clamp(ShaftRotation, -2.0f, 2.0f),
GripHeight = Math.Clamp(GripHeight, 0.2f, 2.4f),
Compliance = Math.Clamp(Compliance, 0.1f, 2.5f),
EntryTaper = Math.Clamp(EntryTaper, 0.01f, 0.50f),
ExitTaper = Math.Clamp(ExitTaper, 0.01f, 0.50f),
PigmentScale = Math.Clamp(PigmentScale, 0.05f, 4.0f),

View file

@ -51,6 +51,10 @@ public static class BokushoBrushSimulation
var radius = MathF.Max(frame.BrushRadius * stroke.RadiusScale, 0.0001f);
var normalRadius = MathF.Max(radius * stroke.NormalScale, 0.0001f);
var tangentRadius = MathF.Max(radius * stroke.TangentScale, 0.0001f);
var poseTilt = stroke.ShaftTilt;
var poseRotation = stroke.ShaftRotation;
var gripHeight = stroke.GripHeight;
var compliance = stroke.Compliance;
for (var tuft = 0; tuft < tuftCount; tuft++)
{
@ -62,7 +66,8 @@ public static class BokushoBrushSimulation
var split = Saturate((0.20f - LaneHash(strokeIndex, tuft, 53)) * 4.0f) * Saturate((edge - 0.18f) * 1.7f) * stroke.SplitScale;
var initialCohesion = LaneCohesion(edge, split, wetness, pressure);
var tip = StrokePoint(stroke, 0.0f);
var offset = restOffset * normalRadius * (0.42f + splay * 0.38f) + (laneHash - 0.5f) * normalRadius * 0.05f;
var poseBias = poseTilt * 0.18f + poseRotation * 0.08f;
var offset = (restOffset + poseBias * (1.0f - edge * 0.35f)) * normalRadius * (0.42f + splay * 0.38f) + (laneHash - 0.5f) * normalRadius * 0.05f;
var stateLoad = load * (0.62f + initialCohesion * 0.46f) * (1.0f - edge * 0.18f) * laneLoad * (1.0f - split * 0.36f);
var stateWet = wetness * (0.74f + initialCohesion * 0.24f - split * 0.08f);
@ -80,17 +85,20 @@ public static class BokushoBrushSimulation
var gestureWidth = StrokeGestureWidthShape(stroke, t, sampleCount);
var localPressure = pressure * taper * pressureShape * gesturePressure;
var cohesion = LaneCohesion(edge, split, stateWet, localPressure);
var localNormalRadius = MathF.Max(normalRadius * normalShape * gestureWidth, 0.0001f);
var localTangentRadius = MathF.Max(tangentRadius * tangentShape * (0.92f + gestureWidth * 0.08f), 0.0001f);
var poseSpread = Saturate(0.92f + MathF.Abs(poseTilt) * 0.22f + compliance * 0.10f - gripHeight * 0.04f);
var localNormalRadius = MathF.Max(normalRadius * normalShape * gestureWidth * poseSpread, 0.0001f);
var localTangentRadius = MathF.Max(tangentRadius * tangentShape * (0.86f + gestureWidth * 0.08f + gripHeight * 0.10f), 0.0001f);
var turn = MathF.Sin(t * MathF.Tau + strokeIndex * 0.37f);
var targetOffset = restOffset * localNormalRadius * (0.38f + splay * 0.52f + localPressure * 0.08f - wetness * 0.10f) + turn * localNormalRadius * 0.14f * (1.0f - edge);
var recovery = Saturate(0.08f + stateWet * 0.12f + localPressure * 0.08f + (1.0f - edge) * 0.07f);
var rotatedRest = restOffset + poseRotation * 0.10f * (1.0f - edge);
var targetOffset = rotatedRest * localNormalRadius * (0.38f + splay * 0.52f + localPressure * 0.08f - wetness * 0.10f) + (turn + poseRotation * 0.22f) * localNormalRadius * 0.14f * (1.0f - edge);
var recovery = Saturate(0.06f + stateWet * 0.10f + localPressure * 0.07f + (1.0f - edge) * 0.06f + compliance * 0.07f);
offset = Lerp(offset, targetOffset, recovery);
var lag = localTangentRadius * (0.12f + bend * 0.72f + friction * localPressure * 0.34f + edge * 0.18f);
var lag = localTangentRadius * (0.10f + bend * 0.62f + gripHeight * 0.18f + friction * localPressure * 0.30f + edge * 0.16f);
var desiredTip = center + normal * offset - tangent * lag;
var slip = desiredTip - tip;
var contact = Saturate(localPressure * stateWet * stateLoad * (0.58f + cohesion * 0.40f + (1.0f - edge) * 0.18f));
var poseContact = 0.90f + compliance * 0.10f + (1.0f - Saturate(gripHeight / 2.4f)) * 0.10f;
var contact = Saturate(localPressure * poseContact * stateWet * stateLoad * (0.58f + cohesion * 0.40f + (1.0f - edge) * 0.18f));
var drag = contact * friction * (0.38f + stateWet * 0.22f + edge * 0.18f);
tip += slip * (1.0f - drag);
@ -243,10 +251,12 @@ public static class BokushoBrushSimulation
var lateral = Vector2.Dot(world - centerPoint, normal);
var taper = StrokeTaper(bestT, stroke.EntryTaper, stroke.ExitTaper);
var gestureWidth = StrokeGestureWidthShape(stroke, bestT, sampleCount);
var radius = MathF.Max(frame.BrushRadius * stroke.RadiusScale * stroke.NormalScale * StrokeNormalRadiusShape(taper) * gestureWidth, 0.0001f);
var poseSpread = Saturate(0.92f + MathF.Abs(stroke.ShaftTilt) * 0.22f + stroke.Compliance * 0.10f - stroke.GripHeight * 0.04f);
var radius = MathF.Max(frame.BrushRadius * stroke.RadiusScale * stroke.NormalScale * StrokeNormalRadiusShape(taper) * gestureWidth * poseSpread, 0.0001f);
var splay = Saturate(frame.Splay / 2.0f);
var pressure = Saturate(frame.Pressure * stroke.PressureScale * 0.5f) * taper;
pressure *= StrokePressureShape(bestT, stroke.EntryTaper, stroke.ExitTaper) * StrokeGesturePressureShape(stroke, bestT, sampleCount);
var poseContact = 0.90f + stroke.Compliance * 0.10f + (1.0f - Saturate(stroke.GripHeight / 2.4f)) * 0.10f;
pressure *= StrokePressureShape(bestT, stroke.EntryTaper, stroke.ExitTaper) * StrokeGesturePressureShape(stroke, bestT, sampleCount) * poseContact;
var footprint = radius * (0.42f + splay * 0.74f + pressure * 0.18f);
var tuftT = Saturate(lateral / MathF.Max(footprint, 0.001f) * 0.5f + 0.5f);
var distance = MathF.Sqrt(bestDistance);

View file

@ -4786,6 +4786,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
new D3D12BokushoBrushStrokePacket(
new Vector4(frame.RadiusScale, frame.PressureScale, frame.NormalScale, frame.TangentScale),
new Vector4(0.10f, 0.14f, 1.0f, 1.0f),
new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
frame.StrokeP0,
frame.StrokeP1,
frame.StrokeP2,
@ -4798,6 +4799,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
return new D3D12BokushoBrushStrokePacket(
new Vector4(stroke.RadiusScale, stroke.PressureScale, stroke.NormalScale, stroke.TangentScale),
new Vector4(stroke.EntryTaper, stroke.ExitTaper, stroke.PigmentScale, stroke.SplitScale),
new Vector4(stroke.ShaftTilt, stroke.ShaftRotation, stroke.GripHeight, stroke.Compliance),
stroke.StrokeP0,
stroke.StrokeP1,
stroke.StrokeP2,
@ -7025,6 +7027,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
private readonly record struct D3D12BokushoBrushStrokePacket(
Vector4 Profile,
Vector4 Dynamics,
Vector4 Pose,
Vector4 StrokeP0,
Vector4 StrokeP1,
Vector4 StrokeP2,

View file

@ -16,6 +16,7 @@ struct BokushoBrushStroke
{
float4 profile;
float4 dynamics;
float4 pose;
float4 p0;
float4 p1;
float4 p2;
@ -163,8 +164,13 @@ void D3D12BokushoBrushCS(uint3 dispatchThreadId : SV_DispatchThreadID)
float radius = max(brushMaterial.x * stroke.profile.x, 0.0001);
float normalRadius = max(radius * stroke.profile.z, 0.0001);
float tangentRadius = max(radius * stroke.profile.w, 0.0001);
float poseTilt = stroke.pose.x;
float poseRotation = stroke.pose.y;
float gripHeight = stroke.pose.z;
float compliance = stroke.pose.w;
float2 tip = StrokePoint(stroke, 0.0);
float offset = restOffset * normalRadius * (0.42 + splay * 0.38) + (laneHash - 0.5) * normalRadius * 0.05;
float poseBias = poseTilt * 0.18 + poseRotation * 0.08;
float offset = (restOffset + poseBias * (1.0 - edge * 0.35)) * normalRadius * (0.42 + splay * 0.38) + (laneHash - 0.5) * normalRadius * 0.05;
float stateLoad = load * (0.62 + initialCohesion * 0.46) * (1.0 - edge * 0.18) * laneLoad * (1.0 - split * 0.36);
float stateWet = wetness * (0.74 + initialCohesion * 0.24 - split * 0.08);
@ -183,17 +189,20 @@ void D3D12BokushoBrushCS(uint3 dispatchThreadId : SV_DispatchThreadID)
float gestureWidth = StrokeGestureWidthShape(stroke, t);
float localPressure = pressure * taper * pressureShape * gesturePressure;
float cohesion = LaneCohesion(edge, split, stateWet, localPressure);
float localNormalRadius = max(normalRadius * normalShape * gestureWidth, 0.0001);
float localTangentRadius = max(tangentRadius * tangentShape * (0.92 + gestureWidth * 0.08), 0.0001);
float poseSpread = saturate(0.92 + abs(poseTilt) * 0.22 + compliance * 0.10 - gripHeight * 0.04);
float localNormalRadius = max(normalRadius * normalShape * gestureWidth * poseSpread, 0.0001);
float localTangentRadius = max(tangentRadius * tangentShape * (0.86 + gestureWidth * 0.08 + gripHeight * 0.10), 0.0001);
float turn = sin(t * 6.28318530718 + (float)strokeIndex * 0.37);
float targetOffset = restOffset * localNormalRadius * (0.38 + splay * 0.52 + localPressure * 0.08 - wetness * 0.10) + turn * localNormalRadius * 0.14 * (1.0 - edge);
float recovery = saturate(0.08 + stateWet * 0.12 + localPressure * 0.08 + (1.0 - edge) * 0.07);
float rotatedRest = restOffset + poseRotation * 0.10 * (1.0 - edge);
float targetOffset = rotatedRest * localNormalRadius * (0.38 + splay * 0.52 + localPressure * 0.08 - wetness * 0.10) + (turn + poseRotation * 0.22) * localNormalRadius * 0.14 * (1.0 - edge);
float recovery = saturate(0.06 + stateWet * 0.10 + localPressure * 0.07 + (1.0 - edge) * 0.06 + compliance * 0.07);
offset = cultmath_lerp(offset, targetOffset, recovery);
float lag = localTangentRadius * (0.12 + bend * 0.72 + friction * localPressure * 0.34 + edge * 0.18);
float lag = localTangentRadius * (0.10 + bend * 0.62 + gripHeight * 0.18 + friction * localPressure * 0.30 + edge * 0.16);
float2 desiredTip = center + normal * offset - tangent * lag;
float2 slip = desiredTip - tip;
float contact = saturate(localPressure * stateWet * stateLoad * (0.58 + cohesion * 0.40 + (1.0 - edge) * 0.18));
float poseContact = 0.90 + compliance * 0.10 + (1.0 - saturate(gripHeight / 2.4)) * 0.10;
float contact = saturate(localPressure * poseContact * stateWet * stateLoad * (0.58 + cohesion * 0.40 + (1.0 - edge) * 0.18));
float drag = contact * friction * (0.38 + stateWet * 0.22 + edge * 0.18);
tip = tip + slip * (1.0 - drag);

View file

@ -49,6 +49,7 @@ struct BokushoBrushStroke
{
float4 profile;
float4 dynamics;
float4 pose;
float4 p0;
float4 p1;
float4 p2;
@ -258,9 +259,11 @@ float bokushoStrokePageHeight(float2 world, BokushoBrushStroke stroke, uint stro
float lateral = dot(world - center, normal);
float taper = bokushoStrokeTaper(stroke, bestT);
float gestureWidth = bokushoStrokeGestureWidthShape(stroke, bestT);
float radius = max(bokushoMaterial.x * stroke.profile.x * stroke.profile.z * bokushoStrokeNormalRadiusShape(taper) * gestureWidth, 0.0001);
float poseSpread = saturate(0.92 + abs(stroke.pose.x) * 0.22 + stroke.pose.w * 0.10 - stroke.pose.z * 0.04);
float radius = max(bokushoMaterial.x * stroke.profile.x * stroke.profile.z * bokushoStrokeNormalRadiusShape(taper) * gestureWidth * poseSpread, 0.0001);
float splay = saturate(bokushoDynamics.x / 2.0);
float pressure = saturate(bokushoMaterial.y * stroke.profile.y * 0.5) * taper * bokushoStrokePressureShape(stroke, bestT) * bokushoStrokeGesturePressureShape(stroke, bestT);
float poseContact = 0.90 + stroke.pose.w * 0.10 + (1.0 - saturate(stroke.pose.z / 2.4)) * 0.10;
float pressure = saturate(bokushoMaterial.y * stroke.profile.y * 0.5) * taper * bokushoStrokePressureShape(stroke, bestT) * bokushoStrokeGesturePressureShape(stroke, bestT) * poseContact;
float footprint = radius * (0.42 + splay * 0.74 + pressure * 0.18);
float tuftT = saturate(lateral / max(footprint, 0.001) * 0.5 + 0.5);
float distance = sqrt(bestDistance);

View file

@ -358,6 +358,23 @@ public sealed class BokushoBrushSimulationTests
Assert.True(curvedCoverage > straightCoverage);
}
[Fact]
public void CpuBrushPoseControlsStrokeSpreadAndPigment()
{
var neutral = PoseFrame(tilt: 0.0f, rotation: 0.0f, gripHeight: 1.0f, compliance: 1.0f);
var expressive = PoseFrame(tilt: 0.85f, rotation: 0.65f, gripHeight: 0.58f, compliance: 1.65f);
var neutralResult = BokushoBrushSimulation.Evaluate(neutral);
var expressiveResult = BokushoBrushSimulation.Evaluate(expressive);
var neutralPage = BokushoBrushSimulation.ProjectCanvasToPage(neutral, neutralResult.Canvas, 128, 128, Vector2.Zero, 4.0f);
var expressivePage = BokushoBrushSimulation.ProjectCanvasToPage(expressive, expressiveResult.Canvas, 128, 128, Vector2.Zero, 4.0f);
var neutralCoverage = neutralPage.Count(value => value > 0.004f);
var expressiveCoverage = expressivePage.Count(value => value > 0.004f);
Assert.True(expressiveResult.Canvas.Sum() > neutralResult.Canvas.Sum() * 1.04f);
Assert.True(expressiveCoverage > neutralCoverage);
}
private static AquariumBokushoBrushFrame StrokeDynamicsFrame(float pigmentScale, float entryTaper)
{
return new AquariumBokushoBrushFrame
@ -428,6 +445,45 @@ public sealed class BokushoBrushSimulationTests
};
}
private static AquariumBokushoBrushFrame PoseFrame(float tilt, float rotation, float gripHeight, float compliance)
{
return new AquariumBokushoBrushFrame
{
TuftCount = 15,
SampleCount = 84,
PhysicsHz = 500.0f,
BrushRadius = 1.16f,
Pressure = 0.86f,
InkLoad = 1.24f,
Wetness = 1.08f,
Splay = 0.84f,
Bend = 0.76f,
Friction = 0.68f,
Strokes =
[
new AquariumBokushoBrushStroke
{
StrokeP0 = new Vector4(-2.8f, 0.4f, 0.0f, 0.0f),
StrokeP1 = new Vector4(-1.2f, -0.7f, 0.0f, 0.0f),
StrokeP2 = new Vector4(1.6f, 0.5f, 0.0f, 0.0f),
StrokeP3 = new Vector4(2.8f, -0.3f, 0.0f, 0.0f),
RadiusScale = 0.90f,
PressureScale = 1.0f,
NormalScale = 0.66f,
TangentScale = 1.18f,
ShaftTilt = tilt,
ShaftRotation = rotation,
GripHeight = gripHeight,
Compliance = compliance,
EntryTaper = 0.08f,
ExitTaper = 0.24f,
PigmentScale = 1.0f,
SplitScale = 1.25f,
},
],
};
}
private static AquariumBokushoBrushFrame LaneCohesionFrame(float wetness)
{
return new AquariumBokushoBrushFrame