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

World grid part 2/2: Integrate into Viewer #8234

Merged
merged 31 commits into from
Dec 6, 2024
Merged

World grid part 2/2: Integrate into Viewer #8234

merged 31 commits into from
Dec 6, 2024

Conversation

Wumpf
Copy link
Member

@Wumpf Wumpf commented Nov 27, 2024

Related

What

Adds new line grid property to the 3D view and enables it by default.

Furthermore...

  • improves the grid shader with infinite cardinal lines while showing only two types of "cardinalitities"
    • this is simply based on log10(camera distance from plane) and then blends between two levels of grid
  • improve grid's handling of extreme zoom levels. Still some instability on WebGL, but overall much more robust (less flickering/cutoff)
  • Introduce a general Plane3D component which is meant for later reuse in other contexts

The new view property is best described its fbs:

/// Configuration for the 3D line grid.
table LineGrid3D (
    "attr.rerun.scope": "blueprint"
) {
    /// Whether the grid is visible.
    ///
    /// Defaults to true.
    visible: rerun.blueprint.components.Visible ("attr.rerun.component_optional", nullable, order: 1000);

    /// Space between grid lines spacing of one line to the next in scene units.
    ///
    /// As you zoom out, successively only every tenth line is shown.
    /// This controls the closest zoom level.
    spacing: rerun.blueprint.components.GridSpacing ("attr.rerun.component_optional", nullable, order: 2000);

    /// In what plane the grid is drawn.
    ///
    /// Defaults to whatever plane is determined as the plane at zero units up/down as defined by [components.ViewCoordinates] if present.
    plane: rerun.components.Plane3D ("attr.rerun.component_optional", nullable, order: 3000);

    /// How thick the lines should be in ui units.
    ///
    /// Default is 1.0 ui unit.
    stroke_width: rerun.components.StrokeWidth ("attr.rerun.component_optional", nullable, order: 5000);

    /// Color used for the grid.
    ///
    /// Transparency via alpha channel is supported.
    /// Defaults to a slightly transparent light gray.
    color: rerun.components.Color ("attr.rerun.component_optional", nullable, order: 6000);
}

Properties in the viewer in default selection panel width
image

New plane controls expanded:
image

Examples of the grid in action (in default settings):
image
image

Bad case - grid is not fine enough and through the scene:
image
Bad case - grid is above the scene.
image

Testing

  • Metal
  • Vulkan
  • WebGPU
  • WebGL

Future work

  • tweak some examples to disable the grid or change its spacing
  • Extend grid to 2d scenes

@Wumpf Wumpf added 📺 re_viewer affects re_viewer itself include in changelog labels Nov 27, 2024
Copy link

github-actions bot commented Nov 27, 2024

Latest documentation preview deployed successfully.

Result Commit Link
5fe5dfd https://landing-nuo6pcdya-rerun.vercel.app/docs

Note: This comment is updated whenever you push a commit.

Copy link

github-actions bot commented Nov 27, 2024

Web viewer built successfully. If applicable, you should also test it:

  • I have tested the web viewer
Result Commit Link
5fe5dfd https://rerun.io/viewer/pr/8234

Note: This comment is updated whenever you push a commit.

@Wumpf Wumpf force-pushed the andreas/world-grid2 branch from 0c859e6 to d8eaa07 Compare November 28, 2024 10:01
Wumpf added a commit that referenced this pull request Nov 28, 2024
### Related

This is the first half of

* #872

The second half is here:
* #8234

### What

Implements a "world grid" to be used later in the spatial views of the
viewer.
Haven't tested yet how suitable this is for 2D views, might need some
adjustments.

## Video

