float TerrainGenerator::operator()(float x, float z) const
{
	float h = 0;
	h += (simplexNoise(x/2000,z/2000)) * 512;
	h += (simplexNoise(x/1024,z/1024)) * 256;
	h += (simplexNoise(x/512,z/1024)) * 128;
	h += (simplexNoise(x/256,z/256)) * 64;
	h += (simplexNoise(x/128,z/128)) * 32;
	h += (simplexNoise(x/64,z/64)) * 16;
	h = fabs(h);
	return h;
}
Example #2
0
 STARTDECL(simplex) (Value &pos, Value &octaves, Value &scale, Value &persistence)
 {
     auto v = ValueDecTo<float4>(pos, 0);
     // TODO: if performance is ever an issue, could add an arg to indicate 2/3/4d version
     return Value(simplexNoise(octaves.ival, persistence.fval, scale.fval, v));
 }
Example #3
0
// 4D Scaled Multi-octave Simplex noise.
//
// Returned value will be between loBound and hiBound.
float simplexScaledNoise( const float octaves, const float persistence, const float scale, const float loBound, const float hiBound, const float x, const float y, const float z, const float w ) {
	return simplexNoise(octaves, persistence, scale, x, y, z, w) * (hiBound - loBound) / 2 + (hiBound + loBound) / 2;
}
Example #4
0
Quadtree::Quadtree(GLdouble a1, GLdouble b1, GLdouble a2, GLdouble b2, size_t level, unsigned int face) {
  const GLdouble L = (a2 - a1) / CHUNK_SIZE;

  box = new GLdouble[4];
  box[0] = a1;
  box[1] = b1;
  box[2] = a2;
  box[3] = b2;

  children[0] = NULL;
  children[1] = NULL;
  children[2] = NULL;
  children[3] = NULL;

  this->level = level - 1;
  this->face = face;

  // Generate cube.
  vertices = new Vertex[VERTICES];
  size_t i = 0;
  for (size_t b = 0; b < CHUNK_SIZE; b++) {
    for (size_t a = 0; a < CHUNK_SIZE; a++) {
      switch (face) {
        case FRONT:
          vertices[i].position[0] = a1 + L * (a + 0); vertices[i].position[1] = b1 + L * (b + 0); vertices[i].position[2] = 1.; i++;
          vertices[i].position[0] = a1 + L * (a + 1); vertices[i].position[1] = b1 + L * (b + 0); vertices[i].position[2] = 1.; i++;
          vertices[i].position[0] = a1 + L * (a + 1); vertices[i].position[1] = b1 + L * (b + 1); vertices[i].position[2] = 1.; i++;
          vertices[i].position[0] = a1 + L * (a + 0); vertices[i].position[1] = b1 + L * (b + 1); vertices[i].position[2] = 1.; i++;
          break;
        case BACK:
          vertices[i].position[0] = a1 + L * (a + 1); vertices[i].position[1] = b1 + L * (b + 0); vertices[i].position[2] = -1.; i++;
          vertices[i].position[0] = a1 + L * (a + 0); vertices[i].position[1] = b1 + L * (b + 0); vertices[i].position[2] = -1.; i++;
          vertices[i].position[0] = a1 + L * (a + 0); vertices[i].position[1] = b1 + L * (b + 1); vertices[i].position[2] = -1.; i++;
          vertices[i].position[0] = a1 + L * (a + 1); vertices[i].position[1] = b1 + L * (b + 1); vertices[i].position[2] = -1.; i++;
          break;
        case TOP:
          vertices[i].position[0] = a1 + L * (a + 1); vertices[i].position[1] = 1.f; vertices[i].position[2] = b1 + L * (b + 0); i++;
          vertices[i].position[0] = a1 + L * (a + 0); vertices[i].position[1] = 1.f; vertices[i].position[2] = b1 + L * (b + 0); i++;
          vertices[i].position[0] = a1 + L * (a + 0); vertices[i].position[1] = 1.f; vertices[i].position[2] = b1 + L * (b + 1); i++;
          vertices[i].position[0] = a1 + L * (a + 1); vertices[i].position[1] = 1.f; vertices[i].position[2] = b1 + L * (b + 1); i++;
          break;
        case BOTTOM:
          vertices[i].position[0] = a1 + L * (a + 0); vertices[i].position[1] = -1.f; vertices[i].position[2] = b1 + L * (b + 0); i++;
          vertices[i].position[0] = a1 + L * (a + 1); vertices[i].position[1] = -1.f; vertices[i].position[2] = b1 + L * (b + 0); i++;
          vertices[i].position[0] = a1 + L * (a + 1); vertices[i].position[1] = -1.f; vertices[i].position[2] = b1 + L * (b + 1); i++;
          vertices[i].position[0] = a1 + L * (a + 0); vertices[i].position[1] = -1.f; vertices[i].position[2] = b1 + L * (b + 1); i++;
          break;
        case LEFT:
          vertices[i].position[0] = -1.f; vertices[i].position[1] = b1 + L * (b + 1); vertices[i].position[2] = a1 + L * (a + 0); i++;
          vertices[i].position[0] = -1.f; vertices[i].position[1] = b1 + L * (b + 0); vertices[i].position[2] = a1 + L * (a + 0); i++;
          vertices[i].position[0] = -1.f; vertices[i].position[1] = b1 + L * (b + 0); vertices[i].position[2] = a1 + L * (a + 1); i++;
          vertices[i].position[0] = -1.f; vertices[i].position[1] = b1 + L * (b + 1); vertices[i].position[2] = a1 + L * (a + 1); i++;
          break;
        case RIGHT:
          vertices[i].position[0] = 1.f; vertices[i].position[1] = b1 + L * (b + 0); vertices[i].position[2] = a1 + L * (a + 0); i++;
          vertices[i].position[0] = 1.f; vertices[i].position[1] = b1 + L * (b + 1); vertices[i].position[2] = a1 + L * (a + 0); i++;
          vertices[i].position[0] = 1.f; vertices[i].position[1] = b1 + L * (b + 1); vertices[i].position[2] = a1 + L * (a + 1); i++;
          vertices[i].position[0] = 1.f; vertices[i].position[1] = b1 + L * (b + 0); vertices[i].position[2] = a1 + L * (a + 1); i++;
          break;
      }
    }
  }

  // Spherize cube.
  for (size_t i = 0; i < VERTICES; i++) {
    const GLdouble x2 = vertices[i].position[0] * vertices[i].position[0];
    const GLdouble y2 = vertices[i].position[1] * vertices[i].position[1];
    const GLdouble z2 = vertices[i].position[2] * vertices[i].position[2];
    const GLdouble noise = simplexNoise(20, 0.5, 0.125, vertices[i].position[0], vertices[i].position[1], vertices[i].position[2], 0.) + 1.;
    vertices[i].position[0] *= sqrt(1 - y2 / 2 - z2 / 2 + y2 * z2 / 3) * noise;
    vertices[i].position[1] *= sqrt(1 - x2 / 2 - z2 / 2 + x2 * z2 / 3) * noise;
    vertices[i].position[2] *= sqrt(1 - x2 / 2 - y2 / 2 + x2 * y2 / 3) * noise;
  }

  // Compile vertex buffer object.
  glGenBuffers(1, &vertexbuffer);
  glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
  glBufferData(GL_ARRAY_BUFFER, VERTICES * sizeof(Vertex), vertices, GL_STATIC_DRAW);
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, position));

  GLuint *indices = new GLuint[INDICES];
  for (size_t i = 0; i < INDICES; i++) {
    indices[i] = i;
  }
  glGenBuffers(1, &indexbuffer);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexbuffer);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDICES * sizeof(GLuint), indices, GL_STATIC_DRAW);
  delete indices;
}