How to draw sprites using a palette in GM Studio:
Notes:
"uniform sampler2D Palette" refer to a sampler texture that is an externally loaded sprites since GM will auto batch sprites into a "Texture Page". When that happens, GM will change the UV coords to something unexpected. But, I need to know the exact UV coords of the palette image, so instead I externally load them to reserve the original UV coords.
The drawn sprite (gm_BaseTexture) is an indexed sprite, where each pixel's color.r (indexPixel.x) refers to the x coordinate of the correct color within the palette (domain [0,255]) and color.g (indexPixel.y) refers to the y coordinate of the correct color within the palette (domain [0,255]).
___
I'm just typing this up for other people and for my own reference. If you ever move to GM Studio or any other graphics library (OpenGL, Direct X), you can still refer to the above to draw sprites with arbitrary palettes.
Gors Edit: parts of the code were being rendered as smilies. I disabled smilies in this post.