Generate Procedural Mesh

Gravity point and procedurally generated planets:

https://www…com/watch?v=PLzu-nCjhA8

Very nice Xilverback!
Very impressive Tefel!

Thnaks! I am working with new 4.9. There is a lot of useful things. Thanks Epic team.

Anyway I read there is ‘fast path’ Update Mesh. I thought is also for triangles change but I realize there is no triangles array ;/

Hi lspangler, I think I was experimenting with the same Dual Contouring reference library, and couldn’t work out the source of the rough edges – data doesn’t cause it. Apart from the edge of the mesh, you can see it in some other ares with more detail (for example around the square hole in the ‘ground’ mesh). Dual Contouring itself should not be causing these errors. My suspicion is that the QEF implementation that I used (and that you probably use as a reference) has an error somewhere…

Those rough edges really start causing problems when you start looking into tiling the world, and creating different LODs. Some work arounds that I saw are all about creating ‘mesh skirts’ to fill the gaps, but that seems to be incorrect approach.

Let us know how you get on with it…

[=lspangler;361844]
EDIT: Yep I’ve fixed my problem. I don’t think it’s really that relevant to anyone else so I won’t put the solution here (basically just me being dumb)
Anyways, I basically have dual contouring implemented:


So if anyone has any questions about that I might be able to help.

I still have to figure out how multiple materials, multiple chunks, and texturing is going to work so I have quite a bit of work before the basic terrain is there.
[/]

If anyone has an interest, I forked 4.9 release and added support for an additional UV set in ProceduralMeshComponent (also required changes to DynamicMeshBuilder). It’s probably not suitable for a pull request to Epic as I was forced to ‘require’ the additional UV for some unrelated editor based users of DynamicMeshBuilder (there are some overlapping dependencies on the PMC that I wouldn’t have expected)

If you have Epic access, you should be able to see/acquire my changes here: .com/casperjeff/UnrealEngine/tree/proceduralmesh_multi_uvs
I haven’t run across any negative side effects - although its very possible I missed something (first engine tweak for me)

My team is using the additional UVs to pass in custom data to store with the mesh so that we can do some material/shader trickery (change emission settings) based on reading these non-texture based uv values.

Enjoy!

Any advice on how I should go about aligning the edges of adjacent meshes? I don’t want to just set the front row of one equal to the back row of the other since that wastes quite a few vertices, but I guess I’m at a loss for a better option.

[=The_Shane;375662]
Any advice on how I should go about aligning the edges of adjacent meshes? I don’t want to just set the front row of one equal to the back row of the other since that wastes quite a few vertices, but I guess I’m at a loss for a better option.
[/]

If these are two separate meshes, you can’t do it any other way. You have to have vertices in the same location, one set for one mesh, and another for the other mesh.

Did you see inigo post about Procedural Fractal ‘Volumetric Decals’?

It’s fantastic!

Hi ,

With Procedural Mesh Component, I managed to render the landscape as a mesh, divided up into sections just like the landscape. You can set the landscape to any size, any quad size, and it will match.

On the left is the landscape. On the right is the mesh output which is completely from blueprint, uvs and all. I have a few questions!

  1. The normals are smoothed as if the vertices are shared across triangles. However, I’m purposely creating every vertex of every triangle, then feeding unique elements into the triangle array with the intent on having completely faceted normals. Obviously this isn’t happening. Any help on achieving faceted normals without a shader?
  2. Is it possible to cast this as a static mesh so I can paint vertex colors?
  3. Any idea on sampling the terrain layers’ diffuse textures to a vertex color? Ideally I’d get each diffuse/albedo and X and Y coordinate in world space, look that up in uv space on the diffuse with tiling taken into account, then store that pixel color off. Then I’d determine the blend weight, lerp as needed, then store the result as a vertex color. Move to the next vertex and repeat. But, I don’t know if any of that sampling is available?

P.S. As you can see, triangles on the far right border of the procedural mesh are not set correctly. The linetracing is not hitting the terrain correctly at section borders, so I have to slightly bias the raycast inward per-border-vertex. I have it on the left and bottom borders but not the top and right.

And the blueprint just for fun:

Thanks for your help!

I solved the faceting issue. I thought that feeding unique values into the triangle array would do it, but averaging the vertex normals manually did the trick.

Now to figure out how to sample layers.

[edit] Small update. I was getting some odd world normals between my sections. Seams were visible. I rolled my own mesh normalization function and it cleaned it up, though since no vertices are shared it’s nice and faceted.

HI guys,

this thread is pure gold for anyone trying to create procedural geometry. thanks! I have a question, and I was hopping that you could know the answer: is it possible to render the procedural geometry as points (think point cloud) instead of tris?

thanks!

[=indie_unreal;382374]
HI guys,

this thread is pure gold for anyone trying to create procedural geometry. thanks! I have a question, and I was hopping that you could know the answer: is it possible to render the procedural geometry as points (think point cloud) instead of tris?

thanks!
[/]

I think ue only supports triangles, and triangle strips this time.

[=indie_unreal;382374]
HI guys,

this thread is pure gold for anyone trying to create procedural geometry. thanks! I have a question, and I was hopping that you could know the answer: is it possible to render the procedural geometry as points (think point cloud) instead of tris?

thanks!
[/]

You can do that propably a lot easier with a custom particle editor module. I described how to do that here: Free Particle Editor Module for Spiral Galaxies - Community & Industry Discussion - Epic Developer Community Forums

Hi. This is mine one uncompleted land mesh generator:

