sings: render real text, improve performance, re-enable frustum culling

This commit is contained in:
Bixilon 2022-04-22 14:30:39 +02:00
parent 55d0419040
commit 214959d200
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 41 additions and 31 deletions

View File

@ -189,7 +189,7 @@ object MinecraftBlocks {
val LADDER = "minecraft:ladder".toResourceLocation() val LADDER = "minecraft:ladder".toResourceLocation()
val RAIL = "minecraft:rail".toResourceLocation() val RAIL = "minecraft:rail".toResourceLocation()
val COBBLESTONE_STAIRS = "minecraft:cobblestone_stairs".toResourceLocation() val COBBLESTONE_STAIRS = "minecraft:cobblestone_stairs".toResourceLocation()
val OAK_WALL_SIGN = "minecraft:oak_wall_sign.json".toResourceLocation() val OAK_WALL_SIGN = "minecraft:oak_wall_sign".toResourceLocation()
val SPRUCE_WALL_SIGN = "minecraft:spruce_wall_sign".toResourceLocation() val SPRUCE_WALL_SIGN = "minecraft:spruce_wall_sign".toResourceLocation()
val BIRCH_WALL_SIGN = "minecraft:birch_wall_sign".toResourceLocation() val BIRCH_WALL_SIGN = "minecraft:birch_wall_sign".toResourceLocation()
val ACACIA_WALL_SIGN = "minecraft:acacia_wall_sign".toResourceLocation() val ACACIA_WALL_SIGN = "minecraft:acacia_wall_sign".toResourceLocation()

View File

@ -33,7 +33,7 @@ object RenderConstants {
val TEXT_BACKGROUND_COLOR = RGBColor(0, 0, 0, 80) val TEXT_BACKGROUND_COLOR = RGBColor(0, 0, 0, 80)
const val FRUSTUM_CULLING_ENABLED = false const val FRUSTUM_CULLING_ENABLED = true
const val SHOW_FPS_IN_WINDOW_TITLE = true const val SHOW_FPS_IN_WINDOW_TITLE = true
const val MAXIMUM_QUEUE_TIME_PER_FRAME = 20L const val MAXIMUM_QUEUE_TIME_PER_FRAME = 20L

View File

@ -33,9 +33,9 @@ object BaseComponentRenderer : ChatComponentRenderer<BaseComponent> {
return false return false
} }
override fun render3DFlat(matrix: Mat4, mesh: WorldMesh, text: BaseComponent) { override fun render3dFlat(renderWindow: RenderWindow, matrix: Mat4, scale: Float, mesh: WorldMesh, text: BaseComponent, light: Int) {
for (part in text.parts) { for (part in text.parts) {
ChatComponentRenderer.render3DFlat(matrix, mesh, text) ChatComponentRenderer.render3dFlat(renderWindow, matrix, scale, mesh, part, light)
} }
} }
} }

View File

