rendering: fluid: remove model matrix, fix some optimizer bugs

This commit is contained in:
Bixilon 2021-03-28 15:09:33 +02:00
parent 1729bdbb29
commit 6883f79464
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 22 additions and 26 deletions

View File

@ -256,7 +256,10 @@ class Camera(
} }
private fun sendPositionToServer() { private fun sendPositionToServer() {
if (System.currentTimeMillis() - lastMovementPacketSent > ProtocolDefinition.TICK_TIME) { if (System.currentTimeMillis() - lastMovementPacketSent < ProtocolDefinition.TICK_TIME) {
return
}
if (!currentPositionSent && !currentPositionSent) { if (!currentPositionSent && !currentPositionSent) {
connection.sendPacket(PacketPlayerPositionAndRotationSending(cameraPosition - Vec3(0, PLAYER_HEIGHT, 0), EntityRotation(yaw, pitch), false)) connection.sendPacket(PacketPlayerPositionAndRotationSending(cameraPosition - Vec3(0, PLAYER_HEIGHT, 0), EntityRotation(yaw, pitch), false))
} else if (!currentPositionSent) { } else if (!currentPositionSent) {
@ -269,7 +272,6 @@ class Camera(
currentRotationSent = true currentRotationSent = true
return return
} }
}
fun setPosition(position: Vec3) { fun setPosition(position: Vec3) {
cameraPosition = (position + Vec3(0, PLAYER_HEIGHT, 0)) cameraPosition = (position + Vec3(0, PLAYER_HEIGHT, 0))

View File

@ -65,7 +65,7 @@ class BlockRenderer : BlockRenderInterface {
for (direction in Directions.DIRECTIONS) { for (direction in Directions.DIRECTIONS) {
var directionIsCullFace: Boolean? = null var directionIsCullFace: Boolean? = null
var directionIsNotTransparent: Boolean? = null var directionIsNotTransparent: Boolean? = null
var faceBorderSites: MutableList<FaceSize> = mutableListOf() val faceBorderSites: MutableList<FaceSize> = mutableListOf()
for (element in elements) { for (element in elements) {
if (element.isCullFace(direction)) { if (element.isCullFace(direction)) {
directionIsCullFace = true directionIsCullFace = true
@ -102,7 +102,9 @@ class BlockRenderer : BlockRenderInterface {
val invertedDirection = direction.inverse val invertedDirection = direction.inverse
var isNeighbourTransparent = false var isNeighbourTransparent = false
var neighbourFaceSize: Array<FaceSize>? = null var neighbourFaceSize: Array<FaceSize>? = null
neighbourBlocks[direction.ordinal]?.getBlockRenderer(blockPosition + direction)?.let { val neighbourBlock = neighbourBlocks[direction.ordinal]
// ToDo: We need to rotate the direction first and then rotate it
neighbourBlock?.getBlockRenderer(blockPosition + direction)?.let {
if (it.transparentFaces[invertedDirection.ordinal]) { if (it.transparentFaces[invertedDirection.ordinal]) {
isNeighbourTransparent = true isNeighbourTransparent = true
} }
@ -114,7 +116,6 @@ class BlockRenderer : BlockRenderInterface {
for (element in elements) { for (element in elements) {
var drawElementFace = true var drawElementFace = true
neighbourFaceSize?.let { neighbourFaceSize?.let {
// force draw transparent faces // force draw transparent faces
if (transparentFaces[direction.ordinal] || isNeighbourTransparent) { if (transparentFaces[direction.ordinal] || isNeighbourTransparent) {
@ -129,9 +130,8 @@ class BlockRenderer : BlockRenderInterface {
if (elementFaceBorderSize.end.x > size.end.x || elementFaceBorderSize.end.y > size.end.y) { if (elementFaceBorderSize.end.x > size.end.x || elementFaceBorderSize.end.y > size.end.y) {
return@let return@let
} }
drawElementFace = false
break
} }
drawElementFace = false
} }
if (!drawElementFace) { if (!drawElementFace) {

View File

@ -74,7 +74,7 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo
val face = faces[realDirection] ?: return // Not our face val face = faces[realDirection] ?: return // Not our face
val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[realDirection.ordinal] val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[realDirection.ordinal]
val texture = textureMapping[face.textureName] ?: TODO() val texture = textureMapping[face.textureName] ?: TODO("Unknown texture used ${face.textureName}")
val lightLevel = lightAccessor.getLightLevel(blockPosition + directionMapping[face.cullFace]) // ToDo: rotate cullface val lightLevel = lightAccessor.getLightLevel(blockPosition + directionMapping[face.cullFace]) // ToDo: rotate cullface

View File

@ -15,11 +15,9 @@ import de.bixilon.minosoft.gui.rendering.textures.Texture
import de.bixilon.minosoft.gui.rendering.util.VecUtil import de.bixilon.minosoft.gui.rendering.util.VecUtil
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
import glm_.glm import glm_.glm
import glm_.mat4x4.Mat4
import glm_.vec2.Vec2 import glm_.vec2.Vec2
import glm_.vec3.Vec3 import glm_.vec3.Vec3
import glm_.vec3.Vec3i import glm_.vec3.Vec3i
import glm_.vec4.Vec4
class FluidRenderer( class FluidRenderer(
private val stillTextureName: String, private val stillTextureName: String,
@ -35,8 +33,6 @@ class FluidRenderer(
if (!RenderConstants.RENDER_FLUIDS) { if (!RenderConstants.RENDER_FLUIDS) {
return return
} }
val modelMatrix = Mat4().translate(Vec3(blockPosition))
val lightLevel = lightAccessor.getLightLevel(blockPosition) val lightLevel = lightAccessor.getLightLevel(blockPosition)
val heights = calculateHeights(neighbourBlocks, blockState, world, blockPosition) val heights = calculateHeights(neighbourBlocks, blockState, world, blockPosition)
val isFlowing = isLiquidFlowing(heights) val isFlowing = isLiquidFlowing(heights)
@ -63,7 +59,7 @@ class FluidRenderer(
face.rotate(angle) face.rotate(angle)
val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[direction.ordinal] val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[direction.ordinal]
val drawPositions = arrayOf(positions[positionTemplate[0]], positions[positionTemplate[1]], positions[positionTemplate[2]], positions[positionTemplate[3]]) val drawPositions = arrayOf(positions[positionTemplate[0]], positions[positionTemplate[1]], positions[positionTemplate[2]], positions[positionTemplate[3]])
createQuad(drawPositions, face.getTexturePositionArray(direction), texture, modelMatrix, meshCollection, tintColor, lightLevel) createQuad(drawPositions, face.getTexturePositionArray(direction), texture, blockPosition, meshCollection, tintColor, lightLevel)
} }
} }
@ -110,13 +106,11 @@ class FluidRenderer(
return heights.toSet().size != 1 // liquid is flowing, if not all of the heights are the same return heights.toSet().size != 1 // liquid is flowing, if not all of the heights are the same
} }
private fun createQuad(drawPositions: Array<Vec3>, texturePositions: Array<Vec2?>, texture: Texture, modelMatrix: Mat4, meshCollection: ChunkMeshCollection, tintColor: RGBColor?, lightLevel: Int) { private fun createQuad(drawPositions: Array<Vec3>, texturePositions: Array<Vec2?>, texture: Texture, blockPosition: Vec3i, meshCollection: ChunkMeshCollection, tintColor: RGBColor?, lightLevel: Int) {
val mesh = ElementRenderer.getMesh(meshCollection, texture.transparency) val mesh = ElementRenderer.getMesh(meshCollection, texture.transparency)
for (vertex in ElementRenderer.DRAW_ODER) { for (vertex in ElementRenderer.DRAW_ODER) {
val input = Vec4(drawPositions[vertex.first], 1.0f)
val output = modelMatrix * input
mesh.addVertex( mesh.addVertex(
position = output.toVec3(), position = blockPosition plus drawPositions[vertex.first],
textureCoordinates = texturePositions[vertex.second]!!, textureCoordinates = texturePositions[vertex.second]!!,
texture = texture, texture = texture,
tintColor = tintColor, tintColor = tintColor,