How do I optimize this scene?

Hi,
I’m working on a level for a simple game I’m designing. It’s mostly for educational/demonstration purposes.
Before I commit fully to developing it, I have a few questions which I think need to be addressed now rather than later. The questions are about optimization.

I have created a single tree and plan to use many of them for the nature environment I’ll be using to host my game.
The tree has only 744 faces, see here: http://www.pasteall.org/blend/17649
and is linked to this scene: http://www.pasteall.org/blend/17650

After watching quite a number of tuts, I was under the impression that this is how it’s done, i.e. create low poly assets in separate files and link/append them to the main scene. So I’ve linked the tree a few times to the level scene and gave it a go to test how things are coming up.

What is alarming, is that I only get say 15-20 fps with that scene, that is without linking any of the other props/assets (which might be low poly but then again so are the trees). Not only that but the rasterizer seems to range from 30-80% upon drawing this simple scene!

My laptop is not exactly cutting edge but it’s got a dual core cpu, 4 GB ram, and runs linux. It’s my main machine and I use Blender on it every day without problems (except say sculpting after using 5+ mutlires levels). So I wouldn’t think it’s my system to blame for this, just my design of the game.

#1. What am I doing wrong? Its the tree design an overkill? What’s the best way of approaching this?
#2. How can optimize this, cos I fear that if I link more assets it’s not gonna be playable anymore (unless of course playable means 1fps).

Hope the problem description is clear.
thanx in advance

Please make sure the paths are relative when linking in the groups. As for your specs, you never mentioned a graphics card, do you have a dedicated graphics card? The BGE has been known to perform pretty poorly on an Intel graphics chip. Also, you might want to consider somesort of LoD and make your trees 2D planes out past a certain distance.

Hi, thanx for taking the time to check this out and respond! :slight_smile:
Relative paths are enabled by default and I usually not change this setting.
I’m not sure why this is relevant though. I mean if they are not relative then linking wil not work at all.

As for your specs, you never mentioned a graphics card, do you have a dedicated graphics card?

yep:
01:00.0 VGA compatible controller: Advanced Micro Devices [AMD] nee ATI RV620 [Mobility Radeon HD 3400 Series]

The BGE has been known to perform pretty poorly on an Intel graphics chip.

well, apparently this is not an Intel integrated graphics chip we’re talking about here.

Also, you might want to consider somesort of LoD and make your trees 2D planes out past a certain distance.

I can look into LoD but I’m wondering how much of a difference it can really make if the scence is loaded with lots of other models -no matter how low poly they are.
In the meantime I’ve continued testing and I’m getting disappointing results with the fps dropping about 5fps at both FullHD and HD! :frowning:

The libraries are absolute in your file: /home\ilias\007\Eleftheria ree_01.blend

You’re right, sloppy texture packing on my part.
Here’s the new file which should work:

http://www.pasteall.org/blend/17659

Any ideas?

sample_level.blend is still using absolute paths for the library (the group).

http://www.pasteall.org/blend/17662

There I’ve re-created the links. Does it work now?

Thanx for bearing up with my sloppiness :0

I get 60fps with your scene. I’m on Win7 64bit with an NVIDIA GT 425M.

60fps?!
I’ll be damned! :0

So this was optimal to begin with? Wow!!!
Shall I presume that this the way to go then?
Even if it means that I won’t be able to play the game on my pc?
Any thoughts?

Well, the fact that it’s running at about 100fps on my machine with vsync disabled is a bit troubling. I did notice you had the size of your shadow map very high (try 1024 or lower), but playing with this didn’t make a large impact. Removing trees made a much larger impact, which means it’s something to do with the trees. Taking a look, I’d say you’re probably fragment bound. Since your leaves have spec, normal, and diffuse maps, they’re going to have some spendier shaders. Since they’re transparent, I don’t think they write to the depth buffer, which means you’re probably going to have massive amounts of overdraw.

so go for 512 texture maps then, that’s not a problem

Removing trees made a much larger impact, which means it’s something to do with the trees.

that’s what I suspected as there are only trees involved in the scene :frowning:

Taking a look, I’d say you’re probably fragment bound.

Uh, what does this mean? Too many faces/verts or something else?

Since your leaves have spec, normal, and diffuse maps, they’re going to have some spendier shaders.

Two questions:
#1. are these maps the bare minimum for making a semi realistic (or say good-looking) game? From what I gather I should also include AO maps if not others
#2. Shall I use diffuse maps only?

Since they’re transparent, I don’t think they write to the depth buffer, which means you’re probably going to have massive amounts of overdraw.

So you mean that I should avoid transparent materials? But what is the alternative? Modeling branches and leaves by hand?! Wouldn’t that dramatically increase the poly count?

Many thanx for helping out!

Basically, those transparent faces are expensive, so try to have fewer of them. Also LoD should help a lot.

Ok, thanx!
I’m still working on it, got up to 30 fps by unwrapping several branches on a single plane instead of one like I did in my earlier tests. Despite the use of alpha, it looks more promising at the moment.

