sky model update

This commit is contained in:
minjaesong
2023-07-25 15:15:12 +09:00
parent a73c536941
commit 4fb30821f1
5 changed files with 23 additions and 15 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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<ArrayList<ActorWithBody>>("visibleActorsRenderBehind")!! +
INGAME.extortField<ArrayList<ActorWithBody>>("visibleActorsRenderMiddle")!! +
INGAME.extortField<ArrayList<ActorWithBody>>("visibleActorsRenderMidTop")!! +
INGAME.extortField<ArrayList<ActorWithBody>>("visibleActorsRenderFront")!! +
INGAME.extortField<ArrayList<ActorWithBody>>("visibleActorsRenderOverlay")!!
)
}
catch (e: NumberFormatException) {
Echo("Wrong number input.")

View File

@@ -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