google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.75k stars 1.88k forks source link

Complex transparent glasses render incorrectly #2744

Closed vcxyk closed 4 years ago

vcxyk commented 4 years ago

hi, I have a 'glb' glasses model exported from substance painter, which is combined with several parts of transparent submeshes. It seems the mesh sorting algorithm cannot perfectly rendering such glb models. How can I avoid all these rendering errors in Filament 1.7.0, or is there any suggestion for making such models to reduce those rendering errors? image image

Same .obj file rendered by Mac file preview: image

romainguy commented 4 years ago

Could you share the model with us please? A solution would be enable the twoPassesOneSide rendering mode. See https://google.github.io/filament/Materials.md.html#materialdefinitions/materialblock/blendingandtransparency:transparency There's a screenshot showing exactly the problem you are running into.

@prideout I wonder if we should add an option in gltfio to be able to turn on that mode. We didn't turn it on by default because it's not what some models want. Wdyt?

Alternatively make sure the winding of all your faces is correct. What you are seeing could also be z-fighting, making sure that your triangles are not too close to each other would help.

vcxyk commented 4 years ago

Could you share the model with us please? A solution would be enable the twoPassesOneSide rendering mode. See https://google.github.io/filament/Materials.md.html#materialdefinitions/materialblock/blendingandtransparency:transparency There's a screenshot showing exactly the problem you are running into.

@prideout I wonder if we should add an option in gltfio to be able to turn on that mode. We didn't turn it on by default because it's not what some models want. Wdyt?

Alternatively make sure the winding of all your faces is correct. What you are seeing could also be z-fighting, making sure that your triangles are not too close to each other would help.

hi, Thanks for you reply. Here's the model. test_glasses.glb.zip

  1. The seam on the glasses seems z-fighting because it is gone when the viewpoint changes.
  2. The glasses's leg behind the transparent glasses only shows the 'opaque steel' part and the 'transparent skin' part is not rendered.
vcxyk commented 4 years ago

append: I tried modified the MaterialGenerator's default "blend" behavior to twoPassesDoubleSides, and the problem is gone. image

(ps: The default blending value is "fade" and I don't know why it's not "transparent", which is more fit for the glass specular. And It also confuses me that the depth-writing is set to 'true' explicitly for blending mode. False seems ok for my tests.).

(pps: TwoPassesOneSide solve Problem.1 above but the Problem.2 still exists.)

romainguy commented 4 years ago

The problem is that gltf doesn't define how blending should work. Some models expect fade, other expect transparent. I'm surprised we picked fade though. @prideout do you remember?

Setting depth writing to true for transpent objects helps with some models.

romainguy commented 4 years ago

What is the transparent skin you're talking about?

romainguy commented 4 years ago

Apparently we use fade to match other viewers, see bug https://github.com/google/filament/issues/1461

vcxyk commented 4 years ago

What is the transparent skin you're talking about?

image Look at the legs behind the glass piece. It has a "transparent" plastic part and a 'opaque' steel inside. But through the glass we can only see the steel, and the plastic is not rendered. (Is it depth-culled by the glasses in front during the transparent rendering pass?)

romainguy commented 4 years ago

For that not to happen you need to make sure the sides of the frame (the "legs”) are separate objects.

romainguy commented 4 years ago

I finally tested your model. Some info:

Screen Shot 2020-06-29 at 2 25 32 PM

Anyway I don't think there's anything actionable on our side aside from maybe offering a TRANSPARENT mode for glTF instead of always using FADE.

prideout commented 4 years ago

Note that we switched from TRANSPARENT to FADE to "fix" issue #1461.

I would rather not make this configurable since it would double the number of ubershader permutations. It's impossible to make everybody happy when transparency in involved. :)

romainguy commented 4 years ago

I know but fade is very very wrong for glass :)