Search Unity

Question Precomputed Realtime GI with Instancing/Indirect Instancing

Discussion in 'Global Illumination' started by chris_schubert, Apr 20, 2020.

  1. chris_schubert

    chris_schubert

    Joined:
    Jan 8, 2019
    Posts:
    28
    Hi all,

    I'm trying to get to the bottom of whether or not there is anyway with Realtime GI to have different lighting across instances rendered using Graphics.DrawMeshInstancedIndirect or Graphics.DrawMeshInstancedProcedural.

    When drawing instanced (not indirect), it is possible to provide the light probe usage and it works well. You can either blend probes normally, provide a proxy volume, or specify custom lighting per instance (example).

    I was hoping this would extend to indirect instancing, as the API for Graphics.DrawMeshInstanced & Graphics.DrawMeshInstanced[Indirect/Procedural] are basically the same, and the latter also takes the probe usage data argument.

    However, as soon as I try to make this work with indirect instancing, I get bad ambient lighting on the rendered meshes. Am I missing something? Or does indirect instancing simply not support different ambient light across instances, no matter what? Is it possible that I simply didn't set something up right when doing my instanced indirect setup?

    INSTANCED_VS_INDIRECT.png

    Here's my procedural setup for the shader:

    Code (CSharp):
    1.    
    2. #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    3.    
    4.     struct IndirectShaderData
    5.     {
    6.         float4x4 PositionMatrix;
    7.         float4x4 InversePositionMatrix;
    8.     };
    9.    
    10.     #if defined(SHADER_API_GLCORE) || defined(SHADER_API_D3D11) || defined(SHADER_API_GLES3) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN) || defined(SHADER_API_PS4) || defined(SHADER_API_XBOXONE)
    11.    
    12.     StructuredBuffer<IndirectShaderData> IndirectShaderDataBuffer;
    13.    
    14.     #endif
    15.    
    16.     #endif
    17.      
    18.     void setup()
    19.     {  
    20. #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    21.  
    22.         unity_ObjectToWorld = IndirectShaderDataBuffer[unity_InstanceID].PositionMatrix;
    23.         unity_WorldToObject = IndirectShaderDataBuffer[unity_InstanceID].InversePositionMatrix;
    24.  
    25. #endif
    26.     }
    27.