fix 3d biome detection, fix some transparency issues

This commit is contained in:
Bixilon 2021-03-10 16:54:51 +01:00
parent d43c0bddc9
commit e5c8f43aa9
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
11 changed files with 87 additions and 26 deletions

View File

@ -46,6 +46,8 @@ data class Dimension(
height / ProtocolDefinition.SECTION_HEIGHT_Y
}
val supports3DBiomes = resourceLocation.full != "minecraft:overworld" // ToDo
override fun toString(): String {
return resourceLocation.toString()
}

View File

@ -18,5 +18,5 @@ import de.bixilon.minosoft.data.world.BlockPosition
interface BiomeAccessor {
fun getBiome(position: BlockPosition): Biome?
fun getBiome(position: BlockPosition, is3d: Boolean = true): Biome?
}

View File

@ -17,7 +17,8 @@ import de.bixilon.minosoft.data.mappings.biomes.Biome
import de.bixilon.minosoft.data.world.BlockPosition
class DummyBiomeAccessor(private val biome: Biome) : BiomeAccessor {
override fun getBiome(position: BlockPosition): Biome {
override fun getBiome(position: BlockPosition, is3d: Boolean): Biome {
return biome
}
}

View File

@ -20,9 +20,14 @@ class NoiseBiomeAccessor(
private val biomes: Array<Biome>,
) : BiomeAccessor {
override fun getBiome(position: BlockPosition): Biome? {
override fun getBiome(position: BlockPosition, is3d: Boolean): Biome? {
val inChunk = position.getInChunkSectionPosition()
val index = (inChunk.y / 4 * 16 + ((inChunk.z / 4 * 4) + (inChunk.x / 4)))
val y = if (is3d) {
inChunk.y / 4 * 16
} else {
0
}
val index = (y + ((inChunk.z / 4 * 4) + (inChunk.x / 4)))
if (index < 0 || index > biomes.size) {
return null
}

View File

@ -20,7 +20,7 @@ class XZBiomeAccessor(
private val biomes: Array<Biome>,
) : BiomeAccessor {
override fun getBiome(position: BlockPosition): Biome {
override fun getBiome(position: BlockPosition, is3d: Boolean): Biome {
return biomes[(position.x and 0x0F) or ((position.z and 0x0F) shl 4)]
}
}

View File

@ -206,14 +206,14 @@ class Camera(
headLocation = Position(cameraPosition)
feetLocation = Position(headLocation.x, headLocation.y - PLAYER_HEIGHT, headLocation.z)
blockPosition = feetLocation.toBlockPosition()
currentBiome = connection.player.world.getChunk(blockPosition.getChunkPosition())?.biomeAccessor?.getBiome(blockPosition)
currentBiome = connection.player.world.getChunk(blockPosition.getChunkPosition())?.biomeAccessor?.getBiome(blockPosition, connection.player.world.dimension?.supports3DBiomes ?: false)
chunkPosition = blockPosition.getChunkPosition()
sectionHeight = blockPosition.getSectionHeight()
inChunkSectionPosition = blockPosition.getInChunkSectionPosition()
// recalculate sky color for current biome
val blockPosition = Position(cameraPosition).toBlockPosition()
renderWindow.setSkyColor(connection.player.world.getChunk(blockPosition.getChunkPosition())?.biomeAccessor?.getBiome(blockPosition)?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR)
renderWindow.setSkyColor(connection.player.world.getChunk(blockPosition.getChunkPosition())?.biomeAccessor?.getBiome(blockPosition, connection.player.world.dimension?.supports3DBiomes ?: false)?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR)
connection.renderer.renderWindow.worldRenderer.recalculateFrustum(Frustum(this))
connection.player.world.dimension?.hasSkyLight?.let {
if (it) {

View File

@ -29,6 +29,7 @@ object RenderConstants {
val EXPERIENCE_BAR_LEVEL_COLOR = RGBColor("#80ff20")
val HP_TEXT_COLOR = RGBColor("#ff1313")
const val COLORMAP_SIZE = 255

View File

@ -53,7 +53,7 @@ class WorldRenderer(
visibleChunks.add(chunkPosition)
}
val chunk = world.getChunk(chunkPosition)!!
val dimensionSupports3dBiomes = connection.player.world.dimension?.supports3DBiomes ?: false
val mesh = ChunkMesh()
for ((index, blockInfo) in section.blocks.withIndex()) {
@ -67,7 +67,7 @@ class WorldRenderer(
neighborBlocks[direction.ordinal] = world.getBlockInfo(blockPosition + direction)
}
val biome = chunk.biomeAccessor!!.getBiome(blockPosition)
val biome = chunk.biomeAccessor!!.getBiome(blockPosition, dimensionSupports3dBiomes)
var tintColor: RGBColor? = null
if (StaticConfiguration.BIOME_DEBUG_MODE) {
@ -106,6 +106,12 @@ class WorldRenderer(
override fun postInit() {
renderWindow.textures.use(chunkShader, "textureArray")
for (block in connection.version.mapping.blockStateIdMap.values) {
for (model in block.renders) {
model.postInit()
}
}
}
override fun draw() {
@ -143,6 +149,7 @@ class WorldRenderer(
return textures
}
fun prepareChunk(chunkPosition: ChunkPosition, chunk: Chunk? = world.getChunk(chunkPosition), checkQueued: Boolean = true) {
if (chunk == null || !chunk.isFullyLoaded) {
return
@ -193,17 +200,17 @@ class WorldRenderer(
}
fun prepareChunkSection(chunkPosition: ChunkPosition, sectionHeight: Int, section: ChunkSection) {
Minosoft.THREAD_POOL.execute {
val mesh = prepareChunk(chunkPosition, sectionHeight, section)
Minosoft.THREAD_POOL.execute {
val mesh = prepareChunk(chunkPosition, sectionHeight, section)
var sectionMap = chunkSectionsToDraw[chunkPosition]
if (sectionMap == null) {
sectionMap = ConcurrentHashMap()
chunkSectionsToDraw[chunkPosition] = sectionMap
}
renderWindow.renderQueue.add {
mesh.load()
sectionMap[sectionHeight]?.unload()
var sectionMap = chunkSectionsToDraw[chunkPosition]
if (sectionMap == null) {
sectionMap = ConcurrentHashMap()
chunkSectionsToDraw[chunkPosition] = sectionMap
}
renderWindow.renderQueue.add {
mesh.load()
sectionMap[sectionHeight]?.unload()
sectionMap[sectionHeight] = mesh
}
}

View File

@ -24,6 +24,7 @@ import de.bixilon.minosoft.data.world.light.LightAccessor
import de.bixilon.minosoft.gui.rendering.chunk.ChunkMesh
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
import de.bixilon.minosoft.gui.rendering.textures.Texture
import de.bixilon.minosoft.gui.rendering.textures.TextureTransparencies
import glm_.mat4x4.Mat4
class BlockRenderer {
@ -67,18 +68,38 @@ class BlockRenderer {
textureMapping[key] = texture!!
}
}
}
fun postInit() {
for (direction in Directions.DIRECTIONS) {
var directionIsCullface: Boolean? = null
var directionIsNotTransparent: Boolean? = null
var directionIsFull: Boolean? = null
for (element in elements) {
if (element.isCullFace(direction)) {
cullFaces.add(direction)
directionIsCullface = true
}
if (textureMapping[element.getTexture(direction)]?.isTransparent == true) { // THIS IS BROKEN!
transparentFaces.add(direction)
if (textureMapping[element.getTexture(direction)]?.transparency != TextureTransparencies.OPAQUE) {
if (directionIsNotTransparent == null) {
directionIsNotTransparent = false
}
} else {
directionIsNotTransparent = true
}
if (element.isFullTowards(direction)) {
fullFaceDirections.add(direction)
directionIsFull = true
}
}
if (directionIsCullface == true) {
cullFaces.add(direction)
}
if (directionIsNotTransparent == false) {
transparentFaces.add(direction)
}
if (directionIsFull == true) {
fullFaceDirections.add(direction)
}
}
}

View File

@ -28,7 +28,8 @@ class Texture(
var layer = -1
var width: Int = 0
var height: Int = 0
var isTransparent: Boolean = false
lateinit var transparency: TextureTransparencies
private set
lateinit var buffer: ByteBuffer
var loaded = false
@ -49,10 +50,13 @@ class Texture(
width = decoder.width
height = decoder.height
buffer.rewind()
transparency = TextureTransparencies.OPAQUE
for (i in 0 until buffer.limit() step 4) {
val color = RGBColor(buffer.get(), buffer.get(), buffer.get(), buffer.get())
if (color.alpha < 0xFF) {
isTransparent = true
if (color.alpha == 0x00 && transparency != TextureTransparencies.SEMI_TRANSPARENT) {
transparency = TextureTransparencies.TRANSPARENT
} else if (color.alpha < 0xFF) {
transparency = TextureTransparencies.SEMI_TRANSPARENT
}
}
buffer.flip()

View File

@ -0,0 +1,20 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.textures
enum class TextureTransparencies {
OPAQUE,
TRANSPARENT,
SEMI_TRANSPARENT,
}