private void updateWeights() { // recompute weights eagerly spectralWeights = new float[octaves]; for (int i = 0; i < octaves; i++) { spectralWeights[i] = (float) Math.pow(lacunarity, -persistence * i); } scale = computeScale(spectralWeights); } }
/** * Returns Fractional Brownian Motion at the given position. * * @param x Position on the x-axis * @param y Position on the y-axis * @param z Position on the z-axis * @return The noise value in the range of the base noise function */ @Override public float noise(float x, float y, float z) { float result = 0.0f; float workingX = x; float workingY = y; float workingZ = z; for (int i = 0; i < getOctaves(); i++) { result += other.noise(workingX, workingY, workingZ) * spectralWeights[i]; workingX *= (float) getLacunarity(); workingY *= (float) getLacunarity(); workingZ *= (float) getLacunarity(); } return result * scale; }
/** * @param other other the noise to use as a basis * @param octaves the number of octaves to use */ public BrownianNoise(Noise other, int octaves) { this.other = other; setOctaves(octaves); }
/** * @param min the minimum thickness for the layer * @param max the maximum thickness for the layer */ public MinMaxLayerThickness(int min, int max) { //TODO: make sure that layers at different heights have different noise super(seed -> new BrownianNoise(new SimplexNoise(seed), 2)); this.min = min; this.max = max; }
/** * @param octaves the number of octaves used for computation */ public void setOctaves(int octaves) { this.octaves = octaves; updateWeights(); }
@Override public void setSeed(long seed) { // TODO: reduce the number of octaves in BrownianNoise mountainNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 3)), new Vector2f(0.0002f, 0.0002f), 4); hillNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 4)), new Vector2f(0.0008f, 0.0008f), 4); }
/** * Persistence is what makes the amplitude shrink. * More precisely the amplitude of octave i = lacunarity^(-persistence * i) * @param persistence the persistence to set */ public void setPersistence(double persistence) { this.persistence = persistence; updateWeights(); }
@Override public void setSeed(long seed) { oceanNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 1), 8), new Vector2f(0.0009f, 0.0009f), SAMPLE_RATE); }
/** * Returns Fractional Brownian Motion at the given position. * * @param x Position on the x-axis * @param y Position on the y-axis * @return The noise value in the range of the base noise function */ @Override public float noise(float x, float y) { float result = 0.0f; float workingX = x; float workingY = y; for (int i = 0; i < getOctaves(); i++) { result += other.noise(workingX, workingY) * spectralWeights[i]; workingX *= (float) getLacunarity(); workingY *= (float) getLacunarity(); } return result * scale; }
@Override public void setSeed(long seed) { temperatureNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 5), 8), new Vector2f(0.0005f, 0.0005f), SAMPLE_RATE); }
@Override public void setSeed(long seed) { riverNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 2), 8), new Vector2f(0.0008f, 0.0008f), SAMPLE_RATE); }
private void reload() { float realScale = config.scale * 0.01f; Vector2f scale = new Vector2f(realScale, realScale); BrownianNoise brown = new BrownianNoise(new PerlinNoise(seed + 6), config.octaves); humidityNoise = new SubSampledNoise(brown, scale, SAMPLE_RATE); }
@Override public void setSeed(long seed) { BrownianNoise source = new BrownianNoise(new PerlinNoise(seed), 8); surfaceNoise = new SubSampledNoise(source, new Vector2f(0.004f, 0.004f), SAMPLE_RATE); }
@Parameters(name = "{0}") public static Collection<Noise[]> data() { return Arrays.asList(new Noise[][]{ {new WhiteNoise(0xCAFE)}, {new DiscreteWhiteNoise(0xCAFE)}, {new SimplexNoise(0xCAFE)}, {new PerlinNoise(0xCAFE)}, {new BrownianNoise(new WhiteNoise(0xCAFE), 3)} }); }