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

Rendering issue at the boundary of the clear color #2374

Open
allsey87 opened this issue Jun 22, 2021 · 17 comments
Open

Rendering issue at the boundary of the clear color #2374

allsey87 opened this issue Jun 22, 2021 · 17 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@allsey87
Copy link
Contributor

Bevy version

0.5.0

Operating system & version

Arch Linux (5.12.9-arch1-1) running on a Toshiba laptop with Intel UHD Graphics 620 graphics.

What you did

Created a simple scene with a couple of meshes representing a floor and two boxes, although the problem was also recreated by just running the examples from bevy-inspector-egui.

What you expected to happen

The shadows from the egui widgets should blend nicely with the clear color set by AppBuilder's insert_resource(ClearColor(...)). Similarly, I suspect the meshes in my scene should not have this fine white outline where they transition from the mesh to the clear color.

What actually happened

The shadows from the egui widgets and the outline of the meshes interact strangely with the clear color. When changing the clear color dynamically using the widgets in the bevy-inspector-egui world example, it appears that the pixels in question are picking up the clear color but at a brightness several times higher than it should be.

Additional information

This problem is present either the X11 or Wayland features enabled on the Bevy crate (see below) and is present with/without egui/egui_bevy included in the project.

Screenshot from Wayland
wayland

Screenshot from X11
x11

@allsey87 allsey87 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jun 22, 2021
@CptPotato
Copy link
Contributor

CptPotato commented Jun 22, 2021

I have the hunch that this is because of transparency ending up in the swap chain image.
Even if the background is opaque, drawing something transparent on top of it will result in the render target becoming transparent (with default alpha blending ops).

Using a separate OP for blending the alpha channel might fix it if this is really the case.

@allsey87
Copy link
Contributor Author

@CptPotato it's a bit out of my league to come up with a solution to this problem, but I can definitely run some tests if you have an idea as to where the problem lies.

@mockersf
Copy link
Member

@allsey87 would you happen to have the code to reproduce this somewhere available?

@allsey87
Copy link
Contributor Author

@mockersf for the white outline between the meshes and clear color, I can see it when I pull the main branch and run the 3d_scene example with cargo run --example 3d_scene:
image

Tomorrow, I will add an egui window on top of this and post the code and screenshots for it.

@allsey87
Copy link
Contributor Author

By the way, I get this warning when I run Bevy examples and apps:

MESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0

Probably nothing, but I am making a note of it since it is related to graphics.

@lukors
Copy link
Contributor

lukors commented Jun 22, 2021

@allsey87 I believe that latest note is more of a configuration thing for your computer. At least for me, I got that same message for many applications.

Luckily I recorded what I did to do the configuration the message suggests:

  1. sudo -i
  2. echo dev.i915.perf_stream_paranoid=0 > /etc/sysctl.d/60-mdapi.conf
  3. Rebooted computer
  4. Verified the value with sysctl -n dev.i915.perf_stream_paranoid

Source: https://ubuntuforums.org/showthread.php?t=2457426

@bjorn3
Copy link
Contributor

bjorn3 commented Jun 22, 2021

You don't have to do this if you don't actually want to measure the performance of rendering beyond fps or don't want to measure it at all.

@mockersf
Copy link
Member

@mockersf for the white outline between the meshes and clear color, I can see it when I pull the main branch and run the 3d_scene example with cargo run --example 3d_scene:

Oh, definitely not what I'm seeing, even your clear color seems wrong, it should be #666666:
Screenshot 2021-06-22 at 23 02 32

@mockersf
Copy link
Member

It was mentioned on discord that this may be a case of #419. Could you check by playing with the msaa parameter?

@allsey87
Copy link
Contributor Author

allsey87 commented Jun 23, 2021

@mockersf you are correct. Setting Msaa { samples: 1 } solves the problem. When switching to Msaa { samples: 2 } or back to Msaa { samples: 4 }, the problem shows up again. So it seems to me that the clear color is not correct when MSAA samples is greater than one and that this edge (or in the case of the egui widgets, that incorrect shadow) that I am seeing is actually what the clear color should be.

image

Issue gfx-rs/wgpu#725 reports this problem, specifically calling out Linux and Intel graphics chips.

@DJMcNab
Copy link
Member

DJMcNab commented Jun 23, 2021

Is this therefore a duplicate of #419?

Maybe we should add a comment on Msaa mentioning that it causes issues on certain configurations, pointing to #419.

@DJMcNab DJMcNab added S-Duplicate This issue or PR already exists A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled S-Duplicate This issue or PR already exists labels Jun 23, 2021
@ppearson
Copy link

I'm also seeing the same issue with Bevy 0.7 on Linux Mint 20.3 on a Thinkpad with an Intel UHD Graphics 620 with the vulkan x11 backend, the drivers I'm using are the Mesa Intel ones.
Setting MSAA to 1 also avoids the issue, but I'd like to have that on if possible.

image

glxinfo shows this for my drivers:
client glx vendor string: Mesa Project and SGI
Device: Mesa Intel(R) UHD Graphics 620 (KBL GT2) (0x5917)
OpenGL renderer string: Mesa Intel(R) UHD Graphics 620 (KBL GT2)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 21.2.6
OpenGL version string: 4.6 (Compatibility Profile) Mesa 21.2.6
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 21.2.6

@Munksgaard
Copy link

As mentioned in #7126, I get a similar issue running the 2d_shapes example from the repo:

@Munksgaard
Copy link

Setting MSAA to 1 in the example seems to fix the problem. Curiously though, it also changes the color of the background?

screenshot

@Munksgaard
Copy link

That's weird. I just tried an even simpler example, setting MSAA to 1 instead of 4 changes the color of the default background. Surely, that's not intended? Should I report a second bug?

use bevy::{prelude::*, sprite::MaterialMesh2dBundle};

fn main() {
    App::new()
        .insert_resource(Msaa { samples: 1 })  // removing this line changes the background color
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    commands.spawn(Camera2dBundle::default());
}

@FHomps
Copy link

FHomps commented Oct 24, 2023

Hi,

I can confirm I'm having the same issue on a Linux laptop with UHD620 graphics. Bevy 0.11.3 and X11 on a fresh debian 12 install.
I am rendering lines with a custom shader and alpha gradient from 1.0 to 0, and my case ends up particularly egregious.

With MSAA on :
image

With MSAA off :
image

The background / clear color only seems to be rendered correctly when a fragment with an alpha of some kind sits atop of it or is in the vicinity (~4 pixels away max).

@andriyDev
Copy link
Contributor

andriyDev commented Jun 5, 2024

I am also being affected by this issue in Bevy 0.13.2 on Linux, Wayland. My adapter is "Intel HD Graphics 520 (SKL GT2)". Just the same as everyone here, with MSAA on (the default) the clear color is darker (pretty much black), and blending with the clear color adds a weird outline. Blending sprites together doesn't seem to produce this effect (layering transparent sprites on top of each other) though this might just be because the transparency is so weak. It almost looks like the blended part is the correct color, and the only problem is the cleared area is the wrong color.

Thankfully turning MSAA off fixes it like others, and practically most completed games will avoid the clear color entirely, so this is likely just a dev issue.

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
Projects
None yet
Development

No branches or pull requests

10 participants