diff --git a/SparkEmitter.cpp b/SparkEmitter.cpp index 59eb352..f5c8dd7 100644 --- a/SparkEmitter.cpp +++ b/SparkEmitter.cpp @@ -54,9 +54,22 @@ namespace ZL { return; } - for (const auto& particle : particles) { - if (!particle.active) continue; + std::vector> sortedParticles; + sortedParticles.reserve(getActiveParticleCount()); + for (const auto& particle : particles) { + if (particle.active) { + sortedParticles.push_back({ &particle, particle.position.v[2] }); + } + } + + std::sort(sortedParticles.begin(), sortedParticles.end(), + [](const auto& a, const auto& b) { + return a.second > b.second; + }); + + for (const auto& [particlePtr, depth] : sortedParticles) { + const auto& particle = *particlePtr; Vector3f pos = particle.position; float size = 0.04f * particle.scale; @@ -116,6 +129,9 @@ namespace ZL { glBindTexture(GL_TEXTURE_2D, texture->getTexID()); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE);// Аддитивное смешивание для эффекта свечения + renderer.PushMatrix(); renderer.LoadIdentity(); renderer.TranslateMatrix({ 0, 0, -1.0f * zoom }); @@ -124,6 +140,9 @@ namespace ZL { renderer.PopMatrix(); renderer.PopProjectionMatrix(); + + glDisable(GL_BLEND); + renderer.DisableVertexAttribArray(vPositionName); renderer.DisableVertexAttribArray(vTexCoordName); renderer.shaderManager.PopShader();