Commit 246344ea authored by David Lonie's avatar David Lonie Committed by Kitware Robot

Merge topic '16899-MSAA-depth-fix'

28839f4a Fix issue with coincident geometry + MSAA. See #16899.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !2124
parents 6cf5847e 28839f4a
......@@ -564,6 +564,13 @@ bool vtkDepthPeelingPass::ReplaceShaderValues(std::string &,
"uniform sampler2D translucentZTexture;\n"
);
// Set gl_FragDepth if it isn't set already. It may have already been replaced
// by the mapper, in which case the substitution will fail and the previously
// set depth value will be used.
vtkShaderProgram::Substitute(
fragmentShader, "//VTK::Depth::Impl",
"gl_FragDepth = gl_FragCoord.z;");
// the .0000001 below is an epsilon. It turns out that
// graphics cards can render the same polygon two times
// in a row with different z values. I suspect it has to
......
......@@ -115,6 +115,12 @@ bool vtkDualDepthPeelingPass::ReplaceShaderValues(std::string &,
switch (this->CurrentStage)
{
case vtkDualDepthPeelingPass::InitializingDepth:
// Set gl_FragDepth if it isn't set already. It may have already been
// replaced by the mapper, in which case the substitution will fail and
// the previously set depth value will be used.
vtkShaderProgram::Substitute(
fragmentShader, "//VTK::Depth::Impl",
"gl_FragDepth = gl_FragCoord.z;");
vtkShaderProgram::Substitute(
fragmentShader, "//VTK::DepthPeeling::Dec",
"uniform sampler2D opaqueDepth;\n");
......@@ -136,6 +142,12 @@ bool vtkDualDepthPeelingPass::ReplaceShaderValues(std::string &,
break;
case vtkDualDepthPeelingPass::Peeling:
// Set gl_FragDepth if it isn't set already. It may have already been
// replaced by the mapper, in which case the substitution will fail and
// the previously set depth value will be used.
vtkShaderProgram::Substitute(
fragmentShader, "//VTK::Depth::Impl",
"gl_FragDepth = gl_FragCoord.z;");
vtkShaderProgram::Substitute(
fragmentShader, "//VTK::DepthPeeling::Dec",
"uniform sampler2D lastFrontPeel;\n"
......@@ -239,6 +251,12 @@ bool vtkDualDepthPeelingPass::ReplaceShaderValues(std::string &,
break;
case vtkDualDepthPeelingPass::AlphaBlending:
// Set gl_FragDepth if it isn't set already. It may have already been
// replaced by the mapper, in which case the substitution will fail and
// the previously set depth value will be used.
vtkShaderProgram::Substitute(
fragmentShader, "//VTK::Depth::Impl",
"gl_FragDepth = gl_FragCoord.z;");
vtkShaderProgram::Substitute(
fragmentShader, "//VTK::DepthPeeling::Dec",
"uniform sampler2D lastDepthPeel;\n");
......
......@@ -1559,17 +1559,28 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderDepth(
std::map<vtkShader::Type, vtkShader *> shaders,
vtkRenderer *, vtkActor *)
{
std::string FSSource = shaders[vtkShader::Fragment]->GetSource();
vtkShaderProgram::Substitute(FSSource,"//VTK::Depth::Impl",
"gl_FragDepth = gl_FragCoord.z;");
shaders[vtkShader::Fragment]->SetSource(FSSource);
// If MSAA is enabled, don't write to gl_FragDepth unless we absolutely have
// to. See VTK issue 16899.
#if GL_ES_VERSION_3_0 != 1
bool multisampling = glIsEnabled(GL_MULTISAMPLE) == GL_TRUE;
#else
bool multisample = false;
#endif
if (!multisampling)
{
std::string FSSource = shaders[vtkShader::Fragment]->GetSource();
vtkShaderProgram::Substitute(FSSource,
"//VTK::Depth::Impl",
"gl_FragDepth = gl_FragCoord.z;");
shaders[vtkShader::Fragment]->SetSource(FSSource);
}
}
void vtkOpenGLPolyDataMapper::ReplaceShaderValues(
std::map<vtkShader::Type, vtkShader *> shaders,
vtkRenderer *ren, vtkActor *actor)
{
this->ReplaceShaderRenderPass(shaders, ren, actor);
this->ReplaceShaderColor(shaders, ren, actor);
this->ReplaceShaderNormal(shaders, ren, actor);
this->ReplaceShaderLight(shaders, ren, actor);
......@@ -1580,6 +1591,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(
this->ReplaceShaderPositionVC(shaders, ren, actor);
this->ReplaceShaderCoincidentOffset(shaders, ren, actor);
this->ReplaceShaderDepth(shaders, ren, actor);
this->ReplaceShaderRenderPass(shaders, ren, actor);
//cout << "VS: " << shaders[vtkShader::Vertex]->GetSource() << endl;
//cout << "GS: " << shaders[vtkShader::Geometry]->GetSource() << endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment