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));
go.name = 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?