Youtube unfortunately compresses this a lot and Github doesn't let me
upload any significant amount of video
(click me)
[![youtube video of world grid
v1](http://img.youtube.com/vi/Ho-iGdmJi4Q/0.jpg)](http://www.youtube.com/watch?v=Ho-iGdmJi4Q
"World Grid v1")

## Screenshots

Analytical anti-aliasing (shown is what is supposed to be a 1ui unit ==
2pixel wide line):
<img width="1215" alt="image"
src="https://github.com/user-attachments/assets/702b82ac-2629-4aa5-9304-0cd3c4d87fc5">

Distance has only the cardinal lines (== every tenth line). Those fade
eventually as well:
<img width="747" alt="image"
src="https://github.com/user-attachments/assets/ebe6b2c9-37e5-4406-8d28-5260cf2940d4">

Fading is based on "how many lines coincide here" which makes fading
view dependent rather than distance dependent:
<img width="439" alt="image"
src="https://github.com/user-attachments/assets/9bea7a42-9edc-4a7d-be19-9498a1f29fdf">
(this makes this hopefully robust for many usecases)

Grid intersects non-transparent geometry (transparent geometry will be
ignored in the future. previous surveying showed that this is common and
not a biggy)
<img width="426" alt="image"
src="https://github.com/user-attachments/assets/19de2cc9-015d-4fdd-a275-096768119a9e">

Grid fades at acute viewing angles (because empirically and
unsurprisingly it looks weird if we don't!)
<img width="1437" alt="image"
src="https://github.com/user-attachments/assets/2a05b8e5-9915-4dda-9a54-4db829e22ac3">

Tested image quality to be satisfying on high dpi (ui unit == 2 pixels)
and low dpi (ui unit == pixel).

## How does it work

* Draw a large shader generated plane (mostly because setting up vertex
buffers is just more hassle 😄 )
    * depth test enabled
    * depth write disabled
    * premultiplied alpha blend
* make sure we draw this after the background (reminder: we first draw
solid, then background)
* Fragment shader looks at 2d coordinate on the plane and decides how
"liney" it is
* using screen space derivatives (ddx/ddy) we figure out how far to go
on the plane to achieve a certain line thickness
   * fades:
        * fade if the line density gets too high
        * fade if view angle is too acute relative  
   * ... lot's of details documented in the shader code!

I considered just drawing a screen space triangle, but drawing a plane
that moves with the camera has lots of advantages:
* don't have to manipulate depth
    * faster since early z just works
    * less thinking required!
* don't cover things above the horizon - even if only the grid is
visible, less pixels will be shaded

## Known shortcomings

* various hardcoded values around how fading works. Tricky to formalize
this better, but likely good enough
* Doesn't look equally good at all pixel widths, but decent for the
range we care
* every tenth line is a "cardinal line", that's nice but it stops there
- "infinite" amount of cardinal lines would be nicer
* Experimented with that but so far didn't get anything that was
compelling. Having many order-of-magnitude lines looks way too busy
imho, it needs a mechanism that limits that to two.
* Blender's 2D view does this really well, but in 3D they only do two
cardinals as well.

## Try it yourself

Controls:
- Space: Pause
- G: Toggle camera mode

native:
```
cargo run -p re_renderer_examples --bin world_grid
```

web:
```
cargo run-wasm -p re_renderer_examples --bin world_grid
```


## Backend testing matrix

* [x] Metal
* [x] Vulkan
* [x] WebGL
* [x] WebGPU
Base automatically changed from andreas/world-grid to main November 28, 2024 10:05
@Wumpf Wumpf force-pushed the andreas/world-grid2 branch from d8eaa07 to 6b18472 Compare November 28, 2024 12:56
@nikolausWest
Copy link
Member

Small bug: it's now possible to set alpha in the color picker for the Lines3D override (which obviously doesn't work)

Screenshot 2024-11-29 at 15 02 01

@Wumpf Wumpf force-pushed the andreas/world-grid2 branch from 6b18472 to d884bd3 Compare December 3, 2024 13:39
@Wumpf Wumpf force-pushed the andreas/world-grid2 branch from a34682c to 0117aa8 Compare December 3, 2024 18:14
Wumpf added a commit that referenced this pull request Dec 4, 2024
### Related

* split out of #8234 

### What

* use `ViewProperty` util construct some more
* route individual property ui via `view_property_component_ui_custom`
making it easier to draw custom ui for specific view properties while
still having all tooltip & extra menus be the same
@Wumpf Wumpf force-pushed the andreas/world-grid2 branch from aac6b34 to 87aff22 Compare December 4, 2024 08:01
grtlr pushed a commit that referenced this pull request Dec 4, 2024
### Related

* split out of #8234 

### What

* use `ViewProperty` util construct some more
* route individual property ui via `view_property_component_ui_custom`
making it easier to draw custom ui for specific view properties while
still having all tooltip & extra menus be the same
@Wumpf Wumpf marked this pull request as ready for review December 5, 2024 10:04
@nikolausWest
Copy link
Member

Just clicking through some examples it's clear that the grid doesn't end up at the "right" height for most of them. Wonder if it's worth explicitly settign the plane height to make those look good?

@Wumpf
Copy link
Member Author

Wumpf commented Dec 5, 2024

yes, we should likely do some adjustments there on a per example basis. For some examples we may also want to turn it off

@Wumpf Wumpf requested a review from abey79 December 5, 2024 14:58
Copy link
Member

@abey79 abey79 left a comment

Choose a reason for hiding this comment

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

Awesome!

crates/viewer/re_space_view_spatial/src/view_3d.rs Outdated Show resolved Hide resolved
Comment on lines +473 to +474
// TODO(#1611): The color picker for the color component doesn't show alpha values so far since alpha is almost never supported.
// Here however, we need that alpha color picker!
Copy link
Member

Choose a reason for hiding this comment

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

Note: another short term quick win by rolling tagged component to view property. We could make the component ui editor white list some Archetype/Field for the transparency ui.

docs/snippets/all/views/spatial3d.py Outdated Show resolved Hide resolved
@Wumpf Wumpf merged commit 601afc8 into main Dec 6, 2024
37 checks passed
@Wumpf Wumpf deleted the andreas/world-grid2 branch December 6, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

World-space grid
3 participants