ez06
1
I have a texture for my character with a white t-shirt.
How do I tint only a certain part of my texture, say the rectangle from (0,0.3) to (0.5,1)?
I am not proficient with shader programming.
Where exactly should I add a line of code, and which line of code exactly?
I want to multiply the texture’s color by my tint color.
In general, as a good start point to understand Surface Shader writing in Unity, I always recommend the examples : Unity - Manual: Surface Shader examples
And to do strictly what you said, try this shader :
Shader "Example/Diffuse Texture" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_MyColor("My Color", Color = (1,1,1,1)
_MyRectangle("My Rectangle", Vector) = (0, 0.3, 0.5, 1)
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
float4 _MyColor;
float4 _MyRectangle;
void surf (Input IN, inout SurfaceOutput o) {
float4 c = tex2D (_MainTex, IN.uv_MainTex).rgb;
if (
IN.uv_MainTex.x > _MyRectangle.x &&
IN.uv_MainTex.x < _MyRectangle.z &&
IN.uv_MainTex.y > _MyRectangle.y &&
IN.uv_MainTex.y < _MyRectangle.w )
{
c.rgb *= _MyColor.rgb;
}
o.Albedo = c;
}
ENDCG
}
Fallback "Diffuse"
}