Vegetation

What would be the best way to paint vegetation over a generated mesh? I’m working on a procedural world generator that works by generating a mesh from a series of vertices (for reference, I’ve based it off of Brackeys’ procedural terrain YouTube tutorial), and I’m at the stage where I need to add vegetation. Specifically grass.

I’ve tried randomly instantiating massive amounts of grass objects over the landscape but that killed performance before I even really got a particularly thick coverage. I experimented with setting the meshes to only render at a certain distance and only when the player is looking at them, but that only helped marginally, and I can only imagine it would get worse when adding more complicated meshes such as trees and bushes.

I’m aware that Unity offers terrain generation tools, and I would use them, but I need something that will work with my custom mesh, and not a terrain object made with Unity’s built in tools which to my knowledge is not possible. Unless I’m wrong? Anyway, any help would be greatly appreciated!

For the placement take a look at Poisson Disc Sampling. Sebastian Lague has a nice video on it.
To not kill performance take a look at culling, gpu instantiation, LOD, billboards and not overdoing it otherwise.

Grass is actually a heavy performance hitter, hence why very few games have extremely lush environments. However, contrary to your assumption, adding trees, rocks and other props would most likely not increase the performance hit that much, since you’d have to render less grass (the one that’s behind the objects) when doing occlusion culling.

Be aware that performance is generally an advanced topic.

ohhhhhh interesting. So if you handle the culling right, then placing a bigger variety of objects can actually reduce the number of objects rendered? That’s very clever, thanks.

Also I checked out Sebastians video on poisson disc sampling and as far as placement goes, that’s exactly what I was looking for, thanks! The concept is actually similar to what I was already doing, but this specific method solves some issues I was running into. Sebastian is a god; I’ve seen a few of his videos before but wasn’t aware of this one, so thanks for the recommendation.

when you say “billboards” are you referring to converting meshes to sprites as they get further away?

More like, if you place bigger objects closer to the camera, then everything fully hidden by them does not need to be rendered. And since bigger objects like trees generally dont have equally as much complexity (and mostly require one instead of many drawcalls), this can save performance. In the end it comes down to the number of drawcalls, as well as the complexity of the scene (triangles) that actually needs to be drawn. This is true, unless you are bottlenecking on the CPU or performing other heavy operations (like ray marching, heavy shading, …) on the GPU.

Yes. Actually, i’ve never used this myself (mostly since i’m rather working on algorithms than actual scene design), but i know that there is some option which turns far away objects like trees into billboard representations of themselves, saving quite a bit of performance and, when done right, being unnoticable.