mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
particles: add second mesh to improve transparency
This commit is contained in:
parent
38297daf21
commit
ada390bd4d
@ -39,6 +39,7 @@ class ParticleRenderer(
|
|||||||
) : Renderer {
|
) : Renderer {
|
||||||
private lateinit var particleShader: Shader
|
private lateinit var particleShader: Shader
|
||||||
private var particleMesh = ParticleMesh()
|
private var particleMesh = ParticleMesh()
|
||||||
|
private var transparentParticleMesh = ParticleMesh()
|
||||||
|
|
||||||
private var particles: MutableSet<Particle> = synchronizedSetOf()
|
private var particles: MutableSet<Particle> = synchronizedSetOf()
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ class ParticleRenderer(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
particleMesh.load()
|
particleMesh.load()
|
||||||
|
transparentParticleMesh.load()
|
||||||
connection.registries.particleTypeRegistry.forEachItem {
|
connection.registries.particleTypeRegistry.forEachItem {
|
||||||
for (resourceLocation in it.textures) {
|
for (resourceLocation in it.textures) {
|
||||||
renderWindow.textures.allTextures[resourceLocation] = Texture(resourceLocation)
|
renderWindow.textures.allTextures[resourceLocation] = Texture(resourceLocation)
|
||||||
@ -85,7 +87,9 @@ class ParticleRenderer(
|
|||||||
particleShader.use()
|
particleShader.use()
|
||||||
|
|
||||||
particleMesh.unload()
|
particleMesh.unload()
|
||||||
|
transparentParticleMesh.unload()
|
||||||
particleMesh = ParticleMesh()
|
particleMesh = ParticleMesh()
|
||||||
|
transparentParticleMesh = ParticleMesh()
|
||||||
|
|
||||||
|
|
||||||
for (particle in particles.toSynchronizedSet()) {
|
for (particle in particles.toSynchronizedSet()) {
|
||||||
@ -94,13 +98,16 @@ class ParticleRenderer(
|
|||||||
this.particles -= particle
|
this.particles -= particle
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
particle.addVertex(particleMesh)
|
particle.addVertex(transparentParticleMesh, particleMesh)
|
||||||
}
|
}
|
||||||
|
|
||||||
particleMesh.load()
|
particleMesh.load()
|
||||||
|
transparentParticleMesh.load()
|
||||||
|
|
||||||
|
particleMesh.draw()
|
||||||
|
|
||||||
glDepthMask(false)
|
glDepthMask(false)
|
||||||
particleMesh.draw()
|
transparentParticleMesh.draw()
|
||||||
glDepthMask(true)
|
glDepthMask(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ abstract class Particle(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun addVertex(particleMesh: ParticleMesh)
|
abstract fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val MAGIC_VELOCITY_CONSTANT = 0.4000000059604645
|
private const val MAGIC_VELOCITY_CONSTANT = 0.4000000059604645
|
||||||
|
@ -21,5 +21,5 @@ import glm_.vec3.Vec3d
|
|||||||
|
|
||||||
abstract class NoRenderParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData?) : Particle(connection, position, velocity, data) {
|
abstract class NoRenderParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData?) : Particle(connection, position, velocity, data) {
|
||||||
|
|
||||||
override fun addVertex(particleMesh: ParticleMesh) {}
|
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh) {}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
|||||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleMesh
|
import de.bixilon.minosoft.gui.rendering.particle.ParticleMesh
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.RenderParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.RenderParticle
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||||
|
import de.bixilon.minosoft.gui.rendering.textures.TextureTransparencies
|
||||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||||
import glm_.vec3.Vec3d
|
import glm_.vec3.Vec3d
|
||||||
|
|
||||||
@ -24,9 +25,13 @@ abstract class TextureParticle(connection: PlayConnection, position: Vec3d, velo
|
|||||||
abstract val texture: Texture?
|
abstract val texture: Texture?
|
||||||
|
|
||||||
|
|
||||||
override fun addVertex(particleMesh: ParticleMesh) {
|
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh) {
|
||||||
texture?.let {
|
texture?.let {
|
||||||
particleMesh.addVertex(cameraPosition, scale, it, color)
|
if (it.transparency == TextureTransparencies.TRANSLUCENT || color.alpha != 255) {
|
||||||
|
transparentMesh
|
||||||
|
} else {
|
||||||
|
particleMesh
|
||||||
|
}.addVertex(cameraPosition, scale, it, color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.advanced
|
|||||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleMesh
|
import de.bixilon.minosoft.gui.rendering.particle.ParticleMesh
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.SimpleTextureParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.SimpleTextureParticle
|
||||||
|
import de.bixilon.minosoft.gui.rendering.textures.TextureTransparencies
|
||||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
||||||
import glm_.vec3.Vec3d
|
import glm_.vec3.Vec3d
|
||||||
@ -24,9 +25,13 @@ abstract class AdvancedTextureParticle(connection: PlayConnection, position: Vec
|
|||||||
var minUV: Vec2 = Vec2(0.0f, 0.0f)
|
var minUV: Vec2 = Vec2(0.0f, 0.0f)
|
||||||
var maxUV: Vec2 = Vec2(1.0f, 1.0f)
|
var maxUV: Vec2 = Vec2(1.0f, 1.0f)
|
||||||
|
|
||||||
override fun addVertex(particleMesh: ParticleMesh) {
|
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh) {
|
||||||
texture?.let {
|
texture?.let {
|
||||||
particleMesh.addVertex(cameraPosition, scale, it, color, minUV, maxUV)
|
if (it.transparency == TextureTransparencies.TRANSLUCENT || color.alpha != 255) {
|
||||||
|
transparentMesh
|
||||||
|
} else {
|
||||||
|
particleMesh
|
||||||
|
}.addVertex(cameraPosition, scale, it, color, minUV, maxUV)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user