# Change in rendering of semi-opaque solid meshes with edges enabled

**URL:** https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120
**Category:** Support
**Created:** [April 3, 2023, 5:41pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120 "2023-04-03T17:41:07Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ahall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6bbea6/32.png) [@ahall](https://discourse.vtk.org/u/ahall)
#### Post date: [April 3, 2023, 5:41pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/1 "2023-04-03T17:41:07Z")

</div>

Hello. We recently updated from VTK 8.1.1 to VTK 9.2.6. It has been pretty smooth, but I have noticed one issue.  
vtk8

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

vtk9

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

This is with:  
SetRepresentationToSurface()  
SetEdgeVisibility(true)  
Opacity of less than 1.  
This occurs both with and without depth peeling.

The triangle edge in the middle is only barely visible, and only with transparency turned on. I did diff the relevant sections of vtkOpenGLPolyDataMapper.cxx, and there seem to have been many MANY changes in this area. Does anybody have any insight?

Thanks!

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [April 3, 2023, 7:08pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/2 "2023-04-03T19:08:12Z")

</div>

Hmm. This is not the first time seeing that happen. Can you try to increase the line width? Default is 1. The surface with edges algorithm used in `vtkOpenGLPolyDataMapper` works best with line widths somewhere between 2 and 5.

---

<div class="post-metadata">

### Author: ![ahall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6bbea6/32.png) [@ahall](https://discourse.vtk.org/u/ahall)
#### Post date: [April 3, 2023, 7:20pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/3 "2023-04-03T19:20:35Z")

</div>

Hi, thanks for responding! Setting the thickness to be larger has the same effect, just with thicker lines

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

Unfortunately it is very important that I continue to support arbitrary line widths, including a thickness of 1.

I’m guessing you are talking about some of the work done in `vtkOpenGLPolyDataMapper::RenderPieceDraw` ? It looks like there have been a number of changes in that function related to the ways that lines are drawn, I’m picking it apart to see if any of it could be involved.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [April 3, 2023, 7:35pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/4 "2023-04-03T19:35:41Z")

</div>

This happens only at specific camera viewpoints, right? I assumed it’s just a quad. Here is what I tried to emulate your issue. Interestingly enough, changing the edge color to something that’s not close to the surface color removes that diagonal line. ex: edge colored red. With a width of 1, I can still see some traces of red on the diagonal.

```python
import vtk

polydata = vtk.vtkPolyData()
points = vtk.vtkPoints()
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(1, 0, 0)
points.InsertNextPoint(1, 1, 0)
points.InsertNextPoint(0, 1, 0)
polys = vtk.vtkCellArray()
polys.InsertNextCell(4, [0, 1, 2, 3])
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(4)
colors.InsertNextTuple([200, 200, 200, 255])
polydata.SetPoints(points)
polydata.SetPolys(polys)
polydata.GetCellData().SetScalars(colors)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(polydata)

actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetEdgeColor(1, 0, 0)
actor.GetProperty().SetEdgeVisibility(True)
actor.GetProperty().SetLineWidth(2)

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
renWin.Render()
renderer.ResetCamera()

interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renWin)
interactor.Start()

```

The related code is in [vtkPolyDataEdgesGS.glsl](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/OpenGL2/glsl/vtkPolyDataEdgesGS.glsl) and `vtkOpenGLPolyDataMapper::ReplaceShaderEdges`, bisecting there can help you figure it out. I’m almost sure this is a precision issue when the shader computes color using emix for the invisible edges.

Please open an issue at [https://gitlab.kitware.com/vtk/vtk/-/issues/new](https://gitlab.kitware.com/vtk/vtk/-/issues/new). This is a bug.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [April 3, 2023, 7:37pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/5 "2023-04-03T19:37:18Z")

</div>

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

If you squint hard enough, there’s a red diagonal.

---

<div class="post-metadata">

### Author: ![ahall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6bbea6/32.png) [@ahall](https://discourse.vtk.org/u/ahall)
#### Post date: [April 3, 2023, 7:38pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/6 "2023-04-03T19:38:29Z")

</div>

Wow, thanks for making my MRE for me! Tomorrow morning I will see if I can find anything in the file you specified, and in either case I will file the bug report.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [April 3, 2023, 7:51pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/7 "2023-04-03T19:51:15Z")

</div>

No worries. Surface with edges in OpenGL has been optimized in the past. The algorithm is based on [http://www.imm.dtu.dk/~janba/Wireframe/](http://www.imm.dtu.dk/~janba/Wireframe/) with some modifications. In VTK, it has some artifacts like you pointed out and more in [https://gitlab.kitware.com/vtk/vtk/-/issues/18064](https://gitlab.kitware.com/vtk/vtk/-/issues/18064).

For the upcoming WebGPU mapper, I attempted a slightly different approach based on the original algorithm without deviating, [shader](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/WebGPU/wgsl/PolyData.wgsl)

Here’s how it looks with the experimental WebGPU mapper without anti-aliasing.

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

---

<div class="post-metadata">

### Author: ![ahall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6bbea6/32.png) [@ahall](https://discourse.vtk.org/u/ahall)
#### Post date: [April 3, 2023, 7:54pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/8 "2023-04-03T19:54:04Z")

</div>

Oh, and to answer your question, yes I only see it from oblique angles. It tends to go away when the surface is viewed from acute angles.

Cool, I will review the WebGPU shader as well. Being honest, I had always wondered how this effect was done in VTK, happy to poke around and find out. That is a nifty looking algo.

---

<div class="post-metadata">

### Author: ![ahall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6bbea6/32.png) [@ahall](https://discourse.vtk.org/u/ahall)
#### Post date: [April 4, 2023, 12:36pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/9 "2023-04-04T12:36:11Z")

</div>

Bug filed:  
[https://gitlab.kitware.com/vtk/vtk/-/issues/18865](https://gitlab.kitware.com/vtk/vtk/-/issues/18865)

---

<div class="post-metadata">

### Author: ![ahall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6bbea6/32.png) [@ahall](https://discourse.vtk.org/u/ahall)
#### Post date: [April 24, 2023, 12:21pm UTC](https://discourse.vtk.org/t/change-in-rendering-of-semi-opaque-solid-meshes-with-edges-enabled/11120/10 "2023-04-24T12:21:44Z")

</div>

Unfortunately it will not be possible for me to look into this issue further.
