@Override public void setSeed(long seed) { typeNoiseGen = new WhiteNoise(seed + 1); }
@Override public void generateChunk(CoreChunk chunk, Region chunkRegion) { FloraFacet facet = chunkRegion.getFacet(FloraFacet.class); WhiteNoise noise = new WhiteNoise(chunk.getPosition().hashCode()); Map<BaseVector3i, FloraType> entries = facet.getRelativeEntries(); // check if some other rasterizer has already placed something here entries.keySet().stream().filter(pos -> chunk.getBlock(pos).equals(air)).forEach(pos -> { FloraType type = entries.get(pos); List<Block> list = flora.get(type); int blockIdx = Math.abs(noise.intNoise(pos.x(), pos.y(), pos.z())) % list.size(); Block block = list.get(blockIdx); chunk.setBlock(pos, block); }); } }
@Test public void testDistribution() { FastRandom rng = new FastRandom(0xBEEF); WhiteNoise noiseGen = new WhiteNoise(0xDEADC0DE); float posZ = rng.nextFloat() * 100f; float noise = 0.5f + 0.5f * noiseGen.noise(posX, posY, posZ); int idx = (int) (noise * bucketCount); if (idx == bucketCount) {
/** * @param x and integer value * @return a random, but deterministic float value in [-1..1] */ public float noise(int x) { float noise = intNoise(x); return noise / Integer.MAX_VALUE; }
/** * @param x any float value * @return a random, but deterministic float value in [-1..1] */ public float noise(float x) { // the floatToIntBits conversion messes with the coords // this is ok, because white noise is invariant to position int fx = Float.floatToIntBits(x); return noise(fx); }
@Override public float noise(float x, float y) { // the floatToIntBits conversion messes with the coords // this is ok, because white noise is invariant to position int fx = Float.floatToIntBits(x); int fy = Float.floatToIntBits(y); return noise(fx, fy); }
@Override public void setSeed(long seed) { super.setSeed(seed); densityNoiseGen = new WhiteNoise(seed); }
@Override public float noise(float x, float y, float z) { // the floatToIntBits conversion messes with the coords // this is ok, because white noise is invariant to position int fx = Float.floatToIntBits(x); int fy = Float.floatToIntBits(y); int fz = Float.floatToIntBits(z); return noise(fx, fy, fz); }
@Override public void setSeed(long seed) { super.setSeed(seed); densityNoiseGen = new WhiteNoise(seed); }
@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)} }); }