Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Graphics Programming with Vulkan

You're reading from  Mastering Graphics Programming with Vulkan

Product type Book
Published in Feb 2023
Publisher Packt
ISBN-13 9781803244792
Pages 382 pages
Edition 1st Edition
Languages
Authors (2):
Marco Castorina Marco Castorina
Profile icon Marco Castorina
Gabriel Sassone Gabriel Sassone
Profile icon Gabriel Sassone
View More author details

Table of Contents (21) Chapters

Preface 1. Part 1: Foundations of a Modern Rendering Engine
2. Chapter 1: Introducing the Raptor Engine and Hydra 3. Chapter 2: Improving Resources Management 4. Chapter 3: Unlocking Multi-Threading 5. Chapter 4: Implementing a Frame Graph 6. Chapter 5: Unlocking Async Compute 7. Part 2: GPU-Driven Rendering
8. Chapter 6: GPU-Driven Rendering 9. Chapter 7: Rendering Many Lights with Clustered Deferred Rendering 10. Chapter 8: Adding Shadows Using Mesh Shaders 11. Chapter 9: Implementing Variable Rate Shading 12. Chapter 10: Adding Volumetric Fog 13. Part 3: Advanced Rendering Techniques
14. Chapter 11: Temporal Anti-Aliasing 15. Chapter 12: Getting Started with Ray Tracing 16. Chapter 13: Revisiting Shadows with Ray Tracing 17. Chapter 14: Adding Dynamic Diffuse Global Illumination with Ray Tracing 18. Chapter 15: Adding Reflections with Ray Tracing 19. Index 20. Other Books You May Enjoy

Adding Volumetric Fog

After adding variable rate shading in the previous chapter, we will implement another modern technique that will enhance the visuals of the Raptor Engine: Volumetric Fog. Volumetric rendering and fog are very old topics in rendering literature, but until a few years ago, they were considered impossible for real-time usage.

The possibility of making this technique feasible in real-time stems from the observation that fog is a low-frequency effect; thus the rendering can be at a much lower resolution than the screen, increasing the performance in real-time usage.

Also, the introduction of compute shaders, and thus generic GPU programming, paired with clever observations about approximations and optimizations of the volumetric aspect of the technique, paved the way to unlocking real-time Volumetric Fog.

The main idea comes from the seminal paper by Bart Wronski (https://bartwronski.files.wordpress.com/2014/08/bwronski_volumetric_fog_siggraph2014.pdf) at...

Technical requirements

Introducing Volumetric Fog Rendering

What exactly is Volumetric Fog Rendering? As the name suggests, it is the combination of Volumetric Rendering and the fog phenomena. We will now give some background on those components and see how they are combined in the final technique.

Let’s begin with Volumetric Rendering.

Volumetric Rendering

This rendering technique describes the visuals associated with what happens to light when it travels through a participating medium. A participating medium is a volume that contains local changes to density or albedo.

The following diagram summarizes what happens to photons in a participating medium:

Figure 10.2 – Light behavior in a participating medium

Figure 10.2 – Light behavior in a participating medium

What we are trying to describe is how light changes when going through a participating medium, namely a fog volume (or clouds or atmospheric scattering).

There are three main phenomena that happen, as follows:

  • Absorption: This happens...

Implementing Volumetric Fog Rendering

We now have all the knowledge necessary to read the code needed to get this algorithm fully working. From a CPU perspective, it is just a series of compute shaders dispatches, so it is straightforward.

The core of this technique is implemented throughout various shaders, and thus on the GPU, working for almost all steps on the frustum aligned Volumetric Texture we talked about in the previous section.

Figure 10.7 shows the different algorithm steps, and we will see each one individually in the following sections.

Data injection

In the first shader, we will write scattering and extinction, starting from the color and density of different fog phenomena.

We decided to add three different fog effects, as follows:

  • A constant fog
  • Height fog
  • Fog in a volume

For each fog, we need to calculate scattering and extinction and accumulate them.

The following code converts color and density to scattering and extinction...

Summary

In this chapter, we introduced the Volumetric Fog rendering technique. We provided a brief mathematical background and algorithmic overview before showing the code. We also showed the different techniques available to improve banding – a vast topic that requires a careful balance of noise and temporal reprojection.

The algorithm presented is also an almost complete implementation that can be found behind many commercial games. We also talked about filtering, especially the temporal filter, which is linked to the next chapter, where we will talk about an anti-aliasing technique that uses temporal reprojection.

In the next chapter, we will see how the synergy between Temporal Anti-Aliasing and noises used to jitter the sampling in Volumetric Fog will ease out the visual bandings. We will also show a feasible way to generate custom textures with a single-use compute shader used to generate a volumetric noise.

This technique is also used for other volumetric algorithms...

Further reading

There are many different papers that are referenced in this chapter, but the most important is the Real-Time Volumetric Rendering paper for general GPU-based volumetric rendering: https://patapom.com/topics/Revision2013/Revision%202013%20-%20Real-time%20Volumetric%20Rendering%20Course%20Notes.pdf.

The algorithm is still a derivation of the seminal paper from Bart Wronski: https://bartwronski.files.wordpress.com/2014/08/bwronski_volumetric_fog_siggraph2014.pdf.

With some evolutions and mathematical improvements in the following link: https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite.

For the depth distribution, we referenced the formula used in iD Tech 6: https://advances.realtimerendering.com/s2016/Siggraph2016_idTech6.pdf.

For banding and noise, the most comprehensive papers come from Playdead:

For information on animated...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Mastering Graphics Programming with Vulkan
Published in: Feb 2023 Publisher: Packt ISBN-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.
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}