bevy/crates/bevy_core_pipeline/src
Patrick Walton 19bfa41768
Implement volumetric fog and volumetric lighting, also known as light shafts or god rays. (#13057)
This commit implements a more physically-accurate, but slower, form of
fog than the `bevy_pbr::fog` module does. Notably, this *volumetric fog*
allows for light beams from directional lights to shine through,
creating what is known as *light shafts* or *god rays*.

To add volumetric fog to a scene, add `VolumetricFogSettings` to the
camera, and add `VolumetricLight` to directional lights that you wish to
be volumetric. `VolumetricFogSettings` has numerous settings that allow
you to define the accuracy of the simulation, as well as the look of the
fog. Currently, only interaction with directional lights that have
shadow maps is supported. Note that the overhead of the effect scales
directly with the number of directional lights in use, so apply
`VolumetricLight` sparingly for the best results.

The overall algorithm, which is implemented as a postprocessing effect,
is a combination of the techniques described in [Scratchapixel] and
[this blog post]. It uses raymarching in screen space, transformed into
shadow map space for sampling and combined with physically-based
modeling of absorption and scattering. Bevy employs the widely-used
[Henyey-Greenstein phase function] to model asymmetry; this essentially
allows light shafts to fade into and out of existence as the user views
them.

Volumetric rendering is a huge subject, and I deliberately kept the
scope of this commit small. Possible follow-ups include:

1. Raymarching at a lower resolution.

2. A post-processing blur (especially useful when combined with (1)).

3. Supporting point lights and spot lights.

4. Supporting lights with no shadow maps.

5. Supporting irradiance volumes and reflection probes.

6. Voxel components that reuse the volumetric fog code to create voxel
shapes.

7. *Horizon: Zero Dawn*-style clouds.

These are all useful, but out of scope of this patch for now, to keep
things tidy and easy to review.

A new example, `volumetric_fog`, has been added to demonstrate the
effect.

## Changelog

### Added

* A new component, `VolumetricFog`, is available, to allow for a more
physically-accurate, but more resource-intensive, form of fog.

* A new component, `VolumetricLight`, can be placed on directional
lights to make them interact with `VolumetricFog`. Notably, this allows
such lights to emit light shafts/god rays.

![Screenshot 2024-04-21
162808](https://github.com/bevyengine/bevy/assets/157897/7a1fc81d-eed5-4735-9419-286c496391a9)

![Screenshot 2024-04-21
132005](https://github.com/bevyengine/bevy/assets/157897/e6d3b5ca-8f59-488d-a3de-15e95aaf4995)

[Scratchapixel]:
https://www.scratchapixel.com/lessons/3d-basic-rendering/volume-rendering-for-developers/intro-volume-rendering.html

[this blog post]: https://www.alexandre-pestana.com/volumetric-lights/

[Henyey-Greenstein phase function]:
https://www.pbr-book.org/4ed/Volume_Scattering/Phase_Functions#TheHenyeyndashGreensteinPhaseFunction
2024-05-16 17:13:18 +00:00
..
auto_exposure Fix incorrect workgroupBarrier and OOB array access in auto_exposure (#13283) 2024-05-12 23:24:58 +00:00
blit Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
bloom Clean up 2d render phases (#12982) 2024-05-08 08:13:39 +00:00
contrast_adaptive_sharpening Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
core_2d Fix ClearColor in 2d pipelines (#13378) 2024-05-15 20:36:02 +00:00
core_3d Implement volumetric fog and volumetric lighting, also known as light shafts or god rays. (#13057) 2024-05-16 17:13:18 +00:00
deferred Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
dof Enable depth of field on webgpu (#13374) 2024-05-16 06:48:28 +00:00
fullscreen_vertex_shader Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
fxaa Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
motion_blur Fix motion blur on wasm (#13099) 2024-05-12 21:03:36 +00:00
prepass Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
skybox Consolidate Render(Ui)Materials(2d) into RenderAssets (#12827) 2024-04-09 13:26:34 +00:00
taa Per-Object Motion Blur (#9924) 2024-04-25 01:16:02 +00:00
tonemapping move wgsl color operations from bevy_pbr to bevy_render (#13209) 2024-05-04 10:30:23 +00:00
upscaling Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
lib.rs Implement fast depth of field as a postprocessing effect. (#13009) 2024-05-13 18:23:56 +00:00
msaa_writeback.rs Clean up 2d render phases (#12982) 2024-05-08 08:13:39 +00:00