You can define:

  1. Texture to generate from (shoud be grayscale and power of two)
  2. Material assign to generated mesh
  3. Generated mesh size
  4. Polygon size
  5. Optimization type:
  • 	None, // without optimization
    
  • 	AxesAlternately, // 2 pass: first Y then X
    
  • 	FrontAndBack, // 1 pass: front on Y and back on X	
    
  1. Downsampling type
  • 	None = 1, // Same as original
    
  • 	TwoTimes = 2, // 2 times lower
    
  • 	FourTimes = 4, // 4 times lower
    

Bugs:

  1. Rectangle and Square optimizations are not finished still. Maybe i will make it later, maybe not.
  2. Optimized mesh has wrong normals. I do not know yet what to do with normals and how to calculate it better.

Sources and example project at :
https://.com/h2ogit/UE4HeightMapGenerator

Class ATestHeightMapLand can be spawned and used in any project, just add .cpp and .h files

[=;290656]
Hey I’m working on a to save procedurally generated meshes as an asset at the moment. I haven’t got much so far but I have an asset type and an editor which you can create lathes in:

It’s still very much a WIP but I’ve got some big plans for the such as being able to edit meshes in world and their editor as well as being able to save them back to a static mesh for efficiency. I’ll probably make a thread about once I have something ready to share but it’s too basic at the moment.

It might not look like much but it took over 2000 lines of code just to get that much!
[/]

How is it going, did you get the saving working yet?

[=JamesG;282933]


[/]

I’ve been messing around with this over the last few days, but I’m having some issues generating a mesh properly.

I’m using a function from 's Victory BP Library to access the vertex positions of a static mesh, then I create the grid mesh triangles based on those. However, since I’m lacking UVs, I don’t think tangents are being calculated properly, so weird things happen:

Is there a way to access the UVs of a preexisting mesh using blueprint (or code)? I’m not quite sure how to access that data.

This is the relevant segment of my blueprint.

[=Aunt Jemima;390304]
I’ve been messing around with this over the last few days, but I’m having some issues generating a mesh properly.

I’m using a function from 's Victory BP Library to access the vertex positions of a static mesh, then I create the grid mesh triangles based on those. However, since I’m lacking UVs, I don’t think tangents are being calculated properly, so weird things happen:

Is there a way to access the UVs of a preexisting mesh using blueprint (or code)? I’m not quite sure how to access that data.

This is the relevant segment of my blueprint.
[/]

“Calculate Tangent For Mesh” calculates smooth normals, if you look at the normal buffer vizualisation you will see that the normals looks very odd for your mesh, ie the sharp corners dosnt have sharp normals :stuck_out_tongue: You will just have to calculate the normals/tangents yourself.

This code is what I use to calculate flat shading:

I’ve been messing around with ProceduralMeshComponent for modifiable terrain. While I have vertex generation and all that going on in separate threads the game stutters for like a second when swapping out the actual meshes (which I have generate physics enabled for). How many vertices do people usually shoot for when creating terrain chunks? I’ve also had issues with Mesh sections just disappearing when replacing sections, I don’t know if anyone knows whats causing that? I’m not sure if I should stick with ProceduralMesh for this or switch to making my own mesh component.

[=;392031]
I’ve been messing around with ProceduralMeshComponent for modifiable terrain. While I have vertex generation and all that going on in separate threads the game stutters for like a second when swapping out the actual meshes (which I have generate physics enabled for). How many vertices do people usually shoot for when creating terrain chunks? I’ve also had issues with Mesh sections just disappearing when replacing sections, I don’t know if anyone knows whats causing that? I’m not sure if I should stick with ProceduralMesh for this or switch to making my own mesh component.
[/]

Our sections are about 2000-5000 vertices, and update physics (and recreating scene proxy) seems fast enough even on slower computers. You should attempt to do as much calculation on a separate thread and leave only physics and render mesh update on game thread.

Note about ProceduralMeshComponent – out of the box SceneProxy declares itself as Dynamic (via Result.bDynamicRelevance = true). This causes render thread to call GetDynamicMeshElements() each frame – make sure you leave this function as lean as possible. Alternatively, it works quite nicely if SceneProxy uses bStaticRelevance instead, but requires coding of DrawStaticElements() override.

We went one step further to employ Instancing of procedurally generated meshes, by combining code from InstancedStaticMesh* and ProceduralMesh* to get to performance comparable to Unreal’s stock foliage system.

The only missing item for us is baking static lighting at runtime :slight_smile:

Hi guys,

I’ve been trying to assign additional UV channels with the method proposed before:


NewData.TextureCoordinates.Add(FVertexStreamComponent(VertexBuffer, STRUCT_OFFSET(FMultipleUVDynamicMeshVertex, UV0), sizeof(FMultipleUVDynamicMeshVertex), VET_Float2));
NewData.TextureCoordinates.Add(FVertexStreamComponent(VertexBuffer, STRUCT_OFFSET(FMultipleUVDynamicMeshVertex, UV1), sizeof(FMultipleUVDynamicMeshVertex), VET_Float2));
NewData.TextureCoordinates.Add(FVertexStreamComponent(VertexBuffer, STRUCT_OFFSET(FMultipleUVDynamicMeshVertex, UV2), sizeof(FMultipleUVDynamicMeshVertex), VET_Float2));
NewData.TextureCoordinates.Add(FVertexStreamComponent(VertexBuffer, STRUCT_OFFSET(FMultipleUVDynamicMeshVertex, UV3), sizeof(FMultipleUVDynamicMeshVertex), VET_Float2));

From Blueprint I can access these parameters in materials through the TextCoord nodes using only even indices (0, 2, 4, 6). Does anyone know, how can I fill odd UV channels as well using C++ code?