MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.43k stars 312 forks source link

Artefacts in meshes with transparency using CairoMakie #2942

Open philbit opened 1 year ago

philbit commented 1 year ago

When plotting meshes with transparency, line artefacts appear where the triangles are touching.

MWE:

using CairoMakie

points = [Point2f(0.0, 0.0),
          Point2f(0.0, 1.0),
          Point2f(1.0, 1.0),
          Point2f(1.0, 0.0)]

m = Makie.GeometryBasics.Mesh(points, Makie.GeometryBasics.earcut_triangulate([points]))

# m is a Mesh{2, Float32, Triangle}:
# Triangle(Float32[0.0, 1.0], Float32[0.0, 0.0], Float32[1.0, 0.0])
# Triangle(Float32[1.0, 0.0], Float32[1.0, 1.0], Float32[0.0, 1.0])

fig = Figure()
ax = Axis(fig[1,1]; aspect = DataAspect())
mesh!(m)
display(fig)

Result:

image

It looks similar to issue #2469, which, as far as I understand, was resolved by not plotting as a mesh. But what if we need to explicitly draw a mesh? Is there a different way I am missing?

This is with CairoMakie 0.10.4.

jkrumbiegel commented 1 year ago

This is a limitation of Cairo, which can only draw mesh patterns triangle per triangle, so you're bound to get artifacts at the edges with alpha. In the future, we would like to implement a software renderer that draws meshes to a bitmap more like GLMakie would.

philbit commented 1 year ago

Thanks for the information. It's a pity it's not simply a bug ;), but I understand the limitation. Software rendering would be great!

jkrumbiegel commented 1 year ago

There are also some attempts to insert GLMakie rendered plot objects into CairoMakie vector graphics, maybe that would be an option in the future.