Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
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
15 changes: 2 additions & 13 deletions crates/bevy_anti_alias/src/dlss/prepare.rs
Original file line number Diff line number Diff line change
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
12 changes: 3 additions & 9 deletions crates/bevy_anti_alias/src/smaa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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 +618,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 +671,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
92 changes: 40 additions & 52 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 @@ -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 @@ -221,9 +220,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 @@ -309,6 +305,7 @@ struct TaaPipelineSpecializer;

#[derive(PartialEq, Eq, Hash, Clone, SpecializerKey)]
struct TaaPipelineKey {
texture_format: TextureFormat,
hdr: bool,
reset: bool,
}
Expand All @@ -322,19 +319,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 @@ -415,42 +408,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 @@ -466,6 +453,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
31 changes: 8 additions & 23 deletions crates/bevy_camera/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::primitives::Frustum;

use super::{
visibility::{Visibility, VisibleEntities},
ClearColorConfig, MsaaWriteback,
ClearColorConfig,
};
use bevy_asset::Handle;
use bevy_derive::Deref;
Expand Down Expand Up @@ -80,17 +80,13 @@ impl Viewport {
}
}

pub fn from_viewport_and_override(
viewport: Option<&Self>,
pub fn from_main_pass_resolution_override(
main_pass_resolution_override: Option<&MainPassResolutionOverride>,
) -> Option<Self> {
if let Some(override_size) = main_pass_resolution_override {
let mut vp = viewport.map_or_else(Self::default, Self::clone);
vp.physical_size = **override_size;
Some(vp)
} else {
viewport.cloned()
}
main_pass_resolution_override.map(|override_size| Viewport {
physical_size: **override_size,
..Default::default()
})
}
}

Expand Down Expand Up @@ -338,14 +334,7 @@ pub enum ViewportConversionError {
/// [`Camera3d`]: crate::Camera3d
#[derive(Component, Debug, Reflect, Clone)]
#[reflect(Component, Default, Debug, Clone)]
#[require(
Frustum,
CameraMainTextureUsages,
VisibleEntities,
Transform,
Visibility,
RenderTarget
)]
#[require(Frustum, VisibleEntities, Transform, Visibility, RenderTarget)]
pub struct Camera {
/// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`].
pub viewport: Option<Viewport>,
Expand All @@ -360,9 +349,6 @@ pub struct Camera {
// todo: reflect this when #6042 lands
/// The [`CameraOutputMode`] for this camera.
pub output_mode: CameraOutputMode,
/// Controls when MSAA writeback occurs for this camera.
/// See [`MsaaWriteback`] for available options.
pub msaa_writeback: MsaaWriteback,
/// The clear color operation to perform on the render target.
pub clear_color: ClearColorConfig,
/// Whether to switch culling mode so that materials that request backface
Expand All @@ -386,7 +372,6 @@ impl Default for Camera {
viewport: None,
computed: Default::default(),
output_mode: Default::default(),
msaa_writeback: MsaaWriteback::default(),
clear_color: Default::default(),
invert_culling: false,
sub_camera_view: None,
Expand Down Expand Up @@ -884,7 +869,7 @@ pub enum NormalizedRenderTarget {

/// A unique id that corresponds to a specific `ManualTextureView` in the `ManualTextureViews` collection.
///
/// See `ManualTextureViews` in `bevy_camera` for more details.
/// See `ManualTextureViews` in `bevy_render` for more details.
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Component, Reflect)]
#[reflect(Component, Default, Debug, PartialEq, Hash, Clone)]
pub struct ManualTextureViewHandle(pub u32);
Expand Down
19 changes: 0 additions & 19 deletions crates/bevy_camera/src/clear_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,6 @@ pub enum ClearColorConfig {
None,
}

/// Controls when MSAA writeback occurs for a camera.
///
/// MSAA writeback copies the previous camera's output into the MSAA sampled texture before
/// rendering, allowing multiple cameras to layer their results when MSAA is enabled.
#[derive(Reflect, Serialize, Deserialize, Copy, Clone, Debug, Default, PartialEq, Eq)]
#[reflect(Serialize, Deserialize, Default, Clone)]
pub enum MsaaWriteback {
/// Never perform MSAA writeback for this camera.
Off,
/// Perform MSAA writeback only when this camera is not the first one rendering to the target.
/// This is the default behavior - the first camera has nothing to write back.
#[default]
Auto,
/// Always perform MSAA writeback, even if this is the first camera rendering to the target.
/// This is useful when content has been written directly to the main texture (e.g., via
/// `write_texture`) and needs to be preserved through the MSAA render pass.
Always,
}

/// A [`Resource`] that stores the default color that cameras use to clear the screen between frames.
///
/// This color appears as the "background" color for simple apps,
Expand Down
Loading