mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -04:00
improve transparency: post drawing
This commit is contained in:
parent
5a991b45b8
commit
7ff391f703
@ -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()
|
||||
|
||||
|
@ -14,7 +14,14 @@
|
||||
package de.bixilon.minosoft.gui.rendering
|
||||
|
||||
interface Renderer {
|
||||
|
||||
fun init() {}
|
||||
|
||||
fun postInit() {}
|
||||
|
||||
fun update() {}
|
||||
|
||||
fun draw() {}
|
||||
|
||||
fun postDraw() {}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ class HUDRenderer(val connection: PlayConnection, val renderWindow: RenderWindow
|
||||
}
|
||||
}
|
||||
|
||||
override fun draw() {
|
||||
override fun postDraw() {
|
||||
if (!RenderConstants.RENDER_HUD) {
|
||||
return
|
||||
}
|
||||
|
@ -135,21 +135,23 @@ 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.world.dimension?.hasSkyLight?.let {
|
||||
if (it) {
|
||||
skyRenderer.baseColor = entity.positionInfo.biome?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR
|
||||
} else {
|
||||
skyRenderer.baseColor = RenderConstants.BLACK_COLOR
|
||||
}
|
||||
} ?: let { skyRenderer.baseColor = RenderConstants.DEFAULT_SKY_COLOR }
|
||||
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) {
|
||||
skyRenderer.baseColor = entity.positionInfo.biome?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR
|
||||
} else {
|
||||
skyRenderer.baseColor = RenderConstants.BLACK_COLOR
|
||||
}
|
||||
} ?: let { skyRenderer.baseColor = RenderConstants.DEFAULT_SKY_COLOR }
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateProjectionMatrix(screenDimensions: Vec2): Mat4d {
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user