Break Bokusho bristle edges by lane contact
This commit is contained in:
parent
baa2c85add
commit
10f9e1c2fb
4 changed files with 37 additions and 11 deletions
|
|
@ -179,8 +179,12 @@ public static class BokushoBrushSimulation
|
|||
var dryMemory = Saturate((1.0f - stateWet) * 0.68f + edgeComb * 0.42f + velocity * 0.004f - localPressure * 0.10f);
|
||||
var fiberNoise = LaneHash(laneKey + sample * 13, tuft, 101);
|
||||
var fiberGate = SmoothStep(0.20f + dryMemory * 0.24f, 0.96f, fiberNoise);
|
||||
var tearNoise = LaneHash(laneKey + sample * 29, tuft, 211);
|
||||
var tearReadiness = Saturate(edge * 1.10f + separation * 0.64f + split * 0.18f + dryMemory * 0.22f - laneCore * 0.36f);
|
||||
var bristleTear = SmoothStep(0.50f - separation * 0.16f - dryMemory * 0.10f, 0.98f, tearNoise) * tearReadiness;
|
||||
var bristleContinuity = 1.0f - bristleTear * (0.42f + dryMemory * 0.24f + edge * 0.16f);
|
||||
var depositBody = 0.70f + laneCore * 0.58f - edgeComb * 0.14f;
|
||||
var depositIntermittency = 1.0f - fiberGate * dryMemory * (0.48f + edge * 0.24f);
|
||||
var depositIntermittency = (1.0f - fiberGate * dryMemory * (0.48f + edge * 0.24f)) * bristleContinuity;
|
||||
var deposition = contact * stateLoad * stateWet * Saturate(0.10f + drag * 0.72f + velocity * 0.010f) * (0.74f + separation * 0.18f + cohesion * 0.26f) * depositBody * depositIntermittency;
|
||||
stateLoad = MathF.Max(0.0f, stateLoad - deposition * segmentSpan * (0.032f + localPressure * 0.020f - cohesion * 0.008f));
|
||||
stateWet = MathF.Max(0.0f, stateWet - deposition * segmentSpan * (0.010f + dryMemory * 0.004f + edgeComb * 0.003f));
|
||||
|
|
@ -191,13 +195,13 @@ public static class BokushoBrushSimulation
|
|||
var pigmentSurvival = 0.62f + cohesion * 0.30f + laneCore * 0.36f - split * 0.08f - dryMemory * 0.12f;
|
||||
var joinBlend = SegmentJoinBlend(strokes, strokeIndex, stroke, t);
|
||||
var pigment = deposition * (8.4f + contact * 2.8f) + contact * stateLoad * stateWet * (0.14f + laneCore * 0.18f) + adhesion * contact * 0.08f;
|
||||
canvas[index] = Saturate(pigment * pigmentSurvival * stroke.PigmentScale * joinBlend);
|
||||
trace[index] = Saturate((contact * (0.24f + stateLoad * 0.36f + adhesion * 0.18f + laneCore * 0.12f) + deposition * 1.9f) * joinBlend);
|
||||
canvas[index] = Saturate(pigment * pigmentSurvival * stroke.PigmentScale * joinBlend * bristleContinuity);
|
||||
trace[index] = Saturate((contact * (0.24f + stateLoad * 0.36f + adhesion * 0.18f + laneCore * 0.12f) + deposition * 1.9f) * joinBlend * (0.72f + bristleContinuity * 0.28f));
|
||||
tips[index] = new Vector4(
|
||||
tip.X,
|
||||
tip.Y,
|
||||
localNormalRadius * (0.54f + laneCore * 0.24f + localPressure * 0.22f + splay * 0.20f - split * 0.04f),
|
||||
localTangentRadius * (0.84f + drag * 0.34f + bend * 0.18f));
|
||||
localNormalRadius * (0.54f + laneCore * 0.24f + localPressure * 0.22f + splay * 0.20f - split * 0.04f) * (1.0f - bristleTear * (0.34f + edge * 0.16f)),
|
||||
localTangentRadius * (0.84f + drag * 0.34f + bend * 0.18f) * (1.0f - bristleTear * 0.18f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -445,7 +449,7 @@ public static class BokushoBrushSimulation
|
|||
var sampleTangent = StrokeTangent(sampleStroke, sampleT, sampleCount);
|
||||
var sampleNormal = new Vector2(-sampleTangent.Y, sampleTangent.X);
|
||||
|
||||
for (var tuftDelta = -4; tuftDelta <= 4; tuftDelta++)
|
||||
for (var tuftDelta = -2; tuftDelta <= 2; tuftDelta++)
|
||||
{
|
||||
var tuftIndex = Math.Clamp(centerTuft + tuftDelta, 0, tuftCount - 1);
|
||||
var previousStrokeIndex = sampleStrokeIndex;
|
||||
|
|
|
|||
|
|
@ -260,8 +260,12 @@ void SimulateBokushoTuftSegment(
|
|||
float dryMemory = saturate((1.0 - stateWet) * 0.68 + edgeComb * 0.42 + velocity * 0.004 - localPressure * 0.10);
|
||||
float fiberNoise = LaneHash(laneKey + sample * 13u, tuft, 101u);
|
||||
float fiberGate = smoothstep(0.20 + dryMemory * 0.24, 0.96, fiberNoise);
|
||||
float tearNoise = LaneHash(laneKey + sample * 29u, tuft, 211u);
|
||||
float tearReadiness = saturate(edge * 1.10 + separation * 0.64 + split * 0.18 + dryMemory * 0.22 - laneCore * 0.36);
|
||||
float bristleTear = smoothstep(0.50 - separation * 0.16 - dryMemory * 0.10, 0.98, tearNoise) * tearReadiness;
|
||||
float bristleContinuity = 1.0 - bristleTear * (0.42 + dryMemory * 0.24 + edge * 0.16);
|
||||
float depositBody = 0.70 + laneCore * 0.58 - edgeComb * 0.14;
|
||||
float depositIntermittency = 1.0 - fiberGate * dryMemory * (0.48 + edge * 0.24);
|
||||
float depositIntermittency = (1.0 - fiberGate * dryMemory * (0.48 + edge * 0.24)) * bristleContinuity;
|
||||
float deposition = contact * stateLoad * stateWet * saturate(0.10 + drag * 0.72 + velocity * 0.010) * (0.74 + separation * 0.18 + cohesion * 0.26) * depositBody * depositIntermittency;
|
||||
stateLoad = max(0.0, stateLoad - deposition * segmentSpan * (0.032 + localPressure * 0.020 - cohesion * 0.008));
|
||||
stateWet = max(0.0, stateWet - deposition * segmentSpan * (0.010 + dryMemory * 0.004 + edgeComb * 0.003));
|
||||
|
|
@ -272,11 +276,14 @@ void SimulateBokushoTuftSegment(
|
|||
float pigmentSurvival = 0.62 + cohesion * 0.30 + laneCore * 0.36 - split * 0.08 - dryMemory * 0.12;
|
||||
float joinBlend = SegmentJoinBlend(outputStrokeIndex, stroke, t);
|
||||
float pigment = deposition * (8.4 + contact * 2.8) + contact * stateLoad * stateWet * (0.14 + laneCore * 0.18) + adhesion * contact * 0.08;
|
||||
float localPigment = saturate(pigment * pigmentSurvival * stroke.dynamics.z * joinBlend);
|
||||
float trace = saturate((contact * (0.24 + stateLoad * 0.36 + adhesion * 0.18 + laneCore * 0.12) + deposition * 1.9) * joinBlend);
|
||||
float localPigment = saturate(pigment * pigmentSurvival * stroke.dynamics.z * joinBlend * bristleContinuity);
|
||||
float trace = saturate((contact * (0.24 + stateLoad * 0.36 + adhesion * 0.18 + laneCore * 0.12) + deposition * 1.9) * joinBlend * (0.72 + bristleContinuity * 0.28));
|
||||
BokushoTraceField[index] = trace;
|
||||
BokushoCanvasField[index] = localPigment;
|
||||
BokushoTipField[index] = float4(tip, localNormalRadius * (0.54 + laneCore * 0.24 + localPressure * 0.22 + splay * 0.20 - split * 0.04), localTangentRadius * (0.84 + drag * 0.34 + bend * 0.18));
|
||||
BokushoTipField[index] = float4(
|
||||
tip,
|
||||
localNormalRadius * (0.54 + laneCore * 0.24 + localPressure * 0.22 + splay * 0.20 - split * 0.04) * (1.0 - bristleTear * (0.34 + edge * 0.16)),
|
||||
localTangentRadius * (0.84 + drag * 0.34 + bend * 0.18) * (1.0 - bristleTear * 0.18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ float bokushoStrokePageHeight(float2 world, BokushoBrushStroke stroke, uint stro
|
|||
float2 sampleNormal = float2(-sampleTangent.y, sampleTangent.x);
|
||||
|
||||
[unroll]
|
||||
for (int tuftDelta = -4; tuftDelta <= 4; tuftDelta += 1)
|
||||
for (int tuftDelta = -2; tuftDelta <= 2; tuftDelta += 1)
|
||||
{
|
||||
uint tuftIndex = min((uint)max((int)centerTuft + tuftDelta, 0), tuftCount - 1u);
|
||||
float4 tip = bokushoTipSample(sampleStrokeIndex, sampleIndex, tuftIndex);
|
||||
|
|
|
|||
|
|
@ -355,10 +355,13 @@ public sealed class BokushoBrushSimulationTests
|
|||
var edgeSum = edge.Sum();
|
||||
var centerBodySamples = center.Count(value => value > 0.10f);
|
||||
var edgeDryBreaks = edge.Count(value => value < 0.035f);
|
||||
var centerRoughness = NormalizedRoughness(center);
|
||||
var edgeRoughness = NormalizedRoughness(edge);
|
||||
|
||||
Assert.True(centerSum > edgeSum * 2.2f);
|
||||
Assert.True(centerBodySamples > result.SampleCount / 3);
|
||||
Assert.True(edgeDryBreaks > result.SampleCount / 2);
|
||||
Assert.True(edgeRoughness > centerRoughness * 1.20f, $"center={centerRoughness:0.000000}; edge={edgeRoughness:0.000000}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -692,6 +695,18 @@ public sealed class BokushoBrushSimulationTests
|
|||
return canvas.Skip(stroke * sampleCount * tuftCount).Take(sampleCount * tuftCount).Sum();
|
||||
}
|
||||
|
||||
private static float NormalizedRoughness(IReadOnlyList<float> samples)
|
||||
{
|
||||
var total = samples.Sum();
|
||||
var variation = 0.0f;
|
||||
for (var index = 1; index < samples.Count; index++)
|
||||
{
|
||||
variation += MathF.Abs(samples[index] - samples[index - 1]);
|
||||
}
|
||||
|
||||
return variation / MathF.Max(total, 0.001f);
|
||||
}
|
||||
|
||||
private static float[] LastSampleOnly(IReadOnlyList<float> canvas, int sampleCount, int tuftCount)
|
||||
{
|
||||
var sparse = new float[canvas.Count];
|
||||
|
|
|
|||
Loading…
Reference in a new issue