Skip to main content

Über dieses Buch

This book is a must-have for anyone serious about rendering in real time. With the announcement of new ray tracing APIs and hardware to support them, developers can easily create real-time applications with ray tracing as a core component. As ray tracing on the GPU becomes faster, it will play a more central role in real-time rendering. Ray Tracing Gems provides key building blocks for developers of games, architectural applications, visualizations, and more. Experts in rendering share their knowledge by explaining everything from nitty-gritty techniques that will improve any ray tracer to mastery of the new capabilities of current and future hardware.
What you'll learn: The latest ray tracing techniques for developing real-time applications in multiple domains
Guidance, advice, and best practices for rendering applications with Microsoft DirectX Raytracing (DXR)
How to implement high-performance graphics for interactive visualizations, games, simulations, and more

Who this book is for:Developers who are looking to leverage the latest APIs and GPU technology for real-time rendering and ray tracing
Students looking to learn about best practices in these areas
Enthusiasts who want to understand and experiment with their new GPUs



Ray Tracing Basics


Open Access

Chapter 1. Ray Tracing Terminology

This chapter provides background information and definitions for terms used throughout this book.

Eric Haines, Peter Shirley

Open Access

Chapter 2. What is a Ray?

We define a ray, show how to use ray intervals, and demonstrate how to specify a ray using DirectX Raytracing (DXR).

Peter Shirley, Ingo Wald, Tomas Akenine-Möller, Eric Haines

Open Access

Chapter 3. Introduction to DirectX Raytracing

Modern graphics APIs such as DirectX 12 expose low-level hardware access and control to developers, often resulting in complex and verbose code that can be intimidating for novices. In this chapter, we hope to demystify the steps to set up and use DirectX for ray tracing.

Chris Wyman, Adam Marrs

Open Access

Chapter 4. A Planetarium Dome Master Camera

This chapter presents a camera implementation for high-quality interactive ray tracing of planetarium dome master images using an azimuthal equidistant projection. Ray tracing is aptly suited for implementing a wide variety of special panoramic and stereoscopic projections without sacrificing image quality. This camera implementation supports antialiasing, depth of field focal blur, and circular stereoscopic projections, all effects that are difficult to produce with high quality using conventional rasterization and image warping.

John E. Stone

Open Access

Chapter 5. Computing Minima and Maxima of Subarrays

This chapter explores the following problem: given an array A of N numbers Ai, how can we efficiently query the minimal or maximal numbers in any sub-range of the array? For example, “what is the minimum of the 8th to the 23rd elements?”

Ingo Wald

Intersections and Efficiency


Open Access

Chapter 6. A Fast and Robust Method for Avoiding Self-Intersection

We present a solution to avoid self-intersections in ray tracing that is more robust than current common practices while introducing minimal overhead and requiring no parameter tweaking.

Carsten Wächter, Nikolaus Binder

Open Access

Chapter 7. Precision Improvements for Ray/Sphere Intersection

The traditional quadratic formula is often presented as the way to compute the intersection of a ray with a sphere. While mathematically correct, this factorization can be numerically unstable when using floating-point arithmetic. We give two little-known reformulations and show how each can improve precision.

Eric Haines, Johannes Günther, Tomas Akenine-Möller

Open Access

Chapter 8. Cool Patches: A Geometric Approach to Ray/Bilinear Patch Intersections

We find intersections between a ray and a nonplanar bilinear patch using simple geometrical constructs. The new algorithm improves the state of the art performance by over 6× and is faster than approximating a patch with two triangles.

Alexander Reshetov

Open Access

Chapter 9. Multi-Hit Ray Tracing in DXR

Multi-hit ray traversal is a class of ray traversal algorithm that finds one or more, and possibly all, primitives intersected by a ray, ordered by point of intersection. Multi-hit traversal generalizes traditional first-hit ray traversal and is useful in computer graphics and physics-based simulation. We present several possible multi-hit implementations using Microsoft DirectX Raytracing and explore the performance of these implementations in an example GPU ray tracer.

Christiaan Gribble

Open Access

Chapter 10. A Simple Load-Balancing Scheme with High Scaling Efficiency

This chapter describes an image partitioning scheme that can be used to distribute the work of computing pixel values across multiple processing units. The resulting workload distribution scheme is simple to implement, yet effective.

Dietger van Antwerpen, Daniel Seibert, Alexander Keller

Reflections, Refractions, and Shadows


Open Access

Chapter 11. Automatic Handling of Materials in Nested Volumes

We present a novel and simple algorithm to automatically handle nested volumes and transitions between volumes, enabling push-button rendering functionality. The only requirements are the use of closed, watertight volumes (along with a ray tracing implementation such as NVIDIA RTX that guarantees watertight traversal and intersection) and that neighboring volumes are not intended to intersect each other, except for a small overlap that actually will model the boundary between the volumes.

