You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 37519dc
Browse filesBrowse the repository at this point in the historyBrowse files
perf(noise): flat gradient tables and hoisted worley hashes
Store the permutation as a Uint8Array and the 3D/4D gradients as flat
Float64Array triples and quads, so each corner contribution indexes the table
directly instead of chasing a nested Vec3[]/Vec4[] pointer. Worley samplers
hoist the y and z hash stages out of the innermost loop. Outputs are
bit-identical to the previous implementation.
Measured with labs against the full-suite baseline (8 fresh-process blocks,
p < .001 on every bench, all output snapshots matched):
perlin2d -42% perlin3d -39% simplex2d -17% simplex3d -20%
simplex4d -13% worley2d -41% worley3d -54% fbm x5 -6%
curl2 -20%
The Permutation type shape changed: gradP/gradP4 are replaced by grad3/grad4.
- <aid="clamp"></a>`clamp(value: number, min: number, max: number): number` — Clamp a value between min and max
46
48
- <aid="repeat"></a>`repeat(t: number, length: number): number` — Loops `t` so that it is never larger than `length` and never smaller than 0.
47
49
- <aid="remap"></a>`remap(number: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number` — Remaps a number from one range to another.
@@ -102,6 +104,7 @@ import { vec2 } from 'math';
102
104
-`vec2.dot(a: Vec2, b: Vec2): number` — Calculates the dot product of two vec2's
103
105
-`vec2.cross(out: Vec3, a: Vec2, b: Vec2): Vec3` — Computes the cross product of two vec2's
104
106
-`vec2.lerp(out: Vec2, a: Vec2, b: Vec2, t: number): Vec2` — Performs a linear interpolation between two vec2's
107
+
-`vec2.lagrange(out: Vec2, a: Vec2, b: Vec2, c: Vec2, t: number): Vec2` — Quadratic interpolation through three vectors using Lagrange interpolation.
105
108
106
109
**Transform**
107
110
@@ -175,6 +178,7 @@ import { vec3 } from 'math';
175
178
-`vec3.cross(out: Vec3, a: Vec3, b: Vec3): Vec3` — Computes the cross product of two vec3's
176
179
-`vec3.perpendicular(out: Vec3, a: Vec3): Vec3` — Calculates a normalized perpendicular vector to the given vector.
177
180
-`vec3.lerp(out: Vec3, a: Vec3, b: Vec3, t: number): Vec3` — Performs a linear interpolation between two vec3's
181
+
-`vec3.lagrange(out: Vec3, a: Vec3, b: Vec3, c: Vec3, t: number): Vec3` — Quadratic interpolation through three vectors using Lagrange interpolation.
178
182
-`vec3.slerp(out: Vec3, a: Vec3, b: Vec3, t: number): Vec3` — Performs a spherical linear interpolation between two vec3's
179
183
-`vec3.hermite(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number): Vec3` — Performs a hermite interpolation with two control points
180
184
-`vec3.bezier(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number): Vec3` — Performs a bezier interpolation with two control points
@@ -249,6 +253,7 @@ import { vec4 } from 'math';
249
253
-`vec4.dot(a: Vec4, b: Vec4): number` — Calculates the dot product of two vec4's
250
254
-`vec4.cross(out: Vec4, u: Vec4, v: Vec4, w: Vec4): Vec4` — Returns the cross-product of three vectors in a 4-dimensional space
251
255
-`vec4.lerp(out: Vec4, a: Vec4, b: Vec4, t: number): Vec4` — Performs a linear interpolation between two vec4's
256
+
-`vec4.lagrange(out: Vec4, a: Vec4, b: Vec4, c: Vec4, t: number): Vec4` — Quadratic interpolation through three vectors using Lagrange interpolation.
252
257
253
258
**Transform**
254
259
@@ -1256,7 +1261,7 @@ import { random } from 'math/random';
1256
1261
1257
1262
**Types**
1258
1263
1259
-
-`type Permutation = { perm: number[]; gradP: Vec3[]; gradP4: Vec4[]; }` — Seeded permutation and gradient tables that back a noise generator.
1264
+
-`type Permutation = { perm: Uint8Array; grad3: Float64Array; grad4: Float64Array; }` — Seeded permutation and gradient tables that back a noise generator.
1260
1265
1261
1266
**Operations**
1262
1267
@@ -1286,7 +1291,7 @@ import { perlin2d } from 'math/noise';
@@ -1326,7 +1331,7 @@ import { simplex2d } from 'math/noise';
1326
1331
1327
1332
**Operations**
1328
1333
1329
-
-`simplex2d.sample({ perm, gradP }: Simplex2DGenerator, x: number, y: number): number` — Samples 2D simplex noise, returning a value in the interval [-1, 1].
1334
+
-`simplex2d.sample({ perm, grad3 }: Simplex2DGenerator, x: number, y: number): number` — Samples 2D simplex noise, returning a value in the interval [-1, 1].
1330
1335
1331
1336
<aid="api-math-noise-simplex3d"></a>
1332
1337
@@ -1346,7 +1351,7 @@ import { simplex3d } from 'math/noise';
1346
1351
1347
1352
**Operations**
1348
1353
1349
-
-`simplex3d.sample({ perm, gradP }: Simplex3DGenerator, x: number, y: number, z: number): number` — Samples 3D simplex noise, returning a value in the interval [-1, 1].
1354
+
-`simplex3d.sample({ perm, grad3 }: Simplex3DGenerator, x: number, y: number, z: number): number` — Samples 3D simplex noise, returning a value in the interval [-1, 1].
1350
1355
1351
1356
<aid="api-math-noise-simplex4d"></a>
1352
1357
@@ -1366,7 +1371,7 @@ import { simplex4d } from 'math/noise';
1366
1371
1367
1372
**Operations**
1368
1373
1369
-
-`simplex4d.sample({ perm, gradP4 }: Simplex4DGenerator, x: number, y: number, z: number, w: number): number` — Samples 4D simplex noise, returning a value in the interval [-1, 1].
1374
+
-`simplex4d.sample({ perm, grad4 }: Simplex4DGenerator, x: number, y: number, z: number, w: number): number` — Samples 4D simplex noise, returning a value in the interval [-1, 1].
0 commit comments