Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to access array elements in Surface Vertex shaders? 0 Answers

Eliminate automatic vertex * mvp from surface shader 0 Answers

Surface Shader apply normal map to object normal without pluggin it into o.Normal 1 Answer

Custom shader always reverts to fallback 1 Answer

Dividing Extruded Object into Manageable Pieces? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges