From c2183bc470ca42dfae05be5bdef0483d477ff7ab Mon Sep 17 00:00:00 2001 From: piexel Date: Tue, 10 Nov 2026 10:55:04 +0100 Subject: [PATCH] Add a combined-value exponent curve to generators Lets a pack curve the combined composite value of an IrisGenerator before opacity, so the final height can be shaped instead of each layer. Defaults to 1, which leaves existing generators and pinned values untouched. v3: 1fe588837 --- .../engine/object/terrain/IrisGenerator.java | 14 +++- .../terrain/IrisGeneratorExponentTest.java | 66 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/art/arcane/iris/engine/object/terrain/IrisGeneratorExponentTest.java diff --git a/core/src/main/java/art/arcane/iris/engine/object/terrain/IrisGenerator.java b/core/src/main/java/art/arcane/iris/engine/object/terrain/IrisGenerator.java index 82668fe25..388e26680 100644 --- a/core/src/main/java/art/arcane/iris/engine/object/terrain/IrisGenerator.java +++ b/core/src/main/java/art/arcane/iris/engine/object/terrain/IrisGenerator.java @@ -56,6 +56,9 @@ public class IrisGenerator extends IrisRegistrant { @Desc("Multiply the compsites instead of adding them") private boolean multiplicitive = false; @MinNumber(0.001) + @Desc("Curves the combined composite value (0-1) as value^exponent before opacity. Above 1 flattens lows and sharpens peaks, below 1 does the opposite. Unlike the exponent on a single noise generator, this acts on the combined result of all composites.") + private double exponent = 1; + @MinNumber(0.001) @Desc("The size of the cell fractures") private double cellFractureZoom = 1D; @MinNumber(0) @@ -195,7 +198,8 @@ public class IrisGenerator extends IrisRegistrant { } } - double v = multiplicitive ? h * opacity : (h / tp) * opacity; + double combined = multiplicitive ? h : h / tp; + double v = applyExponent(combined) * opacity; if (Double.isNaN(v)) { v = 0; @@ -207,6 +211,14 @@ public class IrisGenerator extends IrisRegistrant { return v; } + private double applyExponent(double value) { + if (exponent == 1) { + return value; + } + + return value < 0 ? -Math.pow(-value, exponent) : Math.pow(value, exponent); + } + public double cell(double rx, double rz, double v, double superSeed) { getCellGenerator(getSeed() + 46222).setShuffle(getCellFractureShuffle()); double fractureX = rx / getCellFractureZoom(); diff --git a/core/src/test/java/art/arcane/iris/engine/object/terrain/IrisGeneratorExponentTest.java b/core/src/test/java/art/arcane/iris/engine/object/terrain/IrisGeneratorExponentTest.java new file mode 100644 index 000000000..a6e31c401 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/engine/object/terrain/IrisGeneratorExponentTest.java @@ -0,0 +1,66 @@ +package art.arcane.iris.engine.object.terrain; + +import art.arcane.iris.engine.object.noise.IrisNoiseGenerator; +import art.arcane.volmlib.util.collection.KList; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class IrisGeneratorExponentTest { + private static final long SUPER_SEED = 1234L; + private static final double SAMPLE_X = 10D; + private static final double SAMPLE_Z = -4D; + + private static IrisGenerator constantGenerator(double value) { + IrisNoiseGenerator constant = new IrisNoiseGenerator(false).setOffsetY(value); + return new IrisGenerator().setComposite(new KList().qadd(constant)); + } + + private static double height(IrisGenerator generator) { + return generator.getHeight(SAMPLE_X, SAMPLE_Z, SUPER_SEED); + } + + @Test + public void defaultExponentLeavesTheCompositeUntouched() { + assertEquals(0.3D, height(constantGenerator(0.3D)), 0D); + } + + @Test + public void exponentCurvesThePositiveCompositeValue() { + assertEquals(0.09D, height(constantGenerator(0.3D).setExponent(2D)), 1e-12); + assertEquals(Math.sqrt(0.25D), height(constantGenerator(0.25D).setExponent(0.5D)), 1e-12); + } + + @Test + public void exponentKeepsTheSignOfNegativeCompositeValues() { + assertEquals(-0.09D, height(constantGenerator(-0.3D).setExponent(2D)), 1e-12); + } + + @Test + public void exponentActsBeforeOpacity() { + assertEquals(0.045D, height(constantGenerator(0.3D).setExponent(2D).setOpacity(0.5D)), 1e-12); + } + + @Test + public void exponentActsOnTheCombinedValueOfAllComposites() { + IrisNoiseGenerator low = new IrisNoiseGenerator(false).setOffsetY(0.2D); + IrisNoiseGenerator high = new IrisNoiseGenerator(false).setOffsetY(0.6D); + IrisGenerator generator = new IrisGenerator() + .setComposite(new KList().qadd(low).qadd(high)) + .setExponent(2D); + + assertEquals(0.16D, height(generator), 1e-12); + } + + @Test + public void exponentCurvesTheProductOfMultiplicativeComposites() { + IrisNoiseGenerator first = new IrisNoiseGenerator(false).setOffsetY(0.5D); + IrisNoiseGenerator second = new IrisNoiseGenerator(false).setOffsetY(0.4D); + IrisGenerator generator = new IrisGenerator() + .setComposite(new KList().qadd(first).qadd(second)) + .setMultiplicitive(true) + .setExponent(2D); + + assertEquals(0.04D, height(generator), 1e-12); + } +}