Crates.io | wgpu-tilemap |
lib.rs | wgpu-tilemap |
version | 0.1.1 |
source | src |
created_at | 2023-09-21 04:34:09.40555 |
updated_at | 2023-09-26 19:34:07.032986 |
description | wgpu middleware for GPU-accelerated tilemap rendering, primarily targeted at 2d games |
homepage | |
repository | https://github.com/aweinstock314/wgpu-tilemap |
max_upload_size | |
id | 979090 |
size | 47,404 |
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.
// Create a tilemap pipeline
let mut tilemap_pipeline = TilemapPipeline::new(device, surface_config.format, None);
// Specify a camera matrix
tilemap_pipeline.set_camera(queue, FULLSCREEN_QUAD_CAMERA);
// Create/load a tileset
use image::io::Reader as ImageReader;
let tileset_image = ImageReader::open("tileset.png").unwrap().decode().unwrap();
let tileset = TilesetRef::from_image(&tileset_image, Vec2::new(32, 32));
// Upload a tileset to the GPU
tilemap_pipeline.upload_tilesets(device, queue, &[tileset]);
// Create/load a tilemap
let some_tilemap = TilemapRef::zeroed(Vec2::broadcast(size));
// Upload a tilemap to the GPU
self.tilemap_pipeline.upload_tilemaps(
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)