Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AA with large linewidth differences #2953

Merged
merged 3 commits into from May 26, 2023
Merged

Fix AA with large linewidth differences #2953

merged 3 commits into from May 26, 2023

Conversation

ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented May 14, 2023

Description

This is another fix coming out of #2944. I added per position linewidths with the fixes for line patterns but I didn't think carefully enough about the padding for those cases. Thus we find no anti-aliasing when the change in linewidth from one point to the next is (much) larger than the distance between those points:

scene = Scene(resolution = (400, 400))
campixel!(scene)
lines!(scene, fill(200, 4), [0, 190, 210, 400], linewidth = [2, 2, 202, 202], color = :black)
scene

Screenshot from 2023-05-14 19-56-47

The pr adds scaling so that this is fixed:

Screenshot from 2023-05-14 19-58-38

I didn't bother with patterned lines since, well, they do their own weird thing....
Screenshot from 2023-05-14 19-49-19

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Added an entry in NEWS.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@ffreyer ffreyer added the GLMakie This relates to GLMakie.jl, the OpenGL backend for Makie. label May 14, 2023
@ffreyer
Copy link
Collaborator Author

ffreyer commented May 14, 2023

Here's a sketch for the scaling factor
makie_sketch
v and n match the names in the shader, describing the line direction and normal. AA is AA_THICKNESS. The factor 1/2 in the linewidth difference comes from that difference existing symmetrically on both sides of the line segment. That factor drops out in the shader because widths are scaled by a factor of 2. y is the final (geometric) padding we apply, which is still representative of a padding by AA_THICKNESS in uv.y causing that to have a reduced linewidth.

@MakieBot
Copy link
Collaborator

MakieBot commented May 14, 2023

Compile Times benchmark

Note, that these numbers may fluctuate on the CI servers, so take them with a grain of salt. All benchmark results are based on the mean time and negative percent mean faster than the base branch. Note, that GLMakie + WGLMakie run on an emulated GPU, so the runtime benchmark is much slower. Results are from running:

using_time = @ctime using Backend
# Compile time
create_time = @ctime fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @ctime Makie.colorbuffer(display(fig))
# Runtime
create_time = @benchmark fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @benchmark Makie.colorbuffer(display(fig))
using create display create display
GLMakie 10.20s (9.99, 10.44) 0.16+- 1.17s (1.13, 1.19) 0.02+- 834.46ms (799.34, 885.99) 32.91+- 10.71ms (10.51, 10.89) 0.13+- 91.35ms (89.97, 92.50) 0.95+-
master 10.15s (9.95, 10.35) 0.18+- 1.16s (1.10, 1.21) 0.04+- 819.48ms (795.38, 836.07) 15.02+- 10.74ms (10.59, 10.93) 0.11+- 92.22ms (91.30, 93.18) 0.76+-
evaluation +0.51%, 0.05s invariant (0.31d, 0.57p, 0.17std) +0.98%, 0.01s invariant (0.36d, 0.51p, 0.03std) +1.80%, 14.98ms invariant (0.59d, 0.30p, 23.96std) -0.28%, -0.03ms invariant (-0.25d, 0.65p, 0.12std) -0.95%, -0.87ms invariant (-1.01d, 0.08p, 0.85std)
CairoMakie 10.33s (9.97, 10.73) 0.24+- 1.56s (1.50, 1.59) 0.03+- 345.24ms (330.31, 374.88) 18.82+- 13.79ms (13.50, 14.19) 0.25+- 7.27ms (6.99, 7.74) 0.26+-
master 10.26s (9.90, 10.75) 0.30+- 1.56s (1.51, 1.61) 0.04+- 314.96ms (303.93, 324.12) 8.52+- 13.65ms (13.34, 14.17) 0.30+- 7.27ms (6.95, 7.45) 0.18+-
evaluation +0.65%, 0.07s invariant (0.25d, 0.65p, 0.27std) +0.37%, 0.01s invariant (0.15d, 0.78p, 0.04std) +8.77%, 30.28ms slower❌ (2.07d, 0.00p, 13.67std) +1.04%, 0.14ms invariant (0.52d, 0.35p, 0.28std) +0.04%, 0.0ms invariant (0.01d, 0.98p, 0.22std)
WGLMakie 9.15s (9.00, 9.22) 0.08+- 1.24s (1.19, 1.26) 0.02+- 11.13s (11.03, 11.21) 0.07+- 13.39ms (11.71, 20.09) 2.98+- 751.63ms (710.94, 783.74) 25.61+-
master 9.19s (9.12, 9.26) 0.05+- 1.24s (1.21, 1.27) 0.02+- 11.18s (11.02, 11.45) 0.15+- 12.14ms (11.56, 12.50) 0.32+- 734.12ms (712.13, 753.62) 15.42+-
evaluation -0.44%, -0.04s invariant (-0.59d, 0.29p, 0.07std) +0.20%, 0.0s invariant (0.10d, 0.85p, 0.02std) -0.51%, -0.06s invariant (-0.48d, 0.39p, 0.11std) +9.32%, 1.25ms noisy🤷‍♀️ (0.59d, 0.31p, 1.65std) +2.33%, 17.51ms invariant (0.83d, 0.15p, 20.52std)

@ffreyer ffreyer changed the title scale AA padding with line width difference Fix AA with large linewidth differences May 14, 2023
@SimonDanisch SimonDanisch merged commit 268a3df into master May 26, 2023
14 checks passed
@SimonDanisch SimonDanisch deleted the ff/fix_lines branch May 26, 2023 09:50
@ffreyer ffreyer mentioned this pull request Jul 7, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GLMakie This relates to GLMakie.jl, the OpenGL backend for Makie.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants