Announcement

Collapse
No announcement yet.

Procedural Mesh for terrain - Tiled approach bad for performance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Procedural Mesh for terrain - Tiled approach bad for performance

    I am looking into ways to implement simplistic terrain surface which would allow for deformation in realtime. Procedural meshes seem to be the answer.

    Recently I have put together the following setup:

    Click image for larger version

Name:	1.png
Views:	1
Size:	2.2 KB
ID:	1196753

    This is a procedural mesh component defined by 4 (relative) points.

    P1 = 0x, 0y, 0z
    P2 = 0x, 200y, 0z
    P3 = 200x, 0y, 0z
    P4 = 200x, 200y, 0z

    In my event graph, I create a mesh section, feeding in the 4 points as vertices. When I start it up, the mesh is generated as a 200x200 tile. Great!

    I then used a nested loop to create a 10x10 grid of these meshes, essentially creating 100 tiles in a square to be used as a terrain surface. Now it takes a couple seconds for the game to start but it's not really an issue. The problem is the continued low performance when moving around. Turns out having 100 procedural mesh actors on the screen at the same time takes its toll on the performance. My camera is top-down so I can limit the number of actors on screen by lowering the camera or increasing the size of the actors but this seems like a poor solution.

    So I guess it would make sense to use a single 2000x2000 mesh rather than 100 200x200 meshes. But this introduces a problem - I don't know how to do that. I would need to have vertices every 200 (or less) units, effectively ending up with a mesh like this:

    Click image for larger version

Name:	2.png
Views:	1
Size:	888 Bytes
ID:	1196754

    I need all these vertices because I will be manipulating them in real time to deform the terrain. The value I pass to the Vertices would need to be an array vector containing all these points. I suppose I could run another nested do loop, adding vertices to an array until it encompasses the grid, but what about the triangles? Honestly, I don't know how to tackle this.

    Is this even how it is normally done? I feel like people have to have come across this issue and dealt with it so I'm looking for other solutions here.

    #2
    Currently procmesh is rendered as a dynamic object. As of 4.13 you can merge procmesh to a regular static mesh. You just need to have created the component using the components dropdown in the BP as opposed to an "add proc mesh" node.

    I have tested this and was able to make and merge a 512x512 grid. I did have to go into project settings and increase the max loop iterations by x10 to allow it to finish though. But then you select the proc mesh component in the details panel in the world and a 'create static mesh' button should appear in the details panel below a bit.
    Ryan Brucks
    Principal Technical Artist, Epic Games

    Comment


      #3
      Originally posted by RyanB View Post
      Currently procmesh is rendered as a dynamic object. As of 4.13 you can merge procmesh to a regular static mesh. You just need to have created the component using the components dropdown in the BP as opposed to an "add proc mesh" node.

      I have tested this and was able to make and merge a 512x512 grid. I did have to go into project settings and increase the max loop iterations by x10 to allow it to finish though. But then you select the proc mesh component in the details panel in the world and a 'create static mesh' button should appear in the details panel below a bit.
      He needs deformation on runtime, and he would lose that feature if he would convert the mesh to a static mesh.


      [MENTION=19051]Chumble[/MENTION] Take a look at the Runtime Mesh Component (RMC), it has improved performance over the PMC:

      https://forums.unrealengine.com/show...nerated-meshes!
      Easy to use UMG Mini Map on the UE4 Marketplace.
      Forum thread: https://forums.unrealengine.com/show...-Plug-and-Play

      Comment


        #4
        Originally posted by John Alcatraz View Post
        He needs deformation on runtime, and he would lose that feature if he would convert the mesh to a static mesh.


        [MENTION=19051]Chumble[/MENTION] Take a look at the Runtime Mesh Component (RMC), it has improved performance over the PMC:

        https://forums.unrealengine.com/show...nerated-meshes!
        Sounds great but unfortunately I'm having a tough time getting the plugin installed. I created a plugins folder and extracted the file from here so it currently is

        C:\Users\<user>\Documents\Unreal Projects\<project>\Plugins\RuntimeMeshComponent_v1.2\

        At this location, there exists a RuntimeMeshComponent.uplugin so I believe it is in the right path. When I try to launch my project though, I get

        Click image for larger version

