Render footprint-filtered advanced planet erosion
This commit is contained in:
parent
bc4ca92aab
commit
071bfc288a
5 changed files with 48 additions and 24 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include "CultMath/CultMath.hlsl"
|
||||
|
||||
struct ParityInput { float4 position_base; float4 slope_fade; float4 scalar0; float4 rounding; float4 onset; float4 scalar1; float4 scalar2; };
|
||||
struct ParityInput { float4 position_base; float4 slope_fade; float4 scalar0; float4 rounding; float4 onset; float4 scalar1; float4 scalar2; float4 scalar3; };
|
||||
struct ParityOutput { float4 delta_magnitude; float4 ridge_fade; };
|
||||
StructuredBuffer<ParityInput> inputs : register(t0);
|
||||
RWStructuredBuffer<ParityOutput> outputs : register(u0);
|
||||
|
|
@ -16,7 +16,8 @@ void D3D12AdvancedErosionParityCS(uint3 id : SV_DispatchThreadID)
|
|||
p.rounding=input.rounding; p.onset=input.onset; p.assumed_slope=input.scalar1.xy;
|
||||
p.cell_scale=input.scalar1.z; p.normalization=input.scalar1.w; p.octaves=(int)input.scalar2.x;
|
||||
p.lacunarity=input.scalar2.y; p.gain=input.scalar2.z;
|
||||
CultMathAdvancedErosionResult r = cultmath_advanced_erosion_filter(input.position_base.xy, float3(input.position_base.z, input.slope_fade.xy), input.slope_fade.z, p);
|
||||
CultMathErosionBandSelection band; band.active_octaves=(int)input.scalar3.x; band.final_octave_weight=input.scalar3.y; band.finest_included_wavelength=input.scalar3.z; band.unresolved_height_bound=input.scalar3.w;
|
||||
CultMathAdvancedErosionResult r = cultmath_advanced_erosion_filter_banded(input.position_base.xy, float3(input.position_base.z, input.slope_fade.xy), input.slope_fade.z, p, band);
|
||||
outputs[id.x].delta_magnitude=float4(r.delta, r.magnitude);
|
||||
outputs[id.x].ridge_fade=float4(r.ridge_map, r.fade_target, 0, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,18 +52,29 @@ float3 zySphericalFieldGradient(float3 dir)
|
|||
return gradient - dir * dot(gradient, dir);
|
||||
}
|
||||
|
||||
CultMathSphericalErosionSample zyErosion(float3 dir, float field)
|
||||
CultMathAdvancedErosionParameters zyErosionParameters(float planetRadius)
|
||||
{
|
||||
CultMathSphericalErosionParameters parameters;
|
||||
parameters.frequency = 17.0;
|
||||
parameters.amplitude = 0.012;
|
||||
parameters.lacunarity = 2.03;
|
||||
parameters.gain = 0.52;
|
||||
parameters.slope_strength = 4.5;
|
||||
parameters.detail = 1.35;
|
||||
parameters.seed = 713.0;
|
||||
parameters.octaves = 5;
|
||||
return cultmath_spherical_erosion(dir, field, zySphericalFieldGradient(dir), parameters);
|
||||
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)
|
||||
|
|
@ -252,7 +263,7 @@ float zyPebbleCluster(float3 dir)
|
|||
float zyTerrainOffset(float3 dir, SdfObject sdfObject)
|
||||
{
|
||||
float field = zySphericalField(dir);
|
||||
CultMathSphericalErosionSample erosion = zyErosion(dir, field);
|
||||
float erosionHeight = zyAdvancedErosionHeight(dir, field, sdfObject);
|
||||
float seaLevel = sdfObject.state.z;
|
||||
float land = smoothstep(seaLevel - 0.04, seaLevel + 0.08, field);
|
||||
float mountain = pow(saturate(field - seaLevel), 1.65);
|
||||
|
|
@ -260,7 +271,7 @@ float zyTerrainOffset(float3 dir, SdfObject sdfObject)
|
|||
float authoredMaterial;
|
||||
float authoredGeometry = zyAuthoredBrushTerrainLimited(dir, ZYPHOS_GEOMETRY_BRUSH_LIMIT, authoredMaterial);
|
||||
float tileRelief = zyQuadtreeSdfRelief(dir) * land + zyLeafCluster(dir) * 0.018 + zyPebbleCluster(dir) * 0.010;
|
||||
return (field - seaLevel) * 0.10 + mountain * 0.13 + polarCap * land + tileRelief + authoredGeometry * 0.52 + erosion.height_offset * land;
|
||||
return (field - seaLevel) * 0.10 + mountain * 0.13 + polarCap * land + tileRelief + authoredGeometry * 0.52 + erosionHeight * land;
|
||||
}
|
||||
|
||||
float sdfDistance(float3 p, int sdfIndex)
|
||||
|
|
|
|||
|
|
@ -334,3 +334,4 @@
|
|||
{"ts":"2026-06-01T20:15:00+01:00","type":"implementation","status":"ok","note":"Render debug mode 21 is now an owner-layer overdraw view. Scene/evidence pixel shaders write a fifth additive R16_FLOAT overdraw target after discard/depth eligibility; presentation samples that target as a heat map. Coverage, step count, reservoir stats, and spatial-budget modes remain separate diagnostics instead of being relabeled as overdraw.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12SdfProxy.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12TemporalGaussian.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12FractalSplatRender.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12PointCloud.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl"],"source":"dotnet build Fensalir.sln; AQUARIUM_RENDER_DEBUG_MODE=21 .\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -ClientProject src\\Aquarium.Fensalir\\Aquarium.Fensalir.csproj"}
|
||||
{"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"}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,11 @@ invariants:
|
|||
readback probe. Shader include expansion is owned by D3D12ShaderCompiler
|
||||
and shared with the renderer; parity probes must not boot a swapchain or
|
||||
duplicate CultMath equations.
|
||||
- Planetary erosion frequencies are selected in world-distance wavelengths
|
||||
from the current sample footprint. The last resolvable octave fades
|
||||
fractionally and reports its omitted-height bound; Zyphos lowers the planar
|
||||
reference filter through smooth planet-space triplanar charts, not cube-face
|
||||
terrain ownership.
|
||||
- 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
|
||||
|
|
|
|||
|
|
@ -14,20 +14,22 @@ public sealed class D3D12AdvancedErosionParityTests
|
|||
var parameters = AdvancedErosionParameters.Default;
|
||||
var fixedCases = new[]
|
||||
{
|
||||
new Case(new float2(0.42f, 0.31f), new float3(0.5f, 0.1f, -0.2f), 0.0f, parameters),
|
||||
new Case(new float2(1.7f, -3.2f), new float3(-0.2f, 0.0f, 0.0f), -0.7f, parameters with { Normalization = 0.0f, Octaves = 1 }),
|
||||
new Case(new float2(50.5f, 77.25f), new float3(0.8f, -0.3f, 0.4f), 0.9f, parameters with { Normalization = 1.0f, Octaves = 8 }),
|
||||
new Case(new float2(-8.125f, 3.75f), float3.zero, 0.0f, parameters with { Rounding = float4.zero }),
|
||||
Case.Full(new float2(0.42f, 0.31f), new float3(0.5f, 0.1f, -0.2f), 0.0f, parameters),
|
||||
Case.Full(new float2(1.7f, -3.2f), new float3(-0.2f, 0.0f, 0.0f), -0.7f, parameters with { Normalization = 0.0f, Octaves = 1 }),
|
||||
Case.Full(new float2(50.5f, 77.25f), new float3(0.8f, -0.3f, 0.4f), 0.9f, parameters with { Normalization = 1.0f, Octaves = 8 }),
|
||||
Case.Full(new float2(-8.125f, 3.75f), float3.zero, 0.0f, parameters with { Rounding = float4.zero }),
|
||||
};
|
||||
var random = new System.Random(713);
|
||||
var cases = fixedCases.Concat(Enumerable.Range(0, 2048).Select(index =>
|
||||
{
|
||||
float Next(float min, float max) => min + (float)random.NextDouble() * (max - min);
|
||||
var p = parameters with { Octaves = 1 + index % 8, Normalization = index % 3 * 0.5f };
|
||||
return new Case(
|
||||
new float2(Next(-10, 10), Next(-10, 10)),
|
||||
new float3(Next(-1, 1), Next(-0.8f, 0.8f), Next(-0.8f, 0.8f)),
|
||||
Next(-1, 1),
|
||||
parameters with { Octaves = 1 + index % 8, Normalization = index % 3 * 0.5f });
|
||||
p,
|
||||
new ErosionBandSelection(p.Octaves, index % 2 == 0 ? 1.0f : 0.37f, 0.0f, 0.0f));
|
||||
})).ToArray();
|
||||
var gpuInputs = cases.Select(ParityInput.From).ToArray();
|
||||
var shader = Path.Combine(RepositoryRoot(), "src", "Aquarium.Engine", "Render", "Shaders", "D3D12AdvancedErosionParity.hlsl");
|
||||
|
|
@ -35,7 +37,7 @@ public sealed class D3D12AdvancedErosionParityTests
|
|||
|
||||
for (var index = 0; index < cases.Length; index++)
|
||||
{
|
||||
var cpu = AdvancedErosionFilter.Sample(cases[index].Position, cases[index].Base, cases[index].Fade, cases[index].Parameters);
|
||||
var cpu = AdvancedErosionFilter.Sample(cases[index].Position, cases[index].Base, cases[index].Fade, cases[index].Parameters, cases[index].Band);
|
||||
AssertClose(cpu.Delta.x, gpu[index].DeltaMagnitude.X, index, "height", 2.0e-5f);
|
||||
AssertClose(cpu.Delta.y, gpu[index].DeltaMagnitude.Y, index, "dx", 2.0e-4f);
|
||||
AssertClose(cpu.Delta.z, gpu[index].DeltaMagnitude.Z, index, "dy", 2.0e-4f);
|
||||
|
|
@ -55,17 +57,21 @@ public sealed class D3D12AdvancedErosionParityTests
|
|||
return directory?.FullName ?? throw new InvalidOperationException("Fensalir root not found.");
|
||||
}
|
||||
|
||||
private readonly record struct Case(float2 Position, float3 Base, float Fade, AdvancedErosionParameters Parameters);
|
||||
private readonly record struct Case(float2 Position, float3 Base, float Fade, AdvancedErosionParameters Parameters, ErosionBandSelection Band)
|
||||
{
|
||||
public static Case Full(float2 position, float3 @base, float fade, AdvancedErosionParameters p) => new(position, @base, fade, p, new ErosionBandSelection(p.Octaves, 1.0f, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private readonly record struct ParityInput(Vector4 PositionBase, Vector4 SlopeFade, Vector4 Scalar0, Vector4 Rounding, Vector4 Onset, Vector4 Scalar1, Vector4 Scalar2)
|
||||
private readonly record struct ParityInput(Vector4 PositionBase, Vector4 SlopeFade, Vector4 Scalar0, Vector4 Rounding, Vector4 Onset, Vector4 Scalar1, Vector4 Scalar2, Vector4 Scalar3)
|
||||
{
|
||||
public static ParityInput From(Case c) => new(
|
||||
new(c.Position.x, c.Position.y, c.Base.x, 0), new(c.Base.y, c.Base.z, c.Fade, 0),
|
||||
new(c.Parameters.Scale, c.Parameters.Strength, c.Parameters.GullyWeight, c.Parameters.Detail),
|
||||
(Vector4)c.Parameters.Rounding, (Vector4)c.Parameters.Onset,
|
||||
new(c.Parameters.AssumedSlope.x, c.Parameters.AssumedSlope.y, c.Parameters.CellScale, c.Parameters.Normalization),
|
||||
new(c.Parameters.Octaves, c.Parameters.Lacunarity, c.Parameters.Gain, 0));
|
||||
new(c.Parameters.Octaves, c.Parameters.Lacunarity, c.Parameters.Gain, 0),
|
||||
new(c.Band.ActiveOctaves, c.Band.FinalOctaveWeight, c.Band.FinestIncludedWavelength, c.Band.UnresolvedHeightBound));
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue