From a73c5369419a656d1af4d3e2da2dc2c6c76f4c6e Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 25 Jul 2023 03:47:59 +0900 Subject: [PATCH] skybox model changes on negative deg --- assets/mods/basegame/commands.csv | 2 + .../console/SetGlobalLightOverride.kt | 2 +- .../terrarum/modulebasegame/clut/Skybox.kt | 7 ++-- .../terrarum/modulebasegame/console/SetSol.kt | 37 +++++++++++++++++++ .../modulebasegame/console/SetTurb.kt | 37 +++++++++++++++++++ .../terrarum/ui/BasicDebugInfoWindow.kt | 12 ++++-- .../torvald/terrarum/weather/WeatherMixer.kt | 20 +++++++--- 7 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/console/SetSol.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/console/SetTurb.kt diff --git a/assets/mods/basegame/commands.csv b/assets/mods/basegame/commands.csv index 842175335..ec0392585 100644 --- a/assets/mods/basegame/commands.csv +++ b/assets/mods/basegame/commands.csv @@ -22,6 +22,8 @@ Seed SetAV SetBulletin SetScale +SetSol +SetTurb SetTime SetTimeDelta SpawnPhysTestBall diff --git a/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt b/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt index d00ac1cb2..5d6586850 100644 --- a/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt +++ b/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt @@ -30,7 +30,7 @@ internal object SetGlobalLightOverride : ConsoleCommand { } } - else if (args.size == 2 && args[1].trim().toLowerCase() == "none") { + else if (args.size == 2 && args[1].trim().lowercase() == "none") { WeatherMixer.globalLightOverridden = false } else { diff --git a/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt b/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt index e50cb8b1f..4bb395fc1 100644 --- a/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt +++ b/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt @@ -52,8 +52,9 @@ object Skybox : Disposable { ) } else { - val elevation1 = -elevationDeg - val elevation2 = -elevationDeg / 28.5 + val deg1 = (-elevationDeg / 75.0).pow(0.8).times(-75.0) + val elevation1 = -deg1 + val elevation2 = -deg1 / 28.5 val scale = (1f - (1f - 1f / 1.8.pow(elevation1)) * 0.97f).toFloat() val scale2 = (1.0 - (elevation2.pow(E) / E.pow(elevation2))*0.8).toFloat() CIEXYZ( @@ -65,7 +66,7 @@ object Skybox : Disposable { } } - private val elevations = (-75..75) // 151 + private val elevations = (-75..75) //zw 151 private val elevationsD = (elevations.first.toDouble() .. elevations.last.toDouble()) private val turbidities = (1_0..10_0 step 1) // 99 private val turbiditiesD = (turbidities.first / 10.0..turbidities.last / 10.0) diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetSol.kt b/src/net/torvald/terrarum/modulebasegame/console/SetSol.kt new file mode 100644 index 000000000..3df80f91d --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/console/SetSol.kt @@ -0,0 +1,37 @@ +package net.torvald.terrarum.modulebasegame.console + +import net.torvald.terrarum.console.ConsoleCommand +import net.torvald.terrarum.console.Echo +import net.torvald.terrarum.weather.WeatherMixer + +/** + * Created by minjaesong on 2023-07-25. + */ +internal object SetSol : ConsoleCommand { + override fun execute(args: Array) { + if (args.size == 2) { + if (args[1].trim().lowercase() == "none") { + WeatherMixer.forceSolarElev = null + } + else { + try { + val solarAngle = args[1].toDouble().coerceIn(-75.0..75.0) + WeatherMixer.forceSolarElev = solarAngle + } + catch (e: NumberFormatException) { + Echo("Wrong number input.") + } + catch (e1: IllegalArgumentException) { + Echo("Range: -75.0-75.0") + } + } + } + else { + printUsage() + } + } + + override fun printUsage() { + Echo("usage: setsol <-75.0..75.0 or 'none'>") + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetTurb.kt b/src/net/torvald/terrarum/modulebasegame/console/SetTurb.kt new file mode 100644 index 000000000..70bfe7d8f --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/console/SetTurb.kt @@ -0,0 +1,37 @@ +package net.torvald.terrarum.modulebasegame.console + +import net.torvald.terrarum.console.ConsoleCommand +import net.torvald.terrarum.console.Echo +import net.torvald.terrarum.weather.WeatherMixer + +/** + * Created by minjaesong on 2023-07-25. + */ +object SetTurb : ConsoleCommand { + override fun execute(args: Array) { + if (args.size == 2) { + if (args[1].trim().lowercase() == "none") { + WeatherMixer.forceTurbidity = null + } + else { + try { + val turbidity = args[1].toDouble().coerceIn(1.0..10.0) + WeatherMixer.forceTurbidity = turbidity + } + catch (e: NumberFormatException) { + Echo("Wrong number input.") + } + catch (e1: IllegalArgumentException) { + Echo("Range: 1.0-10.0") + } + } + } + else { + printUsage() + } + } + + override fun printUsage() { + Echo("usage: setturb <1.0..10.0 or 'none'>") + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index b0ac1fea6..582be3eee 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -197,12 +197,16 @@ class BasicDebugInfoWindow : UICanvas() { // sun and weather - val soldeg = world?.worldTime?.solarElevationDeg + val soldeg = WeatherMixer.forceSolarElev ?: world?.worldTime?.solarElevationDeg val soldegStr = (soldeg ?: 0.0).toIntAndFrac(3,2) val soldegNeg = ((soldeg ?: 0.0) >= 0.0).toInt() - val turbidity = WeatherMixer.turbidity - App.fontSmallNumbers.draw(batch, "$SOL $ccG$soldegStr", gap + 7f*(sol), line(mvY)) - App.fontSmallNumbers.draw(batch, "$TAU $ccG$turbidity", gap + 7f*(sol), line(mvY + 1)) + val turbidity = WeatherMixer.forceTurbidity ?: WeatherMixer.turbidity + + val soldegCol = if (WeatherMixer.forceSolarElev != null) ccO else ccG + val turbCol = if (WeatherMixer.forceTurbidity != null) ccO else ccG + + App.fontSmallNumbers.draw(batch, "$SOL $soldegCol$soldegStr", gap + 7f*(sol), line(mvY)) + App.fontSmallNumbers.draw(batch, "$TAU $turbCol$turbidity", gap + 7f*(sol), line(mvY + 1)) diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index b4c809043..de52e3fed 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -59,6 +59,8 @@ internal object WeatherMixer : RNGConsumer { // TODO to save from GL overhead, store lightmap to array; use GdxColorMap var forceTimeAt: Int? = null + var forceSolarElev: Double? = null + var forceTurbidity: Double? = null override fun loadFromSave(s0: Long, s1: Long) { super.loadFromSave(s0, s1) @@ -68,6 +70,8 @@ internal object WeatherMixer : RNGConsumer { fun internalReset() { globalLightOverridden = false forceTimeAt = null + forceSolarElev = null + forceTurbidity = null } init { @@ -160,7 +164,9 @@ internal object WeatherMixer : RNGConsumer { // we will not care for nextSkybox for now val timeNow = (forceTimeAt ?: world.worldTime.TIME_T.toInt()) % WorldTime.DAY_LENGTH - val solarElev = if (forceTimeAt != null) + val solarElev = if (forceSolarElev != null) + forceSolarElev!! + else if (forceTimeAt != null) world.worldTime.getSolarElevationAt(world.worldTime.ordinalDay, forceTimeAt!!) else world.worldTime.solarElevationDeg @@ -185,12 +191,16 @@ internal object WeatherMixer : RNGConsumer { gdxBlendNormalStraightAlpha() - val degThis = solarElev.floorToDouble() + val degThis = if (timeNow < HALF_DAY) solarElev.floorToDouble() else solarElev.ceilToDouble() val degNext = degThis + if (timeNow < HALF_DAY) 1 else -1 // Skybox.get has internal coerceIn - val texture1 = Skybox[degThis, turbidity] - val texture2 = Skybox[degNext, turbidity] - val lerpScale = (if (timeNow < HALF_DAY) solarElev - degThis else 1f - (solarElev - degThis)).toFloat() + val thisTurbidity = forceTurbidity ?: turbidity + + val texture1 = Skybox[degThis, thisTurbidity] + val texture2 = Skybox[degNext, thisTurbidity] + val lerpScale = (if (timeNow < HALF_DAY) solarElev - degThis else -(solarElev - degThis)).toFloat() + +// println("degThis=$degThis, degNext=$degNext, lerp=$lerpScale") val gradY = -(gH - App.scr.height) * ((parallax + 1f) / 2f) batch.inUse {