# Visualization problem of the back side of a surface mesh

**URL:** <https://discourse.julialang.org/t/visualization-problem-of-the-back-side-of-a-surface-mesh/104923>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [October 13, 2023, 9:20am UTC](https://discourse.julialang.org/t/visualization-problem-of-the-back-side-of-a-surface-mesh/104923 "2023-10-13T09:20:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 13, 2023, 9:20am UTC](https://discourse.julialang.org/t/visualization-problem-of-the-back-side-of-a-surface-mesh/104923/1 "2023-10-13T09:20:36Z")

</div>

Hello,

I have a problem with a 3D animation. This is a torus which reverses itself. The problem is that when it is reversed, it is ugly because the normals are not oriented as they should. How to solve this problem?

![CliffordTorus](https://global.discourse-cdn.com/julialang/original/3X/0/d/0d7f52d058ad23d5bd7eefcfe6a814e7bff13073.gif)

```julia
using Meshes
using MeshViz
using GLMakie
using Makie
using Printf

# parameterization of the Clifford torus
function Clifford(u, v)
  [cos(u), sin(u), cos(v), sin(v)] / sqrt(2)
end

# a 4D rotation
function rotate4D(x, t)
  cost = cos(t)
  sint = sin(t)
  [
    -x[1]*sint + x[4]*cost,
     x[2]*cost - x[3]*sint,
     x[2]*sint + x[3]*cost,
    -x[1]*cost - x[4]*sint
  ]
end

# modified stereographic projection
function stereog(p)
  r = acos(p[4]) / pi / sqrt(1-p[4]*p[4])
  (r*p[1], r*p[2], r*p[3])
end

# topology
nu = 300
nv = 300
topo = GridTopology((nv, nu), (true, true))

# subdivisions
u_ = LinRange(0, 2*pi, nu+1)[1:nu]
v_ = LinRange(0, 2*pi, nv+1)[1:nv]

# draw the Clifford torus
function drawCT(nplots, alpha1, alpha2)
  t_ = LinRange(0, 2*pi, nplots+1)[1:nplots]
  for i in 1:nplots
    fig, ax, _ = viz( # invisible bounding box
      Meshes.Box(Meshes.Point(-1, -1, -1), Meshes.Point(1, 1, 1)); 
      alpha = 0
    )
    ax.show_axis = false
    points = [
      stereog(rotate4D(Clifford(u, v), t_[i])) 
      for u in u_ for v in v_
    ]
    mesh = SimpleMesh(Meshes.Point.(points), topo)
    viz!(mesh; color = :maroon1)
    scale!(ax.scene, 1.65, 1.65, 1.65)
    Makie.rotate!(fig.scene, Meshes.Vec3f(1, 0, 0), alpha1)
    Makie.rotate!(ax.scene, Meshes.Vec3f(0, 0, 1), alpha2)
    png = @sprintf "zzpic%03d.png" i
    Makie.save(png, fig)
  end
end

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 13, 2023, 11:14am UTC](https://discourse.julialang.org/t/visualization-problem-of-the-back-side-of-a-surface-mesh/104923/2 "2023-10-13T11:14:18Z")

</div>

@ffreyer I think you fixed this in your current lighting PR? At least I think I remember some mentioning of backlighting changes and specular highlights etc.

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [October 13, 2023, 7:40pm UTC](https://discourse.julialang.org/t/visualization-problem-of-the-back-side-of-a-surface-mesh/104923/3 "2023-10-13T19:40:21Z")

</div>

You can fix that with `backlight = 1f0` regardless of the pr.

We could make that the default, but I’m not sure if we should. For a static surface it makes sense that only one side gets light from a single light source and with `backlight = 1f0` both sides would.

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [October 13, 2023, 8:22pm UTC](https://discourse.julialang.org/t/visualization-problem-of-the-back-side-of-a-surface-mesh/104923/4 "2023-10-13T20:22:59Z")

</div>

I did not know this was an option! It is not currently listed under the “3D shading attributes” when you `?mesh`. Searching the online documentation, it appears to only turn up for `band`.

Still, great to know it’s easy to get surfaces lit on both sides.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 14, 2023, 8:54pm UTC](https://discourse.julialang.org/t/visualization-problem-of-the-back-side-of-a-surface-mesh/104923/5 "2023-10-14T20:54:36Z")

</div>

Thank you. Where should I set this option? In `viz`?
