Text2dShadow sometimes renders in front of its text

Aperta
#26,706 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
game-dev

Direzione di ricerca

Start by reproducing the provided example in the Bevy 2D text rendering pipeline, focusing on Text2dShadow, AlphaMode2d, and the RenderSystems::Queue ordering described in the workaround. Locate where shadow and text draw commands are queued and compare their ordering when an unrelated mesh changes visibility. Done means the reproduction consistently renders the shadow behind the text across the affected platform or build configurations without relying on the workaround.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

C-Bug S-Needs-Triage

Bevy version and features

  • Bevy 0.20.1
  • Bevy 5c485c424 (latest main)

Default features

What you did

Repeatedly include/exclude another (unrelated) mesh from rendering. Visibility::Hidden works, but for some reason moving it out of view produces more noticeable effects.

use bevy::{prelude::*, sprite::Text2dShadow, sprite_render::AlphaMode2d};

fn main() {
    App::new()
        .insert_resource(ClearColor(Color::WHITE))
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, startup)
        .add_systems(Update, update)
        .run();
}

fn startup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    commands.spawn(Camera2d);

    commands.spawn((
        Text2d::new("Red text with blue shadow"),
        TextColor(Color::srgba(1.0, 0.0, 0.0, 1.0)),
        TextFont::from_font_size(64.0),
        Text2dShadow {
            color: Color::srgba(0.0, 0.0, 1.0, 1.0),
            offset: Vec2::ZERO,
        },
    ));

    commands.spawn((
        Mesh2d(meshes.add(Rectangle::new(64.0, 64.0))),
        MeshMaterial2d(materials.add(ColorMaterial {
            color: Color::srgba(0.9, 0.9, 0.9, 1.0),
            alpha_mode: AlphaMode2d::Blend, // this matters
            ..Default::default()
        })),
        Transform::from_xyz(0.0, 96.0, 0.0),
    ));
}

fn update(time: Res<Time>, mut mesh_transform: Single<&mut Transform, With<Mesh2d>>) {
    **mesh_transform = if (time.elapsed().as_millis() / 250) % 2 == 0 {
        // Move the rectangle out of frame.
        // `Visibility::Hidden` also works but seems to only flicker briefly.
        Transform::from_xyz(0.0, 99999.0, 0.0)
    } else {
        Transform::from_xyz(0.0, 96.0, 0.0)
    };
}

This seems to be systems-ordering dependent, so it may not always be easy to reproduce. If the above works as expected, perhaps try a web build.

What went wrong

The blue text shadow sometimes renders in front of the red text, meaning its drawn later.

Additional information

image (still image, in reality text alternates between red and blue)

Workaround:

impl Plugin for RenderingPlugin {
    fn build(&self, app: &mut App) {
        if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
            render_app.add_systems(
                Render,
                (|| {})
                    .in_set(RenderSystems::Queue)
                    .after(queue_material2d_meshes)
                    .before(queue_sprites),
            );
        }
    }
}
Lingua principale
Rust
Stelle
50k
Fork
5.1k
Merge medio
2g 20h
PR unite (30g)
129

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bevyengine/bevy

Tutte le issue di bevyengine/bevy

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.