MeshViz/Makie is smoothing my colors

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:

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:

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

Probably just pass the argument interpolate=false.

And because this looked fun to do, here is my version :smile:
See docs here.

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

1 Like

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

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.

2 Likes