mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
flashing block renderer
This commit is contained in:
parent
ddcb339999
commit
57eac06abf
@ -27,7 +27,7 @@ import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
|||||||
open class BlockFeature(
|
open class BlockFeature(
|
||||||
renderer: EntityRenderer<*>,
|
renderer: EntityRenderer<*>,
|
||||||
state: BlockState?,
|
state: BlockState?,
|
||||||
var scale: Vec3 = Vec3(0.99f),
|
var scale: Vec3 = DEFAULT_SCALE,
|
||||||
) : EntityRenderFeature(renderer) {
|
) : EntityRenderFeature(renderer) {
|
||||||
private var mesh: BlockMesh? = null
|
private var mesh: BlockMesh? = null
|
||||||
private var matrix = Mat4()
|
private var matrix = Mat4()
|
||||||
@ -82,6 +82,10 @@ open class BlockFeature(
|
|||||||
if (mesh.state != Mesh.MeshStates.LOADED) mesh.load()
|
if (mesh.state != Mesh.MeshStates.LOADED) mesh.load()
|
||||||
renderer.renderer.context.system.reset(faceCulling = false)
|
renderer.renderer.context.system.reset(faceCulling = false)
|
||||||
val shader = renderer.renderer.features.block.shader
|
val shader = renderer.renderer.features.block.shader
|
||||||
|
draw(mesh, shader)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun draw(mesh: BlockMesh, shader: BlockShader) {
|
||||||
shader.use()
|
shader.use()
|
||||||
shader.matrix = matrix
|
shader.matrix = matrix
|
||||||
shader.tint = renderer.light.value
|
shader.tint = renderer.light.value
|
||||||
@ -93,4 +97,8 @@ open class BlockFeature(
|
|||||||
this.mesh = null
|
this.mesh = null
|
||||||
renderer.renderer.queue += { mesh.unload() }
|
renderer.renderer.queue += { mesh.unload() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val DEFAULT_SCALE = Vec3(0.99f)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,15 @@ package de.bixilon.minosoft.gui.rendering.entities.feature.block
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
|
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.block.flashing.FlashingBlockShader
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.feature.register.FeatureRegister
|
import de.bixilon.minosoft.gui.rendering.entities.feature.register.FeatureRegister
|
||||||
|
|
||||||
class BlockRegister(renderer: EntitiesRenderer) : FeatureRegister {
|
class BlockRegister(renderer: EntitiesRenderer) : FeatureRegister {
|
||||||
val shader = renderer.context.system.createShader(minosoft("entities/features/block"), ::BlockShader)
|
val shader = renderer.context.system.createShader(minosoft("entities/features/block"), ::BlockShader)
|
||||||
|
val flashing = renderer.context.system.createShader(minosoft("entities/features/block/flashing"), ::FlashingBlockShader)
|
||||||
|
|
||||||
override fun postInit() {
|
override fun postInit() {
|
||||||
shader.load()
|
shader.load()
|
||||||
|
flashing.load()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ 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.shader.NativeShader
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
||||||
|
|
||||||
class BlockShader(
|
open class BlockShader(
|
||||||
override val native: NativeShader,
|
override val native: NativeShader,
|
||||||
) : Shader(), TextureShader, ViewProjectionShader, FogShader, TintedShader {
|
) : Shader(), TextureShader, ViewProjectionShader, FogShader, TintedShader {
|
||||||
override var textures: TextureManager by textureManager()
|
override var textures: TextureManager by textureManager()
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.block.flashing
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
|
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
|
||||||
|
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||||
|
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.block.BlockFeature
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.block.BlockMesh
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.block.BlockShader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
|
||||||
|
open class FlashingBlockFeature(
|
||||||
|
renderer: EntityRenderer<*>,
|
||||||
|
state: BlockState?,
|
||||||
|
scale: Vec3 = DEFAULT_SCALE,
|
||||||
|
var flashColor: RGBColor = ChatColors.WHITE,
|
||||||
|
var flashInterval: Float = 0.2f,
|
||||||
|
var maxFlash: Float = 0.5f
|
||||||
|
) : BlockFeature(renderer, state, scale) {
|
||||||
|
private var progress = 0.0f
|
||||||
|
|
||||||
|
|
||||||
|
override fun update(millis: Long, delta: Float) {
|
||||||
|
super.update(millis, delta)
|
||||||
|
updateFlashing(delta)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateFlashing(delta: Float) {
|
||||||
|
if (delta > flashInterval) return
|
||||||
|
progress += (delta / flashInterval)
|
||||||
|
if (progress > maxFlash) {
|
||||||
|
progress -= maxFlash * 2.0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw(mesh: BlockMesh, shader: BlockShader) {
|
||||||
|
val shader = renderer.renderer.features.block.flashing
|
||||||
|
shader.use()
|
||||||
|
shader.flashColor = flashColor
|
||||||
|
shader.flashProgress = abs(progress)
|
||||||
|
super.draw(mesh, shader)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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.block.flashing
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.block.BlockShader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader
|
||||||
|
|
||||||
|
class FlashingBlockShader(
|
||||||
|
native: NativeShader,
|
||||||
|
) : BlockShader(native) {
|
||||||
|
var flashColor by uniform("uFlashColor", ChatColors.WHITE) { shader, name, value -> shader.setUInt(name, value.rgb) }
|
||||||
|
var flashProgress by uniform("uFlashProgress", 0.0f)
|
||||||
|
}
|
@ -18,10 +18,10 @@ import de.bixilon.minosoft.data.registries.blocks.MinecraftBlocks
|
|||||||
import de.bixilon.minosoft.data.registries.identified.Identified
|
import de.bixilon.minosoft.data.registries.identified.Identified
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
|
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.factory.RegisteredEntityModelFactory
|
import de.bixilon.minosoft.gui.rendering.entities.factory.RegisteredEntityModelFactory
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.feature.block.BlockFeature
|
import de.bixilon.minosoft.gui.rendering.entities.feature.block.flashing.FlashingBlockFeature
|
||||||
|
|
||||||
class PrimedTNTEntityRenderer(renderer: EntitiesRenderer, entity: PrimedTNT) : EntityRenderer<PrimedTNT>(renderer, entity) {
|
class PrimedTNTEntityRenderer(renderer: EntitiesRenderer, entity: PrimedTNT) : EntityRenderer<PrimedTNT>(renderer, entity) {
|
||||||
val block = BlockFeature(this, renderer.connection.registries.block[MinecraftBlocks.TNT]?.states?.default).register()
|
val block = FlashingBlockFeature(this, renderer.connection.registries.block[MinecraftBlocks.TNT]?.states?.default).register()
|
||||||
|
|
||||||
|
|
||||||
companion object : RegisteredEntityModelFactory<PrimedTNT>, Identified {
|
companion object : RegisteredEntityModelFactory<PrimedTNT>, Identified {
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
uniform float uFlashProgress;
|
||||||
|
|
||||||
|
flat in uint finTextureIndex;
|
||||||
|
in vec3 finTextureCoordinates;
|
||||||
|
|
||||||
|
in vec4 finTintColor;
|
||||||
|
in vec4 finFlashColor;
|
||||||
|
|
||||||
|
#define TRANSPARENT
|
||||||
|
|
||||||
|
#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;
|
||||||
|
foutColor = mix(foutColor, finFlashColor, uFlashProgress);
|
||||||
|
|
||||||
|
set_fog();
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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 vinTint;
|
||||||
|
|
||||||
|
uniform mat4 uViewProjectionMatrix;
|
||||||
|
uniform mat4 uMatrix;
|
||||||
|
uniform uint uTintColor;
|
||||||
|
uniform uint uFlashColor;
|
||||||
|
|
||||||
|
|
||||||
|
flat out uint finTextureIndex;
|
||||||
|
out vec3 finTextureCoordinates;
|
||||||
|
out vec3 finFragmentPosition;
|
||||||
|
|
||||||
|
out vec4 finTintColor;
|
||||||
|
out vec4 finFlashColor;
|
||||||
|
|
||||||
|
|
||||||
|
#include "minosoft:color"
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 position = uMatrix * vec4(vinPosition, 1.0f);
|
||||||
|
gl_Position = uViewProjectionMatrix * position;
|
||||||
|
finTintColor = getRGBColor(floatBitsToUint(vinTint)) * getRGBColor(uTintColor);
|
||||||
|
finFragmentPosition = position.xyz;
|
||||||
|
|
||||||
|
uint indexLayerAnimation = floatBitsToUint(vinIndexLayerAnimation);
|
||||||
|
finTextureIndex = indexLayerAnimation >> 28u;
|
||||||
|
finTextureCoordinates = vec3(vinUV, ((indexLayerAnimation >> 12) & 0xFFFFu));
|
||||||
|
finFlashColor = getRGBColor(uFlashColor);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user