Bauxitedev / bitmapflow

A tool to generate inbetweens for animated sprites, written in godot-rust
437 stars 20 forks source link
game-dev game-development godot-engine interpolation rust rust-lang sprite-animation tool

Bitmapflow

ko-fi

Bitmapflow is a tool to help you generate inbetweens for animated sprites. In other words, it makes your animations smoother. It uses optical flow to try to guess how the pixels move between frames, and blends them accordingly. The results are far from perfect, and probably require some editing by hand afterwards, but sometimes it can produce decent results.

It supports loading and saving animated gifs, spritesheets and individual frames.

Example:

Example

Usage

You can download the executables here. (Windows and Linux only for now). On Windows, you'll need to install the Visual Studio Redistributable first (unless you already have Visual Studio 2015 or newer installed). On Linux, you'll need to install OpenCV 4.2, see the releases page for more details. Other than that, it should work out of the box.

A video tutorial on how to use the program can be found here.

A short summary:

  1. Drag and drop your image into the program. It can be an animated gif, a spritesheet, or individual frames. If you don't have any sprites laying around you can find some in the examples folder in this repository.
  2. Tweak the parameters.
  3. Open the File menu to export the results as an animated gif, a spritesheet, or individual frames.

If you use big sprites with lots of frames, you may need to wait a while after tweaking the parameters for the processing to complete, since calculating optical flow can be quite CPU intensive.

A short explanation of the parameters follows.

Basic Parameters

Advanced Parameters

I could explain all the advanced parameters in detail, but since they describe internal optical flow algorithm parameters, they require some background knowledge about the algorithm before they start to make sense. You can check the official documentation for SimpleFlow or the official documentation for DenseRLOF for more details.

You'll need to experiment a lot to find parameters that work well, although the default parameters seem to work decently for a lot of sprites. See my video tutorial on the subject.

Tips

The algorithm works best for sprites that only have movement in the two-dimensional plane. That means, things only move horizontally, vertically, or diagonally, not towards or away from the viewer.

Additionally, the algorithm assumes the brightness of pixels doesn't change between frames. That means, things like explosions, particle effects and blinking lights won't work that well, because they generally start bright and become dimmer over time.

Finally, if you feed pixel art into the program, make sure the pixel art isn't upscaled. It should be at its original resolution.

Compiling from source

If you want to dig through the source code and compile Bitmapflow yourself, you'll need to jump through some hoops. The program is written in Godot using godot-rust, so the project consists of two parts:

  1. The Godot project, found in the godot folder.
  2. The rust crate, found in the rust folder.

To get it to work, you'll need to install the following things on your system first:

I'm going to assume you're on Windows, but technically speaking this should work on other platforms as well, but the details and filenames will be different.

Getting it to work:

  1. Go to the rust folder and run cargo build --release. (Note: the crate requires that it is inside of a Git repostory, otherwise it will fail to build. This may not be the case if you downloaded the source code from the Releases page. In that case, run git init to create a .git folder as a workaround)
  2. After a while this should produce a DLL file called bitmapflow_rust.dll in the rust/target/release folder (On Linux this file will be called libbitmapflow_rust.so). Copy this file to the godot folder.
  3. Now open Godot and run the project in the godot folder.

That's all.

FAQ

On Windows, the program crashes after the splash screen, or I get an error about vcruntime140.dll not being found. What to do?

On Windows, when exporting I get an error similar to "Failed to save spritesheet as [name]; Access is denied (os error 5)."

I get some weird OpenCV error about sizes or something after loading my sprite?

License

The code is licensed under MIT. The included example sprites (in the examples folder) are licensed as follows: