create PositiveWhiteNoiseSampler

This commit is contained in:
dfsek
2021-12-15 19:52:36 -07:00
parent 3d5b23d0f5
commit 7a935e10f0

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.noise.samplers.noise.random;
import com.dfsek.terra.addons.noise.samplers.noise.NoiseFunction;
/**
* NoiseSampler implementation to produce random, uniformly distributed (white) noise.
*/
public class PositiveWhiteNoiseSampler extends WhiteNoiseSampler {
private static final long POSITIVE_POW1 = 0b01111111111L << 52;
// Bits that when applied to the exponent/sign section of a double, produce a positive number with a power of 1.
public double getNoiseRaw(long seed) {
return (Double.longBitsToDouble((murmur64(seed) & 0x000fffffffffffffL) | POSITIVE_POW1) - 1.5) * 2;
}
@Override
public double getNoiseRaw(long seed, double x, double y) {
return (getNoiseUnmapped(seed, x, y) - 1);
}
@Override
public double getNoiseRaw(long seed, double x, double y, double z) {
return (getNoiseUnmapped(seed, x, y, z) - 1);
}
}