wip face culling

This commit is contained in:
Bixilon 2023-06-05 00:40:26 +02:00
parent 47366750e0
commit 10ffa3818e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 85 additions and 2 deletions

View File

@ -31,6 +31,7 @@ class BakedFace(
val tintIndex: Int,
val cull: Directions?,
val texture: AbstractTexture,
val size: SideSize.FaceSize?,
) {
private var cullIndex = cull?.ordinal ?: SELF_LIGHT_INDEX

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.models.block.state.baked
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.world.positions.BlockPosition
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.cull.FaceCulling
import de.bixilon.minosoft.gui.rendering.models.block.state.render.BlockRender
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh
@ -33,9 +34,13 @@ class BakedModel(
var rendered = false
for ((index, faces) in faces.withIndex()) {
if (neighbours[index] != null) continue // TODO
for ((direction, faces) in faces.withIndex()) {
val neighbour = neighbours[direction]
for (face in faces) {
if (FaceCulling.canCull(face, neighbour)) {
continue
}
face.render(offset, mesh, light, tints)
rendered = true

View File

@ -0,0 +1,31 @@
/*
* Minosoft
* Copyright (C) 2020-2023 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.models.block.state.baked.cull
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedFace
object FaceCulling {
fun canCull(face: BakedFace, neighbour: BlockState?): Boolean {
if (neighbour == null) return false
if (!face.touchingSide) return false
return true // TODO
}
private inline val BakedFace.touchingSide: Boolean get() = size != null
}

View File

@ -0,0 +1,46 @@
package de.bixilon.minosoft.gui.rendering.models.block.state.baked.cull
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedFace
import de.bixilon.minosoft.gui.rendering.models.block.state.baked.SideSize
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureTransparencies
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.MemoryTexture
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Test
class FaceCullingTest {
private fun createFace(size: SideSize.FaceSize? = SideSize.FaceSize(Vec2(0), Vec2(1)), transparency: TextureTransparencies = TextureTransparencies.OPAQUE): BakedFace {
return BakedFace(floatArrayOf(), floatArrayOf(), 1.0f, -1, null, MemoryTexture(minosoft("test"), Vec2i.EMPTY), size)
}
private fun createNeighbour(size: SideSize? = SideSize(arrayOf(SideSize.FaceSize(Vec2(0), Vec2(1)))), transparency: TextureTransparencies = TextureTransparencies.OPAQUE): BlockState {
TODO()
}
@Test
fun noNeighbour() {
val face = createFace()
assertFalse(FaceCulling.canCull(face, null))
}
@Test
fun selfNotTouching() {
val face = createFace(null)
val neighbour = createNeighbour()
assertFalse(FaceCulling.canCull(face, neighbour))
}
@Test
fun neighbourNotTouching() {
val face = createFace()
val neighbour = createNeighbour(null)
assertFalse(FaceCulling.canCull(face, neighbour))
}
// TODO: force no cull (e.g. leaves), mix of transparency, mix of side sizes
}