MaterialPropertyBlock.SetTexture not working

…either not working or i didn’t get it right…

  1. Does this SetTexture really allow for multiple textures and keep gpu instancing working? It seems to good to be true?
UNITY_INSTANCING_BUFFER_START(Props)        
     UNITY_DEFINE_INSTANCED_PROP(sampler2D, _MainTex)
UNITY_INSTANCING_BUFFER_END(Props)

and:

fixed4 c = tex2D(UNITY_ACCESS_INSTANCED_PROP(Props, _MainTex), IN.uv_MainTex) * _Color;

this gives the following error:
sampler array index must be a literal expression

google wasn’t giving me much on this error

all in editor, windows 10, dx11 and inside a surface shader…

ps. works just fine with float4 colors etc.

EDIT: the answer seems to be Texture2DArray, and sending an index with it…
https://www.reddit.com/r/Unity3D/comments/6uueox/gpu_instancing_texture2darray/
reddit helped. I understand that unity is moving fast, but the documentation on most advanced topics is horrible

2 Likes

One more problem - the shader code from the reddit link, which seems to work fine for everyone there throws an error for me: Shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
actually there are a few errors, regarding compilation, not syntax but this is the bottom line

happens on two machines, not the newest ones, but both dx11… i can only assume that something else changed in the unity versions since the reddit post (or i again don’t get it)

EDIT: Solved:
the reddit shader sample has a closing bracket missing on the line with UNITY_SAMPLE_TEX2DARRAY, this gave that cascade of strange errors (magic number etc.)
in case anyone else is trying that code…

1 Like