ProceduralMeshComponent Material Advice

Currently I am working on a procedurally generated block game, more of an experiment than anything else.

Currently I’m spawning blueprints of boxes made from 6 sides, hiding faces and setting materials to it as needed, and this is working fine so far, however, the problem is each face is a separate static meshes and in world that’s about 48 X 48 X 48 blocks that’s a lot of static meshes and the game runs slow,

So I want to use the Procedural Mesh Component to Segment the world and vastly reduce the number of draw calls.

Currently each face has it’s own Material Instance Dynamic Which has the texture it’s using and the lighting information. The plan for the Procedural Mesh is to generate a lightmap texture dynamically and assign it to the material but currently procedural Meshes can only have one uv channel making it tricky to use both a lightmap and a diffuse map. not impossible but harder.

So I was wondering how viable would it be to do what I am currently doing as far as having a MaterialInstanceDynamic for each face, I.E. Having thousands of Mesh Sections and thousands of MaterialInstances for each Procedural Mesh Component. Doing it this way would make is so I would not have to generate a light map at all and have to worry about the UV’s of the mesh, and just generally make what I’m trying to do easier.

True that the component is experimental but as it stands now how possible (Stupid, odd) is doing it that way?
Would it kill any performance gains, would it take up way to much memory.

I am currently working with creating a voxel based terrain. What you want to do, is generate your voxel data and then generate your mesh based on that data. Having so many separate meshes causes an over abundance of draw calls which will cause low fps.

my current process is not optimized yet but basically, after you generate your voxel data, you need to iterate over each voxel and if the current voxel is solid, check it’s neighbor voxels and if a neighbor is not solid, generate the vertices and indeces for the mesh to cover that side and add those to a TArray. When the iteration is complete, take the vertices and indices arrays and create your mesh section.

My current implementation doesn’t create any duplicate vertices which is accomplished by storing the vertex and index in a TMap in c++. if the vertex already exists, don’t add it to the vertex array. Instead, get the index and add it to the index array.

Materials and texturing is going to be a bit harder. I haven’t got to that point yet in my project and I’m going about it a different route anyway so I can’t really help there at the moment.

Recently I tried the approach of using as many sections as there are faces and it did not go well. I was able to light the whole thing real easy this way but I offered not performance boost over just using a whole bunch of static meshes for each face.

So I dumped the lighting for now and instead add a face to a section and gave each section a unique material. All grass faces are in the grass section all stone is in the stone section. Doing so boost the performance By a ton. I’m definitely going to have to continue like this if I want to make a big world.

It also means I’m going to have to generate a light map to pass the procedural meshes material as parameter. Not a big deal but more work is all.

Things are going pretty good now!, I managed to get lighting data on the vertex colors of the mesh but doing so meant sub dividing each face. But now I looks good and is running real smooth. The only thing is Ambient Occlusion doesn’t quite work right on the mesh, I don’t know if it has to do with the fact that I’m not setting the vertex tangents or not also Transparent surfaces are getting a lot of ordering problems, such as water. Either way things are going great now.

WOW you guys are heros! I used the exact same procedure that you mentioned but I created a mesh section for each face which destroyed my FPS from 120 to 35 with only 256 voxels. Now everything is going much better.

2 Questions however:

  1. If I understand correctly you create a mesh section for each material type?

  2. Do you think it would be possible to instead of creating a few different mesh sections for each material type, create one mesh section that uses a single material containing an atlas map texture of all the material types in one. Effectively reducing draw calls even further?