Skip to content

Instantly share code, notes, and snippets.

View Pandaqi's full-sized avatar

Pandaqi Pandaqi

View GitHub Profile
// Find unit grid cell containing point
var X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z), W = Math.floor(w);
// Get relative xyzw coordinates of point within that cell
x = x - X; y = y - Y; z = z - Z; w = w - W;
// Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255; Y = Y & 255; Z = Z & 255; w = W & 255;
// Calculate noise contributions from each of the SIXTEEN corners
// (Just follow the patterns; every unique combination must appear exactly once)
var n0000 = gradP[X+ perm[Y+ perm[Z+ perm[W ]]]].dot4(x, y, z, w);