5
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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 System.

The simplest way is to create your own planar mesh and apply a shader with back faces or use a reversed V pattern which are really close to each other and where each side is the mirror of the opposite. Then place copies of those manually one by one in your scene. The trick is to make sure it's both a static prefab as well as having GPU Instancing enabled on its 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 will which manage what's where based on the priorities.)

The con of that option is that it's time consuming.

The slightly more complex but way faster option is to use a particle (shuriken) system with a Mesh emitter with 0 Gravity and Force and with Normal Offset set 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 and Prewarm and typing Infinity in the StartLifetime option. Ideally, you would have to have a script that calls the Stop() function so the particle system stops calculating generation, but still keeps the instantiated particles in the scene.

If these instructions are followed, this will generate grass with GPU instancing.

The cool thing about this possibility is that you can control the particle's 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 will generate multiple kinds of grass and flowers.

The only con to this option is the lack of LOD if you have some really complex geometry for the mesh on which the grass texture appears. (It will apply Mipmaps if the textures have Mipmaps activated!) If you wonder, yeah it's possible to have the wind's force affect the particles... but that has to be done in the shader used for the particle.

\$\endgroup\$
1
  • \$\begingroup\$ Hey thanks, I am working on other projects now, but will definitely try out the particle system setup. \$\endgroup\$
    – ElDuderino
    Sep 18 '18 at 8:17
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ I've also done this in the past using a Particle System to generate my grass quads. I disabled its animation so the grass wouldn't appear/vanish based on particle lifetime, basically using the system as a way to manage many billboarded textured quads efficiently. ;) \$\endgroup\$
    – DMGregory
    Feb 15 '16 at 14:57
-3
\$\begingroup\$

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.

Please Click the link For more details:

\$\endgroup\$
2
  • \$\begingroup\$ As said in the question, it's not a unity terrain, it's just a mesh I constructed myself. \$\endgroup\$
    – ElDuderino
    Nov 16 '15 at 11:59
  • \$\begingroup\$ you can't able to add normal grass in your own mesh. but if you create your own grass with animation means you can able place it manually it will work. \$\endgroup\$ Nov 17 '15 at 4:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .