Thursday, November 15, 2018

Animation Optimization

Hi guys,
There are actually two things I would like to talk about, but to keep the post from getting too long, I'll just mainly talk about animation for this post.  The following may be a bit technical, but basically I've reached the level of animation I wanted for large frame-by-frame animations.

In my last post about animation, I talked two different ways I use to animate in Conception Maiden.  One by morphing images combined with easing("Figure animation"), and the other being simple frame-by-frame animation created in MMD("MMD animation").

Looking at MMD animation(which you could call simple frame-by-frame animation in the game), there were a number of problems using this in game before recently.  Mainly being the filesize on the harddrive, the amount of memory used per animation, and the time it takes to load it into the game.  These problems were fixed on my last animation post, with the exception of one thing, the time it takes to load in-game.

For example, a 14 frame animation would take about 8 seconds to load in-game before it can be used, and a 28 frame animation would take about 23 seconds to load in-game before it can be used.  This is a lot of time to wait that can really add up when you have more than one animation.

-------------------------------------------------------------------

However, I've discovered how I can get around this, first, instead of each frame of the animation being a single file on the hard drive(14 frames = 14 image files on harddrive), I can have all the frames on a single image file as a strip(14 frames = all inside 1 image file) like below, which greatly reduces the number of files needed to be accessed by the game.


 ---------------------------
At this point, there are two ways I can save this image strip to eliminate the long load times, first is by saving the images as a png file with transparency, loading this will be fast ingame,  however the filesize on the harddrive will be very large(5MB for the single 14 animation, so a 28 frame animation might be like 10MB).  This techinally isn't a problem if I only have a few animation strips, but this can really add up if I want to have alot of them in game, and I would like a compression level closer to MPEG4 video compression.  

The other way I can save the image strip is as a JPEG file which is lower quality but has significantly higher compression.  For game quality I generally like to always avoid using JPEGs but since I would like something closer to video compression of alot of 1080p frames, it seems like it might be useful here.  Um, so anyways, I save the frames as a medium quality JPEG file.  Here's what the 14 frame animation would look like as a JPEG file(click image for fullsize):


Quality may look lower at first, but once in-game with the mask, it will turn out well.  Since I'm using JPEGs, another problem is it doesn't have transparency.  So to add transparency back, I save another image strip(a "mask") showing the transparency as black and the non-transparency as white(note this image filesize is very small, less than 50KB):



 This "mask" is combined with the JPEG image on the fly to create an animation with transparency in game.



So comparing the file sizes for 14 frames, it would be something like this:

Previous method(#1), individual image files for each frame, saved as JPEGs(+transparency mask image for each frame) - total filesize: 1.24MB, in-game load time: 8 seconds

Newer method(#2), single strip image file, saved as a lossess PNG - total filesize: 4.7MB, in-game load time: 4 seconds

New method(#3), single strip image file, saved as a JPEG(+another image for the transparency mask) - total filesize: 556KB, in-game load time: 3.4 seconds

-------------------
As you can see method #3 loads both loads faster and has a smaller filesize(almost 10 times smaller).  Not only that, this method also has an exponentially smaller loading effect the more frames you have, for example: 28 frame PNG image files - loads in 23 seconds, vs 28 frame JPEG strip(+mask) - loads in 6.25 seconds.

These are all very rough estimates, but as you can see the game is much faster at loading images, and most of my 1080p animations probably won't need 28+ frames.

Here's is an example of the 14 frame animation with the new method(#3) above in-game(again, this loads in about 3.4 seconds and is about 556KB on hard-drive, while in memory it is slightly over 200MB):

Note that the gif animation above is much smaller than it is in-game.  
In-game it's a 1080p animation, inside a 720p game window.


This is pretty much the ideal optimization of frame-by-frame animation in-game, as I can show 4 or 5 1080p animations at a time in-game and only use a 1GB of memory(note that I'm trying to always keep the game's memory usage below/at 1GB max).  

So basically, I finally have animation optimization the way I would like it be at in-game now(I don't really think it can get much more optimized than it is now by normal means).  Sorry if this post was too technical.

My next post will probably be about Conception Maiden's side-view battles, weapons and fighting game AIs.

Um, that's all for now,
See you all later.

2 comments:

  1. Really enjoy what you are doing with conception maiden, keep up the awesome work! Can't wait to see whats next. Thank you for spending your time on it.

    ReplyDelete
  2. It's been a while since the poll, so at this point I can only assume you aren't going to be making any more Desires Of Persephone. As a fan of the game, it's disappointing, but I respect your right as a developer to make what you want. Good luck with your future projects.

    ReplyDelete