Volumetric Lighting
I will talk about how scattering works briefly.
And then I will go through how I implement and optimize basic volumetric lighting.
At the end, I will talk about some better techniques .
About Scattering
Volumetric lighting is one of the simulations of how rays propagate through air. During this propagation process, rays hit particles(medium) floating on the air.
When a photon hits a particle, two things happen:
- The direction of photon changes. (Scattering)
- The kinetic energy of photon may change.
There are two scattering models that describes the distribution of scattering: Mie Scattering and Rayleigh Scattering.
There are more models, but we only care about these two.
Fortunately, it seems like the kinetic energy of photon is conserved in both models. Two models differs base on size of particle and wavelength of incident ray.
Rayleigh Scattering model in general, is being used to describe atmospheric scattering.
Mie Scattering model is used for interaction with large particles, like dust or fog.
In a nutshell, the model that has been used for scattering is just another form of BRDF. But since scattering is a interaction with particle so that the cosine part is unnecessay. Also, it’s no long an integral of a hemisphere, it should be an integral over the whole sphere.
My implementation
- Generate depth map in light space
- Ray marching
- Ordered Dithering
- Gaussian Blur
Depth Map
Nothing new about depth map.
Procedure of Ray Marching
1. Trace a view ray from camera position(eye) to pixel position.
2. Sampling along the view ray.
Higher number of samples will give a better result along with high computational cost and vice versa for low number of samples.
Rendering time increases from 5.3 ms/frame to 28.9 ms/frame
This runs on my Surface Laptop 2.
GPU: Intel(R) Iris(R) Plus Graphics
CPU: Intel Core i5 8250U
3. Calculate light intensity by using phase function, in this project I use Henyey-Greenstein phase function.
1
-1 <= g <= 1
g determines distribution of scattering from backward scattering (g < 0>) through isotropic scattering (g = 0) to forward scattering (g > 0).
4. Accessing depth map the make sure the sampling position is not occluded by any objects.
This is depth map is not in light space.
5. The accumulation of all samples is the final volumetric light intensity.
Ordered Dithering
I’m not going to talk about how dithering works in details. (maybe I will if I have time)
The idea of useing Ordered dithering is to optimize volumetric lighting.
I did not expect there are so many thing I need to write.
I will complete this post another day.