Jitter TubeField reservoir samples
This commit is contained in:
parent
b1bbaf0799
commit
7c6ef65f86
2 changed files with 77 additions and 29 deletions
|
|
@ -106,6 +106,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private const int RootTubeFieldRenderConstants = 1;
|
||||
private const int RootTubeFieldRenderSource = 2;
|
||||
private const int RootTubeFieldRenderRamp = 3;
|
||||
private const int RootTubeFieldRenderBlueNoise = 4;
|
||||
private static readonly DebugUi.DebugUiOption[] RenderDebugOptions =
|
||||
[
|
||||
new(0, "Final"),
|
||||
|
|
@ -2387,6 +2388,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
activeCommandList.SetPipelineState(tubeFieldRenderPipelineState);
|
||||
activeCommandList.SetGraphicsRootSignature(tubeFieldRenderRootSignature);
|
||||
activeCommandList.SetGraphicsRootDescriptorTable(RootTubeFieldRenderFrameConstants, frameResources.FrameConstantsDescriptor.Gpu);
|
||||
activeCommandList.SetGraphicsRootDescriptorTable(RootTubeFieldRenderBlueNoise, frameResources.BlueNoiseDescriptor.Gpu);
|
||||
BindPipelinePrivateGeneratedMesh(activeCommandList, generatedMesh);
|
||||
foreach (var batch in tubeFieldDrawBatches)
|
||||
{
|
||||
|
|
@ -4285,12 +4287,19 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
43,
|
||||
0,
|
||||
D3D12.DescriptorRangeOffsetAppend);
|
||||
var blueNoiseTexture = new DescriptorRange(
|
||||
DescriptorRangeType.ShaderResourceView,
|
||||
1,
|
||||
44,
|
||||
0,
|
||||
D3D12.DescriptorRangeOffsetAppend);
|
||||
var rootParameters = new[]
|
||||
{
|
||||
new RootParameter(new RootDescriptorTable([frameConstants]), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ConstantBufferView, new RootDescriptor(3, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(42, 0), ShaderVisibility.Pixel),
|
||||
new RootParameter(new RootDescriptorTable([rampTexture]), ShaderVisibility.Pixel),
|
||||
new RootParameter(new RootDescriptorTable([blueNoiseTexture]), ShaderVisibility.Pixel),
|
||||
};
|
||||
var staticSamplers = new[]
|
||||
{
|
||||
|
|
@ -4363,7 +4372,13 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
PixelShader = pixelShader,
|
||||
BlendState = blend,
|
||||
RasterizerState = RasterizerDescription.CullNone,
|
||||
DepthStencilState = DepthStencilDescription.None,
|
||||
DepthStencilState = new DepthStencilDescription
|
||||
{
|
||||
DepthEnable = true,
|
||||
DepthWriteMask = DepthWriteMask.All,
|
||||
DepthFunc = ComparisonFunction.LessEqual,
|
||||
StencilEnable = false,
|
||||
},
|
||||
SampleMask = uint.MaxValue,
|
||||
PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
|
||||
InputLayout = new InputLayoutDescription(
|
||||
|
|
@ -4380,6 +4395,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
]),
|
||||
RenderTargetFormats = [SceneHdrFormat, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat],
|
||||
SampleDescription = new SampleDescription(1, 0),
|
||||
DepthStencilFormat = SceneDepthFormat,
|
||||
};
|
||||
|
||||
try
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ cbuffer TubeFieldConstants : register(b3)
|
|||
|
||||
ByteAddressBuffer TubeFieldSamples : register(t42);
|
||||
Texture2D<float4> TubeFieldRamp : register(t43);
|
||||
Texture2D<float> TubeFieldBlueNoise : register(t44);
|
||||
SamplerState TubeFieldRampSampler : register(s0);
|
||||
RWStructuredBuffer<TubeFieldVertex> TubeFieldVertices : register(u10);
|
||||
RWStructuredBuffer<uint> TubeFieldIndices : register(u11);
|
||||
|
|
@ -347,6 +348,55 @@ void capsuleDistancePx(
|
|||
sdf = normalPxLength - radiusPx;
|
||||
}
|
||||
|
||||
float blueNoiseAt(float2 pixel, uint salt)
|
||||
{
|
||||
uint width;
|
||||
uint height;
|
||||
TubeFieldBlueNoise.GetDimensions(width, height);
|
||||
uint2 dimensions = max(uint2(width, height), uint2(1, 1));
|
||||
uint frame = (uint)frameIndex;
|
||||
uint2 offset = uint2(frame * 17u + salt * 43u, frame * 29u + salt * 71u);
|
||||
uint2 coord = (uint2(max(pixel, float2(0.0, 0.0))) + offset) % dimensions;
|
||||
return TubeFieldBlueNoise.Load(int3(coord, 0));
|
||||
}
|
||||
|
||||
void nearestTubeDistancePx(
|
||||
TubeFieldVertexOut input,
|
||||
float2 samplePx,
|
||||
out float sdf,
|
||||
out float closestT,
|
||||
out float radiusPx,
|
||||
out float2 normalPx)
|
||||
{
|
||||
capsuleDistancePx(samplePx, input.segmentStartPx, input.segmentEndPx, input.segmentRadiusPx.x, input.segmentRadiusPx.y, sdf, closestT, radiusPx, normalPx);
|
||||
|
||||
float previousSdf;
|
||||
float previousT;
|
||||
float previousRadius;
|
||||
float2 previousNormal;
|
||||
capsuleDistancePx(samplePx, input.previousPx, input.segmentStartPx, input.joinRadiusPx.x, input.segmentRadiusPx.x, previousSdf, previousT, previousRadius, previousNormal);
|
||||
if (input.segmentValidity.x > 0.5 && previousSdf < sdf)
|
||||
{
|
||||
sdf = previousSdf;
|
||||
closestT = 0.0;
|
||||
radiusPx = previousRadius;
|
||||
normalPx = previousNormal;
|
||||
}
|
||||
|
||||
float nextSdf;
|
||||
float nextT;
|
||||
float nextRadius;
|
||||
float2 nextNormal;
|
||||
capsuleDistancePx(samplePx, input.segmentEndPx, input.nextPx, input.segmentRadiusPx.y, input.joinRadiusPx.y, nextSdf, nextT, nextRadius, nextNormal);
|
||||
if (input.segmentValidity.y > 0.5 && nextSdf < sdf)
|
||||
{
|
||||
sdf = nextSdf;
|
||||
closestT = 1.0;
|
||||
radiusPx = nextRadius;
|
||||
normalPx = nextNormal;
|
||||
}
|
||||
}
|
||||
|
||||
TubeFieldVertexOut D3D12TubeFieldVS(TubeFieldVertexIn input)
|
||||
{
|
||||
float3 forward;
|
||||
|
|
@ -417,45 +467,27 @@ TubeFieldVertexOut D3D12TubeFieldVS(TubeFieldVertexIn input)
|
|||
|
||||
SceneOut D3D12TubeFieldPS(TubeFieldVertexOut input)
|
||||
{
|
||||
float2 samplePx = input.position.xy;
|
||||
float2 baseSamplePx = input.position.xy;
|
||||
float sdf;
|
||||
float closestT;
|
||||
float radiusPx;
|
||||
float2 normalPx;
|
||||
capsuleDistancePx(samplePx, input.segmentStartPx, input.segmentEndPx, input.segmentRadiusPx.x, input.segmentRadiusPx.y, sdf, closestT, radiusPx, normalPx);
|
||||
nearestTubeDistancePx(input, baseSamplePx, sdf, closestT, radiusPx, normalPx);
|
||||
|
||||
float previousSdf;
|
||||
float previousT;
|
||||
float previousRadius;
|
||||
float2 previousNormal;
|
||||
capsuleDistancePx(samplePx, input.previousPx, input.segmentStartPx, input.joinRadiusPx.x, input.segmentRadiusPx.x, previousSdf, previousT, previousRadius, previousNormal);
|
||||
if (input.segmentValidity.x > 0.5 && previousSdf < sdf)
|
||||
{
|
||||
sdf = previousSdf;
|
||||
closestT = 0.0;
|
||||
radiusPx = previousRadius;
|
||||
normalPx = previousNormal;
|
||||
}
|
||||
|
||||
float nextSdf;
|
||||
float nextT;
|
||||
float nextRadius;
|
||||
float2 nextNormal;
|
||||
capsuleDistancePx(samplePx, input.segmentEndPx, input.nextPx, input.segmentRadiusPx.y, input.joinRadiusPx.y, nextSdf, nextT, nextRadius, nextNormal);
|
||||
if (input.segmentValidity.y > 0.5 && nextSdf < sdf)
|
||||
{
|
||||
sdf = nextSdf;
|
||||
closestT = 1.0;
|
||||
radiusPx = nextRadius;
|
||||
normalPx = nextNormal;
|
||||
}
|
||||
uint jitterSalt = (uint)round(input.tubeData.w * 131.0 + input.tubeData.x * 17.0 + frameIndex * 97.0);
|
||||
float2 jitter01 = float2(
|
||||
blueNoiseAt(baseSamplePx, jitterSalt),
|
||||
blueNoiseAt(baseSamplePx + float2(37.0, 73.0), jitterSalt + 19u));
|
||||
float2 jitterPx = (jitter01 * 2.0 - 1.0) * min(1.25, max(0.25, radiusPx * 0.08));
|
||||
float2 samplePx = baseSamplePx + jitterPx;
|
||||
nearestTubeDistancePx(input, samplePx, sdf, closestT, radiusPx, normalPx);
|
||||
|
||||
float aa = max(fwidth(sdf), max(0.75, radiusPx * max(input.feather, 0.0)));
|
||||
float coverage = 1.0 - smoothstep(0.0, aa, sdf);
|
||||
float sampleX = lerp(input.tubeData.y, input.tubeData.z, closestT);
|
||||
float value = SampleCurve((uint)round(input.tubeData.x), sampleX);
|
||||
float3 rampColor = TubeFieldRamp.SampleLevel(TubeFieldRampSampler, float2(saturate(value), 0.5), 0.0).rgb;
|
||||
float3 ray = rayDirectionForPixel(samplePx, jitterPixels, cameraPosition, cameraTarget);
|
||||
float3 ray = rayDirectionForPixel(baseSamplePx, jitterPixels, cameraPosition, cameraTarget);
|
||||
float3 forward;
|
||||
float3 right;
|
||||
float3 up;
|
||||
|
|
|
|||
Loading…
Reference in a new issue