This post will give you a simple run-down of some of the static mesh LOD features provided by Lumberyard, which Third Kind Games will be using in our new title: The D.R.G. Initiative.
A lot of this blog post is pulled from the Amazon documentation and collated together for ease of reference. There will be a future post detailing skinned mesh LODs.
Static Mesh LOD
Level of detail (LOD) techniques are used to increase performance and reduce draw calls by displaying progressively lower detailed objects the further they are from the camera. Generally, each LOD should have its vertices reduced 50% from the previous level and a reduction in the number of materials used. Lower LODs should also have multiple textures combined into one texture to further reduce draw calls.
DRG takes place in a huge arena with numerous large and complex objects in it. Some of these objects are made from tens of thousands of triangles, which, if we tried to render all of the time would slow the action down to a miserable chug. Adding LODs to these objects will automatically swap out the meshes for lower triangle count versions when the camera is above a certain distance away from them. The distance at which the meshes will swap is predominantly controlled by two variables; the Max View Distance and LOD Distance Ratio, more on these later.
Static Mesh Guidelines
- The Base mesh (LOD 0) has no prefix/suffix. Every successive LOD should be a separate object that is linked/parented to the base mesh with the suffix _lod1, _lod2, etc.
- For clarity, you can also add more information the name of the LOD node, i.e. _lod1_sphere or _lod2_justforfun. The engine only takes the first 5 characters into account.
- You will want to reduce the number of material IDs as much as possible; this will decrease the amount of draw calls your LOD produces. Ideally, the last LOD should only have one render material ID assigned. The r_Stats 6 CVar will allow you to view how many draw calls your objects are producing.
- Each successive LOD step should save 50% of triangles. (i.e. 1200 -> 600 -> 300 triangles) or have the number of rendering materials reduced. A warning message will be displayed during export if the triangle reduction is above 66%.
- Currently, up to 6 LOD’s are supported. This number is hard-coded and may change in the future. The e_LodMin/Max CVars will allow control over which LODs are used on a global scale. Objects can have LOD’s for every sub node. LOD’s must be linked/parented to the nodes they should substitute during rendering.
There are a couple of CVars which will help you check that your LODs are being used, I will just list out the ones we at Third Kind Games use.
e_DebugDraw = 1 – Will cause the name of the used cgf file to render to the screen, along with polycount, and the used LOD.
r_Stats = 6 – Displays the draw call count for each object instance in the scene. The numbers above each object are broken into total draw calls, zpass, general, transparent, shadows, and misc.
If you’re feeling like doing a bit of programming, it is pretty straightforward to improve on the functionality that Lumberyard provides and add custom rendering to show information about objects with no LODs at all, or to only call out objects with a triangle count of higher than a specified value.
LOD Distance Ratio
This ratio is what affects the distance at which LOD transitions will start happening. The higher the value the quicker you will move through the LODs as the camera moves away. By using this combined with the max view distance set on the object you can control how and what you will see at different distances. These are set on the static mesh component and the best way to get a feel for them is to set up an object with a couple of LODs, turn on e_DebugDraw = 1, and experiment with the values.