Portrait Segmentation detects and isolates the subject in the frame, so customized textures and effects can be applied to the background.
Segmentation has a very high performance impact on iOS devices. Segmentation should not be combined with many other features as doing so will cause low FPS and may subsequently lead to not passing QA.
Add a Portrait Segmentation Object
Go to the Hierarchy panel and click the Add button [+] > Segmentation > Portrait Segmentation. A 2D Camera is automatically added.
Use the Portrait Segmentation Object
A Portrait Segmentation with Portrait and Background objects will show up in the Hierarchy panel whenever you add Portrait Segmentation:
- Portrait Segmentation is a container object with a Screen Transform.
- Portrait is essentially an image. The Image component of this object has been automatically assigned with the Portrait Segmentation Texture, which you can find in the Assets panel.
- Background is essentially an image. The Image component of this object has been automatically assigned with Background Texture. You can make it animated by using an Animated Texture.
A Segmentation material will automatically be added to the Material property of the Image component when adding a Portrait Segmentation object. Segmentation material is useful for quickly adding commonly used segmentation effects to the scene.
The Portrait Segmentation object is made up of the following components, found in the Inspector panel:
Demo Effect: Add a 3D Object In Between the Portrait and Background
Add a 3D object in front of or behind the segmentation layer by changing the render order of the cameras.
Download the following file to follow along:
First go to Hierarchy panel and click the Add button [+] > Segmentation > Portrait Segmentation. Next add a Sphere object by clicking the Add button [+] > 3D > Sphere.
You can see that the Sphere object is rendered on top of the Portrait and Background objects.
Make sure that the Sphere object you added is on the same layer as the Camera object.
Render the Segmentation and Background Images Separately
To move the sphere between the Portrait image and the Background image, you must have two 2D cameras to render the two images separately. Then the sphere can be rendered in the middle.
First go to the Hierarchy panel and duplicate the 2D Background Effects render group, or the container with the 2D Background Camera and Portrait Segmentation objects and its child objects. You can rename the duplicated render group by right-clicking it and clicking Rename.
Now drag and drop the duplicated render group under the General render group, or the container with the Sphere object, in the Hierarchy panel.
Disable the Portrait object in the original segmentation canvas and then the Background object in the duplicated segmentation canvas.
You can see that the sphere now moves in between the Portrait and Background images.