Question by 
               io-games · Nov 16, 2016 at 03:11 PM · 
                shadershader programmingshaderlab  
              
 
              Get shader properties value by name in shader code in runtime?
Is it possible to get shader properties by name in runtime? For example:
 Properties{
         _MyTex1("Atlas 1", 2D) = "" {}
         _MyTex2("Atlas 2", 2D) = "" {}
         _MyTex3("Atlas 3", 2D) = "" {}
 }
 
               And want to get it by dynamic name (for example, I can read index from vertex color) or just:
 index = 2
 fixed4 c = tex2D("_MyTex" + index, IN.uv_MainTex);
 
              
               Comment
              
 
               
              Answer by helarts · Nov 16, 2016 at 03:48 PM
EDIT: After testing this works:
 #define GET_TEXTURE_BY_INDEX(name,index) (name##index)
 
               then in fragment shader:
  fixed4 c = tex2D(GET_TEXTURE_BY_INDEX(_MyTex, 2), IN.uv_MainTex);
 
               It seems pretty useless in your case though, I don't know how or if you can use a variable value for the index.
You may also want to check texture arrays if your targeted hardware support them: https://docs.unity3d.com/Manual/SL-TextureArrays.html
Your answer