Esempio n. 1
0
Vector PerlinGenerator::at( const Vector& pos )
{
  //return sky( pos.x,pos.y,pos.z, SKY_BLUE, CLOUD_WHITE ) ;
  Vector n = pos/worldNormalizer ;

  switch( noiseType )
  {
    case PerlinNoiseType::Sky:
      return sky( n.x, n.y, n.z, SKY_BLUE, CLOUD_WHITE ) ;
      
    case PerlinNoiseType::Wood:
      return wood( n.x, n.y, n.z ) ;
      
    case PerlinNoiseType::Marble:
    default:
      return marble( n.x,n.y,n.z, n.x ) ;

    case PerlinNoiseType::CustomLinear:
      return linearSpline( PerlinNoise3D( n.x,n.y,n.z, persistence, lacunarity, octaves ) ) ;
      
    case PerlinNoiseType::CustomQuadratic:
      return quadraticSpline( PerlinNoise3D( n.x,n.y,n.z, persistence, lacunarity, octaves ) ) ;

    case PerlinNoiseType::CustomCubic:
      return cubicSpline( PerlinNoise3D( n.x,n.y,n.z, persistence, lacunarity, octaves ) ) ;

    case PerlinNoiseType::CustomQuartic:
      return quarticSpline( PerlinNoise3D( n.x,n.y,n.z, persistence, lacunarity, octaves ) ) ;

    case PerlinNoiseType::CustomQuintic:
      return quinticSpline( PerlinNoise3D( n.x,n.y,n.z, persistence, lacunarity, octaves ) ) ;

  }
}
Esempio n. 2
0
  Dataset* Dataset::createPyroclasticVolume(size_t sz, float r)
  {
    Dataset* dataset = new Dataset;
    dataset->width = dataset->height = dataset->slices = sz;
    dataset->bytes_elem = sizeof(GLubyte);

    dataset->data = new GLubyte[sz * sz * sz];
    GLubyte* ptr = (GLubyte*) dataset->data;

    float frequency = 3.0f / sz;
    float center = sz / 2.0f + 0.5f;

    for(size_t x = 0; x < sz; ++x) {
      for(size_t y = 0; y < sz; ++y) {
        for(size_t z = 0; z < sz; ++z) {
          float dx = center - x;
          float dy = center - y;
          float dz = center - z;

          float off = fabsf((float) PerlinNoise3D(x * frequency, y * frequency, z * frequency, 5, 6, 3));

          float d = sqrtf(dx*dx + dy*dy + dz*dz) / sz;
          bool isFilled = (d - off) < r;
          *ptr++ = isFilled ? 255 : 0;
        }
      }
    }

    dataset->loaded(true);
    dataset->uploaded(false);

    return dataset;
  }
