Esempio n. 1
0
static inline float fbmnoise4(float x, float y, float z)
{
	const float fbm_falloff = 0.5;
	const float f1 = fbm_falloff;
	const float f2 = fbm_falloff * fbm_falloff;
	const float f3 = fbm_falloff * fbm_falloff * fbm_falloff;

	return 1.0 * open_simplex_noise4(ctx, x, y, z, 1.0) +
		f1 * open_simplex_noise4(ctx, 2.0f * x, 2.0f * y, 2.0f * z, 1.0) +
		f2 * open_simplex_noise4(ctx, 4.0f * x, 4.0f * y, 4.0f * z, 1.0) +
		f3 * open_simplex_noise4(ctx, 8.0f * x, 8.0f * y, 8.0f * z, 1.0);
}
Esempio n. 2
0
VALUE OSimplex_Generator_get_4d_chunk (const VALUE self, const VALUE x, const VALUE y, const VALUE z, const VALUE w, const VALUE width, const VALUE height) {
  SELF2GENERATOR();
  const int           xStart    = NUM2INT(x);
  const int           xEnd      = xStart + NUM2INT(width);
  const int           yStart    = NUM2INT(y);
  const int           yEnd      = yStart + NUM2INT(height);
  const double        zVal      = NUM2DBL(z) / gen->scale;
  const double        wVal      = NUM2DBL(w) / gen->scale;

  VALUE               result    = rb_ary_new();
  for (int j=yStart; j<yEnd; ++j) {
    const double        jVal      = j / gen->scale;
    for (int i=xStart; i<xEnd; ++i) {
      double            val       = normalize( open_simplex_noise4( gen->context, i / gen->scale, jVal, zVal, wVal ), gen);
      rb_ary_push(result, rb_float_new(val));
    }
  }
  return result;
}
Esempio n. 3
0
VALUE OSimplex_Generator_get_4d (const VALUE self, const VALUE x, const VALUE y, const VALUE z, const VALUE w) {
  SELF2GENERATOR();

  double  ret   = open_simplex_noise4( gen->context, NUM2DBL(x) / gen->scale, NUM2DBL(y) / gen->scale, NUM2DBL(z) / gen->scale, NUM2DBL(w) / gen->scale );
  return  rb_float_new( normalize(ret, gen ) );
}
Esempio n. 4
0
static int simplex(double* buffer, const scil_dims_t* dims, double mn, double mx, double arg, double arg2, int seed){
  const int frequencyCount = (int) arg2;
  double highFrequency = (double) arg;

  if( scilU_double_equal(mn, mx) || frequencyCount <= 0 ){
    return SCIL_EINVAL;
  }

  struct osn_context *ctx;
  open_simplex_noise(seed, &ctx);

  int64_t max_potenz = 1<<frequencyCount;
  const size_t* len = dims->length;

  switch(dims->dims){
    case (1):{
      size_t count = scil_dims_get_count(dims);
      for (size_t i=0; i < count; i++){
        buffer[i] = 0;
        int64_t potenz = max_potenz;
        int64_t divisor = 1;
        for(int f = 1 ; f <= frequencyCount; f++){
          buffer[i] += potenz * open_simplex_noise2(ctx, 1.0, (double) i / count * divisor * highFrequency);
          potenz /= 2;
          divisor *= 2;
        }
      }
      break;
    }case (2):{
      for (size_t y=0; y < len[1]; y++){

        for (size_t x=0; x < len[0]; x++){
          double var = 0;
          int64_t potenz = max_potenz;
          int64_t divisor = 1;
          for(int f = 1 ; f <= frequencyCount; f++){
            var += potenz * open_simplex_noise2(ctx, (double) x / len[0] * divisor*highFrequency, (double) y / len[1] * divisor*highFrequency);
            potenz /= 2;
            divisor *= 2;
          }
          buffer[x+y*len[0]] = var;
        }

      }
      break;
    }case (3):{
      for (size_t z=0; z < len[2]; z++){
        for (size_t y=0; y < len[1]; y++){
          for (size_t x=0; x < len[0]; x++){
            double var = 0;
            int64_t potenz = max_potenz;
            int64_t divisor = 1;
            for(int f = 1 ; f <= frequencyCount; f++){
              var += potenz * open_simplex_noise3(ctx, (double) x / len[0]*divisor*highFrequency, (double) y / len[1]*divisor*highFrequency, (double) z / len[2]*divisor*highFrequency);
              potenz /= 2;
              divisor *= 2;
            }
            buffer[x+y*len[0]+z*(len[0]*len[1])] = var;
          }
        }
      }
      break;
    }case (4):{
      for (size_t w=0; w < len[3]; w++){
        for (size_t z=0; z < len[2]; z++){
          for (size_t y=0; y < len[1]; y++){
            for (size_t x=0; x < len[0]; x++){
              double var = 0;
              int64_t potenz = max_potenz;
              int64_t divisor = 1;
              for(int f = 1 ; f <= frequencyCount; f++){
                var += potenz * open_simplex_noise4(ctx, (double) x / len[0]*divisor*highFrequency, (double) y / len[1]*divisor*highFrequency, (double) z / len[2]*divisor*highFrequency, (double) w / len[3]*divisor*highFrequency);
                potenz /= 2;
                divisor *= 2;
              }
              buffer[x+len[0]*(y+len[1]*(z+len[2]*w))] = var;
            }
          }
        }
      }
      break;
    }default:
      assert(0 && "Not supported");
  }

  // fix min + max, first identify min/max
  scilP_change_data_scale(buffer, dims, mn, mx);

  open_simplex_noise_free(ctx);

  return SCIL_NO_ERR;
}