float PerlinNoise::InterpolatedNoise( float x ) { int IntX = (int)x; float FraqX = x - IntX; float v1 = SmoothNoise( IntX ); float v2 = SmoothNoise( IntX + 1 ); return CosineInterpolation( v1, v2, FraqX ); }
float Noise::Turbulance(float x, float y, float z, float size) { float value = 0.0f; float initial_size = size; //std::vector<std::thread*> threads; //while (size >= 1) //{ // threads.push_back(new std::thread(&Noise::ThreadSmoothNoise,this, x, y, z, size, &value)); // size /= 2.0; //} //for (int i = 0; i < threads.size(); i++) //{ // threads[i]->join(); //} //for (int y = 0; y < NOISE_HEIGHT; y++) //{ // smooth_farm_.AddTask(new NoiseSmoothtask(x, y, z, size, &value, this)); //} //smooth_farm_.Run(); while (size >= 1) { value += SmoothNoise(x / size, y / size, z / size) * size; size /= 2.0; } return(128.0f * value / initial_size); }
float PerlinNoise::InterpolatedNoise(float x, float y, int i) { int integerX = (int)x; float fractionalX = x - integerX; int integerY = (int)y; float fractionalY = y - integerY; float v1 = SmoothNoise(integerX, integerY,i); float v2 = SmoothNoise(integerX + 1, integerY,i); float v3 = SmoothNoise(integerX, integerY + 1,i); float v4 = SmoothNoise(integerX + 1, integerY + 1,i); float i1 = Interpolate(v1 , v2 , fractionalX); float i2 = Interpolate(v3 , v4 , fractionalX); return Interpolate(i1 , i2 , fractionalY); }
float InterpolatedNoise(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 = SmoothNoise(integer_X, integer_Y); float v2 = SmoothNoise(integer_X + 1, integer_Y); float v3 = SmoothNoise(integer_X, integer_Y + 1); float v4 = SmoothNoise(integer_X + 1, integer_Y + 1); float i1 = Linear_Interpolate(v1 , v2 , fractional_X); float i2 = Linear_Interpolate(v3 , v4 , fractional_X); return Linear_Interpolate(i1 , i2 , fractional_Y); }
void Noise::ThreadSmoothNoise(float x, float y, float z, float size, float* value) { *value += SmoothNoise(x / size, y / size, z / size) * size; }