cancel
Showing results for 
Search instead for 
Did you mean: 

Unity DrawMeshInstanced not working on Quest

tzmtn
Level 2
For some reason DrawMeshInstanced doesn't work for me on Quest.
I tried both Graphics.DrawMeshInstanced and CommandBuffer.DrawMeshInstanced  and they both don't work.
DrawMesh does work with no problem.
DrawMeshInstanced works on PC running in the Editor or in a build on Rift.
The shader that I'm using is placed in a resources folder so it should be included in the build, but to make sure I also tried placing it in the mush include shaders list and even to place an object in the scene with a material that uses it. All of this didn't help.
I also checked the SystemInfo.supportsInstancing and it returns true on the Quest.
Here is the shader that I'm using:



Shader "Unlit_Mesh_Instance" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
}

SubShader {
Tags {
"Queue"="Overlay"
"RenderType"="Opaque"
}

Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
Blend SrcAlpha OneMinusSrcAlpha
ZTest Always
//Offset -100, -100
Cull Off

CGPROGRAM
#pragma vertex vert
#pragma fragment frag
//#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#pragma multi_compile_fwdbase
#pragma multi_compile_instancing
#pragma only_renderers d3d9 d3d11 glcore gles gles3 metal
#pragma target 3.0

UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float4, _Color)
UNITY_INSTANCING_BUFFER_END(Props)

struct VertexInput {
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct VertexOutput {
float4 pos : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}

float4 frag(VertexOutput i) : COLOR {
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
return UNITY_ACCESS_INSTANCED_PROP(Props, _Color);
}
ENDCG
}
}
}
Am I missing something here?

1 REPLY 1

tzmtn
Level 2
Found a solution,
Turns out it doesn't work when you dynamically create the material and set it to support instancing by code. If you create the material in advance and place it in your resources folder, everything works. Probably a bug, but I can work around that.