Hello! I’m trying to write a simple 2-material blending shader based on texture mask (total noob in whole custom shader business BTW). So far I got the working prototype, the only problem that remains is how to tell the masking texture which UV set to use. It won’t be any good without support for second UV set.
Shader "Custom/2matTexBlend" {
Properties {
_Color ("Tint of the base texture", Color) = (1,1,1,1)
_ExtraCol1 ("Tint of the extra texture1", Color) = (1,1,1,1)
_Glossiness ("Smoothness, multiplied by alpha of normal map", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_Emission ("Emission, multiplied by alpha of texture maps", Range(0,1)) = 0
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_ExtraTex1 ("ExtraTex1 (RGB)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_BumpMap2 ("Normalmap2", 2D) = "bump" {}
_Mask ("Masking texture (RGB)", 2D) = "grey" {}
[Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary material", Float) = 0
[Enum(UV0,0,UV1,1)] _UVMask ("UV Set for the mask", Float) = 0
}
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;
sampler2D _ExtraTex1;
sampler2D _BumpMap;
sampler2D _BumpMap2;
sampler2D _Mask;
struct Input {
float2 uv_MainTex;
float2 uv_ExtraTex1;
float2 uv_BumpMap;
float2 uv_BumpMap2;
float2 uv_Mask;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
fixed4 _ExtraCol1;
half _Emission;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
half4 mask = tex2D (_Mask, IN.uv_Mask);
fixed4 extra1 = tex2D (_ExtraTex1, IN.uv_ExtraTex1) * _ExtraCol1;
fixed4 bump = tex2D (_BumpMap, IN.uv_BumpMap);
fixed4 bump2 = tex2D (_BumpMap2, IN.uv_BumpMap2);
half MaskBlend = mask.r+mask.g+mask.b/3;
c.rgb = lerp(c.rgb,extra1.rgb,MaskBlend);
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = lerp(_Glossiness*bump.a,_Glossiness*bump2.a,MaskBlend);
o.Alpha = c.a;
o.Normal = lerp(UnpackNormal(bump),UnpackNormal(bump2),MaskBlend);
o.Emission = _Emission*c.rgb;
}
ENDCG
}
FallBack "Diffuse"
}
(I shamelessly ripped the Enum construction from the Standard shader UI, but do not know where to plug the UV indices provided by it
The rest of the Standard shader code is just too cryptic for my limited understanding.)