Suggestion: Support for texture atlases?
See original GitHub issueSummary
tModLoader could reduce loading times and raise FPS a lot by supporting texture atlases for Terraria. The rendering pipeline and shaders need to be rewritten and some algorithm for creating this atlas needs to be included.
Hammering glGenTextures
Terraria currently seems to upload every single mod texture to the GPU separately. This makes loading times extremely slow for tModLoader and has a rather big impact on performance.
To put things into perspective, I recorded all the OpenGL API calls with apitrace
.
In the first ~50 seconds of loading some mods (e.g. Thorium Mod), Terraria and tModLoader generated over 9000 OpenGL texture objects (Not even a joke).
(GL calls recorded with apitrace trace -a gl ./Terraria.bin.osx
, calls counted with cat trace | grep glGenTextures | wc -l
)
GPUs simply aren’t optimized for that kind of load. But today they are so powerful these days that this waste of resources isn’t even noticeable on most PCs. Smaller laptops however should theoretically be running Terraria without problems, but are failing because of that exact reason.
According to mysticreddit, this is a Terraria vanilla problem and tModLoader just makes it worse by introducing even more items. Can someone confirm that Terraria isn’t using some caching or an atlas?
I believe though, that tModLoader has the power to fix this by using texture atlases and rewriting the Terraria rendering pipeline.
Texture atlases
Texture atlases could be used to group all these small textures into a big file. The shaders for all items, blocks etc. need to be rewritten and take the position (U,V) of the item in the atlas as arguments.
There are two ways to do this:
Compile-time batching
tModLoader creates an atlas for the Terraria items on installation and every mod introduces a new atlas with its items. When Terraria is run, only the atlases are loaded.
PRO | CON |
---|---|
Fixes a second issue: only 3-4 huge PNGs need to be loaded from disk instead of thousands of little textures (Even faster loading times) | Difficult to implement because an atlas needs to be generated for the vanilla files |
Existing texture packing algorithms can be easily used | Novice modders will face a steeper learning curve because of the more complicated mod creating process |
Run-time batching
When Terraria is started, read every texture PNG (like it is done now) and create a single huge atlas dynamically
PRO | CON |
---|---|
No files need to be changed and nothing needs to be generated on installation | Creating a texture atlas is slow and CPU intensive, there is a possibility that loading times are increased if implemented incorrectly (Why? Creating a 2D atlas with different texture sizes is an NP-hard problem) |
Reading thousands of little PNG files from disk is also slow. Run-time batching doesn’t address that issue. |
Both are rather hard to implement, Run-time batching is easier while compile-time is probably a lot faster and the way to go.
So maintainers of this mod, please consider this, Terraria texture code is so ugly and you have the power to fix it 😃
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Closing this as mostly infeasible in a modded environment. There are too many edge cases to consider.
Nice work terorie