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