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

TRANSLUCENT display incorrect.(use method in sample-transparent-view) #4087

Closed
dsafa22 opened this issue Jun 5, 2021 · 18 comments
Closed

TRANSLUCENT display incorrect.(use method in sample-transparent-view) #4087

dsafa22 opened this issue Jun 5, 2021 · 18 comments

Comments

@dsafa22
Copy link

dsafa22 commented Jun 5, 2021

#4084
use android sample:sample-gltf-viewer
In ModelViewer.kt, use the method in sample-transparent-view,the code changed as blow(no other code change)
inSurfaceCallback :

swapChain = engine.createSwapChain(surface, SwapChain.CONFIG_TRANSPARENT)

In MainActivity.kt:
do not use sky box

//        readCompressedAsset("envs/$ibl/${ibl}_skybox.ktx").let {
//            scene.skybox = KtxLoader.createSkybox(engine, it)
//        }

and I set the view background #0f0 in layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/simple_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#f00">
....

It show as blow
82A3A8D45C5BDD87B8CE060A81BDA658

not right.

@romainguy
Copy link
Collaborator

What's not right? The background is set to red and visible through the 3D view. What issue are you reporting?

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

What's not right? The background is set to red and visible through the 3D view. What issue are you reporting?

The face is missing some part.

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

截屏2021-06-05 13 45 14

18CB8970-6118-4670-9710-1CA8EAF3A9B8

@pixelflinger
Copy link
Collaborator

Is the face okay when you're NOT setting the view to transparent?

@romainguy
Copy link
Collaborator

Could you share the glTF file you are loading please?

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

debug in metal.

after colorGrading, the texture begin not right.
2D4FCBB6-961C-4BAA-80EA-038DDE02C8A4
B469F754-FC90-4404-81A0-6A4CAEEDE21E

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

Could you share the glTF file you are loading please?

it is here.
#4084

https://github.com/google/filament/files/6596877/role_boy.glb.zip

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

the missing part same as the face node exceed the hair node.
F458687C-C029-490A-A6E7-6EB18BC8E248
91FD3A42-DCD2-4AEE-9D2A-170EC4F4C2D2

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

Is the face okay when you're NOT setting the view to transparent?

Yes, it is OK when not set transparent.

BTW.
If the scene has skybox, whatever the view is transparent or not transparent, it is OK too.

@romainguy
Copy link
Collaborator

How did you modify gltf_viewer? When I remove the skybox and set the swap chain to transparent, everything renders properly:

Screen Shot 2021-06-04 at 11 04 44 PM

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

How did you modify gltf_viewer? When I remove the skybox and set the swap chain to transparent, everything renders properly:

Screen Shot 2021-06-04 at 11 04 44 PM

F837CAE8-AFB6-4FBA-AEE2-9FD35A7F2BE2

dest->setBlendMode(View::BlendMode::TRANSLUCENT);

@romainguy
Copy link
Collaborator

Ah I was able to repro. There's no need to set the swap chain to use CONFIG_FLAG_TRANSPARENT. What triggers the bug is setting the View's blend mode to TRANSLUCENT:

view->setBlendMode(View::BlendMode::TRANSLUCENT);

@romainguy
Copy link
Collaborator

@pixelflinger I forgot, is the app supposed to set the ClearOptions in this case? It looks like we're not properly clearing the depth buffer (or depth test is still incorrectly enabled).

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

Ah I was able to repro. There's no need to set the swap chain to use CONFIG_FLAG_TRANSPARENT. What triggers the bug is setting the View's blend mode to TRANSLUCENT:

view->setBlendMode(View::BlendMode::TRANSLUCENT);

yes, very smart!

@romainguy
Copy link
Collaborator

@pixelflinger I found the bug. It's caused by this line in the post processing material:

color.rgb /= color.a + FLT_EPS;

I'm not sure why it causes the problem yet. But it's fine when returning just before and it's broken when returning right after. I imagine we have bad values in color.a.

@romainguy
Copy link
Collaborator

Alright I found the issue. The problem is the asset. The face uses alpha masking with an alpha value that comes from the face texture. And the alpha channel of said texture looks like this:

Screen Shot 2021-06-04 at 11 51 09 PM

So what's happening is that in "view transparent" mode the alpha of the alpha masking is used to blend and we correctly interpret it and the model disappears. The bug doesn't appear in opaque mode because we disable blending so all pixels are treated as alpha=1.

Please disable alpha masking on the face, it'll fix your issue and improve rendering performance.

@dsafa22
Copy link
Author

dsafa22 commented Jun 5, 2021

Alright I found the issue. The problem is the asset. The face uses alpha masking with an alpha value that comes from the face texture. And the alpha channel of said texture looks like this:

Screen Shot 2021-06-04 at 11 51 09 PM

So what's happening is that in "view transparent" mode the alpha of the alpha masking is used to blend and we correctly interpret it and the model disappears. The bug doesn't appear in opaque mode because we disable blending so all pixels are treated as alpha=1.

Please disable alpha masking on the face, it'll fix your issue and improve rendering performance.

Yes, I also suspect that this model has a problem, because other models don't have this problem. I'll try to modify it. Thank you.

@ShoutTree
Copy link

Hi, @romainguy, I also met this issue in version 1.15.0. Does that mean the issue is still not fixed? From your comments above I thought it was a model issue at first, but since the model is correctly rendered in other renderer(https://gltf-viewer.donmccurdy.com/), I concluded that it's still a filament blending issue. Seems filament does not correctly use the alpha masking. Am I right ?
Thanks.

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

No branches or pull requests

4 participants