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

Particles flickering #183

Open
ghashy opened this issue Jun 6, 2023 · 3 comments · Fixed by #305
Open

Particles flickering #183

ghashy opened this issue Jun 6, 2023 · 3 comments · Fixed by #305
Labels
A - internal Internal change on a core system C - bug Something isn't working C - enhancement New feature or request D - complex Complex change

Comments

@ghashy
Copy link

ghashy commented Jun 6, 2023

Bevy 0.10.1
bevy_hanabi - last version from git

Hello, first of all I would like to express my gratitude for this amazing crate!
I can't figure out why I have the flickering in my studying project:

Screen.Recording.2023-06-06.at.12.39.24-2.mov

Slow motion:

Screen.Recording.2023-06-06.at.12.37.51.mov

I created particles with this code:

    let mut color_gradient = Gradient::new();
    color_gradient.add_key(0.0, Vec4::new(1., 0.97, 0.36, 0.0));
    color_gradient.add_key(0.03, Vec4::new(1., 0.76, 0.12, 0.5));
    color_gradient.add_key(0.05, Vec4::new(1., 0.40, 0.05, 0.95));
    color_gradient.add_key(0.07, Vec4::new(0.95, 0.24, 0.02, 0.93));
    color_gradient.add_key(0.09, Vec4::new(0.85, 0.12, 0.02, 0.91));
    color_gradient.add_key(0.11, Vec4::new(0.63, 0., 0., 0.9));

    color_gradient.add_key(0.14, Vec4::new(0.12, 0.08, 0.16, 0.8));
    color_gradient.add_key(0.2, Vec4::new(0.06, 0.02, 0.10, 0.7));
    color_gradient.add_key(1.0, Vec4::new(0., 0., 0., 0.));

    let effect = effects.add(
        EffectAsset {
            name: "RocketFlame".to_string(),
            capacity: 1000,
            spawner: Spawner::rate(70.0.into()).with_starts_active(false),
            ..default()
        }
        .init(InitLifetimeModifier {
            lifetime: 3_f32.into(),
        })
        .init(InitPositionCircleModifier {
            radius: 11.,
            ..default()
        })
        .init(InitVelocityCircleModifier {
            axis: Vec3::Z,
            speed: 30.0.into(),
            ..default()
        })
        .init(InitVelocityTangentModifier {
            speed: Value::Uniform((-20., 20.)),
            axis: Vec3::Z,
            ..default()
        })
        .render(ParticleTextureModifier {
            texture: asset_server.load("sprites/Original/Smoke.png"),
        })
        .render(SizeOverLifetimeModifier {
            gradient: Gradient::constant(Vec2::splat(25.0)),
        })
        .render(ColorOverLifetimeModifier {
            gradient: color_gradient,
        }),
    );

And spawned as children of Sprite:

        .with_children(|parent| {
            parent
                .spawn(SpriteBundle {
                    sprite: Sprite {
                        custom_size: Some(Vec2::new(53., 29.) / 1.5),
                        ..default()
                    },
                    transform: Transform::from_xyz(0., -BALL_SIZE / 2., 0.),
                    texture: asset_server
                        .load("sprites/Original/Rocket engine.png")
                        .into(),

                    ..default()
                })
                .with_children(|parent| {
                    parent.spawn((
                        RocketEngine,
                        ParticleEffectBundle {
                            effect: ParticleEffect::new(effect)
                                .with_z_layer_2d(Some(1.)),
                            ..default()
                        },
                        Name::new("RocketEngineParticles"),
                    ));
                });
        });

I'm not sure, but I guess that the particles are drawing in different order on every frame, and maybe this causes flickering

@djeedai
Copy link
Owner

djeedai commented Jun 6, 2023

Yes, there's no particle sorting. It's unfortunately both a critical feature and something hard to implement.

@ghashy
Copy link
Author

ghashy commented Jun 6, 2023

Thanks for reply, I understood, so I I'll try to workaround this with lower transparency for now)

@djeedai
Copy link
Owner

djeedai commented Jun 6, 2023

Yes this is definitely your best bet. Sorry about that.

@djeedai djeedai added C - bug Something isn't working C - enhancement New feature or request A - internal Internal change on a core system D - complex Complex change labels Jun 6, 2023
djeedai added a commit that referenced this issue Mar 19, 2024
When rendering particles in alpha mask mode, there's no transparency
involved; each fragment is either fully opaque or fully transparent.
Therefore we can use the depth buffer, and don't need some fancy order
independent transparency rendering or distance based sorting (which are
not implemented).

This change enables depth writing when rendering particles through the
`AlphaMask3d` render pass. This prevents particles from flickering, as
visible in the `billboard.rs` example.

Partially fixes #183 (for non-transparent effects)
djeedai added a commit that referenced this issue Mar 19, 2024
When rendering particles in alpha mask mode, there's no transparency
involved; each fragment is either fully opaque or fully transparent.
Therefore we can use the depth buffer, and don't need some fancy order
independent transparency rendering or distance based sorting (which are
not implemented).

This change enables depth writing when rendering particles through the
`AlphaMask3d` render pass. This prevents particles from flickering, as
visible in the `billboard.rs` example.

Partially fixes #183 (for non-transparent effects)
djeedai added a commit that referenced this issue Mar 19, 2024
When rendering particles in alpha mask mode, there's no transparency
involved; each fragment is either fully opaque or fully transparent.
Therefore we can use the depth buffer, and don't need some fancy order
independent transparency rendering or distance based sorting (which are
not implemented).

This change enables depth writing when rendering particles through the
`AlphaMask3d` render pass. This prevents particles from flickering, as
visible in the `billboard.rs` example.

Partially fixes #183 (for non-transparent effects)
@djeedai djeedai reopened this Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A - internal Internal change on a core system C - bug Something isn't working C - enhancement New feature or request D - complex Complex change
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants