mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
rendering: improve cullfacing
This commit is contained in:
parent
841d3227b9
commit
6cc781a724
@ -14,7 +14,7 @@ package de.bixilon.minosoft.data
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.FaceBorderSize
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModelElement
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.oneContainsIgnoreZero
|
||||
import glm_.vec2.Vec2i
|
||||
import glm_.vec3.Vec3
|
||||
import glm_.vec3.Vec3i
|
||||
|
||||
@ -55,12 +55,50 @@ enum class Directions(val directionVector: Vec3i) {
|
||||
*/
|
||||
fun getFaceBorderSizes(start: Vec3, end: Vec3): FaceBorderSize? {
|
||||
// check if face is touching the border of a block
|
||||
if (!start.oneContainsIgnoreZero(blockResolutionVectorFloat) && !end.oneContainsIgnoreZero(blockResolutionVectorFloat)) {
|
||||
// not touching the edge face of our direction
|
||||
return null
|
||||
return when (this) {
|
||||
DOWN -> {
|
||||
if (start.y != 0.0f && end.y != 0.0f) {
|
||||
null
|
||||
} else {
|
||||
FaceBorderSize(Vec2i(start.x, start.z), Vec2i(end.x, end.z))
|
||||
}
|
||||
}
|
||||
UP -> {
|
||||
if (start.y != BlockModelElement.BLOCK_RESOLUTION_FLOAT && end.y != BlockModelElement.BLOCK_RESOLUTION_FLOAT) {
|
||||
null
|
||||
} else {
|
||||
FaceBorderSize(Vec2i(start.x, start.z), Vec2i(end.x, end.z))
|
||||
}
|
||||
}
|
||||
NORTH -> {
|
||||
if (start.z != 0.0f && end.z != 0.0f) {
|
||||
null
|
||||
} else {
|
||||
FaceBorderSize(Vec2i(start.x, start.y), Vec2i(end.x, end.y))
|
||||
}
|
||||
}
|
||||
SOUTH -> {
|
||||
if (start.z != BlockModelElement.BLOCK_RESOLUTION_FLOAT && end.z != BlockModelElement.BLOCK_RESOLUTION_FLOAT) {
|
||||
null
|
||||
} else {
|
||||
FaceBorderSize(Vec2i(start.x, start.y), Vec2i(end.x, end.y))
|
||||
}
|
||||
}
|
||||
WEST -> {
|
||||
if (start.x != 0.0f && end.x != 0.0f) {
|
||||
null
|
||||
} else {
|
||||
FaceBorderSize(Vec2i(start.y, start.z), Vec2i(end.y, end.z))
|
||||
}
|
||||
}
|
||||
EAST -> {
|
||||
if (start.x != BlockModelElement.BLOCK_RESOLUTION_FLOAT && end.x != BlockModelElement.BLOCK_RESOLUTION_FLOAT) {
|
||||
null
|
||||
} else {
|
||||
FaceBorderSize(Vec2i(start.y, start.z), Vec2i(end.y, end.z))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FaceBorderSize() // ToDo
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,11 +15,15 @@ package de.bixilon.minosoft.data.world.light
|
||||
|
||||
import de.bixilon.minosoft.data.world.BlockPosition
|
||||
import de.bixilon.minosoft.data.world.World
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
|
||||
class WorldLightAccessor(
|
||||
private val world: World,
|
||||
) : LightAccessor {
|
||||
override fun getSkyLight(blockPosition: BlockPosition): Int {
|
||||
if (RenderConstants.DISABLE_LIGHTING) {
|
||||
return 15
|
||||
}
|
||||
return world.chunks[blockPosition.getChunkPosition()]?.lightAccessor?.getSkyLight(blockPosition) ?: 0
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,8 @@ object RenderConstants {
|
||||
|
||||
const val MAXIMUM_CALLS_PER_FRAME = 10
|
||||
|
||||
const val DISABLE_LIGHTING = true
|
||||
|
||||
const val RENDER_BLOCKS = true
|
||||
const val RENDER_FLUIDS = true
|
||||
const val RENDER_HUD = true
|
||||
|
@ -24,14 +24,11 @@ import glm_.vec3.Vec3
|
||||
open class BlockModelElement(data: JsonObject) {
|
||||
val faces: MutableMap<Directions, BlockModelFace> = mutableMapOf()
|
||||
var transformedPositions: Array<Vec3>
|
||||
val untransformedPositions: Array<Vec3>
|
||||
val from: Vec3 = data["from"]?.asJsonArray?.toVec3() ?: Vec3()
|
||||
val to: Vec3 = data["to"]?.asJsonArray?.toVec3() ?: Vec3(BLOCK_RESOLUTION)
|
||||
|
||||
init {
|
||||
val from = data["from"]?.asJsonArray?.toVec3() ?: Vec3()
|
||||
|
||||
val to = data["to"]?.asJsonArray?.toVec3() ?: Vec3(BLOCK_RESOLUTION)
|
||||
|
||||
untransformedPositions = arrayOf(
|
||||
transformedPositions = arrayOf(
|
||||
Vec3(from),
|
||||
Vec3(to.x, from.y, from.z),
|
||||
Vec3(from.x, from.y, to.z),
|
||||
@ -46,7 +43,7 @@ open class BlockModelElement(data: JsonObject) {
|
||||
val axis = Axes.valueOf(it["axis"].asString.toUpperCase())
|
||||
val angle = glm.radians(it["angle"].asFloat)
|
||||
val rescale = it["rescale"]?.asBoolean ?: false
|
||||
rotatePositions(untransformedPositions, axis, angle, it["origin"].asJsonArray.toVec3(), rescale)
|
||||
rotatePositions(transformedPositions, axis, angle, it["origin"].asJsonArray.toVec3(), rescale)
|
||||
}
|
||||
|
||||
data["faces"]?.asJsonObject?.let {
|
||||
@ -57,11 +54,9 @@ open class BlockModelElement(data: JsonObject) {
|
||||
}
|
||||
|
||||
// transformed positions
|
||||
val transformedPositions: MutableList<Vec3> = mutableListOf()
|
||||
for (position in untransformedPositions) {
|
||||
transformedPositions.add(transformPosition(position))
|
||||
for ((index, position) in transformedPositions.withIndex()) {
|
||||
transformedPositions[index] = transformPosition(position)
|
||||
}
|
||||
this.transformedPositions = transformedPositions.toTypedArray()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -38,13 +38,14 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo
|
||||
val faceBorderSize: Array<FaceBorderSize?> = arrayOfNulls(Directions.DIRECTIONS.size)
|
||||
private val faces: MutableMap<Directions, BlockModelFace> = mutableMapOf()
|
||||
private var transformedPositions: Array<Vec3> = parent.transformedPositions.clone()
|
||||
private var untransformedPositions: Array<Vec3> = parent.untransformedPositions.clone()
|
||||
private val directionMapping: HashBiMap<Directions, Directions> = HashBiMap.create()
|
||||
private val from = parent.from
|
||||
private val to = parent.to
|
||||
|
||||
init {
|
||||
rotatePositionsAxes(transformedPositions, rotation, rescale)
|
||||
for (direction in Directions.DIRECTIONS) {
|
||||
direction.getFaceBorderSizes(untransformedPositions.first(), untransformedPositions.last())?.let {
|
||||
direction.getFaceBorderSizes(from, to)?.let {
|
||||
faceBorderSize[direction.ordinal] = it
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user