Example #1
0
static PyObject *
py_noise3(PyObject *self, PyObject *args)
{
	float x, y, z;
	int octaves = 1;
	float persistence = 0.5f;
	if (!PyArg_ParseTuple(args, "fff|if:noise3", &x, &y, &z, &octaves, &persistence))
		return NULL;
	
	if (octaves == 1) {
		// Single octave, return simple noise
		return (PyObject *) PyFloat_FromDouble((double) noise3(x, y, z));
	} else if (octaves > 1) {
		int i;
		float freq = 1.0f;
		float amp = 1.0f;
		float total = 0.0f;

		for (i = 0; i < octaves; i++) {
			total += noise3(x * freq, y * freq, z * freq) * amp;
			freq *= 2.0f;
			amp *= persistence;
		}
		return (PyObject *) PyFloat_FromDouble((double) total);
	} else {
		PyErr_SetString(PyExc_ValueError, "Expected octaves value > 0");
		return NULL;
	}
}
Example #2
0
void AD_NoiseModifier::Map(AD_Vect3D *pos, AD_Vect3D *out)
{
   AD_Vect3D d, sp, p;

   p.x=pos->x-center.x;
   p.y=pos->y-center.y;
   p.z=pos->z-center.z;

   sp.x=(0.5f + p.x*scale);
   sp.y=(0.5f + p.y*scale);
   sp.z=(0.5f + p.z*scale);

   if (fractal)
   {
      /*
      d.x = fBm1(Point3(sp.y,sp.z,time),rough,2.0f,iterations);
      d.y = fBm1(Point3(sp.x,sp.z,time),rough,2.0f,iterations);
      d.z = fBm1(Point3(sp.x,sp.y,time),rough,2.0f,iterations);
	  */
      vect_copy(pos, out);
	  return;
   }
   else
   {
      d.x = noise3(sp.z, time, sp.y);
      d.z = noise3(sp.x, time, sp.y);
      d.y = noise3(sp.x, time, sp.z);
   }

   out->x = (p.x + d.x*strength.x) + center.x;
   out->y = (p.y + d.y*strength.y) + center.y;
   out->z = (p.z + d.z*strength.z) + center.z;
}
Example #3
0
/*
* Based on Perlin Noise Math FAQ by M. Zucker
*/
static double tiled_noise2(int * p, double x, double y, double w, double h)
{  
  return
    (
      noise3(p,     x,     y, 0.0) * (w - x) * (h - y) +
      noise3(p, x - w,     y, 0.0) *     (x) * (h - y) +
      noise3(p, x - w, y - h, 0.0) *     (x) *     (y) +
      noise3(p,     x, y - h, 0.0) * (w - x) *     (y)
    ) / (w * h);
}
Example #4
0
void CWindModifier::m_Force (float4 framepos, AD_Vect3D *pos, AD_Vect3D *vel, AD_Vect3D *accel)
{
  AD_Vect3D posrel, tf, p, force, p2;
  float4 dist, freq, turb;

  freq=p_Frequency;
  turb=p_Turbolence;

  if (p_Mapping==FORCE_PLANAR)
  {
    if (p_Decay!=0.0f)
	{
	  vect_sub(pos, &p_CurrentPosition, &posrel);
	  dist=fabsf(vect_dot(&p_Force, &posrel));
      vect_scale(&p_ScaledForce, (float4)exp(-p_Decay*dist), accel);
	}
	else vect_copy(&p_ScaledForce, accel);
  } 
  else
  {
    vect_sub(pos, &p_CurrentPosition, &force);
    dist = vect_length(&force);
    if (dist != 0) vect_auto_scale(&force, 1.0f/dist);
    if (p_Decay != 0)
      vect_scale(&force, p_ScaledStrength*(float4)exp(-p_Decay*dist), accel);
	else
      vect_scale(&force, p_ScaledStrength, accel);
  }

  if (turb != 0)
  {
    vect_sub(pos, &p_CurrentPosition, &p2);
    freq *= 0.01f;

	vect_copy(&p2, &p);
    p.x  = freq * framepos;
    tf.x = noise3(p.x*p_Scale, p.y*p_Scale, p.z*p_Scale);

	vect_copy(&p2, &p);
    p.y  = freq * framepos;
    tf.y = noise3(p.x*p_Scale, p.y*p_Scale, p.z*p_Scale);

	vect_copy(&p2, &p);    
	p.z  = freq * framepos;
    tf.z = noise3(p.x*p_Scale, p.y*p_Scale, p.z*p_Scale);

    turb *= 0.0001f*forceScaleFactor;
    vect_auto_scale(&tf, turb);
	vect_add(accel, &tf, accel);
  }
}
Example #5
0
float Smoke::SmokeFunc(Point3 p, int iter) {
	float s, mag, ft, r[3], d, hfb;
	int i;
	s = 1.0f;
	mag = 0.0f;
	hfb = 2.0f*1.2f; // *hfboost;
	ft = 1.0f;
	float x = p.x;
	float y = p.y;
	float z = p.z;
	for (i = 0; i < iter; i++) {
		float k = ft*phase;
		r[0] = x + xvel[i]*k;
		r[1] = y + yvel[i]*k;
		r[2] = z + zvel[i]*k;
		mag += (float)fabs(noise3(r))/s;
		x *= 2.0f; 
		y *= 2.0f;	
		z *= 2.0f;
		s *= 2.0f; 
		ft *= hfb; // Make motion a little greater for fine detail
		}
	d = mag;
	if (d>1.0f) return 1.0f;
	return (float )pow(d,power);
	}
