- Home /
Can DrawMeshInstancedProcedural be used with Single Pass Instanced Rendering in Unity XR project?
I'm procedurally rendering a whole bunch of meshes using DrawMeshInstancedProcedural and a custom shader along the lines of https://docs.unity3d.com/Manual/GPUInstancing.html which works fine on PC. I'm now trying to use this in a Hololen2 project. If I'm following correctly, the more efficient XR rendering method of "Single Pass Instanced" is also making use of this GPU instance capability to draw the scene's geometry for each eye. Does this mean I can't do both or is there something I need to do to handle this combination correctly in the shader or DrawMeshInstancedProcedural code (ie. per-eye instance vs per DrawMeshInstancedProcedural instance)?
With "Multi-pass" set my scene renders correctly but with "Single Pass Instanced" the transforms are off for my instances in one eye (ie. Seems the instance ID based lookup of the per-instance transforms is off).
I think the issue is the conflict between the instance ID in the vertex shader being for the instanced meshes call vs the stereo render.
I did wonder if the statement at the bottom of the [Unity Hololens Stereo render docs][1] is a clue – “Graphics.DrawProceduralIndirect() and CommandBuffer.DrawProceduralIndirect() get all of their arguments from a compute buffer, so we can’t easily increase the instance count. Therefore you will have to manually double the instance count contained in your compute buffers.”
My shader has all the instance id macros etc as stated in the docs (https://docs.unity3d.com/Manual/SinglePassStereoRenderingHoloLens.html) which are the same ones needed for GPU instancing (https://docs.unity3d.com/2021.2/Documentation/Manual/gpu-instancing-shader.html) which I assume is where the conflict is.
Any help or suggestions would be great.