Factorize transparent mesh rendering.
This commit is contained in:
parent
eaded3bf46
commit
4c9d1888f8
@ -648,7 +648,30 @@ void IrrDriver::renderTransparent()
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glDisable(GL_CULL_FACE);
|
||||
TransparentMeshes<TM_DEFAULT>::reset();
|
||||
TransparentMeshes<TM_ADDITIVE>::reset();
|
||||
m_scene_manager->drawAll(scene::ESNRP_TRANSPARENT);
|
||||
|
||||
if (World::getWorld() && World::getWorld()->isFogEnabled())
|
||||
{
|
||||
glUseProgram(MeshShader::TransparentFogShader::Program);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for (unsigned i = 0; i < TransparentMeshes<TM_DEFAULT>::MeshSet.size(); i++)
|
||||
drawTransparentFogObject(*TransparentMeshes<TM_DEFAULT>::MeshSet[i], TransparentMeshes<TM_DEFAULT>::MVPSet[i], TransparentMeshes<TM_DEFAULT>::MeshSet[i]->TextureMatrix);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
for (unsigned i = 0; i < TransparentMeshes<TM_ADDITIVE>::MeshSet.size(); i++)
|
||||
drawTransparentFogObject(*TransparentMeshes<TM_ADDITIVE>::MeshSet[i], TransparentMeshes<TM_ADDITIVE>::MVPSet[i], TransparentMeshes<TM_ADDITIVE>::MeshSet[i]->TextureMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
glUseProgram(MeshShader::TransparentShader::Program);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for (unsigned i = 0; i < TransparentMeshes<TM_DEFAULT>::MeshSet.size(); i++)
|
||||
drawTransparentObject(*TransparentMeshes<TM_DEFAULT>::MeshSet[i], TransparentMeshes<TM_DEFAULT>::MVPSet[i], TransparentMeshes<TM_DEFAULT>::MeshSet[i]->TextureMatrix);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
for (unsigned i = 0; i < TransparentMeshes<TM_ADDITIVE>::MeshSet.size(); i++)
|
||||
drawTransparentObject(*TransparentMeshes<TM_ADDITIVE>::MeshSet[i], TransparentMeshes<TM_ADDITIVE>::MVPSet[i], TransparentMeshes<TM_ADDITIVE>::MeshSet[i]->TextureMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
void IrrDriver::renderParticles()
|
||||
|
@ -227,30 +227,16 @@ void STKAnimatedMesh::render()
|
||||
glUseProgram(MeshShader::BubbleShader::Program);
|
||||
|
||||
GLMesh* mesh;
|
||||
for_in(mesh, TransparentMesh[TM_BUBBLE])
|
||||
drawBubble(*mesh, ModelViewProjectionMatrix);
|
||||
|
||||
if (World::getWorld() != NULL && World::getWorld()->isFogEnabled())
|
||||
for_in(mesh, TransparentMesh[TM_DEFAULT])
|
||||
{
|
||||
if (!TransparentMesh[TM_DEFAULT].empty() || !TransparentMesh[TM_ADDITIVE].empty())
|
||||
glUseProgram(MeshShader::TransparentFogShader::Program);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for_in(mesh, TransparentMesh[TM_DEFAULT])
|
||||
drawTransparentFogObject(*mesh, ModelViewProjectionMatrix, mesh->TextureMatrix);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
for_in(mesh, TransparentMesh[TM_ADDITIVE])
|
||||
drawTransparentFogObject(*mesh, ModelViewProjectionMatrix, mesh->TextureMatrix);
|
||||
TransparentMeshes<TM_DEFAULT>::MeshSet.push_back(mesh);
|
||||
TransparentMeshes<TM_DEFAULT>::MVPSet.push_back(ModelViewProjectionMatrix);
|
||||
}
|
||||
else
|
||||
|
||||
for_in(mesh, TransparentMesh[TM_ADDITIVE])
|
||||
{
|
||||
if (!TransparentMesh[TM_DEFAULT].empty() || !TransparentMesh[TM_ADDITIVE].empty())
|
||||
glUseProgram(MeshShader::TransparentShader::Program);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for_in(mesh, TransparentMesh[TM_DEFAULT])
|
||||
drawTransparentObject(*mesh, ModelViewProjectionMatrix, mesh->TextureMatrix);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
for_in(mesh, TransparentMesh[TM_ADDITIVE])
|
||||
drawTransparentObject(*mesh, ModelViewProjectionMatrix, mesh->TextureMatrix);
|
||||
TransparentMeshes<TM_ADDITIVE>::MeshSet.push_back(mesh);
|
||||
TransparentMeshes<TM_ADDITIVE>::MVPSet.push_back(ModelViewProjectionMatrix);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -147,6 +147,25 @@ void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectio
|
||||
void drawShadowRef(const GLMesh &mesh, const core::matrix4 &ModelMatrix);
|
||||
void drawShadow(const GLMesh &mesh, const core::matrix4 &ModelMatrix);
|
||||
|
||||
template<enum TransparentMaterial T>
|
||||
class TransparentMeshes
|
||||
{
|
||||
public:
|
||||
static std::vector<GLMesh *> MeshSet;
|
||||
static std::vector<core::matrix4> MVPSet;
|
||||
|
||||
static void reset()
|
||||
{
|
||||
MeshSet.clear();
|
||||
MVPSet.clear();
|
||||
}
|
||||
};
|
||||
|
||||
template<enum TransparentMaterial T>
|
||||
std::vector<GLMesh *> TransparentMeshes<T>::MeshSet;
|
||||
template<enum TransparentMaterial T>
|
||||
std::vector<core::matrix4> TransparentMeshes<T>::MVPSet;
|
||||
|
||||
// Forward pass (for transparents meshes)
|
||||
void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
|
||||
void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
|
||||
|
@ -440,33 +440,23 @@ void STKMeshSceneNode::render()
|
||||
ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation);
|
||||
|
||||
GLMesh* mesh;
|
||||
|
||||
for_in(mesh, TransparentMesh[TM_DEFAULT])
|
||||
{
|
||||
TransparentMeshes<TM_DEFAULT>::MeshSet.push_back(mesh);
|
||||
TransparentMeshes<TM_DEFAULT>::MVPSet.push_back(ModelViewProjectionMatrix);
|
||||
}
|
||||
|
||||
for_in(mesh, TransparentMesh[TM_ADDITIVE])
|
||||
{
|
||||
TransparentMeshes<TM_ADDITIVE>::MeshSet.push_back(mesh);
|
||||
TransparentMeshes<TM_ADDITIVE>::MVPSet.push_back(ModelViewProjectionMatrix);
|
||||
}
|
||||
|
||||
if (!TransparentMesh[TM_BUBBLE].empty())
|
||||
glUseProgram(MeshShader::BubbleShader::Program);
|
||||
for_in(mesh, TransparentMesh[TM_BUBBLE])
|
||||
drawBubble(*mesh, ModelViewProjectionMatrix);
|
||||
|
||||
if (World::getWorld() ->isFogEnabled())
|
||||
{
|
||||
if (!TransparentMesh[TM_DEFAULT].empty() || !TransparentMesh[TM_ADDITIVE].empty())
|
||||
glUseProgram(MeshShader::TransparentFogShader::Program);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for_in(mesh, TransparentMesh[TM_DEFAULT])
|
||||
drawTransparentFogObject(*mesh, ModelViewProjectionMatrix, (*mesh).TextureMatrix);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
for_in(mesh, TransparentMesh[TM_ADDITIVE])
|
||||
drawTransparentFogObject(*mesh, ModelViewProjectionMatrix, (*mesh).TextureMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!TransparentMesh[TM_DEFAULT].empty() || !TransparentMesh[TM_ADDITIVE].empty())
|
||||
glUseProgram(MeshShader::TransparentShader::Program);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for_in(mesh, TransparentMesh[TM_DEFAULT])
|
||||
drawTransparentObject(*mesh, ModelViewProjectionMatrix, (*mesh).TextureMatrix);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
for_in(mesh, TransparentMesh[TM_ADDITIVE])
|
||||
drawTransparentObject(*mesh, ModelViewProjectionMatrix, (*mesh).TextureMatrix);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user