- Home /
Improvements to a grass system
I have been trying to make a grass rendering system that is as simple as possible, but this doesn't seem to be working that well, in the sense that it requires a lot of "unaccounted" ms to render and in general takes around 10-20ms just to render the grass. Here is my current code, improvements to the code would be nice, and I have tried simplifying it as much as I could:
private Camera cam;
public Mesh grassMesh;
public Material grassMaterial;
public int grassRadius = 25;
private Bounds bounds = new Bounds(Vector3.zero,Vector3.one);
void Update () {
Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
for (int x = -grassRadius; x < grassRadius; x++) {
for (int y = -grassRadius; y < grassRadius;y++) {
Vector3 pos = new Vector3 (x * 1.5f, 0.5f, y * 1.5f);
bounds.center = pos;
if (GeometryUtility.TestPlanesAABB(frustumPlanes, bounds)) {
if (Vector3.Distance (transform.position, pos) < grassRadius) {
Graphics.DrawMesh (grassMesh, pos, Quaternion.identity, grassMaterial, 0);
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
how to make an horizontal mesh? c# 0 Answers
Weapon system 0 Answers
UNITY4 all i see is the triangle/verts of objects 1 Answer
Does using Mesh Collider use up more CPU verses just a box Collider? 1 Answer
Passing Underneath Section of a Mesh 0 Answers