From 38553a3e2bfc7dbca16f5c56d0a2eac3ce581d7f Mon Sep 17 00:00:00 2001 From: Ben Wesch Date: Sat, 25 May 2024 17:03:01 +0200 Subject: [PATCH] add simplex algorithm comments --- simplex~.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/simplex~.c b/simplex~.c index c2b787d..beb793a 100644 --- a/simplex~.c +++ b/simplex~.c @@ -1,5 +1,5 @@ // external created by Ben Wesch, 2024 -// simplex algorithms from https://github.com/stegu/perlin-noise/blob/master/src/sdnoise1234.c +// simplex algorithms by Stefan Gustavson (slightly adapted) from https://github.com/stegu/perlin-noise/blob/master/src/sdnoise1234.c #include "m_pd.h" #include @@ -86,14 +86,23 @@ static t_float grad2lut[8][2] = { {-1, 1}, { 0,-1}, { 0, 1}, { 1,-1} }; +/* + * Gradient directions for 3D. + * These vectors are based on the midpoints of the 12 edges of a cube. + * A larger array of random unit length vectors would also do the job, + * but these 12 (including 4 repeats to make the array length a power + * of two) work better. They are not random, they are carefully chosen + * to represent a small, isotropic set of directions. + */ + static t_float grad3lut[16][3] = { - { 1, 0, 1}, { 0, 1, 1}, + { 1, 0, 1}, { 0, 1, 1}, // 12 cube edges {-1, 0, 1}, { 0,-1, 1}, { 1, 0,-1}, { 0, 1,-1}, {-1, 0,-1}, { 0,-1,-1}, { 1,-1, 0}, { 1, 1, 0}, {-1, 1, 0}, {-1,-1, 0}, - { 1, 0, 1}, {-1, 0, 1}, + { 1, 0, 1}, {-1, 0, 1}, // 4 repeats to make 16 { 0, 1,-1}, { 0,-1,-1} };