mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Fix temporal jitter bug (#9462)
* Fixed jitter being applied in the wrong coordinate space, leading to aliasing. * Fixed incorrectly using the cached view_proj instead of account for temporal jitter. * Added a diagram to ensure the coordinate space is clear. Before: ![image](https://github.com/bevyengine/bevy/assets/47158642/55b4bed4-4fb0-4fb2-a271-cc10a987e4d7) After: ![image](https://github.com/bevyengine/bevy/assets/47158642/cbde4553-4e35-44d9-8ccf-f3a06e64a31f)
This commit is contained in:
parent
657c14026a
commit
94e81c2855
2 changed files with 12 additions and 5 deletions
|
@ -19,7 +19,7 @@ use bevy_ecs::{
|
|||
system::{Commands, Query, Res, ResMut, Resource},
|
||||
};
|
||||
use bevy_log::warn;
|
||||
use bevy_math::{Mat4, Ray, Rect, UVec2, UVec4, Vec2, Vec3};
|
||||
use bevy_math::{vec2, Mat4, Ray, Rect, UVec2, UVec4, Vec2, Vec3};
|
||||
use bevy_reflect::prelude::*;
|
||||
use bevy_transform::components::GlobalTransform;
|
||||
use bevy_utils::{HashMap, HashSet};
|
||||
|
@ -769,7 +769,8 @@ impl TemporalJitter {
|
|||
return;
|
||||
}
|
||||
|
||||
let jitter = self.offset / view_size;
|
||||
// https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/blob/d7531ae47d8b36a5d4025663e731a47a38be882f/docs/techniques/media/super-resolution-temporal/jitter-space.svg
|
||||
let jitter = (self.offset * vec2(2.0, -2.0)) / view_size;
|
||||
|
||||
projection.z_axis.x += jitter.x;
|
||||
projection.z_axis.y += jitter.y;
|
||||
|
|
|
@ -375,11 +375,17 @@ pub fn prepare_view_uniforms(
|
|||
let view = camera.transform.compute_matrix();
|
||||
let inverse_view = view.inverse();
|
||||
|
||||
let view_proj = if temporal_jitter.is_some() {
|
||||
projection * inverse_view
|
||||
} else {
|
||||
camera
|
||||
.view_projection
|
||||
.unwrap_or_else(|| projection * inverse_view)
|
||||
};
|
||||
|
||||
let view_uniforms = ViewUniformOffset {
|
||||
offset: view_uniforms.uniforms.push(ViewUniform {
|
||||
view_proj: camera
|
||||
.view_projection
|
||||
.unwrap_or_else(|| projection * inverse_view),
|
||||
view_proj,
|
||||
unjittered_view_proj: unjittered_projection * inverse_view,
|
||||
inverse_view_proj: view * inverse_projection,
|
||||
view,
|
||||
|
|
Loading…
Reference in a new issue