overlay/transparency issue with QVTKOpenGLNativeWidget

I had previously been using QVTKWidget in VTK 7.1.0 with no issues. I decided to upgrade to VTK 8.2.0 and try out QVTKOpenGLNativeWidget. However I am noticing that with the new widget when I overlay two vtkImageActors, the opacity on the top one is reduced for some reason. You can see the attached example. The blue was full opacity before (as it was meant to be), but now is reduced. I’ve put some code below. Any help would be much appreciated! Thanks.

And here is a snippet of code that should give an idea of my pipeline:

    QVTKOpenGLNativeWidget *window = new QVTKOpenGLNativeWidget();
	window->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	window->setMinimumSize(QSize(580, 330));
	vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();

	for (int i = 0; i < 2; ++i)
		// map
		vtkSmartPointer<vtkImageMapToColors> imapper = vtkSmartPointer<vtkImageMapToColors>::New();
		imapper->SetLookupTable(lut[i]); // custom lookup tables (one is just normal grayscale, the other is blue with full transparency on the low end and no transparency on the high end
		// im[0] and im[1] are my vtkImageData that I load up from saved images

		// actor
		vtkSmartPointer<vtkImageActor> iactor = vtkSmartPointer<vtkImageActor>::New();



This is on Windows 10, 64-bit. Using Visual Studio 2017.

1 Like

You might need to enable depth peeling to ensure rendering of semi-transparent polygons in the correct order.

Thanks for the suggestion! Depth peeling helped but still produced some odd opacity issues. However after offsetting the images very slightly (1e-6) the depth peeling was then able to process them correctly. Thanks.

1 Like

Did you try with QVTKOpenGLWidget as well ?

Yes, I found that QVTKOpenGLWidget had the same issues, but also had some other issues with Qt (like overlaying Qt widgets) that the Native version didn’t have.

If you have multiple things exactly in the same position then you need to apply one of the coincident topology resolution techniques. See for example http://vtk.1045678.n5.nabble.com/Coincident-topology-questions-td5746090.html

Unfortunately it appears that the use of depth peeling slows down image rendering substantially. For now I will have to revert back to VTK 7.1.0.

For anyone who is curious, I found a solution for this using VTK 8.2.0. In the function vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry() you uncomment the line after the “// old code” line, and comment out the block below that which starts with “// new approach”. It looks like it was an attempt to improve how translucent geometry was rendered, but made it necessary to use depth peeling (much slower) to get proper translucent effects.