mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -04:00
sky: calculate day and night time
This commit is contained in:
parent
c3af75874c
commit
00ca23c2b8
@ -33,6 +33,8 @@ class RGBColor(val rgba: Int) : ChatCode, TextFormattable {
|
|||||||
|
|
||||||
constructor(red: Double, green: Double, blue: Double, alpha: Double = 1.0) : this(red.toFloat(), green.toFloat(), blue.toFloat(), alpha.toFloat())
|
constructor(red: Double, green: Double, blue: Double, alpha: Double = 1.0) : this(red.toFloat(), green.toFloat(), blue.toFloat(), alpha.toFloat())
|
||||||
|
|
||||||
|
constructor(vec3: Vec3) : this(vec3.r, vec3.g, vec3.b)
|
||||||
|
|
||||||
val argb: Int
|
val argb: Int
|
||||||
get() = (alpha shl 24) or (red shl 16) or (green shl 8) or blue
|
get() = (alpha shl 24) or (red shl 16) or (green shl 8) or blue
|
||||||
|
|
||||||
|
@ -17,15 +17,15 @@ import de.bixilon.kutil.enums.EnumUtil
|
|||||||
import de.bixilon.kutil.enums.ValuesEnum
|
import de.bixilon.kutil.enums.ValuesEnum
|
||||||
|
|
||||||
// see https://minecraft.fandom.com/wiki/Moon
|
// see https://minecraft.fandom.com/wiki/Moon
|
||||||
enum class MoonPhases {
|
enum class MoonPhases(val light: Float) {
|
||||||
FULL_MOON,
|
FULL_MOON(1.0f),
|
||||||
WANING_GIBBOUS,
|
WANING_GIBBOUS(0.7f),
|
||||||
LAST_QUARTER,
|
LAST_QUARTER(0.4f),
|
||||||
WANING_CRESCENT,
|
WANING_CRESCENT(0.2f),
|
||||||
NEW_MOON,
|
NEW_MOON(0.0f),
|
||||||
WAXING_CRESCENT,
|
WAXING_CRESCENT(0.2f),
|
||||||
FIRST_QUARTER,
|
FIRST_QUARTER(0.4f),
|
||||||
WAXING_GIBBOUS,
|
WAXING_GIBBOUS(0.7f),
|
||||||
;
|
;
|
||||||
|
|
||||||
companion object : ValuesEnum<MoonPhases> {
|
companion object : ValuesEnum<MoonPhases> {
|
||||||
|
@ -29,7 +29,7 @@ class WorldTime(
|
|||||||
val time = abs(time) % ProtocolDefinition.TICKS_PER_DAY
|
val time = abs(time) % ProtocolDefinition.TICKS_PER_DAY
|
||||||
val cycling = time >= 0
|
val cycling = time >= 0
|
||||||
|
|
||||||
val moonPhase = MoonPhases[age.toInt() % ProtocolDefinition.TICKS_PER_DAY % MoonPhases.VALUES.size] // ToDo: Verify
|
val moonPhase = MoonPhases[age.toInt() / ProtocolDefinition.TICKS_PER_DAY % MoonPhases.VALUES.size] // ToDo: Verify
|
||||||
val phase = DayPhases.of(time)
|
val phase = DayPhases.of(time)
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.sky.box
|
package de.bixilon.minosoft.gui.rendering.sky.box
|
||||||
|
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.observe
|
import de.bixilon.kutil.watcher.DataWatcher.Companion.observe
|
||||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
|
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
|
||||||
import de.bixilon.minosoft.data.registries.biomes.Biome
|
import de.bixilon.minosoft.data.registries.biomes.Biome
|
||||||
@ -29,7 +30,11 @@ import de.bixilon.minosoft.gui.rendering.sky.properties.DefaultSkyProperties
|
|||||||
import de.bixilon.minosoft.gui.rendering.sky.properties.SkyProperties
|
import de.bixilon.minosoft.gui.rendering.sky.properties.SkyProperties
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.blockPosition
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.blockPosition
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.interpolateLinear
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.interpolateSine
|
||||||
import de.bixilon.minosoft.util.KUtil.minosoft
|
import de.bixilon.minosoft.util.KUtil.minosoft
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
class SkyboxRenderer(
|
class SkyboxRenderer(
|
||||||
private val sky: SkyRenderer,
|
private val sky: SkyRenderer,
|
||||||
@ -136,16 +141,23 @@ class SkyboxRenderer(
|
|||||||
return ChatColors.YELLOW
|
return ChatColors.YELLOW
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateDaytime(progress: Float): RGBColor {
|
private fun calculateDaytime(progress: Float): RGBColor? {
|
||||||
return ChatColors.BLUE
|
val base = calculateBiomeAvg { it.skyColor }?.toVec3() ?: return null
|
||||||
|
|
||||||
|
return RGBColor(interpolateLinear((abs(progress - 0.5f) * 2.0f).pow(2), base, base * 0.9f))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateSunset(progress: Float): RGBColor {
|
private fun calculateSunset(progress: Float): RGBColor {
|
||||||
return ChatColors.RED
|
return ChatColors.RED
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateNight(progress: Float): RGBColor {
|
private fun calculateNight(progress: Float): RGBColor? {
|
||||||
return ChatColors.DARK_BLUE
|
val base = calculateBiomeAvg { it.skyColor }?.toVec3() ?: return null
|
||||||
|
base *= 0.2
|
||||||
|
|
||||||
|
val minColor = Vec3(0.02f, 0.04f, 0.09f) * time.moonPhase.light
|
||||||
|
|
||||||
|
return RGBColor(interpolateSine(abs(progress - 0.5f) * 2.0f, minColor, base))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateSkyColor(): RGBColor? {
|
private fun calculateSkyColor(): RGBColor? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user