- Home /
How to optimize custom grass?
Hey
I have made a procedural terrain generator, the problem is, I tried adding grass the easy way, e.g. texture on a plane is being spawned at a vertex, however, even with that little (compared to what you usually achieve with built-in terrain) amount I got a significant FPS drop, so how would I add vegetation? Or there is no easy way?
Answer by FortisVenaliter · Apr 21, 2017 at 08:35 PM
Well, first, use the quad instead of the plane. It uses like 1/64th as many polys.
But there are, in fact, dozens of ways... however, each have their benefits and drawbacks. I'll list a few I can think of off the top of my head below, but I'm sure there are more comprehensive lists/guides to be found elsewhere online:
Static Batching - basically cram as many grass quads as you can into a single mesh, but that eliminates billboarding
Point Extrusion - define a mesh of points, then use the geometry shader to convert into billboarded quads
Height mapping - similar to #2, but use one repeating flat mesh 'tile' and pass a heightmap to make sure the same mesh can fit itself to any terrain.
Keep in mind, you're also not limited to one method. You can switch methods per LOD to make more expansive grass run well.
Thanks!
I was planning to make it via #1 and still may do it this way, but #2 got me interested. Not easy since I'm new to shaders but seems very procedural-friendly.
Geometry shaders are typically slow and not that cross-platform compatable. I'd recommend investigating using the new GPU instancing feature, or simply a chunked dynamic mesh ins$$anonymous$$d.
Then I guess it's not worth that amount of time I would need to understand them, also as I calculated I get about 100-200k grasses per chunk (that being lowest good-looking amount) so that could be split into 12 grass meshes easily applied as LOD. Gotta check how it runs as 12 meshes, cause now I have 2-3 FPS on my mid-end PC. ~Actually 24, cause normals, but seems to run fine.
Your answer
Follow this Question
Related Questions
Vegetation problem 1 Answer
Optimizing vegetation. 3 Answers
how to import custom plants and grass into unity 1 Answer
Camera flickers near terrain grass/detail on Mobile 0 Answers
Make a simple tree 1 Answer