Search Unity

Question SV_InstanceID vs unity_InstanceID

Discussion in 'Shaders' started by magebuzzcutt, Jan 23, 2023.

  1. magebuzzcutt

    magebuzzcutt

    Joined:
    Jun 20, 2021
    Posts:
    17
    what is the difference between getting and using the instance id using:
    Code (CSharp):
    1. v2f vertexShader (vertexData input, uint instanceID : SV_InstanceID){
    2.      float4 data = positionBuffer[instanceID];
    3. }
    compared to:
    Code (CSharp):
    1.  v2f vertexShader (vertexData input){
    2.      UNITY_SETUP_INSTANCE_ID(input);
    3.      #ifdef INSTANCING_ON
    4.         float4 data = positionBuffer[unity_InstanceID];
    5.      #else
    6.         float4 data = 0.0f;
    7.      #endif
    8. }
    I was trying to use Graphics.DrawMeshInstancedIndirect() and a compute buffer, and the second method does not work where the instancing keyword is not defined. However, the second method works with Graphics.DrawMeshInstanced().
     
    AJMHPC and ChristopherKerr like this.
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,023
    unity_InstanceID
    takes into account stereo rendering. The engine also sets a base instance ID property that's added to
    unity_InstanceID
    automatically for you.

    If something isn't working with Graphics.DrawMeshInstancedIndirect, I would suggest to report a bug.