mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-10 07:48:29 -04:00
mipmaps: fix some bugs
This commit is contained in:
parent
fb540c5a53
commit
c4d242228a
@ -33,8 +33,10 @@ import de.bixilon.minosoft.gui.rendering.block.renderable.BlockLikeRenderContext
|
|||||||
import de.bixilon.minosoft.gui.rendering.input.camera.Frustum
|
import de.bixilon.minosoft.gui.rendering.input.camera.Frustum
|
||||||
import de.bixilon.minosoft.gui.rendering.modding.events.FrustumChangeEvent
|
import de.bixilon.minosoft.gui.rendering.modding.events.FrustumChangeEvent
|
||||||
import de.bixilon.minosoft.gui.rendering.modding.events.RenderingStateChangeEvent
|
import de.bixilon.minosoft.gui.rendering.modding.events.RenderingStateChangeEvent
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.RenderModes
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.shader.Shader
|
import de.bixilon.minosoft.gui.rendering.system.base.shader.Shader
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.opengl.OpenGLShader
|
||||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
|
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
|
||||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.getWorldOffset
|
import de.bixilon.minosoft.gui.rendering.util.VecUtil.getWorldOffset
|
||||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.of
|
import de.bixilon.minosoft.gui.rendering.util.VecUtil.of
|
||||||
@ -62,6 +64,7 @@ class WorldRenderer(
|
|||||||
private val waterBlock = connection.registries.blockRegistry[ResourceLocation("minecraft:water")].nullCast<FluidBlock>()
|
private val waterBlock = connection.registries.blockRegistry[ResourceLocation("minecraft:water")].nullCast<FluidBlock>()
|
||||||
|
|
||||||
private val chunkShader: Shader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "world"))
|
private val chunkShader: Shader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "world"))
|
||||||
|
private val transparentShader: Shader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "world"))
|
||||||
private val lightMap = LightMap(connection)
|
private val lightMap = LightMap(connection)
|
||||||
|
|
||||||
val allChunkSections: SynchronizedMap<Vec2i, SynchronizedMap<Int, ChunkSectionMeshCollection>> = synchronizedMapOf()
|
val allChunkSections: SynchronizedMap<Vec2i, SynchronizedMap<Int, ChunkSectionMeshCollection>> = synchronizedMapOf()
|
||||||
@ -118,8 +121,12 @@ class WorldRenderer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meshCollection.transparentSectionArrayMesh!!.data.isEmpty) {
|
if (meshCollection.translucentMesh!!.data.isEmpty) {
|
||||||
meshCollection.transparentSectionArrayMesh = null
|
meshCollection.translucentMesh = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (meshCollection.transparentMesh!!.data.isEmpty) {
|
||||||
|
meshCollection.transparentMesh = null
|
||||||
}
|
}
|
||||||
return meshCollection
|
return meshCollection
|
||||||
}
|
}
|
||||||
@ -180,11 +187,15 @@ class WorldRenderer(
|
|||||||
|
|
||||||
override fun postInit() {
|
override fun postInit() {
|
||||||
chunkShader.load()
|
chunkShader.load()
|
||||||
|
(transparentShader as OpenGLShader).defines["TRANSPARENT"] = "" // ToDo
|
||||||
|
transparentShader.load()
|
||||||
lightMap.init()
|
lightMap.init()
|
||||||
|
|
||||||
renderWindow.textureManager.staticTextures.use(chunkShader)
|
renderWindow.textureManager.staticTextures.use(chunkShader)
|
||||||
|
renderWindow.textureManager.staticTextures.use(transparentShader)
|
||||||
renderWindow.textureManager.staticTextures.animator.use(chunkShader)
|
renderWindow.textureManager.staticTextures.animator.use(chunkShader)
|
||||||
lightMap.use(chunkShader)
|
lightMap.use(chunkShader)
|
||||||
|
lightMap.use(transparentShader)
|
||||||
|
|
||||||
for (blockState in allBlocks!!) {
|
for (blockState in allBlocks!!) {
|
||||||
for (model in blockState.renderers) {
|
for (model in blockState.renderers) {
|
||||||
@ -205,18 +216,28 @@ class WorldRenderer(
|
|||||||
|
|
||||||
for (map in lastVisibleChunks.values) {
|
for (map in lastVisibleChunks.values) {
|
||||||
for (mesh in map.values) {
|
for (mesh in map.values) {
|
||||||
mesh.opaqueSectionArrayMesh.draw()
|
mesh.opaqueMesh.draw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun postDraw() {
|
override fun postDraw() {
|
||||||
renderWindow.renderSystem.reset(depthMask = false)
|
renderWindow.renderSystem.reset()
|
||||||
chunkShader.use()
|
transparentShader.use()
|
||||||
|
|
||||||
|
|
||||||
for (map in lastVisibleChunks.values) {
|
for (map in lastVisibleChunks.values) {
|
||||||
for (mesh in map.values) {
|
for (mesh in map.values) {
|
||||||
mesh.transparentSectionArrayMesh?.draw()
|
mesh.transparentMesh?.draw()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chunkShader.use()
|
||||||
|
renderWindow.renderSystem.renderMode(RenderModes.TRANSLUCENT)
|
||||||
|
|
||||||
|
for (map in lastVisibleChunks.values) {
|
||||||
|
for (mesh in map.values) {
|
||||||
|
mesh.translucentMesh?.draw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,23 +350,33 @@ class WorldRenderer(
|
|||||||
val sectionMap = allChunkSections.getOrPut(chunkPosition) { synchronizedMapOf() }
|
val sectionMap = allChunkSections.getOrPut(chunkPosition) { synchronizedMapOf() }
|
||||||
|
|
||||||
sectionMap[index]?.let {
|
sectionMap[index]?.let {
|
||||||
it.opaqueSectionArrayMesh.unload()
|
it.opaqueMesh.unload()
|
||||||
meshes--
|
meshes--
|
||||||
triangles -= it.opaqueSectionArrayMesh.vertices
|
triangles -= it.opaqueMesh.vertices
|
||||||
|
|
||||||
it.transparentSectionArrayMesh?.let {
|
it.translucentMesh?.let {
|
||||||
|
it.unload()
|
||||||
|
meshes--
|
||||||
|
triangles -= it.vertices
|
||||||
|
}
|
||||||
|
it.transparentMesh?.let {
|
||||||
it.unload()
|
it.unload()
|
||||||
meshes--
|
meshes--
|
||||||
triangles -= it.vertices
|
triangles -= it.vertices
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
meshCollection.opaqueSectionArrayMesh.let {
|
meshCollection.opaqueMesh.let {
|
||||||
it.load()
|
it.load()
|
||||||
meshes++
|
meshes++
|
||||||
triangles += it.vertices
|
triangles += it.vertices
|
||||||
}
|
}
|
||||||
meshCollection.transparentSectionArrayMesh?.let {
|
meshCollection.translucentMesh?.let {
|
||||||
|
it.load()
|
||||||
|
meshes++
|
||||||
|
triangles += it.vertices
|
||||||
|
}
|
||||||
|
meshCollection.transparentMesh?.let {
|
||||||
it.load()
|
it.load()
|
||||||
meshes++
|
meshes++
|
||||||
triangles += it.vertices
|
triangles += it.vertices
|
||||||
@ -410,12 +441,17 @@ class WorldRenderer(
|
|||||||
private fun unloadMeshes(meshes: Collection<ChunkSectionMeshCollection>) {
|
private fun unloadMeshes(meshes: Collection<ChunkSectionMeshCollection>) {
|
||||||
renderWindow.assertOnRenderThread()
|
renderWindow.assertOnRenderThread()
|
||||||
for (meshCollection in meshes) {
|
for (meshCollection in meshes) {
|
||||||
meshCollection.opaqueSectionArrayMesh.let {
|
meshCollection.opaqueMesh.let {
|
||||||
it.unload()
|
it.unload()
|
||||||
this.meshes--
|
this.meshes--
|
||||||
triangles -= it.vertices
|
triangles -= it.vertices
|
||||||
}
|
}
|
||||||
meshCollection.transparentSectionArrayMesh?.let {
|
meshCollection.translucentMesh?.let {
|
||||||
|
it.unload()
|
||||||
|
this.meshes--
|
||||||
|
triangles -= it.vertices
|
||||||
|
}
|
||||||
|
meshCollection.transparentMesh?.let {
|
||||||
it.unload()
|
it.unload()
|
||||||
this.meshes--
|
this.meshes--
|
||||||
triangles -= it.vertices
|
triangles -= it.vertices
|
||||||
|
@ -17,8 +17,9 @@ import de.bixilon.minosoft.gui.rendering.RenderWindow
|
|||||||
|
|
||||||
class ChunkSectionMeshCollection(
|
class ChunkSectionMeshCollection(
|
||||||
renderWindow: RenderWindow,
|
renderWindow: RenderWindow,
|
||||||
val opaqueSectionArrayMesh: ChunkSectionArrayMesh = ChunkSectionArrayMesh(renderWindow),
|
val opaqueMesh: ChunkSectionArrayMesh = ChunkSectionArrayMesh(renderWindow),
|
||||||
var transparentSectionArrayMesh: ChunkSectionArrayMesh? = ChunkSectionArrayMesh(renderWindow),
|
var translucentMesh: ChunkSectionArrayMesh? = ChunkSectionArrayMesh(renderWindow),
|
||||||
|
var transparentMesh: ChunkSectionArrayMesh? = ChunkSectionArrayMesh(renderWindow),
|
||||||
) {
|
) {
|
||||||
var lowestBlockHeight = 0
|
var lowestBlockHeight = 0
|
||||||
var highestBlockHeight = 0
|
var highestBlockHeight = 0
|
||||||
|
@ -168,11 +168,11 @@ class ElementRenderer(
|
|||||||
|
|
||||||
val DRAW_OFFSET = Vec3(+0.5f, +0.5f, +0.5f)
|
val DRAW_OFFSET = Vec3(+0.5f, +0.5f, +0.5f)
|
||||||
|
|
||||||
fun getMesh(meshCollection: ChunkSectionMeshCollection, textureTransparencies: TextureTransparencies): ChunkSectionArrayMesh {
|
fun getMesh(meshCollection: ChunkSectionMeshCollection, transparency: TextureTransparencies): ChunkSectionArrayMesh {
|
||||||
return if (textureTransparencies == TextureTransparencies.TRANSLUCENT) {
|
return when (transparency) {
|
||||||
meshCollection.transparentSectionArrayMesh!!
|
TextureTransparencies.OPAQUE -> meshCollection.opaqueMesh
|
||||||
} else {
|
TextureTransparencies.TRANSPARENT -> meshCollection.transparentMesh!!
|
||||||
meshCollection.opaqueSectionArrayMesh
|
TextureTransparencies.TRANSLUCENT -> meshCollection.translucentMesh!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 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.system.base
|
||||||
|
|
||||||
|
enum class RenderModes {
|
||||||
|
DEFAULT,
|
||||||
|
TRANSLUCENT,
|
||||||
|
;
|
||||||
|
}
|
@ -89,4 +89,14 @@ interface RenderSystem {
|
|||||||
fun createTextureManager(): TextureManager
|
fun createTextureManager(): TextureManager
|
||||||
|
|
||||||
fun clear(vararg buffers: IntegratedBufferTypes)
|
fun clear(vararg buffers: IntegratedBufferTypes)
|
||||||
|
|
||||||
|
|
||||||
|
fun renderMode(mode: RenderModes) {
|
||||||
|
when (mode) {
|
||||||
|
RenderModes.TRANSLUCENT -> {
|
||||||
|
depthMask = false
|
||||||
|
setBlendFunc(BlendingFunctions.SOURCE_ALPHA, BlendingFunctions.ONE_MINUS_SOURCE_ALPHA, BlendingFunctions.ONE, BlendingFunctions.ONE_MINUS_SOURCE_ALPHA)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,5 +23,5 @@ interface SpriteAnimator {
|
|||||||
fun draw()
|
fun draw()
|
||||||
|
|
||||||
|
|
||||||
fun use(shader: Shader, bufferName: String = "uAnimationBuffer")
|
fun use(shader: Shader, bufferName: String = "uSpriteBuffer")
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ class OpenGLTextureArray(
|
|||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val TEXTURE_RESOLUTION_ID_MAP = arrayOf(16, 32, 64, 128, 256, 512, 1024) // A 12x12 texture will be saved in texture id 0 (in 0 are only 16x16 textures). Animated textures get split
|
val TEXTURE_RESOLUTION_ID_MAP = intArrayOf(16, 32, 64, 128, 256, 512, 1024) // A 12x12 texture will be saved in texture id 0 (in 0 are only 16x16 textures). Animated textures get split
|
||||||
const val TEXTURE_MAX_RESOLUTION = 1024
|
const val TEXTURE_MAX_RESOLUTION = 1024
|
||||||
const val MAX_MIPMAP_LEVELS = 5
|
const val MAX_MIPMAP_LEVELS = 5
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,12 @@ void work() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
outColor = mix(firstTexelColor, secondTexelColor, finInterpolation) * finTintColor;
|
outColor = mix(firstTexelColor, secondTexelColor, finInterpolation) * finTintColor;
|
||||||
|
|
||||||
|
#ifndef TRANSPARENT
|
||||||
|
if (outColor.a < 0.5){
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "minosoft:postprocessing/fragment"
|
#include "minosoft:postprocessing/fragment"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user