Change in rendering of semi-opaque solid meshes with edges enabled

Hello. We recently updated from VTK 8.1.1 to VTK 9.2.6. It has been pretty smooth, but I have noticed one issue.


This is with:
Opacity of less than 1.
This occurs both with and without depth peeling.

The triangle edge in the middle is only barely visible, and only with transparency turned on. I did diff the relevant sections of vtkOpenGLPolyDataMapper.cxx, and there seem to have been many MANY changes in this area. Does anybody have any insight?


Hmm. This is not the first time seeing that happen. Can you try to increase the line width? Default is 1. The surface with edges algorithm used in vtkOpenGLPolyDataMapper works best with line widths somewhere between 2 and 5.

Hi, thanks for responding! Setting the thickness to be larger has the same effect, just with thicker lines

Unfortunately it is very important that I continue to support arbitrary line widths, including a thickness of 1.

I’m guessing you are talking about some of the work done in vtkOpenGLPolyDataMapper::RenderPieceDraw ? It looks like there have been a number of changes in that function related to the ways that lines are drawn, I’m picking it apart to see if any of it could be involved.

This happens only at specific camera viewpoints, right? I assumed it’s just a quad. Here is what I tried to emulate your issue. Interestingly enough, changing the edge color to something that’s not close to the surface color removes that diagonal line. ex: edge colored red. With a width of 1, I can still see some traces of red on the diagonal.

import vtk

polydata = vtk.vtkPolyData()
points = vtk.vtkPoints()
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(1, 0, 0)
points.InsertNextPoint(1, 1, 0)
points.InsertNextPoint(0, 1, 0)
polys = vtk.vtkCellArray()
polys.InsertNextCell(4, [0, 1, 2, 3])
colors = vtk.vtkUnsignedCharArray()
colors.InsertNextTuple([200, 200, 200, 255])

mapper = vtk.vtkPolyDataMapper()

actor = vtk.vtkActor()
actor.GetProperty().SetEdgeColor(1, 0, 0)

renderer = vtk.vtkRenderer()

renWin = vtk.vtkRenderWindow()

interactor = vtk.vtkRenderWindowInteractor()

The related code is in vtkPolyDataEdgesGS.glsl and vtkOpenGLPolyDataMapper::ReplaceShaderEdges, bisecting there can help you figure it out. I’m almost sure this is a precision issue when the shader computes color using emix for the invisible edges.

Please open an issue at This is a bug.


If you squint hard enough, there’s a red diagonal.

Wow, thanks for making my MRE for me! Tomorrow morning I will see if I can find anything in the file you specified, and in either case I will file the bug report.

No worries. Surface with edges in OpenGL has been optimized in the past. The algorithm is based on with some modifications. In VTK, it has some artifacts like you pointed out and more in

For the upcoming WebGPU mapper, I attempted a slightly different approach based on the original algorithm without deviating, shader

Here’s how it looks with the experimental WebGPU mapper without anti-aliasing.


Oh, and to answer your question, yes I only see it from oblique angles. It tends to go away when the surface is viewed from acute angles.

Cool, I will review the WebGPU shader as well. Being honest, I had always wondered how this effect was done in VTK, happy to poke around and find out. That is a nifty looking algo.

Bug filed:

Unfortunately it will not be possible for me to look into this issue further.