guibec / rpgcraft

RPGCraft - Minecraft / Terraria / RPGMaker mashup
MIT License
8 stars 2 forks source link

Runtime Texture Atlas Construction #19

Open jstine35 opened 7 years ago

jstine35 commented 7 years ago

The tilemap engine relies on a fixed-function 'tilemap pipeline' which reads textures from an atlas with uniform layout (fixed size tiles). Atlas textures must be uniform to a fixed grid layout, and must be constructed with 2-pix repeating-texture padding to fix texture sampling bilinear filtering error.

For rapid development purposes it is highly advantageous to be able to specify individual png src textures and assign them into the game. Moreover, calculation of the padding area means that atlas sheets ideal from an asset designer's perspective are still not OK for our purposes.

Therefore I propose adding an Atlas builder to the engine, with the following basic image editing features:

Note that I considered turning off bilinear filtering as a work-around for 2-pix padding.

robinlavallee commented 7 years ago

Yes ! From a gameplay designer point of view, we should make it easy to drop new images and tiles as needed in the "image" directory and have them being picked up automatically by the engine (reloading the engine is okay, but doing it on the fly is even crazier), then it would be possible to reference these new tiles by filename/UVs. Any size should work, the engine would figure out the best texture size for these.

I'm assuming internally it will try to store those images into an Atlas to limit the number of draw calls.

jstine35 commented 7 years ago

Follow-up on the technical design of the tile engine: Multiple atlases can be used by issuing mutli-pass TileMap draws, where tiles from the current atlas are valid IDs and tiles from different atlas are nil. The cost of the draw pass should be pretty inexpensive.

In a pinch, an atlas could just as well be a single tile. This would be an OK work-around for immediate-use of added texture resources. The engine will use the slow-path of issuing separate draw calls for each non-atlas'd texture until the next engine reload. On reload, things get baked into a texture and perf is restored.

This effectively maintains gameplay perf while allowing rapid development with possible perf penalties, as it is considered acceptable criteria to have perf penalties during development cycles.