mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
wip billboard text rendering
This commit is contained in:
parent
977127add7
commit
7619b98a6a
@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.entities.feature.register
|
|||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
|
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.feature.hitbox.HitboxManager
|
import de.bixilon.minosoft.gui.rendering.entities.feature.hitbox.HitboxManager
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillboardTextRegister
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.renderer.living.player.PlayerRegister
|
import de.bixilon.minosoft.gui.rendering.entities.renderer.living.player.PlayerRegister
|
||||||
import de.bixilon.minosoft.util.Initializable
|
import de.bixilon.minosoft.util.Initializable
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ class EntityRenderFeatures(renderer: EntitiesRenderer) : Initializable {
|
|||||||
|
|
||||||
val hitbox = HitboxManager(renderer).register()
|
val hitbox = HitboxManager(renderer).register()
|
||||||
val player = PlayerRegister(renderer).register()
|
val player = PlayerRegister(renderer).register()
|
||||||
|
val text = BillboardTextRegister(renderer).register()
|
||||||
|
|
||||||
|
|
||||||
override fun init() {
|
override fun init() {
|
||||||
|
@ -13,12 +13,16 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.entities.feature.text
|
package de.bixilon.minosoft.gui.rendering.entities.feature.text
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.mat4x4.Mat4
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2
|
import de.bixilon.kotlinglm.vec2.Vec2
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
import de.bixilon.minosoft.data.text.ChatComponent
|
import de.bixilon.minosoft.data.text.ChatComponent
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.feature.EntityRenderFeature
|
import de.bixilon.minosoft.gui.rendering.entities.feature.EntityRenderFeature
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
|
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.font.renderer.component.ChatComponentRenderer
|
import de.bixilon.minosoft.gui.rendering.font.renderer.component.ChatComponentRenderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.renderer.element.TextRenderInfo
|
||||||
import de.bixilon.minosoft.gui.rendering.font.renderer.element.TextRenderProperties
|
import de.bixilon.minosoft.gui.rendering.font.renderer.element.TextRenderProperties
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.DepthFunctions
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
|
|
||||||
open class BillboardTextFeature(
|
open class BillboardTextFeature(
|
||||||
@ -26,6 +30,7 @@ open class BillboardTextFeature(
|
|||||||
text: ChatComponent?,
|
text: ChatComponent?,
|
||||||
) : EntityRenderFeature(renderer) {
|
) : EntityRenderFeature(renderer) {
|
||||||
private var mesh: BillboardTextMesh? = null
|
private var mesh: BillboardTextMesh? = null
|
||||||
|
private var info: TextRenderInfo? = null
|
||||||
var text: ChatComponent? = text
|
var text: ChatComponent? = text
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field == value) return
|
if (field == value) return
|
||||||
@ -35,20 +40,32 @@ open class BillboardTextFeature(
|
|||||||
|
|
||||||
override fun update(millis: Long, delta: Float) {
|
override fun update(millis: Long, delta: Float) {
|
||||||
if (!enabled) return unload()
|
if (!enabled) return unload()
|
||||||
|
if (this.mesh != null) return // matrix, ...?
|
||||||
val text = this.text ?: return unload()
|
val text = this.text ?: return unload()
|
||||||
if (text.length == 0) return unload()
|
if (text.length == 0) return unload()
|
||||||
|
|
||||||
|
createMesh(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createMesh(text: ChatComponent) {
|
private fun createMesh(text: ChatComponent) {
|
||||||
val mesh = BillboardTextMesh(renderer.renderer.context)
|
val mesh = BillboardTextMesh(renderer.renderer.context)
|
||||||
val properties = TextRenderProperties()
|
val info = ChatComponentRenderer.render3d(renderer.renderer.context, PROPERTIES, MAX_SIZE, mesh, text)
|
||||||
ChatComponentRenderer.render3d(renderer.renderer.context, properties, Vec2(Int.MAX_VALUE), mesh, text)
|
|
||||||
|
|
||||||
|
this.mesh = mesh
|
||||||
|
this.info = info
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun draw() {
|
override fun draw() {
|
||||||
// TODO: shader
|
val mesh = this.mesh ?: return
|
||||||
mesh?.draw()
|
if (mesh.state != Mesh.MeshStates.LOADED) mesh.load()
|
||||||
|
renderer.renderer.context.system.reset(depth = DepthFunctions.ALWAYS)
|
||||||
|
val shader = renderer.renderer.features.text.shader
|
||||||
|
shader.use()
|
||||||
|
val matrix = Mat4()
|
||||||
|
.translateAssign(Vec3(renderer.entity.renderInfo.position + renderer.renderer.context.camera.offset.offset) + Vec3(0, 2, 0))
|
||||||
|
shader.matrix = matrix
|
||||||
|
mesh.draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateVisibility(occluded: Boolean) {
|
override fun updateVisibility(occluded: Boolean) {
|
||||||
@ -57,7 +74,14 @@ open class BillboardTextFeature(
|
|||||||
|
|
||||||
override fun unload() {
|
override fun unload() {
|
||||||
val mesh = this.mesh ?: return
|
val mesh = this.mesh ?: return
|
||||||
|
this.mesh = null
|
||||||
|
this.info = null
|
||||||
if (mesh.state != Mesh.MeshStates.LOADED) return
|
if (mesh.state != Mesh.MeshStates.LOADED) return
|
||||||
renderer.renderer.queue += { mesh.unload() }
|
renderer.renderer.queue += { mesh.unload() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
val PROPERTIES = TextRenderProperties(allowNewLine = false)
|
||||||
|
val MAX_SIZE = Vec2(150.0f, PROPERTIES.lineHeight)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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.entities.feature.text
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.register.FeatureRegister
|
||||||
|
|
||||||
|
class BillboardTextRegister(renderer: EntitiesRenderer) : FeatureRegister {
|
||||||
|
val shader = renderer.context.system.createShader(minosoft("entities/features/text"), ::BillboardTextShader)
|
||||||
|
|
||||||
|
override fun postInit() {
|
||||||
|
shader.load()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.entities.feature.text
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.mat4x4.Mat4
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
|
import de.bixilon.minosoft.gui.rendering.camera.FogManager
|
||||||
|
import de.bixilon.minosoft.gui.rendering.light.LightmapBuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.shader.types.FogShader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.shader.types.LightShader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.shader.types.TextureShader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.shader.types.ViewProjectionShader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
||||||
|
|
||||||
|
class BillboardTextShader(
|
||||||
|
override val native: NativeShader,
|
||||||
|
) : Shader(), TextureShader, LightShader, ViewProjectionShader, FogShader {
|
||||||
|
override var textures: TextureManager by textureManager()
|
||||||
|
override val lightmap: LightmapBuffer by lightmap()
|
||||||
|
override var viewProjectionMatrix: Mat4 by viewProjectionMatrix()
|
||||||
|
override var cameraPosition: Vec3 by cameraPosition()
|
||||||
|
override var fog: FogManager by fog()
|
||||||
|
var matrix: Mat4 by uniform("uMatrix", Mat4())
|
||||||
|
}
|
@ -16,7 +16,7 @@
|
|||||||
layout (location = 0) in vec3 vinPosition;
|
layout (location = 0) in vec3 vinPosition;
|
||||||
layout (location = 1) in vec2 vinUV;
|
layout (location = 1) in vec2 vinUV;
|
||||||
layout (location = 2) in float vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000), animation index (0x00000FFF)
|
layout (location = 2) in float vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000), animation index (0x00000FFF)
|
||||||
layout (location = 3) in float vinTintColorAndLight;// Light (0xFF000000); 3 bytes color (0x00FFFFFF)
|
layout (location = 3) in float vinLightTint;// Light (0xFF000000); 3 bytes color (0x00FFFFFF)
|
||||||
|
|
||||||
#include "minosoft:animation/header_vertex"
|
#include "minosoft:animation/header_vertex"
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ uniform mat4 uViewProjectionMatrix;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = uViewProjectionMatrix * vec4(vinPosition, 1.0f);
|
gl_Position = uViewProjectionMatrix * vec4(vinPosition, 1.0f);
|
||||||
uint tintColorAndLight = floatBitsToUint(vinTintColorAndLight);
|
uint lightTint = floatBitsToUint(vinLightTint);
|
||||||
finTintColor = getRGBColor(tintColorAndLight & 0xFFFFFFu) * getLight(tintColorAndLight >> 24u);
|
finTintColor = getRGBColor(lightTint & 0xFFFFFFu) * getLight(lightTint >> 24u);
|
||||||
finFragmentPosition = vinPosition;
|
finFragmentPosition = vinPosition;
|
||||||
|
|
||||||
run_animation();
|
run_animation();
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
layout (location = 0) in vec3 vinPosition;
|
layout (location = 0) in vec3 vinPosition;
|
||||||
layout (location = 1) in vec2 vinUV;
|
layout (location = 1) in vec2 vinUV;
|
||||||
layout (location = 2) in float vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000)
|
layout (location = 2) in float vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000)
|
||||||
layout (location = 3) in float vinTintColorAndLight;// Light (0xFF000000); 3 bytes color (0x00FFFFFF)
|
layout (location = 3) in float vinLightTint;// Light (0xFF000000); 3 bytes color (0x00FFFFFF)
|
||||||
|
|
||||||
uniform mat4 uViewProjectionMatrix;
|
uniform mat4 uViewProjectionMatrix;
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ out vec4 finTintColor;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = uViewProjectionMatrix * vec4(vinPosition, 1.0f);
|
gl_Position = uViewProjectionMatrix * vec4(vinPosition, 1.0f);
|
||||||
uint tintColorAndLight = floatBitsToUint(vinTintColorAndLight);
|
uint lightTint = floatBitsToUint(vinLightTint);
|
||||||
finTintColor = getRGBColor(tintColorAndLight & 0xFFFFFFu) * getLight(tintColorAndLight >> 24u);
|
finTintColor = getRGBColor(lightTint & 0xFFFFFFu) * getLight(lightTint >> 24u);
|
||||||
finFragmentPosition = vinPosition;
|
finFragmentPosition = vinPosition;
|
||||||
|
|
||||||
uint indexLayerAnimation = floatBitsToUint(vinIndexLayerAnimation);
|
uint indexLayerAnimation = floatBitsToUint(vinIndexLayerAnimation);
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#version 330 core
|
||||||
|
|
||||||
|
out vec4 foutColor;
|
||||||
|
|
||||||
|
|
||||||
|
flat in uint finTextureIndex;
|
||||||
|
in vec3 finTextureCoordinates;
|
||||||
|
|
||||||
|
in vec4 finTintColor;
|
||||||
|
|
||||||
|
|
||||||
|
#include "minosoft:texture"
|
||||||
|
#include "minosoft:alpha"
|
||||||
|
#include "minosoft:fog"
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 texelColor = getTexture(finTextureIndex, finTextureCoordinates, 0.0f);
|
||||||
|
discard_if_0(texelColor.a);
|
||||||
|
|
||||||
|
foutColor = texelColor * finTintColor;
|
||||||
|
set_alpha_transparent();
|
||||||
|
|
||||||
|
set_fog();
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 vinPosition;
|
||||||
|
layout (location = 1) in vec2 vinUV;
|
||||||
|
layout (location = 2) in float vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000)
|
||||||
|
layout (location = 3) in float vinLightTint;// Light (0xFF000000); 3 bytes color (0x00FFFFFF)
|
||||||
|
|
||||||
|
uniform mat4 uViewProjectionMatrix;
|
||||||
|
uniform mat4 uMatrix;
|
||||||
|
|
||||||
|
|
||||||
|
flat out uint finTextureIndex;
|
||||||
|
out vec3 finTextureCoordinates;
|
||||||
|
out vec3 finFragmentPosition;
|
||||||
|
|
||||||
|
out vec4 finTintColor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "minosoft:color"
|
||||||
|
#include "minosoft:light"
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = uViewProjectionMatrix * uMatrix * vec4(vinPosition, 1.0f);
|
||||||
|
uint lightTint = floatBitsToUint(vinLightTint);
|
||||||
|
finTintColor = getRGBColor(lightTint & 0xFFFFFFu);// * getLight(lightTint >> 24u); // TODO
|
||||||
|
finFragmentPosition = vinPosition;
|
||||||
|
|
||||||
|
uint indexLayerAnimation = floatBitsToUint(vinIndexLayerAnimation);
|
||||||
|
finTextureIndex = indexLayerAnimation >> 28u;
|
||||||
|
finTextureCoordinates = vec3(vinUV, ((indexLayerAnimation >> 12) & 0xFFFFu));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user