# Opacity problem for selected scalar range

**URL:** https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094
**Category:** Support
**Created:** [April 19, 2020, 1:06am UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094 "2020-04-19T01:06:58Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [April 19, 2020, 1:06am UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/1 "2020-04-19T01:06:58Z")

</div>

Hi All

I’m using vtkDiscretizableColorTransferFunction to set opacity for selected scalar range in unstructured grid.  
Depending of the camera position displayed unstructured grid shows some strange artifacts.  
As you can see in attached image 1, from that angle it looks OK, but in images 2 and 3 parts of the same grid disappear. I tried to use different filters, vtkDataSetSurfaceFilter,vtkGeometryFilter etc, enabled deep peeling all the same.  
Can you please give me idea where to look, I’m using Activiz VTK version 6.3 if that helps.

Thanks  
MK

 ![Image3](https://discourse.vtk.org/uploads/default/original/2X/6/6127c2d3cb8d02a1288cd3df1abacdb528b34947.png) ![Image2](https://discourse.vtk.org/uploads/default/original/2X/3/324c3a4a121005ea88f49723c16056d2f073b6d1.png) ![Image1](https://discourse.vtk.org/uploads/default/original/2X/9/9645136c53588d46902a0042963e6d08f71c889e.png)

---

<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: [April 20, 2020, 12:44pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/2 "2020-04-20T12:44:13Z")

</div>

Hello, Markara,

I’ve also recently had those artifacts with translucent elements. Here’s what I did to render them properly (C++):

```cpp
    // Prepare to render transparency/translucency adequately
    _renderer->SetUseDepthPeeling(1);
    _renderer->SetOcclusionRatio(0.1);
    _renderer->SetMaximumNumberOfPeels(4);
    _vtkwidget->GetRenderWindow()->SetMultiSamples(0);
    _vtkwidget->GetRenderWindow()->SetAlphaBitPlanes(1);

```

The calls above should be added to the part of your code that is configuring the VTK widget, renderer, etc. You can experiment with the values above to different ones that suit you.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [April 20, 2020, 1:20pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/3 "2020-04-20T13:20:03Z")

</div>

Hi Paulo  
I have identical parameters in my settings. Only issue is that I can see for now is that i’m testing this on my laptop which doesn’t have dedicated graphic cart and remote desktop, (working from home, damn COVID) and that could be an issue, but i’m not sure

Thanks for you response

---

<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: [April 20, 2020, 6:28pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/4 "2020-04-20T18:28:01Z")

</div>

It surprises me that it even works remotely. So I guess it is not a VTK issue, then. I’d contact the technical support of whichever virtualization software you’re using to get a configuration that results in good OpenGL rendering. Maybe some OpenGL features are disabled by default. Maybe it’s using software emulation. Who knows…

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [April 20, 2020, 7:03pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/5 "2020-04-20T19:03:08Z")

</div>

> [@MarKara](#):
>
> vtkDiscretizableColorTransferFunction

I’m developer of the software and previously didn’t use vtkDiscretizableColorTransferFunction but just regular vtkColorTransferFunction and was hoping to include transparency in new version. I will go in next couple days to the office and check it on my desktop, but I have a feeling that deep peeling is not an issue. I imported the same grid into ParaView and even there wasn’t perfect although wasn’t the same as in images I attached.

---

<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: [April 20, 2020, 8:58pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/6 "2020-04-20T20:58:13Z")

</div>

It’s not only deep peeling. It’s a combination of parameters! Did you to check the other 4 parameters as shown in the code I posted?

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [April 20, 2020, 10:07pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/7 "2020-04-20T22:07:33Z")

</div>

Yes, I have identical parameters. I checked even on my laptop if deep peeling was used using function  
CurrentRenderer.GetLastRenderingUsedDepthPeeling() and returned value was 1.  
I used the same grid in Paraview, eve there are some artifact depending of the angle, but much less compared to my application.

![Paraview](https://discourse.vtk.org/uploads/default/original/2X/8/86a61dbe8f266a350f4f77489b11e8157b213496.png)

---

<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: [April 21, 2020, 11:28am UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/8 "2020-04-21T11:28:42Z")

</div>

You said that you are using Activiz VTK version 6.3. Does that mean VTK 6.3? If so, I strongly recommend upgrading to a recent version (8 or 9).

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [April 21, 2020, 11:54am UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/9 "2020-04-21T11:54:36Z")

</div>

I’m not sure that’ll help, again, even Paraview with I guess VTK version 8 has the same problem

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [April 21, 2020, 2:08pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/10 "2020-04-21T14:08:30Z")

</div>

Can you share the dataset that shows this problem?

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [April 21, 2020, 2:31pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/11 "2020-04-21T14:31:12Z")

</div>

[BQUGHENTGZ.vtu](https://discourse.vtk.org/uploads/short-url/lRStfCTWWGttiR3RRG39ZTtUzcn.vtu) (82.8 KB)  
Yes, here it is

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [April 21, 2020, 2:33pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/12 "2020-04-21T14:33:05Z")

</div>

[Test.pvsm](https://discourse.vtk.org/uploads/short-url/jk0FA1NrS9JCLkfLbhoMynwFOv1.pvsm) (262.9 KB)  
And her is the PVSM file

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [April 23, 2020, 1:37am UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/13 "2020-04-23T01:37:49Z")

</div>

Hi Cory I found another issue. If I have negative scalars opacity is not working at all not in my application nor in Paraview. Not sure if there is way around, but I couldn’t find it.  
Please see attached image and paraview file.  
Thank you for looking

 ![OpacityWithNegativeScalars](https://discourse.vtk.org/uploads/default/original/2X/a/a2e617c02e5b2f06f78d07e7f3eab0c12130d4a7.png)

[OpacityWitNegScalats.pvsm](https://discourse.vtk.org/uploads/short-url/9DGl8EBssDwXZuXK36YhJxw2EDb.pvsm) (226.8 KB)  
[HMVLXKNXET.vtu](https://discourse.vtk.org/uploads/short-url/vYixA6bNw4lRraxzAq5jsB1dPzu.vtu) (14.1 KB)

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [December 10, 2021, 2:43pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/14 "2021-12-10T14:43:50Z")

</div>

Hi @MarKara. Closing the loop on this: the issue with negative scalars should be resolved in VTK 9.1 and ParaView 5.10.

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [December 10, 2021, 5:57pm UTC](https://discourse.vtk.org/t/opacity-problem-for-selected-scalar-range/3094/15 "2021-12-10T17:57:49Z")

</div>

Thanks Cory
