Skip to content

Commit

Permalink
Ensure that gl_FragDepth is set as-intended with tubes/spheres.
Browse files Browse the repository at this point in the history
The depth was being set in //VTK::Normal::Impl, while the
default //VTK::Depth::Impl was still being used. The default
depth was being used for determining fragment depth during
depth peeling, which led to artifacts on translucent objects.

Refactoring the shaders to set the tube/sphere depth using the
appropriate hook fixes issue #17482.
  • Loading branch information
Allison Vacanti committed Jan 15, 2019
1 parent 6b0342d commit 8099519
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1296,19 +1296,24 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
"uniform float ZCalcR;\n"
);
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Impl",
"//VTK::Depth::Impl",
"float xpos = 2.0*gl_PointCoord.x - 1.0;\n"
" float ypos = 1.0 - 2.0*gl_PointCoord.y;\n"
" float len2 = xpos*xpos+ ypos*ypos;\n"
" if (len2 > 1.0) { discard; }\n"
" vec3 normalVCVSOutput = normalize(\n"
" vec3(2.0*gl_PointCoord.x - 1.0, 1.0 - 2.0*gl_PointCoord.y, sqrt(1.0 - len2)));\n"
" gl_FragDepth = gl_FragCoord.z + normalVCVSOutput.z*ZCalcS*ZCalcR;\n"
" if (cameraParallel == 0)\n"
" {\n"
" float ZCalcQ = (normalVCVSOutput.z*ZCalcR - 1.0);\n"
" gl_FragDepth = (ZCalcS - gl_FragCoord.z) / ZCalcQ + ZCalcS;\n"
" }\n"
);

" float xpos = 2.0*gl_PointCoord.x - 1.0;\n"
" float ypos = 1.0 - 2.0*gl_PointCoord.y;\n"
" float len2 = xpos*xpos+ ypos*ypos;\n"
" if (len2 > 1.0) { discard; }\n"
" vec3 normalVCVSOutput = normalize(\n"
" vec3(2.0*gl_PointCoord.x - 1.0, 1.0 - 2.0*gl_PointCoord.y, sqrt(1.0 - len2)));\n"

" gl_FragDepth = gl_FragCoord.z + normalVCVSOutput.z*ZCalcS*ZCalcR;\n"
" if (cameraParallel == 0) {\n"
" float ZCalcQ = (normalVCVSOutput.z*ZCalcR - 1.0);\n"
" gl_FragDepth = (ZCalcS - gl_FragCoord.z) / ZCalcQ + ZCalcS; }\n"
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Impl",
"//Normal computed in Depth::Impl"
);

shaders[vtkShader::Fragment]->SetSource(FSSource);
Expand Down Expand Up @@ -1341,15 +1346,19 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
"uniform float ZCalcR;\n"
);
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Impl",

"//VTK::Depth::Impl",
"float len2 = tubeBasis1.x*tubeBasis1.x + tubeBasis1.y*tubeBasis1.y;\n"
"float lenZ = clamp(sqrt(1.0 - len2),0.0,1.0);\n"
" float lenZ = clamp(sqrt(1.0 - len2),0.0,1.0);\n"
" gl_FragDepth = gl_FragCoord.z + lenZ*ZCalcS*ZCalcR/clamp(tubeBasis2.z,0.5,1.0);\n"
" if (cameraParallel == 0)\n"
" {\n"
" float ZCalcQ = (lenZ*ZCalcR/clamp(tubeBasis2.z,0.5,1.0) - 1.0);\n"
" gl_FragDepth = (ZCalcS - gl_FragCoord.z) / ZCalcQ + ZCalcS;\n"
" }\n"
);
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Impl",
"vec3 normalVCVSOutput = normalize(tubeBasis1 + tubeBasis2*lenZ);\n"
" gl_FragDepth = gl_FragCoord.z + lenZ*ZCalcS*ZCalcR/clamp(tubeBasis2.z,0.5,1.0);\n"
" if (cameraParallel == 0) {\n"
" float ZCalcQ = (lenZ*ZCalcR/clamp(tubeBasis2.z,0.5,1.0) - 1.0);\n"
" gl_FragDepth = (ZCalcS - gl_FragCoord.z) / ZCalcQ + ZCalcS; }\n"
);

vtkShaderProgram::Substitute(GSSource,
Expand Down

0 comments on commit 8099519

Please sign in to comment.