# Models always shaded flat regardless of interpolation

**URL:** <https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309>\
**Category:** Development\
**Created:** [January 2, 2022, 2:01pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309 "2022-01-02T14:01:28Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [January 2, 2022, 2:01pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/1 "2022-01-02T14:01:28Z")

</div>

This is quite possibly a misunderstanding on my part. It looks like models are always shaded with flat polygons, and the interpolation setting has no effect. Regardless of the setting (Flat, Phong, Gouraud), all polygons are flat (see image below). This is using the “Lights” module, set to Default lighting. Shouldn’t Phong or Gouraud interpolation result in a less “faceted” appearance or am I mis-remembering how these work?

Thanks!!!

-Hollister

Preview 2021-12-19, MacOS, MBP 16" AMD Radeon Pro 5500M 8 GB.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/9/b95f6b50fe7810b3a489a7a35e5141fc0337cc04.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 2, 2022, 2:44pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/2 "2022-01-02T14:44:33Z")

</div>

Sharing requires surface normals. They can be computed in Surface Toolbox module.

Moat mesh file formats allow storage of surface normals. What file format are you reading your model from? What software has created the file?

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [January 2, 2022, 3:39pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/3 "2022-01-02T15:39:14Z")

</div>

It’s a segment converted to a model in Slicer. I computed surface normals in Surface Toolbox and it shades smoothly now - thanks!

I was a little confused because Gouraud shading doesn’t require normals (but Phong does). Anyway, thanks for the help!!

-Hollister

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 2, 2022, 4:20pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/4 "2022-01-02T16:20:24Z")

</div>

> [@hherhold](#):
>
> Gouraud shading doesn’t require normals (but Phong does).

To clarify, Gouraud shading uses normals at the vertices to calculate lighting and then interpolates the colors across the triangle, Phong shading interpolates the normals and recalculates the lighting per-fragment across the triangle. So both require vertex normals. STL format, for example, does not save normals, so they need to be re-calculated for smooth rendeing.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 2, 2022, 4:21pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/5 "2022-01-02T16:21:14Z")

</div>

> [@hherhold](#):
>
> It’s a segment converted to a model in Slicer

In current Slicer versions, surface normal computation is enabled by default, but you can enable/disable it by adjusting segmentation representation conversion parameters:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/d/9d7c357a41044479d2832d03995ff8cdb32c126a.png)

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [January 2, 2022, 4:22pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/6 "2022-01-02T16:22:47Z")

</div>

Got it, ok. I thought Gouraud interpolated vertex colors across the polygon and didn’t use normals.

My undergrad computer graphics class was an embarrassingly long time ago.

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [January 2, 2022, 4:23pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/7 "2022-01-02T16:23:12Z")

</div>

Ah, okay - Thanks, Andras!

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [February 27, 2022, 8:49pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/8 "2022-02-27T20:49:28Z")

</div>

Hi Andras @lassoan,

Quick follow-up to this. It seems whenever I save models as PLY, even if I’ve computed surface normals before saving, when I reload the model files, the normals have been lost. Does Slicer save surface normals in PLY files?

Thanks!!

-Hollister

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 27, 2022, 11:41pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/9 "2022-02-27T23:41:36Z")

</div>

VTK’s PLY reader reads point normals, but VTK’s PLY file _writer_ does not write them.

I’ve submitted a merge request to VTK to add this feature:

> **[Make vtkPLYWriter able to write point normals (!8940) · Merge requests · VTK...](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8940)**
>
> For complex surfaces it is not always trivial to compute the surface normals, so it is useful to store the normals in the mesh. PLY file format can...

Probably it can get into VTK in a couple of days, but I’m not sure when we’ll update Slicer’s VTK to include this update. If it is urgent then we can cherry-pick this feature (and then it’ll be available in the Slicer Preview Release the next day), otherwise it’ll be available in Slicer in a few months.

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [February 28, 2022, 3:01am UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/10 "2022-02-28T03:01:48Z")

</div>

Hey Andras,

Thanks! No, not urgent at all. Just wanted to make sure it wasn’t something I was doing wrong.

-Hollister

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [March 13, 2022, 2:57pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/11 "2022-03-13T14:57:24Z")

</div>

Hi Andras @lassoan,

If I wanted to do a local build that would incorporate the VTK version with this change, how do I go about that? I tried changing \_git\_tag in External\_VTK.cmake to the latest SHA but I get the following error (Windows):

```auto
  Performing update step for 'VTK'
  fatal: reference is not a tree: 21f9d5e14a695d9fc387aee86b28c36bbe19fdb5
  CMake Error at D:/S/S4D/VTK-prefix/tmp/VTK-gitupdate.cmake:175 (execute_process):
    execute_process failed command indexes:

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 13, 2022, 3:59pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/12 "2022-03-13T15:59:19Z")

</div>

The latest master VTK version does not contain some of the fixes that Slicer needs, so you need to backport the PBR fix into Slicer’s VTK. I’ll try to do this for the official Slicer release today or tomorrow.

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [March 13, 2022, 4:03pm UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/13 "2022-03-13T16:03:47Z")

</div>

If it’s too much trouble, this is not a critical need - I can work around by using Surface Toolbox to recompute normals when I reload PLY models.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 14, 2022, 2:33am UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/14 "2022-03-14T02:33:10Z")

</div>

I’ve just checked and latest Slicer Preview Release already includes the fix for writing of PLY normals.

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [March 14, 2022, 11:04am UTC](https://discourse.slicer.org/t/models-always-shaded-flat-regardless-of-interpolation/21309/15 "2022-03-14T11:04:47Z")

</div>

Oh, great! Thanks!

This is what I get for being a few weeks behind in preview releases…
