Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4769,6 +4769,18 @@ description = "Demonstrates screen space reflections with water ripples"
category = "3D Rendering"
wasm = false

[[example]]
name = "camera_color_target_graph"
path = "examples/3d/camera_color_target_graph.rs"
# Causes an ICE on docs.rs
doc-scrape-examples = false

[package.metadata.example.camera_color_target_graph]
name = "Camera color target graph"
description = "Demonstrates connecting color target input and output of multiple cameras"
category = "3D Rendering"
wasm = true

[[example]]
name = "camera_sub_view"
path = "examples/3d/camera_sub_view.rs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use bevy_core_pipeline::{
FullscreenShader,
};
use bevy_ecs::{prelude::*, query::QueryItem};
use bevy_image::BevyDefault as _;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin},
Expand All @@ -17,7 +16,7 @@ use bevy_render::{
*,
},
renderer::RenderDevice,
view::{ExtractedView, ViewTarget},
view::ExtractedView,
Render, RenderApp, RenderStartup, RenderSystems,
};

Expand Down Expand Up @@ -260,11 +259,7 @@ fn prepare_cas_pipelines(
&pipeline_cache,
CasPipelineKey {
denoise: denoise_cas.0,
texture_format: if view.hdr {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
},
texture_format: view.color_target_format,
},
)?;

