Technique for volumetric grass. Texturing question.

I’m working on generated, volumetric grass tiles. They are created during runtime from layers of quads with transparent textures :

(Ignore rear tiles, they are a different type of grass)

Right now just using a single quad prefab that gets generated multiple times vertically, for each tile. Each layer texture is identical, with alpha cutoff decreasing based on height.

The problem:

Limited to two dimensions of detail.
A plan for 3D grass is to use layers of different textures to create a false 3D object.

A grass model sliced into 100 layers :

This code is attached to the root tile object and generates the layers :

	// Input values
	public GameObject grassLayer;
	public float patchHeight;
	public int layerCount;
	public float cutoffMin;
	public float cutoffMax;

	private float x, y, z;
	private float layerSep;
	private Renderer rend;
	void Start() {
		layerSep = patchHeight / layerCount;
		for (int i = 0; i < layerCount; i++) {
			x = transform.position.x;
			y = layerSep + i/(1/layerSep);
			z = transform.position.z;

			// Create/name/inherit grass layers
			GameObject go = (GameObject) Instantiate (grassLayer,
		                                          new Vector3 (x, y, z),
		                                          Quaternion.Euler (90, 0, 0)); = string.Format ("layer{0}", i);
			go.transform.parent = transform;

			// Set material parameters
			rend = go.GetComponent<Renderer>();
			rend.material.shader = Shader.Find("Legacy Shaders/Transparent/Cutout/Diffuse");
			rend.material.SetFloat("_Cutoff", (cutoffMax/layerCount) * i + cutoffMin);

What is a good method for creating 100 materials with unique texture that can be using for all grass tiles generated?

Your approach would be absolutely horrible, performance wise - each material is a seperate shader pass in the final render which has it’s own CPU and GPU overhead. It’s a good performance practice to keep the material layer as down as possible - it’s why the new physically based shading is so popular, it’s a way to generate nearly every surface you need with one material.

If you wish to go with layer generation technique, you want to generate them using shaders (so you basically have one plane in the game with one material, which is rendered as a dozen or so layers), this is a technique more commonly referred to as “fur shader”, google that and see what comes up.

But in total I believe the final result will not be satisfactory for displaying Grass on terrain, especially if this is a third or first person perspective which allows the camera to get close to it.

Currently there’s really no rock solid and high performance way to actually render out real blades of grass like that. Crysis 3 had an approach where each blade of grass is tessellated set of several long thin triangles, connected by joints that behave with realistic physics but the scene where that was heavily used was notorious for bringing down even the highest end PCs to it’s knees.

nVidia has a few tech demos demonstrating realistic grass turf rendering but the complete toolset is still experimental as far as I know.

I think you’d be best to sticking with standard Terrain grass painting tools.