Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How would you make custom-drawn 2D animations/effects and play many of them at the same time?

Discussion in '2D' started by ThisIsDangerous, Sep 30, 2020.

  1. ThisIsDangerous

    ThisIsDangerous

    Joined:
    Dec 3, 2018
    Posts:
    28
    Hi.

    We've got a large 2D MMORPG and we need to be able to make and play many different kinds of effects/animations. Because of their high artistry they seemingly cannot be done using built-in Unity techniques like Animator or Particle Systems. Also they have to reside remotely and be downloaded and played on-demand.

    Currently our artists/animators make them anyhow they like and in any program they like and export them into .webm VP8 which is played in game using VideoPlayer component.

    Unfortunately, VideoPlayer doesn't work well and stably when is used to play many videos simultaneously (like 64 animated item icons in an 8x8 backpack). Also it tends to behave somewhat inconsistently across different platforms (WebGL, desktop, mobiles, Unity Editor). It randomly hangs mobile application for some reason; draws grey rectangle for a moment on WebGL at start of play; ignores transparency here and there and makes it just black; makes coroutines stop working in Unity Editor until it is restarted, and even prevents doing that, hanging the Editor on quit attempt until it is forcefully stopped from the task manager; etc.

    We are tired of battling all these VideoPlayer peculiarities and are looking forward to find a more efficient way to make and play effects and animations.

    The one way I see it is to convert videos into individual images, one for each frame, pack them into atlas and play them. But these imagesets tend to be very large in byte size, much larger than compressed videos.

    But besides that I'm out of ideas, I'm all outta gum.
    So the question is, how would you do it?

    Will appreciate any ideas, thanks.
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    297
    a video cannot have smaller size than the sum of its frames ( logically )

    if your compressed video is smaller than each frame separatelly that means you just aren't compressing the frames when you separate them into images. ( compress the images to fix this )

    there's no high artistry that can be used in a video but not in a unity animation made of images ( because a video is a combination of images, just like a unity animation)
     
    ThisIsDangerous likes this.
  3. ThisIsDangerous

    ThisIsDangerous

    Joined:
    Dec 3, 2018
    Posts:
    28
    Actually, video algorithms (at least some of them, not sure about VP8) store not the frames but differences between them (from the last keyframe, to be technically correct). So, ideally, if there is no motion, thus no difference between frames, the video containing such a still movie would be about the same size as just one frame, the first keyframe that is, no matter how long the video is (well, not exactly, but close), while several individual frames, be them compressed or not, have a size each, regardless of how different they are.

    But you are right about the fact that I didn't compress individual images. I thought I am stuck to using PNGs because I need to have alpha in the effects, but I somehow didn't think (probably drank not enough coffee) about prepacking them into an atlas with DXT/ETC/PVR+GZip compression. So I have made a few experiments and got workable results. So far I am getting atlasses about twice a size compared to the videos they are made from. While it sounds large, it is not so large as twenty times bigger size I get using PNGs. Still it's not the original size. I'm fiddling with compression settings now, probably will get close to the original size.

    Yeah, I meant they can't make these "images" in Unity.
     
  4. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    297
    are you struggling because they take too much disk space or too much ram?

    if its ram you can load and unload the images from disk as they are needed, and if it is disk space maybe you can store the images in another format ( pixel coordinates + color )

    In my project i convert 317mb of .pngs into a custom file that is only 38mb ( omits all the transparent pixels)
     
  5. ThisIsDangerous

    ThisIsDangerous

    Joined:
    Dec 3, 2018
    Posts:
    28
    My concern is the time it takes to download images from server. Our clients (well, players) already complain about long loading times of everything. Another noticeable increase would be undesirable.
    You mean in compressed texture formats like DXT/ETC/PVRTC? That's what I am trying to achieve right now. I will try to tweak compression/quality ratio tomorrow and see what comes out. I shall consider the topic solved shall the size be the same or close to the original video size. If you mean custom format, well, I don't think I can do anything more efficient than existing compression formats. Anyway, I guess using any other format would mean "recoding" it at run-time into aforementioned GPU friendly DXT/ETC/PVRTC, and that's quite an undertaking. Also it would take precious computing resources to do it at run-time.
     
  6. ThisIsDangerous

    ThisIsDangerous

    Joined:
    Dec 3, 2018
    Posts:
    28
    Well, long story short, I have converted all 0.5GB of videos into DXT5 and ETC2 texture atlases 5.8GB each in .pvr containers, supplemented with .xml atlas descriptors. Both these 'sets' become 0.9GB each when GZipped. Acceptable quality (well, DXT is a little worse than ETC2 but still acceptable). Size is considerably larger even when GZipped, that's quite unfortunate, but I don't think there's anything that could be done here since DXT5 and ETC2 are constant rate formats. Guess that's what we are to live with.
     
unityunity