godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.94k stars 20.17k forks source link

TileMapLayer tiles aren't batching #95971

Open boruok opened 3 weeks ago

boruok commented 3 weeks ago

Tested versions

reproduced

System information

Ubuntu 22.04.4 LTS, GTX1060 6GB, NVIDIA 535.183.01, Compatibility mode

Issue description

noticed that Godot 4 TileMapLayer tiles aren't batched if tiles not in same texture, even if textures in same atlas. However in Godot 3 tiles are batching (if textures in same atlas)

godot 4

separate textures, 16x16 rect, 2 tile-types, same atlas texture = 34 drawcalls image same texture, 16x16 rect, 2 tiles, same atlas = 1 drawcall image

godot 3

separate textures, 16x16 rect, 2 tile-types, same atlas texture = 2 drawcalls image image

Steps to reproduce

  1. run attached files
  2. check raster monitor

Minimal reproduction project (MRP)

for_godot3.zip for_godot4.zip

kleonc commented 3 weeks ago

This happens because TileSetAtlasSource.use_texture_padding is enabled for both sources, by default. 3iXmivTBDo

Thus both sources generate new runtime texture with additional padding around tiles. Turning it off makes both sources use the original atlas (and draw with a single draw call because of no texture changes).

Godot_v4 3-stable_win64_VilaZRjBmv Godot_v4 3-stable_win64_DV0W9rjZCt

I'd say this is not a bug, but it could possibly be improved by detecting such situations and generating a shared padded texture for different sources. :thinking:


godot 4

separate textures, 16x16 rect, 2 tile-types, same atlas texture = 34 drawcalls

You've drawn 17x17 cells, just saying. And each draw call is per ~half row of tiles, as then there's a texture change.