wgpu-tilemap
is wgpu middleware for GPU-accelerated tilemap rendering, primarily targeted at 2d games.
It draws each tilemap as a single quad, so the vertex count is independent of the size of the tilemap. It uses texture arrays for the tilesets, so the fragment shader is essentially 2 texture loads: one from the tilemap and one from the tileset. It discards fully transparent fragments, so drawing multiple layers can be accelerated with a depth buffer.
```rust // Create a tilemap pipeline let mut tilemappipeline = TilemapPipeline::new(device, surfaceconfig.format, None);
// Specify a camera matrix tilemappipeline.setcamera(queue, FULLSCREENQUADCAMERA);
// Create/load a tileset
use image::io::Reader as ImageReader;
let tilesetimage = ImageReader::open("tileset.png").unwrap().decode().unwrap();
let tileset = TilesetRef::fromimage(&tileset_image, Vec2::new(32, 32));
// Upload a tileset to the GPU tilemappipeline.uploadtilesets(device, queue, &[tileset]);
// Create/load a tilemap let some_tilemap = TilemapRef::zeroed(Vec2::broadcast(size));
// Upload a tilemap to the GPU self.tilemappipeline.uploadtilemaps( device, queue, &[TilemapDrawData { transform: Mat4::identity(), tilemap: Cow::Borrowed(&some_tilemap), tileset: 0, noise: TilemapNoise::default(), }], );
// Render the uploaded tilemaps tilemap_pipeline.render(&device, &mut rpass); ```
wgpu-tilemap
is licensed under the Apache License, Version 2.0, (LICENSE.apache2 or https://www.apache.org/licenses/LICENSE-2.0)