Loading thousands of tiny textures

A bit of context: I am working on lightmap generation for a custom run-time level editor, that is supposed to update in real time (in the background obviosly, with reasonable delay, but I’d like it to be more or less responsive) and currently facing a problem of uv packing taking too long.

So I was wondering, would it be ok to just store lightmap for every object as a single texture without packing them together in my “editor”? They would be combined eventually during a compilation step but before that, should having, say 10,000 boxes (not visible all at once) with unique light textures (64x64 - 128x128 pixels each) be a concern?

I understand that it’s better to test things like this instead of asking on forums, so that’s what I did first: I spawned 10,000 cubes, each with a unique run-time generated 64x64 texture of a random color, and put them in a long line so frustrum culling doesn’t let me render them all at once. Doesn’t seem to impact fps at all, the whole spawning operation takes only 3 seconds.
I assume this means I’m all set, but GPU stuff is not exactly the area I would consider myself fluent in, so I’m not sure if I’m testing the right things. Can there be any problems on different hardwire, should I worry about how GPU memory handles this in the long run, or I am just stressing too much about this?

If you pack these into a single virtual texture at runtime and update the uvs for the modules you can see you should be fine.

Of course it’ll depend on the hardware, etc. So ymmv.

1 Like

Was gonna say the same as brownboot67. I’m gonna add that if you use spawning, make sure you don’t use material instances. Because that would mean different SetPass/DrawCalls for each object.
Also if you want the same material but with different property values per instance , take a look at MaterialPropertyBlocks.

Yes, I am aware of property blocks, I use them to assign unique lightmap textures for each object instead of instancing the material, which is probably the reason why it didn’t break so far and works like a charm. But if it introduces any trouble in the future, I guess I could always start packing the textures right away, just very slowly and with lowest priority possible.

It shouldn’t…MPBs along with a texture atlas and UVs per instance should give you great perf. Also as I understand it, you don’t alter the textures themselves so when loading the textures,make sure to mark them no longer readable so they’re only residents of gpu mem. That removes the overhead of keeping a CPU side copy.