bevy/crates
Conner Petzold 3f187cf752
Add TilemapChunk rendering (#18866)
# Objective

An attempt to start building a base for first-party tilemaps (#13782).

The objective is to create a very simple tilemap chunk rendering plugin
that can be used as a building block for 3rd-party tilemap crates, and
eventually a first-party tilemap implementation.

## Solution

- Introduces two user-facing components, `TilemapChunk` and
`TilemapChunkIndices`, and a new material `TilemapChunkMaterial`.
- `TilemapChunk` holds the chunk and tile sizes, and the tileset image
- The tileset image is expected to be a layered image for use with
`texture_2d_array`, with the assumption that atlases or multiple images
would go through an asset loader/processor. Not sure if that should be
part of this PR or not..
- `TilemapChunkIndices` holds a 1d representation of all of the tile's
Option<u32> index into the tileset image.
- Indices are fixed to the size of tiles in a chunk (though maybe this
should just be an assertion instead?)
  - Indices are cloned and sent to the shader through a u32 texture.

## Testing

- Initial testing done with the `tilemap_chunk` example, though I need
to include some way to update indices as part of it.
- Tested wasm with webgl2 and webgpu
- I'm thinking it would probably be good to do some basic perf testing.

---

## Showcase

```rust
let chunk_size = UVec2::splat(64);
let tile_size = UVec2::splat(16);
let indices: Vec<Option<u32>> = (0..chunk_size.x * chunk_size.y)
    .map(|_| rng.gen_range(0..5))
    .map(|i| if i == 0 { None } else { Some(i - 1) })
    .collect();

commands.spawn((
    TilemapChunk {
        chunk_size,
        tile_size,
        tileset,
    },
    TilemapChunkIndices(indices),
));
```

![Screenshot 2025-04-17 at 11 54
56 PM](https://github.com/user-attachments/assets/850a53c1-16fc-405d-aad2-8ef5a0060fea)
2025-06-23 23:55:10 +00:00
..
bevy_a11y Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_animation Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_anti_aliasing Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_app Rename num_entities to entity_count (#19781) 2025-06-23 05:08:02 +00:00
bevy_asset Fix some typos (#19788) 2025-06-23 22:32:46 +00:00
bevy_audio Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_color Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_core_pipeline Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_core_widgets Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_derive Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_dev_tools Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_diagnostic Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_dylib Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_ecs Fix some typos (#19788) 2025-06-23 22:32:46 +00:00
bevy_encase_derive Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_gilrs Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_gizmos Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_gltf Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_image Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_input Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_input_focus Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_internal Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_log Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_macro_utils Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_math Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_mesh Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_mikktspace Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_pbr Fix some typos (#19788) 2025-06-23 22:32:46 +00:00
bevy_picking Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_platform Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_ptr Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_reflect Fix some typos (#19788) 2025-06-23 22:32:46 +00:00
bevy_remote Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_render bevy_solari: RIS for Direct Lighting (#19620) 2025-06-23 00:47:10 +00:00
bevy_scene Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_solari bevy_solari: RIS for Direct Lighting (#19620) 2025-06-23 00:47:10 +00:00
bevy_sprite Add TilemapChunk rendering (#18866) 2025-06-23 23:55:10 +00:00
bevy_state Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_tasks Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_text Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_time Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_transform Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_ui Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_utils Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00
bevy_window Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
bevy_winit Bump Version after Release (#19774) 2025-06-22 23:06:43 +00:00