|
| 1 | +--- |
| 2 | +title: "Generalized Atmospheric Scattering Media" |
| 3 | +authors: ["@ecoskey"] |
| 4 | +pull_requests: [20838] |
| 5 | +--- |
| 6 | + |
| 7 | +Until now, Bevy's atmospheric scattering system has been fast and beautiful, but |
| 8 | +not very customizable. There's only a limited number of ways to customize the |
| 9 | +existing parameters, which constrain the system to mostly earth-like scenes. |
| 10 | + |
| 11 | +Bevy 0.18 introduces a new `ScatteringMedium` asset for designing atmospheric |
| 12 | +scattering media of all kinds: clear desert skies, foggy coastlines, and |
| 13 | +even atmospheres of other planets! We've used Bevy's asset system to the |
| 14 | +fullest--alongside some custom optimizations--to make sure rendering stays |
| 15 | +fast even for complicated scattering media. |
| 16 | + |
| 17 | +```rust |
| 18 | +fn setup_camera( |
| 19 | + mut commands: Commands, |
| 20 | + mut media: ResMut<Assets<ScatteringMedium>>, |
| 21 | +) { |
| 22 | + // Also feel free to use `ScatteringMedium::earthlike()`! |
| 23 | + let medium = media.add(ScatteringMedium::new( |
| 24 | + 256, |
| 25 | + 256, |
| 26 | + [ |
| 27 | + ScatteringTerm { |
| 28 | + absorption: Vec3::ZERO, |
| 29 | + scattering: Vec3::new(5.802e-6, 13.558e-6, 33.100e-6), |
| 30 | + falloff: Falloff::Exponential { strength: 12.5 }, |
| 31 | + phase: PhaseFunction::Rayleigh, |
| 32 | + }, |
| 33 | + ScatteringTerm { |
| 34 | + absorption: Vec3::splat(3.996e-6), |
| 35 | + scattering: Vec3::splat(0.444e-6), |
| 36 | + falloff: Falloff::Exponential { strength: 83.5 }, |
| 37 | + phase: PhaseFunction::Mie { asymmetry: 0.8 }, |
| 38 | + }, |
| 39 | + ScatteringTerm { |
| 40 | + absorption: Vec3::new(0.650e-6, 1.881e-6, 0.085e-6), |
| 41 | + scattering: Vec3::ZERO, |
| 42 | + falloff: Falloff::Tent { |
| 43 | + center: 0.75, |
| 44 | + width: 0.3, |
| 45 | + }, |
| 46 | + phase: PhaseFunction::Isotropic, |
| 47 | + }, |
| 48 | + ], |
| 49 | + )); |
| 50 | + |
| 51 | + commands.spawn(( |
| 52 | + Camera3d, |
| 53 | + Atmosphere::earthlike(medium) |
| 54 | + )); |
| 55 | +} |
| 56 | + |
| 57 | +// We've provided a nice `EarthlikeAtmosphere` resource |
| 58 | +// for the most common case :) |
| 59 | +fn setup_camera_simple( |
| 60 | + mut commands: Commands, |
| 61 | + earthlike_atmosphere: Res<EarthlikeAtmosphere> |
| 62 | +) { |
| 63 | + commands.spawn(( |
| 64 | + Camera3d, |
| 65 | + earthlike_atmosphere.get(), |
| 66 | + )); |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +(TODO: engine example of martian/extraterrestrial sunrise) |
| 71 | + |
| 72 | +Alongside this change we've also added a bunch of documentation, and links to |
| 73 | +learn more about the technical terms used. It's definitely a complex feature |
| 74 | +under the hood, so we're hoping to make the learning curve a little less steep :) |
0 commit comments