Reader small image

You're reading from  Mastering Graphics Programming with Vulkan

Product typeBook
Published inFeb 2023
PublisherPackt
ISBN-139781803244792
Edition1st Edition
Right arrow
Authors (2):
Marco Castorina
Marco Castorina
author image
Marco Castorina

Marco Castorina first got familiar with Vulkan while working as a driver developer at Samsung. Later he developed a 2D and 3D renderer in Vulkan from scratch for a leading media-server company. He recently joined the games graphics performance team at AMD. In his spare time, he keeps up to date with the latest techniques in real-time graphics.
Read more about Marco Castorina

Gabriel Sassone
Gabriel Sassone
author image
Gabriel Sassone

Gabriel Sassone is a rendering enthusiast currently working as a Principal Rendering Engineer at Multiplayer Group. Previously working for Avalanche Studios, where his first contact with Vulkan happened, where they developed the Vulkan layer for the proprietary Apex Engine and its Google Stadia Port. He previously worked at ReadyAtDawn, Codemasters, FrameStudios, and some non-gaming tech companies. His spare time is filled with music and rendering, gaming, and outdoor activities.
Read more about Gabriel Sassone

View More author details
Right arrow

Adding Dynamic Diffuse Global Illumination with Ray Tracing

So far in this book, illumination has been based on direct lighting coming from point lights. In this chapter, we will enhance lighting by adding indirect lighting, often referred to as global illumination in the context of video games.

This type of illumination comes from emulating the behavior of light. Without going into quantum physics and optics, the information we need to consider is that light bounces off surfaces a few times until its energy becomes zero.

Throughout movies and video games, global illumination has always been an important aspect of lighting, but often impossible to perform in real time.

With movies, it often took minutes (if not hours) to render a single frame, until global illumination was pioneered. Video games were inspired by this and now include it in their lighting.

In this chapter, we will discover how to implement real-time global illumination by covering these topics:

  • Introduction...

Technical requirements

Introduction to indirect lighting

Going back to direct and indirect lighting, direct lighting just shows the first interaction between light and matter, but light continues to travel in space, bouncing at times.

From a rendering perspective, we use the G-buffer information to calculate the first light interaction with surfaces that are visible from our point of view, but we have little data on what is outside of our view.

The following diagram shows direct lighting:

Figure 14.2 – Direct lighting

Figure 14.2 – Direct lighting

Figure 14.2 describes the current lighting setup. There are light-emitting rays, and those rays interact with surfaces. Light bounces off these surfaces and is captured by the camera, becoming the pixel color. This is an extremely simplified vision of the phenomena, but it contains all the basics we need.

For indirect lighting, relying only on the camera’s point of view is insufficient as we need to calculate how other lights and geometries...

Introduction to Dynamic Diffuse Global Illumination (DDGI)

In this section, we will explain the algorithm behind DDGI. DDGI is based on two main tools: light probes and irradiance volumes:

  • Light probes are points in space, represented as spheres, that encode light information
  • Irradiance volumes are defined as spaces that contain three-dimensional grids of light probes with fixed spacing between them

Sampling is easier when the layout is regular, even though we will see some improvements to placements later. Probes are encoded using octahedral mapping, a convenient way to map a square to a sphere. Links to the math behind octahedral mapping have been provided in the Further reading section.

The core idea behind DDGI is to dynamically update probes using ray tracing: for each probe, we will cast some rays and calculate the radiance at the triangle intersection. Radiance is calculated with the dynamic lights present in the engine, reacting in real time to any light...

Implementing DDGI

The first shaders we will read are the ray tracing shaders. These, as we saw in Chapter 12, Getting Started with Ray Tracing, come as a bundle that includes the ray-generation, ray-hit, and ray-miss shaders.

There are a set of different methods that convert from world space into grid indices and vice versa that will be used here; they are included with the code.

First, we want to define the ray payload – that is, the information that’s cached after the ray tracing query is performed:

struct RayPayload {
    vec3 radiance;
    float distance;
};

Ray-generation shader

The first shader is called ray-generation. It spawns rays from the probe’s position using random directions on a sphere using spherical Fibonacci sequences.

Like dithering for TAA and Volumetric Fog, using random directions and temporal accumulation (which happens in the Probe Update shader) allows us to have more information...

Summary

In this chapter, we introduced the DDGI technique. We started by talking about global illumination, the lighting phenomena that is implemented by DDGI. Then, we provided an overview of the algorithm, explaining each step in more detail.

Finally, we wrote and commented on all the shaders in the implementation. DDGI already enhances the lighting of the rendered frame, but it can be improved and optimized.

One of the aspects of DDGI that makes it useful is its configurability: you can change the resolution of irradiance and visibility textures and change the number of rays, number of probes, and spacing of probes to support lower-end ray tracing-enabled GPUs.

In the next chapter we are going to add another element that will help us increase the accuracy of our lighting solution: reflections!

Further reading

Global illumination is an incredibly big topic that’s covered extensively in all rendering literature, but we wanted to highlight links that are more connected to the implementation of DDGI.

DDGI itself is an idea that mostly came from a team at Nvidia in 2017, with the central ideas described at https://morgan3d.github.io/articles/2019-04-01-ddgi/index.html.

The original articles on DDGI and its evolution are as follows. They also contain supplemental code that was incredibly helpful in implementing the technique:

The following is a great overview of DDGI with Spherical Harmonics support, and the only diagram to copy the border pixels for bilinear interpolation. It also describes other interesting topics: https://handmade.network/p/75/monter/blog/p/7288-engine_work__global_illumination_with_irradiance_probes...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Graphics Programming with Vulkan
Published in: Feb 2023Publisher: PacktISBN-13: 9781803244792
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Marco Castorina

Marco Castorina first got familiar with Vulkan while working as a driver developer at Samsung. Later he developed a 2D and 3D renderer in Vulkan from scratch for a leading media-server company. He recently joined the games graphics performance team at AMD. In his spare time, he keeps up to date with the latest techniques in real-time graphics.
Read more about Marco Castorina

author image
Gabriel Sassone

Gabriel Sassone is a rendering enthusiast currently working as a Principal Rendering Engineer at Multiplayer Group. Previously working for Avalanche Studios, where his first contact with Vulkan happened, where they developed the Vulkan layer for the proprietary Apex Engine and its Google Stadia Port. He previously worked at ReadyAtDawn, Codemasters, FrameStudios, and some non-gaming tech companies. His spare time is filled with music and rendering, gaming, and outdoor activities.
Read more about Gabriel Sassone