Quantcast
Viewing latest article 17
Browse Latest Browse All 112

optimizing a forest.

So i'm trying to make a forest and iv been looking into combining the various tree meshes into one, but then i heard someone say something like: once they are combined, they will all want to render regardless of being on screen or not. because unity is going to think they are all one mesh now. so now i'm totally lost, all i can do is fall back on my beginner knowledge and i make this script: #pragma strict var dist:float; var player:Transform; var trunk:Renderer; var leaves:Renderer; var trunkEnabled:boolean; var leavesEnabled:boolean; var leavesDist:float; var trunkDist:float; function Start () { toggleTrunk(); toggleLeaves(); } function FixedUpdate() { dist = Vector3.Distance(transform.position, player.position); if(dist>trunkDist) { if(trunkEnabled) { toggleTrunk(); } } else if(dist>leavesDist) { if(leavesEnabled) { toggleLeaves(); } if(!trunkEnabled) { toggleTrunk(); } } else { if(!leavesEnabled) { toggleLeaves(); } if(!trunkEnabled) { toggleTrunk(); } } } function toggleTrunk() { trunk.enabled = !trunk.enabled; trunkEnabled = !trunkEnabled; } function toggleLeaves() { leaves.enabled = !leaves.enabled; leavesEnabled = !leavesEnabled; } this script just makes the trunks and the leaves stop rendering after a certain distance (50 for trunks, and 40 for leaves). so far this seems to work alright, iv got around 3k trees packed pretty densely and i'm averaging around 260 draw calls and 150k verts on screen while looking out through the forest. it seems to run fine, i don't lag or anything. but it just feels wrong to me to have 3000 scripts all trying to get the players distance every fixed update. is this normal, or can i do something better? also, if anyone has an general advice on optimizing forest environments that would help me alot, because knowledge is half the battle, and i am ill equipped. - side note: my trees i made have 548 tris / 614 verts each.

Viewing latest article 17
Browse Latest Browse All 112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>