# MeshViz/Makie is smoothing my colors

**URL:** <https://discourse.julialang.org/t/meshviz-makie-is-smoothing-my-colors/91993>\
**Category:** General Usage\
**Tags:** plotting, mesh, makie\
**Created:** [December 22, 2022, 8:07am UTC](https://discourse.julialang.org/t/meshviz-makie-is-smoothing-my-colors/91993 "2022-12-22T08:07:58Z")\
**Posts on this page:** 4\
**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:** [December 22, 2022, 8:07am UTC](https://discourse.julialang.org/t/meshviz-makie-is-smoothing-my-colors/91993/1 "2022-12-22T08:07:58Z")

</div>

Hello,

I have a mesh of a torus, made with **Meshes.jl**. I assigned colors to the vertices in order to have a checkerboard texture:

 ![Capture du 2022-12-22 09-01-37](https://global.discourse-cdn.com/julialang/original/3X/1/9/1928bdb84858ac563d07842c958457b6117d47a4.png)

Nice but the mesh is not smooth, one can see the facets. I found that one can get the visual smoothness by triangulating the mesh. Unfortunately, when I do that the colors are also smoothed, I mean the demarcation between the black rectangles and the white rectangles is blurred:

 ![Capture du 2022-12-22 09-02-22](https://global.discourse-cdn.com/julialang/original/3X/5/8/58e51a79f0f26baf9d5e51a10d2dad8f72dc3982.png)

Is there a way to have the smoothness while preserving the texture?

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [December 22, 2022, 10:00am UTC](https://discourse.julialang.org/t/meshviz-makie-is-smoothing-my-colors/91993/2 "2022-12-22T10:00:44Z")

</div>

Probably just pass the argument `interpolate=false`.

And because this looked fun to do, here is my version 😄  
See docs [here](https://docs.makie.org/v0.19.0/examples/plotting_functions/mesh/index.html#using_geometrybasicsmesh_and_buffersampler_type).

```plaintext
using GLMakie, Colors
using GLMakie.GeometryBasics
using LinearAlgebra

p = 0:7
img = mod.(p .- p', 2) .* colorant"white"

U = LinRange(-pi, pi, 100)
V = LinRange(-pi, pi, 50)
x1 = [cos(u) + 0.5 * cos(u) * cos(v) for u in U, v in V]
y1 = [sin(u) + 0.5 * sin(u) * cos(v) for u in U, v in V]
z1 = [0.5 * sin(v) for u in U, v in V]
points = vec([Point3f(xv, yv, zv) for (xv, yv, zv) in zip(x1, y1, z1)])
faces = decompose(QuadFace{GLIndex}, Tesselation(Rect(0, 0, 1, 1), size(z1)))
normals = normalize.(points)
function gen_uv(shift)
    return vec(map(CartesianIndices(size(z1))) do ci
        tup = ((ci[1], ci[2]) .- 1) ./ ((size(z1) .* shift) .- 1)
        return Vec2f(reverse(tup))
    end)
end

uv = gen_uv(1.0)
uv_buff = Buffer(uv)
t_mesh = GeometryBasics.Mesh(meta(points; uv=uv_buff, normals), faces)

fig = Figure(resolution = (800, 800))
ax = LScene(fig[1,1], show_axis = true)
mesh!(ax, t_mesh; color =img, interpolate=false)
fig

```

 ![torus](https://global.discourse-cdn.com/julialang/original/3X/8/d/8dc3b79fcd2fc538b2f0614f25b1cb1c395b7897.png)

---

<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:** [December 22, 2022, 10:17am UTC](https://discourse.julialang.org/t/meshviz-makie-is-smoothing-my-colors/91993/3 "2022-12-22T10:17:47Z")

</div>

Cool. But there’s no `interpolate` argument in **MeshViz.jl**. I will suggest to the author to add it.

---

<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:** [December 22, 2022, 11:23am UTC](https://discourse.julialang.org/t/meshviz-makie-is-smoothing-my-colors/91993/4 "2022-12-22T11:23:10Z")

</div>

I got an answer from the author. To get sharp colors, one has to assign a color to each face, not to each vertex. And no need to triangulate.

 ![Capture du 2022-12-22 12-21-32](https://global.discourse-cdn.com/julialang/original/3X/9/7/979848aef7faee8fc79df5193dbcd96469d0dd22.png)
