Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite reprojection for FSR2 to work correctly with Reverse-Z. #91799

Merged
merged 1 commit into from
May 11, 2024
Merged
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
4 changes: 3 additions & 1 deletion servers/rendering/renderer_rd/effects/debug_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ void DebugEffects::draw_motion_vectors(RID p_velocity, RID p_depth, RID p_dest_f
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_fb, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD);
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, motion_vectors.pipeline.get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_fb), false, RD::get_singleton()->draw_list_get_current_pass()));

Projection reprojection = p_previous_projection.flipped_y() * p_previous_transform.affine_inverse() * p_current_transform * p_current_projection.flipped_y().inverse();
Projection correction;
correction.set_depth_correction(true, true, false);
Projection reprojection = (correction * p_previous_projection) * p_previous_transform.affine_inverse() * p_current_transform * (correction * p_current_projection).inverse();
RendererRD::MaterialStorage::store_camera(reprojection, motion_vectors.push_constant.reprojection_matrix);

motion_vectors.push_constant.resolution[0] = p_resolution.width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2289,11 +2289,14 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
params.delta_time = float(time_step);
params.reset_accumulation = false; // FIXME: The engine does not provide a way to reset the accumulation.

Projection correction;
correction.set_depth_correction(true, true, false);

const Projection &prev_proj = p_render_data->scene_data->prev_cam_projection;
const Projection &cur_proj = p_render_data->scene_data->cam_projection;
const Transform3D &prev_transform = p_render_data->scene_data->prev_cam_transform;
const Transform3D &cur_transform = p_render_data->scene_data->cam_transform;
params.reprojection = prev_proj.flipped_y() * prev_transform.affine_inverse() * cur_transform * cur_proj.flipped_y().inverse();
params.reprojection = (correction * prev_proj) * prev_transform.affine_inverse() * cur_transform * (correction * cur_proj).inverse();

fsr2_effect->upscale(params);
}
Expand Down
Loading