godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.68k stars 20.11k forks source link

Node icons in the 3D views have a crusty outline #82579

Open mieldepoche opened 11 months ago

mieldepoche commented 11 months ago

Godot version

v4.2.dev.custom_build [e948ce405], but previous versions too

System information

linux

Issue description

there's a like 1px outline around the icons that flickers a bit when translated relative to the camera.

https://github.com/godotengine/godot/assets/71937306/7d28b455-0415-4c6e-9dbe-40f59f65677a

https://github.com/godotengine/godot/assets/71937306/41721833-cc89-453a-ab27-f114b104bb31

Steps to reproduce

add a camera or a decal or an audiostreamplayer3d to a scene and move the camera

Minimal reproduction project

any

capnm commented 11 months ago

CC @MewPurPur 383c0116d7552e294fe716dee370896c3304d619 - 3D troubles with the stroke-opacity on the background path?

GizmoCamera3D

Calinou commented 11 months ago

This may be due to a ThorVG rasterization artifact. I'd suggest using the ThorVG reference rasterizer and outputting a 128×128 PNG to make sure (or use an editor plugin to save the editor icon as a PNG).

Perhaps using premultiplied alpha to draw 3D editor gizmo icons will hide the issue without having to modify how the images themselves are generated.

capnm commented 11 months ago

EDIT: I read it too fast as unpremultiplied alpha :)

Godot gets the correct unpremultiplied alpha raster image process/fix_alpha_border doesn't change anything, IMO it looks like a 3D alpha blending issue...

image

5x image

Calinou commented 11 months ago

I've tried to use premultiplied alpha using https://github.com/godotengine/godot/pull/68548, but it breaks icon rendering:

image

https://github.com/godotengine/godot/blob/0ca8542329888e8dccba89d59d3b728090c29991/editor/plugins/node_3d_editor_gizmos.cpp#L929

I guess ThorVG needs to be told to generate textures for premultiplied alpha (and we need to add an option for it).

capnm commented 11 months ago
$ git grep premultiply_al
core/io/image.cpp:3458: ClassDB::bind_method(D_METHOD("premultiply_alpha"), &Image::premultiply_alpha);
core/io/image.cpp:3726:void Image::premultiply_alpha() {
core/io/image.h:380:    void premultiply_alpha();

image

https://thorvg.github.io/thorvg.viewer/

image

++ Maybe you could scale the foreground path 1-3 pixels larger to avoid the black pixels when rendering small icons (floating point inaccuracy issues)

image

image

MewPurPur commented 11 months ago

Oh yeah, I immediately realized what the deal was, I just forgot to have a fill attribute there. I'll go over gizmos to see where else this problem appears.

MewPurPur commented 11 months ago

Correction, I fixed the little black border above, but I actually don't know what the deal with the white outline is. In general I often find white pixels around icons in the editor, so it's probably not fixable by changing the icons themselves :woman_shrugging:

image

capnm commented 11 months ago

I don't know how you trigger that, I don*t see any such issues.

grafik

MewPurPur commented 11 months ago

I get it in Autocomplete.

MewPurPur commented 10 months ago

Can you give an update on whether you see any issues in beta5?

mieldepoche commented 10 months ago

didn't test with beta 5, but still there in master

capnm commented 10 months ago

image

image

interface/editor/code_font_size = 22 x 4

image

MewPurPur commented 9 months ago

So, transparent pixels become white?

Image.fix_alpha_edges() is a possible expensive workaround for projects, but IMO it should be fixed properly for Godot if possible. Otherwise SVG parsing gets way slower.

aXu-AP commented 4 months ago

Is this problem caused by having bilinear filtering on? Since svg icons are rasterized at the native resolution (AFAIK, feel free to correct me), filtering should be turned off wherever the icons are being rendered.

Calinou commented 4 months ago

Is this problem caused by having bilinear filtering on? Since svg icons are rasterized at the native resolution (AFAIK, feel free to correct me), filtering should be turned off wherever the icons are being rendered.

Using bilinear filtering isn't a problem if the texture is drawn at 1:1 scale compared to the viewport resolution.

However, gizmo icons are not always drawng at 1:1 scale – it depends on viewport resolution, whether Half Resolution is enabled, and so on.

Bilinear Nearest
Screenshot_20240425_194503 image

Nearest gets rid of the outlines, but it makes the scaling look ugly due to uneven pixel scaling.

Bilinear filtering with alpha scissor transparency gets rid of the issue as well:

image

However, while this would also resolve transparency sorting issues with gizmos, this prevents gizmos from having translucent areas.

With a tweaked design (no more translucent area, thinner opaque outline), we can get something that looks nicer:

image

However, the outline artifacts are back in this case as long as we keep using bilinear filtering.

aXu-AP commented 4 months ago

Hmm, too bad... Either way as Mew said, the problem should get fixed properly. Somewhat related, I've noticed a similiar problem with partly transparent fills (which the fix alpha border cannot fix): kuva Would it be possible to add bias in bilinear filtering towards opaque pixels? It could solve or at least mitigate the problem? Would of course complicate the shader somewhat, so performance testing would be needed.

Here's modified icon.svg to test the problem above: icon