bevyengine / bevyengine/bevy

Fxaa causes post processing effects to flicker rapidly

Open
#25,539 0 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug D-Modest S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version and features

0.19.1 (git bisect shows flickering in f1f41547fcad10e7e0b789ecca95f6d60fd86a6a onwards)

## Relevant system information

SystemInfo { os: "Windows 11 Pro", kernel: "26200", cpu: "AMD Ryzen 9 3950X 16-Core Processor", core_count: "16", memory: "31.9 GiB" }
AdapterInfo { name: "AMD Radeon (TM) RX 480", vendor: 4098, device: 26591, device_type: DiscreteGpu, device_pci_bus_id: "", driver: "AMD proprietary driver", driver_info: "24.9.1 (AMD proprietary shader compiler)", backend: Vulkan, subgroup_min_size: 64, subgroup_max_size: 64, transient_saves_memory: Some(false), limit_bucket: None }

## What you did

Tried to create a post processing material in a project using fxaa.

The code is too long to share, but the same effect can be triggered in the examples.

Modify the fullscreen_material or custom_post_processing examples to disable msaa, and enable fxaa

fullscreen_material diff

```diff
diff --git a/examples/shader_advanced/fullscreen_material.rs b/examples/shader_advanced/fullscreen_material.rs
index 4e8f24c77..619d99645 100644
--- a/examples/shader_advanced/fullscreen_material.rs
+++ b/examples/shader_advanced/fullscreen_material.rs
@@ -1,6 +1,7 @@
//! Demonstrates how to write a custom fullscreen shader.

use bevy::{
+ anti_alias::fxaa::Fxaa,
core_pipeline::fullscreen_material::{FullscreenMaterial, FullscreenMaterialPlugin},
prelude::*,
render::{extract_component::ExtractComponent, render_resource::ShaderType},
@@ -26,6 +27,8 @@ fn setup(
Camera3d::default(),
Transform::from_translation(Vec3::new(0.0, 0.0, 5.0)).looking_at(Vec3::default(), Vec3::Y),
FullscreenEffect { intensity: 0.005 },
+ Fxaa::default(),
+ Msaa::Off,
));

commands.spawn((
```

custom_post_processing diff

```diff
diff --git a/examples/shader_advanced/custom_post_processing.rs b/examples/shader_advanced/custom_post_processing.rs
index 7ca96d09d..376b4af3a 100644
--- a/examples/shader_advanced/custom_post_processing.rs
+++ b/examples/shader_advanced/custom_post_processing.rs
@@ -7,6 +7,7 @@
//! This is a fairly low level example and assumes some familiarity with rendering concepts and wgpu.

use bevy::{
+ anti_alias::fxaa::Fxaa,
core_pipeline::{schedule::Core3d, Core3dSystems, FullscreenShader},
prelude::*,
render::{
@@ -249,10 +250,8 @@ fn setup(
commands.spawn((
Camera3d::default(),
Transform::from_translation(Vec3::new(0.0, 0.0, 5.0)).looking_at(Vec3::default(), Vec3::Y),
- Camera {
- clear_color: Color::WHITE.into(),
- ..default()
- },
+ Fxaa::default(),
+ Msaa::Off,
// Add the setting to the camera.
// This component is also used to determine on which camera to run the post processing effect.
PostProcessSettings {
```

## What went wrong
- what were you expecting?
The examples should work largely as normal, but using fxaa
- what actually happened?
The examples flicker rapidly

Video. Warning: Rapid flickering

https://github.com/user-attachments/assets/6cfc8431-d5f5-40dd-8849-787ba63da15a

Note that commenting out the `PostProcessSettings`/`FullscreenEffect` from the respective bundles also avoids the flicker (but obviously disables the effect), so it seems to be some interaction between fxaa, and post processing effects.

## Additional information

- workarounds:
- Only the vulkan backend seems to be affected, using WGPU_BACKEND="dx12" removes the flicker
- Msaa is unaffected by the flicker
- Cameras with a clear color of `Color::WHITE` are unaffected by the flicker for some reason (but 255,255,254 for example is affected)

Contributor guide

Open the contributing guide

Research direction

Start by running the fullscreen_material or custom_post_processing example with Fxaa enabled and Msaa::Off on the reported Vulkan setup. Compare the behavior around commit f1f41547fcad10e7e0b789ecca95f6d60fd86a6a and inspect the post-processing and FXAA paths used by those examples. Done means the post-processing effect no longer flickers rapidly on Vulkan while FXAA remains enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.