I am sure you have seen nice full-screen pixel art backgrounds with slight animations as GIFs. Where maybe some leaves are falling, a ventilator is running etc (example here: Reddit - Dive into anything)
I was wondering how to use those in Unity for example for adventure games. Afaik we can’t use GIFs in Unity so I would need to have an mp4 for that or extract the animated parts and animate them in Unity.
Are there other possibilities? I would like to tell an artist what kind of background and small animation I need and then just use it without any additional technical work.
Thanks, sounds very obvious
Somehow it is a waste of space if the animation has 100 frames and only a few pixels are animated. But what can you do, thanks again!
well if you want to be more optimal you can carve out the area of the frames that is animated and only animate that part, and the rest of the image is static
but this will only save you a few KB maybe some 1 or 2MB of space
Yes, you are correct that Unity does not support GIFs natively, but there are a few ways you can achieve the effect you are looking for. One way is to create a sprite sheet, which is a single image file that contains all the frames of your animation arranged in a grid. You can then import the sprite sheet into Unity and use its animation tools to create an animated sprite. This approach requires some technical work, as you will need to create the sprite sheet and configure the animation settings in Unity.
The GIF format is pretty good about stuff like this, saving only the data that changes from frame to frame essentially, and doing a decent job of compressing it, at least RLE, perhaps more than RLE.
But if you plonk 50 frames from an expanded GIF into Unity, Unity is going to put 50 copies of your entire background in and things will quickly get honkin-huge.
There are asset store things that might make it better, such as:
Disclaimer: I know NOTHING about the two packages above that Google suggested for me.
Otherwise I think you’d have to write some code to delta the frames yourself and hand-monkey-patch the images on the fly, which might be pretty noodly to write all in all.
I was just extrapolating how people will drop a bunch of small-file-sized yet pixel-large PNG files into a Unity project… then Unity will expand it into its own graphics card type compression and their project will be huge compared to how big it was when they first used their files in an Android Studio or XCode / Swift project.
PNG compression can be pretty decent, generally always better than any of the primary graphics card type compression schemes, and GIF can be even better for only a small number of pixels changing. I just know for a fact that there’s no delta-frame compression out-of-box.
I’m kinda curious what those above packages do but not curious enough to drop $125 and see.
Back in the day we used to write custom tools that diffed GIF files at the pixel levels, then packed them into a zipped-up format that could be easily streamed from disk files / CD-R drives and presented. If I had to guess the LucasArts adventures used stuff like that all the time for custom pixel graphic art compression.
Thanks all, I thought about making diffs for each frame (highly dependent on the content) and put a custom RLE on them, should be very small. But also a bit old-school, which is not a bad thing in itself but I was wondering why Unity has no support for that.
In general test before optimizing, but you should also be able to calculate rough estimates whether something is worth testing. Single second of uncompressed 1920x1080 video at 25fps would take ~192010804*25=200MB. Add a couple of those and you have gigabytes. That’s not really practical.
Unity has support for that it’s called video support. Series of frames is a video. The “GIFs” you see on meme websites are often actually short MP4s(or other video format) without proper playback controls and not real GIF files. Browsers are handling it so well that you don’t notice the difference. For the most part everything GIFs do, video can do better. A good example to this is the reddit page you linked. Original image on imgur is a GIF, but in the preview reddit has converted it to MP4, because that was more convenient for them.
In case of pixelart video should’t prevent you from displaying it niceley. Not sure if unity respects previously set settings when outputting to render texture or overrides them based on video, but there is always an option to override sampling mode in a custom shader. One more thing to watch out is any defects caused by lossy compression, but it should be possible to mitigate those by encoding an upscaled animation instead 1:1 pixel size, preferably taking compression block size into account (likely blocks of 4x4 pixels).
Thank you, I will try it out. It is maybe just in my mind that video is inferior to GIF for that special purpose in regard to file size and compression artifacts and codecs and initialization time. GIFs are just clean and lossless. It is like working with ints instead of float if you know what I mean