Example #1
0
float
vsPerlinOctave::SmoothedNoise1D(int x)
{
	float sides   = (Noise1D(x-1) + Noise1D(x+1)) /  4.f;
	float center  =  Noise1D(x) / 2.f;
	return sides + center;
}
Example #2
0
//--------------------------------------------------------------------------------------
// Name: Turbulence1D() / Turbulence2D() / Turbulence3D()
// Desc: Perlin noise functions
//--------------------------------------------------------------------------------------
FLOAT32 CFrmPerlin::Turbulence1D( const FLOAT32 x,
                                  FLOAT32 fFrequency, UINT32 nNumOctaves,
                                  FLOAT32 fAmplitude, FLOAT32 fPersistence )
{
    FLOAT32 fTotal = 0.0f;

    for( UINT32 i=0; i<nNumOctaves; i++ )
    {
        fTotal += Noise1D( fFrequency * x ) * fAmplitude;
        fFrequency *= 2.0f;
        fAmplitude *= fPersistence;
    }
    
    return fTotal;
}
double terra::PerlinNoise::Noise1D(double X, unsigned int Octaves, double Persistence, double ScalingX){
	// Exit if there are no octaves to process
	if (Octaves == 0)
		return 0.;

	// Fancy math time!
	int TruncatedX = static_cast<int>(X);
	double Left = GetSmooth(TruncatedX);
	double Right = GetSmooth(TruncatedX+1);

	// Handle multiple octaves
	if (Octaves > 1)
		return (Interpolate(Left, Right, X-TruncatedX)+Persistence*Noise1D(ScalingX*X, Octaves-1, Persistence))/(1.+Persistence);
	else
		return Interpolate(Left, Right, X-TruncatedX);
}
Example #4
0
//--------------------------------------------------------------------------------------
// Name: TileableNoise1D() / TileableNoise2D() / TileableNoise3D()
// Desc: Tileable, interpolated noise functions
//--------------------------------------------------------------------------------------
FLOAT32 CFrmPerlin::TileableNoise1D(const FLOAT32 x, const FLOAT32 w)
{
    return( Noise1D( x     ) * ( w - x ) +
            Noise1D( x - w ) *       x   ) / w;
}
Example #5
0
/*
 * Looping 1D noise
 */
float Noise::LoopNoise1D(float x, float period)
{
    return ((period - x) * Noise1D(x) + x * Noise1D(period - x)) / period;
}
Example #6
0
/*************
 * DESCRIPTION:   draw star
 * INPUT:         line  address of current screen line
 *                col   color of flare (usually color of light source)
 *                sx    x coord. of center
 *                x,y   coord of pixel (relative to center of star !)
 * OUTPUT:        non
 *************/
void STAR::Draw(SMALL_COLOR *line, COLOR *col, int sx, int x, int y)
{
	float d, d2, intensity;
	float star;
	float Rf,Gf,Bf,redf,n, noiselevel;
	float R, G, B, r, dx;
	int h;

	intensity = 1.0f*255; // for future use
	noiselevel = 0.1f*noise;

	// Calc distance squared and distance, then
	// add d + d^2 to get the falloff function
	d2 = sqrt(x*x + y*y);
	d = ((d2 + d2*d2)*0.02f) / acc_sr;

	// The "Central Glow" falloff function is modified by the
	// "Red Outer Glow" in the inner part of the flare.
	redf = 1.0f/(1.0f + d*STAR_REDGLOWFALLOFF);
	Rf = STAR_FALLOFF + acc_starcolor.r*redf;
	Gf = STAR_FALLOFF + acc_starcolor.g*redf;
	Bf = STAR_FALLOFF + acc_starcolor.b*redf;
	R = 1.0f/(1.f + d*Rf);
	G = 1.0f/(1.f + d*Gf);
	B = 1.0f/(1.f + d*Bf);

	//R=G=B=0.0;
	if (flags & STAR_HALOENABLE)
	{
		// The red "Central Ring"
		if (d > acc_ihr && d < haloradius)
		{
			r = 2.0f*(d - acc_ihr)/(haloradius - acc_ihr);
			if (r > 1.0f)
				r = 2.0f - r;
			r = r*r*(3.f - 2.f*r);
			R += ringcolor.r*r;
			G += ringcolor.g*r;
			B += ringcolor.b*r;
		}
	}

	if (flags & STAR_ENABLE)
	{
		// Random streaks
		// Angle around flare in the range 0 to 2
#ifdef  __STORM__
		star = -newatan2(y, x);
#else
		star = -atan2(y, x);
#endif
		star -= tilt;
		if (star < 0.0f)
			star += 2.f*PI;
		h = (int)(((spikes*star)*INV_TWOPI) + 0.5f) % spikes;
		if (!(spikes % 2))
			star += PI/spikes;
		star = star*INV_PI;
		// Random noise with selectable frequency
		if (noise <= 1.0f)
			n = 1.0f;
		else
			n = Noise1D(star*noise);

		d *= 2.f/intensities[h];
		// Multiply by number of streaks and add in some noise
		star = star*spikes + n*noiselevel;
		// Get range 0 to 1 by reversing the range 1 to 2
		star = fmod(star, 2.0f);
		if (star >= 1.0f)
			star = 2.0f - star;
		// To get more sharply defined streaks, we square them
		// a couple of times
		star = star*star; star = star*star; //star = star*star;
		// Streaks are a maximum value divided by the falloff function,
		// but some noise is also multiplied in to lower the intensity
		// of some of them.
		star = star*(brightness*0.01f)/(1.f + d*2.0f)*n*n;
		if (star > 0.0f) // Until we fix the "negative" bug...
		{
			R += star;
			G += star;
			B += star;
		}
	}
	sx += x;

	dx = d2/acc_sr;
	if (dx < 1.0f)
	{
		dx *= dx;
		R = -R*dx + R;
		G = -G*dx + G;
		B = -B*dx + B;
	}
	else
		R = G = B = 0.0f;

	// Calculate and set RGB
	line[sx].r = clip(line[sx].r + intensity*R);
	line[sx].g = clip(line[sx].g + intensity*G);
	line[sx].b = clip(line[sx].b + intensity*B);
}
Example #7
0
double Noise2D (long x, long y)
{
return Noise1D (x + y * 57);
}
Example #8
0
double SmoothedNoise1D (long x)
{
return Noise1D (x) / 2  +  Noise1D (x-1) / 4  +  Noise1D (x+1) / 4;
}