@@ -53,6 +53,14 @@ SimplexNoise.prototype.dot = function(g, x, y) {
53
53
return g [ 0 ] * x + g [ 1 ] * y ;
54
54
} ;
55
55
56
+ SimplexNoise . prototype . dot3 = function ( g , x , y , z ) {
57
+ return g [ 0 ] * x + g [ 1 ] * y + g [ 2 ] * z ;
58
+ }
59
+
60
+ SimplexNoise . prototype . dot4 = function ( g , x , y , z , w ) {
61
+ return g [ 0 ] * x + g [ 1 ] * y + g [ 2 ] * z + g [ 3 ] * w ;
62
+ } ;
63
+
56
64
SimplexNoise . prototype . noise = function ( xin , yin ) {
57
65
var n0 , n1 , n2 ; // Noise contributions from the three corners
58
66
// Skew the input space to determine which simplex cell we're in
@@ -166,25 +174,25 @@ SimplexNoise.prototype.noise3d = function(xin, yin, zin) {
166
174
if ( t0 < 0 ) n0 = 0.0 ;
167
175
else {
168
176
t0 *= t0 ;
169
- n0 = t0 * t0 * this . dot ( this . grad3 [ gi0 ] , x0 , y0 , z0 ) ;
177
+ n0 = t0 * t0 * this . dot3 ( this . grad3 [ gi0 ] , x0 , y0 , z0 ) ;
170
178
}
171
179
var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 ;
172
180
if ( t1 < 0 ) n1 = 0.0 ;
173
181
else {
174
182
t1 *= t1 ;
175
- n1 = t1 * t1 * this . dot ( this . grad3 [ gi1 ] , x1 , y1 , z1 ) ;
183
+ n1 = t1 * t1 * this . dot3 ( this . grad3 [ gi1 ] , x1 , y1 , z1 ) ;
176
184
}
177
185
var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 ;
178
186
if ( t2 < 0 ) n2 = 0.0 ;
179
187
else {
180
188
t2 *= t2 ;
181
- n2 = t2 * t2 * this . dot ( this . grad3 [ gi2 ] , x2 , y2 , z2 ) ;
189
+ n2 = t2 * t2 * this . dot3 ( this . grad3 [ gi2 ] , x2 , y2 , z2 ) ;
182
190
}
183
191
var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 ;
184
192
if ( t3 < 0 ) n3 = 0.0 ;
185
193
else {
186
194
t3 *= t3 ;
187
- n3 = t3 * t3 * this . dot ( this . grad3 [ gi3 ] , x3 , y3 , z3 ) ;
195
+ n3 = t3 * t3 * this . dot3 ( this . grad3 [ gi3 ] , x3 , y3 , z3 ) ;
188
196
}
189
197
// Add contributions from each corner to get the final noise value.
190
198
// The result is scaled to stay just inside [-1,1]
@@ -286,30 +294,30 @@ SimplexNoise.prototype.noise4d = function( x, y, z, w ) {
286
294
if ( t0 < 0 ) n0 = 0.0 ;
287
295
else {
288
296
t0 *= t0 ;
289
- n0 = t0 * t0 * this . dot ( grad4 [ gi0 ] , x0 , y0 , z0 , w0 ) ;
297
+ n0 = t0 * t0 * this . dot4 ( grad4 [ gi0 ] , x0 , y0 , z0 , w0 ) ;
290
298
}
291
299
var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1 ;
292
300
if ( t1 < 0 ) n1 = 0.0 ;
293
301
else {
294
302
t1 *= t1 ;
295
- n1 = t1 * t1 * this . dot ( grad4 [ gi1 ] , x1 , y1 , z1 , w1 ) ;
303
+ n1 = t1 * t1 * this . dot4 ( grad4 [ gi1 ] , x1 , y1 , z1 , w1 ) ;
296
304
}
297
305
var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2 ;
298
306
if ( t2 < 0 ) n2 = 0.0 ;
299
307
else {
300
308
t2 *= t2 ;
301
- n2 = t2 * t2 * this . dot ( grad4 [ gi2 ] , x2 , y2 , z2 , w2 ) ;
309
+ n2 = t2 * t2 * this . dot4 ( grad4 [ gi2 ] , x2 , y2 , z2 , w2 ) ;
302
310
} var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3 ;
303
311
if ( t3 < 0 ) n3 = 0.0 ;
304
312
else {
305
313
t3 *= t3 ;
306
- n3 = t3 * t3 * this . dot ( grad4 [ gi3 ] , x3 , y3 , z3 , w3 ) ;
314
+ n3 = t3 * t3 * this . dot4 ( grad4 [ gi3 ] , x3 , y3 , z3 , w3 ) ;
307
315
}
308
316
var t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4 ;
309
317
if ( t4 < 0 ) n4 = 0.0 ;
310
318
else {
311
319
t4 *= t4 ;
312
- n4 = t4 * t4 * this . dot ( grad4 [ gi4 ] , x4 , y4 , z4 , w4 ) ;
320
+ n4 = t4 * t4 * this . dot4 ( grad4 [ gi4 ] , x4 , y4 , z4 , w4 ) ;
313
321
}
314
322
// Sum up and scale the result to cover the range [-1,1]
315
323
return 27.0 * ( n0 + n1 + n2 + n3 + n4 ) ;
0 commit comments