Split medium temporal packet from surface identity

This commit is contained in:
Meta Vens 2026-05-09 23:44:47 +01:00
commit 2a32bcc4ef
6 changed files with 123 additions and 15 deletions

View file

@ -96,9 +96,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
private D3D12RenderTarget sceneRenderTarget;
private D3D12RenderTarget sceneMetadataRenderTarget;
private D3D12RenderTarget sceneControlRenderTarget;
private D3D12RenderTarget sceneMediumPacketRenderTarget;
private readonly D3D12RenderTarget[] historyRenderTargets = new D3D12RenderTarget[2];
private readonly D3D12RenderTarget[] historyMetadataRenderTargets = new D3D12RenderTarget[2];
private readonly D3D12RenderTarget[] historyControlRenderTargets = new D3D12RenderTarget[2];
private readonly D3D12RenderTarget[] historyMediumPacketRenderTargets = new D3D12RenderTarget[2];
private readonly D3D12RenderTarget[] bloomRenderTargets = new D3D12RenderTarget[BloomLevelCount];
private readonly D3D12RenderTarget[] bloomScratchTargets = new D3D12RenderTarget[BloomLevelCount];
private D3D12StructuredBuffer froxelPrimitiveBuffer;
@ -198,6 +200,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
sceneRenderTarget = CreateSceneRenderTarget();
sceneMetadataRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-metadata-target", "Aquarium D3D12 Scene Metadata Target");
sceneControlRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-control-target", "Aquarium D3D12 Scene Control Target");
sceneMediumPacketRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-medium-packet-target", "Aquarium D3D12 Scene Medium Packet Target");
CreateHistoryRenderTargets();
CreateBloomRenderTargets();
froxelPrimitiveBuffer = CreateViewFroxelPrimitiveBuffer();
@ -349,6 +352,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
sceneMetadataRenderTarget.CreateShaderResourceView(device, frameResources.SceneMetadataDescriptor);
frameResources.SceneControlDescriptor = frameResources.TransientShaderDescriptors.Allocate();
sceneControlRenderTarget.CreateShaderResourceView(device, frameResources.SceneControlDescriptor);
frameResources.SceneMediumPacketDescriptor = frameResources.TransientShaderDescriptors.Allocate();
sceneMediumPacketRenderTarget.CreateShaderResourceView(device, frameResources.SceneMediumPacketDescriptor);
var historyReadIndex = temporalFrameIndex & 1;
frameResources.HistoryDescriptor = frameResources.TransientShaderDescriptors.Allocate();
historyRenderTargets[historyReadIndex].CreateShaderResourceView(device, frameResources.HistoryDescriptor);
@ -356,6 +361,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
historyMetadataRenderTargets[historyReadIndex].CreateShaderResourceView(device, frameResources.HistoryMetadataDescriptor);
frameResources.HistoryControlDescriptor = frameResources.TransientShaderDescriptors.Allocate();
historyControlRenderTargets[historyReadIndex].CreateShaderResourceView(device, frameResources.HistoryControlDescriptor);
frameResources.HistoryMediumPacketDescriptor = frameResources.TransientShaderDescriptors.Allocate();
historyMediumPacketRenderTargets[historyReadIndex].CreateShaderResourceView(device, frameResources.HistoryMediumPacketDescriptor);
for (var level = 0; level < BloomLevelCount; level++)
{
frameResources.BloomDescriptors[level] = frameResources.TransientShaderDescriptors.Allocate();
@ -468,6 +475,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
sceneRenderTarget.Dispose();
sceneMetadataRenderTarget.Dispose();
sceneControlRenderTarget.Dispose();
sceneMediumPacketRenderTarget.Dispose();
mediumTransportRenderTarget.Dispose();
mediumVolumeRenderTarget.Dispose();
gridHeightRenderTarget.Dispose();
@ -632,6 +640,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
resourceRegistry.RemoveRenderTarget("scene-hdr-target");
resourceRegistry.RemoveRenderTarget("scene-metadata-target");
resourceRegistry.RemoveRenderTarget("scene-control-target");
resourceRegistry.RemoveRenderTarget("scene-medium-packet-target");
resourceRegistry.RemoveRenderTarget("medium-transport-target");
resourceRegistry.RemoveRenderTarget("medium-event-target");
resourceRegistry.RemoveRenderTarget("medium-volume-target");
@ -642,6 +651,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
sceneRenderTarget.Dispose();
sceneMetadataRenderTarget.Dispose();
sceneControlRenderTarget.Dispose();
sceneMediumPacketRenderTarget.Dispose();
mediumTransportRenderTarget.Dispose();
mediumVolumeRenderTarget.Dispose();
gridHeightRenderTarget.Dispose();
@ -672,6 +682,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
sceneRenderTarget = CreateSceneRenderTarget();
sceneMetadataRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-metadata-target", "Aquarium D3D12 Scene Metadata Target");
sceneControlRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-control-target", "Aquarium D3D12 Scene Control Target");
sceneMediumPacketRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-medium-packet-target", "Aquarium D3D12 Scene Medium Packet Target");
CreateHistoryRenderTargets();
CreateBloomRenderTargets();
viewport = new Viewport(0.0f, 0.0f, width, height);
@ -729,6 +740,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
historyRenderTargets[index] = CreateSceneAuxiliaryRenderTarget($"history-{index}", $"Aquarium D3D12 History {index}");
historyMetadataRenderTargets[index] = CreateSceneAuxiliaryRenderTarget($"history-metadata-{index}", $"Aquarium D3D12 History Metadata {index}");
historyControlRenderTargets[index] = CreateSceneAuxiliaryRenderTarget($"history-control-{index}", $"Aquarium D3D12 History Control {index}");
historyMediumPacketRenderTargets[index] = CreateSceneAuxiliaryRenderTarget($"history-medium-packet-{index}", $"Aquarium D3D12 History Medium Packet {index}");
}
}
@ -739,6 +751,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
resourceRegistry.RemoveRenderTarget($"history-{index}");
resourceRegistry.RemoveRenderTarget($"history-metadata-{index}");
resourceRegistry.RemoveRenderTarget($"history-control-{index}");
resourceRegistry.RemoveRenderTarget($"history-medium-packet-{index}");
}
}
@ -749,6 +762,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
historyRenderTargets[index]?.Dispose();
historyMetadataRenderTargets[index]?.Dispose();
historyControlRenderTargets[index]?.Dispose();
historyMediumPacketRenderTargets[index]?.Dispose();
}
}
@ -878,9 +892,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
sceneRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget);
sceneMetadataRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget);
sceneControlRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget);
sceneMediumPacketRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget);
context.CommandList.ClearRenderTargetView(sceneRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
context.CommandList.ClearRenderTargetView(sceneMetadataRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
context.CommandList.ClearRenderTargetView(sceneControlRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
context.CommandList.ClearRenderTargetView(sceneMediumPacketRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
context.CommandList.SetDescriptorHeaps(frameResources.TransientShaderDescriptors.Heap);
context.CommandList.SetPipelineState(scenePipelineState!);
context.CommandList.SetGraphicsRootSignature(fullscreenRootSignature);
@ -897,6 +913,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
sceneRenderTarget.RenderTargetView.Cpu,
sceneMetadataRenderTarget.RenderTargetView.Cpu,
sceneControlRenderTarget.RenderTargetView.Cpu,
sceneMediumPacketRenderTarget.RenderTargetView.Cpu,
],
null);
context.CommandList.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
@ -1005,15 +1022,19 @@ public sealed class D3D12Renderer : IAquariumRenderer
sceneRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
sceneMetadataRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
sceneControlRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
sceneMediumPacketRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
historyRenderTargets[historyReadIndex].Transition(context.CommandList, ResourceStates.PixelShaderResource);
historyMetadataRenderTargets[historyReadIndex].Transition(context.CommandList, ResourceStates.PixelShaderResource);
historyControlRenderTargets[historyReadIndex].Transition(context.CommandList, ResourceStates.PixelShaderResource);
historyMediumPacketRenderTargets[historyReadIndex].Transition(context.CommandList, ResourceStates.PixelShaderResource);
historyRenderTargets[historyWriteIndex].Transition(context.CommandList, ResourceStates.RenderTarget);
historyMetadataRenderTargets[historyWriteIndex].Transition(context.CommandList, ResourceStates.RenderTarget);
historyControlRenderTargets[historyWriteIndex].Transition(context.CommandList, ResourceStates.RenderTarget);
historyMediumPacketRenderTargets[historyWriteIndex].Transition(context.CommandList, ResourceStates.RenderTarget);
context.CommandList.ClearRenderTargetView(historyRenderTargets[historyWriteIndex].RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
context.CommandList.ClearRenderTargetView(historyMetadataRenderTargets[historyWriteIndex].RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
context.CommandList.ClearRenderTargetView(historyControlRenderTargets[historyWriteIndex].RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
context.CommandList.ClearRenderTargetView(historyMediumPacketRenderTargets[historyWriteIndex].RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
context.BackBuffer.Transition(context.CommandList, ResourceStates.RenderTarget);
context.CommandList.SetDescriptorHeaps(frameResources.TransientShaderDescriptors.Heap);
@ -1028,6 +1049,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
context.CommandList.SetGraphicsRootDescriptorTable(9, frameResources.HistoryDescriptor.Gpu);
context.CommandList.SetGraphicsRootDescriptorTable(10, frameResources.HistoryMetadataDescriptor.Gpu);
context.CommandList.SetGraphicsRootDescriptorTable(11, frameResources.HistoryControlDescriptor.Gpu);
context.CommandList.SetGraphicsRootDescriptorTable(13, frameResources.SceneMediumPacketDescriptor.Gpu);
context.CommandList.SetGraphicsRootDescriptorTable(14, frameResources.HistoryMediumPacketDescriptor.Gpu);
context.CommandList.RSSetViewports(viewport);
context.CommandList.RSSetScissorRects(scissorRect);
@ -1037,6 +1060,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
historyRenderTargets[historyWriteIndex].RenderTargetView.Cpu,
historyMetadataRenderTargets[historyWriteIndex].RenderTargetView.Cpu,
historyControlRenderTargets[historyWriteIndex].RenderTargetView.Cpu,
historyMediumPacketRenderTargets[historyWriteIndex].RenderTargetView.Cpu,
],
null);
context.CommandList.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
@ -1656,7 +1680,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
{
if (!PipelinesReady && !pipelineBuildInProgressReported)
{
Console.WriteLine("D3D12 shader pipeline build still running; presenting loading frame.");
Console.WriteLine("D3D12 shader pipeline build still running; waiting behind startup splash.");
pipelineBuildInProgressReported = true;
}
@ -1866,6 +1890,18 @@ public sealed class D3D12Renderer : IAquariumRenderer
8,
0,
D3D12.DescriptorRangeOffsetAppend);
var currentMediumPacketRange = new DescriptorRange(
DescriptorRangeType.ShaderResourceView,
1,
16,
0,
D3D12.DescriptorRangeOffsetAppend);
var historyMediumPacketRange = new DescriptorRange(
DescriptorRangeType.ShaderResourceView,
1,
17,
0,
D3D12.DescriptorRangeOffsetAppend);
var ditherRange = new DescriptorRange(
DescriptorRangeType.ShaderResourceView,
1,
@ -1887,6 +1923,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
new RootParameter(new RootDescriptorTable([historyMetadataRange]), ShaderVisibility.Pixel),
new RootParameter(new RootDescriptorTable([historyControlRange]), ShaderVisibility.Pixel),
new RootParameter(new RootDescriptorTable([ditherRange]), ShaderVisibility.Pixel),
new RootParameter(new RootDescriptorTable([currentMediumPacketRange]), ShaderVisibility.Pixel),
new RootParameter(new RootDescriptorTable([historyMediumPacketRange]), ShaderVisibility.Pixel),
};
var staticSamplers = new[]
{
@ -1930,7 +1968,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
private ID3D12PipelineState CreateScenePipelineState(string path)
{
return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12ScenePS", [SceneHdrFormat, SceneHdrFormat, SceneHdrFormat]);
return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12ScenePS", [SceneHdrFormat, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat]);
}
private ID3D12PipelineState CreateMediumVolumePipelineState(string path)
@ -1973,7 +2011,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
path,
"FullscreenTriangleVS",
"D3D12ResolvePS",
[Format.B8G8R8A8_UNorm, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat]);
[Format.B8G8R8A8_UNorm, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat]);
}
private ID3D12PipelineState CreateGridHeightBasePipelineState(string path)
@ -2326,12 +2364,16 @@ public sealed class D3D12Renderer : IAquariumRenderer
public D3D12DescriptorSlot SceneControlDescriptor { get; set; }
public D3D12DescriptorSlot SceneMediumPacketDescriptor { get; set; }
public D3D12DescriptorSlot HistoryDescriptor { get; set; }
public D3D12DescriptorSlot HistoryMetadataDescriptor { get; set; }
public D3D12DescriptorSlot HistoryControlDescriptor { get; set; }
public D3D12DescriptorSlot HistoryMediumPacketDescriptor { get; set; }
public D3D12DescriptorSlot[] BloomDescriptors { get; } = new D3D12DescriptorSlot[BloomLevelCount];
public D3D12DescriptorSlot[] BloomScratchDescriptors { get; } = new D3D12DescriptorSlot[BloomLevelCount];

View file

@ -31,6 +31,8 @@ Texture2D<float4> historyControlTexture : register(t8);
Texture2D<float4> bloomTexture0 : register(t9);
Texture2D<float4> bloomTexture1 : register(t10);
Texture2D<float4> bloomTexture2 : register(t11);
Texture2D<float4> currentMediumPacketTexture : register(t16);
Texture2D<float4> historyMediumPacketTexture : register(t17);
SamplerState sourceSampler : register(s0);
struct FieldInstance
@ -57,6 +59,7 @@ struct ResolveOut
float4 historyColor : SV_Target1;
float4 historyMetadata : SV_Target2;
float4 historyControl : SV_Target3;
float4 historyMediumPacket : SV_Target4;
};
static const float SUN_RADIUS = 1.12;
@ -221,6 +224,16 @@ float4 loadHistoryControl(float2 uv)
return historyControlTexture.Load(int3(pixelFromUv(uv), 0));
}
float4 loadCurrentMediumPacket(float2 uv)
{
return currentMediumPacketTexture.Load(int3(pixelFromUv(uv), 0));
}
float4 loadHistoryMediumPacket(float2 uv)
{
return historyMediumPacketTexture.Load(int3(pixelFromUv(uv), 0));
}
void currentNeighborhood(float2 uv, out float3 neighborhoodMin, out float3 neighborhoodMax)
{
float2 texel = 1.0 / resolution;
@ -461,12 +474,18 @@ ResolveOut D3D12ResolvePS(VertexOut input)
float currentReactive = saturate(currentControl.x);
float currentCoverage = saturate(currentControl.y);
float currentMediumOpacity = saturate(currentControl.z);
float4 currentMediumPacket = loadCurrentMediumPacket(input.uv);
float currentMediumTravel = currentMediumPacket.y;
float currentMediumLaneOpacity = saturate(currentMediumPacket.z);
float currentMediumDensity = saturate(currentMediumPacket.w);
bool currentIsMedium = abs(currentFieldId - FIELD_ID_MEDIUM) < 0.25;
bool currentIsDistributed = currentIsMedium;
float historyWeight = 0.0;
float historyAge = 0.0;
float3 historyColor = currentColor;
float mediumHistoryWeight = 0.0;
float mediumHistoryAge = 0.0;
if (frameIndex > 0.5 && currentTravel <= farDistance && currentFieldId > 0.5)
{
float3 currentRay = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, gridCenter);
@ -521,7 +540,36 @@ ResolveOut D3D12ResolvePS(VertexOut input)
}
}
float3 resolved = lerp(currentColor, historyColor, historyWeight);
if (frameIndex > 0.5 && currentMediumLaneOpacity > 0.015 && currentMediumTravel <= farDistance)
{
float3 currentRay = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, gridCenter);
float3 mediumWorldPosition = cameraPosition + currentRay * currentMediumTravel;
float2 previousMediumUv = projectWorldToPreviousHistoryUv(mediumWorldPosition);
if (all(previousMediumUv >= 0.0) && all(previousMediumUv <= 1.0))
{
float4 previousMediumPacket = loadHistoryMediumPacket(previousMediumUv);
float previousMediumTravel = previousMediumPacket.y;
float previousMediumOpacity = saturate(previousMediumPacket.z);
float previousMediumDensity = saturate(previousMediumPacket.w);
float previousMediumAge = max(previousMediumPacket.x, 0.0);
float expectedPreviousMediumTravel = distance(previousCameraPosition, mediumWorldPosition);
float travelDelta = abs(previousMediumTravel - expectedPreviousMediumTravel);
float travelTolerance = max(0.08, expectedPreviousMediumTravel * 0.035);
float travelWeight = 1.0 - smoothstep(travelTolerance, travelTolerance * 5.0, travelDelta);
float opacityWeight = 1.0 - smoothstep(0.06, 0.42, abs(previousMediumOpacity - currentMediumLaneOpacity));
float densityWeight = 1.0 - smoothstep(0.06, 0.42, abs(previousMediumDensity - currentMediumDensity));
float mediumConfidence = smoothstep(0.0, 6.0, previousMediumAge);
float validationWeight = travelWeight * opacityWeight * densityWeight;
mediumHistoryWeight = 0.88 * lerp(0.48, 1.0, mediumConfidence) * validationWeight * smoothstep(0.015, 0.35, currentMediumLaneOpacity);
mediumHistoryAge = validationWeight > 0.01 ? min(previousMediumAge + 1.0, MAX_HISTORY_AGE) : 0.0;
float4 previous = historyTexture.SampleLevel(sourceSampler, previousMediumUv, 0.0);
historyColor = lerp(historyColor, previous.rgb, saturate(mediumHistoryWeight / max(max(historyWeight, mediumHistoryWeight), 0.0001)));
}
}
float combinedHistoryWeight = max(historyWeight, mediumHistoryWeight);
float combinedHistoryAge = max(historyAge, mediumHistoryAge);
float3 resolved = lerp(currentColor, historyColor, combinedHistoryWeight);
float3 finalColor = presentColor(resolved, input.uv);
if (renderDebugMode > 0.5 && renderDebugMode < 1.5)
{
@ -533,19 +581,19 @@ ResolveOut D3D12ResolvePS(VertexOut input)
}
else if (renderDebugMode >= 2.5 && renderDebugMode < 3.5)
{
finalColor = (historyAge / MAX_HISTORY_AGE).xxx;
finalColor = (combinedHistoryAge / MAX_HISTORY_AGE).xxx;
}
else if (renderDebugMode >= 3.5 && renderDebugMode < 4.5)
{
finalColor = historyWeight.xxx;
finalColor = combinedHistoryWeight.xxx;
}
else if (renderDebugMode >= 4.5 && renderDebugMode < 5.5)
{
finalColor = saturate(currentControl.xyz);
finalColor = saturate(float3(currentReactive, max(currentCoverage, currentMediumLaneOpacity), currentMediumOpacity));
}
else if (renderDebugMode >= 5.5 && renderDebugMode < 6.5)
{
finalColor = debugFieldIdColor(currentFieldId);
finalColor = currentMediumLaneOpacity > 0.015 ? debugFieldIdColor(FIELD_ID_MEDIUM) : debugFieldIdColor(currentFieldId);
}
else if (renderDebugMode >= 6.5 && renderDebugMode < 7.5)
{
@ -578,6 +626,7 @@ ResolveOut D3D12ResolvePS(VertexOut input)
output.finalColor = float4(finalColor, 1.0);
output.historyColor = float4(resolved, currentTravel);
output.historyMetadata = currentMetadata;
output.historyControl = float4(currentControl.xyz, historyAge);
output.historyControl = float4(currentControl.xyz, combinedHistoryAge);
output.historyMediumPacket = float4(mediumHistoryAge, currentMediumTravel, currentMediumLaneOpacity, currentMediumDensity);
return output;
}

