- Home /
How to dynamically apply a color to one portion of a UV map?
Let's say I want the user to choose the character's shirt color.
What should I do it by script to apply a tint color to a certain part of my UV map? Or is there another way than by script?
Answer by _Yash_ · Jun 17, 2016 at 05:25 AM
You can create a shader for this. There are two ways to do it.
1) create an image in which every part has different RGB values and your shader replaces specific RGB value with the one you provide. for example, if your shirt part in the reference image is red(1,0,0), your shader will replace red with your given color. create this pair for each part.
2) create mask images for every part and use that masks to change the color of the specific part. use all images to change color in the shader.
Hi there, Thanks for your response. Would that mean I would have to write my own shader? I don't know how to, so I'm better off finding one, or some plug-in. Any suggestion for a ready made shader/plugin? Thanks a lot
I don't think you will find this shader online. Because as far as I know shaders can not have the variable number of properties, so you have to make your own shader. It is an easy one, just take one Unlit shader and modify it's fragment function.
Thank you for the clarification.
Say I created a Color property called _shirtColor, and the shirt is in the square between (0,0) and (0.5,0.5) in my UV $$anonymous$$ap. What line should I add to this standard frag function? Is it some kind of Combine line? I really don't know what to do.
fixed4 col = tex2D(_$$anonymous$$ainTex, i.uv);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
Thank you very much for your help
Answer by qwnick · Dec 22, 2020 at 07:39 PM
You can create model with a couple of sockets for materials, and then change color of each material instance independently.