Real-Time Ray Tracing

An overview of Ray Tracing in Unreal Engine 4.

Windows
MacOS
Linux

RayTracingBanner

Ray tracing techniques have long been used in film, television, and visualization for rendering photo-realistic images for a long time but required powerful computers and time to render each image or frame. For film and television, it can take many hours or even days to render out high-quality image sequences, but the final result can create real-life 3D content that can blend seamlessly with real-life ones. For architectural visualization companies, ray tracing has meant creating beautiful renders for the automotive industry or showing what a densely-filled house or office complex could look like when complete all while achieving realistic-looking results.  

With the power of Unreal Engine 4 (UE4) combined with Real-Time Ray Tracing (RTRT), it’s possible to create interactive experiences with subtle lighting effects comparable with many offline renderers. Real-time ray tracing makes things look more natural producing soft shadowing for area lights, accurate ambient occlusion, interactive global illumination, and more. 

Ray Tracing in Unreal Engine

Ray tracing in UE4 is composed of two techniques:

  • A hybrid Ray Tracer that couples ray tracing capabilities with our existing raster effects.

  • A Path Tracer for generating reference renders.

Ray Tracer

The Ray Tracer enables raytraced results for shadows, ambient occlusion (AO), reflections, interactive global illumination, and translucency all in real-time. It does this by using a low number of samples couples with a denoising algorithm that is perceptually close to the ground truth results. For example, for shadows, this means they will soften based on distance from a receiving surface or light source size and have physically correct contact hardening.

Traditional Shadowmapping

Ray Traced Shadows

Path Tracer

The Path Tracer is an unbiased, physically based path tracer that is good for rendering reference images of your scene. It works similarly to offline renderers by gathering samples over time and, in its current state, is useful for generating ground truth renders of your scene rather than final pixels.

For additional information, see the Path Tracer.

Enabling Ray Tracing in your Project

Follow these steps to enable ray tracing support in your project. 

System Requirements

Operating System

Windows 10 RS5 (Build 1809) or later

Verify your Windows build by typing winver in the Windows search bar.

GPU

NVIDIA RTX and some GTX series cards with DXR support using the latest device drivers.

For more informatin, see NVIDIA's site here.

Unreal Engine Version

4.22 or Later

Unreal Engine Rendering Path

Deferred path (See Supported Features below)

Enabling DX12 and Ray Tracing

  1. Go to the main menu and use the File menu to open the Project Settings.

  2. Under Platforms > Windows, use the Default RHI dropdown to select DX12.

    EnableDX12Mode.png

  3. Under Engine > Rendering, enable Ray Tracing.

    ProjectSetting_EnableRT

    To enable Ray Tracing, Support Compute Skincache must be enabled for the project. If it is not already enabled, you’ll receive a message dialogue asking if you would like to enable it now. If so, click Yes.
    SupportSkinCache.png

  4. Restart the engine to launch the Editor with DX12 and to enable Ray Tracing for your project.

Real-Time Ray Tracing Features

Ray Traced Shadows

Ray Traced Shadows simulate soft area lighting effects for objects in the environment. This means that based on the light’s source size or source angle, an object’s shadow will have sharper shadows near the contact surface than farther away where it softens and widens.

Raster Shadows using Shadowmaps

Ray Traced Soft Shadows

For additional information, see Ray Tracing Settings.

Ray Traced Reflections

Ray Traced Reflections (RTR) simulate accurate environment reflections that can support multiple bounces to create inter-reflection for reflective surfaces.

Screen Space Reflections

Ray Traced Reflections

When compared with Screen Space Reflections (SSR), Planar Reflections, or even reflection probes, Ray Traced Reflections captures the entire scene dynamically and is not limited to static captures or objects within the current camera view to be visible in the reflection.

For additional information, see Ray Tracing Settings.

Ray Traced Translucency

Ray Traced Translucency (RTT) accurately represents glass and liquid materials with physically correct reflections, absorption, and refraction on transparent surfaces.

Raster Translucency

Ray Traced Translucency

For additional information, see Ray Tracing Settings.

Ray Traced Ambient Occlusion

Ray Traced Ambient Occlusion (RTAO) accurately shadows areas blocking ambient lighting better grounding objects in the environment, such as shadowing the corners and edges where walls meet or adding depth to the crevices and wrinkles in skin.

Screen Space Ambient Occlusion (SSAO)

Ray Traced Ambient Occlusion (RTAO)

When compared with Screen Space Ambient Occlusion (SSAO), RTAO grounds objects and adds depth to the scene to produce natural looking shadowing in indirectly lit areas.

For additional information, see Ray Tracing Settings.

Ray Traced Global Illumination

Ray Traced Global Illumination (RTGI) adds real-time interactive bounce lighting to areas not directly lit by a given light source.

Sky Light Only

Ray Traced Global Illumination

RTGI is disabled by default and is currently considered experimental. It can be enabled by adding a Post Process Volume to the scene and enabling Ray Traced Global Illumination or by using the console variable r.RayTracing.Globalillumination 1.

For additional information, see Ray Tracing Settings.

Final Gather Method

This is currently an experimental RTGI method.

An alternative ray tracing based global illumination global illumination method using a final gather-based technique has been developed that seeks to give back some runtime performance. This technique is a two-pass algorithm. The first phase distributes shading points—similarly to the original RTGI method—but at a fixed rate of one sample per-pixel. A history of up to 16 shading point samples are stored in screen space during this phase. During the second phase, the algorithm attempts to reconnect to the shading point history, amortizing the cost of the method.

The original RTGI algorithm intends to emulate the [Path Tracer's][Engine/Rendering/RayTracing/PathTracer] ground truth reference and is similar in execution of the path tracing result. The new method trades that emulation for performance, which introduces some limitations; it's currently limited to a single bounce of indirect diffuse GI, and reprojection of the previous frame GI sample data is susceptible to ghosting.

Enable the Final Gather method from the Ray Tracing Global Illumination section of a Post Process Volume using the Types dropdown selection.

To aid in suppressing temporal ghosting artifacts, you can use the following command to modify the world space rejection criteria.

r.RayTracing.GlobalIllumination.FinalGatherDistance [number of units] 

It is currently based on a world distance measured from the original shading point. This rejection crieteria defaults to 10 units.

The Final Gather method also requires the following settings to be used in the Post Process Volume for it to work effectively:

  • Max Bounces: 1

  • Samples Per Pixel: 8

Any additional Max Bounces beyond 1 are silently discarded and when adjusting the Samples Per Pixel, it's best to increase it by powers of two (for example, 8, 16, 32, 64).

Using Ray Tracing Features

Post Process Volume

Use Post Process Volumes to in your scene to control Ray Tracing and Path Tracing features and properties. Volumes can be added to different areas for interiors and exteriors to enable you to apply the features and quality level you want. From these volumes, you can control Ray Traced Reflections, Translucency, Global Illumination, Ambient Occlusion, and the Path Tracer.

  1. From the Modes panel, locate and drag a Post Process Volume into the Level.

    Click image for full size.

  1. With the volume selected, look at the Details panel under Rendering Features to locate the available Ray Tracing and Path Tracing features and properties that can be adjusted.

    Click image for full size.

For additional information, see Ray Tracing Settings.

Lights

The Ray Tracer supports soft area shadows for all types of lights available in UE4.

Ray Traced Shadows: Directional Light | Source Angle: 0.5357

Ray Traced Shadows: Directional Light | Source Angle: 2.0

Control the softness of the shadow by adjusting the following: 

  • On a Directional Light, set the Source Angle.

  • On Point and Spot Lights, set the Source Radius

  • On a Rect Light, set the Barn Door Angle and Barn Door Length to shape and soften the shadow softness.

For additional information, see Ray Tracing Settings.

Sky Lights

On the Sky Light, use SLS Captured Scene or SLS Specified Cubemap with raytraced shadowing to capture the distance parts of the level and apply that to the scene as a light. Check the Cast Raytraced Shadow flag to enable sky lighting in your scene.  

RT_SkyLight

In this scene, a single HDRI is being used to light the scene along with RTGI.

For RTGI to work with the Sky Light, enable RTGI to evaluate the sky's lighting using the experimental console variable r.RayTracing.GlobalIllumination.EvalSkylight.

For additional information, see Ray Tracing Settings.

Ray Tracing Ambient Occlusion

Control Ray Traced Ambient Occlusion using a Post Process Volume in your scene. Under Ambient Occlusion, you can set the Intensity and Radius of the effect to control its size and strength. 

Ray Traced Ambient Occlusion Intensity: 0.75

Ray Traced Ambient Occlusion Intensity: 1.0

Performance and Debugging

Stat GPU

Check relevant Ray Tracing GPU performance by using the console command GPU Stats. You'll find relevant information about enabled Ray Tracing features and how much frame time is being spent to render them in the current view. 

GPUStats1

Stat D3D12RayTracing

Check relevant Ray Tracing resource usage using the console command Stat D3D12RayTracing.

StatD3D12RayTracing

Ray Tracing Debug View Modes

Under the Level Viewport, select the View Mode dropdown and select Ray Tracing Debug to select from the available debug view modes. 

Click image for full size.

Evaluating Denoiser Quality

Evaluate the quality of the Denoiser for different raytracing effects by doing the following: 

  • 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.

Denoised Single Sample Per Pixel

Undenoised Multiple Samples Per Pixel

The denoised single sample per pixel will not be perfect due to information loss. However, when compared to undenoised multiple samples per pixel, the results are consistent. 

Also, keep in mind that the Denoiser supports up to four samples per pixel, which improves the quality and more closely matches the undenoised multiple samples per pixel result.

Other Debugging Notes

  • Use the command r.raytracing.ForceAllRayTracingEffects to quickly enable and disable Ray Tracing in your scene. A value of 0 will disable all effect, 1 will enable all effects, and -1 will use the previous settings enabled for your project.

Additional Notes

Materials 

  • Testing Material Costs

    • Complex Materials can affect performance of Ray Tracing features. Use the console command r.RayTracing.EnableMaterials to test performance impact.

  • Ray Tracing Quality Switch Replace Node

    • Use this node to replace entire parts of your Material logic to lower the cost of features like RTGI, RT Reflections, and RT Translucency with less complex logic. This is a global change that affects all ray tracing effects.

    • In this example, the Normal logic path renders as seen in the scene. The Ray Tracing path uses less complex logic for effects in Ray Tracing, such as RTGI and Reflections where textures, normals, and roughness can be come an expensive added cost.

      Click image for full size.

  • Cast 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 your Materials assigned to geometry that should or should not cast a raytraced shadow.

Reflections

  • Ray Tracing Reflections can be expensive when rendering multiple bounces with reflections inside of reflections. Without multiple bounces, the intra-reflected material will appear black. Enable r.RayTracing.Reflections.ReflectionCaptures to use Reflection Capture Actors as the last bounce in Ray Traced Reflections.

Dragging the slider shows a single bounce RTR, two bounces RTR with no reflection capture fallback, and a single bounce with reflection capture fallback.

Including Translucent Objects in Reflections

Enable objects with translucent materials to appear in Ray Traced Reflections by enabling Include Translucent Objects in the Post Process Volume's settings under Rendering Features > Ray Tracing Reflections.

Translucency Index of Refraction (IOR)

With ray traced translucency, index of refractin (IOR) is controlled with the Material's Specular value clamped from 0 to 1. This is how IOR is determined with a real-world material as well.

IOR Specular Value: 0.0

IOR Specular Value: 0.5

Use the following guidelines to control IOR with a ray traced translucent material:

  • In the Post Process Volume, enable the following settings:

    • Rendering Features > Translucency set to Ray Tracing

    • Rendering Features > Ray Tracing Translucency, enable Refraction

    • Rendering Features > Ray Tracing Translucency, set the Max Refraction Rays to a high enough bounces to see the other side of the material. For example, a single bounce would not be enough to see objects behind it, but several bounces may be.

Use a Material Instance to drive the Specular value to control the IOR.

Sky Lights

Capturing distant objects, like a Sky Dome should be disabled for Sky Light contribution unless needed. This can save some performance and optmize your scene. For the BP_SkySphere provided with the UE4, this option is disabled by default and will make reflections from the sky look different than expected. You can control an ojects contribution by enabling/disabling the checkbox for Visible in Ray Tracing in its Details panel properties.

Ray Tracing Features Optimization

  • Setting Reflections and Translucency Maximum Roughness

    • Use Max Roughness to set a threshold for raytraced reflections on Materials. This can be done within the Post Process Volume or using the console command r.RayTracing.Reflections.MaxRoughness.

  • 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.*.

  • RTGI Optimizations

    • Screen Percentage and Sample Per-Pixel now defaults to 50 and 4, respectively. If you need to set these to different values, by default, use their console commands to do so: r.RayTracing.GlobalIllumination.ScreenPercentage, and r.RayTracing.GlobalIllumination.SamplesPerPixel.

    • Light contribution to GI can be enabled/disabled with the Affect Global Illumination property on the light.

Geometry Considerations with Ray Tracing

  • Geometry with small holes or lots of little details can impact performance, such as foliage and fences. 

  • Indoor environments are slower to render than outdoors ones.

    • For example, when light enters from outside, areas that are directly lit is faster than points that are indirectly lit. 

    • Also, you have to consider that more ray tracing features are being used, such as reflections and translucency

Supported Ray Tracing Features

This list is intended to give you an idea of what is currently supported and is not meant to be a comprehensive list of Ray Tracing feature support in Unreal Engine 4.23.

Feature

Supported (Y/N/Partially)

Additional Notes

Rendering Path

Deferred

Y

Forward

N

Types of Lights

Directional Light

Y

Sky Light

Y

Point Light

Y

Spot Light

Y

Rect Light

Y

Lighting Features

Emissive Surfaces

Partially

Supported for reflections on surfaces, but does not emit light or cast shadows.

Light Transmission

N

The translucent shadow is treated as opaque, meaning no colored shadows or light transmission through the material.

Area Shadowing

Y

IES Profiles

Y

Light Functions

N

Volumetric Fog

N

Image Based Lighting (IBL)

Y

Support for HDRI with Sky Light.

Materials: Blend Mode

Opaque

Y

Masked

Y

With 4.22.1 Hotfix, Masked materials are now supported

Translucent

Partially

Shadow is considered opaque.

Materials: Shading Model

Default Lit

Y

Unlit

Partially

Masked

Partially

Supports casting of masked shadows.

SubSurface and SubSurface Profile

Y

Preintegrated Skin

Partially

Works but the result isn't correctly raytraced. It uses the raster pipeline.

Clear Coat

Y

TwoSided Foliage

Y

Hair

Partially

Works but the result isn't correctly raytraced. It uses the raster pipeline.

Cloth

Partially

Works but the result isn't correctly raytraced. It uses the raster pipeline.

Material Functions

Y

Two-Sided

Y

World Position Offset

Y

Static Mesh is enabled per-Actor.

Geometry Types

Skeletal Mesh

Y

Static Mesh

Y

Geometry Cache (Alembic)

Y

Landscape

Y

Hierarchical Instanced Static Mesh (HISM)

Y

Instanced Static Mesh (ISM)

Y

Splines

N

Procedural Mesh

Y

This type of geometry can be expensive to render in Ray Tracing.

BSP Brushes

N

Levels of Detail (LOD)

Y

Dithered LOD transitions are not yet supported.

Visual Effects (VFX)

Niagara

Partially

Currently supports Sprites and Ribbons.

Cascade

N

Platform Support

Multi-View (VR and Split-Screen)

Y

Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback