improve transparency: post drawing

This commit is contained in:
Bixilon 2021-06-19 22:29:30 +02:00
parent 5a991b45b8
commit 7ff391f703
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 53 additions and 26 deletions

View File

@ -333,9 +333,15 @@ class RenderWindow(
textures.animator.draw()
for (renderer in rendererMap.values) {
renderer.update()
}
for (renderer in rendererMap.values) {
renderer.draw()
}
for (renderer in rendererMap.values) {
renderer.postDraw()
}
renderStats.endDraw()

View File

@ -14,7 +14,14 @@
package de.bixilon.minosoft.gui.rendering
interface Renderer {
fun init() {}
fun postInit() {}
fun update() {}
fun draw() {}
fun postDraw() {}
}

View File

@ -64,6 +64,7 @@ class WorldRenderer(
val allChunkSections: SynchronizedMap<Vec2i, SynchronizedMap<Int, ChunkMeshCollection>> = synchronizedMapOf()
val visibleChunks: SynchronizedMap<Vec2i, SynchronizedMap<Int, ChunkMeshCollection>> = synchronizedMapOf()
private var lastVisibleChunks: SynchronizedMap<Vec2i, SynchronizedMap<Int, ChunkMeshCollection>> = synchronizedMapOf()
val queuedChunks: MutableSet<Vec2i> = synchronizedSetOf()
private val preparationTasks: SynchronizedMap<Vec2i, SynchronizedMap<Int, ThreadPoolRunnable>> = synchronizedMapOf()
@ -194,19 +195,26 @@ class WorldRenderer(
allBlocks = null
}
override fun update() {
lastVisibleChunks = visibleChunks.toSynchronizedMap()
}
override fun draw() {
renderWindow.renderSystem.reset()
chunkShader.use()
val visibleChunks = visibleChunks.toSynchronizedMap()
for (map in visibleChunks.values) {
for (map in lastVisibleChunks.values) {
for (mesh in map.values) {
mesh.opaqueSectionArrayMesh.draw()
}
}
}
renderWindow.renderSystem.depthMask = false
for (map in visibleChunks.values) {
override fun postDraw() {
renderWindow.renderSystem.reset(depthMask = false)
chunkShader.use()
for (map in lastVisibleChunks.values) {
for (mesh in map.values) {
mesh.transparentSectionArrayMesh?.draw()
}

View File

@ -150,7 +150,7 @@ class HUDRenderer(val connection: PlayConnection, val renderWindow: RenderWindow
}
}
override fun draw() {
override fun postDraw() {
if (!RenderConstants.RENDER_HUD) {
return
}

View File

@ -135,12 +135,14 @@ class Camera(
private fun onPositionChange() {
recalculateViewProjectionMatrix()
// recalculate sky color for current biome
val skyRenderer = renderWindow[SkyRenderer.Companion] ?: return
skyRenderer.baseColor = connection.world.getBiome(entity.positionInfo.blockPosition)?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR
frustum.recalculate()
connection.fireEvent(FrustumChangeEvent(renderWindow, frustum))
connection.fireEvent(CameraPositionChangeEvent(renderWindow, entity.eyePosition))
// recalculate sky color for current biome
renderWindow[SkyRenderer.Companion]?.let { skyRenderer ->
skyRenderer.baseColor = connection.world.getBiome(entity.positionInfo.blockPosition)?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR
connection.world.dimension?.hasSkyLight?.let {
if (it) {
@ -149,7 +151,7 @@ class Camera(
skyRenderer.baseColor = RenderConstants.BLACK_COLOR
}
} ?: let { skyRenderer.baseColor = RenderConstants.DEFAULT_SKY_COLOR }
connection.fireEvent(CameraPositionChangeEvent(renderWindow, entity.eyePosition))
}
}
private fun calculateProjectionMatrix(screenDimensions: Vec2): Mat4d {

View File

@ -80,10 +80,7 @@ class ParticleRenderer(
add(particle)
}
override fun draw() {
renderWindow.renderSystem.reset()
particleShader.use()
override fun update() {
particleMesh.unload()
transparentParticleMesh.unload()
particleMesh = ParticleMesh()
@ -101,10 +98,17 @@ class ParticleRenderer(
particleMesh.load()
transparentParticleMesh.load()
}
override fun draw() {
renderWindow.renderSystem.reset()
particleShader.use()
particleMesh.draw()
}
renderWindow.renderSystem.depthMask = false
override fun postDraw() {
renderWindow.renderSystem.reset(depthMask = false)
particleShader.use()
transparentParticleMesh.draw()
}

View File

@ -79,7 +79,7 @@ class SkyRenderer(
}
private fun setSunMatrix(projectionViewMatrix: Mat4d) {
val timeAngle = ((getSkyAngle(connection.world.time).toDouble() * 360.0) + 180.0).rad
val timeAngle = ((getSkyAngle(connection.world.time) * 360.0) + 180.0).rad
val rotatedMatrix = if (timeAngle == 0.0) {
projectionViewMatrix
} else {

View File

@ -24,10 +24,10 @@ interface RenderSystem {
depthTest: Boolean = true,
blending: Boolean = true,
faceCulling: Boolean = true,
depthMask: Boolean = true,
sourceAlpha: BlendingFunctions = BlendingFunctions.SOURCE_ALPHA,
destinationAlpha: BlendingFunctions = BlendingFunctions.ONE_MINUS_SOURCE_ALPHA,
depth: DepthFunctions = DepthFunctions.LESS,
depthMask: Boolean = true,
) {
this[RenderingCapabilities.DEPTH_TEST] = depthTest
this[RenderingCapabilities.BLENDING] = blending

View File

@ -81,8 +81,8 @@ object KUtil {
return ret
}
fun <K, V> Map<K, V>.toSynchronizedMap(): MutableMap<K, V> {
return synchronizedCopy { Collections.synchronizedMap(this.toMutableMap()) }
fun <K, V> Map<K, V>.toSynchronizedMap(): SynchronizedMap<K, V> {
return synchronizedCopy { SynchronizedMap(this.toMutableMap()) }
}
fun <V> Collection<V>.toSynchronizedList(): MutableList<V> {