Unity.mathx


Guides · Getting started ·
Fluent chains ·
Noise ·
SDF ·
Jobify

[!NOTE]\
com.ltmx.mathematics.mathx
- package/ — Unity package (Runtime/, Tests/, package.json)
- website/ — documentation site (MkDocs guides, DocFX API, GitHub Pages output)
- Copy Git Package URL : https://github.com/ltmx/Unity.mathx.git?path=/package
- In Unity : Window > Package Manager > Add Package From Git URL
- Download the package in releases
- Unity : Window > Package Manager > Add Package From Disk
- Select the package.json file inside the unzipped package
using static Unity.Mathematics.mathx;
return anyVector.length().clamp(0, 10).cos().sq().cube().rotate(anyQuaternion).clint().div(3.2f).rcp().mul(3.2f).sum();
// Example
float3 x = new float3(1,1,1);
// here x is set before computing lengthsq()
var x = x.mult(4.2f).shuffle().set(out x).lengthsq() + x;
// we would have to write two lines instead
x = x.div(4.2f).shuffle();
x = x.lengthsq() + x;
bool4.any(); // returns true if any component is true // or-gate
bool4.all(); // returns true if all components are true // and-gate
- Fast Functions
- Constants (PI, HPI, EULER, TAU, and many scientific constants
- Mathf function implementations missing from Unity.Mathematics
- Random Extensions (Random.range and others)
- Component based functions (cmax, cmin, cmul, cmaxAxis, cminAxis, sum)
- Signed Distance Functions
- Component based logic (any, all, select, approx, odd, even, isnan, anynan)
- Multidimentional Array data accessors => anyfloat4[,,].Get(anyInt3)
- Interpolation Functions (InOutCubic, smoothstep, smoothstep11, smoothstep9, and others)
- smoothmin, smoothmax
- Shorthands (3D Directions, 2D Directions, and others)
- Data Construction (append, float2.xyzw(), matrix construction, etc)
- Data Conversion (anyColortArray.tofloat4Array(), and others)
- Noise Functions (Simplex, Perlin, Worley, Layered, Voronoi)
- Job Helpers
- Burst Compiled Function Pointers
- Function Iterators (prevents nested loops)
- Hashing Functions
- Vector Function Builders
- Generic Jobs
struct bounds; // UnityEngine translation compatible with Unity.Mathematics (implicit cast to "UnityEngine.Bounds")
struct ray; // UnityEngine translation compatible with Unity.Mathematics (implicit cast to "UnityEngine.Ray")
struct color; // UnityEngine translation compatible with Unity.Mathematics (implicit cast to "UnityEngine.Color")
struct byte4; // Useful for Color32 to byte conversion, Useful for image file export (implicit cast to "UnityEngine.Color32") //For Unity.QOI
struct byte3; // For Unity.QOI
struct byte2;
struct byte1;
The full searchable API (thousands of overloads) is generated from XML docs:
Browse API →
Topic guides: fluent chains, noise, SDF, Jobify, and more on the docs home.
Edit Mode tests ship in package/Tests/ (Unity Test Framework). Package tests require "testables": ["com.ltmx.mathematics.mathx"] in your project Packages/manifest.json (plus com.unity.test-framework). Then open Window → General → Test Runner → Edit Mode.
See website/docs~/QUALITY.md or the Quality page for setup, golden-value regeneration, and IL2CPP validation.
- All methods should exist in the Unity.Mathematics.mathx class (To prevent multiple using declarations)
- All Methods should follow a lower case syntax (shader like syntax)
- All methods names should be as short as possible while conserving their meaning or naming convension
- Everything must be Open Source
- Credits should (if the author can be found) figure above code snipets or in the file header (if reusing existing code)
- file mames should follow this convention : mathx..
Example : mathx.interpolation.common (common methods for interpolation) or mathx.logix.floatx (float type related logic functions)
- File names for base types such as bounds or byte2 should only have their type as a title : bounds.cs // byte2.cs
- Every method should be static (if applicable)
- Dependencies should not exist if applicable
- Code must be rewritten and optimized for Unity.Mathematics, compatibility checked
- Unification is key : if some functions are already available in math or Unity.Mathematics.math (sometimes under another name), use them !
- Documentation should be inherited from Unity.Mathematics.math methods for direct extension method translations
This project is licensed under the MIT License (License)