Skip to content

Clean up background motion vectors when prepass is disabled#24606

Open
issam3105 wants to merge 1 commit into
bevyengine:mainfrom
issam3105:Skip_background_motion_vectors_when_motion_vector_target_is_absent
Open

Clean up background motion vectors when prepass is disabled#24606
issam3105 wants to merge 1 commit into
bevyengine:mainfrom
issam3105:Skip_background_motion_vectors_when_motion_vector_target_is_absent

Conversation

@issam3105

@issam3105 issam3105 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Objective

  • Fix a render validation error when TemporalAntiAliasing is removed from a camera while DepthPrepass remains enabled.
  • The background motion vectors pipeline state could remain on the render-world view after MotionVectorPrepass was removed, causing the prepass node to try to render background motion vectors without a motion vector target.

Solution

Add a cleanup system for background motion vector state.

Testing

Press Space to disable TAA while keeping DepthPrepass on the camera. Before this PR, it crash with:

Render pipeline targets are incompatible with render pass
Incompatible color attachments at indices []: the RenderPass uses textures with formats [] but the RenderPipeline with 'background_motion_vectors_pipeline' label uses attachments with formats [None, Some(Rg16Float), None, None]

Minimal repro example:

use bevy::anti_alias::taa::TemporalAntiAliasing;
use bevy::core_pipeline::prepass::{DepthPrepass, MotionVectorPrepass};
use bevy::prelude::*;
use bevy::render::camera::{MipBias, TemporalJitter};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, toggle_taa)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn((
        Camera3d::default(),
        Msaa::Off,
        DepthPrepass,
        TemporalAntiAliasing::default(),
        Transform::from_xyz(0.0, 0.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
    ));
}

fn toggle_taa(
    keys: Res<ButtonInput<KeyCode>>,
    camera: Single<Entity, With<Camera3d>>,
    mut commands: Commands,
) {
    if keys.just_pressed(KeyCode::Space) {
        commands.entity(*camera).remove::<(
            TemporalAntiAliasing,
            TemporalJitter,
            MipBias,
            MotionVectorPrepass,
        )>();
    }
}

@issam3105 issam3105 marked this pull request as ready for review June 12, 2026 15:17
@kfc35 kfc35 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 Jun 12, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Jun 12, 2026
@kfc35 kfc35 added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Jun 12, 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-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

3 participants