Search Unity

Hardware Instancing and Unity?

Discussion in 'Scripting' started by Arowx, Mar 24, 2013.

  1. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Hi Scriptonauts,

    In DirectX and OpenGL there is something called Hardware Instancing, that lets you use the same model/texture data repeatedly on the GPU without any additional CPU overhead, a real performance booster/crowd pleaser ;0)

    Now I have been ranting and raving that this is a feature Unity should have for it's AAA push, then I bumped into the SkinnedMesh.BakeMesh function does this provide Hardware Instancing?

    And if it does is there a great example of how best to use it?

    Thank You
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    If Unity has hardware instancing (I don't think so), then its used for specific things within the engine, its not something controllable through script.

    As for skinned meshes: Actually skinned meshes are one of the prime examples of meshes that can not be hardware instanced without a major sacrifice in its gain because they have per instance modifications which breaks the idea of '1 mesh for all instances with changes to the other states and transforms'. In Unitys case I would take it for granted that they not mesh instances, because Unity offloads animation to a distinct CPU thread. Legacy potentially was able to run on vertex shaders and probably did, but in case of Mecanim?
     
  3. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Actually I was wondering if the static and dynamic batching features of Unity were just under the hood Instancing.

    All Instancing does is remove the CPU from having to queue multiple copies of the same mesh, as once the first mesh is on the GPU it can copy it multiple times.

    There is SystemInfo.SupportsInstancing and Graphics.DrawProcedural but they appear to be tied into the DX11 Compute Shader which seems a bit complex compared to a simple command to make duplicate copies of a model+material already on the GPU.