Search Unity

Instancing + Tessellation

Discussion in 'Shaders' started by afrasson, Oct 19, 2016.

  1. afrasson

    afrasson

    Joined:
    Nov 28, 2013
    Posts:
    2
    Hello,

    I am struggling to make a simple shader work with instancing. It seems that unity can't handle vertex, hull, domain and fragment shaders together with GPU instancing. I tried to use both stable (5.4.1f1) and beta (5.5.0b7) versions and the results are the same. I will try to describe my issue as detailed as possible.

    The first problem I faced was that outputs from hull shader and patchconstantfuncb could not have a UNITY_INSTANCE_ID member. The compiler would report "invalid ds_5_0 input semantic 'SV_InstanceID'".
    Code (CSharp):
    1. struct HS_ControlPointOutput
    2. {
    3.     float4 pos    : POS;
    4.     float3 normal : NORMAL;
    5.     float4 tangent : TANGENT;
    6.     UNITY_INSTANCE_ID  // This translates to uint instanceID : SV_InstanceID;
    7. };
    So, instead of using Unity's macros, I explicitly declared the instance id and modified the semantic from SV_InstanceID to BLENDINDICES. With this modification I was able to access the correct MVP matrix (each instance has its own matrix) for each instance inside the domain shader.
    Code (CSharp):
    1. struct HS_ControlPointOutput
    2. {
    3.     float4 pos    : POS;
    4.     float3 normal : NORMAL;
    5.     float4 tangent : TANGENT;
    6.     uint instanceID : BLENDINDICES;
    7. };
    The second and currently unsolved problem I found was that I can't access instance unique properties inside the patchconstantfuncb function, even with the 'solution' above. For this reason I can't correctly define the amount of tessellation needed for each instance.

    Shouldn't tessellation and GPU instancing be compatible? Am I missing something?
     
    Last edited: Oct 20, 2016
    FM-Productions likes this.