void make3DNoiseTexture()
{
	int f, i, j, k, inc;
	int startFrequency = 4;
	int numOctaves = 4;
	double ni[3];
	double inci, incj, inck;
	int frequency = startFrequency;
	GLubyte* ptr;
	double amp = 0.5;

	Noise3DTexPtr = (GLubyte*) malloc(Noise3DTexSize * Noise3DTexSize * Noise3DTexSize * 4);
	for (f = 0, inc = 0; f < numOctaves; ++f, frequency *= 2, ++inc, amp *= 0.5)
	{
		SetNoiseFrequency(frequency);
		ptr = Noise3DTexPtr;
		ni[0] = ni[1] = ni[2] = 0;

		inci = 1.0 / (Noise3DTexSize / frequency);
		for (i = 0; i < Noise3DTexSize; ++i, ni[0] += inci)
		{
			incj = 1.0 / (Noise3DTexSize / frequency);
			for (j = 0; j < Noise3DTexSize; ++j, ni[1] += incj)
			{
				inck = 1.0 / (Noise3DTexSize / frequency);
				for (k = 0; k < Noise3DTexSize; ++k, ni[2] += inck, ptr += 4)
					*(ptr + inc) = (GLubyte) (((noise3(ni) + 1.0) * amp) * 128.0);
			}
		}
	}
}
Example #7
0
static PyObject *
py_noise3(PyObject *self, PyObject *args, PyObject *kwargs)
{
	float x, y, z;
	int octaves = 1;
	float persistence = 0.5f;
    float lacunarity = 2.0f;

	static char *kwlist[] = {"x", "y", "z", "octaves", "persistence", "lacunarity", NULL};

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "fff|iff:snoise3", kwlist,
		&x, &y, &z, &octaves, &persistence, &lacunarity))
		return NULL;
	
	if (octaves == 1) {
		// Single octave, return simple noise
		return (PyObject *) PyFloat_FromDouble((double) noise3(x, y, z));
	} else if (octaves > 1) {
		return (PyObject *) PyFloat_FromDouble(
            (double) fbm_noise3(x, y, z, octaves, persistence, lacunarity));
	} else {
		PyErr_SetString(PyExc_ValueError, "Expected octaves value > 0");
		return NULL;
	}
}
Example #8
0
F32 LLPerlinNoise::clouds3(F32 x, F32 y, F32 z, F32 freq)
{
	F32 t, lx, ly, lz;

	for (t = 0.f ; freq >= 1.f ; freq *= 0.5f)
	{
		lx = freq * x;
		ly = freq * y;
		lz = freq * z;
//		t += noise3(lx,ly,lz)/freq;
//		t += fabs(noise3(lx,ly,lz)) / freq;					// Like snow - bubbly at low frequencies
//		t += sqrt(fabs(noise3(lx,ly,lz))) / freq;			// Better at low freq
		t += (noise3(lx,ly,lz)*noise3(lx,ly,lz)) / freq;		
	}
	return t;
}
Example #9
0
void noise3tex(unsigned char *tex, int size)
{
	int f, i, j, k, inc;
	int startf = 4;
	int numo = 4;
	double ni[3];
	double inci, incj, inck;
	int freq = startf;
	unsigned char *ptr;
	double amp = 0.5;

	for (f = 0, inc = 0; f < numo; ++f, freq *= 2, ++inc, amp *= 0.5)
	{
		ptr = tex;
		ni[0] = ni[1] = ni[2] = 0;

		inci = 1.0/(size/freq);
		for (i = 0; i < size; ++i, ni[0] += inci)
		{
			incj = 1.0/(size/freq);
			for (j = 0; j < size; ++j, ni[1] += incj)
			{
				inck = 1.0/(size/freq);
				for (k = 0; k < size; ++k, ni[2] += inck, ptr += 4)
					*(ptr+inc) = (unsigned char)((noise3(ni) + 1.0)*amp*128.0);
			}
		}
	}
}
Example #10
0
inline float
fbm_noise3(float x, float y, float z, int octaves, float persistence, float lacunarity) {
    float freq = 1.0f;
    float amp = 1.0f;
    float max = 1.0f;
    float total = noise3(x, y, z);
    int i;

    for (i = 1; i < octaves; ++i) {
        freq *= lacunarity;
        amp *= persistence;
        max += amp;
        total += noise3(x * freq, y * freq, z * freq) * amp;
    }
    return total / max;
}
Example #11
0
double fBm( Vector point, double H, double lacunarity, double octaves,
	    int init )
{

    double            value, frequency, remainder;
    int               i;
    static double     exponent_array[10];
    float             vec[3];

    /* precompute and store spectral weights */
    if ( init ) {
	start = 1;
	srand( time(0) );
	/* seize required memory for exponent_array */
	frequency = 1.0;
	for (i=0; i<=octaves; i++) {
	    /* compute weight for each frequency */
	    exponent_array[i] = pow( frequency, -H );
	    frequency *= lacunarity;
	}
    }

    value = 0.0;            /* initialize vars to proper values */
    frequency = 1.0;
    vec[0]=point.x;
    vec[1]=point.y;
    vec[2]=point.z;


    /* inner loop of spectral construction */
    for (i=0; i<octaves; i++) {
	/* value += noise3( vec ) * exponent_array[i];*/
	value += noise3( vec ) * exponent_array[i];
	vec[0] *= lacunarity;
	vec[1] *= lacunarity;
	vec[2] *= lacunarity;
    } /* for */

    remainder = octaves - (int)octaves;
    if ( remainder )      /* add in ``octaves''  remainder */
	/* ``i''  and spatial freq. are preset in loop above */
	value += remainder * noise3( vec ) * exponent_array[i];

    return( value );

} /* fBm() */
Example #12
0
float tileableNoise3(const float x, const float y, const float z, const float w, const float h, const float d){
	return (noise3(x,     y,     z)     * (w - x) * (h - y) * (d - z) +
			noise3(x - w, y,     z)     *      x  * (h - y) * (d - z) +
			noise3(x,     y - h, z)     * (w - x) *      y  * (d - z) +
			noise3(x - w, y - h, z)     *      x  *      y  * (d - z) + 
			noise3(x,     y,     z - d) * (w - x) * (h - y) *      z  +
			noise3(x - w, y,     z - d) *      x  * (h - y) *      z  +
			noise3(x,     y - h, z - d) * (w - x) *      y  *      z  +
			noise3(x - w, y - h, z - d) *      x  *      y  *      z) / (w * h * d);
}
Example #13
0
void
noise_fp(float *ret, float4 p)
{
    float r;

    r = noise3(p.x, p.y, p.z);
    
    (*ret) = r;
}
Example #14
0
scalar_t turbulence3(scalar_t x, scalar_t y, scalar_t z, int octaves)
{
	int i;
	scalar_t res = 0.0f, freq = 1.0f;
	for(i=0; i<octaves; i++) {
		res += fabs(noise3(x * freq, y * freq, z * freq) / freq);
		freq *= 2.0f;
	}
	return res;
}
Example #15
0
float turbulence3(const float x, const float y, const float z, float freq){
	float t = 0.0f;

	do {
		t += noise3(freq * x, freq * y, freq * z) / freq;
		freq *= 0.5f;
	} while (freq >= 1.0f);
	
	return t;
}
Example #16
0
static PyObject *
py_noise3(PyObject *self, PyObject *args, PyObject *kwargs)
{
	float x, y, z;
	int octaves = 1;
	float persistence = 0.5f;
    float lacunarity = 2.0f;
	int repeatx = 1024; // arbitrary
	int repeaty = 1024; // arbitrary
	int repeatz = 1024; // arbitrary
	int base = 0;

	static char *kwlist[] = {"x", "y", "z", "octaves", "persistence", "lacunarity",
		"repeatx", "repeaty", "repeatz", "base", NULL};

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "fff|iffiiii:noise3", kwlist,
		&x, &y, &z, &octaves, &persistence, &lacunarity, &repeatx, &repeaty, &repeatz, &base))
		return NULL;
	
	if (octaves == 1) {
		// Single octave, return simple noise
		return (PyObject *) PyFloat_FromDouble((double) noise3(x, y, z, 
			repeatx, repeaty, repeatz, base));
	} else if (octaves > 1) {
		int i;
		float freq = 1.0f;
		float amp = 1.0f;
		float max = 0.0f;
		float total = 0.0f;

		for (i = 0; i < octaves; i++) {
			total += noise3(x * freq, y * freq, z * freq, 
				(const int)(repeatx*freq), (const int)(repeaty*freq), (const int)(repeatz*freq), base) * amp;
			max += amp;
			freq *= lacunarity;
			amp *= persistence;
		}
		return (PyObject *) PyFloat_FromDouble((double) (total / max));
	} else {
		PyErr_SetString(PyExc_ValueError, "Expected octaves value > 0");
		return NULL;
	}
}
Example #17
0
scalar_t fbm3(scalar_t x, scalar_t y, scalar_t z, int octaves)
{
	int i;
	scalar_t res = 0.0f, freq = 1.0f;
	for(i=0; i<octaves; i++) {
		res += noise3(x * freq, y * freq, z * freq) / freq;
		freq *= 2.0f;
	}
	return res;
}
Example #18
0
static int l_noise3(lua_State * L)
{
  int * p = (int *)luaL_checkudata(L, 1, LUAPERLIN_MT);
  double x = luaL_checknumber(L, 2);
  double y = luaL_checknumber(L, 3);
  double z = luaL_checknumber(L, 4);

  lua_pushnumber(L, noise3(p, x, y, z));

  return 1;
}
Example #19
0
static int perlin_lua(lua_State *L) {
    int top = lua_gettop(L);
    if(top == 2) {
        lua_pushnumber(L, noise2(lua_tonumber(L, 1), lua_tonumber(L, 2)));
    } else if(top == 3) {
        lua_pushnumber(L, noise3(lua_tonumber(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3)));
    } else {
        return luaL_error(L, "expected 2 or 3 arguments but got %d", top);
    }
    return 1;
}
Example #20
0
//
//  Create 3D noise texture
//
int CreateNoise3D(int unit)
{
   int f,i,j,k,inc;
   unsigned int id;
   int numOctaves = 4;
   double ni[3];
   double inci,incj,inck;
   int frequency = 4;
   double amp = 0.5;
   char* ptr;
   char pix[size * size * size * 4];

   for (f=0,inc=0; f<numOctaves; f++,frequency*=2,inc++,amp*=0.5)
   {
      SetNoiseFrequency(frequency);
      ptr = pix;
      ni[0] = ni[1] = ni[2] = 0;

      inci = 1.0 / (size / frequency);
      for (i = 0; i < size; ++i, ni[0] += inci)
      {
         incj = 1.0 / (size / frequency);
         for (j = 0; j < size; ++j, ni[1] += incj)
         {
            inck = 1.0 / (size / frequency);
            for (k = 0; k < size; ++k, ni[2] += inck, ptr += 4)
               *(ptr + inc) = (char) (((noise3(ni) + 1.0) * amp) * 128.0);
         }
      }
   }

   //  Select texture unit
   glActiveTexture(unit);

   //  Generate 2D texture id and make current
   glGenTextures(1,&id);
   glBindTexture(GL_TEXTURE_2D,id);

   //  Copy noise to texture
   glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, size, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix);

   //  Set texture parameters
   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

   //  Select texture unit
   glActiveTexture(GL_TEXTURE0);

   return id;
}
Example #21
0
double PerlinGenerator::PerlinNoise3D(double x, double y, double z, double divisionFactor, double freqMult, int numFreqs )
{
  double sum = 0;
  double p[3],scale = 1;

  p[0] = x;
  p[1] = y;
  p[2] = z;
  for( int i = 0 ; i < numFreqs ; i++ )
  {
    sum += noise3(p) / scale;
    scale *= divisionFactor ;
    p[0] *= freqMult ;
    p[1] *= freqMult ;
    p[2] *= freqMult ;
  }
  return sum ;
}
Example #22
0
float interpolatedNoise3(float x, float y, float z, float maxx, float maxy, float maxz, int octave)
{
    register int	intx	= (int)x;
    register int	inty	= (int)y;
    register int	intz	= (int)z;
    register int	nextx	= (intx == (int)maxx ? 0 : intx+1);
    register int	nexty	= (inty == (int)maxy ? 0 : inty+1);
    register int	nextz	= (intz == (int)maxz ? 0 : intz+1);
    register float	fracx	= x - (float)intx;
    register float	fracy	= y - (float)inty;
    register float	fracz	= z - (float)intz;
    register float	i1		= interpolate(noise3(intx, inty, intz, octave), noise3(nextx, inty, intz, octave), fracx);
    register float	i2		= interpolate(noise3(intx, nexty, intz, octave), noise3(nextx, nexty, intz, octave), fracx);
    register float	i3		= interpolate(noise3(intx, inty, nextz, octave), noise3(nextx, inty, nextz, octave), fracx);
    register float	i4		= interpolate(noise3(intx, nexty, nextz, octave), noise3(nextx, nexty, nextz, octave), fracx);
    register float	i5		= interpolate(i1, i2, fracy);
    register float	i6		= interpolate(i3, i4, fracy);

    return interpolate(i5, i6, fracz);
}
Example #23
0
 I noisetest::noise(I x, I y, I z, I alpha, I beta, I n)
 {
   int i;
   I val,sum = 0;
   I p[3],scale = 1;
   
   p[0] = x;
   p[1] = y;
   p[2] = z;
   for (i=0;i<n;i++) {
     val = noise3(p);
     sum += val / scale;
     scale *= alpha;
     p[0] *= beta;
     p[1] *= beta;
     p[2] *= beta;
   }
   return(sum);
 }
