Legacy GM how to replace entire color palettes?[solved]

trying to understand shaders or color replacement in the least. My entire game is composed of only 8 shades, but I want to be able to change the hue of the shades in different areas. Kinda like how you can change the palette of gameboy games on new systems.
So I can make this

into this

I saw this this shader could be used

http://gmc.yoyogames.com/index.php?showtopic=589348

but the example is only a demonstration of the shader. I'm at a total loss on out how to use this in an actual game.
 
1. Since you're using monochrome images there's a solution without using shaders:
draw_sprite_ext( sprite, subimg, x, y, xscale, yscale, rot, colour, alpha );
the argument "color" will set the hue of your image. You can either set colors
  • with built in constants like c_red
  • or in a hexadecimal $BBGGRR. $9999FF would be a light red
  • or by using the function make_colour_rgb(red, green, blue);
2. If you want to use shaders, watch and read tutorials on those.
Basically you need to create a shader in the ressource tree and write a fragement shader (vertex shader wont be necessary in your case).
In draw event you need to set the the shader, draw the sprite and reset the shader. To optimze performance you should set and reset the shader only once. So make sure you set it in the beginning and reset it in the end only.
Most shaders also need to receive values so you need to setup those as well - the tutorials should explain what and how.

Xor has some great tutorials here (start at the bottom and work to the top, then there's more when you click on intermediate tutorials):
http://xorshaders.weebly.com/tutorials/category/beginner

3. There's a very intersting asset on the marketplace that might suit you as well and seems to be easy to implement. But I guess if you want to use monochrome sprites only this would be unecessary:
https://marketplace.yoyogames.com/assets/1661/retro-palette-swapper
I haven't bought it yet, but bookmarked it in case I ever want some palette swapping done.


So to keep things simple, just try option 1 and if that's not good enough, check the rest :)
 
Last edited:

TheouAegis

Member
His example is a bit lackluster. I think he wanted more akin to GBC or SGB swaps, which are full on palette swaps, not hue shifts.
 
Just tested that and TheouAegis is right of course. Colorizing with a new hue won't give the desired result because GMS darkens the image (not like image manipulation programs colorize).

Leaves you with option 2 and 3.
 


It seems this is usable, though not exactly what need. I'm guessing. I would require shaders. if I wanted to make each color completely different. not following a palette correct? Like making light grey into green and black into blue?
 
N

Never Mind

Guest
Just figure out exactly what you want to happen.
For example you could decide on a default color palette only using a few chosen colors. Then create a shader and use it to draw the application surface.

You could pass in a float as a uniform to represent which palette you want to use.
Within the fragment shader you can look at the color each pixel is about to output, then draw a different color depending on the current palette you choose.

-EDIT-
Here's another idea to make it easier to test around with different palettes:
Use a pallet sprite that's a certain number of pixels wide or tall. Each sub-image could represent a swap of the default pallet (the first sub-image could be the default).
Then you could use sprite_get_texture(). to pass sub-images into the shader as samplers.

Depending on the chosen pallet the shader could use a different sub-image to look up the new color at the same coordinates on the original color on the default sampler.

Then you could use the sprite editor to sit and test different palettes out without hard-coding any in.
Although, you may find it easiest to hard-code the first palette.
These ideas and tips are not perfect but maybe they'll give you some ideas.
 
Last edited by a moderator:
Just thought of another option: blend modes

Keep using the greyscale assets, and undo that draw_sprite_ext solution I offered earlier.

Then create an object with no sprite and only this code in the draw gui event, place it anywhere in the room. This should lead to a result much more like what you aimed for.

Code:
draw_set_blend_mode(bm_max);
draw_set_color($000099);
draw_rectangle(0, 0, display_get_gui_width(), display_get_gui_height(), false);
draw_set_color(c_white);
draw_set_blend_mode(bm_normal);
With draw_set_color you can change the hue.
As mentioned the format is not RGB but BGR so $000099 is no green, no blue and quite a bit red.
Want a darker red? Lower the last two digits.
Want a brighter red? Increase the last two digits (hexadecimal so after 9 there's a, b, c, d, e, f up to ff.
Want green instead? Try $009900.

The color can also be stored in a variable like:
color_cyan_overlay = $666600;

Of course shaders are nice and eventually you should look into them. But if you want to avoid shaders even if only for now, give this solution a try.
 
Last edited:
Thank you so much that works a lot better!

I'm actually using this as practice for color replacement. I'll start looking at the shader tutorial as well

 
N

Never Mind

Guest
Sorry for the over-complication. I didn't realize the "palette" you were trying to replace with is only one color. ;)

Alright you caught me, I suck at spelling palette. It seems I lucked out and maybe nobody read my post.
 
Top