1 //////////////////////////////////////////////////////////////////////
2 //
3 // Pixie
4 //
5 // Copyright � 1999 - 2003, Okan Arikan
6 //
7 // Contact: okan@cs.utexas.edu
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 ///////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////
25 //
26 // File : noise.cpp
27 // Classes : -
28 // Description : The misc noise functions
29 //
30 ////////////////////////////////////////////////////////////////////////
31 #include <math.h>
32
33 #include "common/algebra.h"
34 #include "common/os.h"
35 #include "noise.h"
36
37
38 #define FADE(t) ( t * t * t * ( t * ( t * 6 - 15 ) + 10 ) )
39 #define FASTFLOOR(x) ( ((x)>0) ? ((int)x) : ((int)x-1 ) )
40 #define LERP(t, a, b) ((a) + (t)*((b)-(a)))
41
42 #include "noiseTables.h"
43
44 // Helper gradient functions
grad(int hash,T x)45 template <class T> T grad(int hash,T x) {
46 int h = hash & 15;
47 T grad = (T) 1.0 + (h & 7);
48 if (h&8) grad = -grad;
49 return ( grad * x );
50 }
51
grad(int hash,T x,T y)52 template <class T> T grad(int hash,T x,T y) {
53 int h = hash & 7;
54 const T u = h<4 ? x : y;
55 const T v = h<4 ? y : x;
56 return ((h&1)? -u : u) + ((h&2)? (T) -2.0*v : (T) 2.0*v);
57 }
58
grad(int hash,T x,T y,T z)59 template <class T> T grad(int hash,T x,T y ,T z) {
60 int h = hash & 15;
61 const T u = h<8 ? x : y;
62 const T v = h<4 ? y : h==12||h==14 ? x : z;
63 return ((h&1)? -u : u) + ((h&2)? -v : v);
64 }
65
grad(int hash,T x,T y,T z,T t)66 template <class T> T grad(int hash,T x,T y,T z,T t ) {
67 int h = hash & 31;
68 const T u = h<24 ? x : y;
69 const T v = h<16 ? y : z;
70 const T w = h<8 ? z : t;
71 return ((h&1)? -u : u) + ((h&2)? -v : v) + ((h&4)? -w : w);
72 }
73
74
75
76
77 /////////////////////////////////////////////////////////////////////////////////
78 //
79 // Noise functions start here
80 //
81 /////////////////////////////////////////////////////////////////////////////////
82
83
84
85
noise(T x,const unsigned char * perm)86 template <class T> T noise(T x,const unsigned char *perm) {
87 int ix0, ix1;
88 T fx0, fx1;
89 T s, n0, n1;
90
91 ix0 = FASTFLOOR( x );
92 fx0 = x - ix0;
93 fx1 = fx0 - 1.0f;
94 ix1 = ( ix0+1 ) & 0xff;
95 ix0 = ix0 & 0xff;
96
97 s = FADE( fx0 );
98
99 n0 = grad( perm[ ix0 ], fx0 );
100 n1 = grad( perm[ ix1 ], fx1 );
101 return 0.5f * (1.0f + 0.188f * ( LERP( s, n0, n1 ) ));
102 }
103
pnoise(T x,int px,const unsigned char * perm)104 template <class T> T pnoise(T x,int px,const unsigned char *perm) {
105 int ix0, ix1;
106 T fx0, fx1;
107 T s, n0, n1;
108
109 px = max(px,1);
110
111 ix0 = FASTFLOOR( x );
112 fx0 = x - ix0;
113 fx1 = fx0 - 1.0f;
114 ix1 = (( ix0 + 1 ) % px) & 0xff;
115 ix0 = ( ix0 % px ) & 0xff;
116
117 s = FADE( fx0 );
118
119 n0 = grad( perm[ ix0 ], fx0 );
120 n1 = grad( perm[ ix1 ], fx1 );
121 return 0.5f * (1.0f + 0.188f * ( LERP( s, n0, n1 ) ));
122 }
123
124
noise(T x,T y,const unsigned char * perm)125 template <class T> T noise(T x,T y,const unsigned char *perm) {
126 int ix0, iy0, ix1, iy1;
127 T fx0, fy0, fx1, fy1;
128 T s, t, nx0, nx1, n0, n1;
129
130 ix0 = FASTFLOOR( x );
131 iy0 = FASTFLOOR( y );
132 fx0 = x - ix0;
133 fy0 = y - iy0;
134 fx1 = fx0 - 1.0f;
135 fy1 = fy0 - 1.0f;
136 ix1 = (ix0 + 1) & 0xff;
137 iy1 = (iy0 + 1) & 0xff;
138 ix0 = ix0 & 0xff;
139 iy0 = iy0 & 0xff;
140
141 t = FADE( fy0 );
142 s = FADE( fx0 );
143
144 nx0 = grad(perm[ix0 + perm[iy0]], fx0, fy0);
145 nx1 = grad(perm[ix0 + perm[iy1]], fx0, fy1);
146 n0 = LERP( t, nx0, nx1 );
147
148 nx0 = grad(perm[ix1 + perm[iy0]], fx1, fy0);
149 nx1 = grad(perm[ix1 + perm[iy1]], fx1, fy1);
150 n1 = LERP(t, nx0, nx1);
151
152 return 0.5f * (1.0f + 0.507f * ( LERP( s, n0, n1 ) ) );
153 }
154
pnoise(T x,T y,int px,int py,const unsigned char * perm)155 template <class T> T pnoise(T x,T y, int px, int py,const unsigned char *perm) {
156 int ix0, iy0, ix1, iy1;
157 T fx0, fy0, fx1, fy1;
158 T s, t, nx0, nx1, n0, n1;
159
160 px = max(px,1);
161 py = max(py,1);
162
163 ix0 = FASTFLOOR( x );
164 iy0 = FASTFLOOR( y );
165 fx0 = x - ix0;
166 fy0 = y - iy0;
167 fx1 = fx0 - 1.0f;
168 fy1 = fy0 - 1.0f;
169 ix1 = (( ix0 + 1 ) % px) & 0xff;
170 iy1 = (( iy0 + 1 ) % py) & 0xff;
171 ix0 = ( ix0 % px ) & 0xff;
172 iy0 = ( iy0 % py ) & 0xff;
173
174 t = FADE( fy0 );
175 s = FADE( fx0 );
176
177 nx0 = grad(perm[ix0 + perm[iy0]], fx0, fy0);
178 nx1 = grad(perm[ix0 + perm[iy1]], fx0, fy1);
179 n0 = LERP( t, nx0, nx1 );
180
181 nx0 = grad(perm[ix1 + perm[iy0]], fx1, fy0);
182 nx1 = grad(perm[ix1 + perm[iy1]], fx1, fy1);
183 n1 = LERP(t, nx0, nx1);
184
185 return 0.5f * (1.0f + 0.507f * ( LERP( s, n0, n1 ) ) );
186 }
187
188
noise(T x,T y,T z,const unsigned char * perm)189 template <class T> T noise(T x,T y,T z,const unsigned char *perm) {
190 int ix0, iy0, ix1, iy1, iz0, iz1;
191 T fx0, fy0, fz0, fx1, fy1, fz1;
192 T s, t, r;
193 T nxy0, nxy1, nx0, nx1, n0, n1;
194
195 ix0 = FASTFLOOR( x );
196 iy0 = FASTFLOOR( y );
197 iz0 = FASTFLOOR( z );
198 fx0 = x - ix0;
199 fy0 = y - iy0;
200 fz0 = z - iz0;
201 fx1 = fx0 - 1.0f;
202 fy1 = fy0 - 1.0f;
203 fz1 = fz0 - 1.0f;
204 ix1 = ( ix0 + 1 ) & 0xff;
205 iy1 = ( iy0 + 1 ) & 0xff;
206 iz1 = ( iz0 + 1 ) & 0xff;
207 ix0 = ix0 & 0xff;
208 iy0 = iy0 & 0xff;
209 iz0 = iz0 & 0xff;
210
211 r = FADE( fz0 );
212 t = FADE( fy0 );
213 s = FADE( fx0 );
214
215 nxy0 = grad(perm[ix0 + perm[iy0 + perm[iz0]]], fx0, fy0, fz0);
216 nxy1 = grad(perm[ix0 + perm[iy0 + perm[iz1]]], fx0, fy0, fz1);
217 nx0 = LERP( r, nxy0, nxy1 );
218
219 nxy0 = grad(perm[ix0 + perm[iy1 + perm[iz0]]], fx0, fy1, fz0);
220 nxy1 = grad(perm[ix0 + perm[iy1 + perm[iz1]]], fx0, fy1, fz1);
221 nx1 = LERP( r, nxy0, nxy1 );
222
223 n0 = LERP( t, nx0, nx1 );
224
225 nxy0 = grad(perm[ix1 + perm[iy0 + perm[iz0]]], fx1, fy0, fz0);
226 nxy1 = grad(perm[ix1 + perm[iy0 + perm[iz1]]], fx1, fy0, fz1);
227 nx0 = LERP( r, nxy0, nxy1 );
228
229 nxy0 = grad(perm[ix1 + perm[iy1 + perm[iz0]]], fx1, fy1, fz0);
230 nxy1 = grad(perm[ix1 + perm[iy1 + perm[iz1]]], fx1, fy1, fz1);
231 nx1 = LERP( r, nxy0, nxy1 );
232
233 n1 = LERP( t, nx0, nx1 );
234
235 return 0.5f * (1.0f + 0.936f * ( LERP( s, n0, n1 ) ) );
236 }
237
pnoise(T x,T y,T z,int px,int py,int pz,const unsigned char * perm)238 template <class T> T pnoise(T x,T y,T z,int px,int py,int pz,const unsigned char *perm) {
239 int ix0, iy0, ix1, iy1, iz0, iz1;
240 T fx0, fy0, fz0, fx1, fy1, fz1;
241 T s, t, r;
242 T nxy0, nxy1, nx0, nx1, n0, n1;
243
244 px = max(px,1);
245 py = max(py,1);
246 pz = max(pz,1);
247
248 ix0 = FASTFLOOR( x );
249 iy0 = FASTFLOOR( y );
250 iz0 = FASTFLOOR( z );
251 fx0 = x - ix0;
252 fy0 = y - iy0;
253 fz0 = z - iz0;
254 fx1 = fx0 - 1.0f;
255 fy1 = fy0 - 1.0f;
256 fz1 = fz0 - 1.0f;
257 ix1 = (( ix0 + 1 ) % px ) & 0xff;
258 iy1 = (( iy0 + 1 ) % py ) & 0xff;
259 iz1 = (( iz0 + 1 ) % pz ) & 0xff;
260 ix0 = ( ix0 % px ) & 0xff;
261 iy0 = ( iy0 % py ) & 0xff;
262 iz0 = ( iz0 % pz ) & 0xff;
263
264 r = FADE( fz0 );
265 t = FADE( fy0 );
266 s = FADE( fx0 );
267
268 nxy0 = grad(perm[ix0 + perm[iy0 + perm[iz0]]], fx0, fy0, fz0);
269 nxy1 = grad(perm[ix0 + perm[iy0 + perm[iz1]]], fx0, fy0, fz1);
270 nx0 = LERP( r, nxy0, nxy1 );
271
272 nxy0 = grad(perm[ix0 + perm[iy1 + perm[iz0]]], fx0, fy1, fz0);
273 nxy1 = grad(perm[ix0 + perm[iy1 + perm[iz1]]], fx0, fy1, fz1);
274 nx1 = LERP( r, nxy0, nxy1 );
275
276 n0 = LERP( t, nx0, nx1 );
277
278 nxy0 = grad(perm[ix1 + perm[iy0 + perm[iz0]]], fx1, fy0, fz0);
279 nxy1 = grad(perm[ix1 + perm[iy0 + perm[iz1]]], fx1, fy0, fz1);
280 nx0 = LERP( r, nxy0, nxy1 );
281
282 nxy0 = grad(perm[ix1 + perm[iy1 + perm[iz0]]], fx1, fy1, fz0);
283 nxy1 = grad(perm[ix1 + perm[iy1 + perm[iz1]]], fx1, fy1, fz1);
284 nx1 = LERP( r, nxy0, nxy1 );
285
286 n1 = LERP( t, nx0, nx1 );
287
288 return 0.5f * (1.0f + 0.936f * ( LERP( s, n0, n1 ) ) );
289 }
290
291
noise(T x,T y,T z,T w,const unsigned char * perm)292 template <class T> T noise(T x,T y,T z,T w,const unsigned char *perm) {
293 int ix0, iy0, iz0, iw0, ix1, iy1, iz1, iw1;
294 T fx0, fy0, fz0, fw0, fx1, fy1, fz1, fw1;
295 T s, t, r, q;
296 T nxyz0, nxyz1, nxy0, nxy1, nx0, nx1, n0, n1;
297
298 ix0 = FASTFLOOR( x );
299 iy0 = FASTFLOOR( y );
300 iz0 = FASTFLOOR( z );
301 iw0 = FASTFLOOR( w );
302 fx0 = x - ix0;
303 fy0 = y - iy0;
304 fz0 = z - iz0;
305 fw0 = w - iw0;
306 fx1 = fx0 - 1.0f;
307 fy1 = fy0 - 1.0f;
308 fz1 = fz0 - 1.0f;
309 fw1 = fw0 - 1.0f;
310 ix1 = ( ix0 + 1 ) & 0xff;
311 iy1 = ( iy0 + 1 ) & 0xff;
312 iz1 = ( iz0 + 1 ) & 0xff;
313 iw1 = ( iw0 + 1 ) & 0xff;
314 ix0 = ix0 & 0xff;
315 iy0 = iy0 & 0xff;
316 iz0 = iz0 & 0xff;
317 iw0 = iw0 & 0xff;
318
319 q = FADE( fw0 );
320 r = FADE( fz0 );
321 t = FADE( fy0 );
322 s = FADE( fx0 );
323
324 nxyz0 = grad(perm[ix0 + perm[iy0 + perm[iz0 + perm[iw0]]]], fx0, fy0, fz0, fw0);
325 nxyz1 = grad(perm[ix0 + perm[iy0 + perm[iz0 + perm[iw1]]]], fx0, fy0, fz0, fw1);
326 nxy0 = LERP( q, nxyz0, nxyz1 );
327
328 nxyz0 = grad(perm[ix0 + perm[iy0 + perm[iz1 + perm[iw0]]]], fx0, fy0, fz1, fw0);
329 nxyz1 = grad(perm[ix0 + perm[iy0 + perm[iz1 + perm[iw1]]]], fx0, fy0, fz1, fw1);
330 nxy1 = LERP( q, nxyz0, nxyz1 );
331
332 nx0 = LERP ( r, nxy0, nxy1 );
333
334 nxyz0 = grad(perm[ix0 + perm[iy1 + perm[iz0 + perm[iw0]]]], fx0, fy1, fz0, fw0);
335 nxyz1 = grad(perm[ix0 + perm[iy1 + perm[iz0 + perm[iw1]]]], fx0, fy1, fz0, fw1);
336 nxy0 = LERP( q, nxyz0, nxyz1 );
337
338 nxyz0 = grad(perm[ix0 + perm[iy1 + perm[iz1 + perm[iw0]]]], fx0, fy1, fz1, fw0);
339 nxyz1 = grad(perm[ix0 + perm[iy1 + perm[iz1 + perm[iw1]]]], fx0, fy1, fz1, fw1);
340 nxy1 = LERP( q, nxyz0, nxyz1 );
341
342 nx1 = LERP ( r, nxy0, nxy1 );
343
344 n0 = LERP( t, nx0, nx1 );
345
346 nxyz0 = grad(perm[ix1 + perm[iy0 + perm[iz0 + perm[iw0]]]], fx1, fy0, fz0, fw0);
347 nxyz1 = grad(perm[ix1 + perm[iy0 + perm[iz0 + perm[iw1]]]], fx1, fy0, fz0, fw1);
348 nxy0 = LERP( q, nxyz0, nxyz1 );
349
350 nxyz0 = grad(perm[ix1 + perm[iy0 + perm[iz1 + perm[iw0]]]], fx1, fy0, fz1, fw0);
351 nxyz1 = grad(perm[ix1 + perm[iy0 + perm[iz1 + perm[iw1]]]], fx1, fy0, fz1, fw1);
352 nxy1 = LERP( q, nxyz0, nxyz1 );
353
354 nx0 = LERP ( r, nxy0, nxy1 );
355
356 nxyz0 = grad(perm[ix1 + perm[iy1 + perm[iz0 + perm[iw0]]]], fx1, fy1, fz0, fw0);
357 nxyz1 = grad(perm[ix1 + perm[iy1 + perm[iz0 + perm[iw1]]]], fx1, fy1, fz0, fw1);
358 nxy0 = LERP( q, nxyz0, nxyz1 );
359
360 nxyz0 = grad(perm[ix1 + perm[iy1 + perm[iz1 + perm[iw0]]]], fx1, fy1, fz1, fw0);
361 nxyz1 = grad(perm[ix1 + perm[iy1 + perm[iz1 + perm[iw1]]]], fx1, fy1, fz1, fw1);
362 nxy1 = LERP( q, nxyz0, nxyz1 );
363
364 nx1 = LERP ( r, nxy0, nxy1 );
365
366 n1 = LERP( t, nx0, nx1 );
367
368 return 0.5f * (1.0f + 0.87f * ( LERP( s, n0, n1 ) ) );
369 }
370
pnoise(T x,T y,T z,float w,int px,int py,int pz,int pw,const unsigned char * perm)371 template <class T> T pnoise(T x,T y,T z, float w,int px,int py,int pz,int pw,const unsigned char *perm) {
372 int ix0, iy0, iz0, iw0, ix1, iy1, iz1, iw1;
373 T fx0, fy0, fz0, fw0, fx1, fy1, fz1, fw1;
374 T s, t, r, q;
375 T nxyz0, nxyz1, nxy0, nxy1, nx0, nx1, n0, n1;
376
377 px = max(px,1);
378 py = max(py,1);
379 pz = max(pz,1);
380 pw = max(pw,1);
381
382 ix0 = FASTFLOOR( x );
383 iy0 = FASTFLOOR( y );
384 iz0 = FASTFLOOR( z );
385 iw0 = FASTFLOOR( w );
386 fx0 = x - ix0;
387 fy0 = y - iy0;
388 fz0 = z - iz0;
389 fw0 = w - iw0;
390 fx1 = fx0 - 1.0f;
391 fy1 = fy0 - 1.0f;
392 fz1 = fz0 - 1.0f;
393 fw1 = fw0 - 1.0f;
394 ix1 = (( ix0 + 1 ) % px ) & 0xff;
395 iy1 = (( iy0 + 1 ) % py ) & 0xff;
396 iz1 = (( iz0 + 1 ) % pz ) & 0xff;
397 iw1 = (( iw0 + 1 ) % pw ) & 0xff;
398 ix0 = ( ix0 % px ) & 0xff;
399 iy0 = ( iy0 % py ) & 0xff;
400 iz0 = ( iz0 % pz ) & 0xff;
401 iw0 = ( iw0 % pw ) & 0xff;
402
403 q = FADE( fw0 );
404 r = FADE( fz0 );
405 t = FADE( fy0 );
406 s = FADE( fx0 );
407
408 nxyz0 = grad(perm[ix0 + perm[iy0 + perm[iz0 + perm[iw0]]]], fx0, fy0, fz0, fw0);
409 nxyz1 = grad(perm[ix0 + perm[iy0 + perm[iz0 + perm[iw1]]]], fx0, fy0, fz0, fw1);
410 nxy0 = LERP( q, nxyz0, nxyz1 );
411
412 nxyz0 = grad(perm[ix0 + perm[iy0 + perm[iz1 + perm[iw0]]]], fx0, fy0, fz1, fw0);
413 nxyz1 = grad(perm[ix0 + perm[iy0 + perm[iz1 + perm[iw1]]]], fx0, fy0, fz1, fw1);
414 nxy1 = LERP( q, nxyz0, nxyz1 );
415
416 nx0 = LERP ( r, nxy0, nxy1 );
417
418 nxyz0 = grad(perm[ix0 + perm[iy1 + perm[iz0 + perm[iw0]]]], fx0, fy1, fz0, fw0);
419 nxyz1 = grad(perm[ix0 + perm[iy1 + perm[iz0 + perm[iw1]]]], fx0, fy1, fz0, fw1);
420 nxy0 = LERP( q, nxyz0, nxyz1 );
421
422 nxyz0 = grad(perm[ix0 + perm[iy1 + perm[iz1 + perm[iw0]]]], fx0, fy1, fz1, fw0);
423 nxyz1 = grad(perm[ix0 + perm[iy1 + perm[iz1 + perm[iw1]]]], fx0, fy1, fz1, fw1);
424 nxy1 = LERP( q, nxyz0, nxyz1 );
425
426 nx1 = LERP ( r, nxy0, nxy1 );
427
428 n0 = LERP( t, nx0, nx1 );
429
430 nxyz0 = grad(perm[ix1 + perm[iy0 + perm[iz0 + perm[iw0]]]], fx1, fy0, fz0, fw0);
431 nxyz1 = grad(perm[ix1 + perm[iy0 + perm[iz0 + perm[iw1]]]], fx1, fy0, fz0, fw1);
432 nxy0 = LERP( q, nxyz0, nxyz1 );
433
434 nxyz0 = grad(perm[ix1 + perm[iy0 + perm[iz1 + perm[iw0]]]], fx1, fy0, fz1, fw0);
435 nxyz1 = grad(perm[ix1 + perm[iy0 + perm[iz1 + perm[iw1]]]], fx1, fy0, fz1, fw1);
436 nxy1 = LERP( q, nxyz0, nxyz1 );
437
438 nx0 = LERP ( r, nxy0, nxy1 );
439
440 nxyz0 = grad(perm[ix1 + perm[iy1 + perm[iz0 + perm[iw0]]]], fx1, fy1, fz0, fw0);
441 nxyz1 = grad(perm[ix1 + perm[iy1 + perm[iz0 + perm[iw1]]]], fx1, fy1, fz0, fw1);
442 nxy0 = LERP( q, nxyz0, nxyz1 );
443
444 nxyz0 = grad(perm[ix1 + perm[iy1 + perm[iz1 + perm[iw0]]]], fx1, fy1, fz1, fw0);
445 nxyz1 = grad(perm[ix1 + perm[iy1 + perm[iz1 + perm[iw1]]]], fx1, fy1, fz1, fw1);
446 nxy1 = LERP( q, nxyz0, nxyz1 );
447
448 nx1 = LERP ( r, nxy0, nxy1 );
449
450 n1 = LERP( t, nx0, nx1 );
451
452 return 0.5f * (1.0f + 0.87f * ( LERP( s, n0, n1 ) ) );
453 }
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470 ///////////////////////////////////////////////////////////////////////
471 // Function : noiseFloat1D
472 // Description :
473 // Return Value :
474 // Comments :
noiseFloat(float arg)475 float noiseFloat(float arg) {
476 return noise<float>(arg,permX);
477 }
478
479 ///////////////////////////////////////////////////////////////////////
480 // Function : noiseFloat2D
481 // Description :
482 // Return Value :
483 // Comments :
noiseFloat(float uarg,float varg)484 float noiseFloat(float uarg,float varg) {
485 return noise<float>(uarg,varg,permX);
486 }
487
488 ///////////////////////////////////////////////////////////////////////
489 // Function : noiseFloat3D
490 // Description :
491 // Return Value :
492 // Comments :
noiseFloat(const float * vec)493 float noiseFloat(const float *vec) {
494 return noise<float>(vec[0],vec[1],vec[2],permX);
495 }
496
497 ///////////////////////////////////////////////////////////////////////
498 // Function : noiseFloat4D
499 // Description :
500 // Return Value :
501 // Comments :
noiseFloat(const float * argu,float argv)502 float noiseFloat(const float *argu,float argv) {
503 return noise<float>(argu[0],argu[1],argu[2],argv,permX);
504 }
505
506 ///////////////////////////////////////////////////////////////////////
507 // Function : noiseVector1D
508 // Description :
509 // Return Value :
510 // Comments :
noiseVector(float * r,float arg)511 void noiseVector(float *r,float arg) {
512 r[0] = noise<float>(arg,permX);
513 r[1] = noise<float>(arg,permY);
514 r[2] = noise<float>(arg,permZ);
515 }
516
517 ///////////////////////////////////////////////////////////////////////
518 // Function : noiseVector2D
519 // Description :
520 // Return Value :
521 // Comments :
noiseVector(float * r,float uarg,float varg)522 void noiseVector(float *r,float uarg,float varg) {
523 r[0] = noise<float>(uarg,varg,permX);
524 r[1] = noise<float>(uarg,varg,permY);
525 r[2] = noise<float>(uarg,varg,permZ);
526 }
527
528 ///////////////////////////////////////////////////////////////////////
529 // Function : noiseVector3D
530 // Description :
531 // Return Value :
532 // Comments :
noiseVector(float * r,const float * vec)533 void noiseVector(float *r,const float *vec) {
534 r[0] = noise<float>(vec[0],vec[1],vec[2],permX);
535 r[1] = noise<float>(vec[0],vec[1],vec[2],permY);
536 r[2] = noise<float>(vec[0],vec[1],vec[2],permZ);
537 }
538
539
540 ///////////////////////////////////////////////////////////////////////
541 // Function : noiseVector4D
542 // Description :
543 // Return Value :
544 // Comments :
noiseVector(float * r,const float * argu,float argv)545 void noiseVector(float *r,const float *argu,float argv) {
546 r[0] = noise<float>(argu[0],argu[1],argu[2],argv,permX);
547 r[1] = noise<float>(argu[0],argu[1],argu[2],argv,permY);
548 r[2] = noise<float>(argu[0],argu[1],argu[2],argv,permZ);
549 }
550
551
552
553 ///////////////////////////////////////////////////////////////////////
554 // Function : pnoiseFloat1D
555 // Description :
556 // Return Value :
557 // Comments :
pnoiseFloat(float u,float uperiod)558 float pnoiseFloat(float u,float uperiod) {
559 return pnoise<float>(u,(int) uperiod,permX);
560 }
561
562
563 ///////////////////////////////////////////////////////////////////////
564 // Function : pnoiseFloat2D
565 // Description :
566 // Return Value :
567 // Comments :
pnoiseFloat(float u,float v,float uperiod,float vperiod)568 float pnoiseFloat(float u,float v,float uperiod,float vperiod) {
569 return pnoise<float>(u,v,(int) uperiod,(int) vperiod,permX);
570 }
571
572 ///////////////////////////////////////////////////////////////////////
573 // Function : pnoiseFloat3D
574 // Description :
575 // Return Value :
576 // Comments :
pnoiseFloat(const float * arg,const float * periods)577 float pnoiseFloat(const float *arg,const float *periods) {
578 return pnoise<float>(arg[0],arg[1],arg[2],(int) periods[0],(int) periods[1],(int) periods[2],permX);
579 }
580
581 ///////////////////////////////////////////////////////////////////////
582 // Function : pnoiseFloat4D
583 // Description :
584 // Return Value :
585 // Comments :
pnoiseFloat(const float * arg,float w,const float * periods,float wperiod)586 float pnoiseFloat(const float *arg,float w,const float *periods,float wperiod) {
587 return pnoise<float>(arg[0],arg[1],arg[2],w,(int) periods[0],(int) periods[1],(int) periods[2],(int) wperiod,permX);
588 }
589
590 ///////////////////////////////////////////////////////////////////////
591 // Function : pnoiseVector1D
592 // Description :
593 // Return Value :
594 // Comments :
pnoiseVector(float * r,float u,float uperiod)595 void pnoiseVector(float *r,float u,float uperiod) {
596 r[0] = pnoise<float>(u,(int) uperiod,permX);
597 r[1] = pnoise<float>(u,(int) uperiod,permY);
598 r[2] = pnoise<float>(u,(int) uperiod,permZ);
599 }
600
601 ///////////////////////////////////////////////////////////////////////
602 // Function : pnoiseVector2D
603 // Description :
604 // Return Value :
605 // Comments :
pnoiseVector(float * r,float u,float v,float uperiod,float vperiod)606 void pnoiseVector(float *r,float u,float v,float uperiod,float vperiod) {
607 r[0] = pnoise<float>(u,v,(int) uperiod,(int) vperiod,permX);
608 r[1] = pnoise<float>(u,v,(int) uperiod,(int) vperiod,permY);
609 r[2] = pnoise<float>(u,v,(int) uperiod,(int) vperiod,permZ);
610 }
611
612 ///////////////////////////////////////////////////////////////////////
613 // Function : pnoiseVector3D
614 // Description :
615 // Return Value :
616 // Comments :
pnoiseVector(float * r,const float * arg,const float * periods)617 void pnoiseVector(float *r,const float *arg,const float *periods) {
618 r[0] = pnoise<float>(arg[0],arg[1],arg[2],(int) periods[0],(int) periods[1],(int) periods[2],permX);
619 r[1] = pnoise<float>(arg[0],arg[1],arg[2],(int) periods[0],(int) periods[1],(int) periods[2],permY);
620 r[2] = pnoise<float>(arg[0],arg[1],arg[2],(int) periods[0],(int) periods[1],(int) periods[2],permZ);
621 }
622
623 ///////////////////////////////////////////////////////////////////////
624 // Function : pnoiseVector4D
625 // Description :
626 // Return Value :
627 // Comments :
pnoiseVector(float * r,const float * arg,float w,const float * periods,float wperiod)628 void pnoiseVector(float *r,const float *arg,float w,const float *periods,float wperiod) {
629 r[0] = pnoise<float>(arg[0],arg[1],arg[2],w,(int) periods[0],(int) periods[1],(int) periods[2],(int) wperiod,permX);
630 r[1] = pnoise<float>(arg[0],arg[1],arg[2],w,(int) periods[0],(int) periods[1],(int) periods[2],(int) wperiod,permY);
631 r[2] = pnoise<float>(arg[0],arg[1],arg[2],w,(int) periods[0],(int) periods[1],(int) periods[2],(int) wperiod,permZ);
632 }
633
634 // Musc macro to permute the inputs
635 #define permute(__val) \
636 if (__val < 0) i = permN[ (i + ((unsigned int) (__val - 1))) & 4095 ]; \
637 else i = permN[ (i + ((unsigned int) __val)) & 4095 ];
638
639 ///////////////////////////////////////////////////////////////////////
640 // Function : cellNoiseFloat1D
641 // Description : Fast cell noise implementation
642 // Return Value :
643 // Comments :
cellNoiseFloat(float arg)644 float cellNoiseFloat(float arg) {
645 unsigned int i = 0;
646
647 permute(arg);
648
649 return randN[i];
650 }
651
652 ///////////////////////////////////////////////////////////////////////
653 // Function : cellNoiseFloat2D
654 // Description :
655 // Return Value :
656 // Comments :
cellNoiseFloat(float u,float v)657 float cellNoiseFloat(float u,float v) {
658 unsigned int i = 0;
659
660 permute(u);
661 permute(v);
662
663 return randN[i];
664 }
665
666 ///////////////////////////////////////////////////////////////////////
667 // Function : cellNoiseFloat3D
668 // Description :
669 // Return Value :
670 // Comments :
cellNoiseFloat(const float * arg)671 float cellNoiseFloat(const float *arg) {
672 unsigned int i = 0;
673
674 permute(arg[0]);
675 permute(arg[1]);
676 permute(arg[2]);
677
678 return randN[i];
679 }
680
681 ///////////////////////////////////////////////////////////////////////
682 // Function : cellNoiseFloat4D
683 // Description :
684 // Return Value :
685 // Comments :
cellNoiseFloat(const float * arg,float w)686 float cellNoiseFloat(const float *arg,float w) {
687 unsigned int i = 0;
688
689 permute(arg[0]);
690 permute(arg[1]);
691 permute(arg[2]);
692 permute(w);
693
694 return randN[i];
695 }
696
697 ///////////////////////////////////////////////////////////////////////
698 // Function : cellNoiseVector1D
699 // Description :
700 // Return Value :
701 // Comments :
cellNoiseVector(float * r,float arg)702 void cellNoiseVector(float *r,float arg) {
703 unsigned int i = 0;
704
705 permute(arg);
706
707 r[0] = randN[i];
708 r[1] = randN[permN[i]];
709 r[2] = randN[permN[permN[i]]];
710 }
711
712 ///////////////////////////////////////////////////////////////////////
713 // Function : cellNoiseVector2D
714 // Description :
715 // Return Value :
716 // Comments :
cellNoiseVector(float * r,float u,float v)717 void cellNoiseVector(float *r,float u,float v) {
718 unsigned int i = 0;
719
720 permute(u);
721 permute(v);
722
723 r[0] = randN[i];
724 r[1] = randN[permN[i]];
725 r[2] = randN[permN[permN[i]]];
726 }
727
728 ///////////////////////////////////////////////////////////////////////
729 // Function : cellNoiseVector3D
730 // Description :
731 // Return Value :
732 // Comments :
cellNoiseVector(float * r,const float * arg)733 void cellNoiseVector(float *r,const float *arg) {
734 unsigned int i = 0;
735
736 permute(arg[0]);
737 permute(arg[1]);
738 permute(arg[2]);
739
740 r[0] = randN[i];
741 r[1] = randN[permN[i]];
742 r[2] = randN[permN[permN[i]]];
743 }
744
745 ///////////////////////////////////////////////////////////////////////
746 // Function : cellNoiseVector4D
747 // Description :
748 // Return Value :
749 // Comments :
cellNoiseVector(float * r,const float * arg,float w)750 void cellNoiseVector(float *r,const float *arg,float w) {
751 unsigned int i = 0;
752
753 permute(arg[0]);
754 permute(arg[1]);
755 permute(arg[2]);
756 permute(w);
757
758 r[0] = randN[i];
759 r[1] = randN[permN[i]];
760 r[2] = randN[permN[permN[i]]];
761 }
762