mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-22 16:18:32 +00:00
Reformat
This commit is contained in:
@@ -9,17 +9,46 @@ package com.dfsek.terra.addons.noise;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.addons.noise.config.CubicSplinePointTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
|
||||
import com.dfsek.terra.addons.noise.config.templates.*;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.*;
|
||||
import com.dfsek.terra.addons.noise.config.templates.BinaryArithmeticTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.DerivativeNoiseSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.DomainWarpTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.FunctionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.ImageSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.KernelTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.LinearHeightmapSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.TranslateSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.CellularNoiseTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.ConstantNoiseTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.DistanceSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.ExpressionFunctionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.GaborNoiseTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.PseudoErosionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.SimpleNoiseTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.fractal.BrownianMotionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.fractal.PingPongTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.fractal.RidgedFractalTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.*;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ClampNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.CubicSplineNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ExpressionNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.LinearNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.NormalNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.PosterizationNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ProbabilityNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ScaleNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.math.CubicSpline;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.*;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.AdditionSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.DivisionSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.MaxSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.MinSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.MultiplicationSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.SubtractionSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.CellularSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.DistanceSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.random.GaussianNoiseSampler;
|
||||
@@ -41,10 +70,6 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class NoiseAddon implements AddonInitializer {
|
||||
public static final TypeKey<Supplier<ObjectTemplate<NoiseSampler>>> NOISE_SAMPLER_TOKEN = new TypeKey<>() {
|
||||
@@ -97,7 +122,7 @@ public class NoiseAddon implements AddonInitializer {
|
||||
noiseRegistry.register(addon.key("SIMPLEX"), () -> new SimpleNoiseTemplate(SimplexSampler::new));
|
||||
noiseRegistry.register(addon.key("GABOR"), GaborNoiseTemplate::new);
|
||||
noiseRegistry.register(addon.key("PSEUDOEROSION"), PseudoErosionTemplate::new);
|
||||
|
||||
|
||||
noiseRegistry.register(addon.key("VALUE"), () -> new SimpleNoiseTemplate(ValueSampler::new));
|
||||
noiseRegistry.register(addon.key("VALUE_CUBIC"), () -> new SimpleNoiseTemplate(ValueCubicSampler::new));
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
|
||||
import com.dfsek.terra.addons.noise.config.templates.FunctionTemplate;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class NoiseConfigPackTemplate implements ConfigTemplate, Properties {
|
||||
|
||||
@@ -14,7 +14,8 @@ public class DerivativeNoiseSamplerTemplate extends SamplerTemplate<DerivativeNo
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if (!DerivativeNoiseSampler.isDifferentiable(sampler)) throw new ValidationException("Provided sampler does not support calculating a derivative");
|
||||
if(!DerivativeNoiseSampler.isDifferentiable(sampler)) throw new ValidationException(
|
||||
"Provided sampler does not support calculating a derivative");
|
||||
return super.validate();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,16 +8,15 @@
|
||||
package com.dfsek.terra.addons.noise.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.ImageSampler;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.ImageSampler;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
|
||||
public class ImageSamplerTemplate extends SamplerTemplate<ImageSampler> {
|
||||
|
||||
@@ -10,60 +10,47 @@ import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
|
||||
public class PseudoErosionTemplate extends NoiseTemplate<PseudoErosionSampler> {
|
||||
|
||||
@Value("octaves")
|
||||
@Default
|
||||
private int octaves = 4;
|
||||
|
||||
@Value("lacunarity")
|
||||
@Default
|
||||
private double lacunarity = 2.0;
|
||||
|
||||
@Value("gain")
|
||||
@Default
|
||||
private double gain = 0.5;
|
||||
|
||||
@Value("slope-strength")
|
||||
@Default
|
||||
private double slopeStrength = 1.0;
|
||||
|
||||
@Value("branch-strength")
|
||||
@Default
|
||||
private double branchStrength = 1.0;
|
||||
|
||||
@Value("strength")
|
||||
@Default
|
||||
private double strength = 0.04;
|
||||
|
||||
@Value("erosion-frequency")
|
||||
@Default
|
||||
private double erosionFrequency = 0.02;
|
||||
|
||||
@Value("sampler")
|
||||
private DerivativeNoiseSampler heightSampler;
|
||||
|
||||
@Value("slope-mask.enable")
|
||||
@Default
|
||||
private boolean slopeMask = true;
|
||||
|
||||
@Value("slope-mask.none")
|
||||
@Default
|
||||
private double slopeMaskNone = -0.5;
|
||||
|
||||
@Value("slope-mask.full")
|
||||
@Default
|
||||
private double slopeMaskFull = 1;
|
||||
|
||||
@Value("jitter")
|
||||
@Default
|
||||
private double jitterModifier = 1;
|
||||
|
||||
@Value("average-impulses")
|
||||
@Default
|
||||
private boolean averageErosionImpulses = true;
|
||||
|
||||
@Value("frequency")
|
||||
@Default
|
||||
protected @Meta double frequency = 1d;
|
||||
@Value("octaves")
|
||||
@Default
|
||||
private int octaves = 4;
|
||||
@Value("lacunarity")
|
||||
@Default
|
||||
private double lacunarity = 2.0;
|
||||
@Value("gain")
|
||||
@Default
|
||||
private double gain = 0.5;
|
||||
@Value("slope-strength")
|
||||
@Default
|
||||
private double slopeStrength = 1.0;
|
||||
@Value("branch-strength")
|
||||
@Default
|
||||
private double branchStrength = 1.0;
|
||||
@Value("strength")
|
||||
@Default
|
||||
private double strength = 0.04;
|
||||
@Value("erosion-frequency")
|
||||
@Default
|
||||
private double erosionFrequency = 0.02;
|
||||
@Value("sampler")
|
||||
private DerivativeNoiseSampler heightSampler;
|
||||
@Value("slope-mask.enable")
|
||||
@Default
|
||||
private boolean slopeMask = true;
|
||||
@Value("slope-mask.none")
|
||||
@Default
|
||||
private double slopeMaskNone = -0.5;
|
||||
@Value("slope-mask.full")
|
||||
@Default
|
||||
private double slopeMaskFull = 1;
|
||||
@Value("jitter")
|
||||
@Default
|
||||
private double jitterModifier = 1;
|
||||
@Value("average-impulses")
|
||||
@Default
|
||||
private boolean averageErosionImpulses = true;
|
||||
|
||||
@Override
|
||||
public PseudoErosionSampler get() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.addons.noise.samplers.noise;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
|
||||
|
||||
public abstract class DerivativeNoiseFunction extends NoiseFunction implements DerivativeNoiseSampler {
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
|
||||
@@ -9,12 +9,12 @@ public class PseudoErosionSampler extends NoiseFunction {
|
||||
public static final float TAU = (float) (2.0 * Math.PI);
|
||||
private static final float HASH_X = 0.3183099f;
|
||||
private static final float HASH_Y = 0.3678794f;
|
||||
private final int octaves;
|
||||
public final double gain;
|
||||
public final double lacunarity;
|
||||
public final double slopeStrength;
|
||||
public final double branchStrength;
|
||||
public final double erosionStrength;
|
||||
private final int octaves;
|
||||
private final double erosionFrequency;
|
||||
private final DerivativeNoiseSampler sampler;
|
||||
private final boolean slopeMask;
|
||||
@@ -25,7 +25,8 @@ public class PseudoErosionSampler extends NoiseFunction {
|
||||
private final double maxCellDistSqRecip;
|
||||
private final boolean averageErosionImpulses;
|
||||
|
||||
public PseudoErosionSampler(int octaves, double gain, double lacunarity, double slopeStrength, double branchStrength, double erosionStrength, double erosionFrequency, DerivativeNoiseSampler sampler,
|
||||
public PseudoErosionSampler(int octaves, double gain, double lacunarity, double slopeStrength, double branchStrength,
|
||||
double erosionStrength, double erosionFrequency, DerivativeNoiseSampler sampler,
|
||||
boolean slopeMask, double slopeMaskFull, double slopeMaskNone, double jitterModifier,
|
||||
boolean averageErosionImpulses) {
|
||||
this.octaves = octaves;
|
||||
@@ -59,41 +60,7 @@ public class PseudoErosionSampler extends NoiseFunction {
|
||||
}
|
||||
|
||||
public static float fract(float x) {
|
||||
return (x - (float)Math.floor(x));
|
||||
}
|
||||
|
||||
public float[] erosion(int seed, float x, float y, float dirX, float dirY) {
|
||||
int gridX = Math.round(x);
|
||||
int gridY = Math.round(y);
|
||||
float noise = 0.0f;
|
||||
float dirOutX = 0.0f;
|
||||
float dirOutY = 0.0f;
|
||||
float cumAmp = 0.0f;
|
||||
|
||||
for (int cellX = gridX - 1; cellX <= gridX + 1; cellX++) {
|
||||
for (int cellY = gridY - 1; cellY <= gridY + 1; cellY++) {
|
||||
float cellHash = hash(seed, cellX, cellY);
|
||||
float cellOffsetX = (float) (hashX(seed, cellHash) * jitter);
|
||||
float cellOffsetY = (float) (hashY(seed, cellHash) * jitter);
|
||||
float cellOriginDeltaX = (x - cellX) + cellOffsetX;
|
||||
float cellOriginDeltaY = (y - cellY) + cellOffsetY;
|
||||
float cellOriginDistSq = cellOriginDeltaX * cellOriginDeltaX + cellOriginDeltaY * cellOriginDeltaY;
|
||||
if (cellOriginDistSq > maxCellDistSq) continue; // Skip calculating cells too far away
|
||||
float ampTmp = (float) ((cellOriginDistSq * maxCellDistSqRecip) - 1); float amp = ampTmp * ampTmp; // Decrease cell amplitude further away
|
||||
cumAmp += amp;
|
||||
float directionalStrength = dot(cellOriginDeltaX, cellOriginDeltaY, dirX, dirY) * TAU;
|
||||
noise += (float) (MathUtil.cos(directionalStrength) * amp);
|
||||
float sinAngle = (float) MathUtil.sin(directionalStrength) * amp;
|
||||
dirOutX -= sinAngle * (cellOriginDeltaX + dirX);
|
||||
dirOutY -= sinAngle * (cellOriginDeltaY + dirY);
|
||||
}
|
||||
}
|
||||
if (averageErosionImpulses && cumAmp != 0) {
|
||||
noise /= cumAmp;
|
||||
dirOutX /= cumAmp;
|
||||
dirOutY /= cumAmp;
|
||||
}
|
||||
return new float[] {noise, dirOutX, dirOutY};
|
||||
return (x - (float) Math.floor(x));
|
||||
}
|
||||
|
||||
public static float smoothstep(float edge0, float edge1, float x) {
|
||||
@@ -107,6 +74,45 @@ public class PseudoErosionSampler extends NoiseFunction {
|
||||
return Math.max(minVal, Math.min(maxVal, x));
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float x2, float y2) {
|
||||
return x1 * x2 + y1 * y2;
|
||||
}
|
||||
|
||||
public float[] erosion(int seed, float x, float y, float dirX, float dirY) {
|
||||
int gridX = Math.round(x);
|
||||
int gridY = Math.round(y);
|
||||
float noise = 0.0f;
|
||||
float dirOutX = 0.0f;
|
||||
float dirOutY = 0.0f;
|
||||
float cumAmp = 0.0f;
|
||||
|
||||
for(int cellX = gridX - 1; cellX <= gridX + 1; cellX++) {
|
||||
for(int cellY = gridY - 1; cellY <= gridY + 1; cellY++) {
|
||||
float cellHash = hash(seed, cellX, cellY);
|
||||
float cellOffsetX = (float) (hashX(seed, cellHash) * jitter);
|
||||
float cellOffsetY = (float) (hashY(seed, cellHash) * jitter);
|
||||
float cellOriginDeltaX = (x - cellX) + cellOffsetX;
|
||||
float cellOriginDeltaY = (y - cellY) + cellOffsetY;
|
||||
float cellOriginDistSq = cellOriginDeltaX * cellOriginDeltaX + cellOriginDeltaY * cellOriginDeltaY;
|
||||
if(cellOriginDistSq > maxCellDistSq) continue; // Skip calculating cells too far away
|
||||
float ampTmp = (float) ((cellOriginDistSq * maxCellDistSqRecip) - 1);
|
||||
float amp = ampTmp * ampTmp; // Decrease cell amplitude further away
|
||||
cumAmp += amp;
|
||||
float directionalStrength = dot(cellOriginDeltaX, cellOriginDeltaY, dirX, dirY) * TAU;
|
||||
noise += (float) (MathUtil.cos(directionalStrength) * amp);
|
||||
float sinAngle = (float) MathUtil.sin(directionalStrength) * amp;
|
||||
dirOutX -= sinAngle * (cellOriginDeltaX + dirX);
|
||||
dirOutY -= sinAngle * (cellOriginDeltaY + dirY);
|
||||
}
|
||||
}
|
||||
if(averageErosionImpulses && cumAmp != 0) {
|
||||
noise /= cumAmp;
|
||||
dirOutX /= cumAmp;
|
||||
dirOutY /= cumAmp;
|
||||
}
|
||||
return new float[]{ noise, dirOutX, dirOutY };
|
||||
}
|
||||
|
||||
public float heightMap(long seed, float x, float y) {
|
||||
double[] sample = sampler.noised(seed, x, y);
|
||||
float height = (float) sample[0];
|
||||
@@ -125,7 +131,7 @@ public class PseudoErosionSampler extends NoiseFunction {
|
||||
float freq = 1.0f;
|
||||
|
||||
// Stack erosion octaves
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
float[] erosionResult = erosion((int) seed,
|
||||
x * freq * (float) erosionFrequency,
|
||||
y * freq * (float) erosionFrequency,
|
||||
@@ -139,7 +145,6 @@ public class PseudoErosionSampler extends NoiseFunction {
|
||||
freq *= lacunarity;
|
||||
}
|
||||
|
||||
// TODO - Test different output ranges, see how they affect visuals
|
||||
// Normalize erosion noise
|
||||
erosion /= cumAmp;
|
||||
// [-1, 1] -> [0, 1]
|
||||
@@ -147,7 +152,7 @@ public class PseudoErosionSampler extends NoiseFunction {
|
||||
|
||||
// Without masking, erosion noise in areas with small gradients tend to produce mounds,
|
||||
// this reduces erosion amplitude towards smaller gradients to avoid this
|
||||
if (slopeMask) {
|
||||
if(slopeMask) {
|
||||
float dirMagSq = dot(baseDirX, baseDirY, baseDirX, baseDirY);
|
||||
float flatness = smoothstep((float) slopeMaskNoneSq, (float) slopeMaskFullSq, dirMagSq);
|
||||
erosion *= flatness;
|
||||
@@ -156,10 +161,6 @@ public class PseudoErosionSampler extends NoiseFunction {
|
||||
return (float) (height + erosion * erosionStrength);
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float x2, float y2) {
|
||||
return x1 * x2 + y1 * y2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoiseRaw(long seed, double x, double y) {
|
||||
return heightMap(seed, (float) x, (float) y);
|
||||
|
||||
@@ -276,6 +276,7 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler {
|
||||
|
||||
return value * 9.046026385208288;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return true;
|
||||
@@ -283,173 +284,174 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler {
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
// 2D OpenSimplex2S case is a modified 2D simplex noise.
|
||||
int seed = (int) sl;
|
||||
// 2D OpenSimplex2S case is a modified 2D simplex noise.
|
||||
|
||||
final double SQRT3 = 1.7320508075688772935274463415059;
|
||||
final double G2 = (3 - SQRT3) / 6;
|
||||
final double SQRT3 = 1.7320508075688772935274463415059;
|
||||
final double G2 = (3 - SQRT3) / 6;
|
||||
|
||||
final double F2 = 0.5f * (SQRT3 - 1);
|
||||
double s = (x + y) * F2;
|
||||
x += s;
|
||||
y += s;
|
||||
final double F2 = 0.5f * (SQRT3 - 1);
|
||||
double s = (x + y) * F2;
|
||||
x += s;
|
||||
y += s;
|
||||
|
||||
|
||||
int i = (int) Math.floor(x);
|
||||
int j = (int) Math.floor(y);
|
||||
double xi = x - i;
|
||||
double yi = y - j;
|
||||
int i = (int) Math.floor(x);
|
||||
int j = (int) Math.floor(y);
|
||||
double xi = x - i;
|
||||
double yi = y - j;
|
||||
|
||||
i *= PRIME_X;
|
||||
j *= PRIME_Y;
|
||||
int i1 = i + PRIME_X;
|
||||
int j1 = j + PRIME_Y;
|
||||
i *= PRIME_X;
|
||||
j *= PRIME_Y;
|
||||
int i1 = i + PRIME_X;
|
||||
int j1 = j + PRIME_Y;
|
||||
|
||||
double t = (xi + yi) * G2;
|
||||
double x0 = xi - t;
|
||||
double y0 = yi - t;
|
||||
double t = (xi + yi) * G2;
|
||||
double x0 = xi - t;
|
||||
double y0 = yi - t;
|
||||
|
||||
double[] out = { 0.0f, 0.0f, 0.0f };
|
||||
double[] out = { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
double a0 = (2.0 / 3.0) - x0 * x0 - y0 * y0;
|
||||
double aa0 = a0 * a0, aaa0 = aa0 * a0, aaaa0 = aa0 * aa0;
|
||||
int gi0 = gradCoordIndex(seed, i, j);
|
||||
double gx0 = GRADIENTS_2_D[gi0], gy0 = GRADIENTS_2_D[gi0 | 1];
|
||||
double rampValue0 = gx0 * x0 + gy0 * y0;
|
||||
out[0] = aaaa0 * rampValue0;
|
||||
out[1] = gx0 * aaaa0 - 8 * rampValue0 * aaa0 * x0;
|
||||
out[2] = gy0 * aaaa0 - 8 * rampValue0 * aaa0 * y0;
|
||||
double a0 = (2.0 / 3.0) - x0 * x0 - y0 * y0;
|
||||
double aa0 = a0 * a0, aaa0 = aa0 * a0, aaaa0 = aa0 * aa0;
|
||||
int gi0 = gradCoordIndex(seed, i, j);
|
||||
double gx0 = GRADIENTS_2_D[gi0], gy0 = GRADIENTS_2_D[gi0 | 1];
|
||||
double rampValue0 = gx0 * x0 + gy0 * y0;
|
||||
out[0] = aaaa0 * rampValue0;
|
||||
out[1] = gx0 * aaaa0 - 8 * rampValue0 * aaa0 * x0;
|
||||
out[2] = gy0 * aaaa0 - 8 * rampValue0 * aaa0 * y0;
|
||||
|
||||
|
||||
double a1 = 2 * (1 - 2 * G2) * (1 / G2 - 2) * t + ((-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a0);
|
||||
double x1 = x0 - (1 - 2 * G2);
|
||||
double y1 = y0 - (1 - 2 * G2);
|
||||
double aa1 = a1 * a1, aaa1 = aa1 * a1, aaaa1 = aa1 * aa1;
|
||||
int gi1 = gradCoordIndex(seed, i1, j1);
|
||||
double gx1 = GRADIENTS_2_D[gi1], gy1 = GRADIENTS_2_D[gi1 | 1];
|
||||
double rampValue1 = gx1 * x1 + gy1 * y1;
|
||||
out[0] += aaaa1 * rampValue1;
|
||||
out[1] += gx1 * aaaa1 - 8 * rampValue1 * aaa1 * x1;
|
||||
out[2] += gy1 * aaaa1 - 8 * rampValue1 * aaa1 * y1;
|
||||
|
||||
double a1 = 2 * (1 - 2 * G2) * (1 / G2 - 2) * t + ((-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a0);
|
||||
double x1 = x0 - (1 - 2 * G2);
|
||||
double y1 = y0 - (1 - 2 * G2);
|
||||
double aa1 = a1 * a1, aaa1 = aa1 * a1, aaaa1 = aa1 * aa1;
|
||||
int gi1 = gradCoordIndex(seed, i1, j1);
|
||||
double gx1 = GRADIENTS_2_D[gi1], gy1 = GRADIENTS_2_D[gi1 | 1];
|
||||
double rampValue1 = gx1 * x1 + gy1 * y1;
|
||||
out[0] += aaaa1 * rampValue1;
|
||||
out[1] += gx1 * aaaa1 - 8 * rampValue1 * aaa1 * x1;
|
||||
out[2] += gy1 * aaaa1 - 8 * rampValue1 * aaa1 * y1;
|
||||
|
||||
// Nested conditionals were faster than compact bit logic/arithmetic.
|
||||
double xmyi = xi - yi;
|
||||
if(t > G2) {
|
||||
if(xi + xmyi > 1) {
|
||||
double x2 = x0 + (3 * G2 - 2);
|
||||
double y2 = y0 + (3 * G2 - 1);
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i + (PRIME_X << 1), j + PRIME_Y);
|
||||
double gx2 = GRADIENTS_2_D[gi2 | 0], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
} else {
|
||||
double x2 = x0 + G2;
|
||||
double y2 = y0 + (G2 - 1);
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i, j + PRIME_Y);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
}
|
||||
|
||||
if(yi - xmyi > 1) {
|
||||
double x3 = x0 + (3 * G2 - 1);
|
||||
double y3 = y0 + (3 * G2 - 2);
|
||||
double a3 = (2.0 / 3.0) - x3 * x3 - y3 * y3;
|
||||
if(a3 > 0) {
|
||||
double aa3 = a3 * a3, aaa3 = aa3 * a3, aaaa3 = aa3 * aa3;
|
||||
int gi3 = gradCoordIndex(seed, i + PRIME_X, j + (PRIME_Y << 1));
|
||||
double gx3 = GRADIENTS_2_D[gi3], gy3 = GRADIENTS_2_D[gi3 | 1];
|
||||
double rampValue3 = gx3 * x3 + gy3 * y3;
|
||||
out[0] += aaaa3 * rampValue3;
|
||||
out[1] += gx3 * aaaa3 - 8 * rampValue3 * aaa3 * x3;
|
||||
out[2] += gy3 * aaaa3 - 8 * rampValue3 * aaa3 * y3;
|
||||
}
|
||||
} else {
|
||||
double x3 = x0 + (G2 - 1);
|
||||
double y3 = y0 + G2;
|
||||
double a3 = (2.0 / 3.0) - x3 * x3 - y3 * y3;
|
||||
if(a3 > 0) {
|
||||
double aa3 = a3 * a3, aaa3 = aa3 * a3, aaaa3 = aa3 * aa3;
|
||||
int gi3 = gradCoordIndex(seed, i + PRIME_X, j);
|
||||
double gx3 = GRADIENTS_2_D[gi3], gy3 = GRADIENTS_2_D[gi3 | 1];
|
||||
double rampValue3 = gx3 * x3 + gy3 * y3;
|
||||
out[0] += aaaa3 * rampValue3;
|
||||
out[1] += gx3 * aaaa3 - 8 * rampValue3 * aaa3 * x3;
|
||||
out[2] += gy3 * aaaa3 - 8 * rampValue3 * aaa3 * y3;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(xi + xmyi < 0) {
|
||||
double x2 = x0 + (1 - G2);
|
||||
double y2 = y0 - G2;
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i - PRIME_X, j);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2; }
|
||||
} else {
|
||||
double x2 = x0 + (G2 - 1);
|
||||
double y2 = y0 + G2;
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i + PRIME_X, j);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
}
|
||||
|
||||
if(yi < xmyi) {
|
||||
double x2 = x0 - G2;
|
||||
double y2 = y0 - (G2 - 1);
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i, j - PRIME_Y);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2; }
|
||||
} else {
|
||||
double x2 = x0 + G2;
|
||||
double y2 = y0 + (G2 - 1);
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i, j + PRIME_Y);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
}
|
||||
// Nested conditionals were faster than compact bit logic/arithmetic.
|
||||
double xmyi = xi - yi;
|
||||
if(t > G2) {
|
||||
if(xi + xmyi > 1) {
|
||||
double x2 = x0 + (3 * G2 - 2);
|
||||
double y2 = y0 + (3 * G2 - 1);
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i + (PRIME_X << 1), j + PRIME_Y);
|
||||
double gx2 = GRADIENTS_2_D[gi2 | 0], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
out[0] *= 18.24196194486065;
|
||||
out[1] *= 18.24196194486065;
|
||||
out[2] *= 18.24196194486065;
|
||||
return out;
|
||||
} else {
|
||||
double x2 = x0 + G2;
|
||||
double y2 = y0 + (G2 - 1);
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i, j + PRIME_Y);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
}
|
||||
|
||||
if(yi - xmyi > 1) {
|
||||
double x3 = x0 + (3 * G2 - 1);
|
||||
double y3 = y0 + (3 * G2 - 2);
|
||||
double a3 = (2.0 / 3.0) - x3 * x3 - y3 * y3;
|
||||
if(a3 > 0) {
|
||||
double aa3 = a3 * a3, aaa3 = aa3 * a3, aaaa3 = aa3 * aa3;
|
||||
int gi3 = gradCoordIndex(seed, i + PRIME_X, j + (PRIME_Y << 1));
|
||||
double gx3 = GRADIENTS_2_D[gi3], gy3 = GRADIENTS_2_D[gi3 | 1];
|
||||
double rampValue3 = gx3 * x3 + gy3 * y3;
|
||||
out[0] += aaaa3 * rampValue3;
|
||||
out[1] += gx3 * aaaa3 - 8 * rampValue3 * aaa3 * x3;
|
||||
out[2] += gy3 * aaaa3 - 8 * rampValue3 * aaa3 * y3;
|
||||
}
|
||||
} else {
|
||||
double x3 = x0 + (G2 - 1);
|
||||
double y3 = y0 + G2;
|
||||
double a3 = (2.0 / 3.0) - x3 * x3 - y3 * y3;
|
||||
if(a3 > 0) {
|
||||
double aa3 = a3 * a3, aaa3 = aa3 * a3, aaaa3 = aa3 * aa3;
|
||||
int gi3 = gradCoordIndex(seed, i + PRIME_X, j);
|
||||
double gx3 = GRADIENTS_2_D[gi3], gy3 = GRADIENTS_2_D[gi3 | 1];
|
||||
double rampValue3 = gx3 * x3 + gy3 * y3;
|
||||
out[0] += aaaa3 * rampValue3;
|
||||
out[1] += gx3 * aaaa3 - 8 * rampValue3 * aaa3 * x3;
|
||||
out[2] += gy3 * aaaa3 - 8 * rampValue3 * aaa3 * y3;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(xi + xmyi < 0) {
|
||||
double x2 = x0 + (1 - G2);
|
||||
double y2 = y0 - G2;
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i - PRIME_X, j);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
} else {
|
||||
double x2 = x0 + (G2 - 1);
|
||||
double y2 = y0 + G2;
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i + PRIME_X, j);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
}
|
||||
|
||||
if(yi < xmyi) {
|
||||
double x2 = x0 - G2;
|
||||
double y2 = y0 - (G2 - 1);
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i, j - PRIME_Y);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
} else {
|
||||
double x2 = x0 + G2;
|
||||
double y2 = y0 + (G2 - 1);
|
||||
double a2 = (2.0 / 3.0) - x2 * x2 - y2 * y2;
|
||||
if(a2 > 0) {
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i, j + PRIME_Y);
|
||||
double gx2 = GRADIENTS_2_D[gi2], gy2 = GRADIENTS_2_D[gi2 | 1];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
}
|
||||
}
|
||||
out[0] *= 18.24196194486065;
|
||||
out[1] *= 18.24196194486065;
|
||||
out[2] *= 18.24196194486065;
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -206,7 +206,8 @@ public class OpenSimplex2Sampler extends SimplexStyleSampler {
|
||||
double rampValue = gx * x2 + gy * y2;
|
||||
out[0] += cccc * rampValue;
|
||||
out[1] += gx * cccc - 8 * rampValue * ccc * x2;
|
||||
out[2] += gy * cccc - 8 * rampValue * ccc * y2; }
|
||||
out[2] += gy * cccc - 8 * rampValue * ccc * y2;
|
||||
}
|
||||
|
||||
if(y0 > x0) {
|
||||
double x1 = x0 + G2;
|
||||
@@ -219,7 +220,8 @@ public class OpenSimplex2Sampler extends SimplexStyleSampler {
|
||||
double rampValue = gx * x1 + gy * y1;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x1;
|
||||
out[2] += gy * bbbb - 8 * rampValue * bbb * y1; }
|
||||
out[2] += gy * bbbb - 8 * rampValue * bbb * y1;
|
||||
}
|
||||
} else {
|
||||
double x1 = x0 + (G2 - 1);
|
||||
double y1 = y0 + G2;
|
||||
@@ -231,7 +233,8 @@ public class OpenSimplex2Sampler extends SimplexStyleSampler {
|
||||
double rampValue = gx * x1 + gy * y1;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x1;
|
||||
out[2] += gy * bbbb - 8 * rampValue * bbb * y1; }
|
||||
out[2] += gy * bbbb - 8 * rampValue * bbb * y1;
|
||||
}
|
||||
}
|
||||
|
||||
out[0] *= 99.83685446303647f;
|
||||
@@ -242,114 +245,116 @@ public class OpenSimplex2Sampler extends SimplexStyleSampler {
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long sl, double x, double y, double z) {
|
||||
int seed = (int) sl;
|
||||
// 3D OpenSimplex2Sampler case uses two offset rotated cube grids.
|
||||
final double R3 = (2.0 / 3.0);
|
||||
double r = (x + y + z) * R3; // Rotation, not skew
|
||||
x = r - x;
|
||||
y = r - y;
|
||||
z = r - z;
|
||||
int seed = (int) sl;
|
||||
// 3D OpenSimplex2Sampler case uses two offset rotated cube grids.
|
||||
final double R3 = (2.0 / 3.0);
|
||||
double r = (x + y + z) * R3; // Rotation, not skew
|
||||
x = r - x;
|
||||
y = r - y;
|
||||
z = r - z;
|
||||
|
||||
|
||||
int i = (int) Math.round(x);
|
||||
int j = (int) Math.round(y);
|
||||
int k = (int) Math.round(z);
|
||||
double x0 = x - i;
|
||||
double y0 = y - j;
|
||||
double z0 = z - k;
|
||||
int i = (int) Math.round(x);
|
||||
int j = (int) Math.round(y);
|
||||
int k = (int) Math.round(z);
|
||||
double x0 = x - i;
|
||||
double y0 = y - j;
|
||||
double z0 = z - k;
|
||||
|
||||
int xNSign = (int) (-1.0 - x0) | 1;
|
||||
int yNSign = (int) (-1.0 - y0) | 1;
|
||||
int zNSign = (int) (-1.0 - z0) | 1;
|
||||
int xNSign = (int) (-1.0 - x0) | 1;
|
||||
int yNSign = (int) (-1.0 - y0) | 1;
|
||||
int zNSign = (int) (-1.0 - z0) | 1;
|
||||
|
||||
double ax0 = xNSign * -x0;
|
||||
double ay0 = yNSign * -y0;
|
||||
double az0 = zNSign * -z0;
|
||||
double ax0 = xNSign * -x0;
|
||||
double ay0 = yNSign * -y0;
|
||||
double az0 = zNSign * -z0;
|
||||
|
||||
i *= PRIME_X;
|
||||
j *= PRIME_Y;
|
||||
k *= PRIME_Z;
|
||||
i *= PRIME_X;
|
||||
j *= PRIME_Y;
|
||||
k *= PRIME_Z;
|
||||
|
||||
double[] out = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
double a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
|
||||
|
||||
for(int l = 0; ; l++) {
|
||||
if(a > 0) {
|
||||
double aa = a * a, aaa = aa * a, aaaa = aa * aa;
|
||||
int gi = gradCoordIndex(seed, i, j, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * y0 + gz * z0;
|
||||
out[0] += aaaa * rampValue;
|
||||
out[1] += gx * aaaa - 8 * rampValue * aaa * x0;
|
||||
out[1] += gy * aaaa - 8 * rampValue * aaa * y0;
|
||||
out[2] += gz * aaaa - 8 * rampValue * aaa * z0;
|
||||
}
|
||||
double[] out = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
double a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
|
||||
|
||||
if(ax0 >= ay0 && ax0 >= az0) {
|
||||
double b = a + ax0 + ax0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i - xNSign * PRIME_X, j, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * (x0 + xNSign) + gy * y0 + gz * z0;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * (x0 + xNSign);
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * y0;
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * z0;
|
||||
}
|
||||
} else if(ay0 > ax0 && ay0 >= az0) {
|
||||
double b = a + ay0 + ay0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i, j - yNSign * PRIME_Y, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * (y0 + yNSign) + gz * z0;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x0;
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * (y0 + yNSign);
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * z0; }
|
||||
} else {
|
||||
double b = a + az0 + az0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i, j, k - zNSign * PRIME_Z);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * y0 + gz * (z0 + zNSign);
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x0;
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * y0;
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * (z0 + zNSign); }
|
||||
}
|
||||
|
||||
if(l == 1) break;
|
||||
|
||||
ax0 = 0.5 - ax0;
|
||||
ay0 = 0.5 - ay0;
|
||||
az0 = 0.5 - az0;
|
||||
|
||||
x0 = xNSign * ax0;
|
||||
y0 = yNSign * ay0;
|
||||
z0 = zNSign * az0;
|
||||
|
||||
a += (0.75 - ax0) - (ay0 + az0);
|
||||
|
||||
i += (xNSign >> 1) & PRIME_X;
|
||||
j += (yNSign >> 1) & PRIME_Y;
|
||||
k += (zNSign >> 1) & PRIME_Z;
|
||||
|
||||
xNSign = -xNSign;
|
||||
yNSign = -yNSign;
|
||||
zNSign = -zNSign;
|
||||
|
||||
seed = ~seed;
|
||||
for(int l = 0; ; l++) {
|
||||
if(a > 0) {
|
||||
double aa = a * a, aaa = aa * a, aaaa = aa * aa;
|
||||
int gi = gradCoordIndex(seed, i, j, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * y0 + gz * z0;
|
||||
out[0] += aaaa * rampValue;
|
||||
out[1] += gx * aaaa - 8 * rampValue * aaa * x0;
|
||||
out[1] += gy * aaaa - 8 * rampValue * aaa * y0;
|
||||
out[2] += gz * aaaa - 8 * rampValue * aaa * z0;
|
||||
}
|
||||
out[0] *= 32.69428253173828125;
|
||||
out[1] *= 32.69428253173828125;
|
||||
out[2] *= 32.69428253173828125;
|
||||
out[3] *= 32.69428253173828125;
|
||||
return out;
|
||||
|
||||
if(ax0 >= ay0 && ax0 >= az0) {
|
||||
double b = a + ax0 + ax0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i - xNSign * PRIME_X, j, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * (x0 + xNSign) + gy * y0 + gz * z0;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * (x0 + xNSign);
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * y0;
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * z0;
|
||||
}
|
||||
} else if(ay0 > ax0 && ay0 >= az0) {
|
||||
double b = a + ay0 + ay0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i, j - yNSign * PRIME_Y, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * (y0 + yNSign) + gz * z0;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x0;
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * (y0 + yNSign);
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * z0;
|
||||
}
|
||||
} else {
|
||||
double b = a + az0 + az0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i, j, k - zNSign * PRIME_Z);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * y0 + gz * (z0 + zNSign);
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x0;
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * y0;
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * (z0 + zNSign);
|
||||
}
|
||||
}
|
||||
|
||||
if(l == 1) break;
|
||||
|
||||
ax0 = 0.5 - ax0;
|
||||
ay0 = 0.5 - ay0;
|
||||
az0 = 0.5 - az0;
|
||||
|
||||
x0 = xNSign * ax0;
|
||||
y0 = yNSign * ay0;
|
||||
z0 = zNSign * az0;
|
||||
|
||||
a += (0.75 - ax0) - (ay0 + az0);
|
||||
|
||||
i += (xNSign >> 1) & PRIME_X;
|
||||
j += (yNSign >> 1) & PRIME_Y;
|
||||
k += (zNSign >> 1) & PRIME_Z;
|
||||
|
||||
xNSign = -xNSign;
|
||||
yNSign = -yNSign;
|
||||
zNSign = -zNSign;
|
||||
|
||||
seed = ~seed;
|
||||
}
|
||||
out[0] *= 32.69428253173828125;
|
||||
out[1] *= 32.69428253173828125;
|
||||
out[2] *= 32.69428253173828125;
|
||||
out[3] *= 32.69428253173828125;
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.simplex;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.DerivativeNoiseFunction;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.NoiseFunction;
|
||||
|
||||
|
||||
/**
|
||||
@@ -117,12 +116,12 @@ public abstract class SimplexStyleSampler extends DerivativeNoiseFunction {
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y) {
|
||||
return new double[]{0, 0, 0};
|
||||
return new double[]{ 0, 0, 0 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y, double z) {
|
||||
return new double[]{0, 0, 0, 0};
|
||||
return new double[]{ 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user