diff --git a/README.md b/README.md index 04784ae..c2ac20f 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,11 @@ use bevy_volumetric_clouds::CloudsPlugin; app.add_plugins(CloudsPlugin); ``` +Then add `CloudCamera` component to the camera that should have clouds. +```rust +commands.spawn((Camera3d::default(), Hdr, CloudCamera)); +``` + Look at [the minimal example](examples/minimal.rs) for a working example. The [the demo example](examples/demo.rs) features a usable demo where you can move the camera around diff --git a/examples/demo.rs b/examples/demo.rs index c20d3a8..b02eb1c 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -6,9 +6,9 @@ use bevy::prelude::*; use bevy::render::view::Hdr; #[cfg(feature = "debug")] use bevy_egui::EguiPlugin; -use bevy_volumetric_clouds::CloudsPlugin; #[cfg(feature = "fly_camera")] use bevy_volumetric_clouds::fly_camera::{FlyCam, FlyCameraPlugin}; +use bevy_volumetric_clouds::{CloudCamera, CloudsPlugin}; fn close_on_esc( mut commands: Commands, @@ -45,6 +45,7 @@ fn setup( commands.spawn(( Camera3d::default(), Hdr, + CloudCamera, #[cfg(feature = "fly_camera")] FlyCam, Transform::from_translation(Vec3::new(0.0, 3.0, 0.0)).looking_to(Vec3::X, Vec3::Y), diff --git a/examples/minimal.rs b/examples/minimal.rs index a865211..45a1bcc 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -1,6 +1,6 @@ //! A minimal example featuring clouds. use bevy::{prelude::*, render::view::Hdr}; -use bevy_volumetric_clouds::CloudsPlugin; +use bevy_volumetric_clouds::{CloudCamera, CloudsPlugin}; fn main() { App::new() @@ -10,5 +10,5 @@ fn main() { } fn setup(mut commands: Commands) { - commands.spawn((Camera3d::default(), Hdr)); + commands.spawn((Camera3d::default(), Hdr, CloudCamera)); } diff --git a/src/compute.rs b/src/compute.rs index e6315d5..9dd2f4f 100644 --- a/src/compute.rs +++ b/src/compute.rs @@ -1,12 +1,17 @@ use bevy::{ asset::load_embedded_asset, + camera::CameraProjection, + core_pipeline::core_3d::graph::{Core3d, Node3d}, ecs::system::ResMut, prelude::*, render::{ Extract, Render, RenderApp, RenderSystems, + extract_component::ExtractComponentPlugin, extract_resource::ExtractResourcePlugin, render_asset::RenderAssets, - render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext, RenderLabel}, + render_graph::{ + NodeRunError, RenderGraphContext, RenderGraphExt, RenderLabel, ViewNode, ViewNodeRunner, + }, render_resource::{ AsBindGroup, BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, CachedComputePipelineId, CachedPipelineState, ComputePassDescriptor, @@ -19,7 +24,7 @@ use bevy::{ /// Controls the compute shader which renders the volumetric clouds. use std::borrow::Cow; -use crate::config::CloudsConfig; +use crate::{CloudCamera, config::CloudsConfig}; use super::{ images::IMAGE_SIZE, @@ -47,11 +52,12 @@ fn prepare_uniforms_bind_group( pipeline: Res, render_queue: Res, mut clouds_uniform_buffer: ResMut, - camera: ResMut, + camera: Option>, clouds_config: Res, render_device: Res, time: Res