Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

MaterialPropertyBlock.SetTexture not working

Discussion in 'Shaders' started by Atair, May 17, 2018.

  1. Atair

    Atair

    Joined:
    Oct 16, 2015
    Posts:
    42
    ..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?

    Code (CSharp):
    1. UNITY_INSTANCING_BUFFER_START(Props)        
    2.      UNITY_DEFINE_INSTANCED_PROP(sampler2D, _MainTex)
    3. UNITY_INSTANCING_BUFFER_END(Props)
    and:

    Code (CSharp):
    1. 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
     
    Last edited: May 17, 2018
    Manoleitor and SugoiDev like this.
  2. Atair

    Atair

    Joined:
    Oct 16, 2015
    Posts:
    42
    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..
     
    Last edited: May 17, 2018
    Manoleitor likes this.