Add temporal SDF Gaussian renderer field
This commit is contained in:
parent
681dee5f1d
commit
1ac4886852
17 changed files with 683 additions and 6 deletions
57
docs/temporal-sdf-gaussian-field.md
Normal file
57
docs/temporal-sdf-gaussian-field.md
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Temporal SDF Gaussian Field
|
||||
|
||||
## Objective
|
||||
|
||||
Aquarium owns the renderer feature for live volumetric point-cloud/splat input:
|
||||
clients provide stable world-space Gaussian observations, and the engine turns
|
||||
them into a buffered, reprojectable, D3D12-rendered field. LocalCastBridge can
|
||||
then feed sensor-fusion output into Aquarium as a normal scene contract instead
|
||||
of smuggling renderer policy through client code.
|
||||
|
||||
## Current Mechanism
|
||||
|
||||
The client-facing contract is `AquariumSceneState.TemporalGaussianField`.
|
||||
Each `AquariumTemporalSdfGaussian` carries stable identity, current and previous
|
||||
center, velocity, oriented radii, color/opacity, confidence, history weight,
|
||||
compact-kernel controls, and field id.
|
||||
|
||||
`Aquarium.Engine.Fractal.Temporal.TemporalGaussianAccumulator` consumes
|
||||
`TemporalGaussianObservation` rows and owns the live buffering policy:
|
||||
|
||||
- stable keys identify tracks across camera/sensor frames
|
||||
- presentation delay lets late sensor data converge before rendering
|
||||
- accumulation window expires old tracks
|
||||
- smoothed velocity predicts the presented center
|
||||
- history weight is confidence scaled by age inside the window
|
||||
|
||||
The D3D12 renderer lowers the field into `D3D12TemporalGaussianPacket`, uploads a
|
||||
4096-entry structured buffer, and renders an instanced proxy-quad pass from
|
||||
`D3D12TemporalGaussian.hlsl`. The pixel shader evaluates a compact anisotropic
|
||||
Gaussian kernel in world space, writes HDR scene color/travel, field metadata,
|
||||
normal, and temporal-control coverage so the existing resolve sees the field as
|
||||
diegetic scene content.
|
||||
|
||||
## Invariants
|
||||
|
||||
- Field accumulation happens in world space before pixel history. TAA is the
|
||||
resolver, not the owner of sensor identity.
|
||||
- Stable keys belong to the producer/accumulator boundary; shader packets are
|
||||
backend output and do not invent identity.
|
||||
- The compact support kernel has a finite bound. Renderer cost must scale from
|
||||
declared bounds, not from infinite translucent fog.
|
||||
- Client code may construct observations or a field, but Aquarium owns packet
|
||||
layout, root binding, shader evaluation, and temporal-control metadata.
|
||||
- JSON is not a renderer boundary. CultCache/CultNet producers should lower into
|
||||
typed contract rows before Aquarium sees the data.
|
||||
|
||||
## Cut Line
|
||||
|
||||
This cut deliberately does not claim million-splat residency yet. The live D3D12
|
||||
path draws up to 4096 temporal Gaussians through instanced proxy quads. Scaling
|
||||
past that belongs to the Aquarium renderer: selected-cut residency, tiled/bin
|
||||
dispatch, or Aquarium/Aquarium-like compute lowering. Do not push that scheduler
|
||||
into LocalCastBridge.
|
||||
|
||||
The first shader pass also uses camera-facing proxy planes to evaluate each
|
||||
kernel. True ray-integrated volume compositing, Gaussian depth sorting, and
|
||||
per-Gaussian previous-center reprojection remain the next renderer cuts.
|
||||
|
|
@ -130,12 +130,25 @@ Current Gate 2B implementation:
|
|||
- this gives analytic SDF bodies object motion without a full velocity buffer
|
||||
yet
|
||||
|
||||
Current Gate 2C implementation:
|
||||
|
||||
- `AquariumSceneState.TemporalGaussianField` carries world-space temporal SDF
|
||||
Gaussian splats with stable keys, current/previous center, velocity,
|
||||
confidence, history weight, field id, and compact-kernel controls
|
||||
- `TemporalGaussianAccumulator` buffers sensor observations in world space before
|
||||
rendering, using a presentation delay plus accumulation window instead of
|
||||
asking final-pixel TAA to discover identity after projection
|
||||
- D3D12 uploads the field into a structured buffer and renders it through
|
||||
`D3D12TemporalGaussian.hlsl`, writing color/travel, field metadata, normals,
|
||||
and temporal-control coverage into the existing scene/resolve path
|
||||
|
||||
Still missing:
|
||||
|
||||
- separate field ids once the SDF field registry exists
|
||||
- reactive/coverage masks
|
||||
- richer disocclusion classification
|
||||
- a general velocity buffer for non-rigid fields and deformation
|
||||
- per-Gaussian previous-center reprojection in the resolve pass
|
||||
|
||||
### Gate 3: Stochastic Event Control
|
||||
|
||||
|
|
|
|||
|
|
@ -132,6 +132,12 @@ public sealed class AquariumShaderBuilder(AquariumShaderManifest manifest)
|
|||
return this;
|
||||
}
|
||||
|
||||
public AquariumShaderBuilder TemporalGaussian(string path)
|
||||
{
|
||||
manifest.TemporalGaussian(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AquariumShaderBuilder Include(string path)
|
||||
{
|
||||
manifest.Include(path);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ public sealed class AquariumShaderManifest
|
|||
|
||||
public string SceneShader { get; private set; } = "D3D12Scene.hlsl";
|
||||
|
||||
public string TemporalGaussianShader { get; private set; } = "D3D12TemporalGaussian.hlsl";
|
||||
|
||||
public string PostShader { get; private set; } = "D3D12Post.hlsl";
|
||||
|
||||
public string SdfCommonInclude { get; private set; } = "D3D12SdfCommon.hlsli";
|
||||
|
|
@ -59,6 +61,12 @@ public sealed class AquariumShaderManifest
|
|||
return this;
|
||||
}
|
||||
|
||||
public AquariumShaderManifest TemporalGaussian(string path)
|
||||
{
|
||||
TemporalGaussianShader = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AquariumShaderManifest Post(string path)
|
||||
{
|
||||
PostShader = path;
|
||||
|
|
@ -233,6 +241,32 @@ public readonly record struct AquariumHeightFieldBrush(
|
|||
float DomainX = 0.0f,
|
||||
float DomainY = 0.0f);
|
||||
|
||||
public readonly record struct AquariumTemporalSdfGaussian(
|
||||
string StableKey,
|
||||
Vector3 Center,
|
||||
Vector3 PreviousCenter,
|
||||
Vector3 Velocity,
|
||||
Vector3 Radii,
|
||||
Quaternion Orientation,
|
||||
Vector4 ColorOpacity,
|
||||
float Confidence,
|
||||
float HistoryWeight,
|
||||
float LastObservedTimeSeconds,
|
||||
float Falloff,
|
||||
float ShapePower,
|
||||
int FieldId);
|
||||
|
||||
public sealed class AquariumTemporalGaussianField
|
||||
{
|
||||
public static AquariumTemporalGaussianField Empty { get; } = new();
|
||||
|
||||
public IReadOnlyList<AquariumTemporalSdfGaussian> Gaussians { get; init; } = [];
|
||||
|
||||
public float AccumulationWindowSeconds { get; init; }
|
||||
|
||||
public float PresentationDelaySeconds { get; init; }
|
||||
}
|
||||
|
||||
public sealed class AquariumSceneState
|
||||
{
|
||||
public static AquariumSceneState Empty { get; } = new();
|
||||
|
|
@ -246,4 +280,6 @@ public sealed class AquariumSceneState
|
|||
public IReadOnlyList<AquariumSdfObject> SdfObjects { get; init; } = [];
|
||||
|
||||
public IReadOnlyList<AquariumSdfLight> SdfLights { get; init; } = [];
|
||||
|
||||
public AquariumTemporalGaussianField TemporalGaussianField { get; init; } = AquariumTemporalGaussianField.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,171 @@
|
|||
using System.Numerics;
|
||||
using Aquarium.Engine.Render;
|
||||
|
||||
namespace Aquarium.Engine.Fractal.Temporal;
|
||||
|
||||
public sealed class TemporalGaussianAccumulator
|
||||
{
|
||||
private readonly Dictionary<string, TemporalGaussianTrack> tracks = [];
|
||||
|
||||
public TemporalGaussianAccumulator(
|
||||
float accumulationWindowSeconds,
|
||||
float presentationDelaySeconds,
|
||||
float smoothing = 0.35f)
|
||||
{
|
||||
if (!float.IsFinite(accumulationWindowSeconds) || accumulationWindowSeconds <= 0.0f)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(accumulationWindowSeconds), accumulationWindowSeconds, "Accumulation window must be positive.");
|
||||
}
|
||||
|
||||
if (!float.IsFinite(presentationDelaySeconds) || presentationDelaySeconds < 0.0f)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(presentationDelaySeconds), presentationDelaySeconds, "Presentation delay must be non-negative.");
|
||||
}
|
||||
|
||||
if (!float.IsFinite(smoothing) || smoothing <= 0.0f || smoothing > 1.0f)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(smoothing), smoothing, "Smoothing must be in (0, 1].");
|
||||
}
|
||||
|
||||
AccumulationWindowSeconds = accumulationWindowSeconds;
|
||||
PresentationDelaySeconds = presentationDelaySeconds;
|
||||
Smoothing = smoothing;
|
||||
}
|
||||
|
||||
public float AccumulationWindowSeconds { get; }
|
||||
|
||||
public float PresentationDelaySeconds { get; }
|
||||
|
||||
public float Smoothing { get; }
|
||||
|
||||
public void Observe(IEnumerable<TemporalGaussianObservation> observations)
|
||||
{
|
||||
foreach (var observation in observations)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(observation.StableKey))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tracks.TryGetValue(observation.StableKey, out var current))
|
||||
{
|
||||
tracks[observation.StableKey] = current.Update(observation, Smoothing);
|
||||
}
|
||||
else
|
||||
{
|
||||
tracks[observation.StableKey] = TemporalGaussianTrack.Create(observation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AquariumTemporalGaussianField BuildField(float renderTimeSeconds)
|
||||
{
|
||||
var presentationTime = renderTimeSeconds - PresentationDelaySeconds;
|
||||
var cutoff = presentationTime - AccumulationWindowSeconds;
|
||||
var gaussians = new List<AquariumTemporalSdfGaussian>(tracks.Count);
|
||||
var expired = new List<string>();
|
||||
|
||||
foreach (var (key, track) in tracks)
|
||||
{
|
||||
if (track.LastObservedTimeSeconds < cutoff)
|
||||
{
|
||||
expired.Add(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
var age = MathF.Max(0.0f, presentationTime - track.LastObservedTimeSeconds);
|
||||
var historyWeight = Math.Clamp(1.0f - (age / AccumulationWindowSeconds), 0.0f, 1.0f) * track.Confidence;
|
||||
var predictedCenter = track.Center + track.Velocity * (presentationTime - track.LastObservedTimeSeconds);
|
||||
var previousCenter = predictedCenter - track.Velocity * (1.0f / 60.0f);
|
||||
gaussians.Add(new AquariumTemporalSdfGaussian(
|
||||
track.StableKey,
|
||||
predictedCenter,
|
||||
previousCenter,
|
||||
track.Velocity,
|
||||
track.Radii,
|
||||
track.Orientation,
|
||||
track.ColorOpacity,
|
||||
track.Confidence,
|
||||
historyWeight,
|
||||
track.LastObservedTimeSeconds,
|
||||
track.Falloff,
|
||||
track.ShapePower,
|
||||
track.FieldId));
|
||||
}
|
||||
|
||||
foreach (var key in expired)
|
||||
{
|
||||
tracks.Remove(key);
|
||||
}
|
||||
|
||||
return new AquariumTemporalGaussianField
|
||||
{
|
||||
Gaussians = gaussians.OrderByDescending(item => item.HistoryWeight).ToArray(),
|
||||
AccumulationWindowSeconds = AccumulationWindowSeconds,
|
||||
PresentationDelaySeconds = PresentationDelaySeconds,
|
||||
};
|
||||
}
|
||||
|
||||
private readonly record struct TemporalGaussianTrack(
|
||||
string StableKey,
|
||||
Vector3 Center,
|
||||
Vector3 Velocity,
|
||||
Vector3 Radii,
|
||||
Quaternion Orientation,
|
||||
Vector4 ColorOpacity,
|
||||
float Confidence,
|
||||
float LastObservedTimeSeconds,
|
||||
float Falloff,
|
||||
float ShapePower,
|
||||
int FieldId)
|
||||
{
|
||||
public static TemporalGaussianTrack Create(TemporalGaussianObservation observation)
|
||||
{
|
||||
return new TemporalGaussianTrack(
|
||||
observation.StableKey,
|
||||
observation.Center,
|
||||
Vector3.Zero,
|
||||
SanitizeRadii(observation.Radii),
|
||||
SanitizeOrientation(observation.Orientation),
|
||||
observation.ColorOpacity,
|
||||
Math.Clamp(observation.Confidence, 0.0f, 1.0f),
|
||||
observation.ObservedTimeSeconds,
|
||||
MathF.Max(0.0001f, observation.Falloff),
|
||||
MathF.Max(0.0001f, observation.ShapePower),
|
||||
observation.FieldId);
|
||||
}
|
||||
|
||||
public TemporalGaussianTrack Update(TemporalGaussianObservation observation, float smoothing)
|
||||
{
|
||||
var dt = MathF.Max(0.0001f, observation.ObservedTimeSeconds - LastObservedTimeSeconds);
|
||||
var measuredVelocity = (observation.Center - Center) / dt;
|
||||
var alpha = smoothing * Math.Clamp(observation.Confidence, 0.0f, 1.0f);
|
||||
var updatedCenter = Vector3.Lerp(Center, observation.Center, alpha);
|
||||
return this with
|
||||
{
|
||||
Center = updatedCenter,
|
||||
Velocity = Vector3.Lerp(Velocity, measuredVelocity, alpha),
|
||||
Radii = Vector3.Lerp(Radii, SanitizeRadii(observation.Radii), alpha),
|
||||
Orientation = SanitizeOrientation(Quaternion.Slerp(Orientation, SanitizeOrientation(observation.Orientation), alpha)),
|
||||
ColorOpacity = Vector4.Lerp(ColorOpacity, observation.ColorOpacity, alpha),
|
||||
Confidence = Math.Clamp((Confidence * 0.85f) + (observation.Confidence * 0.15f), 0.0f, 1.0f),
|
||||
LastObservedTimeSeconds = observation.ObservedTimeSeconds,
|
||||
Falloff = MathF.Max(0.0001f, observation.Falloff),
|
||||
ShapePower = MathF.Max(0.0001f, observation.ShapePower),
|
||||
FieldId = observation.FieldId,
|
||||
};
|
||||
}
|
||||
|
||||
private static Vector3 SanitizeRadii(Vector3 radii)
|
||||
{
|
||||
return Vector3.Max(radii, new Vector3(0.0001f));
|
||||
}
|
||||
|
||||
private static Quaternion SanitizeOrientation(Quaternion orientation)
|
||||
{
|
||||
return orientation.LengthSquared() <= 0.000001f
|
||||
? Quaternion.Identity
|
||||
: Quaternion.Normalize(orientation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace Aquarium.Engine.Fractal.Temporal;
|
||||
|
||||
public readonly record struct TemporalGaussianObservation(
|
||||
string StableKey,
|
||||
Vector3 Center,
|
||||
Vector3 Radii,
|
||||
Quaternion Orientation,
|
||||
Vector4 ColorOpacity,
|
||||
float Confidence,
|
||||
float ObservedTimeSeconds,
|
||||
float Falloff = 4.0f,
|
||||
float ShapePower = 1.0f,
|
||||
int FieldId = 0);
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
using System.Numerics;
|
||||
using Aquarium.Engine.Render;
|
||||
|
||||
namespace Aquarium.Engine.Fractal.Temporal;
|
||||
|
||||
public static class TemporalSdfGaussianKernel
|
||||
{
|
||||
public static float CompactWeight(AquariumTemporalSdfGaussian gaussian, Vector3 point)
|
||||
{
|
||||
var local = Vector3.Transform(point - gaussian.Center, Quaternion.Inverse(gaussian.Orientation));
|
||||
var radii = Vector3.Max(gaussian.Radii, new Vector3(0.0001f));
|
||||
var q = local / radii;
|
||||
var radiusSquared = Vector3.Dot(q, q);
|
||||
if (radiusSquared >= 1.0f)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
var falloff = MathF.Max(gaussian.Falloff, 0.0001f);
|
||||
var shapePower = MathF.Max(gaussian.ShapePower, 0.0001f);
|
||||
var edge = MathF.Exp(-falloff);
|
||||
var value = MathF.Exp(-falloff * radiusSquared);
|
||||
var compact = Math.Clamp((value - edge) / MathF.Max(1.0f - edge, 0.000001f), 0.0f, 1.0f);
|
||||
return MathF.Pow(compact, shapePower);
|
||||
}
|
||||
|
||||
public static float SignedDistance(AquariumTemporalSdfGaussian gaussian, Vector3 point)
|
||||
{
|
||||
var local = Vector3.Transform(point - gaussian.Center, Quaternion.Inverse(gaussian.Orientation));
|
||||
var radii = Vector3.Max(gaussian.Radii, new Vector3(0.0001f));
|
||||
var q = local / radii;
|
||||
return (q.Length() - 1.0f) * MathF.Min(radii.X, MathF.Min(radii.Y, radii.Z));
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private const Format SceneDepthFormat = Format.D32_Float;
|
||||
private const int MaxSdfLightCount = 64;
|
||||
private const int MaxSdfObjectCount = 64;
|
||||
private const int MaxTemporalGaussianCount = 4096;
|
||||
private const float SurfaceTransparentMinZ = -1.85f;
|
||||
private const float SurfaceTransparentMaxZ = 0.45f;
|
||||
private const int BloomLevelCount = 3;
|
||||
|
|
@ -50,6 +51,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private const int RootStudioPmrem = 10;
|
||||
private const int RootStudioIrradiance = 11;
|
||||
private const int RootSdfObjects = 12;
|
||||
private const int RootTemporalGaussians = 13;
|
||||
private static readonly DebugUi.DebugUiOption[] RenderDebugOptions =
|
||||
[
|
||||
new(0, "Final"),
|
||||
|
|
@ -86,6 +88,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private ID3D12PipelineState? heightFieldBasePipelineState;
|
||||
private ID3D12PipelineState? heightFieldBrushPipelineState;
|
||||
private ID3D12PipelineState? scenePipelineState;
|
||||
private ID3D12PipelineState? temporalGaussianPipelineState;
|
||||
private ID3D12PipelineState?[] sdfProxyPipelineStates = [];
|
||||
private ID3D12PipelineState? bloomPrefilterPipelineState;
|
||||
private ID3D12PipelineState? bloomDownsamplePipelineState;
|
||||
|
|
@ -123,10 +126,13 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private readonly D3D12RenderTarget[] bloomScratchTargets = new D3D12RenderTarget[BloomLevelCount];
|
||||
private readonly D3D12StructuredBuffer sdfLightBuffer;
|
||||
private readonly D3D12StructuredBuffer sdfObjectBuffer;
|
||||
private readonly D3D12StructuredBuffer temporalGaussianBuffer;
|
||||
private readonly D3D12CubeTexture studioPmremTexture;
|
||||
private readonly D3D12CubeTexture studioIrradianceTexture;
|
||||
private readonly AquariumSdfLight[] sdfLights = new AquariumSdfLight[MaxSdfLightCount];
|
||||
private readonly AquariumSdfObject[] sdfObjects = new AquariumSdfObject[MaxSdfObjectCount];
|
||||
private readonly D3D12TemporalGaussianPacket[] temporalGaussians = new D3D12TemporalGaussianPacket[MaxTemporalGaussianCount];
|
||||
private int temporalGaussianCount;
|
||||
private Viewport viewport;
|
||||
private RawRect scissorRect;
|
||||
private int width;
|
||||
|
|
@ -224,8 +230,10 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
CreateGraphRenderTargets();
|
||||
sdfLightBuffer = new D3D12StructuredBuffer(device, MaxSdfLightCount, Marshal.SizeOf<AquariumSdfLight>(), "Aquarium D3D12 Sdf Light Buffer");
|
||||
sdfObjectBuffer = new D3D12StructuredBuffer(device, MaxSdfObjectCount, Marshal.SizeOf<AquariumSdfObject>(), "Aquarium D3D12 Sdf Object Buffer");
|
||||
temporalGaussianBuffer = new D3D12StructuredBuffer(device, MaxTemporalGaussianCount, Marshal.SizeOf<D3D12TemporalGaussianPacket>(), "Aquarium D3D12 Temporal Gaussian Buffer");
|
||||
resourceRegistry.Add("sdf-light-buffer", sdfLightBuffer);
|
||||
resourceRegistry.Add("sdf-object-buffer", sdfObjectBuffer);
|
||||
resourceRegistry.Add("temporal-gaussian-buffer", temporalGaussianBuffer);
|
||||
commandList = device.CreateCommandList<ID3D12GraphicsCommandList>(0, CommandListType.Direct, frames[frameIndex].CommandAllocator, null);
|
||||
commandList.Name = "Aquarium D3D12 Graphics Command List";
|
||||
commandList.Close();
|
||||
|
|
@ -498,7 +506,12 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
settings.SceneExposure,
|
||||
settings.BloomIntensity,
|
||||
settings.BloomVeilIntensity,
|
||||
new Vector4(frame.CursorWorld.X, frame.CursorWorld.Y, previousCursorWorld.X, previousCursorWorld.Y)));
|
||||
new Vector4(frame.CursorWorld.X, frame.CursorWorld.Y, previousCursorWorld.X, previousCursorWorld.Y),
|
||||
new Vector4(
|
||||
temporalGaussianCount,
|
||||
MaxTemporalGaussianCount,
|
||||
frame.Scene.TemporalGaussianField.AccumulationWindowSeconds,
|
||||
frame.Scene.TemporalGaussianField.PresentationDelaySeconds)));
|
||||
frameResources.FrameConstantsDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
device.CreateConstantBufferView(
|
||||
new ConstantBufferViewDescription(frameConstants.GpuVirtualAddress, frameConstants.SizeInBytes),
|
||||
|
|
@ -513,6 +526,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
sdfLightBuffer.CreateShaderResourceView(device, frameResources.SdfLightDescriptor);
|
||||
frameResources.SdfObjectDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
sdfObjectBuffer.CreateShaderResourceView(device, frameResources.SdfObjectDescriptor);
|
||||
frameResources.TemporalGaussianDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
temporalGaussianBuffer.CreateShaderResourceView(device, frameResources.TemporalGaussianDescriptor);
|
||||
frameResources.StudioPmremDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
studioPmremTexture.CreateShaderResourceView(device, frameResources.StudioPmremDescriptor);
|
||||
frameResources.StudioIrradianceDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
|
|
@ -553,7 +568,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
var recordCpuStart = Stopwatch.GetTimestamp();
|
||||
commandList.BeginEvent("Aquarium D3D12 Frame");
|
||||
UploadSdfLightResources(commandList, frameResources);
|
||||
UploadSceneStructuredResources(commandList, frameResources);
|
||||
RenderHeightField(commandList, frameResources);
|
||||
RenderSceneAndPresent(new D3D12PassContext(commandList, frameResources.BackBuffer, frameResources.BackBufferRenderTargetView.Cpu), frameResources);
|
||||
commandList.EndEvent();
|
||||
|
|
@ -682,6 +697,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
heightFieldBasePipelineState is not null
|
||||
&& heightFieldBrushPipelineState is not null
|
||||
&& scenePipelineState is not null
|
||||
&& temporalGaussianPipelineState is not null
|
||||
&& sdfProxyPipelineStates.All(pipeline => pipeline is not null)
|
||||
&& bloomPrefilterPipelineState is not null
|
||||
&& bloomDownsamplePipelineState is not null
|
||||
|
|
@ -858,6 +874,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
heightFieldBrush.Name = "Aquarium D3D12 Height Field Brush Pipeline";
|
||||
var scene = CreateScenePipelineState(paths.Scene);
|
||||
scene.Name = "Aquarium D3D12 Scene Pipeline";
|
||||
var temporalGaussian = CreateTemporalGaussianPipelineState(paths.TemporalGaussian);
|
||||
temporalGaussian.Name = "Aquarium D3D12 Temporal Gaussian Pipeline";
|
||||
var sdfProxies = new ID3D12PipelineState[paths.SdfShaders.Count];
|
||||
for (var index = 0; index < paths.SdfShaders.Count; index++)
|
||||
{
|
||||
|
|
@ -880,6 +898,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
heightFieldBase,
|
||||
heightFieldBrush,
|
||||
scene,
|
||||
temporalGaussian,
|
||||
sdfProxies,
|
||||
bloomPrefilter,
|
||||
bloomDownsample,
|
||||
|
|
@ -1205,6 +1224,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
context.CommandList.SetGraphicsRootDescriptorTable(RootStudioPmrem, frameResources.StudioPmremDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(RootStudioIrradiance, frameResources.StudioIrradianceDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(RootSdfObjects, frameResources.SdfObjectDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(RootTemporalGaussians, frameResources.TemporalGaussianDescriptor.Gpu);
|
||||
context.CommandList.RSSetViewports(viewport);
|
||||
context.CommandList.RSSetScissorRects(scissorRect);
|
||||
context.CommandList.OMSetRenderTargets(
|
||||
|
|
@ -1222,6 +1242,12 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
context.CommandList.SetPipelineState(sdfProxyPipelineStates[sdfIndex]!);
|
||||
context.CommandList.DrawInstanced(6, 1, 0, 0);
|
||||
}
|
||||
|
||||
if (temporalGaussianCount > 0)
|
||||
{
|
||||
context.CommandList.SetPipelineState(temporalGaussianPipelineState!);
|
||||
context.CommandList.DrawInstanced(6, (uint)temporalGaussianCount, 0, 0);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -1332,6 +1358,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
context.CommandList.SetGraphicsRootDescriptorTable(RootHistoryMetadata, frameResources.HistoryMetadataDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(RootHistoryControl, frameResources.HistoryControlDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(RootSdfObjects, frameResources.SdfObjectDescriptor.Gpu);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(RootTemporalGaussians, frameResources.TemporalGaussianDescriptor.Gpu);
|
||||
|
||||
context.CommandList.RSSetViewports(viewport);
|
||||
context.CommandList.RSSetScissorRects(scissorRect);
|
||||
|
|
@ -1352,13 +1379,14 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
}
|
||||
}
|
||||
|
||||
private void UploadSdfLightResources(ID3D12GraphicsCommandList activeCommandList, FrameResources frameResources)
|
||||
private void UploadSceneStructuredResources(ID3D12GraphicsCommandList activeCommandList, FrameResources frameResources)
|
||||
{
|
||||
activeCommandList.BeginEvent("SDF State Upload");
|
||||
try
|
||||
{
|
||||
sdfLightBuffer.Upload(activeCommandList, frameResources.UploadRing, sdfLights);
|
||||
sdfObjectBuffer.Upload(activeCommandList, frameResources.UploadRing, sdfObjects);
|
||||
sdfObjectBuffer.Upload(activeCommandList, frameResources.UploadRing, sdfObjects);
|
||||
temporalGaussianBuffer.Upload(activeCommandList, frameResources.UploadRing, temporalGaussians);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -1399,6 +1427,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
{
|
||||
Array.Clear(sdfObjects);
|
||||
Array.Clear(sdfLights);
|
||||
Array.Clear(temporalGaussians);
|
||||
temporalGaussianCount = 0;
|
||||
heightFieldBrushConstants = D3D12HeightFieldBrushConstants.FromBrushes(scene.HeightFieldBrushes);
|
||||
|
||||
var objectCount = Math.Min(scene.SdfObjects.Count, MaxSdfObjectCount);
|
||||
|
|
@ -1412,6 +1442,28 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
{
|
||||
sdfLights[index] = scene.SdfLights[index];
|
||||
}
|
||||
|
||||
var gaussianCount = Math.Min(scene.TemporalGaussianField.Gaussians.Count, MaxTemporalGaussianCount);
|
||||
temporalGaussianCount = gaussianCount;
|
||||
for (var index = 0; index < gaussianCount; index++)
|
||||
{
|
||||
temporalGaussians[index] = ToTemporalGaussianPacket(scene.TemporalGaussianField.Gaussians[index]);
|
||||
}
|
||||
}
|
||||
|
||||
private static D3D12TemporalGaussianPacket ToTemporalGaussianPacket(AquariumTemporalSdfGaussian gaussian)
|
||||
{
|
||||
var orientation = gaussian.Orientation.LengthSquared() <= 0.000001f
|
||||
? Quaternion.Identity
|
||||
: Quaternion.Normalize(gaussian.Orientation);
|
||||
return new D3D12TemporalGaussianPacket(
|
||||
new Vector4(gaussian.Center, gaussian.HistoryWeight),
|
||||
new Vector4(gaussian.PreviousCenter, gaussian.FieldId),
|
||||
new Vector4(gaussian.Velocity, gaussian.Confidence),
|
||||
new Vector4(gaussian.Radii, gaussian.Falloff),
|
||||
new Vector4(orientation.X, orientation.Y, orientation.Z, orientation.W),
|
||||
gaussian.ColorOpacity,
|
||||
new Vector4(gaussian.ShapePower, 0.0f, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
private static float SceneFlags(AquariumSceneState scene)
|
||||
|
|
@ -1639,6 +1691,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
heightFieldBasePipelineState!,
|
||||
heightFieldBrushPipelineState!,
|
||||
scenePipelineState!,
|
||||
temporalGaussianPipelineState!,
|
||||
sdfProxyPipelineStates.Select(pipeline => pipeline!).ToArray(),
|
||||
bloomPrefilterPipelineState!,
|
||||
bloomDownsamplePipelineState!,
|
||||
|
|
@ -1653,6 +1706,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
heightFieldBasePipelineState = pipelines.HeightFieldBase;
|
||||
heightFieldBrushPipelineState = pipelines.HeightFieldBrush;
|
||||
scenePipelineState = pipelines.Scene;
|
||||
temporalGaussianPipelineState = pipelines.TemporalGaussian;
|
||||
for (var index = 0; index < sdfProxyPipelineStates.Length; index++)
|
||||
{
|
||||
sdfProxyPipelineStates[index] = pipelines.SdfProxies[index];
|
||||
|
|
@ -1670,6 +1724,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
heightFieldBasePipelineState = null;
|
||||
heightFieldBrushPipelineState = null;
|
||||
scenePipelineState = null;
|
||||
temporalGaussianPipelineState = null;
|
||||
Array.Clear(sdfProxyPipelineStates);
|
||||
bloomPrefilterPipelineState = null;
|
||||
bloomDownsamplePipelineState = null;
|
||||
|
|
@ -1816,6 +1871,12 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
24,
|
||||
0,
|
||||
D3D12.DescriptorRangeOffsetAppend);
|
||||
var temporalGaussianRange = new DescriptorRange(
|
||||
DescriptorRangeType.ShaderResourceView,
|
||||
1,
|
||||
25,
|
||||
0,
|
||||
D3D12.DescriptorRangeOffsetAppend);
|
||||
var rootParameters = new[]
|
||||
{
|
||||
new RootParameter(new RootDescriptorTable([constantBufferRange]), ShaderVisibility.All),
|
||||
|
|
@ -1831,6 +1892,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
new RootParameter(new RootDescriptorTable([studioPmremRange]), ShaderVisibility.Pixel),
|
||||
new RootParameter(new RootDescriptorTable([studioIrradianceRange]), ShaderVisibility.Pixel),
|
||||
new RootParameter(new RootDescriptorTable([sdfObjectRange]), ShaderVisibility.All),
|
||||
new RootParameter(new RootDescriptorTable([temporalGaussianRange]), ShaderVisibility.All),
|
||||
};
|
||||
var staticSamplers = new[]
|
||||
{
|
||||
|
|
@ -1881,6 +1943,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
return CreateFullscreenPipelineState(path, "D3D12SdfObjectProxyVS", "D3D12SdfProxyPS", [SceneHdrFormat, SceneHdrFormat, SceneHdrFormat], enableDepth: true);
|
||||
}
|
||||
|
||||
private ID3D12PipelineState CreateTemporalGaussianPipelineState(string path)
|
||||
{
|
||||
return CreateFullscreenPipelineState(path, "D3D12TemporalGaussianVS", "D3D12TemporalGaussianPS", [SceneHdrFormat, SceneHdrFormat, SceneHdrFormat], enableDepth: true);
|
||||
}
|
||||
|
||||
private ID3D12PipelineState CreateBloomPrefilterPipelineState(string path)
|
||||
{
|
||||
return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12BloomPrefilterPS", SceneHdrFormat);
|
||||
|
|
@ -2061,11 +2128,13 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
float Exposure,
|
||||
float BloomIntensity,
|
||||
float BloomVeilIntensity,
|
||||
Vector4 CursorWorlds);
|
||||
Vector4 CursorWorlds,
|
||||
Vector4 TemporalGaussianInfo);
|
||||
|
||||
private sealed record D3D12ShaderPaths(
|
||||
string HeightField,
|
||||
string Scene,
|
||||
string TemporalGaussian,
|
||||
string SdfCommon,
|
||||
string SdfProxy,
|
||||
IReadOnlyList<string> SdfShaders,
|
||||
|
|
@ -2073,7 +2142,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
IReadOnlyList<string> Includes,
|
||||
string Post)
|
||||
{
|
||||
public IReadOnlyList<string> All { get; } = [HeightField, Scene, SdfCommon, SdfProxy, ..SdfShaders, SdfMath, ..Includes, Post];
|
||||
public IReadOnlyList<string> All { get; } = [HeightField, Scene, TemporalGaussian, SdfCommon, SdfProxy, ..SdfShaders, SdfMath, ..Includes, Post];
|
||||
|
||||
public static D3D12ShaderPaths FromManifest(string root, AquariumShaderManifest manifest)
|
||||
{
|
||||
|
|
@ -2084,6 +2153,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
return new D3D12ShaderPaths(
|
||||
shaderPath(manifest.HeightFieldShader),
|
||||
shaderPath(manifest.SceneShader),
|
||||
shaderPath(manifest.TemporalGaussianShader),
|
||||
shaderPath(manifest.SdfCommonInclude),
|
||||
shaderPath(manifest.SdfProxyInclude),
|
||||
manifest.SdfShaderPaths.Select(shaderPath).ToArray(),
|
||||
|
|
@ -2097,6 +2167,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
ID3D12PipelineState HeightFieldBase,
|
||||
ID3D12PipelineState HeightFieldBrush,
|
||||
ID3D12PipelineState Scene,
|
||||
ID3D12PipelineState TemporalGaussian,
|
||||
IReadOnlyList<ID3D12PipelineState> SdfProxies,
|
||||
ID3D12PipelineState BloomPrefilter,
|
||||
ID3D12PipelineState BloomDownsample,
|
||||
|
|
@ -2111,6 +2182,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
BloomBlurHorizontal.Dispose();
|
||||
BloomDownsample.Dispose();
|
||||
BloomPrefilter.Dispose();
|
||||
TemporalGaussian.Dispose();
|
||||
foreach (var sdfProxy in SdfProxies)
|
||||
{
|
||||
sdfProxy.Dispose();
|
||||
|
|
@ -2141,6 +2213,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
public D3D12DescriptorSlot SdfObjectDescriptor { get; set; }
|
||||
|
||||
public D3D12DescriptorSlot TemporalGaussianDescriptor { get; set; }
|
||||
|
||||
public D3D12DescriptorSlot StudioPmremDescriptor { get; set; }
|
||||
|
||||
public D3D12DescriptorSlot StudioIrradianceDescriptor { get; set; }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Aquarium.Engine.Render.Features;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly record struct D3D12TemporalGaussianPacket(
|
||||
Vector4 CenterHistoryWeight,
|
||||
Vector4 PreviousCenterFieldId,
|
||||
Vector4 VelocityConfidence,
|
||||
Vector4 RadiiFalloff,
|
||||
Vector4 Orientation,
|
||||
Vector4 ColorOpacity,
|
||||
Vector4 ShapePad);
|
||||
|
|
@ -22,6 +22,7 @@ cbuffer AquariumFrame : register(b0)
|
|||
float bloomIntensity;
|
||||
float bloomVeilIntensity;
|
||||
float4 cursorWorlds;
|
||||
float4 temporalGaussianInfo;
|
||||
};
|
||||
|
||||
cbuffer HeightFieldBrushes : register(b1)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ cbuffer AquariumFrame : register(b0)
|
|||
float bloomIntensity;
|
||||
float bloomVeilIntensity;
|
||||
float4 cursorWorlds;
|
||||
float4 temporalGaussianInfo;
|
||||
};
|
||||
|
||||
Texture2D<float4> sourceTexture : register(t0);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ cbuffer AquariumFrame : register(b0)
|
|||
float bloomIntensity;
|
||||
float bloomVeilIntensity;
|
||||
float4 cursorWorlds;
|
||||
float4 temporalGaussianInfo;
|
||||
};
|
||||
|
||||
Texture2D<float4> heightFieldTexture : register(t0);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ cbuffer AquariumFrame : register(b0)
|
|||
float bloomIntensity;
|
||||
float bloomVeilIntensity;
|
||||
float4 cursorWorlds;
|
||||
float4 temporalGaussianInfo;
|
||||
};
|
||||
|
||||
cbuffer HeightFieldBrushes : register(b1)
|
||||
|
|
|
|||
181
src/Aquarium.Engine/Render/Shaders/D3D12TemporalGaussian.hlsl
Normal file
181
src/Aquarium.Engine/Render/Shaders/D3D12TemporalGaussian.hlsl
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
cbuffer AquariumFrame : register(b0)
|
||||
{
|
||||
float2 resolution;
|
||||
float timeSeconds;
|
||||
float viewRadius;
|
||||
float3 cameraPosition;
|
||||
float farDistance;
|
||||
float3 cameraTarget;
|
||||
float sceneFlags;
|
||||
float2 viewCenter;
|
||||
float frameIndex;
|
||||
float previousTimeSeconds;
|
||||
float3 previousCameraPosition;
|
||||
float previousViewRadius;
|
||||
float3 previousCameraTarget;
|
||||
float previousSceneFlags;
|
||||
float2 previousViewCenter;
|
||||
float2 jitterPixels;
|
||||
float2 previousJitterPixels;
|
||||
float renderDebugMode;
|
||||
float exposure;
|
||||
float bloomIntensity;
|
||||
float bloomVeilIntensity;
|
||||
float4 cursorWorlds;
|
||||
float4 temporalGaussianInfo;
|
||||
};
|
||||
|
||||
struct TemporalGaussian
|
||||
{
|
||||
float4 centerHistoryWeight;
|
||||
float4 previousCenterFieldId;
|
||||
float4 velocityConfidence;
|
||||
float4 radiiFalloff;
|
||||
float4 orientation;
|
||||
float4 colorOpacity;
|
||||
float4 shapePad;
|
||||
};
|
||||
|
||||
StructuredBuffer<TemporalGaussian> temporalGaussians : register(t25);
|
||||
|
||||
struct TemporalGaussianVertexOut
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
nointerpolation uint gaussianIndex : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct SceneOut
|
||||
{
|
||||
float4 colorTravel : SV_Target0;
|
||||
float4 metadata : SV_Target1;
|
||||
float4 control : SV_Target2;
|
||||
float depth : SV_Depth;
|
||||
};
|
||||
|
||||
static const float FIELD_ID_TEMPORAL_GAUSSIAN_BASE = 2000.0;
|
||||
|
||||
void cameraBasis(float3 camera, float3 target, out float3 forward, out float3 right, out float3 up)
|
||||
{
|
||||
forward = normalize(target - camera);
|
||||
right = normalize(cross(forward, float3(0.0, 0.0, 1.0)));
|
||||
up = cross(right, forward);
|
||||
}
|
||||
|
||||
float3 rayDirectionForPixel(float2 pixel, float2 jitter, float3 camera, float3 target)
|
||||
{
|
||||
float2 ndc = ((pixel + jitter) * 2.0 - resolution) / resolution.y;
|
||||
float3 forward;
|
||||
float3 right;
|
||||
float3 up;
|
||||
cameraBasis(camera, target, forward, right, up);
|
||||
return normalize(forward * 1.6 + right * ndc.x + up * ndc.y);
|
||||
}
|
||||
|
||||
float3 rotateByQuaternion(float3 p, float4 q)
|
||||
{
|
||||
return p + 2.0 * cross(q.xyz, cross(q.xyz, p) + q.w * p);
|
||||
}
|
||||
|
||||
float3 inverseRotateByQuaternion(float3 p, float4 q)
|
||||
{
|
||||
return rotateByQuaternion(p, float4(-q.xyz, q.w));
|
||||
}
|
||||
|
||||
float4 safeNormalizeQuaternion(float4 q)
|
||||
{
|
||||
return dot(q, q) <= 0.000001 ? float4(0.0, 0.0, 0.0, 1.0) : normalize(q);
|
||||
}
|
||||
|
||||
float compactGaussianWeight(TemporalGaussian gaussian, float3 p)
|
||||
{
|
||||
float3 local = inverseRotateByQuaternion(p - gaussian.centerHistoryWeight.xyz, safeNormalizeQuaternion(gaussian.orientation));
|
||||
float3 radii = max(gaussian.radiiFalloff.xyz, 0.0001);
|
||||
float3 q = local / radii;
|
||||
float radiusSquared = dot(q, q);
|
||||
if (radiusSquared >= 1.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float falloff = max(gaussian.radiiFalloff.w, 0.0001);
|
||||
float edge = exp(-falloff);
|
||||
float value = exp(-falloff * radiusSquared);
|
||||
float compact = saturate((value - edge) / max(1.0 - edge, 0.000001));
|
||||
return pow(compact, max(gaussian.shapePad.x, 0.0001));
|
||||
}
|
||||
|
||||
TemporalGaussianVertexOut D3D12TemporalGaussianVS(uint vertexId : SV_VertexID, uint instanceId : SV_InstanceID)
|
||||
{
|
||||
float2 corners[6] =
|
||||
{
|
||||
float2(-1.0, -1.0),
|
||||
float2(1.0, -1.0),
|
||||
float2(1.0, 1.0),
|
||||
float2(-1.0, -1.0),
|
||||
float2(1.0, 1.0),
|
||||
float2(-1.0, 1.0),
|
||||
};
|
||||
|
||||
TemporalGaussian gaussian = temporalGaussians[instanceId];
|
||||
float3 forward;
|
||||
float3 right;
|
||||
float3 up;
|
||||
cameraBasis(cameraPosition, cameraTarget, forward, right, up);
|
||||
float3 center = gaussian.centerHistoryWeight.xyz;
|
||||
float3 delta = center - cameraPosition;
|
||||
float z = max(dot(delta, forward), 0.0001);
|
||||
float2 projected = float2(dot(delta, right), dot(delta, up)) / z * 1.6;
|
||||
float clipAspect = resolution.x / max(resolution.y, 1.0);
|
||||
float boundRadius = max(max(gaussian.radiiFalloff.x, gaussian.radiiFalloff.y), gaussian.radiiFalloff.z) * 1.12;
|
||||
float projectedRadius = boundRadius / z * 1.6 + 0.004;
|
||||
float2 clipCenter = float2(projected.x / clipAspect, projected.y);
|
||||
float2 clipRadius = float2(projectedRadius / clipAspect, projectedRadius);
|
||||
|
||||
TemporalGaussianVertexOut output;
|
||||
output.position = float4(clipCenter + corners[vertexId] * clipRadius, 0.0, 1.0);
|
||||
output.gaussianIndex = instanceId;
|
||||
return output;
|
||||
}
|
||||
|
||||
SceneOut D3D12TemporalGaussianPS(TemporalGaussianVertexOut input)
|
||||
{
|
||||
TemporalGaussian gaussian = temporalGaussians[input.gaussianIndex];
|
||||
float2 pixel = float2(input.position.x, resolution.y - input.position.y);
|
||||
float3 rayDirection = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, cameraTarget);
|
||||
float3 forward;
|
||||
float3 right;
|
||||
float3 up;
|
||||
cameraBasis(cameraPosition, cameraTarget, forward, right, up);
|
||||
|
||||
float planeDenominator = dot(rayDirection, forward);
|
||||
if (abs(planeDenominator) <= 0.00001)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
float travel = dot(gaussian.centerHistoryWeight.xyz - cameraPosition, forward) / planeDenominator;
|
||||
if (travel <= 0.0 || travel >= farDistance)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
float3 p = cameraPosition + rayDirection * travel;
|
||||
float weight = compactGaussianWeight(gaussian, p);
|
||||
float opacity = saturate(weight * gaussian.colorOpacity.w * gaussian.velocityConfidence.w);
|
||||
if (opacity <= 0.002)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
float4 orientation = safeNormalizeQuaternion(gaussian.orientation);
|
||||
float3 local = inverseRotateByQuaternion(p - gaussian.centerHistoryWeight.xyz, orientation);
|
||||
float3 radii = max(gaussian.radiiFalloff.xyz, 0.0001);
|
||||
float3 normal = normalize(rotateByQuaternion(local / (radii * radii), orientation));
|
||||
|
||||
SceneOut output;
|
||||
output.colorTravel = float4(gaussian.colorOpacity.rgb * opacity, min(travel, farDistance + 1.0));
|
||||
output.metadata = float4(FIELD_ID_TEMPORAL_GAUSSIAN_BASE + gaussian.previousCenterFieldId.w, normal);
|
||||
output.control = float4(opacity, saturate(gaussian.centerHistoryWeight.w), saturate(gaussian.shapePad.x / 8.0), 0.0);
|
||||
output.depth = saturate(travel / max(farDistance, 0.001));
|
||||
return output;
|
||||
}
|
||||
|
|
@ -148,3 +148,4 @@
|
|||
{"timestamp":"2026-05-18T09:58:37+01:00","topic":"zyphos-visible-sun-and-domain-zoom","lesson":"The primary star cannot remain only an SDF light if users need spatial orientation; it is now a rendered SDF object with emission/corona and a Solar navigation target. Camera zoom limits are now derived from the selected domain pose instead of a global 8-unit floor, so leaf and pebble domains can be inspected at their own scale while broad orbital domains still retain safe maximum framing.","files":["src/Aquarium.Zyphos/ZyphosRenderPlan.cs","src/Aquarium.Zyphos/ZyphosSceneBuilder.cs","src/Aquarium.Zyphos/Shaders/D3D12ZyphosStar.hlsl","src/Aquarium.Zyphos/ZyphosCameraComposer.cs","src/Aquarium.Zyphos/ZyphosRuntime.cs","src/Aquarium.Zyphos/ZyphosSpatialDomainCatalog.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosCameraComposerTests.cs"],"source":"user asked where the sun is and why zoom cannot reach the cool small features"}
|
||||
{"lesson":"The first live bridge from the fractal architecture into Zyphos SDF rendering is material/detail, not traced form: .aquageo now preserves multiple tile roots, height brush packets carry cube-tile face/level/x/y metadata, D3D12 binds that packet table into the SDF pass, and the planet shader evaluates authored brushes in cube-face tile space after hit. Evaluating all authored brushes inside sdfDistance was tested and cut because it pushed the live frame toward 50-100 ms; traced geometry needs selected-cut/resident packet policy first.","timestamp":"2026-05-18T11:28:00+01:00","files":["src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs","src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs","src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","research/rendering/fractal-brush-implementation-roadmap.md"],"source":"user pointed out the renderer was only a pile of legos and ordered the real machine to be built","topic":"zyphos-aquageo-tile-packet-sdf-bridge"}
|
||||
{"timestamp":"2026-05-18T12:22:00+01:00","topic":"fractal-temporal-detail-control","lesson":"Fractal cache influence now has a first TAA-facing lane. SdfSurface carries temporalDetail, SDF proxy writes it into scene-control.z, D3D12Post validates history continuity against the current and previous temporalDetail signal, and history-control.z preserves it across frames. Zyphos feeds this from authored cube-face brush material influence; other SDFs explicitly emit zero until they gain cache-owned detail.","files":["src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12SdfProxy.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","src/Aquarium.Epiphany/Shaders"],"source":"user said to weave the stochastic fractal cache into TAA buffers"}
|
||||
{"timestamp":"2026-05-18T18:09:50+01:00","topic":"temporal-sdf-gaussian-renderer-boundary","lesson":"Live sensor-fusion splats now enter Aquarium through an engine-owned temporal SDF Gaussian field instead of client-side renderer folklore. The contract carries stable keyed world-space Gaussians; `TemporalGaussianAccumulator` buffers observations with presentation delay and history weights; D3D12 uploads structured packets and renders an instanced compact-kernel splat pass into the existing scene/metadata/control targets. Scaling beyond 4096 splats belongs to Aquarium residency/binning, not LocalCastBridge.","files":["src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs","src/Aquarium.Engine/Render/Shaders/D3D12TemporalGaussian.hlsl","src/Aquarium.Engine/Render/D3D12Renderer.cs","docs/temporal-sdf-gaussian-field.md"],"source":"user directed the point-cloud/TAA renderer feature to be implemented on the Aquarium side for clean client consumption"}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ current_model:
|
|||
runtime_surface: docs/cult-runtime-surface.md
|
||||
native_spine: docs/vortice-spine.md
|
||||
tsr_inspired_taa_spec: docs/tsr-inspired-taa-spec.md
|
||||
temporal_sdf_gaussian_field: docs/temporal-sdf-gaussian-field.md
|
||||
input: docs/input.md
|
||||
zyphos_eusocial_sync: docs/zyphos-eusocial-sync.md
|
||||
hdr_pbr_presentation: research/rendering/hdr-pbr-presentation.md
|
||||
|
|
@ -109,6 +110,7 @@ renderer_state:
|
|||
- Face voice routing is no longer a singleton. Epiphany persists typed FaceVoiceEndpoint rows with id, display name, thread id, voice, prompt, enabled flag, XY proximity anchor, and an audible-radius scale. FaceVoiceRouter uses proximity only to choose the addressed endpoint for user input; enabled endpoints can all run concurrently so active rumination loops may speak regardless of listener distance. Distance shapes PCM output gain and stereo pan through AquariumAudioDocument/WasapiAudioDevice.
|
||||
- Global GraphicsSettings document feeding render debug, exposure, bloom intensity, and bloom veil.
|
||||
- Temporal resolve uses scene color, metadata, and control history only; dormant event history lanes are cut until a real producer and consumer contract exists.
|
||||
- Aquarium owns the temporal SDF Gaussian field renderer boundary: clients can publish `AquariumTemporalGaussianField`, `TemporalGaussianAccumulator` can buffer stable keyed observations in world space, and D3D12 lowers those packets into an instanced compact-kernel splat pass that writes normal scene color/travel/metadata/control targets.
|
||||
- Isolated Epiphany agent preview renders run through the real D3D12 renderer from src/Aquarium.Epiphany.AgentPreview; preview isolation is owned by a preview-only scene shader, while the engine exposes only final-frame PNG capture.
|
||||
- Zyphos is the first nontrivial non-Epiphany client: a planetary-scale demo with spherical-domain terrain, atmospheric rim lighting, night-side glints, fixed-sky Umbros, and first-pass eclipse cadence.
|
||||
- Zyphos/Umbros render-scale binary constants live in src/Aquarium.Zyphos/ZyphosUmbrosSystem.cs: Umbros is modeled as a 0.9-radius mutually tidally locked twin at 8 Zyphos radii, while the dim primary star phase moves through the Zyphos-local frame.
|
||||
|
|
@ -159,6 +161,7 @@ next_actions:
|
|||
- Use research/rendering/fractal-brush-implementation-roadmap.md as the actionable execution checklist for fractal brush work.
|
||||
- Follow docs/zyphos-eusocial-sync.md and E:\Projects\Eusocial Interbeing\Eusocial Interbeing\World\Zyphos Simulation Brief.md before turning Zyphos visual choices into setting claims.
|
||||
- Follow docs/tsr-inspired-taa-spec.md when changing current temporal diagnostics.
|
||||
- Use docs/temporal-sdf-gaussian-field.md before wiring LocalCastBridge visual sensor fusion into Aquarium or scaling the temporal Gaussian renderer beyond the current bounded instanced pass.
|
||||
- Promote future runtime knobs into typed CultCache documents before they become process folklore.
|
||||
- Next Face voice slice: replace text-only input with microphone/WebRTC or a native capture bridge, bind endpoint anchors to real Face/body spatial projections instead of manual XY rows, then move the transport contract from Codex JSON-RPC compatibility toward a typed CultNet FaceVoiceSession once Epiphany advertises that surface.
|
||||
- Keep Aquarium and Epiphany in one repo until the contracts and graph API are stable enough for Epiphany to move out without carrying engine policy or reload folklore with it.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
using System.Numerics;
|
||||
using Aquarium.Engine.Fractal.Temporal;
|
||||
|
||||
namespace Aquarium.Engine.Fractal.Tests;
|
||||
|
||||
public sealed class TemporalGaussianAccumulatorTests
|
||||
{
|
||||
[Fact]
|
||||
public void AccumulatorPredictsBufferedMotionAndExposesHistoryWeight()
|
||||
{
|
||||
var accumulator = new TemporalGaussianAccumulator(accumulationWindowSeconds: 2.0f, presentationDelaySeconds: 0.5f, smoothing: 1.0f);
|
||||
accumulator.Observe([
|
||||
Observation("ball", new Vector3(0.0f, 0.0f, 1.0f), time: 0.0f),
|
||||
Observation("ball", new Vector3(1.0f, 0.0f, 1.0f), time: 1.0f),
|
||||
]);
|
||||
|
||||
var field = accumulator.BuildField(renderTimeSeconds: 1.5f);
|
||||
var gaussian = Assert.Single(field.Gaussians);
|
||||
|
||||
Assert.Equal("ball", gaussian.StableKey);
|
||||
Assert.Equal(new Vector3(1.0f, 0.0f, 1.0f), gaussian.Center);
|
||||
Assert.Equal(new Vector3(1.0f, 0.0f, 0.0f), gaussian.Velocity);
|
||||
Assert.InRange(gaussian.HistoryWeight, 0.99f, 1.0f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AccumulatorExpiresSamplesOutsideWindow()
|
||||
{
|
||||
var accumulator = new TemporalGaussianAccumulator(accumulationWindowSeconds: 1.0f, presentationDelaySeconds: 0.0f);
|
||||
accumulator.Observe([Observation("old", Vector3.Zero, time: 0.0f)]);
|
||||
|
||||
var field = accumulator.BuildField(renderTimeSeconds: 2.0f);
|
||||
|
||||
Assert.Empty(field.Gaussians);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KernelIsCompactAnisotropicAndSdfLike()
|
||||
{
|
||||
var accumulator = new TemporalGaussianAccumulator(accumulationWindowSeconds: 2.0f, presentationDelaySeconds: 0.0f);
|
||||
accumulator.Observe([Observation("brush", Vector3.Zero, time: 0.0f, radii: new Vector3(2.0f, 1.0f, 1.0f))]);
|
||||
var gaussian = Assert.Single(accumulator.BuildField(0.0f).Gaussians);
|
||||
|
||||
Assert.Equal(1.0f, TemporalSdfGaussianKernel.CompactWeight(gaussian, Vector3.Zero), 6);
|
||||
Assert.Equal(0.0f, TemporalSdfGaussianKernel.CompactWeight(gaussian, new Vector3(2.0f, 0.0f, 0.0f)), 6);
|
||||
Assert.True(TemporalSdfGaussianKernel.CompactWeight(gaussian, new Vector3(1.5f, 0.0f, 0.0f)) > 0.0f);
|
||||
Assert.True(TemporalSdfGaussianKernel.CompactWeight(gaussian, new Vector3(0.0f, 1.5f, 0.0f)) == 0.0f);
|
||||
Assert.True(TemporalSdfGaussianKernel.SignedDistance(gaussian, Vector3.Zero) < 0.0f);
|
||||
Assert.Equal(0.0f, TemporalSdfGaussianKernel.SignedDistance(gaussian, new Vector3(2.0f, 0.0f, 0.0f)), 5);
|
||||
}
|
||||
|
||||
private static TemporalGaussianObservation Observation(
|
||||
string key,
|
||||
Vector3 center,
|
||||
float time,
|
||||
Vector3? radii = null)
|
||||
{
|
||||
return new TemporalGaussianObservation(
|
||||
key,
|
||||
center,
|
||||
radii ?? new Vector3(0.1f),
|
||||
Quaternion.Identity,
|
||||
new Vector4(1.0f),
|
||||
Confidence: 1.0f,
|
||||
ObservedTimeSeconds: time,
|
||||
FieldId: 12);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue