This page contains suggestions you can use with Hardware Ray Tracing features.
Materials
The following suggestions work with Materials and hardware ray tracing features.
Ray Tracing Quality Switch Replace Node
Use this node to replace entire parts of your Material logic to lower the cost of features like Lumen hit lighting, ray traced shadows, and translucency with less complex logic. When applying these in your Material, it will affect any ray tracing with this material where it is applied in the Level.
The example below shows the Normal logic path with diffuse, roughness and normal map textures. The Ray Tracing path removes the Normal map texture and uses less complex logic for Roughness. This change makes the material cheaper to render for ray tracing effects, especially with Lumen hit lighting.
Click image for full size.
Ray Traced Shadows Per Material
Use the Cast Ray Traced Shadows checkbox to set whether this Material casts ray traced shadows. This is useful for controlling specific elements of any Materials assigned to geometry that should, or should not cast a raytraced shadow.
Testing Material Costs
Complex Materials can affect performance of hardware ray tracing features. Use the console command r.RayTracing.EnableMaterials to test performance impact.
Translucency Index of Refraction (IOR)
When setting up a Material for refraction with ray tracing, the Refraction material input controls the index of refraction (IOR) in your translucent materials.
The amount of refraction is set up in the Material applied to an object. In the Level, the post process settings control whether refraction is ray traced and the maximum number of refraction bounces that are possible.
Material Setup:
Enable Two Sided in your Material.
While this is not a requirement, single sided/non-manifold geometry doesn't have a good way of handling volume tracking or ray medium stacking. A two-sided material provides accurate results and is the recommended method for handling all translucent materials when using ray tracing translucency.
Set the Lighting Mode to Surface Translucency Volume or Surface Forward Shading.
Use the Refraction input to control the index of refraction.
Post Process Volume Rendering Features Setup:
These steps use the Legacy Ray Tracing translucency method, which is deprecated. It's only available when your project sets the console variable r.RayTracing.Translucency.Supported=1. The newer Ray Traced method has different settings: Max. Primary Hit Events, Max. Secondary Hit Events, and Use Ray Traced Refraction.
Under the Translucency category, set Translucency Method to Legacy Ray Tracing (Deprecated).
In the same category, set the following:
Refraction: Enabled
Max. Refraction Rays: Set the maximum number of rays to use. This should be a high enough value that it allows light to pass through to the other side.
Use a Material Instance to dynamically control the IOR of the material with instance results.
Controlling the amount of Refraction
The amount of refraction and light transport that takes place is controlled by using the Refraction input in a Material. The Post Process Volume settings must have the Refraction check box enabled and greater than 1 Max Refraction Rays set.
The translucent material below is using a refraction input value of 0.04. The post process has a Max Refraction Ray count of 6 to pass light through the translucent material.
The examples below shows how different refraction input values in the Material affect the index of refraction.
Dragging the slider shows the amount of refraction being applied from 0.01, 0.05, and 0.1.
The examples below demonstrate how the Post Process Volume Max Refraction Rays value affects light transport through the translucent material. A single ray does not provide enough bounces to escape the material, leaving it appearing darkened or black. Increasing the maximum number of refraction rays gives light a greater opportunity to escape the material. Not all materials or rays will require the maximum number of refraction rays, but in cases where more are needed, this may leave some materials looking darker than needed.
Dragging the slider shows the result of using 1, 3, and 5 refraction rays.
Single Sided and Two Sided Material Refraction
Ray traced refraction works with both single sided and two sided materials to allow light transport through the object's volume. While single sided materials are supported for refraction, two side materials provide physically accurate results and is recommended for all Translucent Materials using ray tracing transparency.
Use the Post Process Volume Max Refraction Rays property to set the number of refraction bounces light transport should use.
Light Transmission for Subsurface Profile Materials
Light transmission on materials using a Subsurface Profile is possible when the light source also has the Transmission property enabled on the Actor placed in the Level.
A small scattering simulation is run during the ray tracing shadow computation to compute the expected volumetric scattering distance through the medium to the shadow-casting light. The scatter distance is used during lighting to compute the in-scattering contribution from the light.
Sky Lights
Capturing distance objects, like a sky dome mesh, should be disabled for Sky Light contribution, unless it is needed. This saves some performance and optimizes the scene.
The BP_SkySphere sky dome mesh and Blueprint that is included with starter Levels has this sky light contribution disabled by default. It will make reflections from sky look different than expected but saves performance with hardware ray tracing.
Object contribution is enabled/disabled from the Details panel with the checkbox for Visible in Ray Tracing when the object is selected in the Level.
Geometry Considerations with Ray Tracing
Geometry with small holes, or lots of little details, can significantly impact performance. For example, trees and bushes with lots of leaves, or grates and fences that have holds in them.
Indoor environments are slower to render than outdoors ones because often light enters from the outside and is expected to bounce around well enough to light a room. Areas that are directly lit by a light are faster to render than ones indirectly lit by light. Also, consideration with other ray tracing features like reflections and translucency affect performance in these situations.
General Optimizations for Hardware Ray Tracing Features
Setting Reflections and Translucency Maximum Roughness
Use Max Roughness To Trace in the Post Process Volume's Lumen Reflections category to set the roughness threshold for traced reflections, or use the console variable
r.Lumen.Reflections.MaxRoughnessToTrace. For legacy ray traced translucency, use Max Roughness in the Translucency category.
Setting a Maximum Ray Distance for Global Illumination, Reflections, and Translucency
This sets a maximum ray distance for each of these features to lower their cost and contribution in the scene.
Use the console to set the MaxRayDistance console variable for each of these raytraced features. You can find them under r.RayTracing.*.
Ray Tracing Solid Angle and Distance-based Culling
Scenes with ray tracing require objects outside of the camera view to be present in the scene, especially for highly reflective surfaces, which can increase cost of rendering. Culling objects that aren't visible or needed can help optimize and gain some of that performance back.
Ray tracing provides several ways of culling objects in the scene: by distance from the camera, or by projecting an area (or a angle) behind the camera and testing individual object bounds to determine whether they should be culled, not at all, or both simultaneously. The type of culling used is set by using one of the following values with the console variable r.RayTracing.Culling.
0 culling is disabled.
1 culls objects behind the camera by distance and solid angle.
2 culls objects in front of and behind the camera by distance and solid angle.
3 culls objects in front and behind the camera by distance or solid angle. (Default culling method)
Higher values cull more objects in the world.
Additionally, the ray tracing console variables (r.RayTracing.*) use two commands to configure Solid Angle culling: an angle and a radius.
Angle sets the projected area angle behind the camera (in degrees) that object's bounds will be tested against for whether they should be culled or not. Increasing the angle will aggressively cull a lot of objects.
Radius culls any object outside of the specified radius. By default, the radius is set to 300 meters (or 30000 cm/Unreal Units).
Two examples of ray tracing console variables using these would be r.RayTracing.Culling.Angle, and r.RayTracing.Geometry.StaticMeshes.WPO.CullingRadius.
Evaluating Denoiser Quality
Hardware ray tracing features rely heavily on denoising algorithms to use as few pixels as possible and make up the difference with a denoiser to intuit the rest. You can evaluate the quality of the denoiser for different ray tracing effects by following these steps:
Disable Temporal Anti-Aliasing and Depth of Field
Both of these are running in linear color space in Unreal Engine's renderer. They do some HDR color weighting tricks to avoid aliasing between shadows and highlights.
Compare the Denoised single sample per pixel with an Undenoised single sample per pixel.
The result will look incorrect due to the energy difference and that the denoiser is darkening the shadows too much. However, a single sample per pixel will look brighter due to the tonemapper's non-linear operation.
For a better comparison, the Denoised single sample per pixel should be tested against an Undenoised multiple samples per pixel.
The denoised single sample per pixel will not be perfect due to information loss. However, when compared to multiple samples per pixel that are not denoised, the results are consistent.
Keep in mind that the denoiser supports up to four samples per pixel for hardware ray tracing features. The more samples used, the closer it is to matching the multiple samples per pixel result that hasn't been denoised.