As a side-note, it can be faster to have a single high-poly object over keeping them separated as many low-poly objects. As an example, if you’re going to be seeing a lot of a forest at any time, then maybe you could split the forest up into pieces and merge together the trees for that section. That way, the BGE won’t spend time drawing each individual tree when it could just draw the parts of the forest that are necessary to draw (i.e. the section you’re in, or the whole thing, if your card can handle it).

This kind of relates to what SolaLune said ^ Blender has an easier time rendering duplicates.

100 seperate soda can meshes will run faster than 1 mesh of 100 soda cans. UDK runs the same way. I don’t remeber what it is called though. :o

I once built an indoor map out of chunks (different floor tiles, ceiling tiles and wall tiles) And when I joined all the chunks the frame rate dropped 40 frames.

cam.dudes, you’re wrong there.
1 mesh of 100 cans runs faster than 100 of 1.

I am very surprised to hear about your decrease in frame-rate in that scene. Did you add anything else (shaders, textures etc)?

Nope, it was in multitexture. 2.49 I think. I know though for a fact that UDK runs better with duplicates (or groups/prefabs). I just assumed that since that scene slowed down when the meshes were joined that is was the same issue. I even removed over 1000 doubled vertices and it took a dive.

The BGE will take a dive if you’re over-zealous with joining objects. The reason for this is that the BGE can skip drawing objects that are completely out of the view frustum of the camera (frustum culling). However, if you join all the objects in a scene together as one object, the BGE has to always render all of it since it will always be in the view frustum of the camera. The trick is to join objects that are close to each other so you can eliminate draw calls but still take advantage of frustum culling. I bet UDK does more of this behind the scene (automatic joining/batching).

I’d like to thank everybody for sharing their experience and expertise on this issue.

@ Lunarsole: I’ve tried that and it worked when I had joined say 3-4 trees in a lib file and linked it to the main level file.
I had a speed improvement of 5-6 fps. Not much but it’s a start. I should mention, however, that when joining many trees and linking them in the main file things got really slow, less than 5 fps! I guess Moguri’s latest post gives a very plausible explanation for this behavior.

I’ve been reading stuff and exploring the scene. Here are my current conclusions.

#1. Using half the FullHD resolution with a simple sun lamp, a single plane, and no other object in the scene whatsoever gives me no more than 30 fps!!! So I’m beginning to question all my former assumptions. Maybe my laptop is not up to the task after all. This also kinda explains why linking anything in the scene results in a massive fps drop! I usually never get above 30fps.

#2. If as Moguri suggested, it’s a bad idea to use many objects which involve alpha to make e.g. trees in the BGE, why do all relevant sources point to the exact opposite direction? Check this out for example: http://vimeo.com/5264890
It’s an ancient video of the YoFrankie BF game where this same technique is demonstrated. Is the idea to make heavy use of LoD and display the actual tree only from up close? So like use planes which display trees from a distance and replace that when the camera comes near the object?

#3. Shadows. I’ve experimented with shadows a lot. Turning them off or reducing their quality helps but less than I had anticipated.

#4. Lights. Using a sun lamp with shadows enabled is the most demanding of all. Fps drops to 15 or less, depending on the camera angle (i.e. scene is not populated with many objects yet so in some cases there is very little to draw). Using a hemi lamp was the most helpful one and resulted in considerable fps speed gains.

#5. Mist. I’ve read everywhere that it’s supposed to slow BGE down considerably but maybe it’s less than 5 fps. And the visual appeal makes it more bearable.

#6. Shading. GLSL is by far the most demanding. No more than 15 fps no matter what other parameters listed above I changed. Using multitexture is the fastest: regardless of how many objects I link I consistently get 60fps!!! Single texture sux big time visually speaking.

I’ve been linking assets from the YoFrankie game, mostly trees so I can compare things with the trees that I modeled and textured. The difference is not that big really but I get consistently more fps using the YoFrankie assets. Still, the overall performance is very disappointing as adding say 8 trees and a few other props brings fps to 15 or less.

ATM, all this sounds like a dark art! :frowning:

I only hope that it’s just my machine or my understanding that is not up to the task and not the BGE itself.

As for #1, if you’re really getting that bad of an FPS value with a simple scene, you need to either update your graphics card drivers (which can make a huge difference, if I recall. When I installed Linux, the community ATI drivers were really slow, but the proprietary ones were far faster), or use a less intensive graphic mode.

As for #2, I didn’t watch the whole tutorial, but he should be using Clip Alpha, which is basically alpha transparency that’s 1-bit (either on or off). That’s less intensive than normal Alpha transparency, but it’s slightly more intensive than normal Opaque graphics (I would assume).

The BGE isn’t the fastest engine, but it can do quite a lot at a good FPS rate. Your graphics card sounds like it’s struggling to draw in GLSL mode. As an example, what games can you play on your laptop? If you can’t play games at a high quality at a good framerate, then you probably won’t be able to develop them that way. Singletexture and Multitexture mode are both lower quality visually (they don’t allow for shaders or shadows, at least, not built-in), but they run a lot faster than GLSL mode. You should go with GLSL mode if you’ve got a good graphics card. Usually, one that’s built into the computer when you buy it isn’t up to the task of 3D modern gaming. However, a good graphics card can be purchased for not that much money at all, so it’s worth consideration.