How to place grass on custom terrain mesh
I made a custom terrain mesh and textured it, now I want to place grass on it, but I don't know how. I only find info about grass with the unity terrain. I am not even sure what exactly to look for. What is the best/easiest way to place grass on a terrain? I'd like to do it in the shader if possible, but I guess I will need additional geometry if I want it to "stick out"? (Random example picture http://www.beamng.com/attachments/stuff-png.16516/) I'd appreciate a general outline on how to tackle this problem and maybe some links for further reading. Thanks.
You need to create a texture for your grass, then create the geometry that the texture will be rendered onto. Use each vertex in the terrain as a starting point for the origin where to render each instance of the grass geometry and using a pseudo random offset for each origin, you could render lots of grass fairly quickly
Google will provide many shader driven approaches and other techniques.
This is an old topic, but it’s still valid.
There are a couple of ways you can handle grass outside of Unity’s Terrain.
The most simple way is to create your own planar mesh and apply a shader with back face OR use a reversed V pattern which are really close to each other where each side is the mirror of the opposite. Then place that manually one by one in your scene. The trick is to make sure it’s both a static prefab as well as having it enabling GPU Instancing on the material. This will allow the grass to be either batched or having a single copy stored in the GPU and rendered with the lighting variation. (It’s one or the other, but by enabling both, the engine is the one which manage what’s where based on the priorities.)
The CON of that option is that it’s time consuming.
The slightly more complex by WAY faster option is to use a particle (shuriken) system with a Mesh emitter with 0 gravity and force and with the setting so that the grass appears on the mesh’s surface. You can make the grass particle infinite by disabling the “over lifetime” module in the particle, activating “Looping” + “Prewarm” and by typing “Infinity” in the StartLifetime option. Ideally, you would have to have a script that could call the Stop() function so that the particle stop calculating generating, but keep the instantiated particles in the scene.
If everything have been set right, this would generate the grass with GPU instancing.
The cool thing about this possibility is that you can controls the particles features like cast/receive shadows, the amount of grass generated, if the grass is affected by light probs and reflection probs or not, etc. It makes it easy to setup with advanced graphical options.
You can even setup a master shuriken particle system that generate different multiple kinds of grass and flowers if you set it up right.
The only CON to this option is the lack of LOD if you got some really complex geometry for the mesh on which the grass texture appears. (It does apply Midmaps if the textures has Mipmap activated!) If you wonder, yeah it’s possible to have the winds/force to affect particles… but that’s has to be done in the shader used for the particle.
It is very simple, Create one pdf like a grass texture. Place it in your unity package and goto terrain settings in 6th tab you can find a button lime a grass select it. select edit Details -> Add Grass Testure -> Detail Texture. in detail texture select the pdf file you have been created. adjuse the brush size and opacity. click your terrain.
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport