Generate every HLSL swizzle and mixed constructor; fix intrinsic types
tools/generate-swizzles.ps1 writes the checked-in src/CultMath/Swizzles.g.cs
as partial structs plus a partial math: for float2/3/4, int2/3/4 and bool2/3/4
every swizzle of length 2-4 including repeats, in xyzw and rgba naming, with
setters only on non-repeating masks, plus single-component r/g/b/a. double2/3
get lengths 2-3 (there is no double4). Every HLSL mixed constructor
(float4(float2, float2), float4(float, float2, float), copy forms, ...) exists
as a struct constructor and, for float/int/bool, a math function. The
hand-written swizzles and mixed constructors it supersedes are deleted.
Matrices store private rows and return ref float2/float3 from the row
indexer ([UnscopedRef], polyfilled for netstandard2.1), so m[1][2] = s
compiles as in HLSL; _mRC are get/set properties over the rows. Equality and
hashing stay value-based.
Intrinsics follow HLSL: sign returns int/intN and yields 0 for NaN; step is
x >= y ? 1 : 0 so NaN yields 0; any/all accept float and int vectors;
min/max/abs on int vectors return int vectors, and abs(int) returns int.
Strips the UTF-8 BOMs this branch added to math.cs, CultMath.csproj and
HlslSemanticsTests.cs.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 13:57:02 +02:00
|
|
|
<Project Sdk="Microsoft.NET.Sdk">
|
2026-05-08 01:49:44 +01:00
|
|
|
|
|
|
|
|
<PropertyGroup>
|
2026-07-12 19:33:59 +01:00
|
|
|
<TargetFrameworks>net8.0;netstandard2.1</TargetFrameworks>
|
2026-05-08 01:49:44 +01:00
|
|
|
<ImplicitUsings>enable</ImplicitUsings>
|
|
|
|
|
<Nullable>enable</Nullable>
|
2026-07-12 19:33:59 +01:00
|
|
|
<LangVersion>latest</LangVersion>
|
2026-05-08 01:49:44 +01:00
|
|
|
<RootNamespace>CultMath</RootNamespace>
|
|
|
|
|
<AssemblyName>CultMath</AssemblyName>
|
2026-08-26 17:35:51 +02:00
|
|
|
<PackageId>GameCult.Math</PackageId>
|
Add PCG integer hashes to CultMath and release 0.2.3
CultMath's hash is the shader-style frac(sin(x) * 43758.5453) and
returns float. Unity.Mathematics' hash returned a well-mixed uint, and
seeding from the float hash collapses: a 100x100 position grid gave 1625
distinct values in Aetheria's zone generator.
- math.pcg(uint), pcg3d(int3/float2/float3), and pcg4d(int4/float4)
follow Jarzynski and Olano, "Hash Functions for GPU Rendering"
(JCGT 9(3), 2020). pcg3d and pcg4d are the paper's code from page 32.
pcg is O'Neill's RXS-M-XS 32/32 output over one LCG step, with the
constants checked against pcg-c's pcg_variants.h.
- CultMath has no uint vectors, so pcg3d and pcg4d carry uint bit
patterns in int3/int4. The float overloads hash IEEE-754 bits via the
HLSL intrinsic asuint(float), which is new. pcg3d(float2) holds z at
0, the paper's route for 2 -> N inputs.
- The HLSL mirror gains the same functions, written over scalar uints
so the text compiles both in dxc 1.9.0.5402 (lib_6_3, HV 2021, clean)
and in C#. HlslSourceCompatibilityTests now compares int and uint
arguments and results by value; a wrong shift in the mirror's pcg4d
gives 208 mismatches.
- Known-answer vectors come from an independent Python transcription.
pcg3d separates a 100x100 half-unit grid (the full int3). One
component alone has one birthday collision there, as a 32-bit value
can. The same grid on the integer lattice has none.
- design.md states that the hashes are integer-exact in HLSL and on the
CPU: dxc wraps uint multiply and add modulo 2^32, as C# unchecked does.
- Bump to 0.2.3 and rebuild the tracked Unity DLL and pdb.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 18:19:53 +02:00
|
|
|
<Version>0.2.3</Version>
|
2026-05-08 01:49:44 +01:00
|
|
|
<Description>Clean-room C# math shaped for HLSL-style renderer code.</Description>
|
|
|
|
|
<Authors>GameCult</Authors>
|
|
|
|
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
|
|
|
|
<NoWarn>$(NoWarn);CS8981</NoWarn>
|
2026-06-03 02:58:56 +01:00
|
|
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
2026-09-14 14:27:44 +02:00
|
|
|
<!-- The Unity DLL is committed beside its source, so its bytes must not name a commit. -->
|
|
|
|
|
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
2026-05-08 01:49:44 +01:00
|
|
|
</PropertyGroup>
|
|
|
|
|
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
|
2026-06-10 21:22:43 +01:00
|
|
|
<None Include="..\..\shaders\CultMath.hlsl" Pack="true" PackagePath="contentFiles\any\any\shaders\CultMath.hlsl" CopyToOutputDirectory="PreserveNewest" />
|
2026-05-08 01:49:44 +01:00
|
|
|
</ItemGroup>
|
|
|
|
|
|
|
|
|
|
</Project>
|