MakieOrg / Makie.jl

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

Lines plot artifacts with GLMakie v0.10.2 on julia 1.10.3 (win10) #3906

Open devel-chm opened 1 month ago

devel-chm commented 1 month ago

Previously posted on discourse at https://discourse.julialang.org/t/lines-plot-artifacts-with-glmakie-v0-10-2-on-julia-1-10-3-win10/114933

I was plotting some curves with a lot of low level noise with GLMakie and the plots had a lot of extra line cruft as if the line segments for the lines in the plot were not being correctly handled.

image

A MWE for the above example is

using GLMakie;
data = [1 + 2*rand() + i/100 for i in 1:10000];
lines(data)

This should show a line of slope 1/100 with random noise as a thickening strip of size 2 superimposed.

This is much less than the figure dimensions so the plot should resemble a thick line. I find that if I zoom in enough that some/most of the spilling line ends clean up.

devel-chm commented 1 month ago

I tried this on two other machines, one win11 with nvidia graphics and another with win10 and intel graphics. These both showed the correct image:

correct_mwe_image

SimonDanisch commented 1 month ago

What is the GPU of the faulty plot?

ffreyer commented 1 month ago

Could you also try this with the faulty plot?

begin
    using GLMakie;
    data = [1 + 2*rand() + i/100 for i in 1:10000];
    f, a, p = lines(data)
    p.attributes[:debug] = Observable(true)
    f
end
devel-chm commented 1 month ago

@SimonDanisch: GPU is AMD Radeon Pro WX 3200 series

@ffreyer: The resulting image:
image

ffreyer commented 1 month ago

Does joinstyle = :bevel fix this?

SimonDanisch commented 1 month ago

Looks like art!

ffreyer commented 1 month ago

The green parts in the debug plot are lines that are hidden due to joint truncation. Since there is more green towards the top and less spikes, I'm thinking that always truncating may hide the issue. But we shouldn't have such long line segments in the first place. Something is wrong with the quad positions. My guess would be that normalize(a - b) or (a - b) / length(a - b) is unstable here.

https://github.com/MakieOrg/Makie.jl/blob/f3e9013222aba5a55bb934137b8b5714b831bb8c/GLMakie/assets/shader/lines.geom#L275-L285

Maybe another good test would be to make the line alternate so that we should always get truncated joints. If we don't then the failure has to happen pretty early, i.e. probably with the normalizations.

begin
    using GLMakie;
    data = [1 + 2*(i % 2) + i/100 for i in 1:10000];
    f, a, p = lines(data)
    p.attributes[:debug] = Observable(true)
    f
end

https://github.com/MakieOrg/Makie.jl/blob/f3e9013222aba5a55bb934137b8b5714b831bb8c/GLMakie/assets/shader/lines.geom#L295-L307

devel-chm commented 1 month ago

Does joinstyle = :bevel fix this?

No but :round did appear to fix it. NOTE: I did not see :bevel as one of the documented joinstyles for GLMakie.