Jump to content
  • Advertisement
Sign in to follow this  

Unity Getting color pallette of non-shaded texture that ignores aliasing

This topic is 2124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Edit: I've gotten it from 5k to about 60 by only checking 100% opaque values and introducing floating point tolerances since Unity converts all the colors to floating point. But that's still about ~13-15x the number in the actual number in the photo ... that's with pretty generous tolerances of .1f which is is ~ +/- 25 in the 8-bit color scale.

So I'm trying to write a tool for my Unity game that will allow me to make a color edit mode. I figured if I went the extra step to make sure my colors were all completed seperated that it would be fairly easy, but I'm still getting far more colors then I actually attempted using when I colored the picture. The picture was done with vector graphics so I know the precise color of each not including the aliased lines which are interpolated with a completely alpha color.

I'm not 100% that aliasing is the problem but otherwise I am completely unsure why there would be in the realm of 4000 different colors showing in my photo. They all seem to be really similar versions of the same color so aliasing is the only thing that makes sense. The idea is have a color mask, a and a pallete to map use selected colors too at run time.

This is just a sample file of peach from paper mario I'm using to test the system [attachment=11405:PrincessColor.png]

The goal is to use this color map with the BW and a shade map to construct the final picture. I was separating the BW from the color to try and solve the aliasing issue but that isn't the solution.

Hopefully looking like this in the end.[attachment=11406:ColorPrincess.png]

I got it working in photoshop but need to find out how to export this to my game. I could do it by exporting each clip mask out as a picture then recombining them mathematically to guarantee they are exact, but exporting 6-12 pics per frame then recombining is more work then it should have to be. Any help would be appreciated.


[source lang="java"]public class ColorEditorWindow : EditorWindow
static ColorEditorWindow window = null;
List<Color> ColorPallette = new List<Color>();
// Use this for initialization
static public void Start ()
if (window == null)
window = EditorWindow.GetWindow<ColorEditorWindow>();

public void GetPallette()
if (texture != null)

//Reset Pallette if previous one existed
if(ColorPallette.Count != 0) ColorPallette.Clear();

Color temp = new Color(); //cache color value to use as temporary

for (int i = 0; i < texture.height; i++)
for (int j = 0; j < texture.width; j++)
temp = texture.GetPixel(j, i); //Get pixel to test

if (temp.a == 0)//Ignore pure alpha colors

//See if color is unique
for (int k = 0; k < ColorPallette.Count; k++) //If color exists in pallette skip it -- goto is ugly consider something else
{ if (ColorPallette[k].r == temp.r && ColorPallette[k].g == temp.g && ColorPallette[k].b == temp.b) goto NEXT; }

ColorPallette.Add(temp); //If not in pallette add to pallette

NEXT: continue; //If temp exists go here and continue.


public Texture2D texture = null;
public void OnGUI()
texture = EditorGUILayout.ObjectField(texture, typeof(Texture2D)) as Texture2D;

if (GUILayout.Button("Get Pallette"))

/* for (int i = 0; i < ColorPallette.Count; i++)
ColorPallette = EditorGUILayout.ColorField(ColorPallette);

EditorGUILayout.LabelField("Colors: " + ColorPallette.Count);
}[/source] Edited by ChaseRLewis

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!