Skip to content

Commit

Permalink
#5909: Depth fill pass only needs to check materials with alphatest s…
Browse files Browse the repository at this point in the history
…tages, the rest can go ahead without changing the texture binding
  • Loading branch information
codereader committed Mar 18, 2022
1 parent e3cc69d commit 305f81d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
30 changes: 21 additions & 9 deletions radiantcore/rendersystem/backend/LightInteractions.cpp
Expand Up @@ -73,23 +73,35 @@ void LightInteractions::fillDepthBuffer(OpenGLState& state, GLSLDepthFillAlphaPr

if (!depthFillPass) continue;

const auto& material = shader->getMaterial();
assert(material);

// Skip translucent materials
if (shader->getMaterial() && shader->getMaterial()->getCoverage() == Material::MC_TRANSLUCENT)
if (material->getCoverage() == Material::MC_TRANSLUCENT)
{
continue;
}

// Evaluate the shader stages of this material
depthFillPass->evaluateShaderStages(renderTime, entity);
if (material->getCoverage() == Material::MC_PERFORATED)
{
// Evaluate the shader stages of this material
depthFillPass->evaluateShaderStages(renderTime, entity);

// Apply the alpha test value, it might be affected by time and entity parms
program.setAlphaTest(depthFillPass->getAlphaTestValue());
// Apply the alpha test value, it might be affected by time and entity parms
program.setAlphaTest(depthFillPass->getAlphaTestValue());

// If there's a diffuse stage, apply the correct texture
OpenGLState::SetTextureState(state.texture0, depthFillPass->state().texture0, GL_TEXTURE0, GL_TEXTURE_2D);
// If there's a diffuse stage, apply the correct texture
OpenGLState::SetTextureState(state.texture0, depthFillPass->state().texture0, GL_TEXTURE0, GL_TEXTURE_2D);

// Set evaluated stage texture transformation matrix to the GLSL uniform
program.setDiffuseTextureTransform(depthFillPass->getDiffuseTextureTransform());
// Set evaluated stage texture transformation matrix to the GLSL uniform
program.setDiffuseTextureTransform(depthFillPass->getDiffuseTextureTransform());
}
else
{
// No alpha test on this material, pass -1 to deactivate texture sampling
// in the GLSL program
program.setAlphaTest(-1);
}

for (const auto& object : objects)
{
Expand Down
10 changes: 10 additions & 0 deletions radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -1287,6 +1287,16 @@ void ShaderTemplate::determineCoverage()
{
// we have an interaction draw
_coverage = Material::MC_OPAQUE;

// Check if we have alpha-tested layers
for (const auto& layer : _layers)
{
if (layer->hasAlphaTest())
{
_coverage = Material::MC_PERFORATED;
break;
}
}
}
else
{
Expand Down

0 comments on commit 305f81d

Please sign in to comment.