Change Palettes(For Pixel Arts)

1525420--87692--$mario-and-luyi.png
Change image’s color is a useful trick in game with pixel arts.

Usually, change color means create a new image with different palette chunk,
it cost more memory and bring a peak of cpu usage(when creating).
The more palettes, the more images need to be created;

Fortunately, use SHADER may avoid those troubles.

This is the effect : change “Offset” value to use different palette.

This is a very simple trick:
First:Seperate palette form image.
Forexample:Only 4 colors exist in “mario”, the new palette image is 4*4 and queue the colors in the last line.
Red in “mario” should change the value to (0.5,0,0), it mean the point with UV(0.5,0,0)in new palette image is red.
1525420--87694--$mario-and-palette.png
Second:Show color in new palette by UV in the upper image;
Third:Add more palettes in new palette image, and change “offset” to use them.
1525420--87695--$offset.png

Download demo in last line.

1525420–87753–$demo.rar (112 KB)

Hello! You shouldn’t use any filtering for coordinates this will lead to artifacts. Try use tex2Dlod instead tex2D.
Also try look this.

Oh,that’s great.
Set the pics “no mipmap” and “filter=point” also works.