Example #24
0
double PerlinNoise3D(double x,double y,double z,double alpha,double beta,int n)
{
   int i;
   double val,sum = 0;
   double p[3],scale = 1;

   p[0] = x;
   p[1] = y;
   p[2] = z;
   for (i=0;i<n;i++) {
      val = noise3(p);
      sum += val / scale;
      scale *= alpha;
      p[0] *= beta;
      p[1] *= beta;
      p[2] *= beta;
   }
	return(sum);
}
void make3DNoiseTexture(void){

   int f, i, j, k, inc;
    int startFrequency = 4;
    int numOctaves = 4;
    double ni[3];
    double inci, incj, inck;
    int frequency = startFrequency;
    GLubyte *ptr;
    double amp = 0.5;

    if ((noise3DTexPtr = (GLubyte *) malloc(noise3DTexSize *
                                            noise3DTexSize *
                                            noise3DTexSize * 4)) == NULL)
        {
        fprintf(stderr, "ERROR: Could not allocate 3D noise texture\n");
        exit(1);
        }

    for (f=0, inc=0; f < numOctaves;
        ++f, frequency *= 2, ++inc, amp *= 0.5)
        {
        SetNoiseFrequency(frequency);
        ptr = noise3DTexPtr;
        ni[0] = ni[1] = ni[2] = 0;

        inci = 1.0 / (noise3DTexSize / frequency);
        for (i=0; i<noise3DTexSize; ++i, ni[0] += inci)
            {
            incj = 1.0 / (noise3DTexSize / frequency);
            for (j=0; j<noise3DTexSize; ++j, ni[1] += incj)
                {
                inck = 1.0 / (noise3DTexSize / frequency);
                for (k=0; k<noise3DTexSize; ++k, ni[2] += inck, ptr+= 4)
                    {
                    *(ptr+inc) = (GLubyte) (((noise3(ni)+1.0) * amp)*128.0);
                    }
                }
            } 
        }
	
}
Example #26
0
float Perlin::perlin_noise_3D(float vec[3]) {
    int terms = mOctaves;
    float freq = mFrequency;
    float result = 0.0f;
    float amp = mAmplitude;

    vec[0] *= mFrequency;
    vec[1] *= mFrequency;
    vec[2] *= mFrequency;

    for(int i=0; i<terms; i++ ) {
        result += noise3(vec)*amp;
        vec[0] *= 2.0f;
        vec[1] *= 2.0f;
        vec[2] *= 2.0f;
        amp*=0.5f;
    }

    return result;
}
Example #27
0
/*
STUCCO function

works off a noise function 'f'in range [0..1.0]

when f<=threshold returns 0.0;

state.thickness is the fraction of the remaining interval [thresh..1.0] 
taken up by a transition from 0 to 1.0;
Over this interval, a 2nd order curve (piecewise parabolic) is used.
over the first CRV part of the transition its parablolic, then for
the next 1-2*CRV part its linear, then for the last CRV part it's
an inverted parabola.
-------------------------------------------------------
*/
float Stucco::Func(Point3 p, float scl) {
	float f,t;
	f = 0.5f*(noise3(p)+1.0f); /* get number from  0 to 1.0 */

	if (f <= thresh) 
		return(float) 0.0f;
	t = thick+0.5f*scl;
	f = (f-thresh)/t;
	if (f >= 1.0f) 
		return (float) (1.0f);
	if (f < CRV) 	{
		return (float) (K1*f*f);
		}
	else 
	if (f < (1.0f-CRV)) {
	   return (float) (K*((2.0f*f)-CRV));
		}
	else {
		f = 1.0f-f;
		return (float) (1.0f - K1*(f*f));
		}
	}
