question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: Support for texture atlases?

See original GitHub issue

Summary

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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Chicken-Bonescommented, Nov 30, 2018

Closing this as mostly infeasible in a modded environment. There are too many edge cases to consider.

1reaction
glehucommented, Jan 1, 2018

Nice work terorie

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Request] Texture Atlas support for UMG
Hi, Please, allow using texture atlas for UI textures ! ... (you need an override path, the Atlas file suggestion sounds good for...
Read more >
shader supporting tiling texture atlases
hi there, at the moment i am working on a terrain decal shader which i would like support tiling texture atlases.
Read more >
Howdo I create differently sized texture atlases for ...
I am beginning game development and using texture atlases. I've created textures based on the resolution 1920x1080, so I created a 1024x1024 ...
Read more >
Texture atlases
Hi, first time poster. I'm scoping out alternatives to Construct now that they're going full on subscription and first impressions of GMS are...
Read more >
Seamless Texture Atlases
Texture atlas parameterization provides an effective way to map a variety of color and data attributes from 2D tex- ture domains onto polygonal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found