Esempio n. 3
0
void maze(int low, int high)
{
  int x, y, z, lines, num, dimension_increment;

  for(x = 1; x < WORLDX-1; x++)
    for(y = low; y <= high; y++)
      for(z = 1; z < WORLDZ-1; z++)
        if(0 < PerlinNoise3D(x/12.0, y/12.0, z/12.0, 2.1, 1.9, 2))
        {
           if(rand() % 3 > 1)
             world[x][y][z] = STONE;
           else
             world[x][y][z] = DIRT;
        }

  for(dimension_increment = 0; dimension_increment <= 1; dimension_increment++)
  {
    for(x = 0; x < WORLDX; x++)
      for(y = low; y <= high; y++)
      {
        if(dimension_increment == 0)
        {
          world[x][y][0] = STONE;
          world[x][y][WORLDZ-1] = STONE;
        }
        else
        {
          world[0][y][x] = STONE;
          world[WORLDX-1][y][x] = STONE;
        }
      }


    lines = rand() % 15;
    for(num = 0; num < lines; num++)
    {
      if(num == 0) x = 45;
      else x = rand() % (WORLDX-1);
      for(z = 1; z < WORLDZ-1; z++)
      {
        for(y = low; y <= high; y++)
        {
          if(dimension_increment == 0)
          {
            world[x][y][z] = EMPTY;
          } 
          else if(dimension_increment == 1)
          {
            world[z][y][x] = EMPTY;
          }
        }
      }
    }
  }
}
Esempio n. 4
0
Vector PerlinGenerator::marble( double x, double y, double z, double grainVariable,
  int freckling, double freqBoost,
  const Vector& c1, const Vector& c2, const Vector& c3, const Vector& c4 )
{
  // sin( x + |noise(p)| + .5*|noise(2p)| + ... )
  real n = PerlinNoise3D( x,y,z, 2, 2, freckling ) ;
  real val = sin( freqBoost*(grainVariable + n) ) ;
  
  // You can also blend using a bezier type spline,
  real t = ( 1 + val ) / 2.0 ;

  return cubicSpline( t,c1,c2,c3,c4 ) ;
}
Esempio n. 5
0
Vector PerlinGenerator::marble( double x, double y, double z, double grainVariable,
  int freckling, double freqBoost, const Vector& c1, const Vector& c2 )
{
  // sin( x + |noise(p)| + .5*|noise(2p)| + ... )
  real n = PerlinNoise3D( x,y,z, 2, 2, freckling ) ;
  real val = sin( freqBoost*(grainVariable + n) ) ;
  
  // has black rifts between colors,
  ////if( val < 0 )  return (-val)*colorMinus;
  ////else  return val*colorPlus;
  
  real t = (1+val)/2.0 ;
  return linearSpline( t, c1, c2 ) ;
}
Esempio n. 6
0
static inline void cbite()
{
    auto startTime = boost::get_system_time().time_of_day().total_milliseconds();
    for (int x = 0 ; x < 128 ; ++x)
    {
        double xx = x;
        for (int y = 0 ; y < 128 ; ++y)
        {
            double yy = y;
            for (int z = 0 ; z < 128 ; ++z)
            {
                double zz = z;
                PerlinNoise3D(xx, yy, zz, 2.0, 2.0, 4);
            }
        }
    }
    std::cout << "c time= " << (boost::get_system_time().time_of_day().total_milliseconds() - startTime) << "ms\n";
}
Esempio n. 7
0
Vector PerlinGenerator::sky( double x, double y, double z, const Vector& skyColor, const Vector& cloud )
{
  //real val = PerlinNoise3D( x,y,z, 1.2, 2, 12 ) ; // rocky and pixellated
  
  ///////real a=.1, // a is the size of the sides.  a=big means THICK DONUT
  ///////     c=.6; // c is the size of the ring.  c=big means LARGE CIRCUMFERENCE DONUT
  ///////x *= 2*PI ;
  ///////y *= 2*PI ;
  ///////real xt = (c+a*cos(y))*cos(x);
  ///////real yt = (c+a*cos(y))*sin(x);
  ///////real zt = a*sin(y);
  ///////real val = PerlinNoise3D( xt,yt,zt, 1.5, 2, 12 ) ; // torus

  real val = PerlinNoise3D( x,y,z, 1.5, 2, 12 ) ; // "very good" cloud

  //real val = PerlinNoise3D( x,y,z, 2, 4, 12 ) ; // smoother than "very good"
  //real val = PerlinNoise3D( x,y,z, 2, 2, 12 ) ; // too smooth

  // force x,y,z input values to REPEAT, making it tileable
  // travel in a torus.
  //real c=4, a=1;
  //real x1 = (c+a*cos(y))*cos(x);
  //real y1 = (c+a*cos(y))*sin(x);
  //real val = PerlinNoise2D( x,y, 2, 2, 12 ) ; // test
  
  real t = (1+val)/2.0 ;
  
  //return (t*t*skyColor + (1-t)*(1-t)*cloud).clamp(0,1) ; // DARKER clouds
  //return (t*skyColor + (1-t)*(1-t)*cloud).clamp(0,1) ; // lighter clouds
  //return linearSpline( t, skyColor, cloud ) ; //very smooth, light clouds day
  
  //return cubicSpline( t, 1, .5, Vector( 0.570, 0.710, 1.000 ), Vector( .168, .612, 1 ) ) ; // another nice cloud
  //return cubicSpline( t, cloud, .5, Vector(0.2016, 0.7344, 1), skyColor ) ;
  //return cubicSpline( t, cloud, cloud*.5, (skyColor*1.2).clamp(0,1), skyColor ) ;
  //return cubicSpline( t, cloud, 0,.5, skyColor ) ; // dark/ominous.
  //return quinticSpline( t, cloud, .5,Vector(.2,.4,1),-.2,1, skyColor ) ; // abstract/painterly
  //return quinticSpline( t, cloud, .5, .5, 0, Vector(.2,.4,1), skyColor ) ; // ok
  
  return quadraticSpline( t, cloud, .6, skyColor ) ; // Very good.
  
}
Esempio n. 8
0
/* Makes perlin-noise clouds! Uses Ken Perlin's PerlinNoise3D function, taken from
http://local.wasp.uwa.edu.au/~pbourke/texture_colour/perlin */
void perlin_clouds(double level, double scale, double deg)
{
  int x, z;
  GLfloat *light = getLightPosition();
  clouds_flag = 1;

  level = bounds(level, 0, WORLDY-1);
  for(x = 0; x < WORLDX; x++)
  {
    for(z = 0; z < WORLDZ; z++)
    {
      /* Overwrite whatever was here before, as long as it isn't the sun. */
      if(!((float)x == light[0] && level == light[1] && (float)z == light[2]))
	world[x][(int)level][z] = EMPTY;

      /* Using deg (from update) as the y-axis, step through slices of
	 smooth volumetric noise to get realistic looking clouds. */
      if((PerlinNoise3D(x/76.0, z/76.0, deg/108.0, 1.99, 2.1, 4) * scale) > 0)
	world[x][(int)level][z] = WHITE;
    }
  }
}
Esempio n. 9
0
//======================================================================================
//======================================================================================
double PNoise::PNoise3D(double x, double y, double z)
{
  return PerlinNoise3D(x,y,z, _n, _alpha, _beta);
}