How to write a CGA shader that limit the palette to 4 colors and match the original colors with those (cyan, magenta, black, white)??
I'm working on Game Maker Studio Professional, that actually allows the using of shaders writing vertex and fragment code
I already asked this question also in the yoyogames community and in the openGl forum
someone answered me with this :
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
const mat3 rgb_to_wcm = mat3(1,-1, 0, 1, 0,-1, -1, 1, 1);
void main()
{
vec4 rgba = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord);
vec3 wcm = rgb_to_wcm * rgba.rgb;
vec3 rgb = dot(wcm,vec3(1,1,1)) < 0.5
? vec3(0,0,0)
: wcm.x > wcm.y
? (wcm.x > wcm.z ? vec3(1,1,1) : vec3(1,0,1))
: (wcm.y > wcm.z ? vec3(0,1,1) : vec3(1,0,1));
gl_FragColor = vec4(rgb, rgba.a);
}
it works, but not return a cga palette, it return a black and white (not grayscale)
how can I do?
Thanks a lot I did in a different way, maybe more simple
https://www.shadertoy.com/view/MdlyDH
here I also included the way to convert this shadertoy shader to a game maker studio shader, because in game maker studio there isn't the uniform time and resolution to make a time editing and the vec2 uv
I also included the commented right palettes for all the cga color palettes and a bonus palette 0 that it is a gameboy palette
I also included the conversion from rgb 255 value to the float for who could not be able to convert
the only problem here is that it is not able to invert colors or change position of the colors in the palette, it takes the original source and output the 4 colors, this is the only gap.