Simulation / Modeling / Design

Tips and Tricks: Getting the Best Ray Tracing Performance Out of Unreal Engine 4.23

Roughly five months ago, we introduced you to the new ray tracing support (via DirectX Raytracing) in the 4.22 release of Unreal Engine. Recently, Epic Games released version 4.23 which brings a number of upgrades for those working with ray tracing. Even better, many of these new and improved features, such as enhancements to performance, quality, and stability, require no direct user effort. We highly recommend everyone working with ray tracing in Unreal Engine to upgrade to 4.23. In addition to adding features and enhancing performance, the new update addresses several DXR and D3D12 items that should enhance stability for most users. Below are more details on some of the improvements.

New RT Geometry Types

The 4.23 release adds full support for landscape meshes and procedural meshes as well as partial support for instanced static meshes , including foliage in ray tracing. A developer may wish to plan ahead for the addition of instanced static meshes, since the amount of geometry being processed during ray tracing can grow substantially. Fortunately, ray tracing generally scales very well as the amount of geometry in a scene increases; however, one must account for a few secondary effects.

First, all geometry instances require setup processing. The increase in geometry also increases CPU-related geometry setup costs. Next, the additional geometry can impact the quality of the ray tracing acceleration structure. Often, instanced static meshes include many overlapping geometry nodes, which may subsequently reduce the quality of the acceleration structure. To combat both of these issues, UE4.23 contains settings for culling instances based on range and size. Setting these appropriately helps manage the performance impact of the extra work. Finally, it is important to carefully evaluate whether the new geometric elements make a meaningful visual impact in the context of scene. For example, grass foliage billboards quickly add a lot of geometry, but rarely produce any notable visual benefit in reflections. Further, grass foliage billboards can cast undesirable shadows, and they are rarely allowed to do so for raster shadows.

; Whether to include Instanced Static Meshes in BVH
r.RayTracing.InstancedStaticMeshes [0|1]

; Whether to enable culling of instance data
r.RayTracing.InstancedStaticMeshes.Culling [0|1]

; Scale factor on how large clusters are
; Number represents a scale against the size of instances
; 5.0 means that clusters are 5x the size of the largest
; instance object
r.RayTracing.InstancedStaticMeshes.CullClusterMaxRadiusMultiplier

; Distance at which to cull a cluster
r.RayTracing.InstancedStaticMeshes.CullClusterRadius

; Threshold for when an object is considered small
r.RayTracing.InstancedStaticMeshes.LowScaleRadiusThreshold

; Distance at which to cull small objects
r.RayTracing.InstancedStaticMeshes.LowScaleCullRadius

As noted above, HISMs are only partially supported in 4.23. As with most other objects, they lack support for world position offset (often used to make foliage sway). Second, the shading can be subtly incorrect as the normal may lack an instance transform. These artifacts are subtle – typically only appearing in reflections – and are hard to notice.

New RT Shader Management

4.23 brings new support for DXR shader collections. This shader management feature enables less shader compilation and linking overhead as new DXR hit group shaders are streamed in. The result is fewer hitches, stutters, and a smoother experience for end users.

Additionally, steps have been taken to mitigate the costs of data management when binding large numbers of instances to a TLAS. For cases where many identical hit groups are used in the binding table, the record will be cached and reused rather than handling the resource tracking and binding separately for each instance. It is controlled by the following CVar.

r.RayTracing.CacheShaderRecords [0|1]

RT Shadow Enhancements

4.22 offered batching support for denoising of ray traced shadows, but it required one full screen render target for each light processed. 4.23 improves this by running shadows in smaller batches to keep the memory overhead down. The saved memory enables all ray traced shadows to receive batching whether they are denoised or not. Further, when possible, ray traced shadows now obey the light source’s scissor rectangle, which can dramatically improve performance in many cases.

; Number of shadows combined in a single batch
; controls max amount of memory used for shadow intermediates
r.RayTracing.Shadow.MaxBatchSize

RT Reflections Enhancements

Ray traced reflections received general performance improvements, but the biggest changes are in the handling of special cases. First, reflections now optionally sample environment probes on termination. This produces a visual result similar to multi-bounce reflections, but with performance comparable to a single bounce. Next, if the scene requires multiple bounces, performance can be dramatically increased by the accumulation of path roughness. Accumulating a roughness value along a path enables early termination when a ray has become too diffuse to resolve detail through multiple glossy reflections. This optimization reduces the cost of multi-bounce reflections in the Realistic Rendering sample by more than half. Finally, interactions with the clear coat material are substantially improved. The DXR Ray Generation Shader no longer fires two rays for every clear coat material interaction. Instead, the top coat is first checked to see if has a meaningful level of contribution and falls back to a normal material model when it does not. For example, this is handy when clear coat is used to simulate wet and dry patches across a surface. Additionally, ray traced reflections now optionally fallback to sampling a reflection probe for the undercoat (just like SSR), but with the additional capability of only performing the fallback after the Nth bounce. This ensures that the most important interactions are faithfully captured.

; Sample reflection captures to fill in data on early ray termination 
r.RayTracing.Reflections.ReflectionCaptures [0|1]

; Test accumulated path roughness to attempt to terminate rays early
r.RayTracing.Reflections.TestPathRoughness [0|1]

; Lowest strength of clear coat that invokes the clear coat shading model
r.RayTracing.Reflections.MinClearCoatLevel [0.0-1.0]

; Number of reflection bounces that will attempt to evaluate the full clearcoat model
r.RayTracing.Reflections.MaxUnderCoatBounces [Integer]

For more information on real-time ray tracing in Unreal Engine, please check out the prior post, “Introduction to Ray Tracing in Unreal Engine 4.22”.

Discuss (0)

Tags