Name:	1.png
Views:	1
Size:	5.2 KB
ID:	1116582

        If I press no (because I don't want to disable it), I get

        Click image for larger version

Name:	1.png
Views:	1
Size:	15.5 KB
ID:	1116583

        Click image for larger version

Name:	1.png
Views:	1
Size:	5.4 KB
ID:	1116584

        The documentation indicates simply putting it in that location should be enough.

        Comment


          #5
          What engine version are you using? You could also try to just install it from the UE4 Marketplace, that should be easier.
          Easy to use UMG Mini Map on the UE4 Marketplace.
          Forum thread: https://forums.unrealengine.com/show...-Plug-and-Play

          Comment


            #6
            4.13.1 - installing it from the marketplace seemed to work. Giving it a test now

            Comment


              #7
              Holy cow - Yeah the performance is MUCH better. I experienced absolutely no performance issues with the same setup I had with the procedural mesh.

              So I guess there's no real need to replace this grid of meshes with a single grid. Still, I wonder if it's the smart thing to do.. using a single mesh over a ton of small ones.

              Comment


                #8
                Originally posted by Chumble View Post
                Holy cow - Yeah the performance is MUCH better. I experienced absolutely no performance issues with the same setup I had with the procedural mesh.

                So I guess there's no real need to replace this grid of meshes with a single grid. Still, I wonder if it's the smart thing to do.. using a single mesh over a ton of small ones.
                A little late, but...

                There are tradeoffs to one larger, vs multiple smaller meshes especially with terrain. First up, one large mesh means that the whole thing draws if the bounding box overlaps the view frustum. Since terrain, especially procedural, can be large and high poly, this probably isn't going to be a great idea. It also means that updating small areas require copying much larger pieces of data around. Multiple smaller meshes allow the culling to draw much less, but at the cost of higher draw call counts. There's kind of a balance between the two and there's no exact number as it depends on your project.

                Glad to hear the RMC helped!
                Runtime Mesh Component - The best way to render procedural/runtime created meshes! - Version 4.1 out now!

                Come talk about anything RMC or Procedural Mesh Related in our Discord!

                Comment


                  #9
                  I've decided to go with the smaller meshes (specifically, 200x200) over the larger ones. So far, my biggest headache is finding a good way to keep them linked.

                  What I mean by this is when I modify the vertex on one mesh, the corresponding vertex needs to be modified on the 3 connected/surrounding meshes.

                  Click image for larger version

Name:	Untitled.png
Views:	1
Size:	2.4 KB
ID:	1116835

                  Take this scenario with a 3x3 grid of meshes. There are four major vertex intersections, labeled as A B C and D. If I wanted to raise the vertex of mesh 1 at A (bottom right corner), I need to raise the bottom left corner of 2, the top right corner of 4 and the top left corner of 5.

                  My first method of dealing with this was by creating collision spheres at each corner.

                  Click image for larger version

Name:	Untitled.png
Views:	1
Size:	3.0 KB
ID:	1116836

                  (in this picture I only drew them at the important intersections though they exist at all corners).

                  Now when I want to raise one corner, I can also look to see what other meshes exist and collide with the sphere. But this introduces a new problem. If I get all overlapping actors for that mesh, I get three meshes and no way to identify which one is which. I need to know which one is which because I need to know which corner to raise since it is different for each one. So then I added additional collision spheres.

                  Click image for larger version

Name:	Untitled.png
Views:	1
Size:	4.2 KB
ID:	1116837

                  These spheres allowed me to identify that 4 was below 1, so I need to raise the top right corner. 2 is to the right of 1 so I need to raise the bottom left corner. Then, by using the corner overlap, I got all actors and made sure they were not 4 or 2. The remaining one has to be 5, so I raised the top left corner.

                  Overall, I hate this method. It's incredibly messy in every way. The only advantage I see to this is it's dynamic, allowing me to add additional meshes to either side and it will be able to adjust properly. But I can't help but feel like there has to be a better way to handle this.. it seems like such an easy problem that I'm having such a hard time with.

                  While typing this, I did just think of one other thing.. using boxes instead of spheres for collision.

                  Click image for larger version

Name:	Untitled.png
Views:	1
Size:	2.5 KB
ID:	1116838

                  I only drew the ones for mesh 1 but the idea is that each box collides with 1 and only 1 mesh. This eliminates the problem of having multiple colliding meshes for one collision.

                  But it's still messy.

                  Anyone have any better more clever solutions for this?

                  Comment


                    #10
                    Have a look at what we have been working on. May be what you are looking for.
                    https://forums.unrealengine.com/show...174#post638174

                    Dave

                    Comment


                      #11
                      Originally posted by Chumble View Post
                      I've decided to go with the smaller meshes (specifically, 200x200) over the larger ones. So far, my biggest headache is finding a good way to keep them linked.

                      What I mean by this is when I modify the vertex on one mesh, the corresponding vertex needs to be modified on the 3 connected/surrounding meshes.

                      .....

                      Anyone have any better more clever solutions for this?

                      I had to deal with the exact same problem.
                      To know the position of the vertex inside the chunk(TopBorder, bottomBorder, TopLeftEdge, etc.) you can use a little math.


                      let's say you have ChunkSize = 200.
                      Now you want to know the position of the vertex with the LocalChunkCoordinates (199, 0).

                      This gives you the result (x=1, y=0). Which is the top border.
                      Click image for larger version

Name:	dfggfghfg.JPG
Views:	1
Size:	34.2 KB
ID:	1120138


                      Text Example
                       
                      Spoiler


                      BP mockup example:
                       
                      Spoiler

                      Comment

                      Working...
                      X