Procedural Mesh Create Section Performance

Hi,

I am using the ProceduralMeshComponent to render the current state of a 3d reconstruction (like Kinect Fusion). I update the sections at runtime (in the tick function) using CreateMeshSection. When looking at the frame rate everything seems fine (>100 fps), however one can still perceive lag, which probably comes from the CreateMeshSection function. Why does the frame timing not show this problem and is there is there a way remove that lag? Maybe with multithreading? I dont care if the the update takes a couple of frames as long as the rendering is smooth.

More information is needed.
When you talk about the lag or smoothness of the rendering, are you referring to dropped frames, are you refering to the consistency of the geometry, or the refresh rate of the geometry?
What are you doing with the old meshes?
Are you using CreateMeshSection multiple times every frame?
Are you sure that there is some lag between when the CreateMeshSection function is called, and when your geometry appears, or could it be due to something else, like garbage collection? Have you tried using UpdateMeshSection instead of CreateMeshSection?

I can notice small “jumps” when I move through the scene while updating it, so apparently some frames are not rendered. When the geometry is not updated anymore, the rendering is smooth.

I have divided the world into a 3d grid and I have a mesh for each grid element. Whenever data from one grid element changes I compute the mesh (this is done in another process, not in Unreal). I read the new mesh data via shared memory to Unreal’s TArrays and then pass it to CreateMeshSection. I have only one set of TArrays for new mesh data which is reused every frame. Since I dont have any other copies of the old meshes I dont do anything specific with them. Am I supposed to take care of the old meshes by myself? I though that this is done in the CreateMeshSection function anyway when I call it with an existing ID.

I update one mesh per frame, so CreateMeshSection is called only once. I cannot use UpdateMeshSection because the whole mesh changes, not just the vertex data.

Okay, now we are getting somewhere.
You’re using shared memory to communicate information between two programs, this is ill advised. The jumps you are experiencing may be the result of thread lock, which is common among shared memory situations. The game thread of Unreal is waiting on a memory region to be released by the other program so that it can create the mesh section. It’s much more advisable that if you must communicate between two different programs, you do so through an appropriate communication layer, TCP will do in a pinch. The difference will be that while it might be slightly slower, there will be far fewer chances for the race conditions you may be experiencing.

As for the old meshes, garbage collection will take care of any left over memory allocations made for them, if you’re only making approximately 60 meshes a second, i don’t think garbage collection lag is the issue.

Thanks for your input so far. You are right, the thread lock could have been the problem, but I think it is not. I read the data from shared memory in a separate thread now and the problem still exists. I did some more testing and it seems that the problem is neither related to shared memory nor to the procedural mesh update. The lag even appears in a very simple scene with just a few spheres and cones (but it is a lot less than compared to my 3d reconstruction scene). Maybe it is some driver issue, I dont know… The hardware should not be a problem at all.

Well if the jumpiness exists even in simple scenes not utilizing the ProcedualMeshComponent, then it’s most definitely not an issue of Procedural Mesh Create Section Performance. So you should make a new issue more accurately representing your issue.

You might be low spec?

The problem is a lot worse when I use my code with the procedural meshing, but I also think that this is not the main issue. Ah and the hardware is definitely fast enough (i7-4940MX, 16GB RAM, GTX980M).

Lag is generated from collisions, especially the UpdateCollision function, i had this problem too and this function is taking 90% of the time. What i did was splitting my mesh up in different sections and generate them over frames, this could help you to reduce the lag. I was making an openworld game, but instead of only generating surface, i was also drawing boundary triangles, like some box. Removing those boundaries improved frame time a lot.

Hey there,

I have tried to answer this once, because I thought I had the correct answer, but now I have played around with this a lot and I have found the solution for my performance problem:

I used the function UKismetProceduralMeshLibrary::CalculateTangentsForMesh to automatically calculate the tangents for my ProceduralMeshComponent. But this function has an exponential runtime, depending on the number of vertices you put into the MeshSection that you want to calculate the tangents for.

First I mitigated the problem by limiting the number of vertices in each MeshSection and increasing the number of MeshSections per Mesh. But then you get a problem with performance, because of the increased number of draw calls needed for each MeshSection.

Finally I just used my own function to calculate the tangents for my mesh, which had a linear runtime and thus I had no problem with generation time or performance anymore.

TL;DR - Don’t use UKismetProceduralMeshLibrary::CalculateTangentsForMesh, it has an exponential runtime.

Answer to the question, if CreateMeshSection resets the MeshSection, if an already existing SectionIndex is used:
Yes!

I looked it up in the ProceduralMeshComponent.cpp:


    // Reset this section (in case it already existed)
    FProcMeshSection& NewSection = ProcMeshSections[SectionIndex];
    NewSection.Reset();