501 lines
14 KiB
C#
501 lines
14 KiB
C#
using System.Numerics;
|
|
using System.Runtime.InteropServices;
|
|
using Aquarium.Engine.Fractal;
|
|
|
|
namespace Aquarium.Engine.Render;
|
|
|
|
public sealed class AquariumRenderPlan
|
|
{
|
|
public AquariumRenderPlan()
|
|
{
|
|
Shaders = new AquariumShaderManifest();
|
|
Graph = new AquariumRenderGraphDescription();
|
|
}
|
|
|
|
public AquariumShaderManifest Shaders { get; }
|
|
|
|
public AquariumRenderGraphDescription Graph { get; }
|
|
}
|
|
|
|
public sealed class AquariumShaderManifest
|
|
{
|
|
private readonly List<string> sdfShaderPaths = [];
|
|
private readonly List<string> includePaths = [];
|
|
|
|
public string? ShaderRoot { get; private set; }
|
|
|
|
public string HeightFieldShader { get; private set; } = "D3D12HeightField.hlsl";
|
|
|
|
public string SceneShader { get; private set; } = "D3D12Scene.hlsl";
|
|
|
|
public string TemporalGaussianShader { get; private set; } = "D3D12TemporalGaussian.hlsl";
|
|
|
|
public string LocalCastFusionShader { get; private set; } = "D3D12LocalCastFusion.hlsl";
|
|
|
|
public string FractalReservoirShader { get; private set; } = "D3D12FractalReservoirCompute.hlsl";
|
|
|
|
public string FractalSplatRenderShader { get; private set; } = "D3D12FractalSplatRender.hlsl";
|
|
|
|
public string PostShader { get; private set; } = "D3D12Post.hlsl";
|
|
|
|
public string SdfCommonInclude { get; private set; } = "D3D12SdfCommon.hlsli";
|
|
|
|
public string SdfProxyInclude { get; private set; } = "D3D12SdfProxy.hlsli";
|
|
|
|
public string SdfMathInclude { get; private set; } = "D3D12SdfMath.hlsli";
|
|
|
|
public string? SdfLibraryInclude { get; private set; }
|
|
|
|
public IReadOnlyList<string> SdfShaderPaths => sdfShaderPaths;
|
|
|
|
public IReadOnlyList<string> IncludePaths => includePaths;
|
|
|
|
public AquariumShaderManifest Root(string path)
|
|
{
|
|
ShaderRoot = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest HeightField(string path)
|
|
{
|
|
HeightFieldShader = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest Scene(string path)
|
|
{
|
|
SceneShader = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest TemporalGaussian(string path)
|
|
{
|
|
TemporalGaussianShader = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest LocalCastFusion(string path)
|
|
{
|
|
LocalCastFusionShader = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest FractalReservoir(string path)
|
|
{
|
|
FractalReservoirShader = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest FractalSplatRender(string path)
|
|
{
|
|
FractalSplatRenderShader = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest Post(string path)
|
|
{
|
|
PostShader = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest SdfCommon(string path)
|
|
{
|
|
SdfCommonInclude = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest SdfProxy(string path)
|
|
{
|
|
SdfProxyInclude = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest SdfMath(string path)
|
|
{
|
|
SdfMathInclude = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest SdfLibrary(string? path)
|
|
{
|
|
SdfLibraryInclude = path;
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest Include(string path)
|
|
{
|
|
includePaths.Add(path);
|
|
return this;
|
|
}
|
|
|
|
public AquariumShaderManifest SdfShader(string path)
|
|
{
|
|
sdfShaderPaths.Add(path);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public sealed class AquariumRenderGraphDescription
|
|
{
|
|
private readonly List<AquariumRenderTargetDescription> renderTargets = [];
|
|
private readonly List<AquariumCameraDescription> cameras = [];
|
|
private readonly List<AquariumPassDescription> passes = [];
|
|
private readonly List<AquariumDebugViewDescription> debugViews = [];
|
|
|
|
public IReadOnlyList<AquariumRenderTargetDescription> RenderTargets => renderTargets;
|
|
|
|
public IReadOnlyList<AquariumCameraDescription> Cameras => cameras;
|
|
|
|
public IReadOnlyList<AquariumPassDescription> Passes => passes;
|
|
|
|
public IReadOnlyList<AquariumDebugViewDescription> DebugViews => debugViews;
|
|
|
|
public RenderTargetHandle RenderTarget(string name, RenderFormat format, AquariumTargetSize size, bool sampled = true, int historyFrames = 0)
|
|
{
|
|
var handle = new RenderTargetHandle(name);
|
|
renderTargets.Add(new AquariumRenderTargetDescription(handle, format, size, sampled, historyFrames));
|
|
return handle;
|
|
}
|
|
|
|
public CameraHandle Camera(string name)
|
|
{
|
|
var handle = new CameraHandle(name);
|
|
cameras.Add(new AquariumCameraDescription(handle));
|
|
return handle;
|
|
}
|
|
|
|
public PassHandle Pass(string name, AquariumPassKind kind)
|
|
{
|
|
var handle = new PassHandle(name);
|
|
passes.Add(new AquariumPassDescription(handle, kind));
|
|
return handle;
|
|
}
|
|
|
|
public AquariumRenderGraphDescription DebugView(string name, RenderTargetHandle target)
|
|
{
|
|
debugViews.Add(new AquariumDebugViewDescription(name, target));
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public readonly record struct RenderTargetHandle(string Name);
|
|
|
|
public readonly record struct DepthTargetHandle(string Name);
|
|
|
|
public readonly record struct CameraHandle(string Name);
|
|
|
|
public readonly record struct ShaderHandle(string Name);
|
|
|
|
public readonly record struct BufferHandle<T>(string Name) where T : unmanaged;
|
|
|
|
public readonly record struct TextureHandle(string Name);
|
|
|
|
public readonly record struct PassHandle(string Name);
|
|
|
|
public readonly record struct AquariumRenderTargetDescription(
|
|
RenderTargetHandle Handle,
|
|
RenderFormat Format,
|
|
AquariumTargetSize Size,
|
|
bool Sampled,
|
|
int HistoryFrames);
|
|
|
|
public readonly record struct AquariumCameraDescription(CameraHandle Handle);
|
|
|
|
public readonly record struct AquariumPassDescription(PassHandle Handle, AquariumPassKind Kind);
|
|
|
|
public readonly record struct AquariumDebugViewDescription(string Name, RenderTargetHandle Target);
|
|
|
|
public readonly record struct AquariumTargetSize(AquariumTargetSizeKind Kind, int Width, int Height, float Scale)
|
|
{
|
|
public static AquariumTargetSize Fixed(int width, int height) => new(AquariumTargetSizeKind.Fixed, width, height, 1.0f);
|
|
|
|
public static AquariumTargetSize MatchWindow(float scale = 1.0f) => new(AquariumTargetSizeKind.MatchWindow, 0, 0, scale);
|
|
}
|
|
|
|
public enum AquariumTargetSizeKind
|
|
{
|
|
Fixed,
|
|
MatchWindow,
|
|
}
|
|
|
|
public enum RenderFormat
|
|
{
|
|
Unknown,
|
|
R16Float,
|
|
Rgba16Float,
|
|
Bgra8Unorm,
|
|
Depth32Float,
|
|
}
|
|
|
|
public enum AquariumPassKind
|
|
{
|
|
Fullscreen,
|
|
Proxy,
|
|
Instanced,
|
|
Compute,
|
|
Copy,
|
|
Present,
|
|
Overlay,
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public readonly record struct AquariumSdfLight(
|
|
Vector4 CenterRadius,
|
|
Vector4 RadianceFieldId);
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public readonly record struct AquariumSdfObject(
|
|
Vector4 CenterRadius,
|
|
Vector4 PreviousCenterPad,
|
|
Vector4 State);
|
|
|
|
public readonly record struct AquariumHeightFieldBrush(
|
|
Vector2 Center,
|
|
float Radius,
|
|
float Power,
|
|
float Amplitude,
|
|
float WaveAmplitude,
|
|
float WaveFrequency,
|
|
float WaveSpeed,
|
|
float WaveSinePower,
|
|
float RadiusY = 0.0f,
|
|
float RotationRadians = 0.0f,
|
|
float EnvelopeFalloff = 0.0f,
|
|
float DomainFace = -1.0f,
|
|
float DomainLevel = 0.0f,
|
|
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 readonly record struct AquariumGpuFusionSeed(
|
|
string StableKey,
|
|
Vector3 Center,
|
|
Vector3 PreviousCenter,
|
|
Vector3 Velocity,
|
|
Vector3 Radii,
|
|
Vector4 ColorOpacity,
|
|
float Confidence,
|
|
float HistoryWeight,
|
|
float Falloff,
|
|
float ShapePower,
|
|
int FieldId);
|
|
|
|
public enum AquariumGpuSensorKind
|
|
{
|
|
Unknown,
|
|
RgbCamera,
|
|
HighRateTracker,
|
|
LeapPackedMap,
|
|
}
|
|
|
|
public enum AquariumGpuSensorPixelFormat
|
|
{
|
|
Unknown,
|
|
Bgra8Unorm,
|
|
Rgba8Unorm,
|
|
R8Unorm,
|
|
R16Unorm,
|
|
R16Float,
|
|
Rg8Unorm,
|
|
LeapPackedMap,
|
|
}
|
|
|
|
public readonly record struct AquariumExternalGpuTexture(
|
|
TextureHandle Handle,
|
|
IntPtr SharedHandle,
|
|
int Width,
|
|
int Height,
|
|
AquariumGpuSensorPixelFormat PixelFormat,
|
|
long TimestampNs,
|
|
int PlaneIndex = 0,
|
|
string SharedHandleName = "");
|
|
|
|
public readonly record struct AquariumGpuSensorCamera(
|
|
string SensorId,
|
|
AquariumGpuSensorKind Kind,
|
|
Matrix4x4 WorldFromSensor,
|
|
Matrix4x4 SensorFromWorld,
|
|
Vector4 Intrinsics,
|
|
Vector4 Distortion01,
|
|
Vector4 Distortion23,
|
|
int Width,
|
|
int Height,
|
|
int FirstTextureIndex,
|
|
int TextureCount,
|
|
long TimestampNs);
|
|
|
|
public sealed class AquariumGpuSensorFrame
|
|
{
|
|
public static AquariumGpuSensorFrame Empty { get; } = new();
|
|
|
|
public IReadOnlyList<AquariumGpuSensorCamera> Cameras { get; init; } = [];
|
|
|
|
public IReadOnlyList<AquariumExternalGpuTexture> ExternalTextures { get; init; } = [];
|
|
|
|
public float AccumulationWindowSeconds { get; init; }
|
|
|
|
public float PresentationDelaySeconds { get; init; }
|
|
|
|
public bool HasInput => Cameras.Count > 0 || ExternalTextures.Count > 0;
|
|
}
|
|
|
|
public enum AquariumAcousticConstraintKind
|
|
{
|
|
Unknown,
|
|
UltrasonicReflector,
|
|
VoiceTdoa,
|
|
SpeakerProbe,
|
|
ClapImpact,
|
|
}
|
|
|
|
public readonly record struct AquariumAcousticConstraint(
|
|
string StableKey,
|
|
AquariumAcousticConstraintKind Kind,
|
|
Vector3 Position,
|
|
Vector3 Velocity,
|
|
float RadiusMeters,
|
|
float Confidence,
|
|
long TimestampNs);
|
|
|
|
public sealed class AquariumAcousticFieldFrame
|
|
{
|
|
public static AquariumAcousticFieldFrame Empty { get; } = new();
|
|
|
|
public IReadOnlyList<AquariumAcousticConstraint> Constraints { get; init; } = [];
|
|
|
|
public long TimingOracleNs { get; init; }
|
|
|
|
public float TimingConfidence { get; init; }
|
|
|
|
public float TimingUncertaintyMicroseconds { get; init; }
|
|
|
|
public float AccumulationWindowSeconds { get; init; }
|
|
|
|
public float PresentationDelaySeconds { get; init; }
|
|
|
|
public bool HasInput => Constraints.Count > 0;
|
|
}
|
|
|
|
public readonly record struct AquariumClapCalibrationEvent(
|
|
string StableKey,
|
|
Vector3 Position,
|
|
long AcousticOracleNs,
|
|
long VisualObservedNs,
|
|
float TimingUncertaintyMicroseconds,
|
|
float VisualConfidence,
|
|
float AcousticConfidence);
|
|
|
|
public sealed class AquariumCalibrationEventFrame
|
|
{
|
|
public static AquariumCalibrationEventFrame Empty { get; } = new();
|
|
|
|
public IReadOnlyList<AquariumClapCalibrationEvent> ClapEvents { get; init; } = [];
|
|
|
|
public bool HasInput => ClapEvents.Count > 0;
|
|
}
|
|
|
|
public sealed class AquariumGpuFusionField
|
|
{
|
|
public static AquariumGpuFusionField Empty { get; } = new();
|
|
|
|
public IReadOnlyList<AquariumGpuFusionSeed> Seeds { get; init; } = [];
|
|
|
|
public AquariumGpuFusionPointBuffer PointBuffer { get; init; }
|
|
|
|
public float AccumulationWindowSeconds { get; init; }
|
|
|
|
public float PresentationDelaySeconds { get; init; }
|
|
|
|
public bool HasInput => Seeds.Count > 0 || PointBuffer.HasInput;
|
|
}
|
|
|
|
public readonly record struct AquariumGpuFusionPointBuffer(
|
|
IntPtr Buffer,
|
|
int Count,
|
|
int StrideBytes)
|
|
{
|
|
// Caller owns the memory and must keep it stable until the render frame has uploaded it.
|
|
public bool HasInput => Buffer != IntPtr.Zero && Count > 0 && StrideBytes > 0;
|
|
}
|
|
|
|
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 AquariumFractalReservoirField
|
|
{
|
|
public static AquariumFractalReservoirField Empty { get; } = new();
|
|
|
|
public int SplatCount { get; init; }
|
|
|
|
public int Depth { get; init; } = 8;
|
|
|
|
public uint Seed { get; init; } = 0xA17EA11u;
|
|
|
|
public int CandidatesPerReservoirUpdate { get; init; } = 2;
|
|
|
|
public int SplatUpdatesPerFrame { get; init; }
|
|
|
|
public int ReservoirUpdatesPerPass { get; init; }
|
|
|
|
public IReadOnlyList<AquariumPackedFractalIfsTransform> ProgramTransforms { get; init; } = [];
|
|
|
|
public Vector4 WorldCenterRadius { get; init; }
|
|
|
|
public bool HasInput =>
|
|
SplatCount > 0 &&
|
|
Depth > 0 &&
|
|
CandidatesPerReservoirUpdate > 0 &&
|
|
SplatUpdatesPerFrame > 0 &&
|
|
SplatUpdatesPerFrame <= SplatCount &&
|
|
ReservoirUpdatesPerPass > 0 &&
|
|
ReservoirUpdatesPerPass <= SplatCount;
|
|
}
|
|
|
|
public sealed class AquariumSceneState
|
|
{
|
|
public static AquariumSceneState Empty { get; } = new();
|
|
|
|
public bool TraceHeightFieldSurface { get; init; } = true;
|
|
|
|
public bool UseStarfieldBackground { get; init; }
|
|
|
|
public IReadOnlyList<AquariumHeightFieldBrush> HeightFieldBrushes { get; init; } = [];
|
|
|
|
public IReadOnlyList<AquariumSdfObject> SdfObjects { get; init; } = [];
|
|
|
|
public IReadOnlyList<AquariumSdfLight> SdfLights { get; init; } = [];
|
|
|
|
public AquariumTemporalGaussianField TemporalGaussianField { get; init; } = AquariumTemporalGaussianField.Empty;
|
|
|
|
public AquariumFractalReservoirField FractalReservoirField { get; init; } = AquariumFractalReservoirField.Empty;
|
|
|
|
public AquariumGpuSensorFrame GpuSensorFrame { get; init; } = AquariumGpuSensorFrame.Empty;
|
|
|
|
public AquariumAcousticFieldFrame AcousticFieldFrame { get; init; } = AquariumAcousticFieldFrame.Empty;
|
|
|
|
public AquariumCalibrationEventFrame CalibrationEventFrame { get; init; } = AquariumCalibrationEventFrame.Empty;
|
|
|
|
public AquariumGpuFusionField GpuFusionField { get; init; } = AquariumGpuFusionField.Empty;
|
|
}
|