Upstream bevy_infinite_grid#23482
Conversation
jbuehler23
left a comment
There was a problem hiding this comment.
Do we think this belongs as a standalone module/crate? Or is it better suited for bevy_dev_tools?
| // 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Doesn't this mean we should be discarding if t < 0, since it would be behind the viewer?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
If nothing else, not using the f32::EPSILON constant would be good, to avoid implying that this is somehow a "special" value.
There was a problem hiding this comment.
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>
|
The generated |
alice-i-cecile
left a comment
There was a problem hiding this comment.
None of the remaining comments are blocking. We can refine this in follow-up just fine :)
|
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. |
|
I think the PR is ready to merge. I feel like it's more code than necessary but I can iterate later. |
Cherry-picked infinite_grid module from bevyengine#23482 into bevy_dev_tools for use by the editor.
# 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>
Objective
Solution
Testing
Showcase