Carsten Wächter, Matthias Raab

Open Access

Chapter 12. A Microfacet-Based Shadowing Function to Solve the Bump Terminator Problem

We present a technique to hide the abrupt shadow terminator line when strong bump or normal maps are used to emulate micro-geometry. Our approach, based on microfacet shadowing functions, is simple and inexpensive. Instead of rendering detailed and expensive height-field shadows, we apply a statistical solution built on the assumption that normals follow a nearly normal random distribution. We also contribute a useful approximate variance measure for GGX, which is otherwise undefined analytically.

Alejandro Conty Estevez, Pascal Lecocq, Clifford Stein

Open Access

Chapter 13. Ray Traced Shadows: Maintaining Real-Time Frame Rates

Efficient and accurate shadow computation is a long-standing problem in computer graphics. In real-time applications, shadows have traditionally been computed using the rasterization-based pipeline. With recent advances of graphics hardware, it is now possible to use ray tracing in real-time applications, making ray traced shadows a viable alternative to rasterization. While ray traced shadows avoid many problems inherent in rasterized shadows, tracing every shadow ray independently can become a bottleneck if the number of required rays rises, e.g., for high-resolution rendering, for scenes with multiple lights, or for area lights. Therefore, the computation should focus on image regions where shadows actually appear, in particular on the shadow boundaries.We present a practical method for ray traced shadows in real-time applications. Our method uses the standard rasterization pipeline for resolving primary-ray visibility and ray tracing for resolving visibility of light sources. We propose an adaptive sampling algorithm for shadow rays combined with an adaptive shadowfiltering method. These two techniques allow computing high-quality shadows with a limited number of shadow rays per pixel. We evaluated our method using a recent real-time ray tracing API (DirectX Raytracing) and compare the results with shadow mapping using cascaded shadow maps.

Jakub Boksansky, Michael Wimmer, Jiri Bittner

Open Access

Chapter 14. Ray-Guided Volumetric Water Caustics in Single Scattering Media with DXR

This chapter presents a hybrid algorithm that uses ray tracing and rasterization to render surface and volumetric caustics in single scattering participating media. The algorithm makes use of ray tracing based on DirectX Raytracing (DXR) to generate data that drives hardware tessellation to adaptively refine triangular beam volumes that are rendered to slice volumetric caustics. Further on in the rendering pipeline, ray tracing is also used to generate secondary caustics maps that store the positions of ray/scene intersections for light rays that get reflected or refracted by a water surface.

Holger Gruen



Open Access

Chapter 15. On the Importance of Sampling

With the recent arrival of ray tracing to the real-time graphics pipeline, developers are faced with a new challenge: figuring out how to make the most of the rays that they’re able to trace. One important question to decide is for which lighting effects to trace rays—choices include shadows, reflections, ambient occlusion, and full global illumination.Another important question is how to choose which rays to trace for the chosen effect; an introduction to that question is the topic of this chapter. In the following, we will see how most lighting calculations in rendering can be interpreted as estimating the values of integrals and how tracing rays is a natural fit to an effective numerical integration technique: Monte Carlo. Given some background in Monte Carlo integration, we then see how well-chosen rays can dramatically improve the speed of convergence, which in turn can either improve overall system performance—by getting the same quality result for fewer rays—or improve image quality—by getting lower error from the same number of rays.

Matt Pharr

Open Access

Chapter 16. Sampling Transformations Zoo

We present several formulas and methods for generating samples distributed according to a desired probability density function on a specific domain. Sampling is a fundamental operation in modern rendering, both at runtime and in preprocessing. It is becoming ever more prevalent with the introduction of ray tracing in standard APIs, as many ray tracing algorithms are based on sampling by nature. This chapter provides a concise list of some useful tricks and methods.

Peter Shirley, Samuli Laine, David Hart, Matt Pharr, Petrik Clarberg, Eric Haines, Matthias Raab, David Cline

Open Access

Chapter 17. Ignoring the Inconvenient When Tracing Rays

Ray tracing’s greatest strength—that it can simulate all types of light transport—can also be its greatest weakness: when there are a few paths that unexpectedly carry much more light than others, the produced images contain a smattering of pixels that have bright spiky noise. Not only can it require a prohibitive number of additional rays to average out those spikes, but those pixels present a challenge for denoising algorithms. This chapter presents two techniques to address this problem, preventing it from occurring in the first place.

Matt Pharr

Open Access

Chapter 18. Importance Sampling of Many Lights on the GPU

The introduction of standardized APIs for ray tracing, together with hardware acceleration, opens up possibilities for physically based lighting in real-time rendering. Light importance sampling is one of the fundamental operations in light transport simulations, applicable to both direct and indirect illumination. This chapter describes a bounding volume hierarchy data structure and associated sampling methods to accelerate importance sampling of local light sources. The work is based on recently published methods for light sampling in production rendering, but it is evaluated in a real-time implementation using Microsoft DirectX Raytracing.

Pierre Moreau, Petrik Clarberg

Denoising and Filtering


Open Access

Chapter 19. Cinematic Rendering in UE4 with Real-Time Ray Tracing and Denoising

We present cinematic quality real-time rendering by integrating ray tracing in Unreal Engine 4. We improve the state-of-the-art performance in GPU ray tracing by an order of magnitude through a combination of engineering work, new ray tracing hardware, hybrid rendering techniques, and novel denoising algorithms.

Edward Liu, Ignacio Llamas, Juan Cañada, Patrick Kelly

Open Access

Chapter 20. Texture Level of Detail Strategies for Real-Time Ray Tracing

Unlike rasterization, where one can rely on pixel quad partial derivatives, an alternative approach must be taken for filtered texturing during ray tracing. We describe two methods for computing texture level of detail for ray tracing. The first approach uses ray differentials, which is a general solution that gives high-quality results. It is rather expensive in terms of computations and ray storage, however. The second method builds on ray cone tracing and uses a single trilinear lookup, a small amount of ray storage, and fewer computations than ray differentials. We explain how ray differentials can be implemented within DirectX Raytracing (DXR) and how to combine them with a G-buffer pass for primary visibility. We present a new method to compute barycentric differentials. In addition, we give previously unpublished details about ray cones and provide a thorough comparison with bilinearly filtered mip level 0, which we consider as a base method.

Tomas Akenine-Möller, Jim Nilsson, Magnus Andersson, Colin Barré-Brisebois, Robert Toth, Tero Karras

Open Access

Chapter 21. Simple Environment Map Filtering Using Ray Cones and Ray Differentials

We describe simple methods for how to filter environment maps using ray cones and ray differentials in a ray tracing engine.

Tomas Akenine-Möller, Jim Nilsson

Open Access

Chapter 22. Improving Temporal Antialiasing with Adaptive Ray Tracing

In this chapter, we discuss a pragmatic approach to real-time supersampling that extends commonly used temporal antialiasing techniques with adaptive ray tracing. The algorithm conforms to the constraints of a commercial game engine, removes blurring and ghosting artifacts associated with standard temporal antialiasing, and achieves quality approaching 16× supersampling of geometry, shading, and materials within the 16 ms frame budget required of most games.

Adam Marrs, Josef Spjut, Holger Gruen, Rahul Sathe, Morgan McGuire

Hybrid Approaches and Systems


Open Access

Chapter 23. Interactive Light Map and Irradiance Volume Preview in Frostbite

This chapter presents the real-time global illumination (GI) preview system available in the Frostbite engine. Our approach is based on Monte Carlo path tracing running on the GPU, built using the DirectX Raytracing (DXR) API. We present an approach to updating light maps and irradiance volumes in real time according to elements constituting a scene. Methods to accelerate these updates, such as view prioritization and irradiance caching, are also described. A light map denoiser is used to always present a pleasing image on screen. This solution allows artists to visualize the result of their edits, progressively refined on screen, rather than waiting minutes to hours for the final result using the previous CPUbased GI solver. Even if the GI solution being refined in real time on screen has not converged after a few seconds, it is enough for artists to get an idea of the final look and assess the scene quality. It enables them to iterate faster and so achieve a higher-quality scene lighting setup.

Diede Apers, Petter Edblom, Charles de Rousiers, Sébastien Hillaire

Open Access

Chapter 24. Real-Time Global Illumination with Photon Mapping

Indirect lighting, also known as global illumination, is a crucial effect in photorealistic images. While there are a number of effective global illumination techniques based on precomputation that work well with static scenes, including global illumination for scenes with dynamic lighting and dynamic geometry remains a challenging problem. In this chapter, we describe a real-time global illumination algorithm based on photon mapping that evaluates several bounces of indirect lighting without any precomputed data in scenes with both dynamic lighting and fully dynamic geometry. We explain both the pre- and post-processing steps required to achieve dynamic high-quality illumination within the limits of a realtime frame budget.

Niklas Smal, Maksim Aizenshtein

Open Access

Chapter 25. Hybrid Rendering for Real-Time Ray Tracing

This chapter describes the rendering pipeline developed for PICA PICA, a real-time ray tracing experiment featuring self-learning agents in a procedurally assembled world. PICA PICA showcases a hybrid rendering pipeline in which rasterization, compute, and ray tracing shaders work together to enable real-time visuals approaching the quality of offline path tracing.The design behind the various stages of such a pipeline is described, including implementation details essential to the realization of PICA PICA’s hybrid ray tracing techniques. Advice on implementing the various ray tracing stages is provided, supplemented by pseudocode for ray traced shadows and ambient occlusion. A replacement to exponential averaging in the form of a reactive multi-scale mean estimator is also included. Even though PICA PICA’s world is lightly textured and small, this chapter describes the necessary building blocks of a hybrid rendering pipeline that could then be specialized for any AAA game. Ultimately, this chapter provides the reader with an overall good design to augment existing physically based deferred rendering pipelines with ray tracing, in a modular fashion that is compatible across visual styles.

Colin Barré-Brisebois, Henrik Halén, Graham Wihlidal, Andrew Lauritzen, Jasper Bekkers, Tomasz Stachowiak, Johan Andersson

Open Access

Chapter 26. Deferred Hybrid Path Tracing

We describe a hybrid rendering approach that leverages existing rasterizationbased techniques and combines them with ray tracing in order to achieve realtime global illumination. We reduce the number of traced rays by trying to find an intersection in screen space and reuse information from previous frames via reprojection and filtering. Artificial lighting is stored in nodes of the spatial acceleration structure to ensure efficient memory access. Our techniques require no manual preprocessing and only a few seconds of precomputation. They were developed as a real-time rendering solution for architectural design but can be applied to other purposes as well.

Thomas Willberger, Clemens Musterle, Stephan Bergmann

Open Access

Chapter 27. Interactive Ray Tracing Techniques for High-Fidelity Scientific Visualization

This chapter describes rendering techniques and implementation considerations when using ray tracing for interactive scientific and technical visualization. Ray tracing offers a convenient framework for building high-fidelity rendering engines that can directly generate publication-quality images for scientific manuscripts while also providing high interactivity in a what-you-see-is-what-you-get rendering experience. The combination of interactivity with sophisticated rendering enables scientists who are typically not experts in computer graphics or rendering technologies to be able to immediately apply advanced rendering features in their daily work. This chapter summarizes techniques and practical approaches learned from applying ray tracing techniques to scientific visualization, and molecular visualization in particular.

John E. Stone

Global Illumination


Open Access

Chapter 28. Ray Tracing Inhomogeneous Volumes

Simulating the interaction of light with scattering and absorbing media requires importance sampling of distances proportional to the volume transmittance. A simple method originating from neutron transport simulation can be used to importance-sample collision events of a particle like a photon with arbitrary media.

Matthias Raab

Open Access

Chapter 29. Efficient Particle Volume Splatting in a Ray Tracer

Rendering of particle data sets is a common problem in many domains including games, film, and scientific visualization. Conventionally, this has been accomplished using rasterization-based splatting methods, which scale linearly with respect to problem size. Given sufficiently low-cost ray traversal with logarithmic complexity, splatting within a ray tracing framework could scale better to larger geometry. In this chapter, we provide a method for efficiently rendering larger particle data, exploiting ray coherence and leveraging hardware-accelerated traversal on architectures such as the NVIDIA RTX 2080 Ti (Turing) GPUs with RT Cores technology.

Aaron Knoll, R. Keith Morley, Ingo Wald, Nick Leaf, Peter Messmer

Open Access

Chapter 30. Caustics Using Screen-Space Photon Mapping

Photon mapping is a global illumination technique for rendering caustics and indirect lighting by simulating the transportation of photons emitted from the light. This chapter introduces a technique to render caustics with photon mapping in screen space with hardware ray tracing and a screen-space denoiser in real time.

Hyuk Kim

Open Access

Chapter 31. Variance Reduction via Footprint Estimation in the Presence of Path Reuse

Multiple importance sampling is a tool to weight the results of different samplers with the goal of a minimal variance for the sampled function. If applied to light transport paths, this tool enables techniques such as bidirectional path tracing and vertex connection and merging. The latter generalizes the path probability measure to merges—also known as photon mapping. Unfortunately, the resulting heuristic can fail, resulting in a noticeable increase of noise. This chapter provides an insight into why things go wrong and proposes a simple-to-implement heuristic that is closer to an optimal solution and more reliable over different scenes. The trick is to use footprint estimates of sub-paths to predict the true variance reduction that is introduced by reusing all the photons.

Johannes Jendersie

Open Access

Chapter 32. Accurate Real-Time Specular Reflections with Radiance Caching

We present an algorithm for perspective-correct, real-time specular illumination for surfaces of varying glossiness in dynamic environments. Our algorithm leverages properties from earlier techniques (e.g., radiance probes and screenspace reflections) while reducing the amount of visual errors by adding ray tracing to the rendering pipeline. Our algorithm extends previous work by allowing accurate reflections for all surfaces regardless of the material, and it has global coherence (i.e., there are no visible discontinuities). With radiance caching, multiple samples can be efficiently computed as the radiance computation is decoupled from the final shading. The radiance cache is also used to approximate the specular term for the roughest surfaces without any ray tracing.

Antti Hirvonen, Atte Seppälä, Maksim Aizenshtein, Niklas Smal
Weitere Informationen