mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 14:04:23 +02:00
Remove additive blending option (force it)
This commit is contained in:
parent
4827a96bfa
commit
2dd494b5df
2 changed files with 10 additions and 65 deletions
|
@ -23,7 +23,6 @@
|
||||||
#include "untextured_particle_frag.h"
|
#include "untextured_particle_frag.h"
|
||||||
#include "textured_particle_vert.h"
|
#include "textured_particle_vert.h"
|
||||||
#include "textured_particle_frag.h"
|
#include "textured_particle_frag.h"
|
||||||
#include "textured_particle_alpha_discard_frag.h"
|
|
||||||
|
|
||||||
static const size_t VERTEX_PER_PARTICLE = 4;
|
static const size_t VERTEX_PER_PARTICLE = 4;
|
||||||
|
|
||||||
|
@ -230,20 +229,6 @@ void RenderableParticleEffectEntityItem::updateRenderItem() {
|
||||||
particlePrimitives->emplace_back(particle.position, glm::vec2(particle.lifetime, particle.seed));
|
particlePrimitives->emplace_back(particle.position, glm::vec2(particle.lifetime, particle.seed));
|
||||||
}
|
}
|
||||||
|
|
||||||
// No need to sort if we're doing additive blending
|
|
||||||
if (!_additiveBlending) {
|
|
||||||
// sort particles back to front
|
|
||||||
// NOTE: this is view frustum might be one frame out of date.
|
|
||||||
auto direction = AbstractViewStateInterface::instance()->getCurrentViewFrustum()->getDirection();
|
|
||||||
// Get direction in the entity space
|
|
||||||
direction = glm::inverse(getRotation()) * direction;
|
|
||||||
|
|
||||||
std::sort(particlePrimitives->begin(), particlePrimitives->end(),
|
|
||||||
[&](const ParticlePrimitive& lhs, const ParticlePrimitive& rhs) {
|
|
||||||
return glm::dot(lhs.xyz, direction) > glm::dot(rhs.xyz, direction);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto bounds = getAABox();
|
auto bounds = getAABox();
|
||||||
auto position = getPosition();
|
auto position = getPosition();
|
||||||
auto rotation = getRotation();
|
auto rotation = getRotation();
|
||||||
|
@ -283,44 +268,29 @@ void RenderableParticleEffectEntityItem::updateRenderItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableParticleEffectEntityItem::createPipelines() {
|
void RenderableParticleEffectEntityItem::createPipelines() {
|
||||||
bool writeToDepthBuffer = false;
|
|
||||||
gpu::State::BlendArg destinationColorBlendArg;
|
|
||||||
if (_additiveBlending) {
|
|
||||||
destinationColorBlendArg = gpu::State::ONE;
|
|
||||||
} else {
|
|
||||||
destinationColorBlendArg = gpu::State::INV_SRC_ALPHA;
|
|
||||||
writeToDepthBuffer = true;
|
|
||||||
}
|
|
||||||
if (!_untexturedPipeline) {
|
if (!_untexturedPipeline) {
|
||||||
auto state = std::make_shared<gpu::State>();
|
auto state = std::make_shared<gpu::State>();
|
||||||
state->setCullMode(gpu::State::CULL_BACK);
|
state->setCullMode(gpu::State::CULL_BACK);
|
||||||
state->setDepthTest(true, writeToDepthBuffer, gpu::LESS_EQUAL);
|
state->setDepthTest(true, false, gpu::LESS_EQUAL);
|
||||||
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD,
|
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE,
|
||||||
destinationColorBlendArg, gpu::State::FACTOR_ALPHA,
|
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||||
gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
|
||||||
auto vertShader = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(untextured_particle_vert)));
|
auto vertShader = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(untextured_particle_vert)));
|
||||||
auto fragShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(untextured_particle_frag)));
|
auto fragShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(untextured_particle_frag)));
|
||||||
|
|
||||||
auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vertShader, fragShader));
|
auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vertShader, fragShader));
|
||||||
_untexturedPipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
_untexturedPipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
||||||
}
|
}
|
||||||
if (!_texturedPipeline) {
|
if (!_texturedPipeline) {
|
||||||
auto state = std::make_shared<gpu::State>();
|
auto state = std::make_shared<gpu::State>();
|
||||||
state->setCullMode(gpu::State::CULL_BACK);
|
state->setCullMode(gpu::State::CULL_BACK);
|
||||||
|
state->setDepthTest(true, false, gpu::LESS_EQUAL);
|
||||||
|
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE,
|
||||||
|
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||||
|
|
||||||
|
|
||||||
bool writeToDepthBuffer = !_additiveBlending;
|
|
||||||
state->setDepthTest(true, writeToDepthBuffer, gpu::LESS_EQUAL);
|
|
||||||
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD,
|
|
||||||
destinationColorBlendArg, gpu::State::FACTOR_ALPHA,
|
|
||||||
gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
|
||||||
auto vertShader = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(textured_particle_vert)));
|
auto vertShader = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(textured_particle_vert)));
|
||||||
gpu::ShaderPointer fragShader;
|
auto fragShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(textured_particle_frag)));
|
||||||
if (_additiveBlending) {
|
|
||||||
fragShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(textured_particle_frag)));
|
|
||||||
} else {
|
|
||||||
//If we are sorting and have no additive blending, we want to discard pixels with low alpha to avoid inter-particle entity artifacts
|
|
||||||
fragShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(textured_particle_alpha_discard_frag)));
|
|
||||||
}
|
|
||||||
auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vertShader, fragShader));
|
auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vertShader, fragShader));
|
||||||
_texturedPipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
_texturedPipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
||||||
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
<@include gpu/Config.slh@>
|
|
||||||
<$VERSION_HEADER$>
|
|
||||||
// Generated on <$_SCRIBE_DATE$>
|
|
||||||
// fragment shader
|
|
||||||
//
|
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
uniform sampler2D colorMap;
|
|
||||||
|
|
||||||
in vec4 varColor;
|
|
||||||
in vec2 varTexcoord;
|
|
||||||
|
|
||||||
out vec4 outFragColor;
|
|
||||||
|
|
||||||
void main(void) {
|
|
||||||
vec4 color = texture(colorMap, varTexcoord);
|
|
||||||
if (color.a < 0.1) {
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
outFragColor = color * varColor;
|
|
||||||
}
|
|
Loading…
Reference in a new issue