Example #1
0
// noise function for wind e.g.
static float wind_func(struct RNG *rng, float strength)
{
	int random = (BLI_rng_get_int(rng)+1) % 128; // max 2357
	float force = BLI_rng_get_float(rng) + 1.0f;
	float ret;
	float sign = 0;
	
	sign = ((float)random > 64.0f) ? 1.0f: -1.0f; // dividing by 2 is not giving equal sign distribution
	
	ret = sign*((float)random / force)*strength/128.0f;
	
	return ret;
}
Example #2
0
Noise::Noise(long seed)
{
  /* Use Blender RNG for repeatable results across platforms. */
  RNG *rng = BLI_rng_new(seed);
  int i, j, k;

  for (i = 0; i < _NOISE_B; i++) {
    p[i] = i;
    g1[i] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B;

    for (j = 0; j < 2; j++)
      g2[i][j] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B;
    normalize2(g2[i]);

    for (j = 0; j < 3; j++)
      g3[i][j] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B;
    normalize3(g3[i]);
  }

  while (--i) {
    k = p[i];
    p[i] = p[j = BLI_rng_get_int(rng) % _NOISE_B];
    p[j] = k;
  }

  for (i = 0; i < _NOISE_B + 2; i++) {
    p[_NOISE_B + i] = p[i];
    g1[_NOISE_B + i] = g1[i];

    for (j = 0; j < 2; j++)
      g2[_NOISE_B + i][j] = g2[i][j];

    for (j = 0; j < 3; j++)
      g3[_NOISE_B + i][j] = g3[i][j];
  }

  BLI_rng_free(rng);
}