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

interpolate between values instead of interpolating between colors #2097

Merged
merged 11 commits into from Jul 21, 2022

Conversation

SimonDanisch
Copy link
Member

We've been interpolating between colors in the mesh shader...
TODO: We also still interpolate between colors in cairo at least for mesh.
Bug report: https://discourse.julialang.org/t/how-to-create-a-patch-shape-with-a-color-gradient-in-a-simple-2d-plot/62607/7?u=sdanisch

Before:

using GLMakie
vertices = Point2[
    (0.0, -1.0)
    (1.0, 0.0)
    (0.6, 1.0)
]
faces = [1, 2, 3]
colors = [1, 2, 3]
f, ax, p = mesh(vertices, faces, color = colors, shading = false, colormap = Reverse(:viridis))
Colorbar(f[1, 2], p)
f

image

With this PR:
image

@MakieBot
Copy link
Collaborator

MakieBot commented Jun 27, 2022

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 14.45s (14.40, 14.50) 0.03+- 20.42s (20.31, 20.55) 0.08+- 17.53s (17.44, 17.62) 0.07+- 15.12ms (15.04, 15.25) 0.07+- 77.63ms (76.89, 79.09) 0.71+-
master 14.41s (14.29, 14.49) 0.08+- 20.10s (19.97, 20.25) 0.08+- 17.53s (17.41, 17.72) 0.10+- 15.13ms (14.98, 15.24) 0.10+- 77.57ms (76.50, 78.82) 0.69+-
evaluation +0.31%, 0.05s invariant (0.70d, 0.22p, 0.06std) +1.58%, 0.32s slower X (3.91d, 0.00p, 0.08std) -0.00%, -0.0s invariant (-0.00d, 1.00p, 0.08std) -0.05%, -0.01ms invariant (-0.09d, 0.86p, 0.08std) +0.08%, 0.06ms invariant (0.09d, 0.87p, 0.70std)
CairoMakie 11.64s (11.39, 12.75) 0.50+- 18.24s (17.84, 19.92) 0.75+- 2.25s (2.21, 2.47) 0.10+- 16.90ms (16.43, 18.11) 0.56+- 22.16ms (21.63, 24.18) 0.90+-
master 11.63s (11.37, 12.70) 0.48+- 17.63s (17.54, 17.84) 0.11+- 2.29s (2.26, 2.31) 0.01+- 17.11ms (16.83, 17.27) 0.16+- 21.86ms (21.72, 22.06) 0.11+-
evaluation +0.04%, 0.0s invariant (0.01d, 0.99p, 0.49std) +3.34%, 0.61s invariant (1.13d, 0.08p, 0.43std) -1.51%, -0.03s invariant (-0.49d, 0.39p, 0.06std) -1.21%, -0.2ms invariant (-0.49d, 0.39p, 0.36std) +1.35%, 0.3ms invariant (0.46d, 0.42p, 0.51std)
WGLMakie 20.62s (20.34, 20.92) 0.20+- 40.51s (39.80, 41.16) 0.45+- 55.20s (54.41, 56.41) 0.78+- 27.03ms (26.03, 27.85) 0.61+- 2.05s (1.96, 2.12) 0.06+-
master 20.52s (20.05, 20.75) 0.22+- 39.91s (39.01, 40.96) 0.71+- 54.94s (53.50, 56.39) 0.94+- 26.96ms (26.07, 27.70) 0.52+- 2.05s (1.99, 2.11) 0.04+-
evaluation +0.46%, 0.09s invariant (0.45d, 0.42p, 0.21std) +1.47%, 0.6s invariant (1.00d, 0.09p, 0.58std) +0.47%, 0.26s invariant (0.30d, 0.58p, 0.86std) +0.29%, 0.08ms invariant (0.14d, 0.80p, 0.57std) -0.08%, -0.0s invariant (-0.04d, 0.95p, 0.05std)

@jkrumbiegel
Copy link
Collaborator

Cairo can't do any other interpolation than between color. So to really support it we would need to software-render our own meshes to bitmaps directly.

@SimonDanisch
Copy link
Member Author

Yeah, I've been wanting to do that... It's not even that hard, just need to find some time for it!

@asinghvi17
Copy link
Member

asinghvi17 commented Jun 28, 2022

Hmm...wouldn't that essentially lose the "vector" nature of the mesh (i.e., zoomability without pixelation)? Or are you proposing subdividing the mesh and interpolating along color gradients of smaller magnitude? Either way, it would probably be nice to be able to turn it on and off by some switch in CairoMakie.

Also, how would this affect large meshes like those generated by surface!?

@jkrumbiegel
Copy link
Collaborator

Mesh is already rasterized (at least in svgs). Could be that it's not in pdfs, not sure, but the mesh operator hasnt been added to the svg spec yet.

@asinghvi17
Copy link
Member

asinghvi17 commented Jun 28, 2022

Hmm, makes sense. I believe PDF does have a mesh gradient intrinsic, but in any case that would be a fixed color interpolation type. Would you be going along a route similar to this, or something else?

Edit: if we're doing this we could theoretically also allow the user to specify the mode of interpolation (linear, cubic, bilinear, etc)

@@ -8,6 +8,7 @@ role as `datalimits` in `violin` [#2137](https://github.com/JuliaPlots/Makie.jl/
- Improve performance around Axis(3) limits [#2115](https://github.com/JuliaPlots/Makie.jl/pull/2115).
- Cleanup stroke artifacts in scatter and text [#2096](https://github.com/JuliaPlots/Makie.jl/pull/2096).
- compile time improvements [#2153](https://github.com/JuliaPlots/Makie.jl/pull/2153).
- interpolate between values instead of interpolating between colors for WGLMakie + GLMakie [#2097](https://github.com/JuliaPlots/Makie.jl/pull/2097)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization here and above :)
It's not that good to paste the PR titles as those are usually not even complete sentences.

@SimonDanisch SimonDanisch merged commit 1281105 into master Jul 21, 2022
@SimonDanisch SimonDanisch deleted the sd/fix-gl-interpolation branch July 21, 2022 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants