Hi,
I’m currently using Unity V5.3.5. In my game, I’m changing meshes on a trigger pull of my controller. At that moment, several meshes with max 1200 vertices and ~6500 triangles are altered (no change in the number of triangles or vertices). The mesh change is performed via worker threads which results in arrays containing the result. Those arrays are then assigned to a newly generated mesh (see code snippet).
private void ApplyPatchMesh(ref TerrainPatch p)
{
MeshFilter meshFilter = p.m_PatchObject.GetComponent<MeshFilter>();
if (meshFilter == null)
meshFilter = p.m_PatchObject.AddComponent(typeof(MeshFilter)) as MeshFilter;
if (p.m_Renderer == null)
{
p.m_Renderer = p.m_PatchObject.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
p.m_Renderer.material.shader = Shader.Find("Sidema/TerrainGPUNoHeight");
}
if (p.m_Collider == null)
p.m_Collider = p.m_PatchObject.AddComponent(typeof(MeshCollider)) as MeshCollider;
if (p.m_PatchObject.GetComponent<Rigidbody>() == null)
{
Rigidbody rb = p.m_PatchObject.AddComponent<Rigidbody>();
rb.isKinematic = true;
}
Mesh m = new Mesh();
m.name = p.m_PatchObject.name;
p.vertices = p.m_patchJob.vertices;
p.uvs = p.m_patchJob.uvs;
p.triangles = p.m_patchJob.triangles;
p.tangents = p.m_patchJob.tangents;
m.vertices = p.vertices;
m.uv = p.uvs;
m.triangles = p.triangles;
m.tangents = p.tangents;
m.RecalculateNormals();
p.m_Collider.sharedMesh = null;
p.m_Collider.sharedMesh = m;
meshFilter.sharedMesh = m;
m.RecalculateBounds();
ApplySubTextures(p);
}
I’ve optimized the code and the deep profiler shows that my code never uses more than 0.76 ms.
But what I see is that OculusWaitForGPU takes up to 50-60 ms in those frames when I change the meshes.
Unfortunately, I only can suppose that it’s the mesh push to the GFX card which causes the “hiccup”, but 50-60ms seems to be highly unreasonable for max. 4-8 6500 triangle patches.
The high OculusWaitForGPU peak lasts for 2 frames.
Has anyone an idea how to improve this? What is OculusWaitForGPU exactly doing at this point when I push a new mesh to the GFX card?