Skip to content

Commit 9ad6e54

Browse files
committed
fixes for dot operations in SimplexNoise. mrdoob#1993
1 parent 0832354 commit 9ad6e54

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

examples/js/SimplexNoise.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ SimplexNoise.prototype.dot = function(g, x, y) {
5353
return g[0]*x + g[1]*y;
5454
};
5555

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+
5664
SimplexNoise.prototype.noise = function(xin, yin) {
5765
var n0, n1, n2; // Noise contributions from the three corners
5866
// Skew the input space to determine which simplex cell we're in
@@ -166,25 +174,25 @@ SimplexNoise.prototype.noise3d = function(xin, yin, zin) {
166174
if(t0<0) n0 = 0.0;
167175
else {
168176
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);
170178
}
171179
var t1 = 0.6 - x1*x1 - y1*y1 - z1*z1;
172180
if(t1<0) n1 = 0.0;
173181
else {
174182
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);
176184
}
177185
var t2 = 0.6 - x2*x2 - y2*y2 - z2*z2;
178186
if(t2<0) n2 = 0.0;
179187
else {
180188
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);
182190
}
183191
var t3 = 0.6 - x3*x3 - y3*y3 - z3*z3;
184192
if(t3<0) n3 = 0.0;
185193
else {
186194
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);
188196
}
189197
// Add contributions from each corner to get the final noise value.
190198
// The result is scaled to stay just inside [-1,1]
@@ -286,30 +294,30 @@ SimplexNoise.prototype.noise4d = function( x, y, z, w ) {
286294
if(t0<0) n0 = 0.0;
287295
else {
288296
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);
290298
}
291299
var t1 = 0.6 - x1*x1 - y1*y1 - z1*z1 - w1*w1;
292300
if(t1<0) n1 = 0.0;
293301
else {
294302
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);
296304
}
297305
var t2 = 0.6 - x2*x2 - y2*y2 - z2*z2 - w2*w2;
298306
if(t2<0) n2 = 0.0;
299307
else {
300308
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);
302310
} var t3 = 0.6 - x3*x3 - y3*y3 - z3*z3 - w3*w3;
303311
if(t3<0) n3 = 0.0;
304312
else {
305313
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);
307315
}
308316
var t4 = 0.6 - x4*x4 - y4*y4 - z4*z4 - w4*w4;
309317
if(t4<0) n4 = 0.0;
310318
else {
311319
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);
313321
}
314322
// Sum up and scale the result to cover the range [-1,1]
315323
return 27.0 * (n0 + n1 + n2 + n3 + n4);

0 commit comments

Comments
 (0)