mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
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
This commit is contained in:
1 parent
843dcf702f
commit
c2183bc470
2 files changed
+79
-1
No files matched your search
@@ -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();
|
||||
|
||||
+66
@@ -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<IrisNoiseGenerator>().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<IrisNoiseGenerator>().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<IrisNoiseGenerator>().qadd(first).qadd(second))
|
||||
.setMultiplicitive(true)
|
||||
.setExponent(2D);
|
||||
|
||||
assertEquals(0.04D, height(generator), 1e-12);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user