diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl index 85e7212..7fa56e0 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl @@ -838,7 +838,14 @@ float3 cursorSpecularFroxelRadiance(float2 uv, float travel, float3 p, float3 no 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 directSpecular = specular * irradiance * ndl * directionConfidence; + + float3 viewFresnel = f0 + (1.0 - f0) * pow(1.0 - ndv, 5.0); + float3 fieldRadiance = irradiance * INV_FOUR_PI; + float backlit = saturate(dot(lightDirection, -viewDirection)) * (1.0 - ndl); + float environmentWeight = 0.22 + 0.48 * backlit; + float3 mediumSpecular = fieldRadiance * viewFresnel * environmentWeight; + return directSpecular + mediumSpecular; } float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int primitiveId) diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 245af1a..3e9505d 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -140,3 +140,4 @@ {"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"]} +{"timestamp":"2026-05-10T17:30:04.3849309+01:00","topic":"D3D12 cursor medium environment specular","lesson":"A metallic cursor has no diffuse fallback. If cursor shading only uses dominant-direction GGX multiplied by NdotL, it can go black while sitting in the brightest medium whenever visible normals do not face the dominant light. Add low-frequency diegetic environment specular from local propagated froxel irradiance; this is reflected medium light, not ambient fill.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]} diff --git a/state/memory.json b/state/memory.json index 663312c..8b3fd21 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; 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.", + "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. The brass cursor also needs low-frequency diegetic environment specular from local froxel irradiance; direct dominant-light GGX alone goes black whenever visible normals fail `NdotL`, even if the cursor sits in the brightest medium in the scene. 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.", diff --git a/state/scratch.md b/state/scratch.md index 29d8a12..9899e80 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -536,3 +536,8 @@ reusing field identity/travel/control. 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. +- D3D12 cursor medium-reflection pass: the brass cursor is metallic, so it has + no diffuse fallback. Direct dominant-direction GGX goes black whenever visible + normals fail `NdotL`, even if the object is inside the scene's brightest + medium. Cursor shading now adds a low-frequency diegetic environment specular + term from local propagated froxel irradiance, boosted for view/backlit cases.