Skip to content

Commit 3f5273c

Browse files
authored
make taa work with ortho (#20951)
# Objective - fix temporal jitter for ortho ## Solution - look at ortho matrix definition and derive correct pixel value range - remove stuff saying you cant taa ortho ## Testing - #20950
1 parent f767e19 commit 3f5273c

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

crates/bevy_anti_alias/src/taa/mod.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy_app::{App, Plugin};
22
use bevy_asset::{embedded_asset, load_embedded_asset, AssetServer, Handle};
3-
use bevy_camera::{Camera, Camera3d, Projection};
3+
use bevy_camera::{Camera, Camera3d};
44
use bevy_core_pipeline::{
55
core_3d::graph::{Core3d, Node3d},
66
prepass::{DepthPrepass, MotionVectorPrepass, ViewPrepassTextures},
@@ -83,7 +83,7 @@ impl Plugin for TemporalAntiAliasPlugin {
8383
}
8484
}
8585

86-
/// Component to apply temporal anti-aliasing to a 3D perspective camera.
86+
/// Component to apply temporal anti-aliasing to a 3D camera.
8787
///
8888
/// Temporal anti-aliasing (TAA) is a form of image smoothing/filtering, like
8989
/// multisample anti-aliasing (MSAA), or fast approximate anti-aliasing (FXAA).
@@ -109,8 +109,6 @@ impl Plugin for TemporalAntiAliasPlugin {
109109
///
110110
/// Any camera with this component must also disable [`Msaa`] by setting it to [`Msaa::Off`].
111111
///
112-
/// [Currently](https://github.com/bevyengine/bevy/issues/8423), TAA cannot be used with [`bevy_camera::OrthographicProjection`].
113-
///
114112
/// TAA also does not work well with alpha-blended meshes, as it requires depth writing to determine motion.
115113
///
116114
/// It is very important that correct motion vectors are written for everything on screen.
@@ -344,20 +342,15 @@ impl SpecializedRenderPipeline for TaaPipeline {
344342
}
345343

346344
fn extract_taa_settings(mut commands: Commands, mut main_world: ResMut<MainWorld>) {
347-
let mut cameras_3d = main_world.query::<(
348-
RenderEntity,
349-
&Camera,
350-
&Projection,
351-
Option<&mut TemporalAntiAliasing>,
352-
)>();
353-
354-
for (entity, camera, camera_projection, taa_settings) in cameras_3d.iter_mut(&mut main_world) {
345+
let mut cameras_3d =
346+
main_world.query::<(RenderEntity, &Camera, Option<&mut TemporalAntiAliasing>)>();
347+
348+
for (entity, camera, taa_settings) in cameras_3d.iter_mut(&mut main_world) {
355349
let mut entity_commands = commands
356350
.get_entity(entity)
357351
.expect("Camera entity wasn't synced.");
358352
if let Some(mut taa_settings) = taa_settings
359353
&& camera.is_active
360-
&& camera_projection.is_perspective()
361354
{
362355
entity_commands.insert(taa_settings.clone());
363356
taa_settings.reset = false;

crates/bevy_render/src/camera.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,6 @@ pub fn sort_cameras(
658658
/// A subpixel offset to jitter a perspective camera's frustum by.
659659
///
660660
/// Useful for temporal rendering techniques.
661-
///
662-
/// Do not use with [`OrthographicProjection`].
663-
///
664-
/// [`OrthographicProjection`]: bevy_camera::OrthographicProjection
665661
#[derive(Component, Clone, Default, Reflect)]
666662
#[reflect(Default, Component, Clone)]
667663
pub struct TemporalJitter {
@@ -671,16 +667,14 @@ pub struct TemporalJitter {
671667

672668
impl TemporalJitter {
673669
pub fn jitter_projection(&self, clip_from_view: &mut Mat4, view_size: Vec2) {
670+
// https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/blob/d7531ae47d8b36a5d4025663e731a47a38be882f/docs/techniques/media/super-resolution-temporal/jitter-space.svg
671+
let mut jitter = (self.offset * vec2(2.0, -2.0)) / view_size;
672+
673+
// orthographic
674674
if clip_from_view.w_axis.w == 1.0 {
675-
warn!(
676-
"TemporalJitter not supported with OrthographicProjection. Use PerspectiveProjection instead."
677-
);
678-
return;
675+
jitter *= vec2(clip_from_view.x_axis.x, clip_from_view.y_axis.y) * 0.5;
679676
}
680677

681-
// https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/blob/d7531ae47d8b36a5d4025663e731a47a38be882f/docs/techniques/media/super-resolution-temporal/jitter-space.svg
682-
let jitter = (self.offset * vec2(2.0, -2.0)) / view_size;
683-
684678
clip_from_view.z_axis.x += jitter.x;
685679
clip_from_view.z_axis.y += jitter.y;
686680
}

0 commit comments

Comments
 (0)