Skip to content
Myr

added integer seed to noise function, use it in multi-octave noises

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent ca980dd · Browse files · 1 file+20 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+20 added−2 removed

  • other:+20 added−2 removed

1 file+20 added−2 removed

modified:stb_perlin.h+20 added-2 removed
30 unmodified lines
31// 0 to mean "don't care". (The noise always wraps every 256 due32// details of the implementation, even if you ask for larger or no33// wrapping.)34//35// float stb_perlin_noise3_seed( float x,36// float y,37// float z,38// int x_wrap=0,39// int y_wrap=0,40// int z_wrap=0,41// int seed)42//43// As above, but 'seed' selects from multiple different variations of the44// noise function. The current implementation only uses the bottom 8 bits45// of 'seed', but possibly in the future more bits will be used.46//47//48// Fractal Noise:49//50// Three common fractal noise functions are included, which produce 51// a wide variety of nice effects depending on the parameters
212 unmodified lines
264{265 return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap,0);266}267268float stb_perlin_noise3_seed(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, int seed)269{270 return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap, (unsigned char) seed);271}272273float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves)274{275 int i;276 float frequency = 1.0f;
2 unmodified lines
279 float sum = 0.0f;280281 for (i = 0; i < octaves; i++) {282 float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i);265 r = offset - fabs(r);283 r = offset - (float) fabs(r);284 r = r*r;285 sum += r*amplitude*prev;286 prev = r;287 frequency *= lacunarity;
25 unmodified lines
313 float sum = 0.0f;314 315 for (i = 0; i < octaves; i++) {316 float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude;299 sum += fabs(r);317 sum += (float) fabs(r);318 frequency *= lacunarity;319 amplitude *= gain;320 }321 return sum;
45 unmodified lines