thombruce / verse

🚀 A universe in progress
Other
8 stars 0 forks source link

Evaluate bevy_tiling_background for tiling backgrounds #7

Closed thombruce closed 1 year ago

thombruce commented 1 year ago

See: https://github.com/BraymatterOrg/bevy_tiling_background

It's a young project (less than a year in development) but it is active. Not much documentation to be found, so I'll want to take it for a test spin and see if I can figure out how to use it from reviewing the source and examples.

  1. Clone the repo and run the examples; find a best fit
  2. Evaluate the example code and modify for Verse
  3. Evaluate and attempt to understand the source[^1]

[^1]: If the project is abandoned, we will be forced to either adopt and maintain it ourselves, wait for someone else to do so, or reimplement the tiled background some other way.

thombruce commented 1 year ago

Seems you can cargo run --example [name] to run the examples in the examples/ directory. Didn't know that, attempting to run the first one now. We have three to evaluate:

  1. custom.rs
  2. layers.rs
  3. tiling.rs

Layers and tiling both sound like features I'm looking for (tiling for stars, layers for nebulae and gases).

thombruce commented 1 year ago

Immediately unable to run the examples - seemingly unable to load the image assets...

I've had to checkout rparrett's branch (PR: https://github.com/BraymatterOrg/bevy_tiling_background/pull/20) and, yup, this fixes the issue.

So... breaking changes on the main branch, but we will probably will be using it since it seems to work in Bevy 0.11 with rparrett's fixes.

thombruce commented 1 year ago

The tiling example works very nicely and the layers example demonstrates almost exactly what I'm looking for and is fun to toy with.

Seems the backgrounds disappear entirely when you travel a certain distance... this may not be an error, but could simply be a limitation of the example code that's easily tweaked.

I don't see anything that would limit the bounds of the background in the example code. Quick guess: Perhaps the background has a position or some preset dimensions that our camera is moving away from - when the camera leaves these bounds, the background is deemed to be no longer visible and not rendered?

That's a maybe.

The background does break in the same way for all three examples. I suspect we can probably modify the bounds of the background object... or else move it with the camera?

This at least looks worth attempting to implement in Verse to me. We'll have to use rparrett's branch until it's merged, then main branch until a release with Bevy 0.11 support.

The source code itself is intimidating (what's a .wgsl file? how do you even work with shaders?) but only around 350 lines of code, so not beyond reason to try and get an understanding of.

thombruce commented 1 year ago

Specifying the dependency:

Until rparrett's fix is merged:

[dependencies]
bevy_tiling_background = { git = "https://github.com/rparrett/bevy_tiling_background.git", branch = "tex-typo" }

Until a release supporting Bevy 0.11:

[dependencies]
bevy_tiling_background = { git = "https://github.com/BraymatterOrg/bevy_tiling_background.git" }
thombruce commented 1 year ago

Also to implement at this point:

The idea is to have the background serve as a reference for the player's movement. We'll then add other entities to the scene (planets, asteroids, other ships) that also move around the space. But maybe we should introduce camera zoom/scaling before doing so? This will help to make clearer the scale and distances between objects in space.

thombruce commented 1 year ago

The Kenney Space Shooter Redux pack I already have downloaded comes with four 256x256 tileable background images. We'll use black.png for now, but consider using the purples and blue in other areas later.

thombruce commented 1 year ago

Best solution I've found to force the visibility to remain on even when the source of the image is far outside the reach of the camera is to add NoFrustrumCulling to the spawn bundle:

commands.spawn((
        BackgroundImageBundle::from_image(image, materials.as_mut()).at_z_layer(-0.1),
        NoFrustumCulling,
    ));

This component essentially instructs the camera not to cull the visibility even if the entity is outside of the camera frustrum (what it can see).

Seems I can fly any distance now without my background disappearing.