Examples: Add basic fog scattering demo. #32613
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue: -
Description
The main purpose of fog in three.js is to fade objects into the background color. Just this fade-out on its own does not look very realistic though since fog has the property to scatter light that travels through it. One way to simulate this is with volumetric rendering but that's in general an expensive technique. The PR demonstrates a simple approach that works on a wide variety of devices and produces a slightly more realistic fog.
The idea is to render the scene with fog as usual but then an additional (downsampled) blurred version. The fog factor is then used to compose both together. Since blurring and fog factor computation are decoupled, you can choose any technique for fog (range, density) and blur (gauss, box, hash) you like.
Related Unity discussion: https://discussions.unity.com/t/screen-space-multiple-scattering/649273
Live link: https://rawcdn.githack.com/Mugen87/three.js/42e4d545dba4e9b821f5e35391e7bb809d8653b4/examples/webgpu_custom_fog_scattering.html
The demo reuses the scene setup of
webgpu_custom_fogwhich is ideal to showcase the effect.