godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.23k stars 21.22k forks source link

Add the ability to import and create palette indexed sprites from GIFs #18269

Closed Two-Tone closed 4 years ago

Two-Tone commented 6 years ago

I recently found out that some engines, like MUGEN, have the ability to import GIFs and automatically convert them into animated sprites. This makes creating and adding 2D animations into the engine incredibly easy and fast.

Mugen also expands on this by allowing the user to edit the indexed palette of sprites to very quickly create palette swapped sprites. Example

You could recolor a sprite with a shader, but it doesn't allow for the same level of fine grained control.

Zylann commented 6 years ago

Just a note, with shader you not only have fine grained control (changing all colors if you want and dynamically), you also have non-destructive control, as in, no need to have separate sprites per palette (where a palette is just a texture listing colors in its pixels in the end). It just needs a bit more work upfront, though.

So, while a shader allows all this, that request mostly sounds like adding tools to do the same thing more easily, as well as supporting GIF. Also, if Godot does allow indexed colors in import, it could also support PNGs which have indexed colors (so that Aseprite users don't have to use GIF just because it has palette)

Two-Tone commented 6 years ago

I've not looked into shaders too deeply, but I was under the impression that a shader wouldn't be able to change just one color at a time, instead changing the whole palette.

Zylann commented 6 years ago

@Two-Tone it's certainly possible to change a single (or more) specific colors in a shader, either by doing a simple if, threshold, or looking up a palette texture (get pixel color of the sprite, use it as X coordinate in the palette texture, and output that instead. For a palette swap, put other palettes further down the Y coordinate). As I said, it's a bit harder to set this up though. Maybe the ability to import sprites as paletted textures could complement this.

blurymind commented 6 years ago

It would certainly be very beneficial to have editor support to swap palettes of sprites that support it

It is a very easy and useful way to create variation in a game, without bloating it with more resources

I think Opentoonz can export images with indexed colors. One of the layer types that it uses (Toonz Raster) supports indexed colors and it's brilliant! Cosmigo pro motion can also do it.

Old games have heavily used the technology to a point where they even animate the color palette of static image files to fake animation on huge background images https://en.wikipedia.org/wiki/Color_cycling

It can be done in html5 too http://www.effectgames.com/effect/article-Old_School_Color_Cycling_with_HTML5.html http://www.effectgames.com/demos/canvascycle/?sound=0

A lot of games use it to create a day and night version of the same levels - without having to make any new sprites and having great artistic control over the result.

According to wikipedia PNG files support 8bit indexed color palette https://en.wikipedia.org/wiki/Indexed_color#Image_file_formats_supporting_indexed_color

The question is wether we can have godot import that data and give the draw API/editor the capability to do some interesting things with it (such as swapping the palette) without too many lines of code (or writing a shader from scratch - which is still a workaround,limited and has been done already)

I wouldnt personally use gif as the filetype to do that myself. Png is better imo

Similar requests here: https://github.com/godotengine/godot/issues/12670

Two-Tone commented 6 years ago

@blurymind GIFs and PNGs should both be supported as while PNG is compressed, most people export their actual animations as GIFs since APNG is not widely supported.

jjhaggar commented 6 years ago

The use of indexed color images and pallette swapping without using shaders would make my life so much more easier. I really do hope this is done sometime in the future :)

In the meantime, we can use this for palette swapping https://godotengine.org/asset-library/asset/239

golddotasksquestions commented 5 years ago

I want to state that the ability to import GIFs into Animated Sprite node or AnimationPlayer would speed up any pixelart workflow and most other 2D workflows a thousandfold. And therefore would make the engine a lot more suitable for fast prototyping. Right now I have to do set timing any keys twice: Once in the Animation tool I use and then again in the Godot Editor.

Color cycling would be also a very very appreciated feature, benefitting everyone doing pixelart, which is a large portion of Godot users. Shaders are really complicated and hard to get into especially for beginners. What @akien-mga mentioned here sounds like a great proposal!

Xrayez commented 5 years ago

I think GIF importing into SpriteFrames is totally doable, yet there's no even basic GIF image loader in Godot yet. The palette part is something I'm more interested in, see #28013.

If GIF importing will be a thing, there would be one issue with extracting palette from imported frames, as they will lose palette information in custom stex format used internally. It would need to store palette as well, meaning potentially breaking existing format...

Each palette entry could be modified, and reimported.

Two-Tone commented 4 years ago

Ported this over to godotengine/godot-proposals#475, closing here.