Recommended Posts

Is it possible to manipulate palettes in Xna?
I want to display many sprites of the same character but changing its colors so it can give some sort of illusion that they are different from each other
something like in old snes games or fighting games

0

Share this post

Link to post

Share on other sites

You create your indexed image and load it in a format such as L8 or A8 for 8-bit(I don't know the format names in XNA). Then inside the program take the palette and create a texture out of it, for 8-bit it would be 256x1 or 1x256. In the pixel shader you use a color component of the source texture as a texture coordinate to lookup the color in the palette texture.

I have an example HLSL shader someplace that I'll try to find, I feel like I've answered this question a million times.

Share this post

Link to post

Share on other sites

You create your indexed image and load it in a format such as L8 or A8 for 8-bit(I don't know the format names in XNA). Then inside the program take the palette and create a texture out of it, for 8-bit it would be 256x1 or 1x256. In the pixel shader you use a color component of the source texture as a texture coordinate to lookup the color in the palette texture.

I have an example HLSL shader someplace that I'll try to find, I feel like I've answered this question a million times.

Edit:*** Source Snippet Removed ***

in directX how would I do that. Would I use the PALETTEENTRY array gotten from one of the CreateTexture... functions, and then what would I do with it?

thanks

0

Share this post

Link to post

Share on other sites

He means make a full-color (32-bit) bitmap where each pixel on the bitmap is one of your palette colors. Kind of like a real life palette. Then you send two textures to the shader-one for the original image, and one for the color palette "lookup table".

The pixel shader will see a color on your source bitmap, then look at the second bitmap to find the replacement color to draw to the screen.

Then, to render the same source bitmap with a different palette, you just need to make another secondary bitmap for each different palette you want to use (i.e. one for the blue player, one for the red player, etc). Then on the C# side you decide which palette texture to use based on your player object or whatever.