How to skip color for part of texture?
Hi, I'm new to Unity and trying to make a Car Game.
I have a car model with a texture. I want to change the color of my car.
the problem is when I set the texture and then set the color for shader. the lights of the car gets the same color in transparency.
I want to change color for body parts of car not the lights and other parts. I've googled and find that's maybe it's about alpha channel the texture. tried the alpha but that didn't help.
Have anyone faced such a problem?
Thanks.
You would probably need to use a custom colour mask shader. By default, these shaders just multiply the texture input by the main colour.
@Namey5, How to use a custom color mask shader? You mean write a custom shader or just modifying the texture's alpha channel?
Answer by Namey5 · Sep 01, 2016 at 07:15 AM
This shader will mask the colour tint by the alpha channel of the main texture, i.e. 0 = no tint, 1 = full tint.
Shader "Custom/ColorMask" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
c *= lerp (half4 (1,1,1,1), _Color, c.a);
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}