decentraland / unity-explorer

Apache License 2.0
8 stars 11 forks source link

Compress and Resize Textures #38

Open mikhail-dcl opened 1 year ago

mikhail-dcl commented 1 year ago

Output should be a texture in a GPU-friendly format (that can be uploaded to GPU without additional conversions, e.g. by SetRawData)

It's possible to retrieve textures from an external source; in this case it can't be preprocessed

Unity does not expose API for decoding textures on a worker thread. Unity support recommended using an external library, e.g. FreeImage

I tried to integrate it in the past without any success, and it was not straightforward at all. I found a topic where a guy tried to do the same without success either.

Just like for Meshes we should introduce different levels of LODs, LODs can be used as mip-maps

mikhail-dcl commented 1 year ago

I have a plan in my head regarding textures: Integrate a library for decoding (FreeImage) Integrate a library for runtime compression (similar to https://docs.unity3d.com/ScriptReference/Texture2D.Compress.html) that can run on a worker thread (I'm talking to Unity to find one) For textures web requests: use a preallocated buffer, just like we discussed before On a background thread decode and compress Take a texture from the pool (in case it is similarly sized we can set data to the internal array directly, otherwise reload the internal array) This technique can be applied to both single textures and gifs

mikhail-dcl commented 1 year ago

Early research showed the following conclusions:

pravusjif commented 1 year ago

Kudos to you, based on your notes your approach looks promising!

You probably already saw this but just in case it's useful for you in any way, FYI for the WebGL client, the kernel processes GIFs in a webworker/thread, stores the texture and sends a pointer to the texture to unity and in unity the image is loaded from that pointer.