- Home /
SplatMaps and packing variables
Hello folks,
I am currently trying to wrap my head around terrain texturing using splatmaps. As a base I a use this shader which I found on reddit :
Shader "Custom/Splatmap" {
Properties {
_MainTex ("Splat Map", 2D) = "white" {}
_Texture1 ("Texture 1", 2D) = "white" {}
_Texture2 ("Texture 2", 2D) = "white" {}
_Texture3 ("Texture 3", 2D) = "white" {}
_Texture4 ("Texture 4", 2D) = "white" {}
}
SubShader {
Tags {"RenderType" = "Opaque"}
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float2 uv_Texture1;
float2 uv_Texture2;
float2 uv_Texture3;
float2 uv_Texture4;
};
sampler2D _MainTex;
sampler2D _Texture1;
sampler2D _Texture2;
sampler2D _Texture3;
sampler2D _Texture4;
void surf (Input i, inout SurfaceOutput o) {
half4 splatmapMask = tex2D (_MainTex, i.uv_MainTex);
half4 combinedColor = tex2D (_Texture1, i.uv_Texture1) * splatmapMask.r;
combinedColor += tex2D (_Texture2, i.uv_Texture2) * splatmapMask.g;
combinedColor += tex2D (_Texture3, i.uv_Texture3) * splatmapMask.b;
combinedColor += tex2D (_Texture4, i.uv_Texture4) * splatmapMask.a;
o.Albedo = combinedColor;
}
ENDCG
}
FallBack "Diffuse"
}
The first problem is, this shader doesn't work as it is, I have to remove one of the textures, else I get " Too many texture interpolators would be used for ForwardBase pass (11 out of max 10)"
So I read and read and found I have to add
#pragma target 3.0
but still I have to remove a texture to make it work.
So I read further and they said I have to pack together my input variables, so 2 float2 become one float4, but here my lack of shader programming skill comes into play... I am not sure how to do that.
I'd imagine to do it like this :
struct Input {
float2 uv_MainTex;
float4 uv_Texture1and2;
float4 uv_Texture3and4;
};
but how do I get them apart again in the surf function? And I am not even sure where this input comes from and how it knows it contains 2 texture coords in 1 variable.
Please, if somebody could enlighten me... Bonus question, how are the 11 interpolators calculated, where do they come from?
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220612044449im_/https://answers.unity.com/themes/thub/images/avi.jpg)