Replay Bokusho tuft state across stroke segments
This commit is contained in:
parent
60987c5df1
commit
43df4e6f89
2 changed files with 182 additions and 109 deletions
|
|
@ -81,67 +81,111 @@ public static class BokushoBrushSimulation
|
|||
var edge = MathF.Abs(restOffset);
|
||||
var laneHash = LaneHash(chainStart, tuft, 17);
|
||||
var laneLoad = 0.76f + laneHash * 0.34f;
|
||||
var split = Saturate((0.20f - LaneHash(chainStart, 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 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 sourceCarry = 1.0f - strokeStart;
|
||||
var stateLoad = load * (0.62f + initialCohesion * 0.46f) * (1.0f - edge * 0.18f) * laneLoad * (1.0f - split * 0.36f) * (0.52f + sourceCarry * 0.48f);
|
||||
var stateWet = wetness * (0.74f + initialCohesion * 0.24f - split * 0.08f) * (0.78f + sourceCarry * 0.22f);
|
||||
var seedStroke = strokes[chainStart];
|
||||
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 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 stateWet = wetness * (0.74f + initialCohesion * 0.24f - seedSplit * 0.08f);
|
||||
|
||||
for (var sample = 0; sample < sampleCount; sample++)
|
||||
for (var replayStrokeIndex = chainStart; replayStrokeIndex < strokeIndex; replayStrokeIndex++)
|
||||
{
|
||||
var t = sampleCount <= 1 ? 0.0f : sample / (float)(sampleCount - 1);
|
||||
var center = StrokePoint(stroke, t);
|
||||
var tangent = StrokeTangent(stroke, t, sampleCount);
|
||||
var normal = new Vector2(-tangent.Y, tangent.X);
|
||||
var strokeT = StrokeProgress(stroke, t);
|
||||
var taper = StrokeTaper(strokeT, stroke.EntryTaper, stroke.ExitTaper);
|
||||
var normalShape = StrokeNormalRadiusShape(taper);
|
||||
var tangentShape = StrokeTangentRadiusShape(taper);
|
||||
var pressureShape = StrokePressureShape(strokeT, stroke.EntryTaper, stroke.ExitTaper);
|
||||
var gesturePressure = StrokeGesturePressureShape(stroke, t, sampleCount);
|
||||
var gestureWidth = StrokeGestureWidthShape(stroke, t, sampleCount);
|
||||
var localPressure = pressure * taper * pressureShape * gesturePressure;
|
||||
var cohesion = LaneCohesion(edge, split, stateWet, localPressure);
|
||||
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 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.04f + bend * 0.32f + gripHeight * 0.10f + friction * localPressure * 0.16f + edge * 0.08f);
|
||||
var desiredTip = center + normal * offset - tangent * lag;
|
||||
var slip = desiredTip - tip;
|
||||
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);
|
||||
|
||||
var velocity = slip.Length() * frame.PhysicsHz / MathF.Max(radius, 0.001f);
|
||||
var tension = Saturate(MathF.Abs(targetOffset - offset) / MathF.Max(localNormalRadius, 0.001f) * 0.38f + velocity * 0.018f + drag * 0.46f);
|
||||
var separation = Saturate(edge * 0.18f + tension * (0.24f + split * 0.18f) + velocity * 0.008f - stateWet * (0.12f + cohesion * 0.10f));
|
||||
var adhesion = Saturate(stateWet * (0.44f + cohesion * 0.28f + localPressure * 0.20f) - separation * 0.16f - tension * 0.07f);
|
||||
var deposition = contact * stateLoad * stateWet * Saturate(0.10f + drag * 0.72f + velocity * 0.010f) * (0.74f + separation * 0.18f + cohesion * 0.26f);
|
||||
stateLoad = MathF.Max(0.0f, stateLoad - deposition * (0.032f + localPressure * 0.020f - cohesion * 0.008f));
|
||||
stateWet = MathF.Max(0.0f, stateWet - deposition * 0.010f);
|
||||
|
||||
var index = ((strokeIndex * tuftCount) + tuft) * sampleCount + sample;
|
||||
var pigmentSurvival = 0.74f + cohesion * 0.36f - split * 0.08f;
|
||||
var joinBlend = SegmentJoinBlend(stroke, t);
|
||||
var localPigment = Saturate((deposition * (7.5f + contact * 2.5f) + contact * stateLoad * stateWet * 0.24f + adhesion * contact * 0.10f) * pigmentSurvival * stroke.PigmentScale * joinBlend);
|
||||
trace[index] = Saturate((contact * (0.30f + stateLoad * 0.42f + adhesion * 0.20f) + deposition * 1.8f) * joinBlend);
|
||||
canvas[index] = localPigment;
|
||||
tips[index] = new Vector4(
|
||||
tip.X,
|
||||
tip.Y,
|
||||
localNormalRadius * (0.70f + localPressure * 0.22f + splay * 0.24f),
|
||||
localTangentRadius * (0.84f + drag * 0.34f + bend * 0.18f));
|
||||
SimulateTuftSegment(strokes[replayStrokeIndex], replayStrokeIndex, chainStart, tuft, sampleCount, tuftCount, frame.PhysicsHz, frame.Pressure, frame.BrushRadius, wetness, load, splay, bend, friction, restOffset, edge, ref offset, ref tip, ref stateLoad, ref stateWet, Span<float>.Empty, Span<float>.Empty, Span<Vector4>.Empty, writeOutput: false);
|
||||
}
|
||||
|
||||
SimulateTuftSegment(stroke, strokeIndex, chainStart, tuft, sampleCount, tuftCount, frame.PhysicsHz, frame.Pressure, frame.BrushRadius, wetness, load, splay, bend, friction, restOffset, edge, ref offset, ref tip, ref stateLoad, ref stateWet, trace, canvas, tips, writeOutput: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SimulateTuftSegment(
|
||||
AquariumBokushoBrushStroke stroke,
|
||||
int strokeIndex,
|
||||
int laneKey,
|
||||
int tuft,
|
||||
int sampleCount,
|
||||
int tuftCount,
|
||||
float physicsHz,
|
||||
float framePressure,
|
||||
float frameBrushRadius,
|
||||
float wetness,
|
||||
float load,
|
||||
float splay,
|
||||
float bend,
|
||||
float friction,
|
||||
float restOffset,
|
||||
float edge,
|
||||
ref float offset,
|
||||
ref Vector2 tip,
|
||||
ref float stateLoad,
|
||||
ref float stateWet,
|
||||
Span<float> trace,
|
||||
Span<float> canvas,
|
||||
Span<Vector4> tips,
|
||||
bool writeOutput)
|
||||
{
|
||||
var pressure = Saturate(framePressure * stroke.PressureScale * 0.5f) * 2.0f;
|
||||
var radius = MathF.Max(frameBrushRadius * stroke.RadiusScale, 0.0001f);
|
||||
var normalRadius = MathF.Max(radius * stroke.NormalScale, 0.0001f);
|
||||
var tangentRadius = MathF.Max(radius * stroke.TangentScale, 0.0001f);
|
||||
var split = Saturate((0.20f - LaneHash(laneKey, tuft, 53)) * 4.0f) * Saturate((edge - 0.18f) * 1.7f) * stroke.SplitScale;
|
||||
for (var sample = 0; sample < sampleCount; sample++)
|
||||
{
|
||||
var t = sampleCount <= 1 ? 0.0f : sample / (float)(sampleCount - 1);
|
||||
var center = StrokePoint(stroke, t);
|
||||
var tangent = StrokeTangent(stroke, t, sampleCount);
|
||||
var normal = new Vector2(-tangent.Y, tangent.X);
|
||||
var strokeT = StrokeProgress(stroke, t);
|
||||
var taper = StrokeTaper(strokeT, stroke.EntryTaper, stroke.ExitTaper);
|
||||
var normalShape = StrokeNormalRadiusShape(taper);
|
||||
var tangentShape = StrokeTangentRadiusShape(taper);
|
||||
var pressureShape = StrokePressureShape(strokeT, stroke.EntryTaper, stroke.ExitTaper);
|
||||
var gesturePressure = StrokeGesturePressureShape(stroke, t, sampleCount);
|
||||
var gestureWidth = StrokeGestureWidthShape(stroke, t, sampleCount);
|
||||
var localPressure = pressure * taper * pressureShape * gesturePressure;
|
||||
var cohesion = LaneCohesion(edge, split, stateWet, localPressure);
|
||||
var poseSpread = Saturate(0.92f + MathF.Abs(stroke.ShaftTilt) * 0.22f + stroke.Compliance * 0.10f - stroke.GripHeight * 0.04f);
|
||||
var localNormalRadius = MathF.Max(normalRadius * normalShape * gestureWidth * poseSpread, 0.0001f);
|
||||
var localTangentRadius = MathF.Max(tangentRadius * tangentShape * (0.86f + gestureWidth * 0.08f + stroke.GripHeight * 0.10f), 0.0001f);
|
||||
var turn = MathF.Sin(t * MathF.Tau + strokeIndex * 0.37f);
|
||||
var rotatedRest = restOffset + stroke.ShaftRotation * 0.10f * (1.0f - edge);
|
||||
var targetOffset = rotatedRest * localNormalRadius * (0.38f + splay * 0.52f + localPressure * 0.08f - wetness * 0.10f) + (turn + stroke.ShaftRotation * 0.22f) * localNormalRadius * 0.14f * (1.0f - edge);
|
||||
var recovery = Saturate(0.06f + stateWet * 0.10f + localPressure * 0.07f + (1.0f - edge) * 0.06f + stroke.Compliance * 0.07f);
|
||||
offset = Lerp(offset, targetOffset, recovery);
|
||||
|
||||
var lag = localTangentRadius * (0.04f + bend * 0.32f + stroke.GripHeight * 0.10f + friction * localPressure * 0.16f + edge * 0.08f);
|
||||
var desiredTip = center + normal * offset - tangent * lag;
|
||||
var slip = desiredTip - tip;
|
||||
var poseContact = 0.90f + stroke.Compliance * 0.10f + (1.0f - Saturate(stroke.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);
|
||||
|
||||
var velocity = slip.Length() * physicsHz / MathF.Max(radius, 0.001f);
|
||||
var tension = Saturate(MathF.Abs(targetOffset - offset) / MathF.Max(localNormalRadius, 0.001f) * 0.38f + velocity * 0.018f + drag * 0.46f);
|
||||
var separation = Saturate(edge * 0.18f + tension * (0.24f + split * 0.18f) + velocity * 0.008f - stateWet * (0.12f + cohesion * 0.10f));
|
||||
var adhesion = Saturate(stateWet * (0.44f + cohesion * 0.28f + localPressure * 0.20f) - separation * 0.16f - tension * 0.07f);
|
||||
var deposition = contact * stateLoad * stateWet * Saturate(0.10f + drag * 0.72f + velocity * 0.010f) * (0.74f + separation * 0.18f + cohesion * 0.26f);
|
||||
stateLoad = MathF.Max(0.0f, stateLoad - deposition * (0.032f + localPressure * 0.020f - cohesion * 0.008f));
|
||||
stateWet = MathF.Max(0.0f, stateWet - deposition * 0.010f);
|
||||
|
||||
if (writeOutput)
|
||||
{
|
||||
var index = ((strokeIndex * tuftCount) + tuft) * sampleCount + sample;
|
||||
var pigmentSurvival = 0.74f + cohesion * 0.36f - split * 0.08f;
|
||||
var joinBlend = SegmentJoinBlend(stroke, t);
|
||||
canvas[index] = Saturate((deposition * (7.5f + contact * 2.5f) + contact * stateLoad * stateWet * 0.24f + adhesion * contact * 0.10f) * pigmentSurvival * stroke.PigmentScale * joinBlend);
|
||||
trace[index] = Saturate((contact * (0.30f + stateLoad * 0.42f + adhesion * 0.20f) + deposition * 1.8f) * joinBlend);
|
||||
tips[index] = new Vector4(
|
||||
tip.X,
|
||||
tip.Y,
|
||||
localNormalRadius * (0.70f + localPressure * 0.22f + splay * 0.24f),
|
||||
localTangentRadius * (0.84f + drag * 0.34f + bend * 0.18f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,49 +172,30 @@ uint StrokeChainStart(uint strokeIndex)
|
|||
return chainStart;
|
||||
}
|
||||
|
||||
[numthreads(128, 1, 1)]
|
||||
void D3D12BokushoBrushCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
void SimulateBokushoTuftSegment(
|
||||
BokushoBrushStroke stroke,
|
||||
uint outputStrokeIndex,
|
||||
uint laneKey,
|
||||
uint tuft,
|
||||
uint sampleCount,
|
||||
uint tuftCount,
|
||||
float restOffset,
|
||||
float edge,
|
||||
inout float offset,
|
||||
inout float2 tip,
|
||||
inout float stateLoad,
|
||||
inout float stateWet,
|
||||
bool writeOutput)
|
||||
{
|
||||
uint sampleCount = max((uint)round(brushShape.x), 2u);
|
||||
uint tuftCount = max((uint)round(brushShape.y), 1u);
|
||||
uint strokeCount = max((uint)round(brushShape.w), 1u);
|
||||
uint globalIndex = dispatchThreadId.x;
|
||||
uint strokeIndex = globalIndex / tuftCount;
|
||||
uint tuft = globalIndex - strokeIndex * tuftCount;
|
||||
if (strokeIndex >= strokeCount || tuft >= tuftCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BokushoBrushStroke stroke = BokushoBrushStrokes[strokeIndex];
|
||||
uint chainStart = StrokeChainStart(strokeIndex);
|
||||
float strokeStart = saturate(stroke.p0.z);
|
||||
float laneT = tuftCount <= 1u ? 0.5 : (float)tuft / (float)(tuftCount - 1u);
|
||||
float restOffset = laneT * 2.0 - 1.0;
|
||||
float edge = abs(restOffset);
|
||||
float laneHash = LaneHash(chainStart, tuft, 17u);
|
||||
float laneLoad = 0.76 + laneHash * 0.34;
|
||||
float split = saturate((0.20 - LaneHash(chainStart, tuft, 53u)) * 4.0) * saturate((edge - 0.18) * 1.7) * stroke.dynamics.w;
|
||||
float pressure = saturate(brushMaterial.y * stroke.profile.y * 0.5) * 2.0;
|
||||
float wetness = saturate(brushMaterial.w / 1.6);
|
||||
float initialCohesion = LaneCohesion(edge, split, wetness, pressure);
|
||||
float load = saturate(brushMaterial.z / 2.0);
|
||||
float splay = saturate(brushDynamics.x / 2.0);
|
||||
float bend = saturate(brushDynamics.y / 2.4);
|
||||
float friction = saturate(brushDynamics.z);
|
||||
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 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 sourceCarry = 1.0 - strokeStart;
|
||||
float stateLoad = load * (0.62 + initialCohesion * 0.46) * (1.0 - edge * 0.18) * laneLoad * (1.0 - split * 0.36) * (0.52 + sourceCarry * 0.48);
|
||||
float stateWet = wetness * (0.74 + initialCohesion * 0.24 - split * 0.08) * (0.78 + sourceCarry * 0.22);
|
||||
float split = saturate((0.20 - LaneHash(laneKey, tuft, 53u)) * 4.0) * saturate((edge - 0.18) * 1.7) * stroke.dynamics.w;
|
||||
|
||||
[loop]
|
||||
for (uint sample = 0u; sample < sampleCount; sample += 1u)
|
||||
|
|
@ -231,19 +212,19 @@ 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 poseSpread = saturate(0.92 + abs(poseTilt) * 0.22 + compliance * 0.10 - gripHeight * 0.04);
|
||||
float poseSpread = saturate(0.92 + abs(stroke.pose.x) * 0.22 + stroke.pose.w * 0.10 - stroke.pose.z * 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 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);
|
||||
float localTangentRadius = max(tangentRadius * tangentShape * (0.86 + gestureWidth * 0.08 + stroke.pose.z * 0.10), 0.0001);
|
||||
float turn = sin(t * 6.28318530718 + (float)outputStrokeIndex * 0.37);
|
||||
float rotatedRest = restOffset + stroke.pose.y * 0.10 * (1.0 - edge);
|
||||
float targetOffset = rotatedRest * localNormalRadius * (0.38 + splay * 0.52 + localPressure * 0.08 - wetness * 0.10) + (turn + stroke.pose.y * 0.22) * localNormalRadius * 0.14 * (1.0 - edge);
|
||||
float recovery = saturate(0.06 + stateWet * 0.10 + localPressure * 0.07 + (1.0 - edge) * 0.06 + stroke.pose.w * 0.07);
|
||||
offset = cultmath_lerp(offset, targetOffset, recovery);
|
||||
|
||||
float lag = localTangentRadius * (0.04 + bend * 0.32 + gripHeight * 0.10 + friction * localPressure * 0.16 + edge * 0.08);
|
||||
float lag = localTangentRadius * (0.04 + bend * 0.32 + stroke.pose.z * 0.10 + friction * localPressure * 0.16 + edge * 0.08);
|
||||
float2 desiredTip = center + normal * offset - tangent * lag;
|
||||
float2 slip = desiredTip - tip;
|
||||
float poseContact = 0.90 + compliance * 0.10 + (1.0 - saturate(gripHeight / 2.4)) * 0.10;
|
||||
float poseContact = 0.90 + stroke.pose.w * 0.10 + (1.0 - saturate(stroke.pose.z / 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);
|
||||
|
|
@ -256,13 +237,61 @@ void D3D12BokushoBrushCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|||
stateLoad = max(0.0, stateLoad - deposition * (0.032 + localPressure * 0.020 - cohesion * 0.008));
|
||||
stateWet = max(0.0, stateWet - deposition * 0.010);
|
||||
|
||||
uint index = ((strokeIndex * tuftCount) + tuft) * sampleCount + sample;
|
||||
float pigmentSurvival = 0.74 + cohesion * 0.36 - split * 0.08;
|
||||
float joinBlend = SegmentJoinBlend(stroke, t);
|
||||
float localPigment = saturate((deposition * (7.5 + contact * 2.5) + contact * stateLoad * stateWet * 0.24 + adhesion * contact * 0.10) * pigmentSurvival * stroke.dynamics.z * joinBlend);
|
||||
float trace = saturate((contact * (0.30 + stateLoad * 0.42 + adhesion * 0.20) + deposition * 1.8) * joinBlend);
|
||||
BokushoTraceField[index] = trace;
|
||||
BokushoCanvasField[index] = localPigment;
|
||||
BokushoTipField[index] = float4(tip, localNormalRadius * (0.70 + localPressure * 0.22 + splay * 0.24), localTangentRadius * (0.84 + drag * 0.34 + bend * 0.18));
|
||||
if (writeOutput)
|
||||
{
|
||||
uint index = ((outputStrokeIndex * tuftCount) + tuft) * sampleCount + sample;
|
||||
float pigmentSurvival = 0.74 + cohesion * 0.36 - split * 0.08;
|
||||
float joinBlend = SegmentJoinBlend(stroke, t);
|
||||
float localPigment = saturate((deposition * (7.5 + contact * 2.5) + contact * stateLoad * stateWet * 0.24 + adhesion * contact * 0.10) * pigmentSurvival * stroke.dynamics.z * joinBlend);
|
||||
float trace = saturate((contact * (0.30 + stateLoad * 0.42 + adhesion * 0.20) + deposition * 1.8) * joinBlend);
|
||||
BokushoTraceField[index] = trace;
|
||||
BokushoCanvasField[index] = localPigment;
|
||||
BokushoTipField[index] = float4(tip, localNormalRadius * (0.70 + localPressure * 0.22 + splay * 0.24), localTangentRadius * (0.84 + drag * 0.34 + bend * 0.18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[numthreads(128, 1, 1)]
|
||||
void D3D12BokushoBrushCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint sampleCount = max((uint)round(brushShape.x), 2u);
|
||||
uint tuftCount = max((uint)round(brushShape.y), 1u);
|
||||
uint strokeCount = max((uint)round(brushShape.w), 1u);
|
||||
uint globalIndex = dispatchThreadId.x;
|
||||
uint strokeIndex = globalIndex / tuftCount;
|
||||
uint tuft = globalIndex - strokeIndex * tuftCount;
|
||||
if (strokeIndex >= strokeCount || tuft >= tuftCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BokushoBrushStroke stroke = BokushoBrushStrokes[strokeIndex];
|
||||
uint chainStart = StrokeChainStart(strokeIndex);
|
||||
BokushoBrushStroke seedStroke = BokushoBrushStrokes[chainStart];
|
||||
float laneT = tuftCount <= 1u ? 0.5 : (float)tuft / (float)(tuftCount - 1u);
|
||||
float restOffset = laneT * 2.0 - 1.0;
|
||||
float edge = abs(restOffset);
|
||||
float laneHash = LaneHash(chainStart, tuft, 17u);
|
||||
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 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 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 stateWet = wetness * (0.74 + initialCohesion * 0.24 - seedSplit * 0.08);
|
||||
|
||||
[loop]
|
||||
for (uint replayStrokeIndex = chainStart; replayStrokeIndex < strokeIndex; replayStrokeIndex += 1u)
|
||||
{
|
||||
SimulateBokushoTuftSegment(BokushoBrushStrokes[replayStrokeIndex], replayStrokeIndex, chainStart, tuft, sampleCount, tuftCount, restOffset, edge, offset, tip, stateLoad, stateWet, false);
|
||||
}
|
||||
|
||||
SimulateBokushoTuftSegment(stroke, strokeIndex, chainStart, tuft, sampleCount, tuftCount, restOffset, edge, offset, tip, stateLoad, stateWet, true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue