Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    15
    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,044
    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:
    15
    @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,044
    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:
    15
    @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,044
    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:
    15
    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:
    2
    _Tints is not declared in Properties section,so you have to move _Tints out from CBUFFER.
     
unityunity