Setting Up Precomputed Visibility (Killing Floor 2)
Introduction
This documentation aims to explain what Precomputed Visibility is, the benefits of using it, when it should be implemented and miscellaneous things to consider when approaching and tweaking it. The official documentation is important to read to grasp a stronger understanding of it (https://api.unrealengine.com/udk/Three/PrecomputedVisibility.html) however this page will tend to cover aspects not covered in the documentation and aspects more specific to Killing Floor 2.
What is Precomputed Visibility?
As a means to increase performance, most game engines try to reduce the amount of things rendered on the screen by using a technique called Occlusion Culling. In a general sense, when a user is not looking at something, or an object is fully hidden/obscured behind another, it should not be rendered as the user cannot see it. Unreal Engine 3 has an automatic system set up for this called the Dynamic Occlusion System. By default all maps made for Killing Floor 2 will use this in some form or another. This is fine in a general sense but it does require additional performance cost in determining what should be rendered and may encounter some problems and fps drops when rapid moving the camera or moving around corners.
Precomputed Visibility (PCV) aims to increase performance by statically saving the occlusion culling to the map. Doing so allows the engine to determine immediately what should be rendered instead of requiring iterations and queries used by the Dynamic system, ultimately increasing rendering time and FPS.
Traditionally PCV is used on mobile games and some consoles. It is used in KF2 since we use a deferred renderer instead of the front renderer typically used in Unreal engine based games. The function is to keep the draw calls in a manageable area and squeeze as much performance as possible out of the maps.
It should be mentioned that PVC is a different rendering system from the Distance Rendering you can set for individual actors in your map. Further discussion on Distance Rendering can be found here. However both should be used to improve your map's performance.
TL;DR: Its a method to increase performance in the map.
Should I and When Should I?
Ideally, all maps for KF2 should try and be as optimized as possible - This means that eventually, yes, you should do it. However, depending on your map size and even your PC hardware, you may want to consider some things:
- Adding PCV to your map will SIGNIFICANTLY increase your lighting build time.
- Small maps which might take 1min to build lighting may now take up to 30mins to even 2 hours or more to fully build.
- Full Sized maps (Eg: Outpost, Paris, Biotics may even take up to 7-9+ hours depending on your hardware).
- You can, disable the requirement to build it in the lighting build options. See Figure 1.1.
- Hardware significantly impacts build time
- PCV build time is solely dependent on how powerful your CPU is. The more cores and threads your CPU have - the faster the build will be.
- Using an Outpost sized map as an example the build time can very based on your CPU
- i7-8700k @ 4.3GHz - Looking around 7-9 hours in build time
- i7-2700k @ 3.4GHz - Looking around 14-18 hours in build time
- These are from my personal experience - feel free to contribute so people can get a perspective on build times.
- TWI also experience these long build times, and have mentioned they often build them overnight.
- Using an Outpost sized map as an example the build time can very based on your CPU
- When PCV is being built, all threads will be occupied and be running at near 100%. As the build will be fully occupying the CPU - you should not use the computer for any other major tasks. Doing so may result in the SDK crashing or longer build times.
- As the CPU will be running at full capacity - you should closely monitor CPU and ambient temperatures as it is under a heavy load. Make sure you have sufficient cooling for your system.
- PCV build time is solely dependent on how powerful your CPU is. The more cores and threads your CPU have - the faster the build will be.
- Smaller Maps Benefit from PCV more than Larger or Full Sized ones.
- PCV is most efficient for for small to medium maps and enclosed spaces/rooms. The performance gained from large maps and open maps may be negligible in the end.
- A Small-Medium sized maps (The Descent) may see an whopping 10+fps increase while large open maps (Outpost) may only receive a 1-3fps increase.
- This does not mean PCV is not valuable on larger maps as any improvement in performance is desirable.
As PCV can significantly increase the build time of a map, you should only implement as the very LAST step before you publish your map. This is when you are 100% confident you do not need to place, move or edit anymore actors/meshes to your map.
How do I set it up?
- TODO
Best Practices for Volumes
There are 3 ways to shape volumes for PCV:
- Encompass the Entire Map in one Volume
- This is the worst and least efficient method to create PCV Volumes. The build time is enormous using this method and is not recommended.
- You will also create visibility cells that are outside the playable area and never used. Essentially resulting in wasted build time.
- Split the map into different 'sectors' or 'fragments' based on room and general layout of the map
- A much more efficient and logical approach to the volumes; shaping the volumes to conform to the shape of the rooms. Build time is better but not the best.
- This will have more accurate visibility cells but may still create them outside the playable area.
- Use multiple small volumes to encompass the entire.
- This will result in the fastest build times
- This will also provide more accurate visibility cells as you are not encompassing large areas.
- This is the best option.
The Official maps do not have a standard for how volumes are set up; different maps use all the different options. This does not mean it is the 'best' practice because it is in the Official maps. I recommend using Option 3 for best results and faster build times.
Debugging and Troubleshooting
When your build is finished, you can use the following commands to evaluate and debug PCV:
TODO
PCV will automatically detect materials with a Blend Mode of 'BLEND_Translucent' (see-through materials) and not cull objects when looking through something like glass. However it is not reliable, always double check to make sure that the final build doesn't mess with hiding some meshes or lights that shouldn't be hidden.
In a similar sense, meshes that are 'Hidden in Game' and are not translucent will still be viewed as a visibility blocker. This can result in things being culled that shouldnt be when in game - simple solution is to use a BLEND_Translucent material so PCV acts as if it is glass (eg: get the standard glass material, swap the textures and give it 100% opacity to make it look opaque/solid).
External Links
Official UDK Documentation - Precomputed Visibility
Steam Guide - Precomputed Visibility: What is it? Why use it? By Kill Master