🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Volumetric lighting

Started by
8 comments, last by Tommato 3 years, 12 months ago

How volumetric lighting works? Can somebody describe this technique to me? Or drop some info

Advertisement

You can look up some presentations about Read Dead Redemption 2 which is most recent example with advanced volumetric lighting.

The starting point (beside some simple analytical fog from depth tricks) is usually to have a 3D volume with some scalar density, and ray marching the volume, evaluating lighting at each step, and accumulating occlusion / coloring from given density.
If this evaluation includes SM lookup, you get god rays for example.

The cheapest method is to apply post processing in screen space. However, without any info in object space, it can only perform rudimentary object occlusion.

The next alternative is to use a stack of quads as sprites along the light direction. Use shader and scrolling noise to fill the volumes, object occlusion is easy to do by adding a depth map from the view of a camera placed at the light source. Aliasing is a bit harder to solve if not enough quads are used.

Ray marching is expensive. and the bigger the screen, the worse it gets.

@undefined Can you describe ray marching technique more detailed, pls?

https://wallisc.github.io/rendering/2020/05/02/Volumetric-Rendering-Part-2.html

Ray marching means to sample at (usually regular) intervals along a ray.
Like in the picture we start from camera, then at each blue sample position we do another raymarch towards the light to see how much light arrives at the sample. We can then lighten the cloud sample, accumulate and continue.

A cheaper approximation would be to use a simple SM lookup instead the secondary raymarch, so ignoring the volume. This would give us still effects like god rays.

To avoid quantization artifacts we can jitter the sample position, or the length of the very first interval, etc. This way we turn banding into noise and TAA might reduce the noise. (e.g. https://blog.demofox.org/2020/05/10/ray-marching-fog-with-blue-noise/)

Although the above is very expensive, it is still incomplete because it only handles direct lighting.

There are different options as well, for example to diffuse the light through the volume, which can avoid the need to calculate expensive shadows, but light moves very slowly only form one cell to the next in one iteration.
But i don't know any examples where this has been used in games.

Here is a video for each.

(1) I implemented the ray marching technique to visualize a Navier Stokes simulation. For each voxel in the grid, I march from that voxel toward camera to accumulated density. Then I march from that voxel toward the light source to determine its brightness and color. You need to march thru each voxel not obstructed by obstacle. Basically what JoeJ described above.

(2) Here is an example of using stack of quads.

Use instancing with minimum geometry, it is quite fast and deliver realistic result.

@JoeJ But i interested in volumetric LIGHTING, not fog or something else. Does it differ somehow??

BANEBYTE said:
i interested in volumetric LIGHTING, not fog or something else. Does it differ somehow??

In the real world, volumetric lighting only exists because of participating media like fog or any other particles in atmosphere. If atmosphere is empty, no light shafts would appear.

But in games it is indeed common to ignore this. You can assume constant particle density, then no sampling along shadow ray is necessary and just its length is enough.
You can also ignore density (and shadows) completely, just drawing the bounding cone of a spot light, look up depth to see how much air is between surface and cone entry, and add light accordingly to get an additive light shaft effect.

This paper shows some examples and different trade-offs: https://developer.amd.com/wordpress/media/2012/10/Mitchell_LightShafts.pdf

You may want to show / describe some examples of effects you want to achieve. It's a broad topic with many ways to tackle it. (And i'm no expert with any of them, just to mention : )

BANEBYTE said:
Can you describe ray marching technique more detailed, pls?

Standard straightforward approch is:

- build shadow buffer first

- every shaded point is a ray from camera (0, 0, 0). Check if the rays intersects light "pyramid” or sphere or something (depending on wanted effect)

- do sample ray intersection segment with N points along the ray, For every point check if it's obscured by shadow and point's color (texture on light). Accumulate color and alpha exponentially

- mix the accumulated color/alpha with your regular shading color

Without self-shadowing it's enough simple

This topic is closed to new replies.

Advertisement