mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Stop fractured noise from mirroring across x = z
Each axis read the fracture at swapped coordinates, so the warp of z at
(a, b) was the warp of x at (b, a) and fractured styles were mirror
images of themselves across the diagonal. Each axis now samples its own
far, uncorrelated part of the fracture noise, on every path (generic,
fast 2D/3D, signed 2D/3D). The 3D fast paths also read the second axis
in 3D instead of 2D. Same number of samples as before.
Ported from v3e 855ab90be. Its second half (axialFracturing for built-in
fractures) does not apply: V5 has no shared-value fracture mode.
Fractured terrain changes. Retaken: TerrainLayersPinTest and the three
fractured values of IrisMathNoiseHotPathParityTest. CNGFractureMirrorTest
fails on the old code (780 of 780 samples mirrored).
This commit is contained in:
1 parent
bcc5a1abb9
commit
ee5f3d90eb
4 files changed
+91
-14
No files matched your search
@@ -53,6 +53,11 @@ public class CNG {
|
||||
public static final NoiseInjector SRC_POW = (s, v) -> new double[]{Math.pow(s, v), 0};
|
||||
public static final NoiseInjector DST_MOD = (s, v) -> new double[]{v % s, 0};
|
||||
public static final NoiseInjector DST_POW = (s, v) -> new double[]{Math.pow(v, s), 0};
|
||||
// Each axis samples the fracture this far from the previous axis, so the warps are uncorrelated. Sampling swapped
|
||||
// coordinates instead mirrors the warp across x = z. Not a multiple of the 65536-cell hash period.
|
||||
private static final double FRACTURE_AXIS_OFFSET = 10_000.5;
|
||||
private static final double SECOND_AXIS_OFFSET = FRACTURE_AXIS_OFFSET;
|
||||
private static final double THIRD_AXIS_OFFSET = 2 * FRACTURE_AXIS_OFFSET;
|
||||
private final double opacity;
|
||||
private double scale;
|
||||
private double bakedScale;
|
||||
@@ -666,20 +671,29 @@ public class CNG {
|
||||
double z = dim.length > 2 ? dim[2] : 0D;
|
||||
|
||||
if (dim.length > 0) {
|
||||
x += (fracture.noise(dim) - 0.5) * fscale;
|
||||
x += axialFractureOffset(0D, dim);
|
||||
}
|
||||
|
||||
if (dim.length > 1) {
|
||||
y += (fracture.noise(dim[1], dim[0]) - 0.5) * fscale;
|
||||
y += axialFractureOffset(SECOND_AXIS_OFFSET, dim);
|
||||
}
|
||||
|
||||
if (dim.length > 2) {
|
||||
z += (fracture.noise(dim[2], dim[0], dim[1]) - 0.5) * fscale;
|
||||
z += axialFractureOffset(THIRD_AXIS_OFFSET, dim);
|
||||
}
|
||||
|
||||
return generator.noise(x * scale, y * scale, z * scale) * opacity;
|
||||
}
|
||||
|
||||
private double axialFractureOffset(double axisOffset, double[] dim) {
|
||||
double sample = switch (dim.length) {
|
||||
case 1 -> fracture.noise(dim[0] + axisOffset);
|
||||
case 2 -> fracture.noise(dim[0] + axisOffset, dim[1] + axisOffset);
|
||||
default -> fracture.noise(dim[0] + axisOffset, dim[1] + axisOffset, dim[2] + axisOffset);
|
||||
};
|
||||
return (sample - 0.5) * fscale;
|
||||
}
|
||||
|
||||
private double getNoise(double x) {
|
||||
ensureFastPathState();
|
||||
double scl = effectiveScale;
|
||||
@@ -701,7 +715,7 @@ public class CNG {
|
||||
}
|
||||
|
||||
double fx = x + ((fracture.noiseFast2D(x, z) - 0.5D) * fscale);
|
||||
double fz = z + ((fracture.noiseFast2D(z, x) - 0.5D) * fscale);
|
||||
double fz = z + ((fracture.noiseFast2D(x + SECOND_AXIS_OFFSET, z + SECOND_AXIS_OFFSET) - 0.5D) * fscale);
|
||||
return generator.noise(fx * scl, fz * scl, 0D) * opacity;
|
||||
}
|
||||
|
||||
@@ -714,8 +728,8 @@ public class CNG {
|
||||
}
|
||||
|
||||
double fx = x + ((fracture.noiseFast3D(x, y, z) - 0.5D) * fscale);
|
||||
double fy = y + ((fracture.noiseFast2D(y, x) - 0.5D) * fscale);
|
||||
double fz = z + ((fracture.noiseFast3D(z, x, y) - 0.5D) * fscale);
|
||||
double fy = y + ((fracture.noiseFast3D(x + SECOND_AXIS_OFFSET, y + SECOND_AXIS_OFFSET, z + SECOND_AXIS_OFFSET) - 0.5D) * fscale);
|
||||
double fz = z + ((fracture.noiseFast3D(x + THIRD_AXIS_OFFSET, y + THIRD_AXIS_OFFSET, z + THIRD_AXIS_OFFSET) - 0.5D) * fscale);
|
||||
return generator.noise(fx * scl, fy * scl, fz * scl) * opacity;
|
||||
}
|
||||
|
||||
@@ -1116,7 +1130,7 @@ public class CNG {
|
||||
}
|
||||
|
||||
double fx = x + (localFracture.noiseFastSigned2D(x, z) * signedFractureScale);
|
||||
double fz = z + (localFracture.noiseFastSigned2D(z, x) * signedFractureScale);
|
||||
double fz = z + (localFracture.noiseFastSigned2D(x + SECOND_AXIS_OFFSET, z + SECOND_AXIS_OFFSET) * signedFractureScale);
|
||||
return signedWithOpacity(localGenerator.noiseSigned(fx * scl, fz * scl, 0D));
|
||||
}
|
||||
|
||||
@@ -1131,8 +1145,8 @@ public class CNG {
|
||||
}
|
||||
|
||||
double fx = x + (localFracture.noiseFastSigned3D(x, y, z) * signedFractureScale);
|
||||
double fy = y + (localFracture.noiseFastSigned2D(y, x) * signedFractureScale);
|
||||
double fz = z + (localFracture.noiseFastSigned3D(z, x, y) * signedFractureScale);
|
||||
double fy = y + (localFracture.noiseFastSigned3D(x + SECOND_AXIS_OFFSET, y + SECOND_AXIS_OFFSET, z + SECOND_AXIS_OFFSET) * signedFractureScale);
|
||||
double fz = z + (localFracture.noiseFastSigned3D(x + THIRD_AXIS_OFFSET, y + THIRD_AXIS_OFFSET, z + THIRD_AXIS_OFFSET) * signedFractureScale);
|
||||
return signedWithOpacity(localGenerator.noiseSigned(fx * scl, fy * scl, fz * scl));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ import static org.mockito.Mockito.when;
|
||||
*/
|
||||
public class TerrainLayersPinTest {
|
||||
private static final long TERRAIN_SEED = 1337L;
|
||||
private static final int TRANSCRIPT_LENGTH = 143080;
|
||||
private static final int TRANSCRIPT_HASH = 1726319394;
|
||||
private static final int TRANSCRIPT_LENGTH = 143112;
|
||||
private static final int TRANSCRIPT_HASH = 149645537;
|
||||
private static final int COLUMN_STEP_X = 61;
|
||||
private static final int COLUMN_STEP_Z = 67;
|
||||
private static final int COLUMN_RANGE = 400;
|
||||
|
||||
+3
-3
@@ -37,17 +37,17 @@ public class IrisMathNoiseHotPathParityTest {
|
||||
.setStyle(NoiseStyle.PERLIN_IRIS.style())
|
||||
.setExponent(1.15D);
|
||||
|
||||
assertEquals(0.3886291844359823D, noiseGenerator.getNoise(9988L, 31.25D, -17.5D, null), 0D);
|
||||
assertEquals(0.5652709414703923D, noiseGenerator.getNoise(9988L, 31.25D, -17.5D, null), 0D);
|
||||
|
||||
IrisGeneratorStyle style = NoiseStyle.IRIS_DOUBLE.style();
|
||||
assertEquals(0.8640377573263068D, style.createNoCache(new RNG(112233L), null).noiseFast2D(42.5D, -19.75D), 0D);
|
||||
assertEquals(0.9127657585776476D, style.createNoCache(new RNG(112233L), null).noiseFast2D(42.5D, -19.75D), 0D);
|
||||
|
||||
IrisGenerator generator = new IrisGenerator()
|
||||
.setZoom(9.5D)
|
||||
.setOpacity(0.91D)
|
||||
.setComposite(new KList<IrisNoiseGenerator>().qadd(noiseGenerator));
|
||||
|
||||
assertEquals(0.5671980255964687D, generator.getHeight(63.0D, -27.0D, 445566L), 0D);
|
||||
assertEquals(0.44868786951463424D, generator.getHeight(63.0D, -27.0D, 445566L), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package art.arcane.iris.util.project.noise;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CNGFractureMirrorTest {
|
||||
private static final int GRID_SIZE = 40;
|
||||
private static final double GRID_STEP = 7.3D;
|
||||
private static final double MIRRORED = 1.0E-12D;
|
||||
private static final int ALLOWED_MIRRORED_SAMPLES = 2;
|
||||
|
||||
@Test
|
||||
public void fracturedNoiseIsNotMirroredAcrossTheDiagonal() {
|
||||
assertNotMirrored("2D fast", (noise, a, b) -> noise.noise(a, b));
|
||||
assertNotMirrored("2D signed", (noise, a, b) -> noise.noiseFastSigned2D(a, b));
|
||||
assertNotMirrored("generic", (noise, a, b) -> noise.noise(new double[]{a, b}));
|
||||
}
|
||||
|
||||
private void assertNotMirrored(String path, Sampler sampler) {
|
||||
CNG noise = fracturedSymmetricNoise();
|
||||
int mirroredSamples = 0;
|
||||
for (int i = 0; i < GRID_SIZE; i++) {
|
||||
for (int j = i + 1; j < GRID_SIZE; j++) {
|
||||
double a = i * GRID_STEP;
|
||||
double b = j * GRID_STEP + 0.5D;
|
||||
if (Math.abs(sampler.sample(noise, a, b) - sampler.sample(noise, b, a)) < MIRRORED) {
|
||||
mirroredSamples++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(path + " fracture mirrors the noise across x = z at " + mirroredSamples + " samples",
|
||||
mirroredSamples <= ALLOWED_MIRRORED_SAMPLES);
|
||||
}
|
||||
|
||||
private static CNG fracturedSymmetricNoise() {
|
||||
CNG fracture = new CNG(new RNG(91L), NoiseType.SIMPLEX, 1D, 1).scale(0.03D);
|
||||
return new CNG(new RNG(17L), new DiagonalSymmetricGenerator(), 1D, 1).fractureWith(fracture, 40D);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface Sampler {
|
||||
double sample(CNG noise, double a, double b);
|
||||
}
|
||||
|
||||
private static final class DiagonalSymmetricGenerator implements NoiseGenerator {
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return noise(x, 0D, 0D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return noise(x, z, 0D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return 0.5D + (Math.sin(x * 0.11D) + Math.sin(y * 0.11D) + Math.sin(z * 0.11D)) / 6D;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user