Translucent assemblies in 8.2.0

I’m seeing a regression in 8.2.0 when rendering translucent objects inside a vtkAssembly. Here are four screen snaps of my test script’s output, top row is VTK 8.1.2, bottom row is VTK 8.2.0. Left column has actors added to scene directly, right column has the actor added to a vtkAssembly, which is then added to the scene.

The 8.2-inside-assembly appears to lose color information somewhere, or sets ambient light to 1, or ??? Is there something I need to add to assemblies now to allow translucency to render properly?

#!/usr/bin/env python

import vtk

use_actors = False
print(vtk.vtkVersion().GetVTKSourceVersion(), use_actors)

def addBall(renderer, center, translucent=False):
    source = vtk.vtkSphereSource()
    source.SetCenter(*center)
    source.SetRadius(3.0)
    source.SetPhiResolution(20)
    source.SetThetaResolution(20)
    source.Update()

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(source.GetOutput())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    if translucent:
        actor.GetProperty().SetOpacity(0.5)

    if use_actors:
        renderer.AddActor(actor)
        return actor
    else:
        assembly = vtk.vtkAssembly()
        assembly.AddPart(actor)
        renderer.AddActor(assembly)
        return assembly

renderer = vtk.vtkRenderer()
renderer.SetBackground(1,1,1)

renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)

a = addBall(renderer, center=(0,0,5), translucent=True)
b = addBall(renderer, center=(1,0,0))

renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindowInteractor.Initialize()

renderWindow.Render()
#print(a)
#print(b)

renderWindowInteractor.Start()

This is definitely a bug in 8.2, I just tested on another machine with completely different hardware and it’s evident there, too. Also applies to any images (irrespective of transparency) that are inside a vtkAssembly.

Here’s some environment information for the two machines:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]
Windows sys.getwindowsversion(major=10, minor=0, build=17134, platform=2, service_pack='')
VTK 8.2.0 Tue Feb 26 07:53:25 2019
OpenGL vendor string:  Intel
OpenGL renderer string:  Intel(R) HD Graphics 630
OpenGL version string:  4.5.0 - Build 25.20.100.6519
OpenGL extensions:  
  ...

PixelFormat Descriptor:
depth:  24
class:  TrueColor
buffer size:  32
level:  0
renderType:  rgba
double buffer:  True
stereo:  False
hardware acceleration:  True
rgba:  redSize=8 greenSize=8blueSize=8alphaSize=8
aux buffers:  0
depth size:  24
stencil size:  8
accum:  redSize=16 greenSize=16blueSize=16alphaSize=16
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]
Windows sys.getwindowsversion(major=10, minor=0, build=17763, platform=2, service_pack='')
VTK 8.2.0 Tue Feb 26 07:53:25 2019
OpenGL vendor string:  NVIDIA Corporation
OpenGL renderer string:  GeForce GTX 1070/PCIe/SSE2
OpenGL version string:  4.5.0 NVIDIA 418.91
OpenGL extensions:  
  ...

PixelFormat Descriptor:
depth:  24
class:  TrueColor
buffer size:  32
level:  0
renderType:  rgba
double buffer:  True
stereo:  False
hardware acceleration:  True
rgba:  redSize=8 greenSize=8blueSize=8alphaSize=8
aux buffers:  4
depth size:  24
stencil size:  0
accum:  redSize=16 greenSize=16blueSize=16alphaSize=16

Anyone have any hints as to where I might start debugging this? vtkAssembly has not changed between 8.1 and 8.2, so it’s not there. I’m guessing the rendering passes in OGL2? Possibly the AA passes?

@allison.vacanti @ken-martin Thoughts?

I just turned on renderer.SetDepthPeeling(True) and that affects the rendering quite a bit, by adding edges, but I’ve stayed away from it before because of the huge performance hit. (I did not test depth peeling with images inside assemblies, which may be a different issue.)

Each image has three spheres, back (red) is not transparent, two front are 0.5 transparent, leftmost sphere is inside an assembly.

8.1.0 without depth peeling, this is my baseline for “looks correct”.
image

8.1 with depth peeling. Looks wrong in that the sphere inside the assembly is too bright.
image

8.2 without. Clearly wacko.
image

8.2 with, looks the same as 8.1 with depth peeling, with the same brightness artifact.
image

I’m not sure what this would be. It’s been a while since I’ve worked on VTK’s rendering, and I’m unfamiliar with how the vtkAssembly are supposed to work. I look through the changes to the assembly classes between 8.1.2 and 8.2 and nothing really changed there.

Maybe @ken-martin knows?

You mentioned something about rendering an image – are the spheres vtkImageData rendered through a vtkVolume? Mixing volumes and other props can be tricky, if so.

I think maybe the images are a different issue, they’re always an issue for us. On the other hand, the spheres are just simple vtkSphereSource -> vtkPolydata (see code in first post). I made my test case as simple as possible to help in debugging (probably should port it to cxx to make it easier for real debuggers, and not hacking debug like I do in Python).

Eric

Sounds a lot like actor information or shader replacements not getting propagated down the assembly as a guess

That was my suspicion, too, since that’s usually the culprit for these sorts of rendering bugs. And sure enough…

image

Patch that fixes it is here: https://gitlab.kitware.com/vtk/vtk/merge_requests/5312

Thanks, Allison! I merged the patch, built and tested. Looks great!

image

This also fixes some other artifacts that I hadn’t immediately connected up with this one. When edge/line objects (leaders or boxes or whatever) were drawn translucent in the line of sight with an opaque object, they would completely disappear over the background object. This has been an issue for us for years, and it looks like your patch fixes that also, so thanks again!

Great! Glad it worked for you.

A while ago I reported problems with transparency in rendering composite data. The above problem looks quite similar. Would the same solution be applicable too?

I’m not sure what I should see, but here’s what your script produces with my patched 8.2.0 build.

Thanks. I made this test to demonstrate how the composite data mappers handle vtkMultiBlockDataSet containing blocks with mixed opacity (middle row). From left to right: vtkCompositePolyDataMapper2, vtkCompositePolyDataMapper, both blocks appended into a single vtkPolyData mapped by vtkPolyDataMapper, and finally each block mapped by a separate vtkPolyDataMapper+vtkActor.

I am glad to have found this discussion. I ran into a very similar problem, just not related to vtkAssembly but rather vtkPropAssembly. I could use the same fix on vtkPropAssembly as presented by Allison for vtkAssembly. Please have a look at https://gitlab.kitware.com/vtk/vtk/merge_requests/6179 if this sounds relevant to you.

Hello,

luckily I have found this thread and both merge requests helped me a lot. Thank you very much for them.

But not all of my problems were solved unfortunately. I use the vtkInteractorStyleUser to implement custom scene navigation. At the moment when I start e.g. rotation or other camera movement, the vtkPropAssembly starts to render exactly as before the fixes mentioned here were applied. Strange is that if I stop the camera movement for a while (e.g. 1s) assembly is rendered correctly and since then the rendering is correct even if I start to move the camera again.

I do not understand it as I do not use any kind of timers to invoke rendering. Anyone has an idea what is going on here? Please tell me.

Petr