- Home /
Can you tint a specific part of a 2D Sprite?
I'm trying to figure out how to use color tinting on a sprite, but only on part of it. I've thought about overlaying, so using two objects with one being composed of the parts to be tinted, but this seems like an inefficient roundabout way. Is there a better/more efficient way of changing the color of a 2D sprite. The object in question would be a simple pixel art sprite on a quad. Basically the goal is to be able to instantiate quads from the same prefab, but with small sections of it being different colors from one another, without tinting the entire texture in the process.
Answer by robertbu · Oct 29, 2013 at 05:55 AM
There are a few different ways to accomplish your goal. Without knowing the number of colors, the number of textures, the number of objects that have this texture and the target platform, it is hard to give a specific recommendation.
The most common way to handle this kind of thing for a for small textures is to just change the whole texture. You can change the whole texture in the material, or a more efficient method would be to change the UV coordinates in the mesh to point to a different area of a texture atlas.
Another solution is to use a custom shader. You would provide a mask to determine what parts of the underlying image get a tint color.
If you build a mesh so that the area to be colored has its own vertices and triangles, you can change the vertex colors in the mesh or the uv for just that specific area.
Or potentially you could do the two quad thing you outline with a quad to color specific areas on top.
Hmm, I didn't think of tweaking it with a sort of localized shader, that could work, thanks.