Add more PreviousViewData (#19605)
Add some more matrices to PreviousViewData for future use with bevy_solari.
This commit is contained in:
parent
b7d2cb8547
commit
e610badf6c
@ -74,11 +74,16 @@ pub struct MotionVectorPrepass;
|
||||
#[reflect(Component, Default)]
|
||||
pub struct DeferredPrepass;
|
||||
|
||||
/// View matrices from the previous frame.
|
||||
///
|
||||
/// Useful for temporal rendering techniques that need access to last frame's camera data.
|
||||
#[derive(Component, ShaderType, Clone)]
|
||||
pub struct PreviousViewData {
|
||||
pub view_from_world: Mat4,
|
||||
pub clip_from_world: Mat4,
|
||||
pub clip_from_view: Mat4,
|
||||
pub world_from_clip: Mat4,
|
||||
pub view_from_clip: Mat4,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
|
@ -216,11 +216,16 @@ pub fn update_previous_view_data(
|
||||
query: Query<(Entity, &Camera, &GlobalTransform), Or<(With<Camera3d>, With<ShadowView>)>>,
|
||||
) {
|
||||
for (entity, camera, camera_transform) in &query {
|
||||
let view_from_world = camera_transform.compute_matrix().inverse();
|
||||
let world_from_view = camera_transform.compute_matrix();
|
||||
let view_from_world = world_from_view.inverse();
|
||||
let view_from_clip = camera.clip_from_view().inverse();
|
||||
|
||||
commands.entity(entity).try_insert(PreviousViewData {
|
||||
view_from_world,
|
||||
clip_from_world: camera.clip_from_view() * view_from_world,
|
||||
clip_from_view: camera.clip_from_view(),
|
||||
world_from_clip: world_from_view * view_from_clip,
|
||||
view_from_clip,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -698,11 +703,16 @@ pub fn prepare_previous_view_uniforms(
|
||||
let prev_view_data = match maybe_previous_view_uniforms {
|
||||
Some(previous_view) => previous_view.clone(),
|
||||
None => {
|
||||
let view_from_world = camera.world_from_view.compute_matrix().inverse();
|
||||
let world_from_view = camera.world_from_view.compute_matrix();
|
||||
let view_from_world = world_from_view.inverse();
|
||||
let view_from_clip = camera.clip_from_view.inverse();
|
||||
|
||||
PreviousViewData {
|
||||
view_from_world,
|
||||
clip_from_world: camera.clip_from_view * view_from_world,
|
||||
clip_from_view: camera.clip_from_view,
|
||||
world_from_clip: world_from_view * view_from_clip,
|
||||
view_from_clip,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -4,6 +4,8 @@ struct PreviousViewUniforms {
|
||||
view_from_world: mat4x4<f32>,
|
||||
clip_from_world: mat4x4<f32>,
|
||||
clip_from_view: mat4x4<f32>,
|
||||
world_from_clip: mat4x4<f32>,
|
||||
view_from_clip: mat4x4<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var<uniform> previous_view_uniforms: PreviousViewUniforms;
|
||||
|
Loading…
Reference in New Issue
Block a user