|Top Previous Next|
The following snippet will allow you to:
- Plan the number of polygons for each entity in your level;
- Estimate the "system requirements" PC for your game;
- Get a significant frame rate increase in your big, detailed levels.
Open test1.wmp and then run it using the culling.wdl script:
There are some values that appear at the top of the screen:
- Culling distance (2000 quants) tells the engine to remove all the entities that are placed outside the culling range (farther than 2,000 quants);
- Visible entities (86) tells us the number of entities that are visible on the screen at a certain moment;
- Visible model poly (412,244) gives the number of model polygons that are rendered each frame;
- Visible map poly (258) gives the number of map polygons that are rendered each frame;
- Used memory (3 MB) tells us the video memory consumption;
- Free memory (155 MB) tells us the amount of free video memory that is left on the 3D card;
- Fog range (20,000 quants) gives us the range of the fog (if the fog is enabled);
- Frame rate (15 fps) gives the frame rate.
It looks like my PC doesn't quite enjoy rendering that many (over 400,000!) polygons per second; however, if I will wait for a few seconds, many of the spheres will be removed automatically. By the way, each sphere has about 10,000 polygons.
What has just happened here? The engine has removed all the entities (the spheres) that are placed farther than 2,000 quants to the player, bringing the frame rate to a good 45 fps. Press and hold the "space" key, and then click the "Manual culling" button. You are now able to adjust the "Culling range" slider and see how its value affects the number of entities that are displayed, and thus the frame rate. Oh, and keep pressing "space" while you are adjusting the slider as well.
You can see that a culling distance of about 3300 quants will display about 330,000 polygons on my PC at a playable 21 fps. The useful culling distance values for my demo will only be in the 1,000 - 10,000 quants range, because I wanted to add as many polygons as possible in a small area. Get your own culling distance in your "real" levels, and then use it to remove the entities that are far away my making them invisible, just like I did in my demo, or use the culling distance for camera.clip_far and so on.
Ready for something new? Press the "Auto culling" button (once again, press and hold the "space" key to do that). Now you can set the desired frame rate and the engine will add / remove the spheres automatically, in such a way that the frame rate will be kept close to the value you've set using the slider.
The values will change a bit over time because the spheres have many polygons, but you can get an average number of polygons that will guarantee a certain frame rate on your PC.
The picture above tells you that I can have about 240,000 polygons visible per frame on my PC if I want to keep the frame rate at about 30 fps. This means that I should plan the poly count for my trees, buildings and so on in such a way that I never go over 240,000 polygons. I can have millions of polygons in my level, but I shouldn't be able to see more than 240,000 polygons at once. If you have a faster computer, you will be able to display even more polygons per frame. And if you can run the demo on several computers you will be able to get a good "system requirements" estimate, based on this combination: number of visible polygons and the resulting frame rate.
Please keep in mind that the "Auto culling" mode shouldn't be used in a real game - it's sole purpose is to help you estimate and plan your level entities and geometry in order to achieve a decent frame rate on a certain computer. Let's test the fog system now: click "Manual culling", and then click "Fog".
Adjust the "Fog range" slider until the fog covers the spheres that are far away from the player. As a general rule, "Fog range" should have a value that's close to the culling distance.
We can test the culling system in real time, because our player can be moved using the arrow keys. Move the player in the level and you will see the hidden spheres fading in gently as you approach them. Press the "Fog" button again to disable the fog.
The code allows you to prevent an entity from being culled; you will probably need that for (let's say) an arrow that points towards the destination - you wouldn't want it to be culled at all!
Do you see the guard model that is far away? It wasn't culled because I have checked its flag8. Do the same thing for all the entities that shouldn't ever disappear.
Here's how you can use the code in your levels:
- Attach the action named "my_entity" to all the entities in your level that don't have any other action attached to them;
- Ignore all the entities that have an action attached to them already;
- Check flag8 for all the entities that should never be culled.
I am using ent_next to go through all the entities and make them visible or invisible one by one. If your level contains thousands of entities you might want to use a faster method, like several parallel-running starter functions that check the distance between the objects and the player and show / hide the entities.