lundi 24 juin 2013

Grass On Mesh Generator

 Intro


Grass On Mesh Generator (GrassOMG) is a powerful plugin for Unity 3D making it incredibly easy to render grass on any mesh, including standard Unity's terrains.

This generator can render high density of grass and will make your environments much more realistic and impressive. It has been developed with one word in mind: performance.

Find GrassOMG on the Asset Store here. [coming soon]
Try the web demo. [coming soon]



GrassOMG has been developed by the creator of TerraVol, a robust volumetric terrain engine for Unity.

Documentation

In order to use GrassOMG, you must create an empty game object in your scene and attach GrassOnMeshGenerator component to it.
Then, be sure to set all parameters value (see below) and press play to see the result!


int maxGrassObjects = 10000;
The number of grass objects to create. The bigger it is, the bigger will be the grass density.
GrassOnMeshGenerator (GrassOMG) handle objects in such a way that performance will not be impacted by this parameter (but of course, the more you have objects, the more there will be polygons in the scene).

int grassUpdatePerFrame = 1000;
This is the number of grass objects to update per frame. While the player is moving, grass objects must be updated to 'follow' him. If your player move fastly, you may need to increase this number. For a standard walking/running player (human speed), this parameter should be about 5% to 10% of the total number of grass objects (see first parameter).
Increasing this number will impact performance.

float drawDistance = 60.0f;
The draw distance of grass. The bigger it is, the more you will need grass objects to keep a good grass density.

Vector3 grassSize = new Vector3 (1f, 1f, 1f);

The size of a grass billboard. If a prefab is given (see grassPrefab parameter), it will be scaled with this value.

float textureTileX = 1f;
This is the horizontal tiling of grass texture on billboards. Ignored if a prefab is given.

bool scaleGrassPerArea = true;
This makes the grass bigger or smaller depending on its position. This way, the grass won't be always the same height and will look more realistic.

float scaleAreaPeriod = 30f;
The bigger it is, the less there will be variations in grass scaling (see previous parameter).

bool scaleOnSlopes = true;
Scale the grass depending on slope. The more the slope will be steep, the smaller will be the grass on it.

float minNormalY = 0.8f;
Grass will be placed at a position only if the Y value of the normal of the mesh at this position if greater than this number. This is equivalent to a slope limit. In other words, if the slope is to steep, grass won't be placed here.

float windStrength = 1f;
This will impact waving speed of grass.

Camera mainCamera;
Grass will be generated around this camera.

GameObject grassPrefab = null;
You can provide a prefab that will be used instead of default billboards to render grass.

Material grassMaterial = null;
This is the material that will be used on billboards. If a prefab is given, this parameter will be ignored.

bool castShadows = false;
Should grass objects cast shadows?

bool receiveShadows = true;
Should grass objects receive shadows?

int rayCastLayerMask = Physics.kDefaultRayCastLayers;
A Layer mask that is used to selectively ignore colliders when casting a ray to place grass objects. See Unity's Physics.Raycast documentation for more information. This allows you to choose on which mesh you want the grass to be placed.

Texture2D controlMap;
The control map is a texture that allows to define where grass should be generated in the world. This also impact how grass object are scaled around the world.
Grass will be placed somewhere only if the pixel corresponding to its world position has a green value greater than 0.
Grass will be scaled depending on the green value too.

Vector2 controlMapWorldSize = new Vector2 (1000f, 1000f);
What is the world size corresponding to the control map? For example, you could give a 512x512px texture for a 2000x2000 world.

Vector2 controlMapWorldOrigin = new Vector2 (0f, 0f);
What is the world coordinate of the (0,0) pixel of the control map? If your world is 1000x1000 and position (0,0,0) is in the middle of it, than origin would be (-500, -500).


Contact

I you have any question or want to give any feedback, please send an email to grassomg.unity@gmail.com