new oregen param: ratio

This commit is contained in:
minjaesong
2023-10-28 16:49:34 +09:00
parent 208bf79353
commit 76d6579ce9
4 changed files with 46 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
"id";"freq";"power";"scale";"tiling";"comment" "id";"freq";"power";"scale";"ratio";"tiling";"comment"
"1";"0.026";"0.01";"0.505";"a16";"copper (malachite)" "1";"0.026";"0.01";"0.505";"1.0";"a16";"copper (malachite)"
"2";"0.040";"0.01";"0.505";"a16";"iron (haematite)" "2";"0.040";"0.01";"0.505";"1.0";"a16";"iron (haematite)"
#"3";"0.040";"0.08";"0.501";"r16";"coal" #"3";"0.040";"0.08";"0.501";"1.0";"r16";"coal"
################################################################################ ################################################################################
@@ -10,6 +10,7 @@
# freq: frequency value used to set up noise generator. Larger = ore veins are closer together # freq: frequency value used to set up noise generator. Larger = ore veins are closer together
# power: power value (as in: randomNumber ^ power) used to set up the noise generator. Larger = veins are larger as you go deeper. 0.01 almost negates this effect # power: power value (as in: randomNumber ^ power) used to set up the noise generator. Larger = veins are larger as you go deeper. 0.01 almost negates this effect
# scale: scale value used to set up the noise generator. Larger = thicker veins. A valid value tend to play around the 0.5; you'll need figure out this value by trial and error # scale: scale value used to set up the noise generator. Larger = thicker veins. A valid value tend to play around the 0.5; you'll need figure out this value by trial and error
# ratio: how elongated (or squeeze) the ore veins are. >1.0 = stretched horizontally, <1.0 = stretched vertically
# #
# tiling: determines how the tiles are tiled # tiling: determines how the tiles are tiled
# - a16: use 4-neighbour autotiling (16 possible cases) # - a16: use 4-neighbour autotiling (16 possible cases)
Can't render this file because it contains an unexpected character in line 4 and column 2.

View File

@@ -520,9 +520,10 @@ object ModMgr {
val freq = rec.get("freq").toDouble() val freq = rec.get("freq").toDouble()
val power = rec.get("power").toDouble() val power = rec.get("power").toDouble()
val scale = rec.get("scale").toDouble() val scale = rec.get("scale").toDouble()
val ratio = rec.get("ratio").toDouble()
val tiling = rec.get("tiling") val tiling = rec.get("tiling")
Worldgen.registerOre(OregenParams(tile, freq, power, scale, tiling)) Worldgen.registerOre(OregenParams(tile, freq, power, scale, ratio, tiling))
} }
} }
catch (e: IOException) { catch (e: IOException) {

View File

@@ -10,12 +10,14 @@ import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_DIVISOR import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_DIVISOR
import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_MAGIC import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_MAGIC
import net.torvald.terrarum.sqr
import net.torvald.terrarum.toInt import net.torvald.terrarum.toInt
import net.torvald.terrarum.utils.OrePlacement import net.torvald.terrarum.utils.OrePlacement
import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.BlocksDrawer
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.max import kotlin.math.max
import kotlin.math.sin import kotlin.math.sin
import kotlin.math.sqrt
/** /**
* Created by minjaesong on 2023-10-25. * Created by minjaesong on 2023-10-25.
@@ -46,7 +48,7 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
*/ */
private fun getGenerator(seed: Long): List<Joise> { private fun getGenerator(seed: Long): List<Joise> {
return ores.map { return ores.map {
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake it.tile, it.freq, it.power, it.scale)) Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake it.tile, it.freq, it.power, it.scale, it.ratio))
} }
} }
@@ -86,7 +88,7 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
} }
} }
private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double): Module { private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double, ratio: Double): Module {
val oreShape = ModuleFractal().also { val oreShape = ModuleFractal().also {
it.setType(ModuleFractal.FractalType.RIDGEMULTI) it.setType(ModuleFractal.FractalType.RIDGEMULTI)
it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT) it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT)
@@ -130,10 +132,22 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
it.setAxisXSource(orePerturbScale) it.setAxisXSource(orePerturbScale)
} }
val oreStrecth = ModuleScaleDomain().also {
val xratio = if (ratio >= 1.0) ratio else 1.0
val yratio = if (ratio < 1.0) 1.0 / ratio else 1.0
val k = sqrt(2.0 / (xratio.sqr() + yratio.sqr()))
val xs = xratio * k
val ys = yratio * k
it.setSource(orePerturb)
it.setScaleX(1.0 / xs)
it.setScaleY(1.0 / ys)
}
val oreSelect = ModuleSelect().also { val oreSelect = ModuleSelect().also {
it.setLowSource(0.0) it.setLowSource(0.0)
it.setHighSource(1.0) it.setHighSource(1.0)
it.setControlSource(orePerturb) it.setControlSource(oreStrecth)
it.setThreshold(0.5) it.setThreshold(0.5)
it.setFalloff(0.0) it.setFalloff(0.0)
} }
@@ -147,5 +161,6 @@ data class OregenParams(
val freq: Double, //adjust the "density" of the caves val freq: Double, //adjust the "density" of the caves
val power: Double, // adjust the "concentration" of the cave gen. Lower = larger voids val power: Double, // adjust the "concentration" of the cave gen. Lower = larger voids
val scale: Double, // also adjust this if you've touched the bias value. Number can be greater than 1.0 val scale: Double, // also adjust this if you've touched the bias value. Number can be greater than 1.0
val ratio: Double, // how stretched the ore veins are. >1.0 = stretched horizontally, <1.0 = stretched vertically
val tiling: String, // a16, a47, r16, r8 val tiling: String, // a16, a47, r16, r8
) )

View File

@@ -29,6 +29,7 @@ import java.util.concurrent.Future
import kotlin.math.* import kotlin.math.*
import kotlin.random.Random import kotlin.random.Random
import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen
import net.torvald.terrarum.sqr
const val NOISEBOX_WIDTH = 922 const val NOISEBOX_WIDTH = 922
const val NOISEBOX_HEIGHT = 2000 const val NOISEBOX_HEIGHT = 2000
@@ -361,17 +362,19 @@ internal object TerragenTest : NoiseMaker {
private val IRON_ORE = 0xff9a5dff.toInt() private val IRON_ORE = 0xff9a5dff.toInt()
private val COPPER_ORE = 0x00e9c8ff private val COPPER_ORE = 0x00e9c8ff
private val COAL_ORE = 0xffffffff.toInt()
override fun draw(x: Int, y: Int, noiseValue: List<Double>, outTex: Pixmap) { override fun draw(x: Int, y: Int, noiseValue: List<Double>, outTex: Pixmap) {
val terr = noiseValue[0].tiered(.0, .5, .88, 1.88) val terr = noiseValue[0].tiered(.0, .5, .88, 1.88)
val cave = if (noiseValue[1] < 0.5) 0 else 1 val cave = if (noiseValue[1] < 0.5) 0 else 1
val copper = (noiseValue[2] > 0.5) val copper = (noiseValue[2] > 0.5)
val iron = (noiseValue[3] > 0.5) val iron = (noiseValue[3] > 0.5)
val coal = (noiseValue[4] > 0.5)
val wallBlock = groundDepthBlock[terr] val wallBlock = groundDepthBlock[terr]
val terrBlock = if (cave == 0) Block.AIR else wallBlock val terrBlock = if (cave == 0) Block.AIR else wallBlock
val ore = if (iron) IRON_ORE else if (copper) COPPER_ORE else null val ore = if (iron) IRON_ORE else if (copper) COPPER_ORE else if (coal) COAL_ORE else null
outTex.drawPixel(x, y, outTex.drawPixel(x, y,
if (ore != null && (terrBlock == Block.STONE || terrBlock == Block.STONE_SLATE)) ore if (ore != null && (terrBlock == Block.STONE || terrBlock == Block.STONE_SLATE)) ore
@@ -686,8 +689,9 @@ internal object TerragenTest : NoiseMaker {
return listOf( return listOf(
Joise(groundScaling), Joise(groundScaling),
Joise(caveScaling), Joise(caveScaling),
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:1", 0.024, 0.01, 0.505)), Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:1", 0.024, 0.01, 0.505, 1.0)),
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:2", 0.04, 0.01, 0.505)), Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:2", 0.04, 0.01, 0.505, 1.0)),
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:3", 0.04, 0.01, 0.505, 10.0)),
) )
} }
@@ -701,7 +705,7 @@ internal object TerragenTest : NoiseMaker {
} }
} }
private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double): Module { private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double, ratio: Double): Module {
val oreShape = ModuleFractal().also { val oreShape = ModuleFractal().also {
it.setType(ModuleFractal.FractalType.RIDGEMULTI) it.setType(ModuleFractal.FractalType.RIDGEMULTI)
it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT) it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT)
@@ -745,10 +749,22 @@ internal object TerragenTest : NoiseMaker {
it.setAxisXSource(orePerturbScale) it.setAxisXSource(orePerturbScale)
} }
val oreStrecth = ModuleScaleDomain().also {
val xratio = if (ratio >= 1.0) ratio else 1.0
val yratio = if (ratio < 1.0) 1.0 / ratio else 1.0
val k = sqrt(2.0 / (xratio.sqr() + yratio.sqr()))
val xs = xratio * k
val ys = yratio * k
it.setSource(orePerturb)
it.setScaleX(1.0 / xs)
it.setScaleY(1.0 / ys)
}
val oreSelect = ModuleSelect().also { val oreSelect = ModuleSelect().also {
it.setLowSource(0.0) it.setLowSource(0.0)
it.setHighSource(1.0) it.setHighSource(1.0)
it.setControlSource(orePerturb) it.setControlSource(oreStrecth)
it.setThreshold(0.5) it.setThreshold(0.5)
it.setFalloff(0.0) it.setFalloff(0.0)
} }