Localize Bokusho DirectCompute parity drift
This commit is contained in:
parent
e189884b97
commit
03ef2cefc1
5 changed files with 72 additions and 19 deletions
|
|
@ -783,10 +783,19 @@ public static class BokushoBrushSimulation
|
|||
|
||||
public static uint EncodePageDensityContribution(float contribution)
|
||||
{
|
||||
var density = -MathF.Log(MathF.Max(1.0f - Saturate(contribution), 0.000001f));
|
||||
var density = PageOpticalDensity(contribution);
|
||||
return (uint)MathF.Floor(MathF.Min(density * PageDensityScale, PageDensityScale) + 0.5f);
|
||||
}
|
||||
|
||||
private static float PageOpticalDensity(float contribution)
|
||||
{
|
||||
var c = Saturate(contribution);
|
||||
var c2 = c * c;
|
||||
var c3 = c2 * c;
|
||||
var c4 = c2 * c2;
|
||||
return c + (c2 * 0.5f) + (c3 * (1.0f / 3.0f)) + (c4 * 0.25f);
|
||||
}
|
||||
|
||||
public static float DecodePageDensity(uint encodedDensity)
|
||||
{
|
||||
return 1.0f - MathF.Exp(-encodedDensity / PageDensityScale);
|
||||
|
|
|
|||
|
|
@ -76,8 +76,10 @@ public static class AquariumHost
|
|||
var readyFrames = 0;
|
||||
var requiredReadyFrames = ParseHeadlessReadyFrames();
|
||||
var captureFramePath = ParseCaptureFramePath(args);
|
||||
var captureBokushoCanvasPath = ParseCaptureBokushoCanvasPath(args);
|
||||
var captureBokushoDensityPath = ParseCaptureBokushoDensityPath(args);
|
||||
var capturedFrame = false;
|
||||
var capturedBokushoCanvas = false;
|
||||
var capturedBokushoDensity = false;
|
||||
IAquariumRuntime? sceneReadyRuntime = null;
|
||||
|
||||
|
|
@ -151,6 +153,16 @@ public static class AquariumHost
|
|||
capturedFrame = true;
|
||||
}
|
||||
|
||||
if (runtime.Options.Headless
|
||||
&& !capturedBokushoCanvas
|
||||
&& !string.IsNullOrWhiteSpace(captureBokushoCanvasPath)
|
||||
&& readyFrames >= requiredReadyFrames)
|
||||
{
|
||||
renderer.SaveBokushoBrushCanvasRaw(captureBokushoCanvasPath);
|
||||
Console.WriteLine($"Headless Aquarium Bokusho canvas captured: {Path.GetFullPath(captureBokushoCanvasPath)}");
|
||||
capturedBokushoCanvas = true;
|
||||
}
|
||||
|
||||
if (runtime.Options.Headless
|
||||
&& !capturedBokushoDensity
|
||||
&& !string.IsNullOrWhiteSpace(captureBokushoDensityPath)
|
||||
|
|
@ -162,11 +174,13 @@ public static class AquariumHost
|
|||
}
|
||||
|
||||
var needsFrameCapture = !string.IsNullOrWhiteSpace(captureFramePath) && !capturedFrame;
|
||||
var needsBokushoCanvasCapture = !string.IsNullOrWhiteSpace(captureBokushoCanvasPath) && !capturedBokushoCanvas;
|
||||
var needsBokushoDensityCapture = !string.IsNullOrWhiteSpace(captureBokushoDensityPath) && !capturedBokushoDensity;
|
||||
if (runtime.Options.Headless
|
||||
&& frames >= 2
|
||||
&& readyFrames >= requiredReadyFrames
|
||||
&& !needsFrameCapture
|
||||
&& !needsBokushoCanvasCapture
|
||||
&& !needsBokushoDensityCapture)
|
||||
{
|
||||
Console.WriteLine("Headless Aquarium completed requested frames.");
|
||||
|
|
@ -233,6 +247,20 @@ public static class AquariumHost
|
|||
return Environment.GetEnvironmentVariable("AQUARIUM_CAPTURE_FRAME");
|
||||
}
|
||||
|
||||
private static string? ParseCaptureBokushoCanvasPath(IReadOnlyCollection<string> args)
|
||||
{
|
||||
var values = args.ToArray();
|
||||
for (var index = 0; index < values.Length - 1; index++)
|
||||
{
|
||||
if (string.Equals(values[index], "--capture-bokusho-canvas", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return values[index + 1];
|
||||
}
|
||||
}
|
||||
|
||||
return Environment.GetEnvironmentVariable("AQUARIUM_CAPTURE_BOKUSHO_CANVAS");
|
||||
}
|
||||
|
||||
private static string? ParseCaptureBokushoDensityPath(IReadOnlyCollection<string> args)
|
||||
{
|
||||
var values = args.ToArray();
|
||||
|
|
|
|||
|
|
@ -1585,7 +1585,13 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
PngImageWriter.WriteRgba(path, width, height, rgba);
|
||||
}
|
||||
|
||||
public unsafe void SaveBokushoPageDensityRaw(string path)
|
||||
public void SaveBokushoBrushCanvasRaw(string path)
|
||||
=> SaveStructuredBufferRaw(bokushoBrushCanvasBuffer, path, "Aquarium D3D12 Bokusho Brush Canvas Readback");
|
||||
|
||||
public void SaveBokushoPageDensityRaw(string path)
|
||||
=> SaveStructuredBufferRaw(bokushoPageDensityBuffer, path, "Aquarium D3D12 Bokusho Page Density Readback");
|
||||
|
||||
private unsafe void SaveStructuredBufferRaw(D3D12StructuredBuffer buffer, string path, string readbackName)
|
||||
{
|
||||
if (!hasPresentedReadyFrame)
|
||||
{
|
||||
|
|
@ -1594,19 +1600,19 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
WaitForGpu();
|
||||
|
||||
var bufferBytes = bokushoPageDensityBuffer.SizeBytes;
|
||||
var bufferBytes = buffer.SizeBytes;
|
||||
using var readback = device.CreateCommittedResource(
|
||||
HeapType.Readback,
|
||||
ResourceDescription.Buffer((ulong)bufferBytes),
|
||||
ResourceStates.CopyDest,
|
||||
null);
|
||||
readback.Name = "Aquarium D3D12 Bokusho Page Density Readback";
|
||||
readback.Name = readbackName;
|
||||
|
||||
using var captureAllocator = device.CreateCommandAllocator(CommandListType.Direct);
|
||||
using var captureList = device.CreateCommandList<ID3D12GraphicsCommandList>(0, CommandListType.Direct, captureAllocator, null);
|
||||
bokushoPageDensityBuffer.Transition(captureList, ResourceStates.CopySource);
|
||||
captureList.CopyBufferRegion(readback, 0, bokushoPageDensityBuffer.Resource, 0, (ulong)bufferBytes);
|
||||
bokushoPageDensityBuffer.Transition(captureList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
buffer.Transition(captureList, ResourceStates.CopySource);
|
||||
captureList.CopyBufferRegion(readback, 0, buffer.Resource, 0, (ulong)bufferBytes);
|
||||
buffer.Transition(captureList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
captureList.Close();
|
||||
commandQueue.ExecuteCommandList(captureList);
|
||||
WaitForGpu();
|
||||
|
|
|
|||
|
|
@ -28,5 +28,7 @@ public interface IAquariumRenderer : IAquariumFieldResourceBroker, IDisposable
|
|||
|
||||
void SaveFramePng(string path);
|
||||
|
||||
void SaveBokushoBrushCanvasRaw(string path);
|
||||
|
||||
void SaveBokushoPageDensityRaw(string path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ float2 StrokeTangent(BokushoBrushStroke stroke, float t)
|
|||
|
||||
float StrokeTaper(float t)
|
||||
{
|
||||
float entry = smoothstep(0.0, 0.10, t);
|
||||
float exit = 1.0 - smoothstep(0.86, 1.0, t);
|
||||
float entry = cultmath_smoothstep(0.0, 0.10, t);
|
||||
float exit = 1.0 - cultmath_smoothstep(0.86, 1.0, t);
|
||||
return 0.04 + entry * exit * 0.96;
|
||||
}
|
||||
|
||||
|
|
@ -62,8 +62,8 @@ float StrokeTaper(BokushoBrushStroke stroke, float t)
|
|||
float strokeT = saturate(lerp(stroke.p0.z, max(stroke.p0.z, stroke.p0.w), t));
|
||||
float entryTaper = clamp(stroke.dynamics.x, 0.01, 0.50);
|
||||
float exitTaper = clamp(stroke.dynamics.y, 0.01, 0.50);
|
||||
float entry = smoothstep(0.0, entryTaper, strokeT);
|
||||
float exit = 1.0 - smoothstep(1.0 - exitTaper, 1.0, strokeT);
|
||||
float entry = cultmath_smoothstep(0.0, entryTaper, strokeT);
|
||||
float exit = 1.0 - cultmath_smoothstep(1.0 - exitTaper, 1.0, strokeT);
|
||||
float contact = pow(entry * exit, 1.12);
|
||||
return 0.018 + contact * 0.982;
|
||||
}
|
||||
|
|
@ -85,6 +85,16 @@ float CanvasPigment(float value)
|
|||
return 0.96 * (1.0 - exp(-max(value, 0.0) * 0.82));
|
||||
}
|
||||
|
||||
uint EncodePageDensityContribution(float contribution)
|
||||
{
|
||||
float c = saturate(contribution);
|
||||
float c2 = c * c;
|
||||
float c3 = c2 * c;
|
||||
float c4 = c2 * c2;
|
||||
float density = c + (c2 * 0.5) + (c3 * (1.0 / 3.0)) + (c4 * 0.25);
|
||||
return (uint)floor(min(density * BOKUSHO_PAGE_DENSITY_SCALE, BOKUSHO_PAGE_DENSITY_SCALE) + 0.5);
|
||||
}
|
||||
|
||||
void DepositSweptPatch(float2 previousTip, float2 tip, float normalRadius, float tangentRadius, float pigment)
|
||||
{
|
||||
float ink = saturate(pigment);
|
||||
|
|
@ -124,16 +134,14 @@ void DepositSweptPatch(float2 previousTip, float2 tip, float normalRadius, float
|
|||
float tangentDistance = dot(local, tangent) / patchTangentRadius;
|
||||
float normalDistance = dot(local, normal) / patchNormalRadius;
|
||||
float ellipse = sqrt(tangentDistance * tangentDistance + normalDistance * normalDistance);
|
||||
float coverage = smoothstep(1.0, 0.0, ellipse);
|
||||
float coverage = cultmath_smoothstep(1.0, 0.0, ellipse);
|
||||
if (coverage <= 0.0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float contribution = ink * coverage * BOKUSHO_PAGE_PATCH_TRANSFER_GAIN;
|
||||
float density = -log(max(1.0 - saturate(contribution), 0.000001));
|
||||
uint fixedDensity = (uint)round(min(density * BOKUSHO_PAGE_DENSITY_SCALE, BOKUSHO_PAGE_DENSITY_SCALE));
|
||||
InterlockedAdd(BokushoPageDensityField[(uint)(y * (int)pageSize + x)], fixedDensity);
|
||||
InterlockedAdd(BokushoPageDensityField[(uint)(y * (int)pageSize + x)], EncodePageDensityContribution(contribution));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -210,7 +218,7 @@ void SimulateBokushoTuftSegment(
|
|||
float2 normal = float2(-tangent.y, tangent.x);
|
||||
float taper = StrokeTaper(stroke, t);
|
||||
float localPressure = pressure * taper;
|
||||
float laneCore = smoothstep(0.0, 0.78, 1.0 - edge);
|
||||
float laneCore = cultmath_smoothstep(0.0, 0.78, 1.0 - edge);
|
||||
float cohesion = saturate(0.28 + stateWet * 0.44 + laneCore * 0.24 + localPressure * 0.10 - split * 0.18);
|
||||
float localNormalRadius = max(normalRadius * (0.18 + taper * 0.82) * (0.72 + splay * 0.34 + localPressure * 0.16 - cohesion * 0.08), 0.0001);
|
||||
float localTangentRadius = max(tangentRadius * (0.24 + taper * 0.76) * (0.86 + bend * 0.18), 0.0001);
|
||||
|
|
@ -236,7 +244,7 @@ void SimulateBokushoTuftSegment(
|
|||
float adhesion = saturate(stateWet * (0.36 + cohesion * 0.40) + localPressure * 0.10 - separation * 0.22);
|
||||
float dryMemory = saturate((1.0 - stateWet) * 0.62 + separation * 0.32 + velocity * 0.004);
|
||||
float fiberNoise = LaneHash(laneKey + sample * 13u, tuft, 101u);
|
||||
float continuity = 1.0 - smoothstep(0.18 + dryMemory * 0.28, 0.96, fiberNoise) * dryMemory * (0.38 + edge * 0.22);
|
||||
float continuity = 1.0 - cultmath_smoothstep(0.18 + dryMemory * 0.28, 0.96, fiberNoise) * dryMemory * (0.38 + edge * 0.22);
|
||||
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) * continuity;
|
||||
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;
|
||||
|
|
@ -293,7 +301,7 @@ void SimulateBokushoTuftSegmentToPage(
|
|||
float2 normal = float2(-tangent.y, tangent.x);
|
||||
float taper = StrokeTaper(stroke, t);
|
||||
float localPressure = pressure * taper;
|
||||
float laneCore = smoothstep(0.0, 0.78, 1.0 - edge);
|
||||
float laneCore = cultmath_smoothstep(0.0, 0.78, 1.0 - edge);
|
||||
float cohesion = saturate(0.28 + stateWet * 0.44 + laneCore * 0.24 + localPressure * 0.10 - split * 0.18);
|
||||
float localNormalRadius = max(normalRadius * (0.18 + taper * 0.82) * (0.72 + splay * 0.34 + localPressure * 0.16 - cohesion * 0.08), 0.0001);
|
||||
float localTangentRadius = max(tangentRadius * (0.24 + taper * 0.76) * (0.86 + bend * 0.18), 0.0001);
|
||||
|
|
@ -319,7 +327,7 @@ void SimulateBokushoTuftSegmentToPage(
|
|||
float adhesion = saturate(stateWet * (0.36 + cohesion * 0.40) + localPressure * 0.10 - separation * 0.22);
|
||||
float dryMemory = saturate((1.0 - stateWet) * 0.62 + separation * 0.32 + velocity * 0.004);
|
||||
float fiberNoise = LaneHash(laneKey + step * 13u, tuft, 101u);
|
||||
float continuity = 1.0 - smoothstep(0.18 + dryMemory * 0.28, 0.96, fiberNoise) * dryMemory * (0.38 + edge * 0.22);
|
||||
float continuity = 1.0 - cultmath_smoothstep(0.18 + dryMemory * 0.28, 0.96, fiberNoise) * dryMemory * (0.38 + edge * 0.22);
|
||||
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) * continuity;
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue