Add faithful advanced erosion filter core
This commit is contained in:
parent
ab6a2c6456
commit
430cbc9695
8 changed files with 327 additions and 1 deletions
44
tests/CultMath.Tests/AdvancedErosionFilterTests.cs
Normal file
44
tests/CultMath.Tests/AdvancedErosionFilterTests.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using Xunit;
|
||||
|
||||
namespace CultMath.Tests;
|
||||
|
||||
public sealed class AdvancedErosionFilterTests
|
||||
{
|
||||
[Fact]
|
||||
public void DefaultReferenceFixtureIsStable()
|
||||
{
|
||||
var result = AdvancedErosionFilter.Sample(
|
||||
new float2(0.42f, 0.31f),
|
||||
new float3(0.5f, 0.1f, -0.2f),
|
||||
0.0f,
|
||||
AdvancedErosionParameters.Default);
|
||||
|
||||
Assert.Equal(0.0639375f, result.Magnitude, precision: 7);
|
||||
Assert.True(float.IsFinite(result.Delta.x));
|
||||
Assert.True(float.IsFinite(result.Delta.y));
|
||||
Assert.True(float.IsFinite(result.Delta.z));
|
||||
Assert.InRange(result.RidgeMap, -1.0f, 1.0f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FlatInputAndZeroRoundingRemainFinite()
|
||||
{
|
||||
var parameters = AdvancedErosionParameters.Default with { Rounding = float4.zero };
|
||||
var result = AdvancedErosionFilter.Sample(new float2(0.25f, 0.75f), float3.zero, 0.0f, parameters);
|
||||
|
||||
Assert.True(float.IsFinite(result.Delta.x));
|
||||
Assert.True(float.IsFinite(result.RidgeMap));
|
||||
Assert.True(float.IsFinite(result.FadeTarget));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PhacellePartialNormalizationIsFiniteAtEndpoints()
|
||||
{
|
||||
foreach (var normalization in new[] { 0.0f, 0.5f, 1.0f })
|
||||
{
|
||||
var sample = AdvancedErosionFilter.Phacelle(new float2(1.7f, -3.2f), new float2(0.6f, -0.8f), 0.7f, 0.25f, normalization);
|
||||
Assert.True(float.IsFinite(sample.x));
|
||||
Assert.True(float.IsFinite(sample.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,11 +7,22 @@ public sealed class HlslMirrorTests
|
|||
[Fact]
|
||||
public void HlslMirrorPublishesSphericalErosionKernel()
|
||||
{
|
||||
var source = File.ReadAllText(FindHlslMirror());
|
||||
var source = File.ReadAllText(Path.Combine(GetRepositoryRoot(), "shaders", "CultMath.hlsl"));
|
||||
Assert.Contains("cultmath_spherical_erosion", source);
|
||||
Assert.Contains("CultMathSphericalErosionParameters", source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HlslMirrorPublishesFaithfulAdvancedErosionKernel()
|
||||
{
|
||||
var mirror = Path.Combine(GetRepositoryRoot(), "shaders", "CultMath.hlsl");
|
||||
var source = File.ReadAllText(mirror);
|
||||
Assert.Contains("AdvancedErosionFilter.hlsl", source);
|
||||
var advanced = File.ReadAllText(Path.Combine(Path.GetDirectoryName(mirror)!, "AdvancedErosionFilter.hlsl"));
|
||||
Assert.Contains("cultmath_phacelle_noise", advanced);
|
||||
Assert.Contains("cultmath_advanced_erosion_filter", advanced);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HlslMirrorPublishesCultMathPrimitives()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using Xunit;
|
||||
|
||||
namespace CultMath.Tests;
|
||||
|
||||
public sealed class SphericalErosionTests
|
||||
|
|
|
|||
Reference in a new issue