Chapter 13.0 Level Optimization: Techniques and Tools

In Unreal Engine 3, interactions between lights and objects are responsible for the majority of CPU and GPU work that needs to be done to render a level. When optimizing content in a level, the best place to start is usually by examining how things are lit.

CPU Overhead
On the CPU side, the major expense of lighting lies in figuring out what objects need to be rendered, and whether or not they are using light environments; and if so, which type of light environment they are using. Since most games using UE3 Have a lot of dynamicly lit moving objects, it is easy to use too many light environments. There are several settings, however, that you can use to reduce the cost of light environments.

GPU Overhead
For the GPU, having to render a pass per light per object can be quite expensive for objects covering a large portion of unoccluded screen space. The main limiting factor on the GPU is usually shader throughput. For example, having an object lit by three lights, in addition to suffering the additional per-pass overhead, will cause the lighting equation and material to be evaluated three times.

In general, stats commands can be used for various asset types in a level. See the Stats Descriptions page for detailed descriptions of stat commands supported by the engine.

Lightmaps have the benefit of reducing both CPU and GPU load. On the CPU side, fewer light-object interactions need to be taken into account; as far as the engine is concerned, the objects aren't relevant to the light, as all lighting information has been baked into the lightmap. On the GPU side, the object doesn't have to be rendered in multiple passes and additionally the lightmap pass is collapsed into the emissive pass to further reduce the number of passes and induce state change overhead.

Dynamic Shadows
Another potential source of performance problems is dynamic shadowing. A quick way to gauge whether dynamic shadowing has an impact on performance is to toggle it off via the SHOW DYNAMICSHADOWS console command. It is advisable to bind a key to this command, so that while the key is pressed dynamic shadows are turned off and then enabled again when the key is released. This can be done from the console - for example: SETBIND F SHOW DYNAMICSHADOWS | ONRELEASE SHOW DYNAMICSHADOWS.

Static Meshes/Primatives
A common source of performance problems is in Static Meshes. In general, you should replace any Static Meshes that are used only once or twice, and replace them with similar ones that are already used frequently. Try to avoid using unique meshes for skyboxes whenever possible. Whenever possible, apply the proper trade-off for vertex lighting vs. lightmap lighting. You can also use the Primitive Stats Browser to look for biggest bang for the buck optimizations (sort by instanced triangle count).

The complexity of the materials in a scene can greatly affect the GPU overhead of the scene. The more dynamic lights that are used, the more costly an expensive material becomes. The editor offers a Shader Complexity Viewmode. Lighter shades of green mean the material is fairly cheap, darker shades indicate a more expensive material, or multiple dynamic lights affecting. Note that to see an accurate representation of shader complexity, the level must have lighting rebuilt.

Static Decals that are placed in the level can eat up performance quickly if not handled properly. If left unchecked, they will project onto extra meshes that are not necessary, and this will skyrocket the amount of Sections that have to be rendered. They should be set to only affect the static meshes/BSP that they need to affect, since this can significantly reduce section count.
Using Decals and the Decal System

Skyboxes usually contain very large objects whose bounding boxes/spheres encompass large portions of the world. This has several notable side effects. Firstly, objects intersecting the near clipping plane will not use occlusion queries and always be rendered, even if no pixels of the mesh are visible. This is usually not a big deal for unlit domes that aren't affected by light, as the engine first renders a depth pass to maximize the utility of early hardware z-rejection. There can be some cost associated with state changes and additional overhead if your skybox is lit and hit by many lights.

Miscellaneous Optimization Techniques

Quick Level Optimization Tips
  • Make sure skybox is unlit, doesn't accept decals, lights, doesn't collide
  • In the Primitive Stats Browser, sort by count and instanced triangles:
    • Eliminate/ reduce instances for meshes that are used a lot.
    • Make sure simplest mesh is used for high inst. triangle counts (for example if 2000 triangle is used 100 times, consider using 200 triangle column).
  • Use collision view modes to disable collision where not needed.
  • Play the game to see what is visible, often times meshes are added that are not visible when playing the game normally as Editor viewpoint doesn't match where the player moves, eye height, etc.
  • Make sure there are no meshes hidden below the world, inside geometry, etc.
  • Mark all BSP surfaces that are no visible as to not accepting lighting.
  • Set default texture on invisible BSP surfaces.
  • Use VIEWMODE LIGHTCOMPLEXITY to ensure level is black where there are no dynamic lights:
    • Only use toggleable lights of small radius.
    • Don't use toggleable directional lights.
  • Keep total static mesh and static mesh section count under budget. 
Final Optimization Techniques

Verify loaded content in-game (not in-editor)
You can make sure only vehicle and weapon assets that are loaded are being used by running the OBJ LIST CLASS=SKELETALMESH command. Follow up with gameplay programmer if this is proven otherwise. For example, in the past we've had issues where certain Kismet actions referenced too much content.
Other useful commands:
  • LISTSOUNDS for audio
  • LISTTEXTURES for textures 
Run "analyzereferencecontent" commandlet
Make sure there are no meshes with excessive convex hull counts. Also try to optimize the most-used meshes. Optimize worst case material offenders, especially once used a lot

No comments:

Post a Comment