From 4fb30821f1baac70fd076c7c55d28a9b8c9ea756 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 25 Jul 2023 15:15:12 +0900 Subject: [PATCH] sky model update --- assets/mods/basegame/weathers/clut_daylight.tga | 4 ++-- src/net/torvald/terrarum/gameworld/WorldTime.kt | 12 ++++-------- .../torvald/terrarum/modulebasegame/clut/Skybox.kt | 7 ++++--- .../terrarum/modulebasegame/console/SetSol.kt | 11 +++++++++++ src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt | 4 ++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/assets/mods/basegame/weathers/clut_daylight.tga b/assets/mods/basegame/weathers/clut_daylight.tga index 27c383349..056655cf3 100644 --- a/assets/mods/basegame/weathers/clut_daylight.tga +++ b/assets/mods/basegame/weathers/clut_daylight.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4c2aeb0565fc7c84d3e708e12c7e1590a151458f9f24cbf994515183a66ce5f3 -size 1218 +oid sha256:0b439c9beeb44162e30538c2b0ed8ea433a9e3e4805218125f222ecd2d8c928f +size 2418 diff --git a/src/net/torvald/terrarum/gameworld/WorldTime.kt b/src/net/torvald/terrarum/gameworld/WorldTime.kt index 2b4441e3b..10a758d85 100644 --- a/src/net/torvald/terrarum/gameworld/WorldTime.kt +++ b/src/net/torvald/terrarum/gameworld/WorldTime.kt @@ -125,21 +125,17 @@ class WorldTime(initTime: Long = 0L) { val TIME_T = DAY_LENGTH * ordinalDay + second val x = (TIME_T % YEAR_SECONDS).toDouble() / DAY_LENGTH + 15 // decimal days. One full day = 1.0 - val d = -23.44 * cos(TWO_PI * x / YEAR_DAYS) - // 51.56 and 23.44 will make yearly min/max elevation to be 75deg - // -0.2504264: a number that makes y=min when x=0 (x=0 is midnight) - return 51.56 * sin(TWO_PI * (x - 0.2504264)) + d + val d = -23.44 * cos(TWO_PI * x / YEAR_DAYS) + return -51.56 * cos(TWO_PI * x) + d } val solarElevationDeg: Double get() { val x = (TIME_T % YEAR_SECONDS).toDouble() / DAY_LENGTH + 15 // decimal days. One full day = 1.0 - val d = -23.44 * cos(TWO_PI * x / YEAR_DAYS) - // 51.56 and 23.44 will make yearly min/max elevation to be 75deg - // -0.2504264: a number that makes y=min when x=0 (x=0 is midnight) - return 51.56 * sin(TWO_PI * (x - 0.2504264)) + d + val d = -23.44 * cos(TWO_PI * x / YEAR_DAYS) + return -51.56 * cos(TWO_PI * x) + d } val solarElevationRad: Double get() = Math.toRadians(solarElevationDeg) diff --git a/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt b/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt index 4bb395fc1..2dfaf502c 100644 --- a/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt +++ b/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt @@ -52,7 +52,7 @@ object Skybox : Disposable { ) } else { - val deg1 = (-elevationDeg / 75.0).pow(0.8).times(-75.0) + val deg1 = (-elevationDeg / 75.0).pow(0.93).times(-75.0) val elevation1 = -deg1 val elevation2 = -deg1 / 28.5 val scale = (1f - (1f - 1f / 1.8.pow(elevation1)) * 0.97f).toFloat() @@ -68,7 +68,8 @@ object Skybox : Disposable { 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 turbidityStep = 5 + private val turbidities = (1_0..10_0 step turbidityStep) // (100 / turbidityStep) - 1 private val turbiditiesD = (turbidities.first / 10.0..turbidities.last / 10.0) private val elevCnt = elevations.count() private val turbCnt = turbidities.count() @@ -94,7 +95,7 @@ object Skybox : Disposable { val elevationDeg = (it / turbCnt).plus(elevations.first).toDouble() val elevationRad = Math.toRadians(elevationDeg) - val turbidity = 1.0 + (it % turbCnt) / 10.0 + val turbidity = 1.0 + (it % turbCnt) / (10.0 / turbidityStep) val state = ArHosekSkyModel.arhosek_xyz_skymodelstate_alloc_init(turbidity, albedo, elevationRad.abs()) val pixmap = Pixmap(1, gradSize, Pixmap.Format.RGBA8888) diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetSol.kt b/src/net/torvald/terrarum/modulebasegame/console/SetSol.kt index 3df80f91d..baa63934f 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SetSol.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SetSol.kt @@ -1,8 +1,12 @@ package net.torvald.terrarum.modulebasegame.console +import net.torvald.reflection.extortField +import net.torvald.terrarum.INGAME import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.Echo +import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.weather.WeatherMixer +import net.torvald.terrarum.worlddrawer.LightmapRenderer /** * Created by minjaesong on 2023-07-25. @@ -17,6 +21,13 @@ internal object SetSol : ConsoleCommand { try { val solarAngle = args[1].toDouble().coerceIn(-75.0..75.0) WeatherMixer.forceSolarElev = solarAngle + LightmapRenderer.recalculate( + INGAME.extortField>("visibleActorsRenderBehind")!! + + INGAME.extortField>("visibleActorsRenderMiddle")!! + + INGAME.extortField>("visibleActorsRenderMidTop")!! + + INGAME.extortField>("visibleActorsRenderFront")!! + + INGAME.extortField>("visibleActorsRenderOverlay")!! + ) } catch (e: NumberFormatException) { Echo("Wrong number input.") diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 582be3eee..6cdfa3628 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -101,8 +101,8 @@ class BasicDebugInfoWindow : UICanvas() { private infix fun Double.pow(b: Double) = Math.pow(this, b) private fun Double?.toIntAndFrac(intLen: Int, fracLen: Int = 4): String = - if (this == null) "null" else if (this.isNaN()) "NaN" else if (this.isInfinite()) "${if (this.sign >= 0) '+' else '-'}Inf" else - "${this.toInt().toString().padStart(intLen)}." + + if (this == null) "null" else if (this.isNaN()) "NaN" else if (this.isInfinite()) "${if (this >= 0.0) '+' else '-'}Inf" else + "${((if (this >= 0.0) "" else "-") + "${this.absoluteValue.toInt()}").padStart(intLen)}." + (10.0 pow fracLen.toDouble()).let { d -> (this.absoluteValue.times(d) % d).toInt().toString().padEnd(fracLen) } private val gap = 14f