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

Fix: Motion blur should sample onscreen fragments with no depth #13573

Merged
Merged
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
11 changes: 10 additions & 1 deletion crates/bevy_core_pipeline/src/motion_blur/motion_blur.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ fn fragment(
// The current sample step vector, from in.uv
let step_vector = 0.5 * exposure_vector * (f32(i) + noise) / f32(n_samples);
var sample_uv = in.uv + step_vector;

// If the sample is off screen, skip it.
if sample_uv.x < 0.0 || sample_uv.x > 1.0 || sample_uv.y < 0.0 || sample_uv.y > 1.0 {
continue;
}

let sample_coords = vec2<i32>(sample_uv * texture_size);

#ifdef MULTISAMPLED
Expand All @@ -103,7 +109,10 @@ fn fragment(

var weight = 1.0;
let is_sample_in_fg = !(depth_supported && sample_depth < this_depth && sample_depth > 0.0);
if is_sample_in_fg {
// If the depth is 0.0, this fragment has no depth written to it and we assume it is in the
// background. This ensures that things like skyboxes, which do not write to depth, are
// correctly sampled in motion blur.
if sample_depth != 0.0 && is_sample_in_fg {
// The following weight calculation is used to eliminate ghosting artifacts that are
// common in motion-vector-based motion blur implementations. While some resources
// recommend using depth, I've found that sampling the velocity results in significantly
Expand Down