I found a way to do it, but its not working on all platforms. Unity allow to declare 2d texture without sampler and then sample texture using other 2dsampler. So I can have 3 2d samplers and use 15 textures with them.
Check “Texture / Sampler declaration macros”
My example:
Shader "Level/PlaneTerrain" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_LowerTex ("Albedo 0 (RGB)", 2D) = "white" {}
_LowerBumpMap ("Normal 0", 2D) = "white" {}
_LowerMRA ("Data 0 (R - metal, G - smoothnes, B - ambient", 2D) = "blue" {}
_Scale0("UV Scale 0", Range(0,40)) = 1
_MainTex ("Albedo 1 (RGB)", 2D) = "white" {}
_MainTex2 ("Albedo 2 (RGB)", 2D) = "white" {}
_MainTex3 ("Albedo 3 (RGB)", 2D) = "white" {}
_MainTex4 ("Albedo 4 (RGB)", 2D) = "white" {}
_BumpMap ("Normal 1", 2D) = "white" {}
_BumpMap2 ("Normal 2", 2D) = "white" {}
_BumpMap3 ("Normal 3", 2D) = "white" {}
_BumpMap4 ("Normal 4", 2D) = "white" {}
_MRA1 ("Data 1", 2D) = "blue" {}
_MRA2 ("Data 2", 2D) = "blue" {}
_MRA3 ("Data 3", 2D) = "blue" {}
_MRA4 ("Data 4", 2D) = "white" {}
_Scale1("UV Scale 1", Range(0,40)) = 1
_Scale2("UV Scale 2", Range(0,40)) = 1
_Scale3("UV Scale 3", Range(0,40)) = 1
_Scale4("UV Scale 4", Range(0,40)) = 1
//_Glossiness ("Smoothness", Range(0,1)) = 0.5
//_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
//sampler2D _BumpMap, _BumpMap2, _BumpMap3;
//sampler2D _LowerMRA, _MRA1, _MRA2, _MRA3;
// Instead of declaring sampler2D for every texture we can declare some text2d with samplers and other with no sampler
UNITY_DECLARE_TEX2D(_LowerTex);
UNITY_DECLARE_TEX2D(_LowerBumpMap);
UNITY_DECLARE_TEX2D(_LowerMRA);
UNITY_DECLARE_TEX2D_NOSAMPLER(_MainTex);
UNITY_DECLARE_TEX2D_NOSAMPLER(_MainTex2);
UNITY_DECLARE_TEX2D_NOSAMPLER(_MainTex3);
UNITY_DECLARE_TEX2D_NOSAMPLER(_MainTex4);
UNITY_DECLARE_TEX2D_NOSAMPLER(_BumpMap);
UNITY_DECLARE_TEX2D_NOSAMPLER(_BumpMap2);
UNITY_DECLARE_TEX2D_NOSAMPLER(_BumpMap3);
UNITY_DECLARE_TEX2D_NOSAMPLER(_BumpMap4);
UNITY_DECLARE_TEX2D_NOSAMPLER(_MRA1);
UNITY_DECLARE_TEX2D_NOSAMPLER(_MRA2);
UNITY_DECLARE_TEX2D_NOSAMPLER(_MRA3);
UNITY_DECLARE_TEX2D_NOSAMPLER(_MRA4);
half _Scale0, _Scale1, _Scale2, _Scale3, _Scale4;
struct Input {
float2 uv_MainTex;
float4 color: Color; // Vertex color
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo
fixed4 c0 = UNITY_SAMPLE_TEX2D(_LowerTex, IN.uv_MainTex * _Scale0);
fixed4 c1 = UNITY_SAMPLE_TEX2D_SAMPLER (_MainTex, _LowerTex, IN.uv_MainTex * _Scale1);
fixed4 c2 = UNITY_SAMPLE_TEX2D_SAMPLER (_MainTex2, _LowerTex, IN.uv_MainTex * _Scale2);
fixed4 c3 = UNITY_SAMPLE_TEX2D_SAMPLER (_MainTex3, _LowerTex, IN.uv_MainTex * _Scale3);
fixed4 c4 = UNITY_SAMPLE_TEX2D_SAMPLER (_MainTex4, _LowerTex, IN.uv_MainTex * _Scale4);
fixed4 c = c0;
c = lerp(c, c1, IN.color.r);
c = lerp(c, c2, IN.color.g);
c = lerp(c, c3, IN.color.b);
c = lerp(c, c4, IN.color.a);
c *= _Color;
// Normal
fixed3 nor0 = UnpackNormal(UNITY_SAMPLE_TEX2D(_LowerBumpMap, IN.uv_MainTex * _Scale0));
fixed3 nor1 = UnpackNormal(UNITY_SAMPLE_TEX2D_SAMPLER(_BumpMap, _LowerBumpMap, IN.uv_MainTex * _Scale1));
fixed3 nor2 = UnpackNormal(UNITY_SAMPLE_TEX2D_SAMPLER(_BumpMap2, _LowerBumpMap, IN.uv_MainTex * _Scale2));
fixed3 nor3 = UnpackNormal(UNITY_SAMPLE_TEX2D_SAMPLER(_BumpMap3, _LowerBumpMap, IN.uv_MainTex * _Scale3));
fixed3 nor4 = UnpackNormal(UNITY_SAMPLE_TEX2D_SAMPLER(_BumpMap4, _LowerBumpMap, IN.uv_MainTex * _Scale4));
fixed3 nor = nor0;
nor = lerp(nor, nor1, IN.color.r);
nor = lerp(nor, nor2, IN.color.g);
nor = lerp(nor, nor3, IN.color.b);
nor = lerp(nor, nor4, IN.color.a);
// Metallic colors
fixed4 data0 = UNITY_SAMPLE_TEX2D (_LowerMRA, IN.uv_MainTex * _Scale0);
fixed4 data1 = UNITY_SAMPLE_TEX2D_SAMPLER (_MRA1, _LowerMRA, IN.uv_MainTex * _Scale1);
fixed4 data2 = UNITY_SAMPLE_TEX2D_SAMPLER (_MRA2, _LowerMRA,IN.uv_MainTex * _Scale2);
fixed4 data3 = UNITY_SAMPLE_TEX2D_SAMPLER (_MRA3, _LowerMRA,IN.uv_MainTex * _Scale3);
fixed4 data4 = UNITY_SAMPLE_TEX2D_SAMPLER (_MRA4, _LowerMRA,IN.uv_MainTex * _Scale4);
fixed4 d = data0;
d = lerp(d, data1, IN.color.r);
d = lerp(d, data2, IN.color.g);
d = lerp(d, data3, IN.color.b);
d = lerp(d, data4, IN.color.a);
// Assign data
o.Albedo = c.rgb;
o.Normal = normalize(nor);
o.Metallic = d.r;
o.Smoothness = d.g;
o.Occlusion = d.b;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Standard"
}