godotengine / godot

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

Shaders glitching with transparency enabled on MeshInstance3D in both editor and when playing the project. #72901

Open viksl opened 1 year ago

viksl commented 1 year ago

Godot version

4.0 Beta 17 mono

System information

Windows 10, Nvidia GTX 1660Ti, Vulkan

Issue description

The best would be to watch the video, 3d shader glitches with Transparency from Geometry section in the Inspector set to any value but 0. To be precise transparency itself on it's own seems to be working strangely too.

Don't be alarmed about the length of the video, I've put timestamps to the description. The glitches happen over the entire length of the video (more or less), I've tried various angles, flags and so on, some of these make this even worse or more prominent.

This happens both in the editor and when I play the project in its own window. It's very consistent issue which can be spotted all time, move the camera around to see more issues.

Video: https://youtu.be/uQahvvtjYTc

Steps to reproduce

Add a MeshInstance3D to your scene. Assign it a box Mesh. Assign the mesh a new StandardMaterial3D. Set it some Albedo Color, let's say blue or green. Change Transparency in Geometry section in the Inspector and observer changes. Move camera around (especially below the grid) and observe changes. At certain angles the shader also almost disappears and more.

For better result create a couple of MeshInstances3D and move them a little bit so they overlap only partially.

Minimal reproduction project

Currently nothing, it's not particular to just one project or model I have it happens even with Godot meshes.

YuriSizov commented 1 year ago

cc @Chaosus

clayjohn commented 1 year ago

This doesn't look like a bug. This just looks like regular alpha sorting issues. Transparent objects are sorted from back to front so that you can properly see further objects through closer objects. However, when all of your objects are baked into one mesh they can't be sorted. So they just get drawn in the order that they appear in the mesh which results in the issues in your video. This is a limitation of using rasterized graphics and is an inherent limitation in every 3D game engine.

viksl commented 1 year ago

@clayjohn but then why the issues also happen with a native godot box, isn't that just one mesh? I'm not talking about the fact how the render order happens when you can see inside and such.

For example at the timestamp in description labeled as "Issue still happens", why with no transparency the entire model is blue but with even a tiny amount the blue color of the overlay almost disappears? At 05:05 you can see at certain angles the blue overlay again in some parts gets hidden behind the mesh I guess or just disapepars? This also happens with the Godot box.

Thank you, I'm new to this so I just want to clarify it if it's not an issues.