From 35812337d768b0eb581e0c4f13bc3e4b12b7eb52 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 12 Jul 2026 20:09:52 +0100 Subject: [PATCH] Generate seam-stable planetary erosion pages --- .../Lod/PlanetarySurfacePage.cs | 62 +++++++++++++++++++ .../Shaders/D3D12ZyphosPlanet.hlsl | 52 +--------------- .../Shaders/D3D12ZyphosTerrain.hlsli | 47 ++++++++++++++ .../Shaders/D3D12ZyphosTerrainPage.hlsl | 26 ++++++++ state/evidence.jsonl | 1 + state/map.yaml | 4 ++ .../PlanetarySurfacePageTests.cs | 37 +++++++++++ .../Aquarium.Engine.Tests.csproj | 1 + .../D3D12PlanetarySurfacePageTests.cs | 48 ++++++++++++++ 9 files changed, 229 insertions(+), 49 deletions(-) create mode 100644 src/Aquarium.Engine.Fractal/Lod/PlanetarySurfacePage.cs create mode 100644 src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrain.hlsli create mode 100644 src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPage.hlsl create mode 100644 tests/Aquarium.Engine.Fractal.Tests/PlanetarySurfacePageTests.cs create mode 100644 tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs diff --git a/src/Aquarium.Engine.Fractal/Lod/PlanetarySurfacePage.cs b/src/Aquarium.Engine.Fractal/Lod/PlanetarySurfacePage.cs new file mode 100644 index 0000000..7657e6a --- /dev/null +++ b/src/Aquarium.Engine.Fractal/Lod/PlanetarySurfacePage.cs @@ -0,0 +1,62 @@ +using System.Numerics; + +namespace Aquarium.Engine.Fractal.Lod; + +public readonly record struct PlanetarySurfacePageRequest(CubeTileKey Tile, int InteriorSize, int BorderSize) +{ + public int StorageSize => checked(InteriorSize + BorderSize * 2); + + public PlanetarySurfacePageRequest Validate() + { + if (InteriorSize < 2) throw new ArgumentOutOfRangeException(nameof(InteriorSize)); + if (BorderSize < 0 || BorderSize >= InteriorSize) throw new ArgumentOutOfRangeException(nameof(BorderSize)); + return this; + } +} + +public readonly record struct PlanetarySurfacePageSummary( + float MinimumHeight, + float MaximumHeight, + float MaximumSlope, + float UnresolvedHeightBound, + float AngularTexelSize); + +public static class PlanetarySurfacePageSampling +{ + private const double QuarterPi = Math.PI * 0.25; + + public static Vector3 Direction(PlanetarySurfacePageRequest request, int storageX, int storageY) + { + request.Validate(); + if ((uint)storageX >= request.StorageSize || (uint)storageY >= request.StorageSize) throw new ArgumentOutOfRangeException(); + var localU = (storageX - request.BorderSize) / (double)(request.InteriorSize - 1); + var localV = (storageY - request.BorderSize) / (double)(request.InteriorSize - 1); + var count = request.Tile.AxisTileCount; + var faceU = -1.0 + 2.0 * (request.Tile.X + localU) / count; + var faceV = -1.0 + 2.0 * (request.Tile.Y + localV) / count; + var u = Math.Tan(faceU * QuarterPi); + var v = Math.Tan(faceV * QuarterPi); + var cube = request.Tile.Face switch + { + CubeFace.PositiveX => new Vector3(1, (float)v, (float)-u), CubeFace.NegativeX => new Vector3(-1, (float)v, (float)u), + CubeFace.PositiveY => new Vector3((float)u, 1, (float)-v), CubeFace.NegativeY => new Vector3((float)u, -1, (float)v), + CubeFace.PositiveZ => new Vector3((float)u, (float)v, 1), CubeFace.NegativeZ => new Vector3((float)-u, (float)v, -1), + _ => throw new ArgumentOutOfRangeException(), + }; + return Vector3.Normalize(cube); + } + + public static float AngularTexelSize(PlanetarySurfacePageRequest request) + { + var center = request.BorderSize + (request.InteriorSize - 1) / 2; + var a = Direction(request, center, center); + var b = Direction(request, Math.Min(center + 1, request.StorageSize - 1), center); + return MathF.Acos(Math.Clamp(Vector3.Dot(a, b), -1.0f, 1.0f)); + } + + public static float NominalAngularTexelSize(PlanetarySurfacePageRequest request) + { + request.Validate(); + return (MathF.PI * 0.5f) / (request.Tile.AxisTileCount * (request.InteriorSize - 1)); + } +} diff --git a/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl index 9085442..6f265d9 100644 --- a/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl +++ b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl @@ -4,6 +4,7 @@ static const int ZYPHOS_GEOMETRY_BRUSH_LIMIT = 4; #include "D3D12SdfCommon.hlsli" #include "D3D12SdfMath.hlsli" #include "CultMath/CultMath.hlsl" +#include "D3D12ZyphosTerrain.hlsli" float3 zyRotateZ(float3 p, float angle) { @@ -29,54 +30,6 @@ float zyUmbrosEclipse(float3 starDirectionLocal) return smoothstep(cos(umbrosAngularRadius * 1.45), cos(umbrosAngularRadius * 0.45), alignment); } -float zySphericalField(float3 dir) -{ - float latitude = asin(saturate(abs(dir.z)) * 2.0 - 1.0); - float longitude = atan2(dir.y, dir.x); - float plates = - sin(longitude * 2.0 + dir.z * 4.5) * 0.28 + - sin(longitude * 3.0 - dir.z * 7.0 + 1.7) * 0.22 + - sin((dir.x + dir.y * 0.7 + dir.z * 0.4) * 8.0) * 0.16 + - sin((dir.x * 1.3 - dir.y + dir.z * 1.9) * 13.0) * 0.08; - float equatorialWarmth = cos(latitude) * 0.18; - return 0.50 + plates + equatorialWarmth; -} - -float3 zySphericalFieldGradient(float3 dir) -{ - const float epsilon = 0.0015; - float dx = zySphericalField(normalize(dir + float3(epsilon, 0, 0))) - zySphericalField(normalize(dir - float3(epsilon, 0, 0))); - float dy = zySphericalField(normalize(dir + float3(0, epsilon, 0))) - zySphericalField(normalize(dir - float3(0, epsilon, 0))); - float dz = zySphericalField(normalize(dir + float3(0, 0, epsilon))) - zySphericalField(normalize(dir - float3(0, 0, epsilon))); - float3 gradient = float3(dx, dy, dz) / (2.0 * epsilon); - return gradient - dir * dot(gradient, dir); -} - -CultMathAdvancedErosionParameters zyErosionParameters(float planetRadius) -{ - CultMathAdvancedErosionParameters p; - p.scale = planetRadius * 0.075; p.strength = 0.12; p.gully_weight = 0.58; p.detail = 1.45; - p.rounding = float4(0.1, 0.015, 0.1, 2.0); p.onset = float4(1.25, 1.25, 2.8, 1.5); - p.assumed_slope = float2(0.7, 0.85); p.cell_scale = 0.7; p.normalization = 0.5; - p.octaves = 7; p.lacunarity = 2.0; p.gain = 0.5; return p; -} - -float zyAdvancedErosionHeight(float3 dir, float field, SdfObject sdfObject) -{ - float radius = max(sdfObject.state.x, 0.001); - float3 world = dir * radius; - float3 gradient = zySphericalFieldGradient(dir) / radius; - float3 weights = pow(abs(dir), 4.0); weights /= max(weights.x + weights.y + weights.z, 1.0e-6); - CultMathAdvancedErosionParameters p = zyErosionParameters(radius); - float sampleSpacing = max(viewRadius / max(resolution.y, 1.0) * 2.0, radius / 8192.0); - CultMathErosionBandSelection band = cultmath_select_erosion_bands(p.scale * p.cell_scale, sampleSpacing, p.octaves, p.lacunarity, p.strength * p.scale, p.gain, 2.0); - float fade = saturate(field * 0.5 + 0.5) * 2.0 - 1.0; - CultMathAdvancedErosionResult xy = cultmath_advanced_erosion_filter_banded(world.xy + float2(713.0, -291.0), float3(field, gradient.x, gradient.y), fade, p, band); - CultMathAdvancedErosionResult yz = cultmath_advanced_erosion_filter_banded(world.yz + float2(-431.0, 887.0), float3(field, gradient.y, gradient.z), fade, p, band); - CultMathAdvancedErosionResult zx = cultmath_advanced_erosion_filter_banded(world.zx + float2(197.0, 557.0), float3(field, gradient.z, gradient.x), fade, p, band); - return xy.delta.x * weights.z + yz.delta.x * weights.x + zx.delta.x * weights.y; -} - float zyHash21(float2 p) { p = frac(p * float2(123.34, 456.21)); @@ -263,7 +216,8 @@ float zyPebbleCluster(float3 dir) float zyTerrainOffset(float3 dir, SdfObject sdfObject) { float field = zySphericalField(dir); - float erosionHeight = zyAdvancedErosionHeight(dir, field, sdfObject); + float sampleSpacing = max(viewRadius / max(resolution.y, 1.0) * 2.0, max(sdfObject.state.x, 0.001) / 8192.0); + float erosionHeight = zyAdvancedErosion(dir, field, max(sdfObject.state.x, 0.001), sampleSpacing).x; float seaLevel = sdfObject.state.z; float land = smoothstep(seaLevel - 0.04, seaLevel + 0.08, field); float mountain = pow(saturate(field - seaLevel), 1.65); diff --git a/src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrain.hlsli b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrain.hlsli new file mode 100644 index 0000000..92fb583 --- /dev/null +++ b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrain.hlsli @@ -0,0 +1,47 @@ +#ifndef D3D12_ZYPHOS_TERRAIN_HLSLI +#define D3D12_ZYPHOS_TERRAIN_HLSLI + +#include "CultMath/CultMath.hlsl" + +float zySphericalField(float3 dir) +{ + float latitude = asin(saturate(abs(dir.z)) * 2.0 - 1.0); + float longitude = atan2(dir.y, dir.x); + float plates = sin(longitude * 2.0 + dir.z * 4.5) * 0.28 + sin(longitude * 3.0 - dir.z * 7.0 + 1.7) * 0.22 + + sin((dir.x + dir.y * 0.7 + dir.z * 0.4) * 8.0) * 0.16 + sin((dir.x * 1.3 - dir.y + dir.z * 1.9) * 13.0) * 0.08; + return 0.50 + plates + cos(latitude) * 0.18; +} + +float3 zySphericalFieldGradient(float3 dir) +{ + const float epsilon = 0.0015; + float dx = zySphericalField(normalize(dir + float3(epsilon,0,0))) - zySphericalField(normalize(dir - float3(epsilon,0,0))); + float dy = zySphericalField(normalize(dir + float3(0,epsilon,0))) - zySphericalField(normalize(dir - float3(0,epsilon,0))); + float dz = zySphericalField(normalize(dir + float3(0,0,epsilon))) - zySphericalField(normalize(dir - float3(0,0,epsilon))); + float3 gradient = float3(dx,dy,dz)/(2.0*epsilon); return gradient-dir*dot(gradient,dir); +} + +CultMathAdvancedErosionParameters zyErosionParameters(float radius) +{ + CultMathAdvancedErosionParameters p; + p.scale=radius*0.075; p.strength=0.12; p.gully_weight=0.58; p.detail=1.45; + p.rounding=float4(0.1,0.015,0.1,2.0); p.onset=float4(1.25,1.25,2.8,1.5); p.assumed_slope=float2(0.7,0.85); + p.cell_scale=0.7; p.normalization=0.5; p.octaves=7; p.lacunarity=2.0; p.gain=0.5; return p; +} + +float4 zyAdvancedErosion(float3 dir, float field, float radius, float sampleSpacing) +{ + float3 world=dir*radius; float3 gradient=zySphericalFieldGradient(dir)/radius; + float3 weights=pow(abs(dir),4.0); weights/=max(weights.x+weights.y+weights.z,1.0e-6); + CultMathAdvancedErosionParameters p=zyErosionParameters(radius); + CultMathErosionBandSelection band=cultmath_select_erosion_bands(p.scale*p.cell_scale,sampleSpacing,p.octaves,p.lacunarity,p.strength*p.scale,p.gain,2.0); + float fade=saturate(field*0.5+0.5)*2.0-1.0; + CultMathAdvancedErosionResult xy=cultmath_advanced_erosion_filter_banded(world.xy+float2(713,-291),float3(field,gradient.x,gradient.y),fade,p,band); + CultMathAdvancedErosionResult yz=cultmath_advanced_erosion_filter_banded(world.yz+float2(-431,887),float3(field,gradient.y,gradient.z),fade,p,band); + CultMathAdvancedErosionResult zx=cultmath_advanced_erosion_filter_banded(world.zx+float2(197,557),float3(field,gradient.z,gradient.x),fade,p,band); + float height=xy.delta.x*weights.z+yz.delta.x*weights.x+zx.delta.x*weights.y; + float ridge=xy.ridge_map*weights.z+yz.ridge_map*weights.x+zx.ridge_map*weights.y; + return float4(height,saturate(ridge*0.5+0.5),saturate(0.5-ridge*0.5),band.unresolved_height_bound); +} + +#endif diff --git a/src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPage.hlsl b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPage.hlsl new file mode 100644 index 0000000..23f6623 --- /dev/null +++ b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPage.hlsl @@ -0,0 +1,26 @@ +#include "D3D12ZyphosTerrain.hlsli" + +struct PageInput { float4 direction_radius; float4 sampling; }; +struct PageOutput { float4 height_gradient; float4 masks; }; +StructuredBuffer page_inputs : register(t0); +RWStructuredBuffer page_outputs : register(u0); +cbuffer PageConstants : register(b0) { uint page_sample_count; } + +float zyPageErosion(float3 direction, float radius, float spacing) +{ + float3 dir=normalize(direction); return zyAdvancedErosion(dir,zySphericalField(dir),radius,spacing).x; +} + +[numthreads(64,1,1)] +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; + 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); + 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); +} diff --git a/state/evidence.jsonl b/state/evidence.jsonl index a29f29b..049bb9f 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -335,3 +335,4 @@ {"timestamp":"2026-07-12T19:25:00+01:00","topic":"stateless-spherical-erosion","lesson":"Cube-sphere erosion must be a pure planet-space point function rather than six face-local filters or a repair pass. CultMath now owns matching C# and HLSL kernels keyed by unit direction, tangent base gradient, seed, and bounded octave parameters; Zyphos composes the result after its continental field, while cube faces remain lookup and scheduling charts.","files":["E:\\Projects\\CultMath\\src\\CultMath\\SphericalErosion.cs","E:\\Projects\\CultMath\\shaders\\CultMath.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","state/map.yaml"],"source":"user requested a C# CPU implementation in CultMath matching the GPU code"} {"timestamp":"2026-07-12T20:30:00+01:00","topic":"advanced-erosion-gpu-parity","lesson":"Float-based cell hashes diverged enough between C# and HLSL to select different erosion pivots across a 2052-sample corpus. CultMath now uses the same integer avalanche hash in both paths, and Fensalir verifies the actual HLSL kernel with a standalone D3D12 compute/readback probe instead of inferring parity from similar source text or booting the renderer.","files":["E:\\Projects\\CultMath\\src\\CultMath\\AdvancedErosionFilter.cs","E:\\Projects\\CultMath\\shaders\\AdvancedErosionFilter.hlsl","src/Aquarium.Engine/Render/D3D12ComputeProbe.cs","src/Aquarium.Engine/Render/D3D12ShaderCompiler.cs","tests/Aquarium.Engine.Tests/D3D12AdvancedErosionParityTests.cs"],"source":"measured CPU/GPU parity implementation"} {"timestamp":"2026-07-12T21:00:00+01:00","topic":"erosion-physical-frequency-bands","lesson":"Planetary erosion LOD is now a filter over one world-space spectrum: CultMath selects active octaves from physical wavelength and sample spacing, fractionally weights the last resolvable octave, and reports omitted height. Zyphos uses that contract through smooth planet-space triplanar charts, so changing view footprint changes represented bands rather than switching terrain authorities.","files":["E:\\Projects\\CultMath\\src\\CultMath\\ErosionFrequencyBands.cs","E:\\Projects\\CultMath\\src\\CultMath\\AdvancedErosionFilter.cs","E:\\Projects\\CultMath\\shaders\\AdvancedErosionFilter.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl"],"source":"phase 3 of stateless planetary erosion rendering plan"} +{"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"} diff --git a/state/map.yaml b/state/map.yaml index 5e7e9b1..f548045 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -89,6 +89,10 @@ invariants: fractionally and reports its omitted-height bound; Zyphos lowers the planar reference filter through smooth planet-space triplanar charts, not cube-face terrain ownership. + - Planetary surface pages use one level-global nominal angular footprint for + band selection. Per-tile projection distortion is summary evidence only; + it may not change terrain at a shared boundary. Page borders evaluate the + spherical field beyond tile bounds without reading neighbor residency. - 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 diff --git a/tests/Aquarium.Engine.Fractal.Tests/PlanetarySurfacePageTests.cs b/tests/Aquarium.Engine.Fractal.Tests/PlanetarySurfacePageTests.cs new file mode 100644 index 0000000..f7b187b --- /dev/null +++ b/tests/Aquarium.Engine.Fractal.Tests/PlanetarySurfacePageTests.cs @@ -0,0 +1,37 @@ +using Aquarium.Engine.Fractal.Lod; + +namespace Aquarium.Engine.Fractal.Tests; + +public sealed class PlanetarySurfacePageTests +{ + [Fact] + public void SiblingPagesShareBitStableBoundaryDirections() + { + var left = new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveZ, 1, 0, 0), 17, 2); + var right = new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveZ, 1, 1, 0), 17, 2); + for (var y = 0; y < left.InteriorSize; y++) + { + var a = PlanetarySurfacePageSampling.Direction(left, left.BorderSize + left.InteriorSize - 1, left.BorderSize + y); + var b = PlanetarySurfacePageSampling.Direction(right, right.BorderSize, right.BorderSize + y); + Assert.Equal(a, b); + } + } + + [Fact] + public void BorderSamplesExtendPastTileWithoutNeighborResidency() + { + var page = new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveX, 0, 0, 0), 17, 3); + var edge = PlanetarySurfacePageSampling.Direction(page, page.BorderSize + page.InteriorSize - 1, page.BorderSize + 8); + var border = PlanetarySurfacePageSampling.Direction(page, page.StorageSize - 1, page.BorderSize + 8); + Assert.NotEqual(edge, border); + Assert.Equal(1.0f, border.Length(), precision: 5); + } + + [Fact] + public void AngularTexelSizeShrinksWithQuadtreeLevel() + { + var root = new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveZ, 0, 0, 0), 129, 4); + var child = new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveZ, 1, 0, 0), 129, 4); + Assert.True(PlanetarySurfacePageSampling.AngularTexelSize(child) < PlanetarySurfacePageSampling.AngularTexelSize(root)); + } +} diff --git a/tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj b/tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj index 63d3d04..1cdd582 100644 --- a/tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj +++ b/tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj @@ -20,6 +20,7 @@ + diff --git a/tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs b/tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs new file mode 100644 index 0000000..76ecf9b --- /dev/null +++ b/tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs @@ -0,0 +1,48 @@ +using System.Numerics; +using System.Runtime.InteropServices; +using Aquarium.Engine.Fractal; +using Aquarium.Engine.Fractal.Lod; +using Aquarium.Engine.Render; + +namespace Aquarium.Engine.Tests; + +public sealed class D3D12PlanetarySurfacePageTests +{ + [Fact] + public void IndependentlyGeneratedSiblingPagesAgreeOnSharedBoundary() + { + var left = new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveZ,1,0,0),9,2); + var right = new PlanetarySurfacePageRequest(new CubeTileKey(CubeFace.PositiveZ,1,1,0),9,2); + var leftOutput = Generate(left); var rightOutput = Generate(right); + for(int y=0;y{Assert.True(float.IsFinite(s.HeightGradient.X));Assert.True(float.IsFinite(s.HeightGradient.Y));Assert.InRange(s.Masks.X,0,1);Assert.InRange(s.Masks.Y,0,1);}); + var min=output.Min(s=>s.HeightGradient.X); var max=output.Max(s=>s.HeightGradient.X); var slope=output.Max(s=>MathF.Sqrt(s.HeightGradient.Y*s.HeightGradient.Y+s.HeightGradient.Z*s.HeightGradient.Z)); + Assert.True(min<=max); Assert.True(slope>=0); Assert.True(output.Max(s=>s.HeightGradient.W)>=0); + } + + private static PageOutput[] Generate(PlanetarySurfacePageRequest request) + { + const float radius=8.4f; var spacing=PlanetarySurfacePageSampling.NominalAngularTexelSize(request)*radius; + var input=new PageInput[request.StorageSize*request.StorageSize]; + for(int y=0;y(shader,"D3D12ZyphosTerrainPageCS",input); + } + + private static string RepositoryRoot(){var d=new DirectoryInfo(AppContext.BaseDirectory);while(d is not null&&!File.Exists(Path.Combine(d.FullName,"Fensalir.sln")))d=d.Parent;return d?.FullName??throw new InvalidOperationException();} + [StructLayout(LayoutKind.Sequential)] private readonly record struct PageInput(Vector4 DirectionRadius,Vector4 Sampling); + [StructLayout(LayoutKind.Sequential)] private readonly record struct PageOutput(Vector4 HeightGradient,Vector4 Masks); +}