Search Unity

UnityPerMaterial CBUFFER with a float4[] is not compatible with SRP Batcher ??

Discussion in 'Shaders' started by PiezPiedPy, Oct 20, 2019.

  1. PiezPiedPy

    PiezPiedPy

    Joined:
    Mar 22, 2019
    Posts:
    14
    I'm using Unity 2019.2.9f1 with LWRP and I have a problem with one of my shaders, Unity is saying it is incompatible with the SRP Batcher.

    Code (CSharp):
    1. #define MAX_LAYERS 18
    2.  
    3. CBUFFER_START(UnityPerMaterial)
    4.  
    5. int _OceanLayerCount;
    6. int _GroundLayerCount;
    7.  
    8. float _Scales[MAX_LAYERS];
    9. float4 _Tints[MAX_LAYERS];
    10. float _TintStrengths[MAX_LAYERS];
    11. float _Blends[MAX_LAYERS];
    12.  
    13. CBUFFER_END
    14.  
    The problem is with the float4 _Tints[MAX_LAYERS]; @ line 9, basically an array or colors.

    The error is "UnityPerMaterial var is not declared in shader property section (_Tints)"

    What am I doing wrong ?
     
    Last edited: Oct 21, 2019
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,546
    Strange. Unity still uses that CBUFFER syntax in the URP/LWRP, so not sure what's wrong. Is this an old shader that you were using in the old shader pipeline? If so it likely needs some changing elsewhere in the code to work and the error chain is just finishing at that point.

    If not, where abouts in your shader code is this part located? Is it within the HLSLPROGRAM?
     
  3. PiezPiedPy

    PiezPiedPy

    Joined:
    Mar 22, 2019
    Posts:
    14
    @Invertex It's a new shader I'm writing and yes the CBUFFER is in the HSLSPROGRAM section, the shader works fine except it is not compatible with the SRP Batcher due to the float4[].
    If I change the float4[] to a standard float[] or just a single float4 it shows as compatible but obviously my shader wont work then as I need my array of colors.
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,546
    Which version of the URP are you using?
    Unity has examples with float4 arrays, though the only ones I can find don't use the UnityPerMaterial context but instead other ones like terrain or UnityBillboardPerBatch. Might be worth a bug report if you're absolutely on the latest version of URP.
     
  5. PiezPiedPy

    PiezPiedPy

    Joined:
    Mar 22, 2019
    Posts:
    14
    @Invertex I'm not using URP, I'm using the latest LWRP v6.9.2
    I think I'll send a bug report, can't hurt ;)
     
  6. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,546
    LWRP was renamed URP, so if you're still on LWRP then it is a bit outdated. It's in the version 7.1+ now.
     
    PiezPiedPy likes this.
  7. PiezPiedPy

    PiezPiedPy

    Joined:
    Mar 22, 2019
    Posts:
    14
    Thanks for the heads up, I was unaware LWRP was being replaced with URP, I'll look into it :)
     
  8. herolang

    herolang

    Joined:
    Mar 25, 2015
    Posts:
    3
    _Tints is not declared in Properties section,so you have to move _Tints out from CBUFFER.
     
  9. Tallek

    Tallek

    Joined:
    Apr 21, 2014
    Posts:
    34
    Did you ever find a solution to this?
    Is there an associated bug report or feature request that you could link?
     
  10. elijad

    elijad

    Joined:
    Mar 19, 2020
    Posts:
    47
    Just add a vector property with the same name in the beginning of the shader.
     
  11. Tallek

    Tallek

    Joined:
    Apr 21, 2014
    Posts:
    34
    I can add a vector property with the same name to the shader properties section, but it doesn't work, complaining about the array size not matching the previous size (50 vs 1 for example). I am not aware of any way to add a vector array property to the shader properties section.
     
  12. elijad

    elijad

    Joined:
    Mar 19, 2020
    Posts:
    47
    My mistake, didn't check it properly. You could probably define a global array and put starting index into the cbuffer.