Add D3D12 transparent event temporal support
This commit is contained in:
parent
ca5106def2
commit
9c93fc3bc9
8 changed files with 115 additions and 18 deletions
|
|
@ -50,9 +50,11 @@ has feature parity.
|
|||
hits. Debug mode `3` shows history age and mode `4` shows history weight.
|
||||
Medium-only pixels use a density-weighted ray centroid as their temporal
|
||||
anchor and a `FIELD_ID_MEDIUM` identity, with continuity weighted by medium
|
||||
opacity and coverage rather than surface normals. Grid/transparent
|
||||
contributions therefore get history through the medium path without becoming
|
||||
fake alpha surfaces.
|
||||
opacity and coverage rather than surface normals. The medium pass also writes
|
||||
a generic transparent-event summary target for binned stochastic surfaces.
|
||||
Scene identity can now use `FIELD_ID_TRANSPARENT_EVENT` with event support and
|
||||
support-weighted travel, so Grid and future particles share temporal support
|
||||
without becoming fake alpha surfaces or opaque depth hits.
|
||||
- D3D12 debug modes `9` and `10` are direct ray-step medium previews, not
|
||||
repainted atlas views. The resolve shader samples the field instance buffer
|
||||
for the requested `MediumDebugStep`, so density/transmittance diagnostics can
|
||||
|
|
|
|||
|
|
@ -246,7 +246,12 @@ contract from opaque solids. The Grid and future particles belong to the shared
|
|||
event-stream design in `docs/stochastic-transparent-surface-pipeline.md`, not to
|
||||
the scene first-hit surface path. A ray can encounter multiple transparent
|
||||
events; stochastic coverage may choose different events across frames; temporal
|
||||
validation must compare distribution summaries instead of one canonical travel.
|
||||
validation compares distribution summaries instead of one canonical travel. In
|
||||
D3D12 the medium pass writes a transparent-event summary target beside the
|
||||
diagnostic and transport atlases. The scene pass uses event support plus
|
||||
support-weighted travel to emit `FIELD_ID_TRANSPARENT_EVENT`, and the resolve
|
||||
treats that identity as distributed medium-like history rather than a surface
|
||||
normal/depth hit.
|
||||
|
||||
The presentation path now applies an explicit exposure before display
|
||||
transformation and adds a low-gain pre-tonemap bloom/veil pyramid. The bloom
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private D3D12RenderTarget gridHeightRenderTarget;
|
||||
private D3D12RenderTarget mediumVolumeRenderTarget;
|
||||
private D3D12RenderTarget mediumTransportRenderTarget;
|
||||
private D3D12RenderTarget mediumEventRenderTarget;
|
||||
private D3D12RenderTarget sceneRenderTarget;
|
||||
private D3D12RenderTarget sceneMetadataRenderTarget;
|
||||
private D3D12RenderTarget sceneControlRenderTarget;
|
||||
|
|
@ -148,6 +149,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightRenderTarget = CreateGridHeightRenderTarget();
|
||||
mediumVolumeRenderTarget = CreateMediumVolumeRenderTarget("medium-volume-target", "Aquarium D3D12 Medium Volume Target");
|
||||
mediumTransportRenderTarget = CreateMediumVolumeRenderTarget("medium-transport-target", "Aquarium D3D12 Medium Transport Target");
|
||||
mediumEventRenderTarget = CreateMediumVolumeRenderTarget("medium-event-target", "Aquarium D3D12 Medium Transparent Event Target");
|
||||
sceneRenderTarget = CreateSceneRenderTarget();
|
||||
sceneMetadataRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-metadata-target", "Aquarium D3D12 Scene Metadata Target");
|
||||
sceneControlRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-control-target", "Aquarium D3D12 Scene Control Target");
|
||||
|
|
@ -294,6 +296,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
mediumVolumeRenderTarget.CreateShaderResourceView(device, frameResources.MediumTargetsDescriptor);
|
||||
frameResources.MediumTransportDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
mediumTransportRenderTarget.CreateShaderResourceView(device, frameResources.MediumTransportDescriptor);
|
||||
frameResources.MediumEventDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
mediumEventRenderTarget.CreateShaderResourceView(device, frameResources.MediumEventDescriptor);
|
||||
frameResources.TransparentSurfaceIndexDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
transparentSurfaceIndexBuffer.CreateShaderResourceView(device, frameResources.TransparentSurfaceIndexDescriptor);
|
||||
frameResources.TransparentSurfaceDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
|
|
@ -385,6 +389,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
sceneMetadataRenderTarget.Dispose();
|
||||
sceneControlRenderTarget.Dispose();
|
||||
mediumTransportRenderTarget.Dispose();
|
||||
mediumEventRenderTarget.Dispose();
|
||||
mediumVolumeRenderTarget.Dispose();
|
||||
gridHeightRenderTarget.Dispose();
|
||||
for (var index = 0; index < frames.Length; index++)
|
||||
|
|
@ -436,6 +441,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
resourceRegistry.RemoveRenderTarget("scene-metadata-target");
|
||||
resourceRegistry.RemoveRenderTarget("scene-control-target");
|
||||
resourceRegistry.RemoveRenderTarget("medium-transport-target");
|
||||
resourceRegistry.RemoveRenderTarget("medium-event-target");
|
||||
resourceRegistry.RemoveRenderTarget("medium-volume-target");
|
||||
resourceRegistry.RemoveRenderTarget("grid-height-target");
|
||||
DisposeBloomRenderTargets();
|
||||
|
|
@ -444,6 +450,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
sceneMetadataRenderTarget.Dispose();
|
||||
sceneControlRenderTarget.Dispose();
|
||||
mediumTransportRenderTarget.Dispose();
|
||||
mediumEventRenderTarget.Dispose();
|
||||
mediumVolumeRenderTarget.Dispose();
|
||||
gridHeightRenderTarget.Dispose();
|
||||
for (var index = 0; index < frames.Length; index++)
|
||||
|
|
@ -466,6 +473,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightRenderTarget = CreateGridHeightRenderTarget();
|
||||
mediumVolumeRenderTarget = CreateMediumVolumeRenderTarget("medium-volume-target", "Aquarium D3D12 Medium Volume Target");
|
||||
mediumTransportRenderTarget = CreateMediumVolumeRenderTarget("medium-transport-target", "Aquarium D3D12 Medium Transport Target");
|
||||
mediumEventRenderTarget = CreateMediumVolumeRenderTarget("medium-event-target", "Aquarium D3D12 Medium Transparent Event Target");
|
||||
sceneRenderTarget = CreateSceneRenderTarget();
|
||||
sceneMetadataRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-metadata-target", "Aquarium D3D12 Scene Metadata Target");
|
||||
sceneControlRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-control-target", "Aquarium D3D12 Scene Control Target");
|
||||
|
|
@ -628,6 +636,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
|
||||
mediumVolumeRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
|
||||
mediumTransportRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
|
||||
mediumEventRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
|
||||
sceneRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget);
|
||||
sceneMetadataRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget);
|
||||
sceneControlRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget);
|
||||
|
|
@ -642,6 +651,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
context.CommandList.SetGraphicsRootDescriptorTable(3, frameResources.FroxelPrimitiveDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(4, frameResources.FieldInstanceDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(5, frameResources.MediumTargetsDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(13, frameResources.MediumEventDescriptor.Gpu);
|
||||
context.CommandList.RSSetViewports(viewport);
|
||||
context.CommandList.RSSetScissorRects(scissorRect);
|
||||
context.CommandList.OMSetRenderTargets(
|
||||
|
|
@ -858,8 +868,10 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightRenderTarget.Transition(activeCommandList, ResourceStates.PixelShaderResource);
|
||||
mediumVolumeRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget);
|
||||
mediumTransportRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget);
|
||||
mediumEventRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget);
|
||||
activeCommandList.ClearRenderTargetView(mediumVolumeRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 1.0f, 0.0f, 0.0f));
|
||||
activeCommandList.ClearRenderTargetView(mediumTransportRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
activeCommandList.ClearRenderTargetView(mediumEventRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
activeCommandList.SetDescriptorHeaps(frameResources.TransientShaderDescriptors.Heap);
|
||||
activeCommandList.SetPipelineState(mediumVolumePipelineState);
|
||||
activeCommandList.SetGraphicsRootSignature(fullscreenRootSignature);
|
||||
|
|
@ -873,6 +885,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
[
|
||||
mediumVolumeRenderTarget.RenderTargetView.Cpu,
|
||||
mediumTransportRenderTarget.RenderTargetView.Cpu,
|
||||
mediumEventRenderTarget.RenderTargetView.Cpu,
|
||||
],
|
||||
null);
|
||||
activeCommandList.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
|
||||
|
|
@ -891,8 +904,10 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
{
|
||||
mediumVolumeRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget);
|
||||
mediumTransportRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget);
|
||||
mediumEventRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget);
|
||||
activeCommandList.ClearRenderTargetView(mediumVolumeRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 1.0f, 0.0f, 0.0f));
|
||||
activeCommandList.ClearRenderTargetView(mediumTransportRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
activeCommandList.ClearRenderTargetView(mediumEventRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -902,7 +917,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
private bool ShouldRenderMediumVolume()
|
||||
{
|
||||
return settings.MediumCompositeIntensity > 0.001f || RenderDebugMode == 11;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void BuildGridHeightBrushes(AquariumFrame frame)
|
||||
|
|
@ -1331,6 +1346,12 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
8,
|
||||
0,
|
||||
D3D12.DescriptorRangeOffsetAppend);
|
||||
var mediumEventRange = new DescriptorRange(
|
||||
DescriptorRangeType.ShaderResourceView,
|
||||
1,
|
||||
17,
|
||||
0,
|
||||
D3D12.DescriptorRangeOffsetAppend);
|
||||
var rootParameters = new[]
|
||||
{
|
||||
new RootParameter(new RootDescriptorTable([constantBufferRange]), ShaderVisibility.All),
|
||||
|
|
@ -1346,6 +1367,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
new RootParameter(new RootDescriptorTable([historyRange]), ShaderVisibility.Pixel),
|
||||
new RootParameter(new RootDescriptorTable([historyMetadataRange]), ShaderVisibility.Pixel),
|
||||
new RootParameter(new RootDescriptorTable([historyControlRange]), ShaderVisibility.Pixel),
|
||||
new RootParameter(new RootDescriptorTable([mediumEventRange]), ShaderVisibility.Pixel),
|
||||
};
|
||||
var staticSamplers = new[]
|
||||
{
|
||||
|
|
@ -1384,7 +1406,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
path,
|
||||
"FullscreenTriangleVS",
|
||||
"MediumVolumePS",
|
||||
[MediumVolumeFormat, MediumVolumeFormat]);
|
||||
[MediumVolumeFormat, MediumVolumeFormat, MediumVolumeFormat]);
|
||||
}
|
||||
|
||||
private ID3D12PipelineState CreateMediumDensityDebugPipelineState(string path)
|
||||
|
|
@ -1708,6 +1730,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
public D3D12DescriptorSlot MediumTransportDescriptor { get; set; }
|
||||
|
||||
public D3D12DescriptorSlot MediumEventDescriptor { get; set; }
|
||||
|
||||
public D3D12DescriptorSlot TransparentSurfaceIndexDescriptor { get; set; }
|
||||
|
||||
public D3D12DescriptorSlot TransparentSurfaceDescriptor { get; set; }
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ struct MediumVolumeOut
|
|||
{
|
||||
float4 diagnostic : SV_Target0;
|
||||
float4 transport : SV_Target1;
|
||||
float4 eventSummary : SV_Target2;
|
||||
};
|
||||
|
||||
VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID)
|
||||
|
|
@ -294,9 +295,10 @@ int froxelIndexForPosition(float3 p)
|
|||
return x + y * FROXEL_COUNT_X + z * FROXEL_COUNT_X * FROXEL_COUNT_Y;
|
||||
}
|
||||
|
||||
float transparentSurfaceDensity(float3 p, TransparentSurface surface, out float3 scattering)
|
||||
float transparentSurfaceDensity(float3 p, TransparentSurface surface, out float3 scattering, out float eventSupport)
|
||||
{
|
||||
scattering = 0.0;
|
||||
eventSupport = 0.0;
|
||||
float radius = max(surface.centerRadius.w, 0.001);
|
||||
float2 local = (p.xy - surface.centerRadius.xy) / radius;
|
||||
float radiusMask = 1.0 - smoothstep(0.92, 1.0, length(local));
|
||||
|
|
@ -318,12 +320,14 @@ float transparentSurfaceDensity(float3 p, TransparentSurface surface, out float3
|
|||
gridColor += float3(0.98, 1.0, 0.78) * contour * 0.16;
|
||||
gridColor += float3(0.36, 0.92, 1.0) * fieldLine * 0.12;
|
||||
scattering = gridColor * density * surface.colorScatter.w;
|
||||
eventSupport = saturate(density);
|
||||
return density * surface.kindDensity.y;
|
||||
}
|
||||
|
||||
float registeredTransparentSurfaceDensity(float3 p, out float3 scattering)
|
||||
float registeredTransparentSurfaceDensity(float3 p, out float3 scattering, out float eventSupport)
|
||||
{
|
||||
scattering = 0.0;
|
||||
eventSupport = 0.0;
|
||||
float density = 0.0;
|
||||
int froxelIndex = froxelIndexForPosition(p);
|
||||
if (froxelIndex < 0)
|
||||
|
|
@ -345,12 +349,15 @@ float registeredTransparentSurfaceDensity(float3 p, out float3 scattering)
|
|||
}
|
||||
|
||||
float3 surfaceScattering;
|
||||
float surfaceDensity = transparentSurfaceDensity(p, transparentSurfaces[id], surfaceScattering);
|
||||
float surfaceSupport;
|
||||
float surfaceDensity = transparentSurfaceDensity(p, transparentSurfaces[id], surfaceScattering, surfaceSupport);
|
||||
density += surfaceDensity;
|
||||
scattering += surfaceScattering;
|
||||
eventSupport += surfaceSupport;
|
||||
}
|
||||
}
|
||||
|
||||
eventSupport = saturate(eventSupport);
|
||||
return saturate(density);
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +386,8 @@ MediumVolumeOut MediumVolumePS(VertexOut input)
|
|||
density *= mediumBlend;
|
||||
scattering *= mediumBlend;
|
||||
float3 gridScattering;
|
||||
float gridDensity = registeredTransparentSurfaceDensity(p, gridScattering);
|
||||
float transparentEventSupport;
|
||||
float gridDensity = registeredTransparentSurfaceDensity(p, gridScattering, transparentEventSupport);
|
||||
density = saturate(density + gridDensity);
|
||||
scattering += gridScattering;
|
||||
float extinction = density * 0.16;
|
||||
|
|
@ -392,5 +400,6 @@ MediumVolumeOut MediumVolumePS(VertexOut input)
|
|||
MediumVolumeOut output;
|
||||
output.diagnostic = float4(saturate(density), saturate(transmittance), sourceDebug, 1.0);
|
||||
output.transport = float4(inScattering, saturate(transmittance));
|
||||
output.eventSummary = float4(transparentEventSupport, gridDensity, saturate(dot(gridScattering, float3(0.2126, 0.7152, 0.0722))), 1.0);
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ static const int PLANET_COUNT = 5;
|
|||
static const float FIELD_ID_GRID = 1.0;
|
||||
static const float FIELD_ID_SELF = 2.0;
|
||||
static const float FIELD_ID_MEDIUM = 3.0;
|
||||
static const float FIELD_ID_TRANSPARENT_EVENT = 4.0;
|
||||
static const float FIELD_ID_PLANET_BASE = 10.0;
|
||||
static const float MAX_HISTORY_AGE = 32.0;
|
||||
static const int FIELD_INSTANCE_COUNT = 10;
|
||||
|
|
@ -116,6 +117,11 @@ float3 debugFieldIdColor(float fieldId)
|
|||
return float3(0.28, 0.72, 1.0);
|
||||
}
|
||||
|
||||
if (abs(fieldId - FIELD_ID_TRANSPARENT_EVENT) < 0.25)
|
||||
{
|
||||
return float3(0.20, 1.0, 0.74);
|
||||
}
|
||||
|
||||
if (fieldId >= 10.0)
|
||||
{
|
||||
float phase = frac((fieldId - 10.0) * 0.37);
|
||||
|
|
@ -463,6 +469,8 @@ ResolveOut D3D12ResolvePS(VertexOut input)
|
|||
float currentCoverage = saturate(currentControl.y);
|
||||
float currentMediumOpacity = saturate(currentControl.z);
|
||||
bool currentIsMedium = abs(currentFieldId - FIELD_ID_MEDIUM) < 0.25;
|
||||
bool currentIsTransparentEvent = abs(currentFieldId - FIELD_ID_TRANSPARENT_EVENT) < 0.25;
|
||||
bool currentIsDistributed = currentIsMedium || currentIsTransparentEvent;
|
||||
|
||||
float historyWeight = 0.0;
|
||||
float historyAge = 0.0;
|
||||
|
|
@ -491,7 +499,7 @@ ResolveOut D3D12ResolvePS(VertexOut input)
|
|||
float travelWeight = 1.0 - smoothstep(travelTolerance, travelTolerance * 4.0, travelDelta);
|
||||
float fieldWeight = abs(previousFieldId - currentFieldId) < 0.001 ? 1.0 : 0.0;
|
||||
float normalWeight = 0.0;
|
||||
if (currentIsMedium)
|
||||
if (currentIsDistributed)
|
||||
{
|
||||
normalWeight = 1.0;
|
||||
}
|
||||
|
|
@ -503,9 +511,9 @@ ResolveOut D3D12ResolvePS(VertexOut input)
|
|||
float3 neighborhoodMin;
|
||||
float3 neighborhoodMax;
|
||||
currentNeighborhood(input.uv, neighborhoodMin, neighborhoodMax);
|
||||
float3 clampedHistory = currentIsMedium ? previous.rgb : clamp(previous.rgb, neighborhoodMin, neighborhoodMax);
|
||||
float3 clampedHistory = currentIsDistributed ? previous.rgb : clamp(previous.rgb, neighborhoodMin, neighborhoodMax);
|
||||
float colorDelta = length(clampedHistory - currentColor);
|
||||
float colorWeight = currentIsMedium ? 1.0 - smoothstep(0.35, 1.6, colorDelta) : 1.0 - smoothstep(0.18, 1.2, colorDelta);
|
||||
float colorWeight = currentIsDistributed ? 1.0 - smoothstep(0.35, 1.6, colorDelta) : 1.0 - smoothstep(0.18, 1.2, colorDelta);
|
||||
float reactiveWeight = 1.0 - currentReactive;
|
||||
float coverageWeight = smoothstep(0.02, 0.55, currentCoverage);
|
||||
float coverageContinuityWeight = 1.0 - smoothstep(0.10, 0.50, abs(previousCoverage - currentCoverage));
|
||||
|
|
@ -514,8 +522,8 @@ ResolveOut D3D12ResolvePS(VertexOut input)
|
|||
float validationWeight = travelWeight * colorWeight * fieldWeight * normalWeight * reactiveWeight * coverageWeight * coverageContinuityWeight * mediumContinuityWeight;
|
||||
|
||||
historyColor = clampedHistory;
|
||||
float maxHistoryWeight = currentIsMedium ? 0.88 : 0.82;
|
||||
float freshHistoryScale = currentIsMedium ? 0.48 : 0.35;
|
||||
float maxHistoryWeight = currentIsTransparentEvent ? 0.90 : currentIsMedium ? 0.88 : 0.82;
|
||||
float freshHistoryScale = currentIsDistributed ? 0.48 : 0.35;
|
||||
historyWeight = maxHistoryWeight * lerp(freshHistoryScale, 1.0, historyConfidence) * validationWeight;
|
||||
historyAge = validationWeight > 0.01 ? min(previousHistoryAge + 1.0, MAX_HISTORY_AGE) : 0.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ cbuffer AquariumFrame : register(b0)
|
|||
Texture2D<float4> gridHeightTexture : register(t0);
|
||||
Texture2D<float4> mediumVolumeTexture : register(t13);
|
||||
Texture2D<float4> mediumTransportTexture : register(t14);
|
||||
Texture2D<float4> mediumEventTexture : register(t17);
|
||||
SamplerState gridSampler : register(s0);
|
||||
|
||||
static const int PLANET_COUNT = 5;
|
||||
|
|
@ -32,6 +33,7 @@ static const float SUN_RADIUS = 1.12;
|
|||
static const float FIELD_ID_GRID = 1.0;
|
||||
static const float FIELD_ID_SELF = 2.0;
|
||||
static const float FIELD_ID_MEDIUM = 3.0;
|
||||
static const float FIELD_ID_TRANSPARENT_EVENT = 4.0;
|
||||
static const float FIELD_ID_PLANET_BASE = 10.0;
|
||||
static const int MEDIUM_FROXEL_ATLAS_COLUMNS = 8;
|
||||
static const int MEDIUM_FROXEL_ATLAS_ROWS = 4;
|
||||
|
|
@ -177,14 +179,26 @@ float mediumSliceTravel(int sliceIndex)
|
|||
return t * farDistance;
|
||||
}
|
||||
|
||||
void integrateMedium(float2 uv, float maxTravel, out float densityMean, out float transmittance, out float3 inScattering, out float representativeTravel)
|
||||
void integrateMedium(
|
||||
float2 uv,
|
||||
float maxTravel,
|
||||
out float densityMean,
|
||||
out float transmittance,
|
||||
out float3 inScattering,
|
||||
out float representativeTravel,
|
||||
out float transparentEventSupport,
|
||||
out float transparentEventTravel)
|
||||
{
|
||||
densityMean = 0.0;
|
||||
transmittance = 1.0;
|
||||
inScattering = 0.0;
|
||||
representativeTravel = maxTravel;
|
||||
transparentEventSupport = 0.0;
|
||||
transparentEventTravel = maxTravel;
|
||||
float densityTravelSum = 0.0;
|
||||
float densitySum = 0.0;
|
||||
float eventTravelSum = 0.0;
|
||||
float eventSupportSum = 0.0;
|
||||
|
||||
[loop]
|
||||
for (int sliceIndex = 0; sliceIndex < MEDIUM_FROXEL_SLICE_COUNT; sliceIndex++)
|
||||
|
|
@ -198,18 +212,28 @@ void integrateMedium(float2 uv, float maxTravel, out float densityMean, out floa
|
|||
float2 atlasUv = mediumAtlasUv(uv, sliceIndex);
|
||||
float4 diagnostic = mediumVolumeTexture.SampleLevel(gridSampler, atlasUv, 0.0);
|
||||
float4 transport = mediumTransportTexture.SampleLevel(gridSampler, atlasUv, 0.0);
|
||||
float4 eventSummary = mediumEventTexture.SampleLevel(gridSampler, atlasUv, 0.0);
|
||||
float eventSupport = saturate(eventSummary.x);
|
||||
densityMean += diagnostic.x;
|
||||
densityTravelSum += diagnostic.x * sliceTravel;
|
||||
densitySum += diagnostic.x;
|
||||
eventTravelSum += eventSupport * sliceTravel;
|
||||
eventSupportSum += eventSupport;
|
||||
inScattering += transmittance * transport.rgb;
|
||||
transmittance *= saturate(transport.a);
|
||||
}
|
||||
|
||||
densityMean = saturate(densityMean / (float)MEDIUM_FROXEL_SLICE_COUNT);
|
||||
transparentEventSupport = saturate(eventSupportSum / (float)MEDIUM_FROXEL_SLICE_COUNT * 4.0);
|
||||
if (densitySum > 0.0001)
|
||||
{
|
||||
representativeTravel = densityTravelSum / densitySum;
|
||||
}
|
||||
|
||||
if (eventSupportSum > 0.0001)
|
||||
{
|
||||
transparentEventTravel = eventTravelSum / eventSupportSum;
|
||||
}
|
||||
}
|
||||
|
||||
float3 shadeBody(float3 p, float3 normal, int primitiveId)
|
||||
|
|
@ -269,11 +293,28 @@ SceneOut D3D12ScenePS(VertexOut input)
|
|||
float transmittance;
|
||||
float3 inScattering;
|
||||
float mediumRepresentativeTravel;
|
||||
float transparentEventSupport;
|
||||
float transparentEventTravel;
|
||||
float mediumTravel = travel <= farDistance ? travel : farDistance;
|
||||
integrateMedium(input.uv, mediumTravel, densityMean, transmittance, inScattering, mediumRepresentativeTravel);
|
||||
integrateMedium(
|
||||
input.uv,
|
||||
mediumTravel,
|
||||
densityMean,
|
||||
transmittance,
|
||||
inScattering,
|
||||
mediumRepresentativeTravel,
|
||||
transparentEventSupport,
|
||||
transparentEventTravel);
|
||||
color = color * transmittance + inScattering;
|
||||
float mediumOpacity = saturate(1.0 - transmittance);
|
||||
if (outputFieldId < 0.5 && mediumOpacity > 0.015)
|
||||
if (outputFieldId < 0.5 && transparentEventSupport > 0.010)
|
||||
{
|
||||
outputFieldId = FIELD_ID_TRANSPARENT_EVENT;
|
||||
outputNormal = -rayDirection;
|
||||
outputCoverage = transparentEventSupport;
|
||||
travel = min(transparentEventTravel, farDistance);
|
||||
}
|
||||
else if (outputFieldId < 0.5 && mediumOpacity > 0.015)
|
||||
{
|
||||
outputFieldId = FIELD_ID_MEDIUM;
|
||||
outputNormal = -rayDirection;
|
||||
|
|
|
|||
|
|
@ -83,3 +83,4 @@
|
|||
{"area":"renderer/d3d12/temporal","lesson":"D3D12 resolve now owns presentation and history output: it writes the swapchain plus ping-pong history color, metadata, and control targets. Opaque current scene hits reproject through previous camera/Grid state, remap orbiting planet hits to previous centers, and validate by field id, travel, normal, neighborhood color, coverage, and medium opacity before blending. Debug mode 3 shows history age and mode 4 history weight. Grid/transparent-specific temporal reconstruction remains pending.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","docs/d3d12-migration.md","docs/hlsl-renderer.md","state/scratch.md"],"verification":["dotnet build src\\Aquarium.Engine\\Aquarium.Engine.csproj","dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=0 exited 0",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=3 exited 0",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=4 exited 0",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=11 exited 0"],"ts":"2026-05-09"}
|
||||
{"area":"renderer/d3d12/temporal","lesson":"Medium-only D3D12 pixels now get a volumetric temporal identity instead of being excluded from history: the scene pass stores FIELD_ID_MEDIUM, coverage from medium opacity/density, and travel from a density-weighted ray centroid. Resolve treats medium history as volumetric by skipping normal rejection, relaxing color rejection, and validating continuity through coverage and medium opacity. This stabilizes binned Grid/fog contribution without turning transparent surfaces back into alpha-depth surfaces.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","docs/d3d12-migration.md","docs/hlsl-renderer.md","state/scratch.md"],"verification":["dotnet build src\\Aquarium.Engine\\Aquarium.Engine.csproj","dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=0 exited 0",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=6 exited 0",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=3 exited 0"],"ts":"2026-05-09"}
|
||||
{"area":"renderer/d3d12/debug","lesson":"D3D12 render debug modes 9 and 10 now match the D3D11 diagnostic contract: the resolve shader binds the field instance buffer and directly samples registered medium density/transmittance at the requested MediumDebugStep. These views are correctness probes independent of the froxel atlas; mode 11 remains the atlas density view.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","docs/d3d12-migration.md","docs/hlsl-renderer.md","state/scratch.md"],"verification":["dotnet build src\\Aquarium.Engine\\Aquarium.Engine.csproj","dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=9 exited 0",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=10 exited 0",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=0 exited 0"],"ts":"2026-05-09"}
|
||||
{"area":"renderer/d3d12/transparent-temporal","lesson":"D3D12 transparent stochastic surfaces now have a generic temporal event summary instead of piggybacking only on bulk medium identity. The medium pass writes a third froxel atlas target carrying transparent event support/density/radiance; the scene pass derives support-weighted travel and emits FIELD_ID_TRANSPARENT_EVENT; the resolve treats that identity as distributed medium-like history. Grid remains just the first producer of this path, not a special transparent surface exception.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","docs/d3d12-migration.md","docs/hlsl-renderer.md","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 with AQUARIUM_RENDERER=d3d12 exited 0"],"ts":"2026-05-09"}
|
||||
|
|
|
|||
|
|
@ -333,3 +333,10 @@ can start porting real passes while keeping D3D11 as the visual reference.
|
|||
implements direct ray-step registered-medium previews for modes 9 and 10.
|
||||
These are correctness probes independent of the froxel atlas; mode 11 remains
|
||||
the atlas density view.
|
||||
- D3D12 transparent event temporal pass: the medium pass now writes a third
|
||||
froxel atlas target for generic transparent-event support. The scene pass
|
||||
samples that summary, derives support-weighted event travel, and emits
|
||||
`FIELD_ID_TRANSPARENT_EVENT` for Grid/particle-class contributions. Resolve
|
||||
treats medium and transparent-event identities as distributed history, not
|
||||
opaque surfaces, so Grid is not special-cased and future stochastic billboards
|
||||
can join the same path.
|
||||
|
|
|
|||
Loading…
Reference in a new issue