delta-client icon indicating copy to clipboard operation
delta-client copied to clipboard

Improve texture loading speed

Open stackotter opened this issue 4 years ago • 1 comments

The slowest resource pack loading steps are loading textures and loading block models. Texture loading is likely slow because of the processing pass I apply to transparent textures to improve the way their mipmaps look. Most fully transparent pixels are set to black, so as the texture gets down scaled the visible parts get darker because their colours blend with that of the transparent pixels (black). The processing pass I made just 'drags' the colour from the opaque pixels to the transparent pixels. But it does so extremely inefficiently. The easy solution would be to just save the 'fixed' textures to the resource pack caching directory and then load them from there on subsequent launches. The other options are writing a custom mipmapper (probably not too difficult), or optimising the 'fixing' algorithm.

Custom mipmapper

If you were to create a custom mipmapper to solve this issue, that would be the best solution. Here's some information about mipmaps. The mipmapper would be just like a normal one, except if a pixel is fully transparent and is getting blended with a coloured pixel, only the colour of the coloured pixel is used.

Creating a custom mipmapper would also fix an issue that is currently happening with animated textures. Whenever one texture changes, the mipmaps are regenerated for every single texture because Metal doesn't expose an API that allows one to selectively create mipmaps for slices of a texture.

The alternative solutions

Although the custom mipmapper is technically the best solution, any of the solutions I described are completely acceptable :) the custom mipmapper just hits multiple birds with one stone. And if you have another solution in mind, I'm open to discussion.

stackotter avatar Oct 07 '21 11:10 stackotter

I think I may have over complicated the texture fixing, it seems like vanilla minecraft just finds the average colour of all opaque pixels in the texture and then sets that as the rgb values for all transparent pixels in the texture. And that seems to work ok even though i would've thought it wouldn't work as well for things such as flowers that have two or more main colours. It's probably best just to do it this way.

stackotter avatar Oct 18 '21 11:10 stackotter

This was solved when I implemented texture palette caching. It now only happens once when loading a new resource pack, which is not a major performance concern at the moment, but may be in the future.

stackotter avatar Feb 23 '23 05:02 stackotter