Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to deal with array properties with SRP Batcher

Discussion in 'Universal Render Pipeline' started by pw_prg_yinchao, Aug 27, 2021.

  1. pw_prg_yinchao

    pw_prg_yinchao

    Joined:
    Feb 14, 2020
    Posts:
    18
    I am writing a custom shader under URP with SRP Batcher enabled.

    I want to declare a vector array property, say "_Colors":
    Code (CSharp):
    1. half4 _Colors[8];
    and in order to let this shader to be SRP Batcher compatible:
    Code (CSharp):
    1. CBUFFER_START(UnityPerMaterial)
    2.     half4 _Colors[8];
    3. CBUFFER_END
    But now I have no idea to declare it in
    Properties
    block, because there is no
    Array
    type similar to
    Vector
    or
    Color
    .

    Besides, I have tried some ways and found something interesting:
    1. If a uniform variable in
    UnityPerMaterial
    CBuffer has a
    Array
    type, and a property declared in
    Properties
    block with same name, whatever its type is, SRP Batcher will feel satisfied. (tested by attachmented TestSRPBatcherCompatibilityWithArrayVariable.shader)
    2. If a uniform variable in
    UnityPerMaterial
    CBuffer has a
    Matrix
    type, and no property declared in
    Properties
    block with same name, SRP Batcher will feel satisfied. (tested by attachmented TestSRPBatcherCompatibilityWithArrayVariable.shader)
    All above are so confused to me.
    (All my attachmented shaders are tested under Unity 2019.4.29f1 with URP 7.4.1, on a Windows PC.)
     

    Attached Files:

    Last edited: Aug 27, 2021
  2. pw_prg_yinchao

    pw_prg_yinchao

    Joined:
    Feb 14, 2020
    Posts:
    18
    I cannot edit this thread. And I missed a shader attachment. And I didn't find out how to delete this thread, so I posted a new one. (Maybe the administrator could help me to delete or lowest this thread?)