Optimizing

Hi, I would like to know how to optimize my level. I have made this terrain (2000x2000) that has some trees and some grass, but not much. Then I have placed 16 copies of a house, that has about 2000 polys and some other props around the level. My terrain uses 5 different textures. I have reflective water underneath the entire level. Then I have 2 point lights and a directional as the sun, which isn’t casting any shadows.
When I’m using a FPSCounter script I found on this forum I’m only getting about 12 FPS. I’m testing it on a new IMac in a web player.

Am I wrong when I think I should get a lot more FPS? Or is this what I can expect from Unity?

Hey lakru,

Terrain optimization (and level optimization in general) is a fine art, but here are some basic tips.

First off, anything over 4 textures on a terrain and you’re making a separate pass on it. So you may as well go up to 8 and add some more detail. Unfortunately at this point you can’t delete textures from a terrain, so unless you want to re-paint the terrain from scratch your stuck with your work so far. This will hopefully be fixed in an upcoming release of Unity.

Are you setting the “Tree Billboard Start” and “Detail Distance” reasonably? This will drastically help your performance.

How much grass? Grass is a performance killer if not used sparingly. If you do need dense grass try making it taller (this makes it look like it’s covering more ground) and lower the distance until the “pop” factor is acceptable.

Bake the lighting into the terrain. This is only possible with Directional lights at the moment. It will look better though and help a little with performance.

Play with the “Pixel Error” setting in the terrain… usually this can be set extremely low without noticeable difference and can help.

How many textures/materials do your houses use? Are they one material or many? Each material costs you another draw call. Combine textures into sheets as much as possible.

Are all 3 of your lights pixel lights? That’s no good either. Only use pixel lights when absolutely necessary. Usually vertex will do the trick.

A great thing for you to do is to go through the Island Demo and pick it apart a little bit. Check out some of the terrain settings and also how other meshes are set up in that scene.

Try some of this and let us know if the framerate goes up a tad.

Welcome to Unity!

Ethan

Hey again,
and thanks for the answer.
After your reply I made a new terrain and started to add my models, one at a time, duplicated my house 50 times and some of the other models. No influence on FPS. Then I added grass (like really painted all the terrain with the biggest brush and highest density) only one or two fps lower. Then I added a tree and painted all over and it cut the FPS down in half. I then deleted all the trees, but the FPS is still on half. How can that be. I’m thinking that the FPSCounter script isn’t working. Now I’m not really a programmer/scripter so maybe one of you guys can see if anything is wrong here:

// Attach this to a GUIText to make a frames/second indicator. 
// 
// It calculates frames/second over each updateInterval, 
// so the display does not keep changing wildly. 
// 
// It is also fairly accurate at very low FPS counts (<10). 
// We do this not by simply counting frames per interval, but 
// by accumulating FPS for each frame. This way we end up with 
// correct overall FPS even if the interval renders something like 
// 5.5 frames. 

var updateInterval = 2.0; 

private var accum = 0.0; // FPS accumulated over the interval 
private var frames = 0; // Frames drawn over the interval 
private var timeleft : float; // Left time for current interval 

private var show = false; 
private var text : String; 

function Start() 
{ 
   if( !guiText ) 
   { 
      print ("FramesPerSecond needs a GUIText component!"); 
      enabled = false; 
      return; 
   } 
   timeleft = updateInterval;    
} 

function Update() 
{ 
   if (Input.GetKeyDown ("1")) 
      show = !show; 
       
   timeleft -= Time.deltaTime; 
   accum += 1.0/Time.deltaTime; 
   ++frames; 
    
   // Interval ended - update GUI text and start new interval 
   if( timeleft <= 0.0 ) 
   { 
      text = "" + (accum/frames).ToString("f1"); 
      timeleft = updateInterval; 
      accum = 0.0; 
      frames = 0; 
   } 
    
   guiText.text = show ? text : ""; 
}

Or is it like when you have first added a tree to your terrain it will have influence on you FPS even if you don’t use it in you level?

To answer your question, then my house consists of 5 textures I know that is a lot for a house, but it is a big one. And as I mentioned it didn’t have any influence on the FPS. What do you mean by combining textures into sheets?

-Lasse

:sweat_smile:

Hi again.
Am I the only one who are having problems with FPS when I’m playing around with the terrain?

I have a level which is pretty detailed, with a high FPS.
When I add two textures to the terrain, it lowers the FPS a lot. And when I paint some trees it gets even worse. And with some grass it gets totally unplayable.
How can that be? When I run around in Tropical Paradise the FPS is nice and it has a lot of texture, trees, grass etc.

Is it possible to load up the tropical paradise level to see the tricks?

If you have more than 4 textures on the terrain it will need to render it in 2 passes as you can only use up to 4 textures for the blending in an SM2 shader. → 1 pass per 4 textures on the terrain

Trees uses ambient occlussion etc and trigger something internally. Don’t ask me what but the performance hit is independent of the amount of trees up to a quite “dense” vegetation.

The Island Demo uses Texture-FILES of 1024 x 1024 but use import settings of 512 x 512 per texture. You should check that for more performance. Also make sure, the texture import setting is set to create mip maps.

Do you have anisotrophic filtering on? And on wich level? A setting of 1 gives a big quality push without hitting performance too much.

On a standard G5 PPC 2.5 i get about 40 - 60 FpS with 8 textures and vegetation, wich is enough for a decent multiplayer shooter.
But i had to turn off anti aliasing. With this function active the FpS drop to almost half performance.

I hope this helps you in some way

Frank

Ok, but I only have two textures on my terrain. That shouldn’t have a drastic impact on my FPS?
And I have about 100 trees.
I don’t really understand the Unity engine :roll:

100 Trees can do a serious impact on performance, when the start billboard is set too far away. Maybe all trees are rendered 3D instead of using the billboard…

But you are correct, 2 textures should have no big impact on performance.

Have you tested the terrain alone, without your house-models and stuff? Maybe your problem lies somewhere else…

Maybe you should try setting the pixel-error setting to a value above 10 if you havent done that already. A 2000 x 2000 units terrain on a pixel-error setting of 1 would result in some million polygons to render per frame…