Implement volumetric fog and volumetric lighting, also known as light shafts or god rays.
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:
-
Raymarching at a lower resolution.
-
A post-processing blur (especially useful when combined with (1)).
-
Supporting point lights and spot lights.
-
Supporting lights with no shadow maps.
-
Supporting irradiance volumes and reflection probes.
-
Voxel components that reuse the volumetric fog code to create voxel shapes.
-
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 withVolumetricFog. Notably, this allows such lights to emit light shafts/god rays.
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
I think the CI failure is spurious.
I think the CI failure is spurious.
Yup, feel free to rebase / merge from main to get the check started again. :)
Closing as I am burned out and have no motivation to get this landed anymore.
Note to maintainers. I extracted the mesh view layouts change to it's own PR since those changes make sense outside of this PR. #13266
That PR should be merged first, but it's not a blocker if we don't do that.
@pcwalton since https://github.com/bevyengine/bevy/pull/13266 was merged this needs a merge. There shouldn't be conflicts, at least nothing complicated, but you'll be able to remove the .view_layouts.get_view_layout that you added in a few places.
Once merge conflicts are resolved I'll merge this in :) Do let us know if you'd like a hand.
I'm not sure I did it correctly, but I merged main and fixed the confict in this PR to your PR https://github.com/pcwalton/bevy/pull/5
This should be ready now.
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to https://github.com/bevyengine/bevy-website/issues/1318 if you'd like to help out.