Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Palette swap on high resolution textures

Discussion in '2D' started by RavenTravelStudios, Jun 27, 2016.

  1. RavenTravelStudios

    RavenTravelStudios

    Joined:
    Oct 15, 2015
    Posts:
    100
    Hi everyone,
    i was playing with textures and i was wondering about the best method to achieve a palette swap using hi res images. With old style low res pixel art textures this is obviously simple and you can take a lot of different paths since usually there are few colors and you can have a good control of each pixel.

    The difficulty is when you try to translate the concept on hi res textures. Basically even if you're using a few colors to fill the image, the brush mark is made by a lot of different pixels, each of which with his own shade/alpha variation, which makes really hard to swap it in a very accurate way.

    So, even a simple texture like this one:


    upload_2016-6-27_20-13-42.png

    Could result in a very high range of colors if you look closely:

    upload_2016-6-27_20-16-58.png



    Now, for the palette swap, what i'd need is a way to get a list of colors and change them in my default texure. I already tried some shader which actually let you choose the source/destination color and they do what they claim, but this is not enough accurate to achieve a good result:

    upload_2016-6-27_20-23-30.png


    Because of bilinear filtering you easily get artifacts, and, most of all, the color swap is very inaccurate, even using different shade tolerance values. Again, this is because we are not really dealing with flat colors, but with a lot of brush shades instead.

    I think the best solution is to extract an indexed source of the all colors used by the texture, and use a shader (or whatever) which can reference the colors by indexes replacing them from another indexed source.
    And it must work with bilinear filtering too, because point filter gives bad results with hi res textures.

    I looked to color correction ramp Unity effect and that's close to what i'd need.
    But it uses the entire camera, while i'd need to apply that to sprites only.

    Also, if someone can point me a good way to extract colors from a texture (lets say with photoshop) and save them as a source for the indexed colors (like color correction ramp works) i'd be grateful.

    So far i worked around that issue by shifting the hue programmatically, that simulates palette swapping very well but its not the real thing.

    Thank you so much guys :)
     

    Attached Files:

    Last edited: Jun 28, 2016