# Struggling with lighting on GLMakie Meshes

**URL:** <https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678>\
**Category:** Visualization\
**Created:** [May 11, 2023, 12:19pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678 "2023-05-11T12:19:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)\
**Post date:** [May 11, 2023, 12:19pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/1 "2023-05-11T12:19:31Z")

</div>

Can anyone point me to an up to date resource on lighting meshes in GLMakie?

Whatever I try at the moment results in a completely flat color, with no way to percieve depth.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [May 11, 2023, 3:27pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/2 "2023-05-11T15:27:49Z")

</div>

Try:

```julia
using GeometryBasics

Makie.mesh(normal_mesh(your_flat_mesh))

```

---

<div class="post-metadata">

**Author:** ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)\
**Post date:** [May 11, 2023, 5:16pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/3 "2023-05-11T17:16:20Z")

</div>

Thanks for getting back to me. I’ve now tried that, but I’m still getting the same.

Any other ideas? I can try to put together a minimal example if that will help

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [May 12, 2023, 8:46am UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/4 "2023-05-12T08:46:56Z")

</div>

Yeah if that doesn’t work, I’ll need a minimal example!

---

<div class="post-metadata">

**Author:** ![math4mad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math4mad/32/49486_2.png) [@math4mad](https://discourse.julialang.org/u/math4mad)\
**Post date:** [May 14, 2023, 2:48pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/5 "2023-05-14T14:48:16Z")

</div>

[lighting](https://docs.makie.org/stable/documentation/lighting/)

[beautiful makie](https://beautiful.makie.org/dev/examples/generated/2d/meshes/meshes/)

I follow above docs ,make some plots

 ![mesh-integrate](https://global.discourse-cdn.com/julialang/original/3X/9/8/9880b371f32e563c32b09c7f6ebee55e3578769c.png)

 ![mesh-integrate9](https://global.discourse-cdn.com/julialang/original/3X/a/3/a3032865129fc34910b4ed1253428deabfbc8673.png)

---

<div class="post-metadata">

**Author:** ![martin.d.maas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martin.d.maas/32/50964_2.png) [@martin.d.maas](https://discourse.julialang.org/u/martin.d.maas)\
**Post date:** [May 15, 2023, 3:21pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/6 "2023-05-15T15:21:37Z")

</div>

It looks like there is indeed some lighting in your plot. Did you try changing `lightposition`, `specular`, or `diffuse`?

---

<div class="post-metadata">

**Author:** ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)\
**Post date:** [May 23, 2023, 12:35pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/7 "2023-05-23T12:35:07Z")

</div>

An update. I’ve partially figured out the problem: when I load an .stl file using FileIO, the loaded mesh has normal vectors all [0.0, 0.0, 0.0]. Therefore calling normal\_mesh does nothing, as it believes the normals are already defined.

I can avoid the problem by using .OBJ files that I have of the mesh, instead of STLs.

I don’t know if this applies to all STLs, or only some.

Here is a minimal example, although I can’t seem to upload the .stl or .obj files here…

```julia
using ColorTypes: RGBA
using GLMakie
using GeometryBasics
using FileIO
using StaticArrays

Makie.inline!(false)
fig = Figure()
ax1 = Axis3(fig[1, 1]; aspect = :data, title=".stl")
ax2 = Axis3(fig[1, 2]; aspect = :data, title=".obj")

# Doesn't work
m1 = normal_mesh(FileIO.load("./link1.stl"))
m2 = normal_mesh(FileIO.load("./link1.obj"))

mesh!(ax1, m1; color = RGBAf(1.0, 1.0, 1.0, 1.0))
mesh!(ax2, m2; color = RGBAf(1.0, 1.0, 1.0, 1.0))
display(fig)

```

 ![Screenshot 2023-05-23 133434](https://global.discourse-cdn.com/julialang/original/3X/4/5/456c6ef4762c380e559bb7d0bbd666d9b5ad397b.png)

---

<div class="post-metadata">

**Author:** ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)\
**Post date:** [May 23, 2023, 12:36pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/8 "2023-05-23T12:36:02Z")

</div>

Note: calling normal mesh in the previous example has no effect. It can be omitted for the same result.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [May 23, 2023, 3:20pm UTC](https://discourse.julialang.org/t/struggling-with-lighting-on-glmakie-meshes/98678/9 "2023-05-23T15:20:48Z")

</div>

Ah that’s weird, not sure if that’s a problem in the `.stl` file or in `MeshIO`.  
You can do:

```julia
m = FileIO.load("./link1.stl")
normal_mesh(GeometryBasics.Mesh(coordinates(m), faces(m)))

```
