Search Unity

Question How to set Unity Matrices for Instancing Indirect?

Discussion in 'Shader Graph' started by Backes, Sep 18, 2019.

  1. Backes

    Backes

    Joined:
    Mar 22, 2018
    Posts:
    4
    Hello,

    I'm writting a custom shader from the shader graph's generated code to enable instancing indirect.
    However, the unity_WorldToObject and unity_ObjectToWorld matrices were replaced by UNITY_MATRIX_I_M and UNITY_MATRIX_M, and now they are const.
    How could I replace theirs values?

    Edit:
    Seems that we cant set the matrices anymore.
    Code (CSharp):
    1. // Define Model Matrix Macro
    2. // Note: In order to be able to define our macro to forbid usage of unity_ObjectToWorld/unity_WorldToObject
    3. // We need to declare inline function. Using uniform directly mean they are expand with the macro
    4. float4x4 GetRawUnityObjectToWorld() { return unity_ObjectToWorld; }
    5. float4x4 GetRawUnityWorldToObject() { return unity_WorldToObject; }
    6.  
    7. #define UNITY_MATRIX_M     ApplyCameraTranslationToMatrix(GetRawUnityObjectToWorld())
    8. #define UNITY_MATRIX_I_M   ApplyCameraTranslationToInverseMatrix(GetRawUnityWorldToObject())
    9.  
    10. // To get instanding working, we must use UNITY_MATRIX_M / UNITY_MATRIX_I_M as UnityInstancing.hlsl redefine them
    11. #define unity_ObjectToWorld Use_Macro_UNITY_MATRIX_M_instead_of_unity_ObjectToWorld
    12. #define unity_WorldToObject Use_Macro_UNITY_MATRIX_I_M_instead_of_unity_WorldToObject
    (Full Code: https://github.com/Unity-Technologi...on/Runtime/ShaderLibrary/ShaderVariables.hlsl")

    Edit:
    Probably we must now set the matrices array (e.g. unity_ObjectToWorldArray), just need figure out how. (Code: https://github.com/Unity-Technologi...lines.core/ShaderLibrary/UnityInstancing.hlsl)

    Edit:
    I`m setting the procedural setup method with:

    #pragma instancing_options procedural:terrain_instancing_setup


    And trying to access:

    void terrain_instancing_setup()
    {
    #if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
    float4x4 m = unity_WorldToObjectArray[unity_InstanceID];
    #endif
    }


    However this error is occurring:
    "undeclared identifier 'unity_WorldToObjectArray'"

    Does anyone know what I'm missing?
     
    Last edited: Sep 18, 2019
    Dinamytes likes this.
  2. sreinhold_mipumi

    sreinhold_mipumi

    Joined:
    May 14, 2019
    Posts:
    1
    I have basically the same problem right now. Did you ever find a solution for your problem? I can't seem to modify unity_ObjectToWorld in any case, although I see example projects online doing it.
     
    JSmithIR likes this.