@ -17,11 +17,9 @@ import de.bixilon.kotlinglm.mat4x4.Mat4
import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.minosoft.data.text.BaseComponent import de.bixilon.minosoft.data.text.BaseComponent
import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.TextComponent import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.gui.rendering.RenderWindow import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.font.Font
import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.Element
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
@ -35,7 +33,7 @@ interface ChatComponentRenderer<T : ChatComponent> {
*/ */
fun render(initialOffset: Vec2i, offset: Vec2i, size: Vec2i, element: Element, renderWindow: RenderWindow, consumer: GUIVertexConsumer?, options: GUIVertexOptions?, renderInfo: TextRenderInfo, text: T): Boolean fun render(initialOffset: Vec2i, offset: Vec2i, size: Vec2i, element: Element, renderWindow: RenderWindow, consumer: GUIVertexConsumer?, options: GUIVertexOptions?, renderInfo: TextRenderInfo, text: T): Boolean
fun render3DFlat(matrix: Mat4, mesh: WorldMesh, text: T) fun render3dFlat(renderWindow: RenderWindow, matrix: Mat4, scale: Float, mesh: WorldMesh, text: T, light: Int)
companion object : ChatComponentRenderer<ChatComponent> { companion object : ChatComponentRenderer<ChatComponent> {
const val TEXT_BLOCK_RESOLUTION = 128 const val TEXT_BLOCK_RESOLUTION = 128
@ -48,32 +46,22 @@ interface ChatComponentRenderer<T : ChatComponent> {
} }
} }
override fun render3DFlat(matrix: Mat4, mesh: WorldMesh, text: ChatComponent) { override fun render3dFlat(renderWindow: RenderWindow, matrix: Mat4, scale: Float, mesh: WorldMesh, text: ChatComponent, light: Int) {
when (text) { when (text) {
is BaseComponent -> BaseComponentRenderer.render3DFlat(matrix, mesh, text) is BaseComponent -> BaseComponentRenderer.render3dFlat(renderWindow, matrix, scale, mesh, text, light)
is TextComponent -> TextComponentRenderer.render3DFlat(matrix, mesh, text) is TextComponent -> TextComponentRenderer.render3dFlat(renderWindow, matrix, scale, mesh, text, light)
else -> TODO("Don't know how to render ${text::class.java}") else -> TODO("Don't know how to render ${text::class.java}")
} }
} }
fun render3dFlat(renderWindow: RenderWindow, position: Vec3, scale: Float, rotation: Vec3, mesh: WorldMesh, text: ChatComponent, light: Int) { fun render3dFlat(renderWindow: RenderWindow, position: Vec3, scale: Float, rotation: Vec3, mesh: WorldMesh, text: ChatComponent, light: Int) {
val rotationMatrix = Mat4() val matrix = Mat4()
.translateAssign(position)
.rotateDegreesAssign(rotation) .rotateDegreesAssign(rotation)
.translateAssign(Vec3(0, 0, -1)) .translateAssign(Vec3(0, 0, -1))
val positionMatrix = Mat4()
.translateAssign(position)
val transformMatrix = positionMatrix * rotationMatrix render3dFlat(renderWindow, matrix, scale, mesh, text, light)
val text = "abcdefghijklmnop"
for ((index, char) in text.codePoints().toArray().withIndex()) {
val data = renderWindow.font[char] ?: continue
val color = ChatColors[index % ChatColors.VALUES.size]
val width = data.render3d(transformMatrix, mesh, color, shadow = false, italic = false, bold = false, strikethrough = false, underlined = false, scale = scale, light = light) + Font.HORIZONTAL_SPACING
transformMatrix.translateAssign(Vec3((width / TEXT_BLOCK_RESOLUTION) * scale, 0, 0))
}
} }
} }
} }

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.font.renderer
import de.bixilon.kotlinglm.mat4x4.Mat4 import de.bixilon.kotlinglm.mat4x4.Mat4
import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.minosoft.data.text.ChatColors import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.PreChatFormattingCodes import de.bixilon.minosoft.data.text.PreChatFormattingCodes
import de.bixilon.minosoft.data.text.TextComponent import de.bixilon.minosoft.data.text.TextComponent
@ -189,7 +190,12 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
return false return false
} }
override fun render3DFlat(matrix: Mat4, mesh: WorldMesh, text: TextComponent) { override fun render3dFlat(renderWindow: RenderWindow, matrix: Mat4, scale: Float, mesh: WorldMesh, text: TextComponent, light: Int) {
TODO("Not yet implemented") for ((index, char) in text.message.codePoints().toArray().withIndex()) {
val data = renderWindow.font[char] ?: continue
val color = ChatColors[index % ChatColors.VALUES.size]
val width = data.render3d(matrix, mesh, color, shadow = false, italic = false, bold = false, strikethrough = false, underlined = false, scale = scale, light = light) + Font.HORIZONTAL_SPACING
matrix.translateAssign(Vec3((width / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION) * scale, 0, 0))
}
} }
} }

View File

@ -21,7 +21,6 @@ interface MeshedBlockEntityRenderer<E : BlockEntity> : BlockEntityRenderer<E>, S
override var light: Int override var light: Int
get() = 0 get() = 0
set(value) {} set(value) {}
override fun draw(renderWindow: RenderWindow) = Unit override fun draw(renderWindow: RenderWindow) = Unit
override fun load() = Unit override fun load() = Unit
override fun unload() = Unit override fun unload() = Unit

