Open Jazzneo opened 5 years ago
I really like this. Animated gifs are awesome, maybe even a way for Neos to convert an animated gif to an mp4 and use the video player for it?
This would be very cool, but it requires a significant work. I might need to a day or two just on this feature (or more if there are more issues), so that makes it difficult to prioritize it over other things.
One problem is that GIF is a bit tricky, because it can be treated both as static texture or a video, but you don't know without actually decoding it (which is usually too late, because the decoding is determined by the type of the asset) so it would require some new pre-decode mechanism.
Another issue is that it requires writing a custom playback handler, which synchronizes decoding of individual frames at the right times and uploading to the GPU, with some decoder that can extract the frames (the FreeImage library we're using can do the frame extracting, but the rest needs to be written from scratch). There are performance implications with that as well.
I'd say that converting to MP4 or another video format is better solution for now, or using a sprite atlas and animating the UV's for short animations.
For what it's worth, you can convert the gif you want to import to a sprite sheet / atlas and then import that as a texture and slap UVAtlasAnimator and TimeIntDriver components on it to play the animation.
Is there a way to implement automatically converting GIFs to spritesheets on import and setting UVAtlasAnimator and such?
There is, but I don't think it's a good idea. Some GIFs can have lots of frames, meaning it would result in a really huge spritesheet (you'd probably need multiple) and result in lots of VRAM usage. It effort is put forward to this, it's better for the actual playback than that.
GIFs also have multiple different modes, e.g. looping modes or looping from certain frame, as well as ways where previous frame is overdrawn and lots of other crazy stuff that's not representable with just UVAtlasAnimator either.
Ah, that's fair. Also I remember that every frame could have different duration, so playback with constant speed wouldn't cover every case.
Yea, gifs have surprisingly sophisticated animation options for being a decades old format.
The glitchy text I've got for the davali changed mask uses a 4k Atlas with 8x8 (64) frames for each animation, so often you can get away with just putting all the frames into one big texture. Most memes or such are less than a few seconds and low resolution, so are fairly easily convertible manually.
As a heads up, there is now a workaround for this issue: https://github.com/kawaiiamber/GifImporter
Thought I might post some relevant information regarding all the tags of gif from System.Drawing.Imaging
0x5101
is the PropertyTagLoopCount
. From what I understand, it could be no loop, loop once, twice, three times, or forever. I have it loop forever regardless of this value.
Just thought I'd mention that the GifImporter mod has moved to https://git.astralchan.xyz/astral/GifImporter if anyone was still wondering about this issue / mod.
Was wonder if possible add gif image support into Neos. nirvana want that Feature so upload gif in neos