Translucent assemblies in 8.2.0

(Eric Fahlgren) #1

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()
(Eric Fahlgren) #2

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
(Eric Fahlgren) #3

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?

(Cory Quammen (Kitware)) #4

@allison.vacanti @ken-martin Thoughts?

(Eric Fahlgren) #5

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

(Allison Vacanti) #6

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.

(Eric Fahlgren) #7

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

(Ken Martin) #8

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

(Allison Vacanti) #9

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

(Eric Fahlgren) #10

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

image

(Eric Fahlgren) #11

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!

(Allison Vacanti) #12

Great! Glad it worked for you.

(Andreas Buykx) #13

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?

(Eric Fahlgren) #14

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

(Andreas Buykx) #15

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.