Expand Down
17 changes: 3 additions & 14 deletions crates/bevy_anti_alias/src/dlss/prepare.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Dlss, DlssFeature, DlssSdk};
use bevy_camera::{Camera3d, CameraMainTextureUsages, MainPassResolutionOverride};
use bevy_camera::{Camera3d, MainPassResolutionOverride};
use bevy_core_pipeline::prepass::{DepthPrepass, MotionVectorPrepass};
use bevy_diagnostic::FrameCount;
use bevy_ecs::{
Expand Down Expand Up @@ -32,7 +32,6 @@ pub fn prepare_dlss<F: DlssFeature>(
&ExtractedView,
&Dlss<F>,
&mut Camera3d,
&mut CameraMainTextureUsages,
&mut TemporalJitter,
&mut MipBias,
Option<&mut DlssRenderContext<F>>,
Expand All @@ -50,19 +49,9 @@ pub fn prepare_dlss<F: DlssFeature>(
frame_count: Res<FrameCount>,
mut commands: Commands,
) {
for (
entity,
view,
dlss,
mut camera_3d,
mut camera_main_texture_usages,
mut temporal_jitter,
mut mip_bias,
mut dlss_context,
) in &mut query
for (entity, view, dlss, mut camera_3d, mut temporal_jitter, mut mip_bias, mut dlss_context) in
&mut query
{
camera_main_texture_usages.0 |= TextureUsages::STORAGE_BINDING;

let mut depth_texture_usages = TextureUsages::from(camera_3d.depth_texture_usages);
depth_texture_usages |= TextureUsages::TEXTURE_BINDING;
camera_3d.depth_texture_usages = depth_texture_usages.into();
Expand Down
9 changes: 2 additions & 7 deletions crates/bevy_anti_alias/src/fxaa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use bevy_core_pipeline::{
FullscreenShader,
};
use bevy_ecs::prelude::*;
use bevy_image::BevyDefault as _;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
Expand All @@ -17,7 +16,7 @@ use bevy_render::{
*,
},
renderer::RenderDevice,
view::{ExtractedView, ViewTarget},
view::ExtractedView,
Render, RenderApp, RenderStartup, RenderSystems,
};
use bevy_shader::Shader;
Expand Down Expand Up @@ -216,11 +215,7 @@ pub fn prepare_fxaa_pipelines(
FxaaPipelineKey {
edge_threshold: fxaa.edge_threshold,
edge_threshold_min: fxaa.edge_threshold_min,
texture_format: if view.hdr {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
},
texture_format: view.color_target_format,
},
);

Expand Down
15 changes: 4 additions & 11 deletions crates/bevy_anti_alias/src/smaa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
//! To use SMAA, add [`Smaa`] to a [`bevy_camera::Camera`]. In a
//! pinch, you can simply use the default settings (via the [`Default`] trait)
//! for a high-quality, high-performance appearance. When using SMAA, you will
//! likely want set [`bevy_render::view::Msaa`] to [`bevy_render::view::Msaa::Off`]
//! for every camera using SMAA.
//! likely want to disable MSAA for every camera using SMAA.
//!
//! Those who have used SMAA in other engines should be aware that Bevy doesn't
//! yet support the following more advanced features of SMAA:
Expand Down Expand Up @@ -48,7 +47,7 @@ use bevy_ecs::{
system::{lifetimeless::Read, Commands, Query, Res, ResMut},
world::World,
};
use bevy_image::{BevyDefault, Image, ToExtents};
use bevy_image::{Image, ToExtents};
use bevy_math::{vec4, Vec4};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
Expand Down Expand Up @@ -618,11 +617,7 @@ fn prepare_smaa_pipelines(
&pipeline_cache,
&smaa_pipelines.neighborhood_blending,
SmaaNeighborhoodBlendingPipelineKey {
texture_format: if view.hdr {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
},
texture_format: view.color_target_format,
preset: smaa.preset,
},
);
Expand Down Expand Up @@ -675,9 +670,7 @@ fn prepare_smaa_textures(
view_targets: Query<(Entity, &ExtractedCamera), (With<ExtractedView>, With<Smaa>)>,
) {
for (entity, camera) in &view_targets {
let Some(texture_size) = camera.physical_target_size else {
continue;
};
let texture_size = camera.main_color_target_size;

// Create the two-channel RG texture for phase 1 (edge detection).
let edge_detection_color_texture = texture_cache.get(
Expand Down
94 changes: 41 additions & 53 deletions crates/bevy_anti_alias/src/taa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bevy_ecs::{
system::{Commands, Query, Res, ResMut},
world::World,
};
use bevy_image::{BevyDefault as _, ToExtents};
use bevy_image::ToExtents;
use bevy_math::vec2;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
Expand All @@ -36,7 +36,7 @@ use bevy_render::{
sync_component::SyncComponentPlugin,
sync_world::RenderEntity,
texture::{CachedTexture, TextureCache},
view::{ExtractedView, Msaa, ViewTarget},
view::{ExtractedView, ViewTarget},
ExtractSchedule, MainWorld, Render, RenderApp, RenderStartup, RenderSystems,
};
use bevy_utils::default;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Plugin for TemporalAntiAliasPlugin {
///
/// # Usage Notes
///
/// Any camera with this component must also disable [`Msaa`] by setting it to [`Msaa::Off`].
/// Any camera with this component must also disable MSAA.
///
/// TAA also does not work well with alpha-blended meshes, as it requires depth writing to determine motion.
///
Expand Down Expand Up @@ -143,24 +143,23 @@ pub struct TemporalAntiAliasNode;

impl ViewNode for TemporalAntiAliasNode {
type ViewQuery = (
&'static ExtractedCamera,
&'static ExtractedView,
&'static ViewTarget,
&'static TemporalAntiAliasHistoryTextures,
&'static ViewPrepassTextures,
&'static TemporalAntiAliasPipelineId,
&'static Msaa,
);

fn run(
&self,
_graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
(camera, view_target, taa_history_textures, prepass_textures, taa_pipeline_id, msaa): QueryItem<
(view, view_target, taa_history_textures, prepass_textures, taa_pipeline_id): QueryItem<
Self::ViewQuery,
>,
world: &World,
) -> Result<(), NodeRunError> {
if *msaa != Msaa::Off {
if view.msaa_samples != 1 {
warn!("Temporal anti-aliasing requires MSAA to be disabled");
return Ok(());
}
Expand Down Expand Up @@ -222,9 +221,6 @@ impl ViewNode for TemporalAntiAliasNode {

taa_pass.set_render_pipeline(taa_pipeline);
taa_pass.set_bind_group(0, &taa_bind_group, &[]);
if let Some(viewport) = camera.viewport.as_ref() {
taa_pass.set_camera_viewport(viewport);
}
taa_pass.draw(0..3, 0..1);

pass_span.end(&mut taa_pass);
Expand Down Expand Up @@ -310,6 +306,7 @@ struct TaaPipelineSpecializer;

#[derive(PartialEq, Eq, Hash, Clone, SpecializerKey)]
struct TaaPipelineKey {
texture_format: TextureFormat,
hdr: bool,
reset: bool,
}
Expand All @@ -323,19 +320,15 @@ impl Specializer<RenderPipeline> for TaaPipelineSpecializer {
descriptor: &mut RenderPipelineDescriptor,
) -> Result<Canonical<Self::Key>, BevyError> {
let fragment = descriptor.fragment_mut()?;
let format = if key.hdr {
if key.hdr {
fragment.shader_defs.push("TONEMAP".into());
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
};

}
if key.reset {
fragment.shader_defs.push("RESET".into());
}

let color_target_state = ColorTargetState {
format,
format: key.texture_format,
blend: None,
write_mask: ColorWrites::ALL,
};
Expand Down Expand Up @@ -416,42 +409,36 @@ fn prepare_taa_history_textures(
views: Query<(Entity, &ExtractedCamera, &ExtractedView), With<TemporalAntiAliasing>>,
) {
for (entity, camera, view) in &views {
if let Some(physical_target_size) = camera.physical_target_size {
let mut texture_descriptor = TextureDescriptor {
label: None,
size: physical_target_size.to_extents(),
mip_level_count: 1,
sample_count: 1,
dimension: TextureDimension::D2,
format: if view.hdr {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
},
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
};

texture_descriptor.label = Some("taa_history_1_texture");
let history_1_texture = texture_cache.get(&render_device, texture_descriptor.clone());

texture_descriptor.label = Some("taa_history_2_texture");
let history_2_texture = texture_cache.get(&render_device, texture_descriptor);

let textures = if frame_count.0.is_multiple_of(2) {
TemporalAntiAliasHistoryTextures {
write: history_1_texture,
read: history_2_texture,
}
} else {
TemporalAntiAliasHistoryTextures {
write: history_2_texture,
read: history_1_texture,
}
};

commands.entity(entity).insert(textures);
}
let mut texture_descriptor = TextureDescriptor {
label: None,
size: camera.main_color_target_size.to_extents(),
mip_level_count: 1,
sample_count: 1,
dimension: TextureDimension::D2,
format: view.color_target_format,
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
};

texture_descriptor.label = Some("taa_history_1_texture");
let history_1_texture = texture_cache.get(&render_device, texture_descriptor.clone());

texture_descriptor.label = Some("taa_history_2_texture");
let history_2_texture = texture_cache.get(&render_device, texture_descriptor);

let textures = if frame_count.0.is_multiple_of(2) {
TemporalAntiAliasHistoryTextures {
write: history_1_texture,
read: history_2_texture,
}
} else {
TemporalAntiAliasHistoryTextures {
write: history_2_texture,
read: history_1_texture,
}
};

commands.entity(entity).insert(textures);
}
}

Expand All @@ -467,6 +454,7 @@ fn prepare_taa_pipelines(
for (entity, view, taa_settings) in &views {
let mut pipeline_key = TaaPipelineKey {
hdr: view.hdr,
texture_format: view.color_target_format,
reset: taa_settings.reset,
};
let pipeline_id = pipeline
Expand Down
Loading
Loading