HLSL is now CultMath's semantic authority where it defines one. - float2/3/4, int2, double2/3, bool2 and quaternion are plain structs with public mutable fields instead of record structs. Indexers and swizzles (float2.yx; float3 xy xz yx yz zy xyz xzy yzx zyx; float4 xy xyz xyw yzx) have setters. - ==, !=, <, >, <=, >= are component-wise and return bool2/3/4. Equals and GetHashCode stay value-based so vectors remain dictionary keys. quaternion is not an HLSL type and keeps a bool ==. - Scalar/vector arithmetic and comparisons get explicit overloads on both sides instead of leaning on implicit splat. - New types: bool3, bool4, int3, int4, float2x2, float3x3 (row-major like HLSL, _mRC fields, Rotate / RotateX/Y/Z / Euler with math.RotationOrder). - New intrinsics: mul (matrix-vector both sides, matrix-matrix), any, all, select (HLSL argument order), log, vector pow/sqrt/sin/cos/acos/atan2, double min/max, int3/int4/bool3/bool4/float2x2/float3x3 constructor functions. - simplex_noise is renamed snoise and gains the Ashima 3D variant; the HLSL mirror follows as cultmath_snoise(float2/float3). - Random gains NextFloat3() and NextFloat3(float3 max) on the same draw order. Tests pin snoise(float3), float3x3.Euler and float2x2.Rotate to Unity.Mathematics reference values, and an HLSL-shaped source block compiles under using static CultMath.math. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
using Xunit;
|
|
|
|
namespace CultMath.Tests;
|
|
|
|
public sealed class HlslMirrorTests
|
|
{
|
|
[Fact]
|
|
public void HlslMirrorDoesNotPublishGeometryKernels()
|
|
{
|
|
var source = File.ReadAllText(Path.Combine(GetCultMathRoot(), "shaders", "CultMath.hlsl"));
|
|
Assert.DoesNotContain("AdvancedErosionFilter.hlsl", source);
|
|
Assert.DoesNotContain("Planetary.hlsl", source);
|
|
Assert.DoesNotContain("spherical_erosion", source);
|
|
Assert.DoesNotContain("planetary_radial_refinement", source);
|
|
}
|
|
|
|
[Fact]
|
|
public void HlslMirrorPublishesCultMathPrimitives()
|
|
{
|
|
var include = File.ReadAllText(Path.Combine(GetCultMathRoot(), "shaders", "CultMath.hlsl"));
|
|
var requiredSymbols = new[]
|
|
{
|
|
"cultmath_radians",
|
|
"cultmath_degrees",
|
|
"cultmath_frac",
|
|
"cultmath_clamp",
|
|
"cultmath_saturate",
|
|
"cultmath_lerp",
|
|
"cultmath_step",
|
|
"cultmath_smoothstep",
|
|
"cultmath_smootherstep",
|
|
"cultmath_lengthsq",
|
|
"cultmath_distance",
|
|
"cultmath_normalize",
|
|
"cultmath_reflect",
|
|
"cultmath_rotate",
|
|
"cultmath_csum",
|
|
"cultmath_decay",
|
|
"cultmath_damp",
|
|
"cultmath_catmullrom",
|
|
"cultmath_quadratic_bezier",
|
|
"cultmath_cubic_bezier",
|
|
"cultmath_hash",
|
|
"cultmath_value_noise",
|
|
"cultmath_snoise(float2",
|
|
"cultmath_snoise(float3",
|
|
"cultmath_value_noise_bicubic",
|
|
"cultmath_value_noise_texture",
|
|
"cultmath_value_noise_texture_bicubic",
|
|
};
|
|
|
|
foreach (var symbol in requiredSymbols)
|
|
{
|
|
Assert.Contains(symbol, include);
|
|
}
|
|
|
|
Assert.Contains("CULTMATH_NORMALIZE_EPSILON", include);
|
|
Assert.Contains("max(length(value), CULTMATH_NORMALIZE_EPSILON)", include);
|
|
}
|
|
|
|
private static string GetCultMathRoot()
|
|
{
|
|
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
|
while (directory is not null)
|
|
{
|
|
var monorepoPackage = Path.Combine(directory.FullName, "packages", "cultmath");
|
|
if (File.Exists(Path.Combine(monorepoPackage, "shaders", "CultMath.hlsl")))
|
|
{
|
|
return monorepoPackage;
|
|
}
|
|
|
|
directory = directory.Parent;
|
|
}
|
|
|
|
throw new InvalidOperationException("Could not locate the CultMath package root.");
|
|
}
|
|
}
|