Skip to content

Add opt-out background motion vectors#23187

Open
aevyrie wants to merge 6 commits intobevyengine:mainfrom
aevyrie:atmosphere-motion-vectors
Open

Add opt-out background motion vectors#23187
aevyrie wants to merge 6 commits intobevyengine:mainfrom
aevyrie:atmosphere-motion-vectors

Conversation

@aevyrie
Copy link
Member

@aevyrie aevyrie commented Mar 2, 2026

Objective

  • Fix broken motion vectors when using atmosphere without a skybox

Note the sun does not make a trail, and mesh edges do not blend with background

image

Solution

  • Solve this class of issue by making cameras write out their motion to any "background" fragments that have not yet been written to.
  • Remove the skybox-specific implementation in favor of the general purpose implementation.

Testing

  • bevy_city with motion blur enabled
image

This is an exaggerated stress test to show the blur across edges is smooth:

image

@greeble-dev greeble-dev added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 2, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering Mar 2, 2026
@alice-i-cecile alice-i-cecile requested review from ecoskey and mate-h March 2, 2026 17:56
@alice-i-cecile alice-i-cecile added D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes X-Uncontroversial This work is generally agreed upon labels Mar 2, 2026
@alice-i-cecile alice-i-cecile added this to the 0.19 milestone Mar 3, 2026
@aevyrie aevyrie changed the title Add motion vectors to Atmosphere Add opt-out background motion vectors Mar 4, 2026
Copy link
Contributor

@mate-h mate-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix thanks for getting this done! I don't have any blocking comments but leaving some feedback

@group(0) @binding(0) var<uniform> view: View;
@group(0) @binding(1) var<uniform> previous_view: PreviousViewUniforms;

/// Writes motion vectors for sky pixels (depth == 0 in reversed-Z) based on camera rotation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency in the terminology say "Writes motion vectors for background pixels" and "cleared depth at background pixels"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat related to this PR, but not in-scope.

Following up from the discussion on discord , we should really consider renaming SkyBox to something else like:
SceneBackground or BackgroundCubemap to distinguish it from the Atmosphere and remove any implication that this can only be a Sky. Seems to be a common point of confusion. SkyBox represents a visual background layer, not a sky model and not an environment lighting source. The current name conflates concepts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could shorten the file name to just motion_vectors.rs, I think it's a better option for the file name itself. (don't feel too strongly about this) everything else in the file using a background terms should stay the same.


impl Plugin for BackgroundMotionVectorsPlugin {
fn build(&self, app: &mut App) {
embedded_asset!(app, "background_motion_vectors.wgsl");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this feels cleaner to not include the background_ prefix for the file name

let world_pos = view.world_from_clip * vec4(clip_pos, 0.0, 1.0);
// Use unjittered_clip_from_world for the current frame to strip TAA jitter from the
// motion vector.
let curr_clip_pos = (view.unjittered_clip_from_world * world_pos).xy;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part I don't fully understand, TAA jitters the clip_from_world by default? what does stripping the TAA jitter do, and why wasn't it there before? is this a bugfix for TAA + motion blur?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was seeing issues when TAA was enabled - this code is what the mesh motion vectors do as well iirc, so the camera jitter doesn't add noise to the motion vectors.

@ecoskey ecoskey added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

5 participants