mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
improve transparency: post drawing
This commit is contained in:
parent
5a991b45b8
commit
7ff391f703
@ -333,9 +333,15 @@ class RenderWindow(
|
|||||||
textures.animator.draw()
|
textures.animator.draw()
|
||||||
|
|
||||||
|
|
||||||
|
for (renderer in rendererMap.values) {
|
||||||
|
renderer.update()
|
||||||
|
}
|
||||||
for (renderer in rendererMap.values) {
|
for (renderer in rendererMap.values) {
|
||||||
renderer.draw()
|
renderer.draw()
|
||||||
}
|
}
|
||||||
|
for (renderer in rendererMap.values) {
|
||||||
|
renderer.postDraw()
|
||||||
|
}
|
||||||
|
|
||||||
renderStats.endDraw()
|
renderStats.endDraw()
|
||||||
|
|
||||||
|
@ -14,7 +14,14 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering
|
package de.bixilon.minosoft.gui.rendering
|
||||||
|
|
||||||
interface Renderer {
|
interface Renderer {
|
||||||
|
|
||||||
fun init() {}
|
fun init() {}
|
||||||
|
|
||||||
fun postInit() {}
|
fun postInit() {}
|
||||||
|
|
||||||
|
fun update() {}
|
||||||
|
|
||||||
fun draw() {}
|
fun draw() {}
|
||||||
|
|
||||||
|
fun postDraw() {}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ class WorldRenderer(
|
|||||||
|
|
||||||
val allChunkSections: SynchronizedMap<Vec2i, SynchronizedMap<Int, ChunkMeshCollection>> = synchronizedMapOf()
|
val allChunkSections: SynchronizedMap<Vec2i, SynchronizedMap<Int, ChunkMeshCollection>> = synchronizedMapOf()
|
||||||
val visibleChunks: 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()
|
val queuedChunks: MutableSet<Vec2i> = synchronizedSetOf()
|
||||||
private val preparationTasks: SynchronizedMap<Vec2i, SynchronizedMap<Int, ThreadPoolRunnable>> = synchronizedMapOf()
|
private val preparationTasks: SynchronizedMap<Vec2i, SynchronizedMap<Int, ThreadPoolRunnable>> = synchronizedMapOf()
|
||||||
|
|
||||||
@ -194,19 +195,26 @@ class WorldRenderer(
|
|||||||
allBlocks = null
|
allBlocks = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun update() {
|
||||||
|
lastVisibleChunks = visibleChunks.toSynchronizedMap()
|
||||||
|
}
|
||||||
|
|
||||||
override fun draw() {
|
override fun draw() {
|
||||||
renderWindow.renderSystem.reset()
|
renderWindow.renderSystem.reset()
|
||||||
chunkShader.use()
|
chunkShader.use()
|
||||||
val visibleChunks = visibleChunks.toSynchronizedMap()
|
|
||||||
|
|
||||||
for (map in visibleChunks.values) {
|
for (map in lastVisibleChunks.values) {
|
||||||
for (mesh in map.values) {
|
for (mesh in map.values) {
|
||||||
mesh.opaqueSectionArrayMesh.draw()
|
mesh.opaqueSectionArrayMesh.draw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderWindow.renderSystem.depthMask = false
|
override fun postDraw() {
|
||||||
for (map in visibleChunks.values) {
|
renderWindow.renderSystem.reset(depthMask = false)
|
||||||
|
chunkShader.use()
|
||||||
|
|
||||||
|
for (map in lastVisibleChunks.values) {
|
||||||
for (mesh in map.values) {
|
for (mesh in map.values) {
|
||||||
mesh.transparentSectionArrayMesh?.draw()
|
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) {
|
if (!RenderConstants.RENDER_HUD) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -135,21 +135,23 @@ class Camera(
|
|||||||
|
|
||||||
private fun onPositionChange() {
|
private fun onPositionChange() {
|
||||||
recalculateViewProjectionMatrix()
|
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()
|
frustum.recalculate()
|
||||||
connection.fireEvent(FrustumChangeEvent(renderWindow, frustum))
|
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))
|
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 {
|
private fun calculateProjectionMatrix(screenDimensions: Vec2): Mat4d {
|
||||||
|
@ -80,10 +80,7 @@ class ParticleRenderer(
|
|||||||
add(particle)
|
add(particle)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun draw() {
|
override fun update() {
|
||||||
renderWindow.renderSystem.reset()
|
|
||||||
particleShader.use()
|
|
||||||
|
|
||||||
particleMesh.unload()
|
particleMesh.unload()
|
||||||
transparentParticleMesh.unload()
|
transparentParticleMesh.unload()
|
||||||
particleMesh = ParticleMesh()
|
particleMesh = ParticleMesh()
|
||||||
@ -101,10 +98,17 @@ class ParticleRenderer(
|
|||||||
|
|
||||||
particleMesh.load()
|
particleMesh.load()
|
||||||
transparentParticleMesh.load()
|
transparentParticleMesh.load()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw() {
|
||||||
|
renderWindow.renderSystem.reset()
|
||||||
|
particleShader.use()
|
||||||
particleMesh.draw()
|
particleMesh.draw()
|
||||||
|
}
|
||||||
|
|
||||||
renderWindow.renderSystem.depthMask = false
|
override fun postDraw() {
|
||||||
|
renderWindow.renderSystem.reset(depthMask = false)
|
||||||
|
particleShader.use()
|
||||||
transparentParticleMesh.draw()
|
transparentParticleMesh.draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class SkyRenderer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setSunMatrix(projectionViewMatrix: Mat4d) {
|
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) {
|
val rotatedMatrix = if (timeAngle == 0.0) {
|
||||||
projectionViewMatrix
|
projectionViewMatrix
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,10 +24,10 @@ interface RenderSystem {
|
|||||||
depthTest: Boolean = true,
|
depthTest: Boolean = true,
|
||||||
blending: Boolean = true,
|
blending: Boolean = true,
|
||||||
faceCulling: Boolean = true,
|
faceCulling: Boolean = true,
|
||||||
|
depthMask: Boolean = true,
|
||||||
sourceAlpha: BlendingFunctions = BlendingFunctions.SOURCE_ALPHA,
|
sourceAlpha: BlendingFunctions = BlendingFunctions.SOURCE_ALPHA,
|
||||||
destinationAlpha: BlendingFunctions = BlendingFunctions.ONE_MINUS_SOURCE_ALPHA,
|
destinationAlpha: BlendingFunctions = BlendingFunctions.ONE_MINUS_SOURCE_ALPHA,
|
||||||
depth: DepthFunctions = DepthFunctions.LESS,
|
depth: DepthFunctions = DepthFunctions.LESS,
|
||||||
depthMask: Boolean = true,
|
|
||||||
) {
|
) {
|
||||||
this[RenderingCapabilities.DEPTH_TEST] = depthTest
|
this[RenderingCapabilities.DEPTH_TEST] = depthTest
|
||||||
this[RenderingCapabilities.BLENDING] = blending
|
this[RenderingCapabilities.BLENDING] = blending
|
||||||
|
@ -81,8 +81,8 @@ object KUtil {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <K, V> Map<K, V>.toSynchronizedMap(): MutableMap<K, V> {
|
fun <K, V> Map<K, V>.toSynchronizedMap(): SynchronizedMap<K, V> {
|
||||||
return synchronizedCopy { Collections.synchronizedMap(this.toMutableMap()) }
|
return synchronizedCopy { SynchronizedMap(this.toMutableMap()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <V> Collection<V>.toSynchronizedList(): MutableList<V> {
|
fun <V> Collection<V>.toSynchronizedList(): MutableList<V> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user