FLOAT32 CFrmPerlin::TileableNoise3D(const FLOAT32 x, const FLOAT32 y, const FLOAT32 z, const FLOAT32 w, const FLOAT32 h, const FLOAT32 d) { return ( Noise3D( x, y, z ) * ( w - x ) * ( h - y ) * ( d - z ) + Noise3D( x - w, y, z ) * x * ( h - y ) * ( d - z ) + Noise3D( x, y - h, z ) * ( w - x ) * y * ( d - z ) + Noise3D( x - w, y - h, z ) * x * y * ( d - z ) + Noise3D( x, y, z - d ) * ( w - x ) * ( h - y ) * z + Noise3D( x - w, y, z - d ) * x * ( h - y ) * z + Noise3D( x, y - h, z - d ) * ( w - x ) * y * z + Noise3D( x - w, y - h, z - d ) * x * y * z ) / ( w * h * d ); }
ssfloat ExpMgr::Turbulence3D(ssfloat x, ssfloat y, ssfloat z) { ssfloat turb, s, limit; turb = -1.0; s = 1; limit = 1.0/256; while (s > limit) { turb += s * Noise3D(x/s,y/s,z/s); s /= 2; } return turb; }
FLOAT32 CFrmPerlin::Turbulence3D( const FLOAT32 x, const FLOAT32 y, const FLOAT32 z, FLOAT32 fFrequency, UINT32 nNumOctaves, FLOAT32 fAmplitude, FLOAT32 fPersistence ) { FLOAT32 fTotal = 0.0f; for( UINT32 i=0; i<nNumOctaves; i++ ) { fTotal += Noise3D( fFrequency * x, fFrequency * y, fFrequency * z ) * fAmplitude; fFrequency *= 2.0f; fAmplitude *= fPersistence; } return fTotal; }
float ValueNoise3D(float x, float y, float z, float amplitude, float wavelength, int octaves, float factor, int seed) { float sum = 0.0f; float range_adjust = 0.0f; float temp_amp = 1.0f; for(int i = 0; i < octaves; i ++) { sum += temp_amp * Noise3D(x / wavelength, y / wavelength, z / wavelength, seed); wavelength *= factor; temp_amp *= factor; range_adjust += temp_amp; } return amplitude * (sum / range_adjust); }
/* * Tileable 3D noise */ float Noise::TileNoise3D( float x, float y, float z, float width, float height, float depth) { float invX = width - x; float invY = height - y; float invZ = depth - z; return ( Noise3D(x, y, z) * invX * invY * invZ + Noise3D(invX, y, z) * x * invY * invZ + Noise3D(x, invY, z) * invX * y * invZ + Noise3D(x, y, invZ) * invX * invY * z + Noise3D(invX, invY, z) * x * y * invZ + Noise3D(invX, y, invZ) * x * invY * z + Noise3D(x, invY, invZ) * invX * y * z + Noise3D(invX, invY, invZ) * x * y * z ) / (width * height * depth); }
/* * Looping 3D noise */ float Noise::LoopNoise3D(float x, float y, float z, float zPeriod) { return ((zPeriod - z) * Noise3D(x,y,z) + z * Noise3D(x, y, zPeriod - z)) / zPeriod; }
void eval_noise(Expr *expr) { expr->l->fn(expr->l); expr->v.x = Noise3D(&expr->l->v); }