public static float noise( float x, float y, float z, float noiseSize, int noiseDepth, int noiseBasis, boolean isHard) { NoiseFunction abstractNoiseFunc = noiseFunctions.get(Integer.valueOf(noiseBasis)); if (abstractNoiseFunc == null) { abstractNoiseFunc = noiseFunctions.get(0); noiseBasis = 0; } if (noiseBasis == 0) { ++x; ++y; ++z; } if (noiseSize != 0.0) { noiseSize = 1.0f / noiseSize; x *= noiseSize; y *= noiseSize; z *= noiseSize; } float result = abstractNoiseFunc.execute(x, y, z); return isHard ? Math.abs(2.0f * result - 1.0f) : result; }
public static float turbulence( float x, float y, float z, float noiseSize, int noiseDepth, int noiseBasis, boolean isHard) { NoiseFunction abstractNoiseFunc = noiseFunctions.get(Integer.valueOf(noiseBasis)); if (abstractNoiseFunc == null) { abstractNoiseFunc = noiseFunctions.get(0); noiseBasis = 0; } if (noiseBasis == 0) { ++x; ++y; ++z; } if (noiseSize != 0.0) { noiseSize = 1.0f / noiseSize; x *= noiseSize; y *= noiseSize; z *= noiseSize; } float sum = 0, t, amp = 1, fscale = 1; for (int i = 0; i <= noiseDepth; ++i, amp *= 0.5, fscale *= 2) { t = abstractNoiseFunc.execute(fscale * x, fscale * y, fscale * z); if (isHard) { t = FastMath.abs(2.0f * t - 1.0f); } sum += t * amp; } sum *= (float) (1 << noiseDepth) / (float) ((1 << noiseDepth + 1) - 1); return sum; }