Color Replace Shader for Unity v1.0
To use it, you'll need a colour map for the colour replacement. Typically it should mostly consist of primary colours (red, green, blue) but experiment with it to see what you can get.
If you find strange "seams" between colours, try removing mipmaps on your texture's import settings.
Changelog
v1.0 - 2020/01/27Initial posted version.
Shader "Custom/ColorReplace" {
Properties {
_ColorTex("Color", 2D) = "white" {}
_MainTex("Detail", 2D) = "transparent" {}
_RedReplace("Red Replace", Color) = (1, 1, 1, 1)
_GreenReplace("Green Replace", Color) = (1, 1, 1, 1)
_BlueReplace("Blue Replace", Color) = (1, 1, 1, 1)
_MetallicTex("Metallic", 2D) = "white" {}
_Smoothness("Smoothness", Range(0, 1)) = 0.6
_NormalTex("Normal", 2D) = "bump" {}
_NormalIntensity("Normal Intensity", Range(0.0, 1.0)) = 0.5
}
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 _ColorTex;
sampler2D _MainTex;
fixed4 _RedReplace;
fixed4 _GreenReplace;
fixed4 _BlueReplace;
sampler2D _MetallicTex;
sampler2D _NormalTex;
struct Input {
float2 uv_MainTex;
};
half _Smoothness;
half _NormalIntensity;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf(Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D(_ColorTex, IN.uv_MainTex);
c = (_RedReplace * c.r) + (_GreenReplace * c.g) + (_BlueReplace * c.b);
fixed4 d = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = (c.rgb * (1 - d.a)) + (d.rgb * d.a);
fixed4 m = tex2D(_MetallicTex, IN.uv_MainTex);
o.Metallic = m.rgb;
o.Smoothness = _Smoothness;
float3 n = UnpackNormal(tex2D(_NormalTex, IN.uv_MainTex));
n.x *= _NormalIntensity;
n.y *= _NormalIntensity;
o.Normal = normalize(n.rgb);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
No comments:
Post a Comment