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

Transparent object with no culling creates visual artifacts #97895

Closed
Ewall198 opened this issue Oct 6, 2024 · 7 comments
Closed

Transparent object with no culling creates visual artifacts #97895

Ewall198 opened this issue Oct 6, 2024 · 7 comments

Comments

@Ewall198
Copy link

Ewall198 commented Oct 6, 2024

Tested versions

  • Reproducible in: 4.1.4.stable, 4.2.2.stable.mono, 4.3.stable, 4.4.dev3

System information

Windows 10 - Godot v 4.3.stable - Compatibility - NVIDIA GeForce RTX 3060, Driver version: 31.0.15.3734

Issue description

Description
An smooth-shaded icosphere with transparency enabled, blend mode mix, and culling disabled will create strange visual artifacts.
I expect this to look like a smooth capsule, but instead I see the jagged tris highlighted with weird shading.

Untitled

Steps to reproduce

  1. Create a smooth-shaded icosphere in blender. Export to .glb file
  2. Import the mech into godot and add it to a MeshInstance3D.
  3. Enabled transparency on the mesh and disable culling.

Minimal reproduction project (MRP)

transparencyartifacts.zip

@tetrapod00
Copy link
Contributor

tetrapod00 commented Oct 6, 2024

This is a limitation of how transparency works. Transparent meshes are sorted then drawn by their distance from the camera, but within each mesh, faces are drawn in an arbitrary order, not sorted. So you can't guarantee that the faces on the far side of the mesh will be drawn before the faces on the close side of the mesh. I believe it's based on the order of the vertices/faces in the mesh's arrays, but I haven't looked at the actual implementation.

You can reproduce this entirely within Godot, too, with a standard sphere mesh:

Godot_v4.3-stable_win64_XFQnAsfNYb.mp4

(Also, your MRP did not actually have Transparency = Alpha, Cull Mode = Disabled set.)

@Ewall198
Copy link
Author

Ewall198 commented Oct 6, 2024

@tetrapod00 Thanks for the response. I updated the MRP.
Any ideas on how best to work around this? I could make two instances of the same mesh with one having back face culled and the other front face culled, but this seems clunky.

@tetrapod00
Copy link
Contributor

The best workaround depends on why you need culling disabled. Two meshes, one with frontface and one with backface culling doesn't sound that unreasonable. I think in some cases you can also use a custom shader with render_mode cull_disabled and use the FRONT_FACING shader built-in to selectively render depending on whether you're rendering front or back faces. Depending on your use case, you might also be able to use Alpha Hash or Alpha Scissor for your transparency, which emulates transparency by selectively rendering opaque pixels and should give you correct sorting of the faces within each mesh.

Github issues aren't the right place for support questions, so I'd recommend one of the community channels if you're looking for in-depth help with this problem.

@Ewall198
Copy link
Author

Ewall198 commented Oct 6, 2024

@tetrapod00 ok thank you

@Ewall198 Ewall198 closed this as completed Oct 6, 2024
@Ewall198
Copy link
Author

Ewall198 commented Oct 11, 2024

@tetrapod00 I'm tempted to reopen this issue. The goal here is to create a semi-transparent capsule. It seems like the only possible solution is to create two meshes; one with cull_front and one with cull_back and ensure the cull_back mesh is always slightly closer to the camera by moving the MeshInstance3D Node. I'm surprised there isn't a better solution to this.

See a similar unanswered forum question from February and a lengthy discussion in Godot Cafe

@tetrapod00
Copy link
Contributor

I think as is, this isn't a bug, but a limitation/missing feature. So I'd recommend opening a proposal for a feature addition of some kind.

There are some existing proposals that are aiming to address similar problems. I think godotengine/godot-proposals#4825 is the closest, but see also godotengine/godot-proposals#7916, godotengine/godot-proposals#7870, godotengine/godot-proposals#496.

@Ewall198
Copy link
Author

Actually, I managed to figure it out. I just needed to change the VisualInstance3D.sorting_offset for the front mesh.
🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants