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

Standardize view and projection matrices #3550

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented Jan 13, 2024

Description

This prepares some things for #3226:

  • move translations from projection to view matrices
  • track eyeposition in Axis and PolarAxis
  • rework Axis3 to use perspectiveprojection and lookat without modification (though I split up lookat into two steps)
  • add inv(::Quaternion)

And some random minor cleanup of Axis3 docs (indention, wrong render order in W/GLMakie, double-plotting of Label) + camera controller (name change).

Axis3 comparsion

Axis3 has more extensive changes so things could be different. Here are some new vs old comparisons with docs:

Aspect

Screenshot from 2024-01-13 14-39-03

Screenshot from 2024-01-13 14-39-03

Viewing angles

Screenshot from 2024-01-13 14-41-01

Tick placement seems to be slightly different (e.g. bottom left z is cut off more, top left z's overlap more(?))

Screenshot from 2024-01-13 14-41-35

Slightly less space to the title here as well

Perspectiveness

Screenshot from 2024-01-13 14-42-26

viewmodes

Screenshot from 2024-01-13 14-50-56

Also checked this with perspectiveness = 0.6, no visible changes.

Tight frustum testing/debugging

This will show you the generated frustum (i.e. what area of the scene will be rendered) with th view space bounding box (+ bounding sphere for :fit) of the Axis3.

using GeometryBasics

function camera_debug(gridpos, ax::Axis3)
    function frustum_snapshot(cam)
        r = Rect3f(Point3f(-1, -1, -1), Vec3f(2, 2, 2))
        rect_ps = coordinates(r) .|> Point3f
        insert!(rect_ps, 13, Point3f(1, -1, 1)) # fix bad line

        inv_pv = inv(cam.projectionview[])
        return map(rect_ps) do p
            p = inv_pv * to_ndim(Point4f, p, 1)
            return p[Vec(1,2,3)] / p[4]
        end
    end

    scene = ax.scene
    cam = scene.camera
    frustum = map(pv -> frustum_snapshot(cam), cam.projectionview)

    scene2 = LScene(gridpos, show_axis = false)

    _cc = Makie.Camera3D(
        scene2.scene, projectiontype = Makie.Orthographic,
        near = 0.001f0, far = 1000.0f0, clipping_mode = :static
    )
    lines!(scene2, frustum, color = :blue, linestyle = :dot)

    # bbox is Axis3 specific
    bbox = ax.finallimits
    model = ax.scene.transformation.model
    bb = map(model, bbox) do model, bb
        ps = [(model * to_ndim(Point4f, p, 1))[Vec(1,2,3)] for p in Makie.corners(bb)]
        Rect3f(ps)
    end
    r = map(bb -> maximum(norm.(Makie.corners(bb))), bb)

    linesegments!(scene2, bb, color = :black)
    wireframe!(scene2, map(r -> Sphere(Point3f(0), r), r), color = (:black, 0.2), transparency = true)
    # scatter!(scene2, scene.camera.eyeposition, color = :red)
    scatter!(scene2, Point3f(0), color = :blue)

    r = map(frustum) do frustum
        ps = vcat(frustum[1:12], frustum[14:end])
        normal_mesh(ps, faces(Rect3f()))
    end
    mesh!(scene2, r, color = (:red, 0.3), fxaa = false, transparency = true)
    notify(frustum)

    return scene2
end

begin
    fig = Figure()

    # show the extent of each cell using a box
    b = Box(fig[1, 1], strokewidth = 0, color = :gray95)
    translate!(b.blockscene, Vec3f(0, 0, -10_000))

    ax = Axis3(
        fig[1, 1]; viewmode = :stretch, protrusions = 0,
        aspect = (1,2,3), perspectiveness = 0.5
    )
    hidedecorations!(ax)
    camera_debug(fig[1, 2], ax)
    fig
end

Type of change

  • internal adjustments

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.

@MakieBot
Copy link
Collaborator

MakieBot commented Jan 13, 2024

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(fig)
using create display create display
GLMakie 3.44s (3.33, 3.61) 0.11+- 394.91ms (377.80, 418.02) 15.32+- 480.01ms (463.39, 500.48) 14.17+- 7.37ms (7.13, 7.74) 0.22+- 25.54ms (25.26, 25.94) 0.29+-
master 3.43s (3.34, 3.49) 0.05+- 404.26ms (391.81, 420.29) 10.08+- 481.27ms (464.89, 534.73) 24.04+- 7.39ms (7.08, 7.79) 0.24+- 25.62ms (25.31, 25.92) 0.22+-
evaluation 1.00x invariant, 0.01s (0.11d, 0.85p, 0.08std) 1.02x invariant, -9.35ms (-0.72d, 0.21p, 12.70std) 1.00x invariant, -1.25ms (-0.06d, 0.91p, 19.10std) 1.00x invariant, -0.01ms (-0.06d, 0.91p, 0.23std) 1.00x invariant, -0.08ms (-0.31d, 0.57p, 0.25std)
CairoMakie 3.07s (3.04, 3.12) 0.03+- 323.74ms (318.14, 330.18) 4.19+- 143.89ms (142.22, 145.87) 1.47+- 7.68ms (7.50, 8.08) 0.20+- 616.61μs (609.81, 624.18) 5.49+-
master 3.09s (3.03, 3.12) 0.03+- 327.71ms (320.60, 334.00) 4.46+- 147.24ms (140.97, 156.87) 5.55+- 7.55ms (7.45, 7.69) 0.08+- 610.42μs (605.64, 616.98) 4.00+-
evaluation 1.00x invariant, -0.01s (-0.42d, 0.45p, 0.03std) 1.01x invariant, -3.98ms (-0.92d, 0.11p, 4.32std) 1.02x invariant, -3.35ms (-0.83d, 0.17p, 3.51std) 0.98x invariant, 0.13ms (0.87d, 0.15p, 0.14std) 0.99x slower X, 6.18μs (1.29d, 0.03p, 4.74std)
WGLMakie 3.82s (3.78, 3.88) 0.04+- 339.80ms (330.17, 359.16) 10.11+- 9.32s (9.22, 9.41) 0.07+- 9.97ms (9.65, 11.24) 0.57+- 71.30ms (68.95, 77.77) 2.98+-
master 3.85s (3.80, 3.92) 0.04+- 348.01ms (329.97, 394.06) 21.64+- 9.46s (9.25, 9.63) 0.15+- 9.84ms (9.51, 10.36) 0.33+- 71.30ms (68.13, 77.48) 3.21+-
evaluation 1.01x invariant, -0.03s (-0.73d, 0.20p, 0.04std) 1.02x invariant, -8.21ms (-0.49d, 0.39p, 15.88std) 1.02x faster ✓, -0.14s (-1.21d, 0.05p, 0.11std) 0.99x invariant, 0.13ms (0.27d, 0.62p, 0.45std) 1.00x invariant, -0.01ms (-0.00d, 1.00p, 3.10std)

@ffreyer
Copy link
Collaborator Author

ffreyer commented Jan 13, 2024

space 3D failing is expected because the near and far planes are now tight to the finallimits in Axis3. This should also change OIT there, but I don't think we explicitly test that.

Failures in CairoMakie are one-pixel offsets of tick labels in Axis3. GLMakie and WGLMakie are the expected space 3D

@ffreyer ffreyer mentioned this pull request Mar 3, 2024
8 tasks
@ffreyer ffreyer changed the title Some preparations for Float32 fixes / Standardize view and projection matrices Standardize view and projection matrices Mar 18, 2024
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

2 participants