# How to realize this feature in VTK

**URL:** <https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825>\
**Category:** Development\
**Tags:** proposal\
**Created:** [June 29, 2022, 12:38am UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825 "2022-06-29T00:38:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ren](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/ed655f/32.png) [@Ren](https://discourse.vtk.org/u/Ren)\
**Post date:** [June 29, 2022, 12:38am UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/1 "2022-06-29T00:38:47Z")

</div>

The power is inside of the car, but it can be saw, I can sure it doesn’t use transparent method, how to do in VTK?  
\< \< Picture removed according to original author desire \> \>

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [June 29, 2022, 1:13pm UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/2 "2022-06-29T13:13:19Z")

</div>

Hello,

My two cents: as far as I know, the alpha channel value in color lookup tables of VTK are used to set translucency. To have custom alpha blending effects like in that example, you can refer to this primer: [https://www.kitware.com/vtk-technical-highlight-dual-depth-peeling/](https://www.kitware.com/vtk-technical-highlight-dual-depth-peeling/) .

It likely involves customizing the shader code in `vtkDualDepthPeelingPass` class: [VTK/vtkDualDepthPeelingPass.cxx at master · Kitware/VTK · GitHub](https://github.com/Kitware/VTK/blob/master/Rendering/OpenGL2/vtkDualDepthPeelingPass.cxx) or related classes.

Maybe someone out there with more experience in this has a simpler approach to customizing the alpha belnding behavior in VTK rendering.

take care,

Paulo

---

<div class="post-metadata">

**Author:** ![Ren](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/ed655f/32.png) [@Ren](https://discourse.vtk.org/u/Ren)\
**Post date:** [June 30, 2022, 2:06am UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/3 "2022-06-30T02:06:08Z")

</div>

In OpenGL, it set GL\_DEPTH\_TEST, it is easy to realize, but I haven’t found the method in VTK

---

<div class="post-metadata">

**Author:** ![Ren](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/ed655f/32.png) [@Ren](https://discourse.vtk.org/u/Ren)\
**Post date:** [June 30, 2022, 2:14am UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/4 "2022-06-30T02:14:44Z")

</div>

Dear Paulo, do you have an example to show how to use `vtkDualDepthPeelingPass`? Thanks

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [June 30, 2022, 3:04pm UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/5 "2022-06-30T15:04:12Z")

</div>

Unfortunately I couldn’t find any examples. I just proposed a starting point. Hence the “my two cents”. Changing the default alpha blending behavior written in VTK without getting into the bowels of OpenGL likely involves writing a custom shader.

Anyway, if you’re familiar with OpenGL, you can study the class `vtkOpenGLState` ([https://vtk.org/doc/nightly/html/classvtkOpenGLState.html#details](https://vtk.org/doc/nightly/html/classvtkOpenGLState.html#details)) to manage the OpenGL context between VTK calls. The OpenGL state is managed by carefully scoping the objects so the state is restored once they go out of scope, thus making it less likely to break VTK innards:

```cpp
(...) //VTK calls unaffected by state change.
{ 
  vtkOpenGLState *ostate = renWin->GetState(); 
  vtkOpenGLState::ScopedglDepthMask dmsaved(ostate); // the prior state is now saved ...
  ostate->glDepthMask(GL_TRUE); // change something 
  (...) //make VTK calls with modified OpenGL state.
} // prior state will be restored here as it goes out of scope
(...) //VTK calls unaffected by state change.

```

regards,

Paulo

---

<div class="post-metadata">

**Author:** ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)\
**Post date:** [July 1, 2022, 8:02am UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/6 "2022-07-01T08:02:16Z")

</div>

maybe you can draw onto 2 separate layers which share the same camera.

---

<div class="post-metadata">

**Author:** ![Thiago\_Neves](https://discourse.vtk.org/user_avatar/discourse.vtk.org/thiago_neves/32/4886_2.png) [@Thiago\_Neves](https://discourse.vtk.org/u/Thiago_Neves)\
**Post date:** [July 2, 2022, 10:00am UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/7 "2022-07-02T10:00:33Z")

</div>

I have a similar feature on my software and im using 2 layers, one in the back and one in the front. When i select a part of the 3d model i move the selected cells to the front renderer. Like what Marco suggested.

---

<div class="post-metadata">

**Author:** ![jal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jal/32/729_2.png) [@jal](https://discourse.vtk.org/u/jal)\
**Post date:** [July 2, 2022, 2:20pm UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/8 "2022-07-02T14:20:08Z")

</div>

looks like the part was rendered twice - once opaque with depth test on, and once with transparency on and depth test off. 2 actors (or a prop assembly), 1 renderer layer.

---

<div class="post-metadata">

**Author:** ![Ren](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/ed655f/32.png) [@Ren](https://discourse.vtk.org/u/Ren)\
**Post date:** [July 5, 2022, 9:22am UTC](https://discourse.vtk.org/t/how-to-realize-this-feature-in-vtk/8825/9 "2022-07-05T09:22:09Z")

</div>

I would like to know how to set depth test on in VTK?