View File

@ -0,0 +1,18 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.world.entities
import de.bixilon.minosoft.data.entities.block.BlockEntity
interface OnlyMeshedBlockEntityRenderer<E : BlockEntity> : MeshedBlockEntityRenderer<E>

View File

@ -30,7 +30,7 @@ import de.bixilon.minosoft.gui.rendering.font.renderer.ChatComponentRenderer
import de.bixilon.minosoft.gui.rendering.models.unbaked.element.UnbakedElement import de.bixilon.minosoft.gui.rendering.models.unbaked.element.UnbakedElement
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3 import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.rotateAssign import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.rotateAssign
import de.bixilon.minosoft.gui.rendering.world.entities.MeshedBlockEntityRenderer import de.bixilon.minosoft.gui.rendering.world.entities.OnlyMeshedBlockEntityRenderer
import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh
import de.bixilon.minosoft.gui.rendering.world.preparer.cull.SolidCullSectionPreparer import de.bixilon.minosoft.gui.rendering.world.preparer.cull.SolidCullSectionPreparer
import de.bixilon.minosoft.util.Broken import de.bixilon.minosoft.util.Broken
@ -40,7 +40,7 @@ class SignBlockEntityRenderer(
val sign: SignBlockEntity, val sign: SignBlockEntity,
val renderWindow: RenderWindow, val renderWindow: RenderWindow,
override val blockState: BlockState, override val blockState: BlockState,
) : MeshedBlockEntityRenderer<SignBlockEntity> { ) : OnlyMeshedBlockEntityRenderer<SignBlockEntity> {
override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean { override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean {
val block = this.blockState.block val block = this.blockState.block
@ -87,9 +87,7 @@ class SignBlockEntityRenderer(
private fun Vec3.signRotate(yRotation: Float) { private fun Vec3.signRotate(yRotation: Float) {
this -= 0.5f this -= 0.5f
rotateAssign(yRotation, Axes.Y) rotateAssign(yRotation, Axes.Y)
this += 0.5f this += 0.5f
} }

View File

@ -34,6 +34,7 @@ import de.bixilon.minosoft.gui.rendering.models.SingleBlockRenderable
import de.bixilon.minosoft.gui.rendering.util.VecUtil import de.bixilon.minosoft.gui.rendering.util.VecUtil
import de.bixilon.minosoft.gui.rendering.world.entities.BlockEntityRenderer import de.bixilon.minosoft.gui.rendering.world.entities.BlockEntityRenderer
import de.bixilon.minosoft.gui.rendering.world.entities.MeshedBlockEntityRenderer import de.bixilon.minosoft.gui.rendering.world.entities.MeshedBlockEntityRenderer
import de.bixilon.minosoft.gui.rendering.world.entities.OnlyMeshedBlockEntityRenderer
import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh
import de.bixilon.minosoft.gui.rendering.world.preparer.SolidSectionPreparer import de.bixilon.minosoft.gui.rendering.world.preparer.SolidSectionPreparer
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
@ -92,7 +93,7 @@ class SolidCullSectionPreparer(
position = Vec3i(offsetX + x, offsetY + y, offsetZ + z) position = Vec3i(offsetX + x, offsetY + y, offsetZ + z)
blockEntity = section.blockEntities.unsafeGet(x, y, z) blockEntity = section.blockEntities.unsafeGet(x, y, z)
val blockEntityModel = blockEntity?.getRenderer(renderWindow, blockState, position, light[SELF_LIGHT_INDEX].toInt()) val blockEntityModel = blockEntity?.getRenderer(renderWindow, blockState, position, light[SELF_LIGHT_INDEX].toInt())
if (blockEntityModel != null) { if (blockEntityModel != null && (blockEntityModel !is OnlyMeshedBlockEntityRenderer)) {
blockEntities += blockEntityModel blockEntities += blockEntityModel
mesh.addBlock(x, y, z) mesh.addBlock(x, y, z)
} }