- Home /
Question by
fschneider · Jun 17, 2014 at 02:32 PM ·
limitsurface shadercustom shader
Shader with 16 sampler2D variables exceeds sampler limit of 16?
I am working on a custom shader inspired by this post.
In the shader, I am using 16 sampler2D variables, but Unity keeps telling me "sampler limit exceeded; more than 16 samplers needed to compile program" Am I doing something wrong, or is this a bug? If a bug, is there a known workaround?
Thanks, Florian
Shader "Custom/WorldShader16" {
Properties {
_MainTex1 ("1", 2D) = "white" {}
_MainTex2 ("2", 2D) = "white" {}
_MainTex3 ("3", 2D) = "white" {}
_MainTex4 ("4", 2D) = "white" {}
_MainTex5 ("5", 2D) = "white" {}
_MainTex6 ("6", 2D) = "white" {}
_MainTex7 ("7", 2D) = "white" {}
_MainTex8 ("8", 2D) = "white" {}
_MainTex9 ("9", 2D) = "white" {}
_MainTex10 ("10", 2D) = "white" {}
_MainTex11 ("11", 2D) = "white" {}
_MainTex12 ("12", 2D) = "white" {}
_MainTex13 ("13", 2D) = "white" {}
_MainTex14 ("14", 2D) = "white" {}
_MainTex15 ("15", 2D) = "white" {}
_MainTex16 ("16", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
CGPROGRAM
#pragma target 3.0
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex1;
};
sampler2D _MainTex1;
sampler2D _MainTex2;
sampler2D _MainTex3;
sampler2D _MainTex4;
sampler2D _MainTex5;
sampler2D _MainTex6;
sampler2D _MainTex7;
sampler2D _MainTex8;
sampler2D _MainTex9;
sampler2D _MainTex10;
sampler2D _MainTex11;
sampler2D _MainTex12;
sampler2D _MainTex13;
sampler2D _MainTex14;
sampler2D _MainTex15;
sampler2D _MainTex16;
void surf (Input IN, inout SurfaceOutput o) {
float x = IN.uv_MainTex1.x;
float y = IN.uv_MainTex1.y;
bool y4 = (y >= 0.75f);
bool y3 = (y < 0.75f) && (y >= 0.5f);
bool y2 = (y < 0.5f) && (y >= 0.25f);
//bool y1 = (y < 0.25f) && (y >= 0.0f);
float2 product = IN.uv_MainTex1 * float2(4.0f,4.0f);
if (x >= 0.75f) {
if (y4) {o.Albedo = tex2D (_MainTex4, product).rgb;}
else if (y3) {o.Albedo = tex2D (_MainTex8, product).rgb;}
else if (y2) {o.Albedo = tex2D (_MainTex12, product).rgb;}
else {o.Albedo = tex2D (_MainTex16, product).rgb;}
}
else if ((x < 0.75f) && (x >= 0.5f)){
if (y4) {o.Albedo = tex2D (_MainTex3, product).rgb;}
else if (y3) {o.Albedo = tex2D (_MainTex7, product).rgb;}
else if (y2) {o.Albedo = tex2D (_MainTex11, product).rgb;}
else {o.Albedo = tex2D (_MainTex15, product).rgb;}
}
else if ((x < 0.5f) && (x >= 0.25f)){
if (y4) {o.Albedo = tex2D (_MainTex2, product).rgb;}
else if (y3) {o.Albedo = tex2D (_MainTex6, product).rgb;}
else if (y2) {o.Albedo = tex2D (_MainTex10, product).rgb;}
else {o.Albedo = tex2D (_MainTex14, product).rgb;}
}
else {
if (y4) {o.Albedo = tex2D(_MainTex1, product).rgb;}
else if (y3) {o.Albedo = tex2D(_MainTex5, product).rgb;}
else if (y2) {o.Albedo = tex2D(_MainTex9, product).rgb;
} else {o.Albedo = tex2D(_MainTex13, product).rgb;}
}
}
ENDCG
}
FallBack "Diffuse"
}
PS. Sorry for the strange formatting, it seems Mono is not auto formatting on .shader files
Comment