Example #1
0
FLOAT32 CFrmPerlin::TileableNoise2(const FLOAT32 x, const FLOAT32 y, const FLOAT32 w, const FLOAT32 h)
{
	return ( Noise2( x,     y )     * ( w - x )* ( h - y ) +
			 Noise2( x - w, y )     *       x  * ( h - y ) +
			 Noise2( x,     y - h ) * ( w - x )*      y  +
			 Noise2( x - w, y - h ) *       x  *      y ) / ( w * h );
}
/*!
 * Multiband Noise 2D
 * @param[in] p[2] 2D座標
 * @param[in] s
 * @param[in] firstBand 最初のバンド
 * @param[in] nbands バンド数
 * @param[in] w 重み
 * @return 
 */
RXREAL rxWaveletNoise::MultibandNoise2(RXREAL p[2], int first, int nbands, RXREAL *w0)
{
	// HACK:WMultibandNoise2
	RXREAL result = 0;
	RXREAL w = pow((RXREAL)2.0, (RXREAL)first);
	RXREAL q[2];

	for(int b = 0; b < nbands; ++b){
		q[0] = p[0]*w;
		q[1] = p[1]*w;
		result += w0[b]*Noise2(q);
		w *= 2.0;
	}

	RXREAL sigma_m = 0;
	for(int b = 0; b < nbands; ++b){
		sigma_m += w0[b]*w0[b];
	}

	// B-Splineの平均分散σNは2Dで0.265,3Dで0.210,2D上へ投影した3Dノイズで0.296
	RXREAL sigma_n = 0.265;
	sigma_m = sqrt(sigma_n*sigma_m);

	// 分散が1になるようにノイズを調整
	if(sigma_m) result /= sigma_m;

	return result;

}
Example #3
0
float InterpolatedNoise2(float x, float y) {

	int integer_X = int(x);
	float fractional_X = x - integer_X;

	int integer_Y = int(y);
	float fractional_Y = y - integer_Y;

	float v1 = Noise2(integer_X, integer_Y);
	float v2 = Noise2(integer_X + 1, integer_Y);
	float v3 = Noise2(integer_X, integer_Y + 1);
	float v4 = Noise2(integer_X + 1, integer_Y + 1);

	float i1 = Interpolate(v1, v2, fractional_X);
	float i2 = Interpolate(v3, v4, fractional_X);
	return Interpolate(i1, i2, fractional_Y);
}
//[-------------------------------------------------------]
//[ Public static functions                               ]
//[-------------------------------------------------------]
float PerlinNoiseTurbulence::Turbulence2(float fX, float fY, float fFreq)
{
	float t = 0.0f;

	do {
		t += Noise2(fFreq*fX, fFreq*fY)/fFreq;
		fFreq *= 0.5f;
	} while (fFreq >= 1.0f);
	
	return t;
}
Example #5
0
FLOAT32 CFrmPerlin::Turbulence2( const FLOAT32 x, const FLOAT32 y, FLOAT32 fFreq )
{
	FLOAT32 t = 0.0f;

	do
    {
		t += Noise2(fFreq * x, fFreq * y) / fFreq;
		fFreq *= 0.5f;
	} while (fFreq >= 1.0f);
	
	return t;
}
Example #6
0
float GNoise::Noise(float vec[], int len)
{
	switch (len) 
	{
		case 0:
			return 0.;
		case 1:
			return Noise1(vec[0]);
		case 2:
			return Noise2(vec);
		default:
			return Noise3(vec);
	}
}
Example #7
0
float GNoise::Perlin_Noise_2D(float vec[2])
{
	int		terms    = m_iOctaves;
	float	freq   = m_fFrequency;
	float	result = 0.0f;
	float	amp = m_fAmplitude;  
	vec[0]*=m_fFrequency;

	vec[1]*=m_fFrequency;	for( int i=0; i<terms; i++ )
	{
		result += Noise2(vec)*amp;
		vec[0] *= 2.0f;
		vec[1] *= 2.0f;
		amp*=0.5f;
	}
	return result;
}
//----------------------------------------------------------------------------
float FvPerlinNoise::SumHarmonics2(const FvVector2& kVector,
	float fPersistence, float fFrequency, float fIterations)
{
	FvVector2 kCurrent(kVector);
	kCurrent *= fFrequency;
	FvVector2 kNormal(kVector);
	kNormal.Normalise();
	kNormal *= fFrequency;

	float fSum = 0.f;
	float fScale = 1.f;
	float i = 0.f;

	while (i < fIterations)
	{
		fSum += (fScale * Noise2(kCurrent));
		fScale *= fPersistence;
		kNormal += kNormal;
		i += 1.f;
		kCurrent += kNormal;
	}

	return fSum + 0.5f;
}
Example #9
0
float SmoothNoise2(int x, int y) {
	
	return  (Noise2(x-1, y-1) + Noise2(x+1, y-1) + Noise2(x-1, y+1) + Noise2(x+1, y+1)) / 16.0f + 
			(Noise2(x-1, y) + Noise2(x, y-1) + Noise2(x+1, y) + Noise2(x, y+1)) / 8.0f +
			Noise2(x, y) / 4.0f;
}
double
SVGFETurbulenceElement::Turbulence(int aColorChannel, double* aPoint,
                                   double aBaseFreqX, double aBaseFreqY,
                                   int aNumOctaves, bool aFractalSum,
                                   bool aDoStitching,
                                   double aTileX, double aTileY,
                                   double aTileWidth, double aTileHeight)
{
  StitchInfo stitch;
  StitchInfo *stitchInfo = NULL; // Not stitching when NULL.
  // Adjust the base frequencies if necessary for stitching.
  if (aDoStitching) {
    // When stitching tiled turbulence, the frequencies must be adjusted
    // so that the tile borders will be continuous.
    if (aBaseFreqX != 0.0) {
      double loFreq = double (floor(aTileWidth * aBaseFreqX)) / aTileWidth;
      double hiFreq = double (ceil(aTileWidth * aBaseFreqX)) / aTileWidth;
      if (aBaseFreqX / loFreq < hiFreq / aBaseFreqX)
        aBaseFreqX = loFreq;
      else
        aBaseFreqX = hiFreq;
    }
    if (aBaseFreqY != 0.0) {
      double loFreq = double (floor(aTileHeight * aBaseFreqY)) / aTileHeight;
      double hiFreq = double (ceil(aTileHeight * aBaseFreqY)) / aTileHeight;
      if (aBaseFreqY / loFreq < hiFreq / aBaseFreqY)
        aBaseFreqY = loFreq;
      else
        aBaseFreqY = hiFreq;
    }
    // Set up initial stitch values.
    stitchInfo = &stitch;
    stitch.mWidth = int (aTileWidth * aBaseFreqX + 0.5f);
    stitch.mWrapX = int (aTileX * aBaseFreqX + sPerlinN + stitch.mWidth);
    stitch.mHeight = int (aTileHeight * aBaseFreqY + 0.5f);
    stitch.mWrapY = int (aTileY * aBaseFreqY + sPerlinN + stitch.mHeight);
  }
  double sum = 0.0f;
  double vec[2];
  vec[0] = aPoint[0] * aBaseFreqX;
  vec[1] = aPoint[1] * aBaseFreqY;
  double ratio = 1;
  for (int octave = 0; octave < aNumOctaves; octave++) {
    if (aFractalSum)
      sum += double (Noise2(aColorChannel, vec, stitchInfo) / ratio);
    else
      sum += double (fabs(Noise2(aColorChannel, vec, stitchInfo)) / ratio);
    vec[0] *= 2;
    vec[1] *= 2;
    ratio *= 2;
    if (stitchInfo != NULL) {
      // Update stitch values. Subtracting sPerlinN before the multiplication
      // and adding it afterward simplifies to subtracting it once.
      stitch.mWidth *= 2;
      stitch.mWrapX = 2 * stitch.mWrapX - sPerlinN;
      stitch.mHeight *= 2;
      stitch.mWrapY = 2 * stitch.mWrapY - sPerlinN;
    }
  }
  return sum;
}
Example #11
0
inline double Smooth(int i, int j)
{
        return (double)(Noise2(i, j)+Noise2(i+1, j)+Noise2(i, j+1)+Noise2(i+1, j+1))/4;
}