- Home /
Question by
MakakWasTaken · Aug 16, 2016 at 08:12 PM ·
shaderoptimizationgrass
Grass performance
I can't come up with more ways to improve this and it doesn't even receive anywhere near the unity terrain system (with only around half the vertices)
Here is the code:
private Camera cam;
public Mesh grassMesh;
public Material grassMaterial;
public int grassRadius = 50;
private Bounds bounds = new Bounds(Vector3.zero,Vector3.one);
void Update () {
Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
Vector3 curPos = transform.position;
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)) {
Graphics.DrawMesh (grassMesh, pos, Quaternion.identity, grassMaterial, 0);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
What- if anything- is wrong with this shader (alpha/reflective/unlit)? 1 Answer
How to make Standard Shader _Color property be Per Instance Data? 0 Answers
Can I make this world reveal shader have more than 1 source of reveal ? 1 Answer
Any tools for profiling shaders? 1 Answer
Alpha channeled grass 0 Answers