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.36k stars 1.84k forks source link

Android Transparent background rendering always drawn in front of other views #7795

Closed danybony closed 2 months ago

danybony commented 2 months ago

Describe the bug When setting the scene like in the Android transparent rendering sample (without skybox, not opaque) the render is always drawn on top of all other Android views, even if they should be on top according to the hierarchy.

To Reproduce In https://github.com/google/filament/blob/main/android/samples/sample-transparent-view/src/main/java/com/google/android/filament/transparentrendering/MainActivity.kt#L111-L116 invert the two addView() invocations so that the surfaceView is added to the FrameLayout before the TextView.

Expected behavior The text should be displayed in front of the rendered triangle

Screenshots The text is instead always drawn below, like in the original sample Screenshot_20240424_131841

Smartphone (please complete the following information):

romainguy commented 2 months ago

That's not how SurfaceView work. A SurfaceView can't be "sandwiched" between Views as it cuts a hole through the window. The content of the SurfaceView is either above your activity, or below. This can be controlled with the zorder on the SurfaceView. Filament's UI utilities automatically set the zorder to be "on top" for transparent rendering because it's what makes the most sense. If you want your Filament rendering sandwiched between Views, use TextureView instead.