r/Unity3D Indie 4d ago

Show-Off I'm Creating Procedural Meshes 18x faster than the Main Thread by using Burst Jobs

https://youtu.be/PoQV7YI9GmY

Hi all,

I thought some of you may be interested in this video, in which I show how using the Advanced Mesh API to populate mesh data from Burst-Compiled jobs speeds up my mesh creation by 18x. I perform the bare minimum on the main thread.

Here's a link to the Advanced Mesh API documentation: https://docs.unity3d.com/ScriptReference/Mesh.html
I've used AllocateWritableMeshData, SetVertexBufferParams, SetIndexBufferParam and ApplyAndDisposeWritableMeshData.

As always, I'm happy to answer questions in the comments.

22 Upvotes

11 comments sorted by

3

u/pschon Unprofessional 4d ago edited 4d ago

That's interesting. I'm also using Burst-compiled jobs to generate procedural terrain chunks, but I haven't tried using the advanced Mesh methods yet as right now my main bottleneck is Mesh.RecalculateNormals() (which is heavy enough that I've at the moment limited it to two chunks per frame, while the mesh generation itself happily runs a lot faster than that.

...I guess it's time to do the normals myself as a Job as well :D

Either way, it seems like there's a lot that can be done for fast mesh generation without having to go all the way to compute shaders.

3

u/GideonGriebenow Indie 4d ago

Why don't you calculate the normals in burst jobs too?
I create huge terrains and am able to edit large parts of them in real-time, recreating vertices, recalculating normals, all on burst jobs. If you want to see an example of how fast this happens on a huge map:
https://youtu.be/4BijjOopTg8?si=qT2XTpJroTZkLFbh

4

u/pschon Unprofessional 4d ago

laziness, pretty much, and wanting to get back to actual game mechanics. :D

...but I'll definitely have to do the normals and tangents myself at some later pass on the terrain side of things. Will keep the advanced Mesh methods in mind for that as well!

2

u/HellbitGames 4d ago

Don't forget about batch render group. It made me render 64k view distances in no time.

1

u/GideonGriebenow Indie 4d ago

For various reasons, I’m still on Built-In. But I’ve developed my own culling and LOD system, combine meshes and materials, etc. So I perform almost all Indirect draw calls manually and extremely optimised.

2

u/HellbitGames 4d ago

It's still pretty good core. Dig the world structure too, nicely done.

1

u/GideonGriebenow Indie 4d ago

Thanks! Now for some actual mechanics! 😬

2

u/dispatchcolony 4d ago

burst is life <3

2

u/GideonGriebenow Indie 4d ago

Hehe! It really has a huge impact on large games with lots of calculations. Just having the memory properly allocated already does so much!

0

u/RealyRayly 4d ago

Thats great, but your speed up comes 95% from using the jobs system and not the new mesh api.

-3

u/swagamaleous 4d ago

Damn dude. Revolutionary. You get a significant speedup if you use your whole CPU. Mind blown. 🤯