Repository navigation
Fix click picks: elements from the pick buffer, pick pass after the scene - #9
Merged
Merged
Conversation
A click on a surface mesh or a volume mesh selected element 0. The click code intersected the click ray with all mesh triangles on the CPU and added that hit with element 0. It gave the face from the pick buffer the same distance, so on the tie the CPU hit won. The click code also ignored the volume mesh cells, the volume grid gridcubes and the camera view wireframes of the pick buffer. As in C++ Polyscope, `App::click_hit_at` now takes the structure and the element from the pick buffer for every structure type. The distance of the element along the click ray comes from the pick depth buffer; points and curve network edges keep their exact ray test. A slice plane under the cursor wins if it is nearer. The CPU triangle test is removed. A gridcube reports the volume grid, with the cell of a cell quantity or the node of a node quantity. The new `RenderEngine::lookup_pick_owner` gives the quantity index of a pick range for this. A camera view reports the edge of its wireframe. `ClickHit::Structure` carries the element type.
The pick pass wrote the full pick uniforms and read the transforms under its own lock, after the frame preparation had written the render uniforms. If another thread moved a structure between the two, the pick buffer of that frame used the new position while the window showed the old one. The pick pass also ran before the scene passes, which make the curve network tube geometry, so for one frame a tube was picked at its old place or with its old radius. Now the frame preparation creates the pick resources and writes the pick uniforms (model, radius and cube size) in the same lock and with the same values as the render uniforms. Volume grid gridcubes do this in `init_volume_grid_quantities`. A gizmo drag in the UI writes the pick uniforms together with the render uniforms. The pick pass runs last in the window frame. It gives the pick ranges and writes only the first pick index of each owner with the new `write_pick_global_start`. A gridcube quantity drops its pick resources when its render data is built again, as a volume mesh does.
The Codex review of this branch found these defects: - `VolumeMesh::set_transform` dropped the pick resources. A gizmo drag after the frame preparation then left the volume mesh out of the pick pass of that frame, although the scene drew it. New render data drops the pick resources since 9c07272, so `set_transform` keeps them. - A node quantity wrote its gridcube pick uniforms only in gridcube mode, but its render uniforms in every mode. When the UI showed the gridcubes again after an isosurface, the pick pass of that frame used an old transform. The pick uniforms now follow the render uniforms in every mode. - A click took the type of a gridcube (node or cell) from the current quantities. If a quantity was removed after the frame, the type could be wrong. The pick pass now records the type of each gridcube range, and the click uses this record. - The click compared a slice plane at the cursor position with the pick depth at the pixel center. The ray tests of points and curve network edges used the current transform, not the one of the displayed frame. The click now uses the pixel center for the pick, the pick depth and the plane test, and the pick depth for every element type, as the scene does. The CPU ray tests are removed. - Each click read the full pick depth buffer. The click now reads it only when a slice plane is under the cursor. Feature Status lists one more known issue: the pick shaders ignore slice planes, so a click can select an element that a slice plane hides.
The second Codex review of this branch found these defects: - The tube pick shader of a curve network wrote the depth of the front of its click area, which is wider than the drawn line or tube. A curve just behind a surface mesh then covered the mesh in the pick buffer, and a click on the mesh selected the curve. The shader now writes the depth that the window shows: the tube surface where the pick ray hits the drawn tube, and the curve line elsewhere. A curve in line mode writes 0 as its tube radius and puts its tube radius into the minimum pick radius, so its click area does not change. - A click unprojected the pick depth of the last frame with the live camera, and it cast the slice plane ray with the live camera. A scroll or a drag before the next frame could then make a slice plane behind a mesh win. The frame preparation now keeps a copy of the camera whose uniforms it writes, and the pick pass makes it the view of the pick buffer. A click and a double-click use this view. - The delayed selection did not check the element index. A point cloud with fewer points after the frame could show a point that it no longer has. The selection now checks the index against the current element count. Architecture Differences now states where the picks of camera views and volume grids differ from C++ Polyscope: C++ gives a camera view one pick index, and it finds the node or the cell of a volume grid on the CPU.
The third Codex review of this branch found these defects: - The frame preparation wrote the tube pick radius for the render mode that it saw. The scene passes read the render mode when they draw. So after a switch from lines to tubes in the UI, the pick pass of that frame took the depth of the line where the window showed the tube. The frame preparation now writes the tube radius in both modes. The pick pass writes 0 for a curve in line mode, with the render mode of its frame. - The nearest point of a curve segment to the pick ray lost its precision for a segment almost parallel to the ray. For a segment parallel to an orthographic ray, it always took the first end, so the edge order decided whether the line covered a surface. The shader now computes the point from the parts of the segment ends across the ray, and a parallel segment takes its nearer end. - A face in the plane of a slice plane could win a click over the plane, because of the rounding of the pick depth. The scene draws the slice planes first and the structures with a "less" depth test, so the window shows the plane. The plane now wins if the face is nearer by less than the precision of the pick depth. Feature Status lists the two other findings of the review as known issues: the click area past a tube end, and a click before the first frame after a window resize.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the three pick issues that PR #7 recorded under Known Issues. Planned for 0.6.3. Five commits: the first two hold the fixes, and the last three hold the fixes from three Codex review rounds.
1. A click takes the element from the pick buffer (0603cad)
App::click_hit_attakes the structure and the element from the pick buffer for every structure type, as C++ Polyscope does.RenderEngine::lookup_pick_ownerandPickOwnerHit, which give the quantity index of a pick range.2. Pick uniforms with the render uniforms, pick pass last (b99f50c)
init_volume_grid_quantities. A gizmo drag in the UI writes both together.write_pick_global_start(a 4-byte write at the offset ofglobal_start).3. First review fixes (306b869)
VolumeMesh::set_transformkeeps its pick resources, so a gizmo drag does not take the volume mesh out of the pick pass. New render data drops them.4. Second review fixes (d5fb584)
5. Third review fixes (0d04f78)
CurveNetwork::write_tube_pick_render_mode). Before, the frame preparation set it, so after a switch from lines to tubes in the UI, the pick pass of that frame took the line depth where the window showed the tube.Known issues (documented in
docs/feature-status.md, not changed here)Tests
crates/polyscope/src/tests/pick.rs. The GPU tests skip when no GPU adapter is available, as the other GPU tests do.test_click_reports_mesh_faces_and_cells,test_click_reports_volume_grid_cells_and_nodes,test_click_selects_a_camera_view.test_pick_pass_uses_the_transform_of_the_scene: another thread moves a point and a tetrahedron after the frame preparation. The scene image and the pick buffer of that frame both show the old position; the next frame shows the new position in both.test_gridcubes_after_an_isosurface_are_picked_in_placeandtest_gridcube_click_keeps_the_element_type_of_the_frame.test_click_compares_slice_planes_with_the_pick_depth: a slice plane behind and in front of a square, with clicks at pixel corners.test_line_behind_a_mesh_does_not_cover_it: a line 0.02 behind a square, with a click area of radius 0.05.test_click_uses_the_camera_of_the_pick_buffer: a scroll after the frame, with a slice plane 0.1 behind a square.test_click_selection_checks_the_element(CPU): a point cloud loses points during the double-click time.test_tube_switch_in_a_frame_is_picked_as_a_tube: the UI switches a line 0.02 behind a square to a tube of radius 0.05 after the frame preparation.test_end_on_line_is_picked_at_its_nearer_end: two lines along an orthographic view direction, in both edge orders, with a square between their ends.test_slice_plane_wins_a_tie_with_a_face: 25 clicks on a square in the plane of a slice plane.test_curve_pick_radius_follows_the_radiusnow expects the new tube radius one frame after the change.set_transformdropping the volume mesh pick resources, gridcube pick uniforms only in gridcube mode, the element type from the current quantities, the curve pick depth from the front of the click area, the old line-mode pick uniforms, the live camera in the click, the selection without the element check, the tube depth source from the frame preparation, the old nearest-point formula, and the strict distance comparison with the slice plane.cargo test --workspace --no-fail-fastgives 346 passed, 0 failed, 2 ignored, with no GPU test skipped.cargo fmt --all -- --check,cargo clippy -- -D warningsandRUSTDOCFLAGS="-D warnings" cargo doc --no-deps --document-private-itemspass.cargo clippy --workspace --all-targetsreports no finding on a line that this branch changes.🤖 Generated with Claude Code