properly ignore skylight in end and nether

This commit is contained in:
Bixilon 2022-11-09 23:26:11 +01:00
parent 4513bf89ce
commit 6ac207e3ef
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 24 additions and 9 deletions

View File

@ -51,16 +51,16 @@ data class DimensionProperties(
}
val maxSection = minSection + sections
val lightLevels = FloatArray(16)
val brightness = FloatArray(16)
init {
check(maxSection > minSection) { "Upper section can not be lower that the lower section ($minSection > $maxSection)" }
check(minSection in ProtocolDefinition.CHUNK_MIN_SECTION..ProtocolDefinition.CHUNK_MAX_SECTION) { "Minimum section out of bounds: $minSection" }
check(maxSection in ProtocolDefinition.CHUNK_MIN_SECTION..ProtocolDefinition.CHUNK_MAX_SECTION) { "Maximum section out of bounds: $minSection" }
for (i in lightLevels.indices) {
val fraction = i / 15.0f
lightLevels[i] = interpolateLinear(ambientLight, fraction / (4.0f - 3.0f * fraction), 1.0f)
for (level in brightness.indices) {
val fraction = level / ProtocolDefinition.MAX_LIGHT_LEVEL.toFloat()
brightness[level] = interpolateLinear(ambientLight, fraction / (4.0f - 3.0f * fraction), 1.0f)
}
}

View File

@ -415,7 +415,7 @@ class World(
fun getBrightness(position: BlockPosition): Float {
val light = getLight(position)
val level = maxOf(light and SectionLight.BLOCK_LIGHT_MASK, light and SectionLight.SKY_LIGHT_MASK shr 4)
return dimension?.lightLevels?.get(level) ?: 0.0f
return dimension?.brightness?.get(level) ?: 0.0f
}
fun recalculateLight() {

View File

@ -18,6 +18,7 @@ import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.exception.Broken
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
import de.bixilon.minosoft.data.world.chunk.Chunk
import de.bixilon.minosoft.data.world.chunk.ChunkSection
import de.bixilon.minosoft.data.world.chunk.neighbours.ChunkNeighbours
@ -241,7 +242,7 @@ class ChunkLight(private val chunk: Chunk) {
section.light.calculate()
}
calculateSkylight()
} else if (previous > y) {
} else if (previous > y && connection.world.dimension.canSkylight()) {
// block is lower
startSkylightFloodFill(x, z)
}
@ -278,7 +279,7 @@ class ChunkLight(private val chunk: Chunk) {
}
private fun calculateSkylight() {
if (chunk.world.dimension?.hasSkyLight != true || !chunk.neighbours.complete) {
if (!chunk.world.dimension.canSkylight() || !chunk.neighbours.complete) {
// no need to calculate it
return
}
@ -395,4 +396,14 @@ class ChunkLight(private val chunk: Chunk) {
// TODO: Optimize for specific section height (i.e. not trace everything above)
calculateSkylight()
}
fun DimensionProperties?.canSkylight(): Boolean {
if (this == null) {
return false
}
if (!this.hasSkyLight || !this.skyProperties.skylight) {
return false
}
return true
}
}

View File

@ -23,6 +23,7 @@ object EndSkyProperties : SkyProperties {
override val resourceLocation = minecraft("the_end")
override val daylightCycle: Boolean get() = false
override val skylight: Boolean get() = false
override val fixedTexture: ResourceLocation = minecraft("environment/end_sky").texture()
override val sun: Boolean get() = false

View File

@ -21,6 +21,7 @@ object NetherSkyProperties : SkyProperties {
override val resourceLocation = minecraft("the_nether")
override val daylightCycle: Boolean get() = false
override val skylight: Boolean get() = false
override val sun: Boolean get() = false
override val moon: Boolean get() = false

View File

@ -21,6 +21,7 @@ object OverworldSkyProperties : SkyProperties {
override val resourceLocation = minecraft("overworld")
override val daylightCycle: Boolean get() = true
override val skylight: Boolean get() = true
override val sun: Boolean get() = true
override val moon: Boolean get() = true

View File

@ -19,6 +19,7 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
interface SkyProperties : ResourceLocationAble {
val daylightCycle: Boolean
val skylight: Boolean
val fixedTexture: ResourceLocation? get() = null
val sun: Boolean

View File

@ -64,8 +64,8 @@ class LegacyLightmapUpdater(private val connection: PlayConnection) : LightmapUp
val index = ((skyLight shl 4) or blockLight) * 4
val skyLightBrightness = (connection.world.dimension?.lightLevels?.get(skyLight) ?: 1.0f) * (skyGradient * 0.95f + 0.05f)
val blockLightBrightness = (connection.world.dimension?.lightLevels?.get(blockLight) ?: 1.0f) * 1.5// ToDo: multiply with time somewhat thing?
val skyLightBrightness = (connection.world.dimension?.brightness?.get(skyLight) ?: 1.0f) * (skyGradient * 0.95f + 0.05f)
val blockLightBrightness = (connection.world.dimension?.brightness?.get(blockLight) ?: 1.0f) * 1.5// ToDo: multiply with time somewhat thing?
var color = Vec3(blockLightBrightness, blockLightBrightness * ((blockLightBrightness * 0.6f + 0.4f) * 0.6f + 0.4f), blockLightBrightness * (blockLightBrightness * blockLightBrightness * 0.6f + 0.4f))