Guides · Getting started · Fluent chains · Noise · SDF · Jobify
Extension Library for Unity.Mathematics & quality of life improvements !
[!NOTE]\
com.ltmx.mathematics.mathx
- Copy Git Package URL :
https://github.com/LTMX/Unity.mathx.git - 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.jsonfile 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 -
Mathffunction implementations missing fromUnity.Mathematics - Random Extensions (
Random.rangeand 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:
Topic guides: fluent chains, noise, SDF, Jobify, and more on the docs home.
Edit Mode tests ship in 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 docs~/QUALITY.md or the Quality page for setup, golden-value regeneration, and IL2CPP validation.
- All methods should exist in the
Unity.Mathematics.mathxclass (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
boundsorbyte2should only have their type as a title : bounds.cs // byte2.cs
- File names for base types such as
- 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)
