bevy_tilemap icon indicating copy to clipboard operation
bevy_tilemap copied to clipboard

Tile Transforms

Open chrisburnor opened this issue 3 years ago • 6 comments

Right now TileMaps can have a local and global transform, but it seems to apply to the whole tilesheet. It would be useful, for animations or effects to be able to control the transform of each Tile as well to enable rotations, scaling, and other arbitrary distortions.

chrisburnor avatar Dec 29 '20 07:12 chrisburnor

I suspect this might be fairly easy to implement, by passing a per-tile transform matrix as another input into the vertex shader. It could multiply that matrix after calculating the coordinates.

IDK how much overhead this would have, and if it might be worth coming up with a way to make it optional, so that people who only want a static grid don't have to pay the price in performance.

inodentry avatar Dec 30 '20 11:12 inodentry

Yes please. Rotating would be very useful.

Lythenas avatar Dec 30 '20 14:12 Lythenas

I just can't help but wonder -- at what point would the functionality of this crate converge with simply using bevy sprites for all the tiles (after bevy implements batching/instancing for sprite rendering to make it efficient). Would this crate eventually become redundant/obsolete? Particularly if its complexity grows due to features like this proposal. It would no longer be simply a crate for efficient rendering of a static grid. So maybe this feature request is out of scope?

IDK, @joshuajbouw is the one to decide / give an opinion on this.

inodentry avatar Dec 30 '20 15:12 inodentry

I was wondering the same thing. My reasoning in putting it here, though, is that, as @jamadazi referenced, it should be simply a transform. Since each tile is already being passed a transform to place it on the screen, it shouldn't be much technical overhead.

I think the open question is more logical overhead in terms of having an API to express matrices and transforms (something the rust ecosystem seems awash in these days without a clear standard lib to do so)

chrisburnor avatar Jan 05 '21 17:01 chrisburnor

@chrisburnor Animations will be coming, same with transforms. It wouldn't be like Bevy's transform API, but just flip flags and vector of animation frames with reference to which tiles to render from the spritesheet. It is MUCH cheaper to hold bit flags of the tile's transform, then it's actual transform.

@jamadazi I don't think so. Tile maps are typically part of a core game dev library. I would at that point switch to doing per tile rendering and check if the performance is the same or better. If it isn't, then I would stick with this method here.

It IS part of the transform which is passed to the shader, I think it is just as simple as passing in the transform.

joshuajbouw avatar Jan 07 '21 12:01 joshuajbouw

bit flags

Does that mean the plan is to only allow flip transforms? My hope had been to give a sort of compression/bend effect as sprites move between tiles to make them feel a bit more 'alive'

chrisburnor avatar Aug 24 '21 01:08 chrisburnor