Add residual quadtree erosion residency
This commit is contained in:
parent
db69e28d2c
commit
5158bb4103
15 changed files with 373 additions and 93 deletions
|
|
@ -35,7 +35,7 @@ parent/child residual transitions have not been built.
|
|||
| 3. Physical bands | Complete | Wavelength selection, fractional terminal octave, unresolved bound |
|
||||
| 4. GPU pages | Complete | Spherical borders, sibling seam tests, GPU summary reduction |
|
||||
| 5. Page-backed intersection | Complete | Persistent page and summary buffers, conservative bounds/steps, bracketed refinement, radial hit parity |
|
||||
| 6. Quadtree transitions | Not started | Parent/child residual ownership still to implement |
|
||||
| 6. Quadtree transitions | In progress | Residual atlas and lifecycle probes complete; visible no-pop capture remains |
|
||||
| 7. Unified differentials/materials | Not started | Final composed derivative contract still to implement |
|
||||
| 8. Profiling/backend decision | Not started | No frame-time or memory-budget claim yet |
|
||||
|
||||
|
|
|
|||
|
|
@ -540,14 +540,23 @@ public readonly record struct AquariumPlanetarySurfacePageInput(Vector4 Directio
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly record struct AquariumPlanetarySurfacePageMetadata(Vector4 Address, Vector4 Layout, Vector4 Bounds, Vector4 State);
|
||||
|
||||
public sealed class AquariumPlanetarySurfacePage
|
||||
{
|
||||
public long ContentKey { get; init; }
|
||||
public IReadOnlyList<AquariumPlanetarySurfacePageInput> Samples { get; init; } = [];
|
||||
public AquariumPlanetarySurfacePageMetadata Metadata { get; init; }
|
||||
public bool HasInput => ContentKey != 0 && Samples.Count > 0;
|
||||
}
|
||||
|
||||
public sealed class AquariumPlanetarySurfacePageSet
|
||||
{
|
||||
public static AquariumPlanetarySurfacePageSet Empty { get; } = new();
|
||||
public string GeneratorEntryPoint { get; init; } = "D3D12PlanetaryTerrainPageCS";
|
||||
public long Version { get; init; }
|
||||
public IReadOnlyList<AquariumPlanetarySurfacePageInput> Samples { get; init; } = [];
|
||||
public AquariumPlanetarySurfacePageMetadata Metadata { get; init; }
|
||||
public bool HasInput => Version > 0 && Samples.Count > 0;
|
||||
public long ContentVersion { get; init; }
|
||||
public long PresentationVersion { get; init; }
|
||||
public IReadOnlyList<AquariumPlanetarySurfacePage> Pages { get; init; } = [];
|
||||
public int SampleCount => Pages.Sum(page => page.Samples.Count);
|
||||
public bool HasInput => ContentVersion != 0 && Pages.Count > 0 && Pages.All(page => page.HasInput);
|
||||
}
|
||||
|
||||
public sealed class AquariumBokushoBrushFrame
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ internal static class D3D12ComputeProbe
|
|||
{
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(0, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(0, 0), ShaderVisibility.All),
|
||||
new RootParameter(new RootConstants(0, 0, 1), ShaderVisibility.All),
|
||||
new RootParameter(new RootConstants(0, 0, 3), ShaderVisibility.All),
|
||||
};
|
||||
var signatureDescription = new RootSignatureDescription(RootSignatureFlags.None, parameters, []);
|
||||
using var signature = device.CreateRootSignature(0, in signatureDescription, RootSignatureVersion.Version1);
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private const int RootPlanetarySurfacePage = 29;
|
||||
private const int RootPlanetarySurfacePageMetadata = 30;
|
||||
private const int RootPlanetarySurfacePageSummary = 31;
|
||||
private const int RootPlanetarySurfacePageSet = 32;
|
||||
private const int RootFusionFrameConstants = 0;
|
||||
private const int RootFusionSeeds = 1;
|
||||
private const int RootFusionSensorCameras = 2;
|
||||
|
|
@ -321,8 +322,10 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private D3D12StructuredBuffer? planetarySurfacePageOutputBuffer;
|
||||
private D3D12StructuredBuffer? planetarySurfacePageMetadataBuffer;
|
||||
private D3D12StructuredBuffer? planetarySurfacePageSummaryBuffer;
|
||||
private D3D12StructuredBuffer? planetarySurfacePageSetBuffer;
|
||||
private AquariumPlanetarySurfacePageSet activePlanetarySurfacePages = AquariumPlanetarySurfacePageSet.Empty;
|
||||
private long residentPlanetarySurfacePageVersion;
|
||||
private long residentPlanetarySurfacePageContentVersion;
|
||||
private long residentPlanetarySurfacePagePresentationVersion;
|
||||
private D3D12StructuredBuffer fieldReservoirCandidateBuffer = null!;
|
||||
private D3D12StructuredBuffer fieldReservoirLockBuffer = null!;
|
||||
private readonly List<D3D12TubeFieldDrawBatch> tubeFieldDrawBatches = [];
|
||||
|
|
@ -1762,6 +1765,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
bokushoSourcePointBuffer.Dispose();
|
||||
bokushoPageDensityBuffer.Dispose();
|
||||
planetarySurfacePageMetadataBuffer?.Dispose();
|
||||
planetarySurfacePageSetBuffer?.Dispose();
|
||||
planetarySurfacePageSummaryBuffer?.Dispose();
|
||||
planetarySurfacePageOutputBuffer?.Dispose();
|
||||
planetarySurfacePageInputBuffer?.Dispose();
|
||||
|
|
@ -3777,6 +3781,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
context.CommandList.SetGraphicsRootShaderResourceView(RootPlanetarySurfacePage, planetarySurfacePageOutputBuffer.Resource.GPUVirtualAddress);
|
||||
context.CommandList.SetGraphicsRootShaderResourceView(RootPlanetarySurfacePageMetadata, planetarySurfacePageMetadataBuffer.Resource.GPUVirtualAddress);
|
||||
context.CommandList.SetGraphicsRootShaderResourceView(RootPlanetarySurfacePageSummary, planetarySurfacePageSummaryBuffer!.Resource.GPUVirtualAddress);
|
||||
context.CommandList.SetGraphicsRootShaderResourceView(RootPlanetarySurfacePageSet, planetarySurfacePageSetBuffer!.Resource.GPUVirtualAddress);
|
||||
context.CommandList.SetGraphicsRootDescriptorTable(RootSceneOverdraw, frameResources.SceneOverdrawDescriptor.Gpu);
|
||||
|
||||
context.CommandList.RSSetViewports(viewport);
|
||||
|
|
@ -3898,32 +3903,52 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
private void EnsurePlanetarySurfacePageBuffers()
|
||||
{
|
||||
var count = Math.Max(activePlanetarySurfacePages.Samples.Count, 1);
|
||||
if (planetarySurfacePageInputBuffer?.ElementCount == count) return;
|
||||
planetarySurfacePageMetadataBuffer?.Dispose(); planetarySurfacePageSummaryBuffer?.Dispose(); planetarySurfacePageOutputBuffer?.Dispose(); planetarySurfacePageInputBuffer?.Dispose();
|
||||
planetarySurfacePageInputBuffer = new D3D12StructuredBuffer(device, count, Marshal.SizeOf<AquariumPlanetarySurfacePageInput>(), "Aquarium Planetary Page Inputs");
|
||||
planetarySurfacePageOutputBuffer = new D3D12StructuredBuffer(device, count, 32, "Aquarium Planetary Page Outputs", allowUnorderedAccess: true);
|
||||
planetarySurfacePageMetadataBuffer = new D3D12StructuredBuffer(device, 1, Marshal.SizeOf<AquariumPlanetarySurfacePageMetadata>(), "Aquarium Planetary Page Metadata");
|
||||
planetarySurfacePageSummaryBuffer = new D3D12StructuredBuffer(device, 1, 32, "Aquarium Planetary Page Summary", allowUnorderedAccess: true);
|
||||
residentPlanetarySurfacePageVersion = 0;
|
||||
var sampleCount = Math.Max(activePlanetarySurfacePages.SampleCount, 1);
|
||||
var pageCount = Math.Max(activePlanetarySurfacePages.Pages.Count, 1);
|
||||
if (planetarySurfacePageInputBuffer?.ElementCount == sampleCount && planetarySurfacePageMetadataBuffer?.ElementCount == pageCount) return;
|
||||
planetarySurfacePageSetBuffer?.Dispose(); planetarySurfacePageMetadataBuffer?.Dispose(); planetarySurfacePageSummaryBuffer?.Dispose(); planetarySurfacePageOutputBuffer?.Dispose(); planetarySurfacePageInputBuffer?.Dispose();
|
||||
planetarySurfacePageInputBuffer = new D3D12StructuredBuffer(device, sampleCount, Marshal.SizeOf<AquariumPlanetarySurfacePageInput>(), "Aquarium Planetary Page Inputs");
|
||||
planetarySurfacePageOutputBuffer = new D3D12StructuredBuffer(device, sampleCount, 32, "Aquarium Planetary Page Outputs", allowUnorderedAccess: true);
|
||||
planetarySurfacePageMetadataBuffer = new D3D12StructuredBuffer(device, pageCount, Marshal.SizeOf<AquariumPlanetarySurfacePageMetadata>(), "Aquarium Planetary Page Metadata");
|
||||
planetarySurfacePageSummaryBuffer = new D3D12StructuredBuffer(device, pageCount, 32, "Aquarium Planetary Page Summaries", allowUnorderedAccess: true);
|
||||
planetarySurfacePageSetBuffer = new D3D12StructuredBuffer(device, 1, 16, "Aquarium Planetary Page Set");
|
||||
residentPlanetarySurfacePageContentVersion = 0;
|
||||
residentPlanetarySurfacePagePresentationVersion = 0;
|
||||
}
|
||||
|
||||
private void DispatchPlanetarySurfacePage(ID3D12GraphicsCommandList activeCommandList, FrameResources frameResources)
|
||||
{
|
||||
if (planetarySurfacePageInputBuffer is null || planetarySurfacePageOutputBuffer is null || planetarySurfacePageMetadataBuffer is null || planetarySurfacePageSummaryBuffer is null) return;
|
||||
if (planetarySurfacePageInputBuffer is null || planetarySurfacePageOutputBuffer is null || planetarySurfacePageMetadataBuffer is null || planetarySurfacePageSummaryBuffer is null || planetarySurfacePageSetBuffer is null) return;
|
||||
if (!activePlanetarySurfacePages.HasInput)
|
||||
{
|
||||
if (residentPlanetarySurfacePageVersion != 0)
|
||||
if (residentPlanetarySurfacePageContentVersion != 0)
|
||||
{
|
||||
planetarySurfacePageMetadataBuffer.Upload(activeCommandList, frameResources.UploadRing, new[] { default(AquariumPlanetarySurfacePageMetadata) });
|
||||
residentPlanetarySurfacePageVersion = 0;
|
||||
planetarySurfacePageSetBuffer.Upload(activeCommandList, frameResources.UploadRing, new[] { Vector4.Zero });
|
||||
residentPlanetarySurfacePageContentVersion = 0;
|
||||
residentPlanetarySurfacePagePresentationVersion = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (residentPlanetarySurfacePageVersion == activePlanetarySurfacePages.Version) return;
|
||||
var samples = activePlanetarySurfacePages.Samples as AquariumPlanetarySurfacePageInput[] ?? activePlanetarySurfacePages.Samples.ToArray();
|
||||
var pages = activePlanetarySurfacePages.Pages;
|
||||
var metadata = new AquariumPlanetarySurfacePageMetadata[pages.Count];
|
||||
var samples = new AquariumPlanetarySurfacePageInput[activePlanetarySurfacePages.SampleCount];
|
||||
var sampleOffset = 0;
|
||||
for (var pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||
{
|
||||
var page = pages[pageIndex];
|
||||
for (var index = 0; index < page.Samples.Count; index++) samples[sampleOffset + index] = page.Samples[index];
|
||||
metadata[pageIndex] = page.Metadata with { Layout = new Vector4(sampleOffset, page.Metadata.Layout.Y, page.Metadata.Layout.Z, page.Metadata.Layout.W) };
|
||||
sampleOffset += page.Samples.Count;
|
||||
}
|
||||
if (residentPlanetarySurfacePagePresentationVersion != activePlanetarySurfacePages.PresentationVersion)
|
||||
{
|
||||
planetarySurfacePageMetadataBuffer.Upload(activeCommandList, frameResources.UploadRing, metadata);
|
||||
planetarySurfacePageSetBuffer.Upload(activeCommandList, frameResources.UploadRing, new[] { new Vector4(pages.Count, 0, 0, 1) });
|
||||
residentPlanetarySurfacePagePresentationVersion = activePlanetarySurfacePages.PresentationVersion;
|
||||
}
|
||||
if (residentPlanetarySurfacePageContentVersion == activePlanetarySurfacePages.ContentVersion) return;
|
||||
planetarySurfacePageInputBuffer.Upload(activeCommandList, frameResources.UploadRing, samples);
|
||||
planetarySurfacePageMetadataBuffer.Upload(activeCommandList, frameResources.UploadRing, new[] { activePlanetarySurfacePages.Metadata });
|
||||
planetarySurfacePageOutputBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
activeCommandList.SetComputeRootSignature(planetarySurfacePageRootSignature);
|
||||
activeCommandList.SetPipelineState(planetarySurfacePagePipelineState!);
|
||||
|
|
@ -3937,12 +3962,17 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
activeCommandList.SetPipelineState(planetarySurfacePageSummaryPipelineState!);
|
||||
activeCommandList.SetComputeRootShaderResourceView(0, planetarySurfacePageOutputBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(1, planetarySurfacePageSummaryBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRoot32BitConstant(2, (uint)samples.Length, 0);
|
||||
activeCommandList.Dispatch(1, 1, 1);
|
||||
for (var pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||
{
|
||||
activeCommandList.SetComputeRoot32BitConstant(2, (uint)pages[pageIndex].Samples.Count, 0);
|
||||
activeCommandList.SetComputeRoot32BitConstant(2, (uint)metadata[pageIndex].Layout.X, 1);
|
||||
activeCommandList.SetComputeRoot32BitConstant(2, (uint)pageIndex, 2);
|
||||
activeCommandList.Dispatch(1, 1, 1);
|
||||
}
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(planetarySurfacePageSummaryBuffer.Resource));
|
||||
planetarySurfacePageSummaryBuffer.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
planetarySurfacePageOutputBuffer.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
residentPlanetarySurfacePageVersion = activePlanetarySurfacePages.Version;
|
||||
residentPlanetarySurfacePageContentVersion = activePlanetarySurfacePages.ContentVersion;
|
||||
}
|
||||
|
||||
private void DispatchFractalReservoirs(ID3D12GraphicsCommandList activeCommandList, FrameResources frameResources)
|
||||
|
|
@ -6326,6 +6356,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(81, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(82, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(83, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(84, 0), ShaderVisibility.All),
|
||||
};
|
||||
var staticSamplers = new[]
|
||||
{
|
||||
|
|
@ -6357,7 +6388,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
{
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(0, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(0, 0), ShaderVisibility.All),
|
||||
new RootParameter(new RootConstants(0, 0, 1), ShaderVisibility.All),
|
||||
new RootParameter(new RootConstants(0, 0, 3), ShaderVisibility.All),
|
||||
};
|
||||
var description = new RootSignatureDescription(RootSignatureFlags.None, parameters, []);
|
||||
return device.CreateRootSignature(0, in description, RootSignatureVersion.Version1);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ struct PageOutput { float4 height_gradient; float4 masks; };
|
|||
struct PageSummary { float4 bounds; float4 metadata; };
|
||||
StructuredBuffer<PageOutput> summary_inputs : register(t0);
|
||||
RWStructuredBuffer<PageSummary> summary_outputs : register(u0);
|
||||
cbuffer PageConstants : register(b0) { uint page_sample_count; }
|
||||
cbuffer PageConstants : register(b0) { uint page_sample_count; uint page_sample_offset; uint page_summary_index; }
|
||||
|
||||
[numthreads(1,1,1)]
|
||||
void D3D12ZyphosTerrainPageSummaryCS(uint3 id : SV_DispatchThreadID)
|
||||
|
|
@ -14,12 +14,12 @@ void D3D12ZyphosTerrainPageSummaryCS(uint3 id : SV_DispatchThreadID)
|
|||
float maximum_unresolved = 0.0;
|
||||
[loop] for (uint index = 0; index < page_sample_count; index++)
|
||||
{
|
||||
float4 sample = summary_inputs[index].height_gradient;
|
||||
float4 sample = summary_inputs[page_sample_offset + index].height_gradient;
|
||||
minimum_height = min(minimum_height, sample.x);
|
||||
maximum_height = max(maximum_height, sample.x);
|
||||
maximum_slope = max(maximum_slope, length(sample.yz));
|
||||
maximum_unresolved = max(maximum_unresolved, sample.w);
|
||||
}
|
||||
summary_outputs[0].bounds = float4(minimum_height, maximum_height, maximum_slope, maximum_unresolved);
|
||||
summary_outputs[0].metadata = float4(page_sample_count, 0.0, 0.0, 1.0);
|
||||
summary_outputs[page_summary_index].bounds = float4(minimum_height, maximum_height, maximum_slope, maximum_unresolved);
|
||||
summary_outputs[page_summary_index].metadata = float4(page_sample_count, page_sample_offset, page_summary_index, 1.0);
|
||||
}
|
||||
|
|
|
|||
3
src/Aquarium.Zyphos/Properties/AssemblyInfo.cs
Normal file
3
src/Aquarium.Zyphos/Properties/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Aquarium.Engine.Tests")]
|
||||
|
|
@ -244,10 +244,13 @@ float sdfDistance(float3 p, int sdfIndex)
|
|||
float zyPlanetTraceBoundRadius(SdfObject sdfObject)
|
||||
{
|
||||
float legacyBound = max(sdfObject.centerRadius.w * 1.42, 0.001);
|
||||
ZyPlanetPageSummary summary = zy_planet_page_summary[0];
|
||||
ZyPlanetPageMetadata metadata = zy_planet_page_metadata[0];
|
||||
if (metadata.state.x < 0.5 || summary.metadata.w < 0.5) return legacyBound;
|
||||
float erosionExtent = max(abs(summary.bounds.x), abs(summary.bounds.y)) + max(summary.bounds.w, 0.0);
|
||||
float erosionExtent=0.0; int pageCount=min((int)zy_planet_page_set[0].state.x,64);
|
||||
[loop] for(int pageIndex=0;pageIndex<pageCount;pageIndex++)
|
||||
{
|
||||
ZyPlanetPageSummary summary=zy_planet_page_summary[pageIndex]; ZyPlanetPageMetadata metadata=zy_planet_page_metadata[pageIndex];
|
||||
if(metadata.state.x<0.5||summary.metadata.w<0.5)continue;
|
||||
erosionExtent+=max(abs(summary.bounds.x),abs(summary.bounds.y))*saturate(metadata.state.y)+max(summary.bounds.w,0.0);
|
||||
}
|
||||
return max(legacyBound, max(sdfObject.state.x, 0.001) + erosionExtent);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@
|
|||
struct ZyPlanetPageOutput { float4 height_gradient; float4 masks; };
|
||||
struct ZyPlanetPageMetadata { float4 address; float4 layout; float4 bounds; float4 state; };
|
||||
struct ZyPlanetPageSummary { float4 bounds; float4 metadata; };
|
||||
struct ZyPlanetPageSet { float4 state; };
|
||||
StructuredBuffer<ZyPlanetPageOutput> zy_planet_page : register(t81);
|
||||
StructuredBuffer<ZyPlanetPageMetadata> zy_planet_page_metadata : register(t82);
|
||||
StructuredBuffer<ZyPlanetPageSummary> zy_planet_page_summary : register(t83);
|
||||
StructuredBuffer<ZyPlanetPageSet> zy_planet_page_set : register(t84);
|
||||
|
||||
static const float ZY_TERRAIN_NON_EROSION_SLOPE_BOUND = 8.0;
|
||||
|
||||
|
|
@ -20,38 +22,51 @@ float2 zyTerrainCubeFaceUv(float3 dir, out float face)
|
|||
if(dir.z>=0){face=4;return dir.xy/a.z;}face=5;return float2(-dir.x,dir.y)/a.z;
|
||||
}
|
||||
|
||||
bool zyTrySampleErosionPage(float3 dir, out float4 heightGradient, out float2 masks)
|
||||
bool zyTerrainPageLocal(float3 dir, ZyPlanetPageMetadata metadata, out float2 local)
|
||||
{
|
||||
ZyPlanetPageMetadata metadata=zy_planet_page_metadata[0]; heightGradient=0; masks=0;
|
||||
if(metadata.state.x<0.5)return false;
|
||||
float face; float2 uv=zyTerrainCubeFaceUv(dir,face); if(abs(face-metadata.address.x)>0.25)return false;
|
||||
float axisTiles=exp2(metadata.address.y); float2 local=(uv*0.5+0.5)*axisTiles-metadata.address.zw;
|
||||
if(any(local<0.0)||any(local>1.0))return false;
|
||||
float face; float2 uv=zyTerrainCubeFaceUv(dir,face); local=0.0;
|
||||
if(metadata.state.x<0.5||abs(face-metadata.address.x)>0.25)return false;
|
||||
float axisTiles=exp2(metadata.address.y); local=(uv*0.5+0.5)*axisTiles-metadata.address.zw;
|
||||
return all(local>=0.0)&&all(local<=1.0);
|
||||
}
|
||||
|
||||
void zySampleErosionPage(int pageIndex, float2 local, out float4 heightGradient, out float2 masks)
|
||||
{
|
||||
ZyPlanetPageMetadata metadata=zy_planet_page_metadata[pageIndex];
|
||||
float storage=metadata.layout.y, interior=metadata.layout.z, border=metadata.layout.w;
|
||||
float2 texel=local*(interior-1.0)+border; float2 base=floor(texel); float2 fraction=frac(texel);
|
||||
int2 p0=(int2)clamp(base,0.0,storage-1.0); int2 p1=min(p0+1,(int2)(storage-1.0));
|
||||
ZyPlanetPageOutput a=zy_planet_page[p0.y*(int)storage+p0.x], b=zy_planet_page[p0.y*(int)storage+p1.x];
|
||||
ZyPlanetPageOutput c=zy_planet_page[p1.y*(int)storage+p0.x], d=zy_planet_page[p1.y*(int)storage+p1.x];
|
||||
int offset=(int)metadata.layout.x;
|
||||
ZyPlanetPageOutput a=zy_planet_page[offset+p0.y*(int)storage+p0.x], b=zy_planet_page[offset+p0.y*(int)storage+p1.x];
|
||||
ZyPlanetPageOutput c=zy_planet_page[offset+p1.y*(int)storage+p0.x], d=zy_planet_page[offset+p1.y*(int)storage+p1.x];
|
||||
heightGradient=lerp(lerp(a.height_gradient,b.height_gradient,fraction.x),lerp(c.height_gradient,d.height_gradient,fraction.x),fraction.y);
|
||||
masks=lerp(lerp(a.masks.xy,b.masks.xy,fraction.x),lerp(c.masks.xy,d.masks.xy,fraction.x),fraction.y); return true;
|
||||
masks=lerp(lerp(a.masks.xy,b.masks.xy,fraction.x),lerp(c.masks.xy,d.masks.xy,fraction.x),fraction.y);
|
||||
}
|
||||
|
||||
bool zyTryGetErosionPageSummary(float3 dir, out ZyPlanetPageSummary summary)
|
||||
bool zyTrySampleErosionPage(float3 dir, out float4 heightGradient, out float2 masks)
|
||||
{
|
||||
summary = zy_planet_page_summary[0];
|
||||
ZyPlanetPageMetadata metadata = zy_planet_page_metadata[0];
|
||||
if (metadata.state.x < 0.5 || summary.metadata.w < 0.5) return false;
|
||||
float face; float2 uv = zyTerrainCubeFaceUv(dir, face);
|
||||
if (abs(face - metadata.address.x) > 0.25) return false;
|
||||
float axisTiles = exp2(metadata.address.y);
|
||||
float2 local = (uv * 0.5 + 0.5) * axisTiles - metadata.address.zw;
|
||||
return all(local >= 0.0) && all(local <= 1.0);
|
||||
heightGradient=0.0; masks=0.0; bool found=false;
|
||||
int pageCount=min((int)zy_planet_page_set[0].state.x,64);
|
||||
[loop] for(int pageIndex=0;pageIndex<pageCount;pageIndex++)
|
||||
{
|
||||
float2 local; ZyPlanetPageMetadata metadata=zy_planet_page_metadata[pageIndex];
|
||||
if(!zyTerrainPageLocal(dir,metadata,local))continue;
|
||||
float4 contribution; float2 pageMasks; zySampleErosionPage(pageIndex,local,contribution,pageMasks);
|
||||
float blend=saturate(metadata.state.y); heightGradient+=contribution*blend;
|
||||
masks=found?lerp(masks,pageMasks,blend):pageMasks; found=true;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
float zyTerrainConservativeDistanceScale(float3 dir)
|
||||
{
|
||||
ZyPlanetPageSummary summary;
|
||||
float erosionSlope = zyTryGetErosionPageSummary(dir, summary) ? summary.bounds.z : 0.0;
|
||||
float erosionSlope=0.0; int pageCount=min((int)zy_planet_page_set[0].state.x,64);
|
||||
[loop] for(int pageIndex=0;pageIndex<pageCount;pageIndex++)
|
||||
{
|
||||
float2 local; ZyPlanetPageMetadata metadata=zy_planet_page_metadata[pageIndex];
|
||||
if(zyTerrainPageLocal(dir,metadata,local)&&zy_planet_page_summary[pageIndex].metadata.w>0.5)
|
||||
erosionSlope+=max(zy_planet_page_summary[pageIndex].bounds.z,0.0)*saturate(metadata.state.y);
|
||||
}
|
||||
float totalSlopeBound = ZY_TERRAIN_NON_EROSION_SLOPE_BOUND + max(erosionSlope, 0.0);
|
||||
return rsqrt(1.0 + totalSlopeBound * totalSlopeBound);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,13 @@ StructuredBuffer<PageInput> page_inputs : register(t0);
|
|||
RWStructuredBuffer<PageOutput> page_outputs : register(u0);
|
||||
cbuffer PageConstants : register(b0) { uint page_sample_count; }
|
||||
|
||||
float zyPageErosion(float3 direction, float radius, float spacing)
|
||||
float zyPageErosion(float3 direction, float radius, float spacing, float parent_spacing)
|
||||
{
|
||||
float3 dir=normalize(direction); return zyAdvancedErosion(dir,zySphericalField(dir),radius,spacing).x;
|
||||
float3 dir=normalize(direction);
|
||||
float child=zyAdvancedErosion(dir,zySphericalField(dir),radius,spacing).x;
|
||||
if(parent_spacing<=0.0)return child;
|
||||
float parent=zyAdvancedErosion(dir,zySphericalField(dir),radius,parent_spacing).x;
|
||||
return child-parent;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -16,11 +20,11 @@ float zyPageErosion(float3 direction, float radius, float spacing)
|
|||
void D3D12ZyphosTerrainPageCS(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if(id.x>=page_sample_count) return;
|
||||
PageInput input=page_inputs[id.x]; float3 dir=normalize(input.direction_radius.xyz); float radius=input.direction_radius.w; float spacing=input.sampling.x;
|
||||
PageInput input=page_inputs[id.x]; float3 dir=normalize(input.direction_radius.xyz); float radius=input.direction_radius.w; float spacing=input.sampling.x; float parent_spacing=input.sampling.y;
|
||||
float3 reference=abs(dir.z)<0.8?float3(0,0,1):float3(0,1,0); float3 tangent_x=normalize(cross(reference,dir)); float3 tangent_y=normalize(cross(dir,tangent_x));
|
||||
float angular=max(spacing/radius,1.0e-6); float center=zyPageErosion(dir,radius,spacing);
|
||||
float dx=(zyPageErosion(normalize(dir+tangent_x*angular),radius,spacing)-zyPageErosion(normalize(dir-tangent_x*angular),radius,spacing))/(2.0*spacing);
|
||||
float dy=(zyPageErosion(normalize(dir+tangent_y*angular),radius,spacing)-zyPageErosion(normalize(dir-tangent_y*angular),radius,spacing))/(2.0*spacing);
|
||||
float angular=max(spacing/radius,1.0e-6); float center=zyPageErosion(dir,radius,spacing,parent_spacing);
|
||||
float dx=(zyPageErosion(normalize(dir+tangent_x*angular),radius,spacing,parent_spacing)-zyPageErosion(normalize(dir-tangent_x*angular),radius,spacing,parent_spacing))/(2.0*spacing);
|
||||
float dy=(zyPageErosion(normalize(dir+tangent_y*angular),radius,spacing,parent_spacing)-zyPageErosion(normalize(dir-tangent_y*angular),radius,spacing,parent_spacing))/(2.0*spacing);
|
||||
float4 erosion=zyAdvancedErosion(dir,zySphericalField(dir),radius,spacing);
|
||||
page_outputs[id.x].height_gradient=float4(center,dx,dy,erosion.w);
|
||||
page_outputs[id.x].masks=float4(erosion.y,erosion.z,0,1);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ struct PageOutput { float4 height_gradient; float4 masks; };
|
|||
struct PageSummary { float4 bounds; float4 metadata; };
|
||||
StructuredBuffer<PageOutput> summary_inputs : register(t0);
|
||||
RWStructuredBuffer<PageSummary> summary_outputs : register(u0);
|
||||
cbuffer PageConstants : register(b0) { uint page_sample_count; }
|
||||
cbuffer PageConstants : register(b0) { uint page_sample_count; uint page_sample_offset; uint page_summary_index; }
|
||||
|
||||
[numthreads(1,1,1)]
|
||||
void D3D12ZyphosTerrainPageSummaryCS(uint3 id : SV_DispatchThreadID)
|
||||
|
|
@ -11,10 +11,10 @@ void D3D12ZyphosTerrainPageSummaryCS(uint3 id : SV_DispatchThreadID)
|
|||
float minimum_height=3.402823466e+38, maximum_height=-3.402823466e+38, maximum_slope=0.0, maximum_unresolved=0.0;
|
||||
[loop] for(uint index=0;index<page_sample_count;index++)
|
||||
{
|
||||
float4 sample=summary_inputs[index].height_gradient;
|
||||
float4 sample=summary_inputs[page_sample_offset+index].height_gradient;
|
||||
minimum_height=min(minimum_height,sample.x); maximum_height=max(maximum_height,sample.x);
|
||||
maximum_slope=max(maximum_slope,length(sample.yz)); maximum_unresolved=max(maximum_unresolved,sample.w);
|
||||
}
|
||||
summary_outputs[0].bounds=float4(minimum_height,maximum_height,maximum_slope,maximum_unresolved);
|
||||
summary_outputs[0].metadata=float4(page_sample_count,0,0,1);
|
||||
summary_outputs[page_summary_index].bounds=float4(minimum_height,maximum_height,maximum_slope,maximum_unresolved);
|
||||
summary_outputs[page_summary_index].metadata=float4(page_sample_count,page_sample_offset,page_summary_index,1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,44 +2,149 @@ using System.Numerics;
|
|||
using Aquarium.Engine.Fractal;
|
||||
using Aquarium.Engine.Fractal.Lod;
|
||||
using Aquarium.Engine.Render;
|
||||
using CultMath;
|
||||
|
||||
namespace Aquarium.Zyphos;
|
||||
|
||||
internal static class ZyphosPlanetarySurfacePages
|
||||
{
|
||||
private static readonly Dictionary<CubeFace, AquariumPlanetarySurfacePageSet> Pages = [];
|
||||
private const int InteriorSize = 17;
|
||||
private const int BorderSize = 2;
|
||||
private const int MaximumLevel = 5;
|
||||
private const float ArrivalSeconds = 0.35f;
|
||||
private static readonly Dictionary<long, AquariumPlanetarySurfacePageInput[]> Content = [];
|
||||
private static readonly Dictionary<long, float> ArrivalTimes = [];
|
||||
private static readonly Dictionary<long, float> DepartureTimes = [];
|
||||
private static readonly Dictionary<long, CubeTileKey> ResidentTiles = [];
|
||||
private static float lastTimeSeconds = float.NegativeInfinity;
|
||||
|
||||
public static AquariumPlanetarySurfacePageSet ForCamera(Vector3 cameraPosition)
|
||||
internal static void Reset()
|
||||
{
|
||||
var direction = Vector3.Normalize(cameraPosition - ZyphosUmbrosSystem.ZyphosCenter);
|
||||
var face = DominantFace(direction);
|
||||
if (Pages.TryGetValue(face, out var cached)) return cached;
|
||||
var request = new PlanetarySurfacePageRequest(new CubeTileKey(face, 0, 0, 0), 17, 2);
|
||||
var radius = ZyphosUmbrosSystem.ZyphosSurfaceRadius;
|
||||
var spacing = PlanetarySurfacePageSampling.NominalAngularTexelSize(request) * radius;
|
||||
var samples = new AquariumPlanetarySurfacePageInput[request.StorageSize * request.StorageSize];
|
||||
for (var y = 0; y < request.StorageSize; y++) for (var x = 0; x < request.StorageSize; x++)
|
||||
ArrivalTimes.Clear(); DepartureTimes.Clear(); ResidentTiles.Clear();
|
||||
lastTimeSeconds=float.NegativeInfinity;
|
||||
}
|
||||
|
||||
public static AquariumPlanetarySurfacePageSet ForCamera(Vector3 cameraPosition, float timeSeconds)
|
||||
{
|
||||
if (timeSeconds < lastTimeSeconds)
|
||||
{
|
||||
var sampleDirection = PlanetarySurfacePageSampling.Direction(request, x, y);
|
||||
samples[y * request.StorageSize + x] = new AquariumPlanetarySurfacePageInput(new Vector4(sampleDirection, radius), new Vector4(spacing, 0, 0, 0));
|
||||
ArrivalTimes.Clear(); DepartureTimes.Clear(); ResidentTiles.Clear();
|
||||
}
|
||||
var metadata = new AquariumPlanetarySurfacePageMetadata(
|
||||
new Vector4((int)face, 0, 0, 0),
|
||||
new Vector4(0, request.StorageSize, request.InteriorSize, request.BorderSize),
|
||||
Vector4.Zero,
|
||||
new Vector4(1, (int)face + 1, PlanetarySurfacePageSampling.AngularTexelSize(request), spacing));
|
||||
return Pages[face] = new AquariumPlanetarySurfacePageSet
|
||||
lastTimeSeconds = timeSeconds;
|
||||
var relative = cameraPosition - ZyphosUmbrosSystem.ZyphosCenter;
|
||||
var distance = Math.Max(relative.Length(), 0.001f);
|
||||
var direction = relative / distance;
|
||||
var desired = DesiredTiles(direction, distance).ToDictionary(ContentKey);
|
||||
foreach (var (key, tile) in desired)
|
||||
{
|
||||
ResidentTiles[key] = tile;
|
||||
if (!ArrivalTimes.TryGetValue(key, out var arrival)) ArrivalTimes[key] = arrival = timeSeconds;
|
||||
DepartureTimes.Remove(key);
|
||||
}
|
||||
foreach (var (key, tile) in ResidentTiles.ToArray())
|
||||
{
|
||||
if (tile.Level == 0 || desired.ContainsKey(key)) continue;
|
||||
if (!DepartureTimes.ContainsKey(key)) DepartureTimes[key] = timeSeconds;
|
||||
if (timeSeconds - DepartureTimes[key] < ArrivalSeconds) continue;
|
||||
ResidentTiles.Remove(key); ArrivalTimes.Remove(key); DepartureTimes.Remove(key);
|
||||
}
|
||||
|
||||
var residents = ResidentTiles.OrderBy(pair => pair.Value.Level).ThenBy(pair => pair.Key).ToArray();
|
||||
var pages = new AquariumPlanetarySurfacePage[residents.Length];
|
||||
for (var index = 0; index < residents.Length; index++)
|
||||
{
|
||||
var (key, tile) = residents[index];
|
||||
var blend = tile.Level == 0 ? 1.0f : DepartureTimes.TryGetValue(key, out var departure)
|
||||
? Math.Clamp(1.0f - (timeSeconds - departure) / ArrivalSeconds, 0.0f, 1.0f)
|
||||
: Math.Clamp((timeSeconds - ArrivalTimes[key]) / ArrivalSeconds, 0.0f, 1.0f);
|
||||
pages[index] = BuildPage(tile, key, blend);
|
||||
}
|
||||
|
||||
var contentVersion = Version(residents.Select(pair => pair.Key));
|
||||
var presentationVersion = Version(pages.Select(page => (long)HashCode.Combine(page.ContentKey, BitConverter.SingleToInt32Bits(page.Metadata.State.Y))));
|
||||
return new AquariumPlanetarySurfacePageSet
|
||||
{
|
||||
GeneratorEntryPoint = "D3D12ZyphosTerrainPageCS",
|
||||
Version = (int)face + 1, Samples = samples, Metadata = metadata,
|
||||
ContentVersion = contentVersion,
|
||||
PresentationVersion = presentationVersion,
|
||||
Pages = pages,
|
||||
};
|
||||
}
|
||||
|
||||
private static CubeFace DominantFace(Vector3 d)
|
||||
private static AquariumPlanetarySurfacePage BuildPage(CubeTileKey tile, long key, float blend)
|
||||
{
|
||||
var request = new PlanetarySurfacePageRequest(tile, InteriorSize, BorderSize);
|
||||
var radius = ZyphosUmbrosSystem.ZyphosSurfaceRadius;
|
||||
var spacing = PlanetarySurfacePageSampling.NominalAngularTexelSize(request) * radius;
|
||||
var parentSpacing = tile.Level == 0
|
||||
? 0.0f
|
||||
: PlanetarySurfacePageSampling.NominalAngularTexelSize(new PlanetarySurfacePageRequest(tile.Parent(), InteriorSize, BorderSize)) * radius;
|
||||
if (!Content.TryGetValue(key, out var samples))
|
||||
{
|
||||
samples = new AquariumPlanetarySurfacePageInput[request.StorageSize * request.StorageSize];
|
||||
for (var y = 0; y < request.StorageSize; y++) for (var x = 0; x < request.StorageSize; x++)
|
||||
{
|
||||
var sampleDirection = PlanetarySurfacePageSampling.Direction(request, x, y);
|
||||
samples[y * request.StorageSize + x] = new AquariumPlanetarySurfacePageInput(
|
||||
new Vector4(sampleDirection, radius), new Vector4(spacing, parentSpacing, 0, 0));
|
||||
}
|
||||
Content[key] = samples;
|
||||
}
|
||||
|
||||
return new AquariumPlanetarySurfacePage
|
||||
{
|
||||
ContentKey = key,
|
||||
Samples = samples,
|
||||
Metadata = new AquariumPlanetarySurfacePageMetadata(
|
||||
new Vector4((int)tile.Face, tile.Level, tile.X, tile.Y),
|
||||
new Vector4(0, request.StorageSize, request.InteriorSize, request.BorderSize),
|
||||
Vector4.Zero,
|
||||
new Vector4(1, blend, PlanetarySurfacePageSampling.NominalAngularTexelSize(request), spacing)),
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<CubeTileKey> DesiredTiles(Vector3 direction, float distance)
|
||||
{
|
||||
foreach (var rootFace in Enum.GetValues<CubeFace>()) yield return new CubeTileKey(rootFace, 0, 0, 0);
|
||||
var altitude = Math.Max(distance - ZyphosUmbrosSystem.ZyphosSurfaceRadius, 0.001f);
|
||||
var footprint = Math.Max(altitude / 720.0f * 2.0f, ZyphosUmbrosSystem.ZyphosSurfaceRadius / 65536.0f);
|
||||
var radius=ZyphosUmbrosSystem.ZyphosSurfaceRadius;
|
||||
var baseWavelength=radius*0.075f*0.7f;
|
||||
var baseAmplitude=0.12f*radius*0.075f;
|
||||
var targetLevel=MaximumLevel;
|
||||
for(var level=0;level<=MaximumLevel;level++)
|
||||
{
|
||||
var request=new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveX,level,0,0),InteriorSize,BorderSize);
|
||||
var spacing=PlanetarySurfacePageSampling.NominalAngularTexelSize(request)*radius;
|
||||
var unresolved=ErosionFrequencyBands.Select(baseWavelength,spacing,7,2.0f,baseAmplitude,0.5f).UnresolvedHeightBound;
|
||||
if(unresolved<=footprint){targetLevel=level;break;}
|
||||
}
|
||||
var (face, uv) = FaceUv(direction);
|
||||
for (var level = 1; level <= targetLevel; level++)
|
||||
{
|
||||
var count = 1 << level;
|
||||
var x = Math.Clamp((int)((uv.X * 0.5f + 0.5f) * count), 0, count - 1);
|
||||
var y = Math.Clamp((int)((uv.Y * 0.5f + 0.5f) * count), 0, count - 1);
|
||||
yield return new CubeTileKey(face, level, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private static (CubeFace Face, Vector2 Uv) FaceUv(Vector3 d)
|
||||
{
|
||||
var a = Vector3.Abs(d);
|
||||
if (a.X >= a.Y && a.X >= a.Z) return d.X >= 0 ? CubeFace.PositiveX : CubeFace.NegativeX;
|
||||
if (a.Y >= a.Z) return d.Y >= 0 ? CubeFace.PositiveY : CubeFace.NegativeY;
|
||||
return d.Z >= 0 ? CubeFace.PositiveZ : CubeFace.NegativeZ;
|
||||
if (a.X >= a.Y && a.X >= a.Z) return d.X >= 0 ? (CubeFace.PositiveX, new(-d.Z / a.X, d.Y / a.X)) : (CubeFace.NegativeX, new(d.Z / a.X, d.Y / a.X));
|
||||
if (a.Y >= a.Z) return d.Y >= 0 ? (CubeFace.PositiveY, new(d.X / a.Y, -d.Z / a.Y)) : (CubeFace.NegativeY, new(d.X / a.Y, d.Z / a.Y));
|
||||
return d.Z >= 0 ? (CubeFace.PositiveZ, new(d.X / a.Z, d.Y / a.Z)) : (CubeFace.NegativeZ, new(-d.X / a.Z, d.Y / a.Z));
|
||||
}
|
||||
|
||||
private static long ContentKey(CubeTileKey tile) => 1L + (long)tile.Face + ((long)tile.Level << 3) + ((long)tile.X << 9) + ((long)tile.Y << 29);
|
||||
|
||||
private static long Version(IEnumerable<long> values)
|
||||
{
|
||||
const long offset = 1469598103934665603;
|
||||
const long prime = 1099511628211;
|
||||
var hash = offset;
|
||||
foreach (var value in values) hash = unchecked((hash ^ value) * prime);
|
||||
return hash == 0 ? 1 : hash;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public static class ZyphosSceneBuilder
|
|||
PriorityFocus = fractalPlan.ReservoirPriorityFocus,
|
||||
ProgramTransforms = fractalPlan.GpuProgramTransforms,
|
||||
},
|
||||
PlanetarySurfacePages = ZyphosPlanetarySurfacePages.ForCamera(cameraPosition),
|
||||
PlanetarySurfacePages = ZyphosPlanetarySurfacePages.ForCamera(cameraPosition, timeSeconds),
|
||||
SdfObjects = BuildSdfObjects(timeSeconds, previousTimeSeconds),
|
||||
SdfLights = BuildSdfLights(timeSeconds),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -338,3 +338,4 @@
|
|||
{"timestamp":"2026-07-12T21:35:00+01:00","topic":"planetary-page-boundary-authority","lesson":"Using each tile's locally measured angular texel size caused independently generated sibling pages to choose different erosion weights at the same shared boundary. Band selection now uses a level-global nominal angular footprint; local projection distortion remains summary evidence. GPU-generated sibling boundaries are identical and borders sample the spherical field without neighbor residency.","files":["src/Aquarium.Engine.Fractal/Lod/PlanetarySurfacePage.cs","src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrain.hlsli","src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPage.hlsl","tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs"],"source":"phase 4 cross-page GPU verification"}
|
||||
{"timestamp":"2026-07-12T22:00:00+01:00","topic":"planetary-page-summary-reduction","lesson":"Planetary erosion pages now reduce minimum/maximum displacement, maximum tangent slope, and maximum unresolved height through the GPU kernel and verify those results against CPU reduction. These summaries are the conservative evidence needed by later intersection and residency; they are not inferred from parameters.","files":["src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPageSummary.hlsl","tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs"],"source":"phase 4 GPU summary gate"}
|
||||
{"timestamp":"2026-07-12T23:15:00+01:00","topic":"page-backed-planetary-intersection","lesson":"Planetary erosion rendering now generates a persistent D3D12 page and GPU summary, binds both to Zyphos SDF tracing, uses measured displacement/slope/unresolved evidence for bounds and conservative radial stepping, and retains the shared bracketed sign-change refiner. Compiling the previously unregistered planet proxy proved that advanced erosion cannot remain nested in the Shader Model 5 pixel trace; exact direct evaluation is therefore the CPU/compute oracle, while visible misses use the resident ancestor or base field. Zyphos now registers and publishes planet, Umbros, and star in matching object-index order.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12SdfProxy.hlsli","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrain.hlsli","src/Aquarium.Zyphos/ZyphosRenderPlan.cs","src/Aquarium.Zyphos/ZyphosSceneBuilder.cs","tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs"],"source":"phase 5 compile, D3D12 summary, lifecycle, and direct-versus-page hit verification"}
|
||||
{"timestamp":"2026-07-13T00:10:00+01:00","topic":"planetary-residual-quadtree-lod","lesson":"Planetary LOD now keeps six root pages and represents a selected camera path as parent low frequencies plus child-only residual bands. CultMath's declared unresolved-height bound divided by projected world footprint chooses the level. Content and presentation versions are separate, so arrival/departure fades update metadata without regenerating pages; departing chains remain resident through zero weight before eviction. GPU tests prove parent plus child residual reconstructs the child filtered field, and timeline tests cover descent, teleport, midpoint, eviction, and reload. Visible capture evidence is still required before claiming the no-pop Phase 6 exit.","files":["src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Zyphos/ZyphosPlanetarySurfacePages.cs","src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPage.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrain.hlsli","tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs"],"source":"phase 6 residual LOD implementation and numerical/timeline verification"}
|
||||
|
|
|
|||
|
|
@ -105,6 +105,19 @@ invariants:
|
|||
root); direct CultMath evaluation remains the CPU/compute verification
|
||||
oracle. Page summaries expand broad-phase bounds and scale radial steps,
|
||||
while the shared SDF proxy owns bracketed sign-change refinement.
|
||||
- Planetary page residency separates content from presentation state.
|
||||
ContentVersion changes only when the resident tile set changes;
|
||||
PresentationVersion carries arrival/departure weights without regenerating
|
||||
erosion. Six root pages remain resident. A projected-error selector uses
|
||||
CultMath's unresolved-height bound against the camera footprint to request
|
||||
one ancestor chain, and departing chains remain addressable until their
|
||||
residual weights reach zero.
|
||||
- Root pages contain the resolvable low-frequency erosion field. Every child
|
||||
page stores `child filtered field - parent filtered field`; the planet
|
||||
shader sums the containing ancestor contributions and weights only those
|
||||
residuals during transitions. Independent full-spectrum pages are never
|
||||
blended. D3D12 flattens resident payloads into one output atlas with indexed
|
||||
metadata and one GPU summary per page at t81-t84.
|
||||
- The shared reservoir is a fractal domain reservoir, not a texel cache.
|
||||
Pixel rows are the current D3D12 execution projection of selected domain
|
||||
evidence. Area-domain contributors must carry selected subpixel or local
|
||||
|
|
|
|||
|
|
@ -25,16 +25,112 @@ public sealed class D3D12PlanetarySurfacePageTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void CameraFaceSelectionReusesResidentPageAndVersionsReplacement()
|
||||
public void QuadtreeSelectionKeepsSixRootsAndAddsOneResidualAncestorChain()
|
||||
{
|
||||
ZyphosPlanetarySurfacePages.Reset();
|
||||
var center = ZyphosUmbrosSystem.ZyphosCenter;
|
||||
var first = ZyphosSceneBuilder.Build(0.0f, 0.0f, center + Vector3.UnitZ * 12.0f, default).PlanetarySurfacePages;
|
||||
var sameFace = ZyphosSceneBuilder.Build(0.0f, 0.0f, center + Vector3.Normalize(new Vector3(0.1f, 0.1f, 1.0f)) * 12.0f, default).PlanetarySurfacePages;
|
||||
var replacement = ZyphosSceneBuilder.Build(0.0f, 0.0f, center + Vector3.UnitX * 12.0f, default).PlanetarySurfacePages;
|
||||
var orbital = ZyphosSceneBuilder.Build(0.0f, 0.0f, center + Vector3.UnitZ * 1000.0f, default).PlanetarySurfacePages;
|
||||
var near = ZyphosSceneBuilder.Build(2.0f, 1.0f, center + Vector3.Normalize(new Vector3(0.13f, 0.19f, 1.0f)) * (ZyphosUmbrosSystem.ZyphosSurfaceRadius + 0.05f), default).PlanetarySurfacePages;
|
||||
|
||||
Assert.Same(first, sameFace);
|
||||
Assert.NotEqual(first.Version, replacement.Version);
|
||||
Assert.NotEqual(first.Metadata.Address.X, replacement.Metadata.Address.X);
|
||||
Assert.Equal(6, orbital.Pages.Count);
|
||||
Assert.Equal(Enum.GetValues<CubeFace>().Select(face => (float)face), orbital.Pages.Select(page => page.Metadata.Address.X));
|
||||
Assert.True(near.Pages.Count > 6);
|
||||
Assert.Equal(Enumerable.Range(1, near.Pages.Count - 6).Select(level => (float)level), near.Pages.Skip(6).Select(page => page.Metadata.Address.Y));
|
||||
Assert.All(near.Pages.Skip(6), page => Assert.True(page.Samples[0].Sampling.Y > page.Samples[0].Sampling.X));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChildPageStoresOnlyTheNewlyResolvableResidualBand()
|
||||
{
|
||||
const float radius=8.4f;
|
||||
var parent=new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveZ,2,2,1),9,2);
|
||||
var child=new PlanetarySurfacePageRequest(parent.Tile.Child(1,0),9,2);
|
||||
var direction=PlanetarySurfacePageSampling.DirectionAtLocal(child,0.43,0.57);
|
||||
var childSpacing=PlanetarySurfacePageSampling.NominalAngularTexelSize(child)*radius;
|
||||
var parentSpacing=PlanetarySurfacePageSampling.NominalAngularTexelSize(parent)*radius;
|
||||
var input=new[]
|
||||
{
|
||||
new PageInput(new Vector4(direction,radius),new Vector4(childSpacing,0,0,0)),
|
||||
new PageInput(new Vector4(direction,radius),new Vector4(parentSpacing,0,0,0)),
|
||||
new PageInput(new Vector4(direction,radius),new Vector4(childSpacing,parentSpacing,0,0)),
|
||||
};
|
||||
var output=D3D12ComputeProbe.Run<PageInput,PageOutput>(ShaderPath(),"D3D12ZyphosTerrainPageCS",input);
|
||||
Assert.InRange(MathF.Abs(output[0].HeightGradient.X-(output[1].HeightGradient.X+output[2].HeightGradient.X)),0,2.0e-5f);
|
||||
Assert.InRange(MathF.Abs(output[0].HeightGradient.Y-(output[1].HeightGradient.Y+output[2].HeightGradient.Y)),0,2.0e-4f);
|
||||
Assert.InRange(MathF.Abs(output[0].HeightGradient.Z-(output[1].HeightGradient.Z+output[2].HeightGradient.Z)),0,2.0e-4f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResidualArrivalChangesPresentationWithoutRegeneratingContent()
|
||||
{
|
||||
ZyphosPlanetarySurfacePages.Reset();
|
||||
var center=ZyphosUmbrosSystem.ZyphosCenter;
|
||||
var direction=Vector3.Normalize(new Vector3(-0.17f,-1.0f,0.23f));
|
||||
var camera=center+direction*(ZyphosUmbrosSystem.ZyphosSurfaceRadius+0.03f);
|
||||
var start=ZyphosSceneBuilder.Build(100.0f,99.9f,camera,default).PlanetarySurfacePages;
|
||||
var middle=ZyphosSceneBuilder.Build(100.175f,100.0f,camera,default).PlanetarySurfacePages;
|
||||
var settled=ZyphosSceneBuilder.Build(100.35f,100.175f,camera,default).PlanetarySurfacePages;
|
||||
Assert.Equal(start.ContentVersion,middle.ContentVersion);
|
||||
Assert.Equal(middle.ContentVersion,settled.ContentVersion);
|
||||
Assert.NotEqual(start.PresentationVersion,middle.PresentationVersion);
|
||||
Assert.All(start.Pages.Skip(6),page=>Assert.Equal(0.0f,page.Metadata.State.Y));
|
||||
Assert.All(middle.Pages.Skip(6),page=>Assert.InRange(page.Metadata.State.Y,0.49f,0.51f));
|
||||
Assert.All(settled.Pages.Skip(6),page=>Assert.InRange(page.Metadata.State.Y,0.999f,1.0f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TeleportCrossFadesOldAndNewResidualChainsBeforeEviction()
|
||||
{
|
||||
ZyphosPlanetarySurfacePages.Reset();
|
||||
var center=ZyphosUmbrosSystem.ZyphosCenter;
|
||||
var radius=ZyphosUmbrosSystem.ZyphosSurfaceRadius+0.03f;
|
||||
var cameraA=center+Vector3.Normalize(new Vector3(1.0f,0.12f,0.18f))*radius;
|
||||
var cameraB=center+Vector3.Normalize(new Vector3(-0.21f,1.0f,-0.14f))*radius;
|
||||
_=ZyphosSceneBuilder.Build(200.0f,199.9f,cameraA,default);
|
||||
var settledA=ZyphosSceneBuilder.Build(200.35f,200.0f,cameraA,default).PlanetarySurfacePages;
|
||||
var oldKeys=settledA.Pages.Skip(6).Select(page=>page.ContentKey).ToHashSet();
|
||||
var departure=ZyphosSceneBuilder.Build(201.0f,200.35f,cameraB,default).PlanetarySurfacePages;
|
||||
var newKeys=departure.Pages.Skip(6).Select(page=>page.ContentKey).Where(key=>!oldKeys.Contains(key)).ToHashSet();
|
||||
Assert.NotEmpty(newKeys);
|
||||
Assert.All(departure.Pages.Where(page=>oldKeys.Contains(page.ContentKey)),page=>Assert.InRange(page.Metadata.State.Y,0.999f,1.0f));
|
||||
Assert.All(departure.Pages.Where(page=>newKeys.Contains(page.ContentKey)),page=>Assert.Equal(0.0f,page.Metadata.State.Y));
|
||||
|
||||
var midpoint=ZyphosSceneBuilder.Build(201.175f,201.0f,cameraB,default).PlanetarySurfacePages;
|
||||
Assert.All(midpoint.Pages.Where(page=>oldKeys.Contains(page.ContentKey)||newKeys.Contains(page.ContentKey)),page=>Assert.InRange(page.Metadata.State.Y,0.49f,0.51f));
|
||||
var settledB=ZyphosSceneBuilder.Build(201.36f,201.175f,cameraB,default).PlanetarySurfacePages;
|
||||
Assert.DoesNotContain(settledB.Pages,page=>oldKeys.Contains(page.ContentKey));
|
||||
Assert.All(settledB.Pages.Where(page=>newKeys.Contains(page.ContentKey)),page=>Assert.InRange(page.Metadata.State.Y,0.999f,1.0f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectedErrorSelectionAddsLevelsMonotonicallyDuringDescent()
|
||||
{
|
||||
ZyphosPlanetarySurfacePages.Reset();
|
||||
var center=ZyphosUmbrosSystem.ZyphosCenter;
|
||||
var direction=Vector3.Normalize(new Vector3(0.11f,0.17f,1.0f));
|
||||
var distances=new[]{1000.0f,100.0f,20.0f,ZyphosUmbrosSystem.ZyphosSurfaceRadius+0.05f};
|
||||
var levels=new List<int>();
|
||||
for(var index=0;index<distances.Length;index++)
|
||||
{
|
||||
var pages=ZyphosSceneBuilder.Build((float)index,(float)index-0.1f,center+direction*distances[index],default).PlanetarySurfacePages;
|
||||
levels.Add((int)pages.Pages.Where(page=>page.Metadata.Address.X==(float)CubeFace.PositiveZ).Max(page=>page.Metadata.Address.Y));
|
||||
}
|
||||
Assert.Equal(levels.Order(),levels);
|
||||
Assert.True(levels[^1]>levels[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReloadReconstructsTheSameCutAndFadesResidualsFromItsParent()
|
||||
{
|
||||
ZyphosPlanetarySurfacePages.Reset();
|
||||
var center=ZyphosUmbrosSystem.ZyphosCenter;
|
||||
var camera=center+Vector3.Normalize(new Vector3(0.61f,-0.22f,0.76f))*(ZyphosUmbrosSystem.ZyphosSurfaceRadius+0.04f);
|
||||
var before=ZyphosSceneBuilder.Build(401.0f,400.0f,camera,default).PlanetarySurfacePages;
|
||||
var reloaded=ZyphosSceneBuilder.Build(0.0f,0.0f,camera,default).PlanetarySurfacePages;
|
||||
Assert.Equal(before.Pages.Select(page=>page.ContentKey),reloaded.Pages.Select(page=>page.ContentKey));
|
||||
Assert.Equal(before.ContentVersion,reloaded.ContentVersion);
|
||||
Assert.All(reloaded.Pages.Take(6),page=>Assert.Equal(1.0f,page.Metadata.State.Y));
|
||||
Assert.All(reloaded.Pages.Skip(6),page=>Assert.Equal(0.0f,page.Metadata.State.Y));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in a new issue