Example #28
0
                T
        noise_3D (
                T		 vec[3])
        {
                T		 amp    = mAmplitude;
                T		 result = 0.0;

                vec[0] *= mFrequency;
                vec[1] *= mFrequency;
                vec[2] *= mFrequency;

                for( int i = 0; i < mOctaves; i++ )
                {
                        result += noise3(vec) * amp;
                        vec[0] *= 2.0;
                        vec[1] *= 2.0;
                        vec[2] *= 2.0;
                        amp    *= 0.5;
                }

                return result;
        }
Example #29
0
float Gradient::NoiseFunc(Point3 p)
	{
	float res(0.0f);
	switch (noiseType) {
		case NOISE_TURB: {
			float sum = 0.0f;
			float l,f = 1.0f;			
			for (l = levels; l>=1.0f; l-=1.0f) {				
				sum += (float)fabs(noise3(p*f))/f;
				f *= 2.0f;
				}
			if (l>0.0f) {				
				sum += l*(float)fabs(noise3(p*f))/f;
				}
			res = sum;
			break;
			}
			
		case NOISE_REGULAR:
			// multiply by junk (1.0) to avoid compiler bug
			res = junk*noise3(p);
			break;

		case NOISE_FRACTAL:
			if (levels==1.0f) {
				res = junk*noise3(p);
			} else {
				float sum = 0.0f;
				float l,f = 1.0f;				
				for (l = levels; l>=1.0f; l-=1.0f) {					
					sum += noise3(p*f)/f;
					f *= 2.0f;
					}
				if (l>0.0f) {					
					sum += l*noise3(p*f)/f;
					}
				res = sum;
				}
			break;
		}
	
	if (low<high) {
		res = 2.0f * sramp((res+1.0f)/2.0f,low,high,sd) - 1.0f;
		}
	return res;
	}
Example #30
0
	double PerlinNoise::perlin_noise_3D(double vec[3])
	{
		int terms    = m_Octaves;
		double freq   = m_Frequency;
		double result = 0.0f;
		double amp = m_Amplitude;

		vec[0]*=freq;
		vec[1]*=freq;
		vec[2]*=freq;

		for( int i=0; i<terms; i++ )
		{
			result += noise3(vec)*amp;
			vec[0] *= 2.0f;
			vec[1] *= 2.0f;
			vec[2] *= 2.0f;
			amp*=0.5f;
		}


		return result;
	}