# Bug on transparency between actor and widgetin VTK9?

**URL:** https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590
**Category:** Development
**Created:** [September 18, 2024, 7:37am UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590 "2024-09-18T07:37:01Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Laure\_C](https://discourse.vtk.org/user_avatar/discourse.vtk.org/laure_c/32/9269_2.png) [@Laure\_C](https://discourse.vtk.org/u/Laure_C)
#### Post date: [September 18, 2024, 7:37am UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/1 "2024-09-18T07:37:01Z")

</div>

Hi,

I want to display an actor and a widget with some transparency.  
It seems VTK8 was in alpha blending but VTK9 uses additive blending. Shading seems broken too.  
How to do to have same rendering as in VTK 8?

![image](https://discourse.vtk.org/uploads/default/original/2X/c/c633e20e449599795619f32325530159ff29b35b.png)

```auto
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereRepresentation.h>
#include <vtkSphereSource.h>
#include <vtkSphereWidget2.h>

int main(int, char*[])
{
    // Create a sphere/mapper/actor
    auto sphereSource = vtkSmartPointer<vtkSphereSource>::New();
    sphereSource->SetRadius(2.0);
    auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(sphereSource->GetOutputPort());
    auto actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
    actor->GetProperty()->SetOpacity(0.5);

    // Create a renderer/render window/interactor
    auto renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);
    renderer->SetBackground(0, 0, 0);
    auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);
    auto renderWindowInteractor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);

    // Create widget
    auto sphereWidget = vtkSmartPointer<vtkSphereWidget2>::New();
    sphereWidget->SetInteractor(renderWindow->GetInteractor());
    auto sphereRep = vtkSmartPointer<vtkSphereRepresentation>::New();
    sphereWidget->SetRepresentation(sphereRep);
    sphereRep->SetRadius(1);
    sphereRep->UseBoundsOff();
    sphereRep->HandleTextOff();
    sphereRep->RadialLineOff();
    sphereRep->GetSphereProperty()->SetOpacity(0.99);
    sphereRep->GetSphereProperty()->SetColor(0.0, 1.0, 0.0);
    sphereRep->SetRepresentationToSurface();
    sphereWidget->On();

    // Start the rendering loop
    renderWindow->Render();
    renderer->ResetCamera();
    renderWindowInteractor->Start();

    return 0;
}

```

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [September 19, 2024, 6:40pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/2 "2024-09-19T18:40:03Z")

</div>

I tried adding a normal `vtkActor`, `vtkPolyDataMapper` and `vtkSphereSource`. I compared the properties, identical, but the sphere from the widget appears wrongly (like the author has shown). Removing the `SetOpacity(0.99)` makes it appear correct, but I guess you know that. It seems like the OIT is broken.

---

<div class="post-metadata">

### Author: ![Laure\_C](https://discourse.vtk.org/user_avatar/discourse.vtk.org/laure_c/32/9269_2.png) [@Laure\_C](https://discourse.vtk.org/u/Laure_C)
#### Post date: [September 20, 2024, 7:43am UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/3 "2024-09-20T07:43:53Z")

</div>

Effectively, having 2 `vtkSphereSource` with `vtkPolyDataMapper` and `vtkActor` with transparency appears correctly. But obviously I need to have a `vtkAbstractWidget` (with transparency, obviously too…).

In reality, I don’t use `vtkSphereWidget2` and `vtkWidgetRepresentation`, but my own widget and representation, inherit from `vtkAbstractWidget` and `vtkSphereRepresentation`. Is there a way to workaround this issue?

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [September 20, 2024, 12:04pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/4 "2024-09-20T12:04:32Z")

</div>

Good question and I would like to see the answer. In a canoe right now. Sunday, when I get back I will check iwhy my widgets with transparency work together with other transparent objects. I have not tried two transparent widgets. I dont inherit from vtkSphereRepresentation

---

<div class="post-metadata">

### Author: ![Laure\_C](https://discourse.vtk.org/user_avatar/discourse.vtk.org/laure_c/32/9269_2.png) [@Laure\_C](https://discourse.vtk.org/u/Laure_C)
#### Post date: [October 8, 2024, 12:08pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/5 "2024-10-08T12:08:03Z")

</div>

I tried to activate depth peeling, but render is still incorrect. ☹

---

<div class="post-metadata">

### Author: ![Olivier\_D](https://discourse.vtk.org/user_avatar/discourse.vtk.org/olivier_d/32/9363_2.png) [@Olivier\_D](https://discourse.vtk.org/u/Olivier_D)
#### Post date: [October 17, 2024, 1:07pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/6 "2024-10-17T13:07:01Z")

</div>

FTR, the issue happens on both VTK 9.2.6 and 9.3.1 which makes me think it’s the switch to VTK 9 which is the culprit. @Jens_Munk_Hansen If you have any idea or need any kind of additional investigation from us, let us know as I am too interested in finding a solution (and hopefully a bug fix) to this issue.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [October 18, 2024, 12:47pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/7 "2024-10-18T12:47:09Z")

</div>

I cannot reproduce similarly behavior here with their latest master. My sphere has opacity 0.5 and the handle, which is part of my widget has opacity 0.99 and is inside.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/c/cfd183910d1cb3fc71fdf280a33d4cbd0b480d9c.png)

The widget I have made using the very old approach where it is not separated into a widget and a representation. There is no secret in the old “vtkImplicitPlaneWidget”. If you want I can upload the code.

---

<div class="post-metadata">

### Author: ![Olivier\_D](https://discourse.vtk.org/user_avatar/discourse.vtk.org/olivier_d/32/9363_2.png) [@Olivier\_D](https://discourse.vtk.org/u/Olivier_D)
#### Post date: [October 24, 2024, 8:43am UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/8 "2024-10-24T08:43:05Z")

</div>

We will try again with the latest commit of VTK. I would also be interested to see the source code of your example combining widgets and actors to see if we are doing something wrong.

---

<div class="post-metadata">

### Author: ![Olivier\_D](https://discourse.vtk.org/user_avatar/discourse.vtk.org/olivier_d/32/9363_2.png) [@Olivier\_D](https://discourse.vtk.org/u/Olivier_D)
#### Post date: [October 29, 2024, 2:13pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/9 "2024-10-29T14:13:14Z")

</div>

![Screenshot 2024-10-29 at 14.56.52](https://discourse.vtk.org/uploads/default/original/2X/3/3c274e99e1216f6a30b01f5aad19dfa8460f5050.png)  
If it’s useful to anybody, in Laure’s code, this is the behavior of the (green) sphere widget when it is moved away from the (red) sphere source.

The widget starts to look green as it should be, but loses its shadow.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [October 30, 2024, 6:48pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/10 "2024-10-30T18:48:12Z")

</div>

Took the exact code, but replaced the widget with my own widget (made using the old design, no representation). Here things look correct. I can reproduce the above behavior for the code Laure provided.

```auto
#include <vtkActor.h>
#include <vtkImplicitRectangleWidget.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkSphereRepresentation.h>
#include <vtkSphereSource.h>
#include <vtkSphereWidget2.h>

int main(int, char*[])
{
  // Create a sphere/mapper/actor
  auto sphereSource = vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->SetRadius(2.0);
  auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(sphereSource->GetOutputPort());
  auto actor = vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
  actor->GetProperty()->SetOpacity(0.5);

  // Create a renderer/render window/interactor
  auto renderer = vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(actor);
  renderer->SetBackground(0, 0, 0);

  auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  auto renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  vtkNew<vtkImplicitRectangleWidget> widget;
  widget->SetInteractor(renderWindow->GetInteractor());
  widget->GetHandleProperty()->SetOpacity(0.99);

  renderWindow->SetMultiSamples(0); // Disable multi-sampling (for clarity)
  renderWindow->SetAlphaBitPlanes(1); // Ensure alpha channel if blending is used

  // Start the rendering loop
  renderWindow->Render();
  renderer->ResetCamera();
  renderWindowInteractor->Initialize();
  widget->On();
  renderWindowInteractor->Start();

  return 0;
}

```

The widget I used can be found here, [gist:c949a1841bb003a9368170b05f34e869 · GitHub](https://gist.github.com/JensMunkHansen/c949a1841bb003a9368170b05f34e869)

The shape I use with transparency is a cone. Perhaps, something is implemented wrongly for the translucent pass in the `vtkSphereWidget2`

---

<div class="post-metadata">

### Author: ![Olivier\_D](https://discourse.vtk.org/user_avatar/discourse.vtk.org/olivier_d/32/9363_2.png) [@Olivier\_D](https://discourse.vtk.org/u/Olivier_D)
#### Post date: [November 15, 2024, 3:24pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/11 "2024-11-15T15:24:40Z")

</div>

I see in your gist that you subclassed the vtk3DWidget, which is the same superclass of vtkSphereWidget.

The new vtkSphereWidget2 is a subclass of vtkAbstractWidget with its own separate representation, and that’s where it fails for our simple example.

---

<div class="post-metadata">

### Author: ![Olivier\_D](https://discourse.vtk.org/user_avatar/discourse.vtk.org/olivier_d/32/9363_2.png) [@Olivier\_D](https://discourse.vtk.org/u/Olivier_D)
#### Post date: [November 19, 2024, 8:03am UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/12 "2024-11-19T08:03:32Z")

</div>

FYI an issue has been opened for this bug: [https://gitlab.kitware.com/vtk/vtk/-/issues/19534](https://gitlab.kitware.com/vtk/vtk/-/issues/19534)

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [November 20, 2024, 9:52pm UTC](https://discourse.vtk.org/t/bug-on-transparency-between-actor-and-widgetin-vtk9/14590/13 "2024-11-20T21:52:11Z")

</div>

That could explain the differences. Looking forward for the bug to be fixed. We also have some widgets that inherit `vtkAbstractWidget`.