View file

@ -65,6 +65,7 @@ struct SceneOut
float4 colorTravel : SV_Target0;
float4 metadata : SV_Target1;
float4 control : SV_Target2;
float4 mediumPacket : SV_Target3;
};
struct SolidHit
@ -85,6 +86,7 @@ struct RayMarchResult
float coverage;
float mediumOpacity;
float densityMean;
float mediumTravel;
};
VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID)
@ -508,6 +510,7 @@ RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 dir
result.coverage = 0.0;
result.mediumOpacity = 0.0;
result.densityMean = 0.0;
result.mediumTravel = farDistance + 1.0;
float transmittance = 1.0;
float3 inScattering = 0.0;
@ -554,6 +557,9 @@ RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 dir
}
integrateMediumRange(uv, 0.0, stopTravel, transmittance, inScattering, densityAccumulation, densityTravelSum, densitySum);
float mediumOpacity = saturate(1.0 - transmittance);
float mediumDensityMean = saturate(densityAccumulation / (float)MEDIUM_FROXEL_SLICE_COUNT);
float mediumTravel = densitySum > 0.0001 ? min(densityTravelSum / densitySum, stopTravel) : farDistance + 1.0;
bool drawGrid = gridHit && stochasticTransparency(screenUv, gridAlpha) > 0.0;
@ -566,20 +572,22 @@ RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 dir
result.fieldId = nearestSolid.fieldId;
result.normal = nearestSolid.normal;
result.coverage = 1.0;
result.mediumOpacity = saturate(1.0 - transmittance);
result.densityMean = saturate(densityAccumulation / (float)MEDIUM_FROXEL_SLICE_COUNT);
result.mediumOpacity = mediumOpacity;
result.densityMean = mediumDensityMean;
result.mediumTravel = mediumTravel;
}
else
{
result.color = result.color * transmittance + inScattering;
result.mediumOpacity = saturate(1.0 - transmittance);
result.densityMean = saturate(densityAccumulation / (float)MEDIUM_FROXEL_SLICE_COUNT);
result.mediumOpacity = mediumOpacity;
result.densityMean = mediumDensityMean;
result.mediumTravel = mediumTravel;
if (result.mediumOpacity > 0.015)
{
result.fieldId = FIELD_ID_MEDIUM;
result.normal = -direction;
result.coverage = saturate(max(result.mediumOpacity, result.densityMean * 4.0));
result.travel = densitySum > 0.0001 ? min(densityTravelSum / densitySum, farDistance) : farDistance;
result.travel = mediumTravel;
}
}
@ -623,5 +631,6 @@ SceneOut D3D12ScenePS(VertexOut input)
output.colorTravel = float4(result.color, min(result.travel, farDistance + 1.0));
output.metadata = float4(result.fieldId, result.normal);
output.control = float4(0.0, result.coverage, result.mediumOpacity, result.densityMean);
output.mediumPacket = float4(FIELD_ID_MEDIUM, result.mediumTravel, result.mediumOpacity, result.densityMean);
return output;
}