# Use of Tessellation Shader in VTK

**URL:** https://discourse.vtk.org/t/use-of-tessellation-shader-in-vtk/1181
**Category:** Support
**Created:** [June 20, 2019, 6:46am UTC](https://discourse.vtk.org/t/use-of-tessellation-shader-in-vtk/1181 "2019-06-20T06:46:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tharun](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/67e7ee/32.png) [@Tharun](https://discourse.vtk.org/u/Tharun)
#### Post date: [June 20, 2019, 6:46am UTC](https://discourse.vtk.org/t/use-of-tessellation-shader-in-vtk/1181/1 "2019-06-20T06:46:47Z")

</div>

I have a triangular mesh(polygons as cells in vtkPolyData). Each point has  
different scalar value. There is a lookup table for coloring based on scalars. On using Point Color data as scalars, triangles  
have graded color. But, what I want is like in the image below

[http://vtk.1045678.n5.nabble.com/file/t341373/test.png](http://vtk.1045678.n5.nabble.com/file/t341373/test.png) .

I know that subdividing the triangular mesh into triangles having same  
color data vertices can give result like this by using Cell data as scalars.

Now, our workflow is similar to example  
[https://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/VisualizationAlgorithms/Cxx/FilledContours.cxx](https://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/VisualizationAlgorithms/Cxx/FilledContours.cxx)  
and I have the desired output. Meshes we deal with have 10s of millions of  
triangles and the process is quite slow.

I recenlty read about Tessellation Shaders at here  
[http://ogldev.atspace.co.uk/www/tutorial30/tutorial30.html](http://ogldev.atspace.co.uk/www/tutorial30/tutorial30.html) , and they  
mentioned about “Primitive Generator” part of Tessellation where we can just  
mention the tessellation levels of each triangle by gl\_TessLevelOuter and  
gl\_TessLevelInner. I believe, specifying gl\_TessLevelOuter for every  
triangle of original mesh based on Vertices Scalar values for all  
triangles solves my problem with performance.

Can anybody please let me know how to do this in VTK?

---

<div class="post-metadata">

### Author: ![dmreagan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmreagan/32/7489_2.png) [@dmreagan](https://discourse.vtk.org/u/dmreagan)
#### Post date: [June 25, 2019, 5:03pm UTC](https://discourse.vtk.org/t/use-of-tessellation-shader-in-vtk/1181/2 "2019-06-25T17:03:00Z")

</div>

As noted by @Dave_DeMarle on the mailing list, VTK only provides support for vertex, geometry, and fragment shaders at this time.

You _might_ be able to get a similar look if you disable color interpolation across the triangles. If you pass your own per-vertex color information into the shader pipeline, you can disable interpolation by declaring the variable with the `flat` qualifier. There is some useful information in [this Stack Overflow post](https://stackoverflow.com/a/27581384). I haven’t actually tried this approach, but it might be worth a shot.

---

<div class="post-metadata">

### Author: ![Tharun](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/67e7ee/32.png) [@Tharun](https://discourse.vtk.org/u/Tharun)
#### Post date: [June 28, 2019, 1:08am UTC](https://discourse.vtk.org/t/use-of-tessellation-shader-in-vtk/1181/3 "2019-06-28T01:08:47Z")

</div>

Thank you for the response.

The problem is solved now. I have used the in-built function itslef. Colors are actually generated from scalar values of vertices from a lookup table of color bar. Without dividing into triangles, I am using InterpolateScalarsBeforeMappingOn() as explained [here](https://blog.kitware.com/what-is-interpolatescalarsbeforemapping-in-vtk/) and it’s working perfectly.

---

<div class="post-metadata">

### Author: ![dmreagan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmreagan/32/7489_2.png) [@dmreagan](https://discourse.vtk.org/u/dmreagan)
#### Post date: [June 28, 2019, 3:38pm UTC](https://discourse.vtk.org/t/use-of-tessellation-shader-in-vtk/1181/4 "2019-06-28T15:38:36Z")

</div>

That’s a much better solution. Glad you got it working.
