I’m writing a program where I’m computing 3D volumetric data and then saving it. This data is floating point and being represented in memory as FORMAT_RF and FORMAT_RGBAF images. I’d like to be able to save and reload these images, preferably with compression. I was hoping I could use the EXR file format for this, but Godot does not let you load EXR from PackedByteArray (since it would add 200kB to the binary).
I was wondering if there was some way to compress images and then save and load the compressed data? Godot does seem to have support for this, but it does not seem to be exposed to the GDScript API. If I have a 2D image with RGBAF pixel data, is there a way to compress it to a VRAM Compressed format, get the buffer, save it to a file, and then load the buffer and recreate the image later?
I’ve tried using compress(FileAccess.COMPRESSION_ZSTD) on the PackedByteArray, but the compression is not very much - less than 10%. I need something that is effective a compressing 32bit floating point values from image data.
Well these are the only built-in compression-methods, so AFAIK you would have to implement your own compression.
I have a bit-writer and bit-reader script to more easily write bits to a packebytearray if you need that
I’ve been looking into TIFF compression, which is a pretty nifty algorithm for compressing this kind of data. The problem is that GDScript is pretty much unusable for this kind of task because it is so slow at number crunching. I’d have to do it with either GDExtension or C#, both of which have portability issues.
GDextension in C++ using the existing framework to have your use case supported in GDScript.
If you want compressed data in GPU local RAM, you can’t use arbitrary codecs, you have to go through formats supported by the underlying APIs.
Not sure what Godot uses for hardware supported compression so it works across the various rendering backends, the docs are a bit sparse.