Crate bevy_atmosphere

source ·
Expand description

A procedural sky plugin for the Bevy game engine.

Provides a framework for creating and using atmospheric models.

§“basic” Example

use bevy::prelude::*;
use bevy_atmosphere::prelude::*;

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, AtmospherePlugin))
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn((Camera3dBundle::default(), AtmosphereCamera::default()));
}

How the sky is rendered is described by an Atmospheric model. bevy_atmosphere provides a collection of models to use, but you can create your own as well.

To read and modify the atmospheric model, use the Atmosphere<T> and AtmosphereMut<T> system params or the AtmosphereModel resource.

fn read_nishita(atmosphere: Atmosphere<Nishita>) {
    let sun_position = atmosphere.sun_position;
    println!("Sun is at {sun_position}");
}

fn write_gradient(mut atmosphere: AtmosphereMut<Gradient>) {
    atmosphere.horizon = LinearRgba::RED;
}

fn check_model(atmosphere: Res<AtmosphereModel>) {
    if let Some(nishita) = atmosphere.to_ref::<Nishita>() {
        println!("Sun is at {}", nishita.sun_position);
    } else {
        println!("Model isn't Nishita");
    }
}

Use the AtmosphereSettings resource to change how the sky is rendered.

AtmosphereSettings {
    // changes the resolution (should be a multiple of 8)
    resolution: 1024,
    // turns off dithering
    dithering: false,
}

To see more examples, view the “examples” directory.

Modules§

  • Provides a collection of atmospheric models.
  • Provides the Atmospheric trait and AtmosphereModel resource.
  • Provides types and logic for a compute pipeline that renders the procedural sky texture.
  • Provides a Plugin for making skyboxes with procedural sky textures.
  • use bevy_atmosphere::prelude::*; to import the most commonly used items.
  • Provides AtmosphereSettings resource, a type that controls how the sky is rendered.
  • Provides types and data needed for rendering a skybox.
  • Provides system params for easy reading/modifying of Atmospheric models.