-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev/fractal-gavoro-pseudoerosion' into ver/6.5.0
- Loading branch information
Showing
7 changed files
with
469 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...in/java/com/dfsek/terra/addons/noise/config/templates/DerivativeNoiseSamplerTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.dfsek.terra.addons.noise.config.templates; | ||
|
||
import com.dfsek.tectonic.api.config.template.annotations.Value; | ||
import com.dfsek.tectonic.api.exception.ValidationException; | ||
|
||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler; | ||
import com.dfsek.terra.api.noise.NoiseSampler; | ||
|
||
|
||
public class DerivativeNoiseSamplerTemplate extends SamplerTemplate<DerivativeNoiseSampler> { | ||
|
||
@Value(".") | ||
private NoiseSampler sampler; | ||
|
||
@Override | ||
public boolean validate() throws ValidationException { | ||
if (!DerivativeNoiseSampler.isDifferentiable(sampler)) throw new ValidationException("Provided sampler does not support calculating a derivative"); | ||
return super.validate(); | ||
} | ||
|
||
@Override | ||
public DerivativeNoiseSampler get() { | ||
return (DerivativeNoiseSampler) sampler; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...n/java/com/dfsek/terra/addons/noise/config/templates/noise/DerivativeFractalTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.dfsek.terra.addons.noise.config.templates.noise; | ||
|
||
import com.dfsek.tectonic.api.config.template.annotations.Default; | ||
import com.dfsek.tectonic.api.config.template.annotations.Value; | ||
|
||
import com.dfsek.terra.addons.noise.config.templates.SamplerTemplate; | ||
import com.dfsek.terra.addons.noise.samplers.noise.simplex.DerivativeFractal; | ||
|
||
|
||
public class DerivativeFractalTemplate extends SamplerTemplate<DerivativeFractal> { | ||
|
||
@Value("octaves") | ||
@Default | ||
private int octaves = 3; | ||
|
||
@Value("gain") | ||
@Default | ||
private double gain = 0.5; | ||
|
||
@Value("lacunarity") | ||
@Default | ||
private double lacunarity = 2.0; | ||
|
||
@Value("frequency") | ||
@Default | ||
private double frequency = 0.02; | ||
|
||
@Override | ||
public DerivativeFractal get() { | ||
return new DerivativeFractal(octaves, gain, lacunarity, frequency); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
.../main/java/com/dfsek/terra/addons/noise/config/templates/noise/PseudoErosionTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.dfsek.terra.addons.noise.config.templates.noise; | ||
|
||
import com.dfsek.tectonic.api.config.template.annotations.Default; | ||
import com.dfsek.tectonic.api.config.template.annotations.Value; | ||
|
||
import com.dfsek.terra.addons.noise.config.templates.SamplerTemplate; | ||
import com.dfsek.terra.addons.noise.samplers.noise.simplex.PseudoErosion; | ||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler; | ||
|
||
|
||
public class PseudoErosionTemplate extends SamplerTemplate<PseudoErosion> { | ||
|
||
@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 PseudoErosion get() { | ||
return new PseudoErosion(octaves, gain, lacunarity, | ||
slopeStrength, branchStrength, strength, | ||
erosionFrequency, heightSampler, slopeMask, slopeMaskFull, slopeMaskNone, jitterModifier, averageErosionImpulses); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
.../src/main/java/com/dfsek/terra/addons/noise/samplers/noise/simplex/DerivativeFractal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.dfsek.terra.addons.noise.samplers.noise.simplex; | ||
|
||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler; | ||
|
||
import static com.dfsek.terra.addons.noise.samplers.noise.simplex.PseudoErosion.dot; | ||
import static com.dfsek.terra.addons.noise.samplers.noise.simplex.PseudoErosion.hash; | ||
import static com.dfsek.terra.addons.noise.samplers.noise.simplex.PseudoErosion.hashX; | ||
import static com.dfsek.terra.addons.noise.samplers.noise.simplex.PseudoErosion.hashY; | ||
|
||
|
||
/** | ||
* Temporary sampler that provides derivatives to test pseudoerosion, should be replaced with | ||
* derivative versions of existing samplers | ||
*/ | ||
public class DerivativeFractal implements DerivativeNoiseSampler { | ||
|
||
private final int heightOctaves; | ||
private final double heightGain; | ||
private final double heightLacunarity; | ||
private final double frequency; | ||
|
||
public DerivativeFractal(int octaves, double gain, double lacunarity, double frequency) { | ||
this.heightOctaves = octaves; | ||
this.heightGain = gain; | ||
this.heightLacunarity = lacunarity; | ||
this.frequency = frequency; | ||
} | ||
|
||
private static float[] baseNoise(float px, float py) { | ||
float ix = (float)Math.floor(px); | ||
float iy = (float)Math.floor(py); | ||
float fx = px - ix; | ||
float fy = py - iy; | ||
|
||
float ux = fx * fx * fx * (fx * (fx * 6.0f - 15.0f) + 10.0f); | ||
float uy = fy * fy * fy * (fy * (fy * 6.0f - 15.0f) + 10.0f); | ||
float dux = fx * fx * 30.0f * (fx * (fx - 2.0f) + 1.0f); | ||
float duy = fy * fy * 30.0f * (fy * (fy - 2.0f) + 1.0f); | ||
|
||
float gan = hash(ix, iy); | ||
float gax = hashX(gan); | ||
float gay = hashY(gan); | ||
|
||
float gbn = hash(ix + 1, iy); | ||
float gbx = hashX(gbn); | ||
float gby = hashY(gbn); | ||
|
||
float gcn = hash(ix, iy + 1); | ||
float gcx = hashX(gcn); | ||
float gcy = hashY(gcn); | ||
|
||
float gdn = hash(ix + 1, iy + 1); | ||
float gdx = hashX(gdn); | ||
float gdy = hashY(gdn); | ||
|
||
float va = dot(gax, gay, fx, fy); | ||
float vb = dot(gbx, gby, fx - 1, fy); | ||
float vc = dot(gcx, gcy, fx, fy - 1); | ||
float vd = dot(gdx, gdy, fx - 1, fy - 1); | ||
|
||
float u2x = gax + (gbx - gax) * ux + (gcx - gax) * uy + (gax - gbx - gcx + gdx) * ux * uy + dux * (uy * (va - vb - vc + vd) + vb - va); | ||
float u2y = gay + (gby - gay) * ux + (gcy - gay) * uy + (gay - gby - gcy + gdy) * ux * uy + duy * (ux * (va - vb - vc + vd) + vc - va); | ||
|
||
return new float[] { va + ux * (vb - va) + uy * (vc - va) + ux * uy * (va - vb - vc + vd), u2x, u2y }; | ||
} | ||
|
||
@Override | ||
public boolean isDifferentiable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public double[] noised(long seed, double x, double y) { | ||
x *= frequency; | ||
y *= frequency; | ||
double[] out = { 0.0f, 0.0f, 0.0f }; | ||
float heightFreq = 1.0f; | ||
float heightAmp = 1f; | ||
float cumAmp = 0.0f; | ||
for (int i = 0; i < heightOctaves; i++) { | ||
float[] noise = baseNoise((float) (x * heightFreq), (float) (y * heightFreq)); | ||
out[0] += noise[0] * heightAmp; | ||
out[1] += noise[1] * heightAmp * heightFreq; | ||
out[2] += noise[2] * heightAmp * heightFreq; | ||
cumAmp += heightAmp; | ||
heightAmp *= heightGain; | ||
heightFreq *= heightLacunarity; | ||
} | ||
out[0] /= cumAmp; | ||
out[1] /= cumAmp; | ||
out[2] /= cumAmp; | ||
return out; | ||
} | ||
|
||
@Override | ||
public double[] noised(long seed, double x, double y, double z) { | ||
return noised(seed, x, z); | ||
} | ||
|
||
@Override | ||
public double noise(long seed, double x, double y) { | ||
return noised(seed, x, y)[0]; | ||
} | ||
|
||
@Override | ||
public double noise(long seed, double x, double y, double z) { | ||
return noised(seed, x, y, z)[0]; | ||
} | ||
} |
Oops, something went wrong.