diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockFeature.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockFeature.kt
index 114720d1a..4ce514a39 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockFeature.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockFeature.kt
@@ -27,7 +27,7 @@ import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
open class BlockFeature(
renderer: EntityRenderer<*>,
state: BlockState?,
- var scale: Vec3 = Vec3(0.99f),
+ var scale: Vec3 = DEFAULT_SCALE,
) : EntityRenderFeature(renderer) {
private var mesh: BlockMesh? = null
private var matrix = Mat4()
@@ -82,6 +82,10 @@ open class BlockFeature(
if (mesh.state != Mesh.MeshStates.LOADED) mesh.load()
renderer.renderer.context.system.reset(faceCulling = false)
val shader = renderer.renderer.features.block.shader
+ draw(mesh, shader)
+ }
+
+ protected open fun draw(mesh: BlockMesh, shader: BlockShader) {
shader.use()
shader.matrix = matrix
shader.tint = renderer.light.value
@@ -93,4 +97,8 @@ open class BlockFeature(
this.mesh = null
renderer.renderer.queue += { mesh.unload() }
}
+
+ companion object {
+ val DEFAULT_SCALE = Vec3(0.99f)
+ }
}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockRegister.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockRegister.kt
index 2043dca60..226da64cb 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockRegister.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockRegister.kt
@@ -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.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
class BlockRegister(renderer: EntitiesRenderer) : FeatureRegister {
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() {
shader.load()
+ flashing.load()
}
}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockShader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockShader.kt
index cb4a2fa20..a2324347b 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockShader.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/BlockShader.kt
@@ -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.texture.TextureManager
-class BlockShader(
+open class BlockShader(
override val native: NativeShader,
) : Shader(), TextureShader, ViewProjectionShader, FogShader, TintedShader {
override var textures: TextureManager by textureManager()
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/flashing/FlashingBlockFeature.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/flashing/FlashingBlockFeature.kt
new file mode 100644
index 000000000..8bbd9cf75
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/flashing/FlashingBlockFeature.kt
@@ -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 .
+ *
+ * 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)
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/flashing/FlashingBlockShader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/flashing/FlashingBlockShader.kt
new file mode 100644
index 000000000..9675eea9c
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/block/flashing/FlashingBlockShader.kt
@@ -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 .
+ *
+ * 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)
+}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/renderer/PrimedTNTEntityRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/renderer/PrimedTNTEntityRenderer.kt
index 405e1b113..c07b5f273 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/renderer/PrimedTNTEntityRenderer.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/renderer/PrimedTNTEntityRenderer.kt
@@ -18,10 +18,10 @@ import de.bixilon.minosoft.data.registries.blocks.MinecraftBlocks
import de.bixilon.minosoft.data.registries.identified.Identified
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
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(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, Identified {
diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.fsh b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.fsh
new file mode 100644
index 000000000..14c6a1cb2
--- /dev/null
+++ b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.fsh
@@ -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 .
+ *
+ * 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();
+}
diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.vsh b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.vsh
new file mode 100644
index 000000000..95ec20fff
--- /dev/null
+++ b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.vsh
@@ -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 .
+ *
+ * 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);
+}