google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 606 forks source link

Setting SceneView background as transparent #263

Open itanbp opened 5 years ago

itanbp commented 5 years ago

Hi, I'm trying to set the SceneView's background color to be transparent, however, the documentation states:

the background color of the Scene is set to getColor() (the alpha of the color is ignored)

Is there a way to do so?

The purpose is to create a "semi-ar" feature (for devices that aren't supported by Arcore) by combining the camera's feed, and a SceneView with a transparent background.

Thanks!

dsternfeld7 commented 5 years ago

There is currently no way to do so. It would be possible for us to add this as a feature, however there will be a hit to performance if we do so.

Can you give us more information about what your use case is for? Since a SceneView is a type of Android SurfaceView, by default, nothing in the android view hierarchy will render behind it. You can force a SurfaceView to render on top, but then nothing in the view hierarchy will render above it.

itanbp commented 5 years ago

@dsternfeld7 setting SurfaceView on top looks like a suitable solution. Actually following this how to make surfaceview transparent SO post, I created custom view TransparentSceneView extending SceneView. In the constructor I added

setZOrderOnTop(true);
SurfaceHolder sfhTrackHolder = getHolder();
sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT);

It didn't work (the camera feed was still hidden by the TransparentSceneView), I assume this is the feature you referred?

Currently many users can't use my app as Arcore's supported devices list is still limited, so I believe offering a basic feature that gives a glimpse of the AR fealing, can be a good compromise until arcore will be common on many Android devices.

Brianvdb commented 5 years ago

@itanbp did you find a solution already?

itanbp commented 5 years ago

@Brianvdb I'm waiting for @dsternfeld7's response

JessHolle commented 5 years ago

It is my understanding that this requirement should be solvable via external textures -- as per discussion on https://github.com/google-ar/sceneform-android-sdk/issues/169

That said, I've not actually coded this -- and how-to code in this regard would be greatly appreciated.

The fact that ARCore supports fairly few devices and that there are other AR libraries and other use cases for mixing 3D and a camera background makes this a recurring question/request.

itanbp commented 5 years ago

@JessHolle well said!

JessHolle commented 5 years ago

P.S. https://github.com/google-ar/sceneform-android-sdk/issues/227 seems like another hugely necessary piece to work well with a real camera without ARCore.

romainguy commented 5 years ago

Making the SurfaceView itself transparent is not enough, Sceneform needs to setup the internal renderer to render to a transparent target. But instead of making the 3D scene transparent you should simply display the camera feed in the 3D scene by using an ExternalTexture (it's what ARSceneView does).

gorastudio-ceo commented 5 years ago

We need transparent in Scene. Can you make this feature in priority, please 🙏

tharinimoorthy commented 5 years ago

We need transparent background in Scene. Can you make this feature in priority, please

fzaiatz commented 5 years ago

+1 would be great to allow 100% transparent background for SceneView.

About the ExternalTexture solution: is it possible / any idea the best way to update a texture contents frame by frame from raw data (byte[])?

AbhisKmr commented 4 years ago

I'm also facing the same issue please do something for this

theguyontheleft commented 4 years ago

Would love to be able to have a transparent background for SceneView as well.

brako commented 4 years ago

I would like to have this feature too. I am mirroring the content of a SceneView using an ExternalTexture to display it in an another SceneView. For now I use the same technique as the Chromakey video sample to have a transparent background. But it won't work if I have some semi-transparent items in my scene.