diff --git a/src/Aquarium.Engine.Contracts/GraphicsSettings.cs b/src/Aquarium.Engine.Contracts/GraphicsSettings.cs index c3d9900..e507d9b 100644 --- a/src/Aquarium.Engine.Contracts/GraphicsSettings.cs +++ b/src/Aquarium.Engine.Contracts/GraphicsSettings.cs @@ -9,7 +9,7 @@ public readonly record struct GraphicsSettings( int MediumDebugStep) { public const int MinRenderDebugMode = 0; - public const int MaxRenderDebugMode = 12; + public const int MaxRenderDebugMode = 13; public const float MinSceneExposure = 0.02f; public const float MaxSceneExposure = 1.2f; public const float MinBloomIntensity = 0.0f; diff --git a/src/Aquarium.Engine/Render/D3D11Renderer.cs b/src/Aquarium.Engine/Render/D3D11Renderer.cs index 7a2fded..a8347bc 100644 --- a/src/Aquarium.Engine/Render/D3D11Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D11Renderer.cs @@ -48,6 +48,7 @@ public sealed class D3D11Renderer : IAquariumRenderer new(10, "Medium Ray Transmittance"), new(11, "Froxel Density"), new(12, "Froxel Light"), + new(13, "Froxel Light Direction"), ]; private const float SunRadius = 1.12f; diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 9621e5e..24c29d4 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -61,6 +61,7 @@ public sealed class D3D12Renderer : IAquariumRenderer new(10, "Medium Ray Transmittance"), new(11, "Froxel Density"), new(12, "Froxel Light"), + new(13, "Froxel Light Direction"), ]; private readonly IDXGIFactory4 factory; @@ -83,6 +84,7 @@ public sealed class D3D12Renderer : IAquariumRenderer private ID3D12PipelineState? mediumLightPropagationPipelineState; private ID3D12PipelineState? mediumDensityDebugPipelineState; private ID3D12PipelineState? mediumLightDebugPipelineState; + private ID3D12PipelineState? mediumLightDirectionDebugPipelineState; private ID3D12PipelineState? bloomPrefilterPipelineState; private ID3D12PipelineState? bloomDownsamplePipelineState; private ID3D12PipelineState? bloomBlurHorizontalPipelineState; @@ -97,7 +99,9 @@ public sealed class D3D12Renderer : IAquariumRenderer private D3D12RenderTarget mediumVolumeRenderTarget; private D3D12RenderTarget mediumTransportRenderTarget; private D3D12RenderTarget mediumLightInjectionRenderTarget; + private D3D12RenderTarget mediumLightDirectionInjectionRenderTarget; private D3D12RenderTarget mediumLightRenderTarget; + private D3D12RenderTarget mediumLightDirectionRenderTarget; private D3D12RenderTarget sceneRenderTarget; private D3D12RenderTarget sceneMetadataRenderTarget; private D3D12RenderTarget sceneControlRenderTarget; @@ -213,7 +217,9 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumVolumeRenderTarget = CreateMediumVolumeRenderTarget("medium-volume-target", "Aquarium D3D12 Medium Volume Target"); mediumTransportRenderTarget = CreateMediumVolumeRenderTarget("medium-transport-target", "Aquarium D3D12 Medium Transport Target"); mediumLightInjectionRenderTarget = CreateMediumVolumeRenderTarget("medium-light-injection-target", "Aquarium D3D12 Medium Light Injection Target"); + mediumLightDirectionInjectionRenderTarget = CreateMediumVolumeRenderTarget("medium-light-direction-injection-target", "Aquarium D3D12 Medium Light Direction Injection Target"); mediumLightRenderTarget = CreateMediumVolumeRenderTarget("medium-light-target", "Aquarium D3D12 Propagated Medium Light Target"); + mediumLightDirectionRenderTarget = CreateMediumVolumeRenderTarget("medium-light-direction-target", "Aquarium D3D12 Propagated Medium Light Direction Target"); sceneRenderTarget = CreateSceneRenderTarget(); sceneMetadataRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-metadata-target", "Aquarium D3D12 Scene Metadata Target"); sceneControlRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-control-target", "Aquarium D3D12 Scene Control Target"); @@ -367,12 +373,16 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumTransportRenderTarget.CreateShaderResourceView(device, frameResources.MediumInjectionTransportDescriptor); frameResources.MediumInjectionLightDescriptor = frameResources.TransientShaderDescriptors.Allocate(); mediumLightInjectionRenderTarget.CreateShaderResourceView(device, frameResources.MediumInjectionLightDescriptor); + frameResources.MediumInjectionLightDirectionDescriptor = frameResources.TransientShaderDescriptors.Allocate(); + mediumLightDirectionInjectionRenderTarget.CreateShaderResourceView(device, frameResources.MediumInjectionLightDirectionDescriptor); frameResources.MediumTargetsDescriptor = frameResources.TransientShaderDescriptors.Allocate(); mediumVolumeRenderTarget.CreateShaderResourceView(device, frameResources.MediumTargetsDescriptor); frameResources.MediumTransportDescriptor = frameResources.TransientShaderDescriptors.Allocate(); mediumTransportRenderTarget.CreateShaderResourceView(device, frameResources.MediumTransportDescriptor); frameResources.MediumLightDescriptor = frameResources.TransientShaderDescriptors.Allocate(); mediumLightRenderTarget.CreateShaderResourceView(device, frameResources.MediumLightDescriptor); + frameResources.MediumLightDirectionDescriptor = frameResources.TransientShaderDescriptors.Allocate(); + mediumLightDirectionRenderTarget.CreateShaderResourceView(device, frameResources.MediumLightDirectionDescriptor); frameResources.SceneDescriptor = frameResources.TransientShaderDescriptors.Allocate(); sceneRenderTarget.CreateShaderResourceView(device, frameResources.SceneDescriptor); frameResources.SceneMetadataDescriptor = frameResources.TransientShaderDescriptors.Allocate(); @@ -473,6 +483,7 @@ public sealed class D3D12Renderer : IAquariumRenderer && mediumLightPropagationPipelineState is not null && mediumDensityDebugPipelineState is not null && mediumLightDebugPipelineState is not null + && mediumLightDirectionDebugPipelineState is not null && bloomPrefilterPipelineState is not null && bloomDownsamplePipelineState is not null && bloomBlurHorizontalPipelineState is not null @@ -520,7 +531,9 @@ public sealed class D3D12Renderer : IAquariumRenderer sceneMediumColorRenderTarget.Dispose(); sceneEventColorRenderTarget.Dispose(); sceneEventMetadataRenderTarget.Dispose(); + mediumLightDirectionRenderTarget.Dispose(); mediumLightRenderTarget.Dispose(); + mediumLightDirectionInjectionRenderTarget.Dispose(); mediumLightInjectionRenderTarget.Dispose(); mediumTransportRenderTarget.Dispose(); mediumVolumeRenderTarget.Dispose(); @@ -650,6 +663,8 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumDensityDebug.Name = "Aquarium D3D12 Medium Density Debug Pipeline"; var mediumLightDebug = CreateMediumLightDebugPipelineState(paths.Smoke); mediumLightDebug.Name = "Aquarium D3D12 Medium Light Debug Pipeline"; + var mediumLightDirectionDebug = CreateMediumLightDirectionDebugPipelineState(paths.Smoke); + mediumLightDirectionDebug.Name = "Aquarium D3D12 Medium Light Direction Debug Pipeline"; var bloomPrefilter = CreateBloomPrefilterPipelineState(paths.Post); bloomPrefilter.Name = "Aquarium D3D12 Bloom Prefilter Pipeline"; var bloomDownsample = CreateBloomDownsamplePipelineState(paths.Post); @@ -669,6 +684,7 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumLightPropagation, mediumDensityDebug, mediumLightDebug, + mediumLightDirectionDebug, bloomPrefilter, bloomDownsample, bloomBlurHorizontal, @@ -698,8 +714,9 @@ public sealed class D3D12Renderer : IAquariumRenderer resourceRegistry.RemoveRenderTarget("scene-event-metadata-target"); resourceRegistry.RemoveRenderTarget("medium-transport-target"); resourceRegistry.RemoveRenderTarget("medium-light-injection-target"); + resourceRegistry.RemoveRenderTarget("medium-light-direction-injection-target"); resourceRegistry.RemoveRenderTarget("medium-light-target"); - resourceRegistry.RemoveRenderTarget("medium-event-target"); + resourceRegistry.RemoveRenderTarget("medium-light-direction-target"); resourceRegistry.RemoveRenderTarget("medium-volume-target"); resourceRegistry.RemoveRenderTarget("grid-height-target"); resourceRegistry.RemoveStructuredBuffer("froxel-primitive-buffer"); @@ -712,7 +729,9 @@ public sealed class D3D12Renderer : IAquariumRenderer sceneMediumColorRenderTarget.Dispose(); sceneEventColorRenderTarget.Dispose(); sceneEventMetadataRenderTarget.Dispose(); + mediumLightDirectionRenderTarget.Dispose(); mediumLightRenderTarget.Dispose(); + mediumLightDirectionInjectionRenderTarget.Dispose(); mediumLightInjectionRenderTarget.Dispose(); mediumTransportRenderTarget.Dispose(); mediumVolumeRenderTarget.Dispose(); @@ -740,7 +759,9 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumVolumeRenderTarget = CreateMediumVolumeRenderTarget("medium-volume-target", "Aquarium D3D12 Medium Volume Target"); mediumTransportRenderTarget = CreateMediumVolumeRenderTarget("medium-transport-target", "Aquarium D3D12 Medium Transport Target"); mediumLightInjectionRenderTarget = CreateMediumVolumeRenderTarget("medium-light-injection-target", "Aquarium D3D12 Medium Light Injection Target"); + mediumLightDirectionInjectionRenderTarget = CreateMediumVolumeRenderTarget("medium-light-direction-injection-target", "Aquarium D3D12 Medium Light Direction Injection Target"); mediumLightRenderTarget = CreateMediumVolumeRenderTarget("medium-light-target", "Aquarium D3D12 Propagated Medium Light Target"); + mediumLightDirectionRenderTarget = CreateMediumVolumeRenderTarget("medium-light-direction-target", "Aquarium D3D12 Propagated Medium Light Direction Target"); froxelPrimitiveBuffer = CreateViewFroxelPrimitiveBuffer(); resourceRegistry.Add("froxel-primitive-buffer", froxelPrimitiveBuffer); sceneRenderTarget = CreateSceneRenderTarget(); @@ -922,6 +943,7 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumVolumeRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); mediumTransportRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); mediumLightRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); + mediumLightDirectionRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); sceneRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget); sceneMetadataRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget); sceneControlRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget); @@ -944,6 +966,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(21, frameResources.MediumLightDirectionDescriptor.Gpu); context.CommandList.RSSetViewports(viewport); context.CommandList.RSSetScissorRects(scissorRect); context.CommandList.OMSetRenderTargets( @@ -1042,25 +1065,34 @@ public sealed class D3D12Renderer : IAquariumRenderer { var showMediumDensity = RenderDebugMode == 11; var showMediumLight = RenderDebugMode == 12; + var showMediumLightDirection = RenderDebugMode == 13; var historyReadIndex = temporalFrameIndex & 1; var historyWriteIndex = 1 - historyReadIndex; - if (showMediumDensity || showMediumLight) + if (showMediumDensity || showMediumLight || showMediumLightDirection) { var sourceDescriptor = showMediumDensity ? frameResources.MediumTargetsDescriptor - : frameResources.MediumLightDescriptor; + : showMediumLight + ? frameResources.MediumLightDescriptor + : frameResources.MediumLightDirectionDescriptor; var pipelineState = showMediumDensity ? mediumDensityDebugPipelineState! - : mediumLightDebugPipelineState!; + : showMediumLight + ? mediumLightDebugPipelineState! + : mediumLightDirectionDebugPipelineState!; if (showMediumDensity) { mediumVolumeRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); } - else + else if (showMediumLight) { mediumLightRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); } + else + { + mediumLightDirectionRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); + } context.BackBuffer.Transition(context.CommandList, ResourceStates.RenderTarget); context.CommandList.SetDescriptorHeaps(frameResources.TransientShaderDescriptors.Heap); @@ -1205,9 +1237,11 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumVolumeRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); mediumTransportRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); mediumLightInjectionRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); + mediumLightDirectionInjectionRenderTarget.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(mediumLightInjectionRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); + activeCommandList.ClearRenderTargetView(mediumLightDirectionInjectionRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); activeCommandList.SetDescriptorHeaps(frameResources.TransientShaderDescriptors.Heap); activeCommandList.SetPipelineState(mediumVolumePipelineState!); activeCommandList.SetGraphicsRootSignature(fullscreenRootSignature); @@ -1221,6 +1255,7 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumVolumeRenderTarget.RenderTargetView.Cpu, mediumTransportRenderTarget.RenderTargetView.Cpu, mediumLightInjectionRenderTarget.RenderTargetView.Cpu, + mediumLightDirectionInjectionRenderTarget.RenderTargetView.Cpu, ], null); activeCommandList.IASetPrimitiveTopology(PrimitiveTopology.TriangleList); @@ -1243,16 +1278,25 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumVolumeRenderTarget.Transition(activeCommandList, ResourceStates.PixelShaderResource); mediumTransportRenderTarget.Transition(activeCommandList, ResourceStates.PixelShaderResource); mediumLightInjectionRenderTarget.Transition(activeCommandList, ResourceStates.PixelShaderResource); + mediumLightDirectionInjectionRenderTarget.Transition(activeCommandList, ResourceStates.PixelShaderResource); mediumLightRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); + mediumLightDirectionRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); activeCommandList.ClearRenderTargetView(mediumLightRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); + activeCommandList.ClearRenderTargetView(mediumLightDirectionRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); activeCommandList.SetDescriptorHeaps(frameResources.TransientShaderDescriptors.Heap); activeCommandList.SetPipelineState(mediumLightPropagationPipelineState!); activeCommandList.SetGraphicsRootSignature(fullscreenRootSignature); activeCommandList.SetGraphicsRootDescriptorTable(0, frameResources.FrameConstantsDescriptor.Gpu); activeCommandList.SetGraphicsRootDescriptorTable(5, frameResources.MediumInjectionTargetsDescriptor.Gpu); + activeCommandList.SetGraphicsRootDescriptorTable(21, frameResources.MediumInjectionLightDirectionDescriptor.Gpu); activeCommandList.RSSetViewports(mediumViewport); activeCommandList.RSSetScissorRects(mediumScissorRect); - activeCommandList.OMSetRenderTargets(mediumLightRenderTarget.RenderTargetView.Cpu, null); + activeCommandList.OMSetRenderTargets( + [ + mediumLightRenderTarget.RenderTargetView.Cpu, + mediumLightDirectionRenderTarget.RenderTargetView.Cpu, + ], + null); activeCommandList.IASetPrimitiveTopology(PrimitiveTopology.TriangleList); activeCommandList.DrawInstanced(3, 1, 0, 0); } @@ -1270,11 +1314,15 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumVolumeRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); mediumTransportRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); mediumLightInjectionRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); + mediumLightDirectionInjectionRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); mediumLightRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); + mediumLightDirectionRenderTarget.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(mediumLightInjectionRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); activeCommandList.ClearRenderTargetView(mediumLightRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); + activeCommandList.ClearRenderTargetView(mediumLightDirectionInjectionRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); + activeCommandList.ClearRenderTargetView(mediumLightDirectionRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); } finally { @@ -1821,10 +1869,11 @@ public sealed class D3D12Renderer : IAquariumRenderer gridHeightBrushPipelineState!, scenePipelineState!, mediumVolumePipelineState!, - mediumLightPropagationPipelineState!, - mediumDensityDebugPipelineState!, - mediumLightDebugPipelineState!, - bloomPrefilterPipelineState!, + mediumLightPropagationPipelineState!, + mediumDensityDebugPipelineState!, + mediumLightDebugPipelineState!, + mediumLightDirectionDebugPipelineState!, + bloomPrefilterPipelineState!, bloomDownsamplePipelineState!, bloomBlurHorizontalPipelineState!, bloomBlurVerticalPipelineState!, @@ -1841,6 +1890,7 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumLightPropagationPipelineState = pipelines.MediumLightPropagation; mediumDensityDebugPipelineState = pipelines.MediumDensityDebug; mediumLightDebugPipelineState = pipelines.MediumLightDebug; + mediumLightDirectionDebugPipelineState = pipelines.MediumLightDirectionDebug; bloomPrefilterPipelineState = pipelines.BloomPrefilter; bloomDownsamplePipelineState = pipelines.BloomDownsample; bloomBlurHorizontalPipelineState = pipelines.BloomBlurHorizontal; @@ -1858,6 +1908,7 @@ public sealed class D3D12Renderer : IAquariumRenderer mediumLightPropagationPipelineState = null; mediumDensityDebugPipelineState = null; mediumLightDebugPipelineState = null; + mediumLightDirectionDebugPipelineState = null; bloomPrefilterPipelineState = null; bloomDownsamplePipelineState = null; bloomBlurHorizontalPipelineState = null; @@ -2036,6 +2087,12 @@ public sealed class D3D12Renderer : IAquariumRenderer 24, 0, D3D12.DescriptorRangeOffsetAppend); + var mediumLightDirectionRange = new DescriptorRange( + DescriptorRangeType.ShaderResourceView, + 1, + 25, + 0, + D3D12.DescriptorRangeOffsetAppend); var rootParameters = new[] { new RootParameter(new RootDescriptorTable([constantBufferRange]), ShaderVisibility.All), @@ -2059,6 +2116,7 @@ public sealed class D3D12Renderer : IAquariumRenderer new RootParameter(new RootDescriptorTable([gridHeightMediumRange]), ShaderVisibility.Pixel), new RootParameter(new RootDescriptorTable([currentMediumColorRange]), ShaderVisibility.Pixel), new RootParameter(new RootDescriptorTable([historyMediumColorRange]), ShaderVisibility.Pixel), + new RootParameter(new RootDescriptorTable([mediumLightDirectionRange]), ShaderVisibility.Pixel), }; var staticSamplers = new[] { @@ -2097,12 +2155,12 @@ public sealed class D3D12Renderer : IAquariumRenderer path, "FullscreenTriangleVS", "MediumVolumePS", - [MediumVolumeFormat, MediumVolumeFormat, MediumVolumeFormat]); + [MediumVolumeFormat, MediumVolumeFormat, MediumVolumeFormat, MediumVolumeFormat]); } private ID3D12PipelineState CreateMediumLightPropagationPipelineState(string path) { - return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "MediumLightPropagatePS", MediumVolumeFormat); + return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "MediumLightPropagatePS", [MediumVolumeFormat, MediumVolumeFormat]); } private ID3D12PipelineState CreateMediumDensityDebugPipelineState(string path) @@ -2115,6 +2173,11 @@ public sealed class D3D12Renderer : IAquariumRenderer return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12MediumLightDebugPS", Format.B8G8R8A8_UNorm); } + private ID3D12PipelineState CreateMediumLightDirectionDebugPipelineState(string path) + { + return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12MediumLightDirectionDebugPS", Format.B8G8R8A8_UNorm); + } + private ID3D12PipelineState CreateBloomPrefilterPipelineState(string path) { return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12BloomPrefilterPS", SceneHdrFormat); @@ -2447,6 +2510,7 @@ public sealed class D3D12Renderer : IAquariumRenderer ID3D12PipelineState MediumLightPropagation, ID3D12PipelineState MediumDensityDebug, ID3D12PipelineState MediumLightDebug, + ID3D12PipelineState MediumLightDirectionDebug, ID3D12PipelineState BloomPrefilter, ID3D12PipelineState BloomDownsample, ID3D12PipelineState BloomBlurHorizontal, @@ -2460,6 +2524,7 @@ public sealed class D3D12Renderer : IAquariumRenderer BloomBlurHorizontal.Dispose(); BloomDownsample.Dispose(); BloomPrefilter.Dispose(); + MediumLightDirectionDebug.Dispose(); MediumLightDebug.Dispose(); MediumDensityDebug.Dispose(); MediumLightPropagation.Dispose(); @@ -2497,12 +2562,16 @@ public sealed class D3D12Renderer : IAquariumRenderer public D3D12DescriptorSlot MediumInjectionLightDescriptor { get; set; } + public D3D12DescriptorSlot MediumInjectionLightDirectionDescriptor { get; set; } + public D3D12DescriptorSlot MediumTargetsDescriptor { get; set; } public D3D12DescriptorSlot MediumTransportDescriptor { get; set; } public D3D12DescriptorSlot MediumLightDescriptor { get; set; } + public D3D12DescriptorSlot MediumLightDirectionDescriptor { get; set; } + public D3D12DescriptorSlot SceneDescriptor { get; set; } public D3D12DescriptorSlot SceneMetadataDescriptor { get; set; } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl index ee01df1..19cf53f 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl @@ -36,6 +36,7 @@ StructuredBuffer fieldInstances : register(t12); Texture2D mediumVolumeTexture : register(t13); Texture2D mediumLightTexture : register(t15); Texture2D gridHeightTexture : register(t22); +Texture2D mediumLightDirectionTexture : register(t25); SamplerState sourceSampler : register(s0); static const int FIELD_INSTANCE_COUNT = 11; @@ -60,6 +61,13 @@ struct MediumVolumeOut float4 diagnostic : SV_Target0; float4 transport : SV_Target1; float4 light : SV_Target2; + float4 lightDirection : SV_Target3; +}; + +struct MediumLightPropagationOut +{ + float4 light : SV_Target0; + float4 lightDirection : SV_Target1; }; VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID) @@ -328,9 +336,11 @@ float emissiveSurfaceTransmittance(float3 p, FieldInstance emitter) return exp(-opticalDepth); } -float3 injectedEmitterIrradiance(float3 p) +void injectedEmitterLighting(float3 p, out float3 irradiance, out float4 directionMoment) { - float3 irradiance = 0.0; + irradiance = 0.0; + float3 directionWeighted = 0.0; + float directionWeight = 0.0; [loop] for (int i = 0; i < FIELD_INSTANCE_COUNT; i++) @@ -344,13 +354,18 @@ float3 injectedEmitterIrradiance(float3 p) float emitterRadius = max(emitter.centerRadius.w, 0.001); float3 toEmitter = emitter.centerRadius.xyz - p; float emitterDistance = length(toEmitter); + float3 lightDirection = toEmitter / max(emitterDistance, 0.0001); float solidAngle = emissiveFieldSolidAngle(p, emitter); float visibility = smoothstep(emitterRadius * 0.98, emitterRadius * 1.08, emitterDistance); float transmittance = emissiveSurfaceTransmittance(p, emitter); - irradiance += emitter.colorIntensity.rgb * solidAngle * visibility * transmittance; + float3 contribution = emitter.colorIntensity.rgb * solidAngle * visibility * transmittance; + float contributionWeight = dot(contribution, float3(0.2126, 0.7152, 0.0722)); + irradiance += contribution; + directionWeighted += lightDirection * contributionWeight; + directionWeight += contributionWeight; } - return irradiance; + directionMoment = float4(directionWeighted, directionWeight); } float mediumSliceTravel(int sliceIndex) @@ -382,12 +397,17 @@ MediumVolumeOut MediumVolumePS(VertexOut input) sigmaT *= mediumBlend; sigmaS *= mediumBlend; float transmittance = exp(-sigmaT * sliceLength); - float3 injectedIrradiance = injectedEmitterIrradiance(p) * mediumBlend; + float3 injectedIrradiance; + float4 lightDirectionMoment; + injectedEmitterLighting(p, injectedIrradiance, lightDirectionMoment); + injectedIrradiance *= mediumBlend; + lightDirectionMoment *= mediumBlend; MediumVolumeOut output; output.diagnostic = float4(saturate(density), sigmaT, sigmaS, albedo); output.transport = float4(0.0, 0.0, 0.0, saturate(transmittance)); output.light = float4(injectedIrradiance, saturate(density)); + output.lightDirection = lightDirectionMoment; return output; } @@ -410,7 +430,16 @@ float3 propagatedNeighbor(int2 cell, int sliceIndex, float weight) return mediumLightTexture.SampleLevel(sourceSampler, uv, 0.0).rgb * weight * occlusion; } -float4 MediumLightPropagatePS(VertexOut input) : SV_Target0 +float4 propagatedDirectionNeighbor(int2 cell, int sliceIndex, float weight) +{ + sliceIndex = clamp(sliceIndex, 0, MEDIUM_FROXEL_SLICE_COUNT - 1); + float2 uv = atlasUvFromCell(cell, sliceIndex); + float sigmaT = mediumVolumeTexture.SampleLevel(sourceSampler, uv, 0.0).y; + float occlusion = exp(-sigmaT * 0.55); + return mediumLightDirectionTexture.SampleLevel(sourceSampler, uv, 0.0) * weight * occlusion; +} + +MediumLightPropagationOut MediumLightPropagatePS(VertexOut input) { int froxelWidth = max((int)(resolution.x / 8.0), 1); int froxelHeight = max((int)(resolution.y / 8.0), 1); @@ -424,15 +453,30 @@ float4 MediumLightPropagatePS(VertexOut input) : SV_Target0 float density = medium.x; float sigmaT = medium.y; float3 center = mediumLightTexture.SampleLevel(sourceSampler, uv, 0.0).rgb; + float4 centerDirection = mediumLightDirectionTexture.SampleLevel(sourceSampler, uv, 0.0); float3 propagated = center * 0.58; + float4 propagatedDirection = centerDirection * 0.58; propagated += propagatedNeighbor(cell + int2(1, 0), sliceIndex, 0.055); propagated += propagatedNeighbor(cell + int2(-1, 0), sliceIndex, 0.055); propagated += propagatedNeighbor(cell + int2(0, 1), sliceIndex, 0.055); propagated += propagatedNeighbor(cell + int2(0, -1), sliceIndex, 0.055); propagated += propagatedNeighbor(cell, sliceIndex + 1, 0.08); propagated += propagatedNeighbor(cell, sliceIndex - 1, 0.08); + propagatedDirection += propagatedDirectionNeighbor(cell + int2(1, 0), sliceIndex, 0.055); + propagatedDirection += propagatedDirectionNeighbor(cell + int2(-1, 0), sliceIndex, 0.055); + propagatedDirection += propagatedDirectionNeighbor(cell + int2(0, 1), sliceIndex, 0.055); + propagatedDirection += propagatedDirectionNeighbor(cell + int2(0, -1), sliceIndex, 0.055); + propagatedDirection += propagatedDirectionNeighbor(cell, sliceIndex + 1, 0.08); + propagatedDirection += propagatedDirectionNeighbor(cell, sliceIndex - 1, 0.08); float localRetention = lerp(0.72, 1.0, saturate(sigmaT * 7.0 + density * 0.35)); float3 light = max(center, propagated * localRetention); - return float4(light, saturate(density)); + float4 directionMoment = abs(centerDirection.a) > abs(propagatedDirection.a * localRetention) + ? centerDirection + : propagatedDirection * localRetention; + + MediumLightPropagationOut output; + output.light = float4(light, saturate(density)); + output.lightDirection = directionMoment; + return output; } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl index 9a408b7..32c23f0 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl @@ -27,6 +27,7 @@ StructuredBuffer froxelPrimitiveIds : register(t1); Texture2D mediumVolumeTexture : register(t13); Texture2D mediumTransportTexture : register(t14); Texture2D mediumLightTexture : register(t15); +Texture2D mediumLightDirectionTexture : register(t25); SamplerState gridSampler : register(s0); struct FieldInstance @@ -71,6 +72,7 @@ static const float GRID_ALPHA_SCALE = 0.56; static const int FIELD_INSTANCE_COUNT = 11; static const int FIELD_FLAG_EMITTER = 8; static const float INV_FOUR_PI = 0.07957747155; +static const float MEDIUM_PHASE_G = 0.34; struct VertexOut { @@ -537,6 +539,23 @@ float3 froxelIrradianceAt(float2 uv, float travel) return mediumLightTexture.SampleLevel(gridSampler, mediumAtlasUv(uv, sliceIndex), 0.0).rgb; } +float froxelDominantLightAt(float2 uv, float travel, out float3 lightDirection) +{ + float slice = saturate(travel / max(farDistance, 0.0001)) * (float)MEDIUM_FROXEL_SLICE_COUNT; + int sliceIndex = clamp((int)floor(slice), 0, MEDIUM_FROXEL_SLICE_COUNT - 1); + float4 moment = mediumLightDirectionTexture.SampleLevel(gridSampler, mediumAtlasUv(uv, sliceIndex), 0.0); + float momentLength = length(moment.rgb); + lightDirection = momentLength > 0.00001 ? moment.rgb / momentLength : normalize(float3(0.18, -0.25, 0.95)); + return saturate(momentLength / max(moment.a, 0.0001)); +} + +float henyeyGreensteinPhase(float cosTheta, float g) +{ + float gg = g * g; + float denominator = max(1.0 + gg - 2.0 * g * cosTheta, 0.0001); + return (1.0 - gg) / (4.0 * PI * denominator * sqrt(denominator)); +} + float mediumSliceTravel(int sliceIndex) { float t = ((float)sliceIndex + 0.5) / (float)MEDIUM_FROXEL_SLICE_COUNT; @@ -577,6 +596,7 @@ SolidHit nearestViewFroxelSolidHit(float2 uv, float3 origin, float3 direction, i void integrateMediumSlice( float2 uv, + float3 rayDirection, int sliceIndex, float intervalFraction, inout float transmittance, @@ -589,6 +609,7 @@ void integrateMediumSlice( float4 diagnostic = mediumVolumeTexture.SampleLevel(gridSampler, atlasUv, 0.0); float4 transport = mediumTransportTexture.SampleLevel(gridSampler, atlasUv, 0.0); float3 propagatedLight = mediumLightTexture.SampleLevel(gridSampler, atlasUv, 0.0).rgb; + float4 directionMoment = mediumLightDirectionTexture.SampleLevel(gridSampler, atlasUv, 0.0); float sliceTravel = mediumSliceTravel(sliceIndex); float fraction = saturate(intervalFraction); float density = saturate(diagnostic.x); @@ -599,7 +620,11 @@ void integrateMediumSlice( float partialTransmittance = exp(-sliceExtinction * fraction); float scatterIntegral = sigmaT > 0.0001 ? sigmaS * (1.0 - partialTransmittance) / sigmaT : 0.0; float densityContribution = density * fraction; - float3 sliceInScattering = propagatedLight * (INV_FOUR_PI * scatterIntegral); + float directionLength = length(directionMoment.rgb); + float3 lightDirection = directionLength > 0.00001 ? directionMoment.rgb / directionLength : -rayDirection; + float directionConfidence = saturate(directionLength / max(directionMoment.a, 0.0001)); + float phase = lerp(INV_FOUR_PI, henyeyGreensteinPhase(dot(-rayDirection, lightDirection), MEDIUM_PHASE_G), directionConfidence); + float3 sliceInScattering = propagatedLight * (phase * scatterIntegral); densityMean += densityContribution; densityTravelSum += densityContribution * sliceTravel; @@ -610,6 +635,7 @@ void integrateMediumSlice( void integrateMediumRange( float2 uv, + float3 rayDirection, float rangeStart, float rangeEnd, inout float transmittance, @@ -645,6 +671,7 @@ void integrateMediumRange( float fraction = saturate((overlapEnd - overlapStart) / max(sliceEnd - sliceStart, 0.0001)); integrateMediumSlice( uv, + rayDirection, sliceIndex, fraction, transmittance, @@ -710,7 +737,7 @@ RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 dir gridHit = gridAlpha > 0.001; } - integrateMediumRange(uv, 0.0, stopTravel, transmittance, inScattering, densityAccumulation, densityTravelSum, densitySum); + integrateMediumRange(uv, direction, 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; @@ -755,15 +782,6 @@ RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 dir return result; } -float emitterSolidAngle(float3 p, FieldInstance emitter) -{ - float emitterRadius = max(emitter.centerRadius.w, 0.001); - float distanceToEmitter = max(length(emitter.centerRadius.xyz - p), emitterRadius + 0.001); - float sinTheta = saturate(emitterRadius / distanceToEmitter); - float cosTheta = sqrt(saturate(1.0 - sinTheta * sinTheta)); - return 2.0 * PI * (1.0 - cosTheta); -} - float3 primitiveEmissionRadiance(float fieldId) { [loop] @@ -780,10 +798,10 @@ float3 primitiveEmissionRadiance(float fieldId) return 0.0; } -float3 cursorSpecularEmitterRadiance(float3 p, float3 normal, float receiverFieldId) +float3 cursorSpecularFroxelRadiance(float2 uv, float travel, float3 p, float3 normal) { static const float MinimumRoughness = 0.045; - static const float CursorRoughness = 0.22; + static const float CursorRoughness = 0.16; float3 viewDirection = normalize(cameraPosition - p); float ndv = saturate(dot(normal, viewDirection)); @@ -794,37 +812,20 @@ float3 cursorSpecularEmitterRadiance(float3 p, float3 normal, float receiverFiel k = (k * k) * 0.125; float geometryV = ndv / max(ndv * (1.0 - k) + k, 0.00001); float3 f0 = float3(0.95, 0.62, 0.26); - float3 reflected = 0.0; - - [loop] - for (int i = 0; i < FIELD_INSTANCE_COUNT; i++) - { - FieldInstance emitter = fieldInstances[i]; - if ((((int)(emitter.fieldFlags.y + 0.5) & FIELD_FLAG_EMITTER) == 0) || - abs(emitter.fieldFlags.x - receiverFieldId) < 0.25) - { - continue; - } - - float emitterRadius = max(emitter.centerRadius.w, 0.001); - float3 toEmitter = emitter.centerRadius.xyz - p; - float emitterDistance = length(toEmitter); - float3 lightDirection = toEmitter / max(emitterDistance, 0.0001); - float3 halfVector = normalize(lightDirection + viewDirection); - float ndl = saturate(dot(normal, lightDirection)); - float ndh = saturate(dot(normal, halfVector)); - float vdh = saturate(dot(viewDirection, halfVector)); - float denominator = ndh * ndh * (alpha2 - 1.0) + 1.0; - float distribution = alpha2 / max(PI * denominator * denominator, 0.00001); - float geometryL = ndl / max(ndl * (1.0 - k) + k, 0.00001); - float geometry = geometryL * geometryV; - float3 fresnel = f0 + (1.0 - f0) * pow(1.0 - vdh, 5.0); - float3 specular = (distribution * geometry) * fresnel / max(4.0 * ndl * ndv, 0.00001); - float visibility = smoothstep(emitterRadius * 0.98, emitterRadius * 1.08, emitterDistance); - reflected += specular * emitter.colorIntensity.rgb * emitterSolidAngle(p, emitter) * ndl * visibility; - } - - return reflected; + float3 irradiance = froxelIrradianceAt(uv, travel); + float3 lightDirection; + float directionConfidence = froxelDominantLightAt(uv, travel, lightDirection); + float3 halfVector = normalize(lightDirection + viewDirection); + float ndl = saturate(dot(normal, lightDirection)); + float ndh = saturate(dot(normal, halfVector)); + float vdh = saturate(dot(viewDirection, halfVector)); + float denominator = ndh * ndh * (alpha2 - 1.0) + 1.0; + float distribution = alpha2 / max(PI * denominator * denominator, 0.00001); + float geometryL = ndl / max(ndl * (1.0 - k) + k, 0.00001); + float geometry = geometryL * geometryV; + float3 fresnel = f0 + (1.0 - f0) * pow(1.0 - vdh, 5.0); + float3 specular = (distribution * geometry) * fresnel / max(4.0 * ndl * ndv, 0.00001); + return specular * irradiance * ndl * directionConfidence; } float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int primitiveId) @@ -841,12 +842,15 @@ float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int primitive if (primitiveId == CURSOR_PRIMITIVE_ID) { - return emission + cursorSpecularEmitterRadiance(p, normal, fieldId); + return emission + cursorSpecularFroxelRadiance(uv, travel, p, normal); } + float3 lightDirection; + float directionConfidence = froxelDominantLightAt(uv, travel, lightDirection); + float lambert = lerp(1.0, saturate(dot(normal, lightDirection)), directionConfidence); float hue = hash21(float2(primitiveId, 6.3)); float3 albedo = lerp(float3(0.34, 0.42, 0.18), float3(0.70, 0.76, 0.42), hue); - return emission + albedo * irradianceLuma / PI; + return emission + albedo * irradianceLuma * lambert / PI; } SceneOut D3D12ScenePS(VertexOut input) diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl index 71266ab..60d1935 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl @@ -75,3 +75,13 @@ float4 D3D12MediumLightDebugPS(VertexOut input) : SV_Target0 float3 color = saturate(chroma * exposure); return float4(max(float3(0.004, 0.008, 0.012), color), 1.0); } + +float4 D3D12MediumLightDirectionDebugPS(VertexOut input) : SV_Target0 +{ + float4 moment = sourceTexture.SampleLevel(sourceSampler, input.uv, 0.0); + float momentLength = length(moment.rgb); + float confidence = saturate(momentLength / max(moment.a, 0.0001)); + float3 direction = momentLength > 0.00001 ? moment.rgb / momentLength : 0.0; + float3 color = (direction * 0.5 + 0.5) * confidence; + return float4(max(float3(0.004, 0.008, 0.012), color), 1.0); +} diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 7eaae58..ea89ce5 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -135,3 +135,4 @@ {"timestamp":"2026-05-10T15:45:00+01:00","topic":"propagated-light-debug","lesson":"Renderer-owned lighting needs its own inspection surface. D3D12 debug mode 12 now shows the propagated froxel light target directly, separate from froxel density, so lighting failures can be diagnosed as injection, propagation, or integration problems instead of guessed from the final composite.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","docs/hlsl-renderer.md","docs/d3d12-migration.md","state/memory.json","state/scratch.md"]} {"timestamp":"2026-05-10T16:05:00+01:00","topic":"d3d12-lighting-sanitation","lesson":"Do not keep dead lighting math in the live medium pass. D3D12 final integration reads density/transmittance plus the propagated froxel light target; the old phase-scattered direct radiance path into `transport.rgb` was unused and has been cut. Docs/state must describe the current direct-traced Grid event lane, not the removed transparent-froxel Grid experiment.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","docs/d3d12-best-practices-audit.md","docs/d3d12-migration.md","docs/hlsl-renderer.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx --no-restore",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 90"]} {"timestamp":"2026-05-10T16:25:00+01:00","topic":"d3d12-physical-medium-coefficients","lesson":"Aquarium medium math should justify where light comes from before beauty tuning. D3D12 froxels now carry explicit density, extinction sigma_t, scattering sigma_s, albedo, slice transmittance, and raw emitter irradiance. Scene integration uses Beer-Lambert transmittance and isotropic single scattering sigma_s * irradiance / 4pi; direct ray transmittance debug uses the same coefficient evaluator. mediumTerms now means x extinction-per-density, y scattering albedo, z reserved phase/aniso, w density scale.","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","src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl","docs/hlsl-renderer.md","docs/sdf-field-renderer-plan.md","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx --no-restore",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 90"]} +{"timestamp":"2026-05-10T16:38:53.8578765+01:00","topic":"D3D12 directional medium lighting","lesson":"Medium lighting needs explicit directional/probe data once phase and glossy surfaces matter. Aquarium now carries a luminance-weighted dominant-light direction moment beside propagated froxel irradiance, uses it for Henyey-Greenstein scattering, and shades solids from the same field instead of private direct emitter loops.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/D3D12Renderer.cs"]} diff --git a/state/map.yaml b/state/map.yaml index e1e9022..c8e7dd6 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -63,13 +63,13 @@ renderer_state: - DirectWrite overlay text after scene rendering. - Direct2D/DirectWrite debug UI panel with code-first controls bound to renderer state. - Global GraphicsSettings document feeding render debug, exposure, bloom intensity, bloom veil, and medium composite intensity. - - Field instance structured buffer feeding D3D12 medium density, transport, raw light injection, and propagated froxel light passes. + - Field instance structured buffer feeding D3D12 medium density, transport, raw light injection, propagated froxel light, and propagated dominant-light direction passes. - D3D12 default renderer behind IAquariumRenderer with device/queue/swapchain, per-frame command allocators, fences, static/transient descriptor arenas, upload ring constants, RTV/SRV/UAV render targets, structured field buffers, tracked barriers, command events, resize descriptor-arena rebuild, migrated Grid height brushes, view-froxel solid bins, HDR/bloom/present, temporal history lanes, and DirectWrite overlay bridge. - D3D12 Grid linework is direct-traced as a non-terminating stochastic event lane before the nearest solid; the failed transparent-froxel Grid bin experiment is dead and must stay out of live code. - Splash screen with bundled app icon and GameCult typefaces. next: - Replace CPU bootstrap view-froxel binning with GPU/raster binning before primitive/event counts scale. - - Add directional/probe lighting for glossy SDF surfaces so cursor metal can stop using a private direct-emitter specular loop. + - Evolve the dominant-light direction field into richer probe lighting once multiple emitters and glossy SDFs need more than one direction. - Promote field instances from fixed renderer table to a CPU-owned registry with per-field debug controls. - Extend explicit renderer debug modes for hits, normals, depth, bins, and lighting. - Add volumetrics as an explicit renderer-owned field pass, starting from Wronski/Hillaire-style frustum volume lighting with Self as the first emitter. diff --git a/state/memory.json b/state/memory.json index 50b6c50..3f87ca6 100644 --- a/state/memory.json +++ b/state/memory.json @@ -52,7 +52,7 @@ "HDR/PBR presentation should follow research/rendering/hdr-pbr-presentation.md: scene-linear lighting, explicit exposure, pre-tonemap bloom/veil, then a display transform. Do not reach for 2000s threshold bloom when the frame needs dynamic range.", "Aquarium's current HDR presentation pass uses fixed manual exposure plus a three-level half/quarter/eighth pre-tonemap bloom pyramid with firefly-safe downsampling and separable blur. Next HDR work is persisted exposure/display controls, not threshold glow.", "Future volumetric lighting should be a field sampled consistently by terrain, planets, fog, particles, and diegetic UI. Do not fake only the planet term if the scene is supposed to bounce light.", - "Volumetric density must not self-illuminate through baked color. D3D12 medium lighting now evaluates physical-ish coefficients first: density for inspection, extinction sigma_t, scattering sigma_s, and albedo. Field mediumTerms mean x = extinction per density, y = scattering albedo, z = reserved phase/aniso, w = density scale. Raw irradiance from FieldFlags.Emitter instances is injected using emitter colorIntensity.rgb, finite solid angle, and cheap depth/radial light-path attenuation; a separate propagation pass turns that into the light field consumed by Beer-Lambert medium integration and solid diffuse shading. Do not compute unused direct-scattering color into transport targets just because an earlier pass did; if phase/direction matters, add explicit directional/probe data. Self, cursor, nebulae, and future emissive SDFs must all use this field-emitter path; do not reintroduce point-light constants or ambient fog glow.", + "Volumetric density must not self-illuminate through baked color. D3D12 medium lighting now evaluates physical-ish coefficients first: density for inspection, extinction sigma_t, scattering sigma_s, and albedo. Field mediumTerms mean x = extinction per density, y = scattering albedo, z = reserved phase/aniso, w = density scale. Raw irradiance from FieldFlags.Emitter instances is injected using emitter colorIntensity.rgb, finite solid angle, and cheap depth/radial light-path attenuation; a separate propagation pass transports both irradiance and a luminance-weighted dominant-light direction moment. Medium integration uses Beer-Lambert transmittance and Henyey-Greenstein phase from that direction field; solids consume the propagated froxel light/direction for diffuse and cursor GGX specular. Do not compute unused direct-scattering color into transport targets or private per-surface emitter loops just because an earlier pass did. Self, cursor, nebulae, and future emissive SDFs must all use this field-emitter path; do not reintroduce point-light constants or ambient fog glow.", "Do not blend D3D12 medium color history into final presentation until the renderer owns a proper light-volume/medium reprojection contract. Medium packets can keep opacity/density/travel age for diagnostics, but resolved fog color history smears badly when injected lighting changes with camera/emitter geometry.", "D3D12 medium radiance has its own temporal lane: scene emits `sceneMediumColor`, resolve keeps surface history surface-only, reprojects medium packet travel into `historyMediumColor`, validates by travel/opacity/density, and composites resolved surface + resolved medium + events. Medium lighting is split into raw emitter injection and a propagated froxel light target; medium integration and solid diffuse shading consume the propagated light field instead of private direct diffuse loops. This is single-step froxel propagation plus reprojection; full multi-bounce GI and directional/probe glossy lighting remain future work.", "Volumetric design must start from research/volumetrics/synthesis.md. The first pass should follow Wronski/Hillaire production shape: explicit low-resolution frustum volume, injected density/extinction/scattering, Self as first emitter, front-to-back transmittance/in-scattering integration, then consistent composition.", @@ -84,7 +84,7 @@ "Grid temporal control coverage is the line/support signal. Do not mark the whole low-support Grid surface reactive; that turns debug control mode red everywhere and reintroduces stale history-murder logic.", "Temporal control background coverage must be zero. Opaque hits can write coverage 1, and Grid hits write line/support coverage; empty background must not appear as stable covered history in mode 5.", "Projection jitter is currently scaled to zero. If Self or planet surfaces visibly judder, the resolve is not hiding jitter and the correct live choice is no jitter until opaque and Grid paths both prove stable.", - "Temporal/debug views are live keys: F1 cycles; 0 final, 1 raw current scene, 2 reprojected history, 3 history age, 4 history weight, 5 current temporal control, 6 current field identity, 7 bloom, 8 exposed luminance, 9 medium ray density, 10 medium ray transmittance, 11 froxel density, 12 propagated froxel light. Use these before guessing whether TAA, medium, or lighting is sampling, validating, or presenting the wrong signal.", + "Temporal/debug views are live keys: F1 cycles; 0 final, 1 raw current scene, 2 reprojected history, 3 history age, 4 history weight, 5 current temporal control, 6 current field identity, 7 bloom, 8 exposed luminance, 9 medium ray density, 10 medium ray transmittance, 11 froxel density, 12 propagated froxel light, 13 propagated froxel light direction. Use these before guessing whether TAA, medium, or lighting is sampling, validating, or presenting the wrong signal.", "Bruneton-style atmospheric scattering is the later sky/planet solution, not the first Grid fog pass. Use LUTs, explicit texture mappings, and unit-tested physical terms when Aquarium reaches ground-to-space atmosphere.", "GigaVoxels-style ray-guided sparse bricks are only for large sparse field/world storage. Do not turn early fog into a monolithic persistent volume cache." ], diff --git a/state/scratch.md b/state/scratch.md index 28141ab..8a1aad4 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -506,3 +506,11 @@ reusing field identity/travel/control. to a hit, then stops on the nearest opaque surface. Current solid evaluators are analytic spheres; future SDF surfaces should replace that evaluator inside this traversal rather than creating a second solid pass. +- D3D12 directional medium lighting pass: medium injection now writes raw + irradiance plus a separate luminance-weighted dominant-light direction + moment at `t25`; propagation transports both irradiance and direction. + Medium integration uses Henyey-Greenstein phase from the propagated direction + instead of pretending every froxel is isotropic. Planets and the cursor sample + the same froxel light/direction field; the old cursor-only direct emitter + specular loop has been cut. Debug mode `13` visualizes propagated froxel light + direction.