Interpolate D3D12 froxel light slices

This commit is contained in:
Meta Vens 2026-05-10 17:26:07 +01:00
commit 87c36a4818
4 changed files with 26 additions and 7 deletions

View file

@ -532,18 +532,31 @@ float2 mediumAtlasUv(float2 uv, int sliceIndex)
return (float2(tileX, tileY) + uv) / float2(MEDIUM_FROXEL_ATLAS_COLUMNS, MEDIUM_FROXEL_ATLAS_ROWS);
}
float sliceCenterCoordinate(float travel)
{
return saturate(travel / max(farDistance, 0.0001)) * (float)MEDIUM_FROXEL_SLICE_COUNT - 0.5;
}
float3 froxelIrradianceAt(float2 uv, float travel)
{
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);
return mediumLightTexture.SampleLevel(gridSampler, mediumAtlasUv(uv, sliceIndex), 0.0).rgb;
float slice = sliceCenterCoordinate(travel);
int sliceA = clamp((int)floor(slice), 0, MEDIUM_FROXEL_SLICE_COUNT - 1);
int sliceB = clamp(sliceA + 1, 0, MEDIUM_FROXEL_SLICE_COUNT - 1);
float sliceBlend = saturate(slice - (float)sliceA);
float3 lightA = mediumLightTexture.SampleLevel(gridSampler, mediumAtlasUv(uv, sliceA), 0.0).rgb;
float3 lightB = mediumLightTexture.SampleLevel(gridSampler, mediumAtlasUv(uv, sliceB), 0.0).rgb;
return lerp(lightA, lightB, sliceBlend);
}
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 slice = sliceCenterCoordinate(travel);
int sliceA = clamp((int)floor(slice), 0, MEDIUM_FROXEL_SLICE_COUNT - 1);
int sliceB = clamp(sliceA + 1, 0, MEDIUM_FROXEL_SLICE_COUNT - 1);
float sliceBlend = saturate(slice - (float)sliceA);
float4 momentA = mediumLightDirectionTexture.SampleLevel(gridSampler, mediumAtlasUv(uv, sliceA), 0.0);
float4 momentB = mediumLightDirectionTexture.SampleLevel(gridSampler, mediumAtlasUv(uv, sliceB), 0.0);
float4 moment = lerp(momentA, momentB, sliceBlend);
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));

View file

@ -139,3 +139,4 @@
{"timestamp":"2026-05-10T16:49:14.2607265+01:00","topic":"Dominant-light direction limitation","lesson":"A single froxel light direction is a lossy artistic approximation. Intersecting beams average, and opposed beams can cancel to low confidence and isotropic fallback. Keep the smear for now because it may look good, but future full transport needs multi-lobe, probe, or reservoir direction storage.","files":["state/memory.json","state/map.yaml","state/scratch.md"]}
{"timestamp":"2026-05-10T17:03:06.9352794+01:00","topic":"D3D12 iterative medium light propagation","lesson":"The propagated medium light field now uses explicit scratch/final froxel targets and four ping-ponged propagation iterations for irradiance plus dominant direction, replacing the single one-pass neighbor spread. This remains a compact diffusion approximation, but propagation state and cost are explicit.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","state/memory.json","state/map.yaml","state/scratch.md"]}
{"timestamp":"2026-05-10T17:18:38.9003279+01:00","topic":"D3D12 medium froxel sample decorrelation","lesson":"Aetheria-style raymarch jitter only fights march-step aliasing because it marches per pixel. Aquarium froxel injection also has an 8x8 screen-space lattice, so medium samples must jitter both sub-froxel XY representative ray location and in-slice Z travel. D3D12 now uploads the Aetheria R8 blue-noise texture as a static structured buffer and uses animated blue-noise offsets for both axes before TAA accumulation.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl","state/memory.json","state/map.yaml","state/scratch.md"]}
{"timestamp":"2026-05-10T17:25:50.2368570+01:00","topic":"D3D12 froxel light slice interpolation","lesson":"Uniform jitter during medium injection is not enough if consumers quantize travel back to a single froxel slice. Surface shading must interpolate propagated froxel irradiance and dominant direction between slice centers, or moving solids pop between lighting slices.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]}

View file

@ -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; propagation ping-pongs four low-resolution froxel iterations through scratch/final irradiance and luminance-weighted dominant-light direction targets. Medium froxel injection samples one representative ray per froxel/slice, decorrelated by the Aetheria blue-noise buffer in both sub-froxel XY and in-slice travel Z; this fights both 32-slice march aliasing and 8x8 froxel row/column aliasing before TAA accumulation. 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. A single direction moment is intentionally lossy: crossing beams smear or cancel to low confidence and fall back toward isotropic scattering. Keep it for now if the smear is useful, but do not mistake it for final transport; future richer lighting needs multi-lobe/probe/reservoir direction storage. 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.",
"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; propagation ping-pongs four low-resolution froxel iterations through scratch/final irradiance and luminance-weighted dominant-light direction targets. Medium froxel injection samples one representative ray per froxel/slice, decorrelated by the Aetheria blue-noise buffer in both sub-froxel XY and in-slice travel Z; this fights both 32-slice march aliasing and 8x8 froxel row/column aliasing before TAA accumulation. Surface shading must interpolate propagated froxel light/direction between slice centers; otherwise moving solids still pop between discrete lighting slices even when injection jitter is uniform. 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. A single direction moment is intentionally lossy: crossing beams smear or cancel to low confidence and fall back toward isotropic scattering. Keep it for now if the smear is useful, but do not mistake it for final transport; future richer lighting needs multi-lobe/probe/reservoir direction storage. 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.",

View file

@ -531,3 +531,8 @@ reusing field identity/travel/control.
representative ray's sub-froxel XY location and the sample's in-slice Z
travel. This is different from Aetheria's per-pixel cloud march: Aquarium must
fight both fixed march-step aliasing and the 8x8 froxel row/column lattice.
- D3D12 propagated light slice interpolation: injection jitter uniformly covers
each froxel slice interval, but surface shading was still flooring
travel-to-slice when sampling propagated froxel light. That reintroduced
visible lighting pops as planets crossed slice boundaries. Surface
irradiance/dominant-direction lookup now interpolates adjacent slice centers.