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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

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.

Feedback on variable & type names welcome needed!

Docs says it all:

/// 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.
    spacing: rerun.blueprint.components.GridSpacing ("attr.rerun.component_optional", nullable, order: 2000);

    /// How the grid is oriented.
    ///
    /// Defaults to whatever plane is determined as the down plane by view coordinates if present.
    orientation: rerun.blueprint.components.PlaneOrientation ("attr.rerun.component_optional", nullable, order: 3000);

    /// Offset of the grid along its normal.
    offset: rerun.blueprint.components.PlaneOffset ("attr.rerun.component_optional", nullable, order: 4000);

    /// How thick the lines should be in ui units.
    ///
    /// Default is 0.5 ui unit.
    line_radius: rerun.blueprint.components.UiRadius ("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:
image

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

Bad case - it's below:
image

Changes to World grid renderer since original PR

  • tweak when to fade - generally fade more aggressively to keep grid not as busy

Testing

  • Metal
  • Vulkan
  • WebGPU
  • WebGL

Draft TODO

  • extend view creation python snippet with this property
    • check if python blueprint api is sane
  • why is background showing as half transparent by default now?
  • Adjust grid height for some samples or turn it off?
  • try new idea for cardinal lines
  • fix line thickness not working
  • switch to plane equations for blueprint api -> provide extensions in all languages

@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
6b18472 https://landing-cle5g2jqm-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
6b18472 https://rerun.io/viewer/pr/8234

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

Comment on lines +12 to +13
/// Space between grid lines spacing of one line to the next in scene units.
spacing: rerun.blueprint.components.GridSpacing ("attr.rerun.component_optional", nullable, order: 2000);
Copy link
Member

Choose a reason for hiding this comment

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

The data model lgtm overall 👍🏻 The spacing is slightly ambiguous? Is that the small lines or big lines. For some reason, my (randomly picked) default mental model was that the spacing refers to the big lines, but looking at the screenshots it seems that it's for the small lines. Maybe just clarify that in the doc string.

And then we're good. (That is, until someone requests arbitrary sub-line count to cover for inch/feet/whatever.

Copy link
Member Author

@Wumpf Wumpf Nov 28, 2024

Choose a reason for hiding this comment

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

thank you!

it's about the small lines. The big lines are right now a hardcoded visual gimmick to deal with zooming out, shows every 10th line
but yeah I can totally see where that confusion comes from!

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
@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

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