(suggestion) color palettes and palette swapping?

Started by Shadowblitz16, June 14, 2017, 05:12:09 AM

Previous topic - Next topic
can the devs add in color palettes and color swapping in solarus? it would be very nice to reduce the amount of sprites someone needs in there game


Yes. In future versions it will be possible to access the pixels with functions get/set_pixel for drawables (surfaces and sprites), and with that you can easily code your own functions to modify the colors and do many other cool stuff. I guess that you will have to wait another year, more or less, until Christopho codes that.

What do you mean by color palettes?
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."


June 14, 2017, 08:14:42 PM #4 Last Edit: January 15, 2019, 02:26:14 AM by froggy77
Thanks to the team, it will be a tremendous improvement.
I believe he's talking about a colorful array of donuts, ... a palette pallet of donuts  ;D


Quote from: Neovyse on June 14, 2017, 07:20:06 PM
I believe he's talking about palette swapping: http://wargroove.com/palette-swapping/

Ok, but for that I think that making new variants for the sprites is probably better (not a Solarus issue), unless there is too much customization and the number of sprites is huge... in that case it should better be done with code and the get/set_pixel functions.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

I mean like built in editor/engine support for it not just set/get pixel functions for script
@Diarandor palette swapping is actually better then creating a bunch of duped sprites as it does the same thing with less work and takes less memory and space.

April 12, 2018, 02:58:50 AM #7 Last Edit: April 13, 2018, 07:39:43 AM by Satoh
if drawables could be accessed as arrays of bytes in a quick and efficient manner, it wouldn't be difficult to code a seek and replace function.

Better still if images could be defined from the start as palettized rather than full color, they could be altered by simply changing 32 bytes or so.

Really the only requirement for supporting palette swapping is allowing access to the memory that defines the image, which is something most engines don't do, presumably for either lack of necessity or lack of desire to deal with user-created issues.

I feel like a 2D pixellated engine would benefit a lot from handling this kind of interaction, but I also realize as a coder, how much hassle it could create.

If solarus ever picks up support for compiled shaders, it wouldn't be difficult to use a fairly lightweight shader to handle palette swapping...
however, shaders are their own box of problems to implement.

It all comes down to time and labor really.

Edit: one of the massive advantages palettes have over duplicated sprites, that hasn't been mentioned, is the ability to alter the colors of the sprite while it is in the middle of an animation, without losing track of frames or having to reload any sprites.
This is how the link-is-damaged flashing was achieved in in all of the 2D zeldas (and most 2D games from the 16 and 8 bit eras in fact).
This is how link can be flashing invincible, while still walking around. His palette would be replaced by red yellow and black or some similar series of colors.
This is also how a lot of water and fire animation was achieved. A single static image of a waterfall would exist in the game, and it would have a palette that rotated from dark to light.

This would be easy to achieve in a more modern way with per-object shaders. I've already written a very simple shader to do it, but I don't know how or if it is possible to apply it to anything in the engine as of now. The entity page is listed as mentioning shaders in the 1.6.0 documents' search, but it does not contain any references to shaders.
Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.