No description
This repository has been archived on 2026-10-29. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • C# 59.9%
  • HLSL 25.1%
  • PowerShell 9.4%
  • Rust 5.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-05-08 01:49:44 +01:00
docs Seed HLSL-shaped math library 2026-05-08 01:49:44 +01:00
src/CultMath Seed HLSL-shaped math library 2026-05-08 01:49:44 +01:00
tests/CultMath.Tests Seed HLSL-shaped math library 2026-05-08 01:49:44 +01:00
.gitignore Seed HLSL-shaped math library 2026-05-08 01:49:44 +01:00
CultMath.slnx Seed HLSL-shaped math library 2026-05-08 01:49:44 +01:00
global.json Seed HLSL-shaped math library 2026-05-08 01:49:44 +01:00
README.md Seed HLSL-shaped math library 2026-05-08 01:49:44 +01:00

CultMath

Clean-room C# math shaped for people who think in HLSL.

CultMath provides lowercase vector types and shader-style intrinsics so math-heavy renderer code can move between C# and HLSL without turning every line into a translation exercise. It is not a Unity.Mathematics clone. It is a small, Aquarium-born library built from public shader semantics and plain .NET.

Current Surface

  • float2, float3, float4
  • component-wise arithmetic
  • scalar-to-vector splats
  • swizzles for common lanes
  • conversions to and from System.Numerics
  • math intrinsics: radians, degrees, abs, floor, ceil, frac, min, max, clamp, saturate, lerp, step, smoothstep, dot, cross, length, distance, normalize, and reflect

Example

using CultMath;

float3 normal = math.normalize(new float3(0.25f, 1.0f, -0.1f));
float rim = math.saturate(1.0f - math.dot(normal, new float3(0.0f, 0.0f, -1.0f)));
float glow = math.smoothstep(0.2f, 1.0f, rim);

Build

dotnet build CultMath.slnx
dotnet test CultMath.slnx

Doctrine

The goal is mechanical sympathy between CPU-side authoring and GPU-side shader math. If an intrinsic exists here, it should behave like the shader concept unless .NET numeric rules make that impossible. Weird deviations get tests and documentation, not folklore.