Skip to content

Upstream bevy_infinite_grid#23482

Merged
alice-i-cecile merged 15 commits intobevyengine:mainfrom
IceSentry:upstream_infinite_grid
Mar 24, 2026
Merged

Upstream bevy_infinite_grid#23482
alice-i-cecile merged 15 commits intobevyengine:mainfrom
IceSentry:upstream_infinite_grid

Conversation

@IceSentry
Copy link
Copy Markdown
Contributor

@IceSentry IceSentry commented Mar 23, 2026

Objective

  • Bevy is now at a point where multiple people are experimenting with editors and pretty much all of them need an infinite grid
  • There are various techniques that can be used to render an infinite grid without artifacts. This one fades out the lines that are too far from the camera. The general idea is that the grid is rendered in a fullscreen pass.
  • bevy_infinite_grid is maintained by foresight spatial labs. It has been used by foresight and other third party projects in production for many years at this point. This PR upstreams that crate with full permission from foresight.

Solution

  • Upstream bevy_infinite_grid
  • A few minor changes were done to bring it in line with the rest of bevy
  • In the process of upstreaming I noticed a few minor issues that I fixed like using a fullscreen triangle instead of a quad and using bevy's View instead of custom one.
  • The infinite_grid is currently part of bevy_dev_tools since we don't have an editor crate but I suspect we'll want to move it to an editor crate down the line. Although I'm sure projects will want to use this even if they aren't using the official editor.

Testing

  • I tested the example to confirm it works

Showcase

infinite_grid_cSJj0G02fP

@IceSentry IceSentry added A-Editor Graphical tools to make Bevy games A-Dev-Tools Tools used to debug Bevy applications. S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Feature A new feature, making something new possible labels Mar 23, 2026
Copy link
Copy Markdown
Contributor

@jbuehler23 jbuehler23 left a comment

Choose a reason for hiding this comment

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

Do we think this belongs as a standalone module/crate? Or is it better suited for bevy_dev_tools?

@alice-i-cecile alice-i-cecile added the M-Release-Note Work that should be called out in the blog due to impact label Mar 23, 2026
// Ray-plane intersection
// t is the signed distance to the plane
let point_to_point = plane_origin - ray_origin;
let t = dot(plane_normal, point_to_point) / dot(ray_direction, plane_normal);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This risks a division by zero / near-zero when the plane and ray are near-parallel. Should we be using an epsilon or some sort of early out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe, but we've never had issues with it AFAIK. This math will likely change soon but I don't think we need to block on this.

let plane_origin = grid_position.origin;

// Ray-plane intersection
// t is the signed distance to the plane
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't this mean we should be discarding if t < 0, since it would be behind the viewer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe, it's another case of "I didn't write the math so I'm not sure" 😅


/// Checks if the point is one the plane
fn plane_check(plane: &GlobalTransform, point: Vec3) -> bool {
plane.up().dot(plane.translation() - point).abs() > f32::EPSILON
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the correct epsilon value to use? This is about 1e-7. Generally I've seen much larger epsilons than this for this sort of grazing check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just know it's the one that we use and we haven't had issues. I technically didn't write this code so it's a bit hard to answer that specifically. I'm pretty sure we can use something larger without issues.

(For anyone reading this without context, that code is older than LLMs, when I say I didn't write it, it's just that it was written years ago by my coworkers.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If nothing else, not using the f32::EPSILON constant would be good, to avoid implying that this is somehow a "special" value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To me epsilon is the one that isn't special. Hardcoding a value would feel like that value has more weight than it has. As if it was picked for a specific reason. Epsilon was just used because it's the easiest to use small value.

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

None of the remaining comments are blocking. We can refine this in follow-up just fine :)

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 23, 2026
@IceSentry IceSentry added S-Blocked This cannot move forward until something else changes and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Mar 23, 2026
@alice-i-cecile alice-i-cecile added this to the 0.19 milestone Mar 23, 2026
@IceSentry
Copy link
Copy Markdown
Contributor Author

I'm in the process of changing how this works so it uses bevy's fullscreen shader features and potentially not use the transparent phase at all so I'd prefer blocking before merging anything.

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Blocked This cannot move forward until something else changes labels Mar 23, 2026
@IceSentry IceSentry added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Mar 24, 2026
@IceSentry
Copy link
Copy Markdown
Contributor Author

I think the PR is ready to merge. I feel like it's more code than necessary but I can iterate later.

jbuehler23 added a commit to jbuehler23/bevy that referenced this pull request Mar 24, 2026
Cherry-picked infinite_grid module from bevyengine#23482
into bevy_dev_tools for use by the editor.
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 24, 2026
Merged via the queue into bevyengine:main with commit 88f9fdf Mar 24, 2026
44 checks passed
splo pushed a commit to splo/bevy that referenced this pull request Mar 31, 2026
# Objective

- Bevy is now at a point where multiple people are experimenting with
editors and pretty much all of them need an infinite grid
- There are various techniques that can be used to render an infinite
grid without artifacts. This one fades out the lines that are too far
from the camera. The general idea is that the grid is rendered in a
fullscreen pass.
- [bevy_infinite_grid](https://github.com/fslabs/bevy_infinite_grid) is
maintained by foresight spatial labs. It has been used by foresight and
other third party projects in production for many years at this point.
This PR upstreams that crate with full permission from foresight.

## Solution

- Upstream bevy_infinite_grid
- A few minor changes were done to bring it in line with the rest of
bevy
- In the process of upstreaming I noticed a few minor issues that I
fixed like using a fullscreen triangle instead of a quad and using
bevy's View instead of custom one.
- The infinite_grid is currently part of bevy_dev_tools since we don't
have an editor crate but I suspect we'll want to move it to an editor
crate down the line. Although I'm sure projects will want to use this
even if they aren't using the official editor.

## Testing

- I tested the example to confirm it works

---

## Showcase

<img width="1280" height="720" alt="infinite_grid_cSJj0G02fP"
src="https://github.com/user-attachments/assets/cacddc5e-9a54-454b-aefa-b7829c34227a"
/>

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Dev-Tools Tools used to debug Bevy applications. A-Editor Graphical tools to make Bevy games C-Feature A new feature, making something new possible M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants