diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt index 93223a8d2..b206fce5c 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt @@ -60,8 +60,6 @@ object RenderConstants { val DEBUG_TEXTURE_RESOURCE_LOCATION = ResourceLocation("minosoft:textures/debug.png") const val DEBUG_TEXTURE_ID = 0 // always add the debug texture to the texture array first to ensure the id is 0 - const val FORCE_DEBUG_TEXTURE = false - val PIXEL_UV_PIXEL_ADD = Vec2(0, 0.1f) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/block/WorldRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/block/WorldRenderer.kt index ac7edeacb..3e06fcd68 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/block/WorldRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/block/WorldRenderer.kt @@ -18,8 +18,6 @@ import de.bixilon.minosoft.data.assets.Resources import de.bixilon.minosoft.data.direction.Directions import de.bixilon.minosoft.data.direction.FakeDirection import de.bixilon.minosoft.data.registries.ResourceLocation -import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties -import de.bixilon.minosoft.data.registries.blocks.properties.MultipartDirectionParser import de.bixilon.minosoft.data.world.ChunkSection import de.bixilon.minosoft.data.world.World import de.bixilon.minosoft.gui.rendering.RenderWindow @@ -74,10 +72,9 @@ class WorldRenderer( val random = Random(0L) - val blockState1 = connection.registries.blockRegistry["grass_block"]?.defaultState - val blockState2 = connection.registries.blockRegistry["oak_fence"]!!.defaultState.withProperties(BlockProperties.MULTIPART_SOUTH to MultipartDirectionParser.SIDE, BlockProperties.MULTIPART_NORTH to MultipartDirectionParser.SIDE, BlockProperties.MULTIPART_EAST to MultipartDirectionParser.SIDE, BlockProperties.MULTIPART_WEST to MultipartDirectionParser.SIDE) + val blockState1 = connection.registries.blockRegistry["redstone_block"]?.defaultState + val blockState2 = connection.registries.blockRegistry["diamond_block"]!!.defaultState//.withProperties(BlockProperties.MULTIPART_SOUTH to MultipartDirectionParser.SIDE, BlockProperties.MULTIPART_NORTH to MultipartDirectionParser.SIDE, BlockProperties.MULTIPART_EAST to MultipartDirectionParser.SIDE, BlockProperties.MULTIPART_WEST to MultipartDirectionParser.SIDE) val section = ChunkSection(Array(4096) { - if (it < 4096) return@Array blockState2 else return@Array null when (random.nextInt(3)) { 1 -> blockState1 2 -> blockState2 @@ -88,8 +85,8 @@ class WorldRenderer( mesh = sectionPreparer.prepare(section) - // for (i in 0 until 1000) - mesh = sectionPreparer.prepare(section) + for (i in 0 until 1000) + mesh = sectionPreparer.prepare(section) /* Log.log(LogMessageType.OTHER, LogLevels.WARN){"Culling now..."} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/block/mesh/ChunkSectionMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/block/mesh/ChunkSectionMesh.kt index c047d3f7b..a1a9f6a57 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/block/mesh/ChunkSectionMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/block/mesh/ChunkSectionMesh.kt @@ -23,38 +23,27 @@ import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct import glm_.vec2.Vec2 import glm_.vec3.Vec3 -class ChunkSectionMesh(renderWindow: RenderWindow) : Mesh(renderWindow, SectionArrayMeshStruct, PrimitiveTypes.QUAD, initialCacheSize = 100000) { +class ChunkSectionMesh(renderWindow: RenderWindow) : Mesh(renderWindow, SectionArrayMeshStruct, PrimitiveTypes.QUAD, initialCacheSize = 200000) { fun addVertex(position: FloatArray, uv: Vec2, texture: AbstractTexture, tintColor: RGBColor?, light: Int) { - //val texture = renderWindow.WHITE_TEXTURE.texture - val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) { - RenderConstants.DEBUG_TEXTURE_ID - } else { - texture.renderData?.layer ?: RenderConstants.DEBUG_TEXTURE_ID - } val transformedUV = texture.renderData?.transformUV(uv) ?: uv - data.addAll( - floatArrayOf( - position[0], - position[1], - position[2], - transformedUV.x, - transformedUV.y, - Float.fromBits(textureLayer), - Float.fromBits(texture.renderData?.animationData ?: -1), - Float.fromBits(tintColor?.rgb ?: 0xFFFFFF), // white - Float.fromBits(light), - )) + data.addAll(floatArrayOf( + position[0], + position[1], + position[2], + transformedUV.x, + transformedUV.y, + Float.fromBits(texture.renderData?.shaderTextureId ?: RenderConstants.DEBUG_TEXTURE_ID), + Float.fromBits((tintColor?.rgb ?: 0xFFFFFF) or (light shl 24)), // white + )) } data class SectionArrayMeshStruct( val position: Vec3, val uv: Vec2, - val textureLayer: Int, - val animationId: Int, - val tintColor: RGBColor, - val light: Int, + val indexLayerAnimation: Int, + val tintLight: Int, ) { companion object : MeshStruct(SectionArrayMeshStruct::class) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt index 9dff63679..8e8cc4992 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt @@ -42,7 +42,7 @@ class GUIMesh( data class GUIMeshStruct( val position: Vec3, val uv: Vec2, - val textureLayer: Int, + val indexLayerAnimation: Int, val tintColor: RGBColor, ) { companion object : MeshStruct(GUIMeshStruct::class) @@ -69,7 +69,7 @@ class GUIMesh( BASE_Z + Z_MULTIPLIER * z, uv.x, uv.y, - Float.fromBits(texture.renderData?.layer ?: RenderConstants.DEBUG_TEXTURE_ID), + Float.fromBits(texture.renderData?.shaderTextureId ?: RenderConstants.DEBUG_TEXTURE_ID), Float.fromBits(color.rgba), ) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt index b167d6749..ead99a987 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt @@ -27,12 +27,6 @@ import glm_.vec3.Vec3d class ParticleMesh(renderWindow: RenderWindow, initialCacheSize: Int) : Mesh(renderWindow, ParticleMeshStruct, PrimitiveTypes.POINT, initialCacheSize) { fun addVertex(position: Vec3d, scale: Float, texture: AbstractTexture, tintColor: RGBColor, uvMin: Vec2 = Vec2(0.0f, 0.0f), uvMax: Vec2 = Vec2(1.0f, 1.0f)) { - val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) { - RenderConstants.DEBUG_TEXTURE_ID - } else { - texture.renderData?.layer ?: RenderConstants.DEBUG_TEXTURE_ID - } - val minTransformedUV = texture.renderData?.transformUV(uvMin) ?: uvMin val maxTransformedUV = texture.renderData?.transformUV(uvMax) ?: uvMax data.addAll( @@ -44,8 +38,7 @@ class ParticleMesh(renderWindow: RenderWindow, initialCacheSize: Int) : Mesh(ren minTransformedUV.y, maxTransformedUV.x, maxTransformedUV.y, - Float.fromBits(textureLayer), - Float.fromBits(texture.renderData?.animationData ?: -1), + Float.fromBits(texture.renderData?.shaderTextureId ?: RenderConstants.DEBUG_TEXTURE_ID), scale, Float.fromBits(tintColor.rgba), )) @@ -56,8 +49,7 @@ class ParticleMesh(renderWindow: RenderWindow, initialCacheSize: Int) : Mesh(ren val position: Vec3, val minUVCoordinates: Vec2, val maxUVCoordinates: Vec2, - val textureLayer: Int, - val animationId: Int, + val indexLayerAnimation: Int, val scale: Float, val tintColor: RGBColor, ) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/texture/TextureRenderData.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/texture/TextureRenderData.kt index 26d670594..d71c06d8d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/texture/TextureRenderData.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/texture/TextureRenderData.kt @@ -16,7 +16,7 @@ package de.bixilon.minosoft.gui.rendering.system.base.texture.texture import glm_.vec2.Vec2 interface TextureRenderData { - val layer: Int + val shaderTextureId: Int val animationData: Int fun transformUV(end: Vec2): Vec2 diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLSpriteAnimator.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLSpriteAnimator.kt index 0cbde458c..6ce81933e 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLSpriteAnimator.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLSpriteAnimator.kt @@ -68,8 +68,8 @@ class OpenGLSpriteAnimator : SpriteAnimator { val arrayOffset = textureAnimation.texture.renderData!!.animationData * INTS_PER_ANIMATED_TEXTURE - uniformBuffer.data[arrayOffset] = currentFrame.texture.renderData!!.layer - uniformBuffer.data[arrayOffset + 1] = nextFrame.texture.renderData!!.layer + uniformBuffer.data[arrayOffset] = currentFrame.texture.renderData!!.shaderTextureId + uniformBuffer.data[arrayOffset + 1] = nextFrame.texture.renderData!!.shaderTextureId uniformBuffer.data[arrayOffset + 2] = interpolation.toInt() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLTextureData.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLTextureData.kt index f2936eac7..08f5e9376 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLTextureData.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLTextureData.kt @@ -22,7 +22,7 @@ class OpenGLTextureData( val uvEnd: Vec2?, override val animationData: Int = -1, ) : TextureRenderData { - override val layer: Int = (array shl 24) or (index) + override val shaderTextureId: Int = (array shl 28) or (index shl 12) or (animationData + 1) override fun transformUV(end: Vec2): Vec2 { if (uvEnd == null) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/SimpleTextureMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/SimpleTextureMesh.kt index f11374ca6..03cbf3b0d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/SimpleTextureMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/SimpleTextureMesh.kt @@ -23,12 +23,6 @@ import glm_.vec3.Vec3 open class SimpleTextureMesh(renderWindow: RenderWindow) : Mesh(renderWindow, SimpleTextureMeshStruct, initialCacheSize = 2 * 3 * SimpleTextureMeshStruct.FLOATS_PER_VERTEX) { fun addVertex(position: Vec3, texture: AbstractTexture, uv: Vec2, tintColor: RGBColor) { - val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) { - RenderConstants.DEBUG_TEXTURE_ID - } else { - texture.renderData?.layer ?: RenderConstants.DEBUG_TEXTURE_ID - } - data.addAll( floatArrayOf( position.x, @@ -36,8 +30,7 @@ open class SimpleTextureMesh(renderWindow: RenderWindow) : Mesh(renderWindow, Si position.z, uv.x, uv.y, - Float.fromBits(textureLayer), - Float.fromBits(tintColor.rgba), + Float.fromBits(texture.renderData?.shaderTextureId ?: RenderConstants.DEBUG_TEXTURE_ID), )) } @@ -45,8 +38,7 @@ open class SimpleTextureMesh(renderWindow: RenderWindow) : Mesh(renderWindow, Si data class SimpleTextureMeshStruct( val position: Vec3, val uv: Vec2, - val textureLayer: Int, - val animationId: Int, + val indexLayerAnimation: Int, ) { companion object : MeshStruct(SimpleTextureMeshStruct::class) } diff --git a/src/main/resources/assets/minosoft/rendering/shader/hud/hud.vsh b/src/main/resources/assets/minosoft/rendering/shader/hud/hud.vsh index 4030d3603..e39427981 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/hud/hud.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/hud/hud.vsh @@ -15,7 +15,7 @@ layout (location = 0) in vec3 vinPosition; layout (location = 1) in vec2 vinUV; -layout (location = 2) in uint vinTextureLayer; +layout (location = 2) in uint vinIndexLayerAnimation; layout (location = 3) in uint vinTintColor; flat out uint finTextureIndex; @@ -26,7 +26,10 @@ out vec4 finTintColor; void main() { gl_Position = vec4(vinPosition.xyz, 1.0f); - finTextureCoordinates = vec3(vinUV, vinTextureLayer & 0xFFFFFFu); - finTextureIndex = vinTextureLayer >> 24u; + + // ToDo: Texture animations + + finTextureIndex = vinIndexLayerAnimation >> 28u; + finTextureCoordinates = vec3(vinUV, ((vinIndexLayerAnimation >> 12) & 0xFFFFu)); finTintColor = getRGBAColor(vinTintColor); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.vsh b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.vsh index 0f4dfbd4a..2efefb5f8 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.vsh @@ -16,11 +16,10 @@ layout (location = 0) in vec3 vinPosition; layout (location = 1) in vec2 vinMinUVCoordinates; layout (location = 2) in vec2 vinMaxUVCoordinates; -layout (location = 3) in uint vinTextureLayer; -layout (location = 4) in int vinAnimationIndex; +layout (location = 3) in uint vinIndexLayerAnimation; -layout (location = 5) in float vinScale; -layout (location = 6) in uint vinTintColor; +layout (location = 4) in float vinScale; +layout (location = 5) in uint vinTintColor; #include "minosoft:animation" @@ -50,24 +49,29 @@ void main() { ginVertex.scale = vinScale; ginVertex.tintColor = getRGBAColor(vinTintColor); - if (vinAnimationIndex == -1) { - ginVertex.textureIndex1 = vinTextureLayer >> 24u; - ginVertex.textureLayer1 = vinTextureLayer & 0xFFFFFFu; + + uint animationIndex = vinIndexLayerAnimation & 0xFFFu; + + if (animationIndex == 0u) { + ginVertex.textureIndex1 = vinIndexLayerAnimation >> 28u; + ginVertex.textureLayer1 = ((vinIndexLayerAnimation >> 12) & 0xFFFFu); ginVertex.interpolation = 0.0f; return; } - uvec4 data = uAnimationData[vinAnimationIndex]; + uvec4 data = uAnimationData[animationIndex -1u]; uint texture1 = data.x; uint texture2 = data.y; uint interpolation = data.z; - ginVertex.textureIndex1 = texture1 >> 24u; - ginVertex.textureLayer1 = texture1 & 0xFFFFFFu; - ginVertex.textureIndex2 = texture2 >> 24u; - ginVertex.textureLayer2 = texture2 & 0xFFFFFFu; + + ginVertex.textureIndex1 = texture1 >> 28u; + ginVertex.textureLayer1 = (texture1 >> 12) & 0xFFFFu; + + ginVertex.textureIndex2 = texture2 >> 28u; + ginVertex.textureLayer2 = (texture2 >> 12) & 0xFFFFu; ginVertex.interpolation = interpolation / 100.0f; } diff --git a/src/main/resources/assets/minosoft/rendering/shader/sky/sun/sky_sun.vsh b/src/main/resources/assets/minosoft/rendering/shader/sky/sun/sky_sun.vsh index 9202f9bd2..229e907bf 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/sky/sun/sky_sun.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/sky/sun/sky_sun.vsh @@ -15,7 +15,7 @@ layout (location = 0) in vec3 vinPosition; layout (location = 1) in vec2 vinUV; -layout (location = 2) in uint vinTextureLayer; +layout (location = 2) in uint vinIndexLayerAnimation; layout (location = 3) in uint vinTintColor; out vec4 finTintColor; @@ -29,7 +29,8 @@ uniform mat4 uSkyViewProjectionMatrix; void main() { gl_Position = (uSkyViewProjectionMatrix * vec4(vinPosition, 1.0f)).xyww - vec4(0.0f, 0.0f, 0.000001f, 0.0f);// prevent face fighting - finTextureCoordinates = vec3(vinUV, vinTextureLayer & 0xFFFFFFu); - finTextureIndex = vinTextureLayer >> 24u; + finTextureIndex = vinIndexLayerAnimation >> 28u; + finTextureCoordinates = vec3(vinUV, ((vinIndexLayerAnimation >> 12) & 0xFFFFu)); + finTintColor = getRGBAColor(vinTintColor); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/world/world.vsh b/src/main/resources/assets/minosoft/rendering/shader/world/world.vsh index a9bb6bc3c..32623ce4c 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/world/world.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/world/world.vsh @@ -15,11 +15,8 @@ layout (location = 0) in vec3 vinPosition; layout (location = 1) in vec2 vinUV; -layout (location = 2) in uint vinTextureLayer; - -layout (location = 3) in int vinAnimationIndex; -layout (location = 4) in uint vinTintColor; -layout (location = 5) in uint vinLight; +layout (location = 2) in uint vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000), animation index (0x00000FFF) +layout (location = 3) in uint vinTintColorAndLight;// Light (0xFF000000); 3 bytes color (0x00FFFFFF) flat out uint finTextureIndex1; out vec3 finTextureCoordinates1; @@ -39,28 +36,27 @@ uniform mat4 uViewProjectionMatrix; void work() { gl_Position = uViewProjectionMatrix * vec4(vinPosition, 1.0f); - finTintColor = getRGBColor(vinTintColor) * getLight(vinLight); + finTintColor = getRGBColor(vinTintColorAndLight & 0xFFFFFFu) * getLight(vinTintColorAndLight >> 24u); - if (vinAnimationIndex == -1) { - finTextureIndex1 = vinTextureLayer >> 24u; - - finTextureCoordinates1 = vec3(vinUV, (vinTextureLayer & 0xFFFFFFu)); - + uint animationIndex = vinIndexLayerAnimation & 0xFFFu; + if (animationIndex == 0u) { + finTextureIndex1 = vinIndexLayerAnimation >> 28u; + finTextureCoordinates1 = vec3(vinUV, ((vinIndexLayerAnimation >> 12) & 0xFFFFu)); finInterpolation = 0.0f; return; } - uvec4 data = uAnimationData[vinAnimationIndex]; - uint firstTexture = data.x; - uint secondTexture = data.y; + uvec4 data = uAnimationData[animationIndex - 1u]; + uint texture1 = data.x; + uint texture2 = data.y; uint interpolation = data.z; - finTextureIndex1 = firstTexture >> 24u; - finTextureCoordinates1 = vec3(vinUV, firstTexture & 0xFFFFFFu); + finTextureIndex1 = texture1 >> 28u; + finTextureCoordinates1 = vec3(vinUV, ((texture1 >> 12) & 0xFFFFu)); - finTextureIndex2 = secondTexture >> 24u; - finTextureCoordinates2 = vec3(vinUV, secondTexture & 0xFFFFFFu); + finTextureIndex2 = texture2 >> 28u; + finTextureCoordinates2 = vec3(vinUV, ((texture2 >> 12) & 0xFFFFu)); finInterpolation = interpolation / 100.0f; }