How to make Facebook 3D-photo in Unity
A bit of theory
Modern devices with two cameras have a Portrait Mode, which beautifully blurred the background.
The phone calculates the distance between the camera and objects in the frame using the offset between the lenses, and then put this data into the image. Using this value, it makes the blur natural.
Facebook created an algorithm that simulates a 3D-Effect when you rotate the phone based on these values.
All it needs is a picture with information about pixels remoteness.
You just need to render 2 pictures — Main Image and Depth Mask, then upload them as a 3D photo to Facebook!
Let's do it
Open Unity and follow these steps:
- Run your game and press Pause in a suitable moment and set a good angle of the Camera. Easiest way to do it - setup scene in Scene Window, select Camera GameObject and go to Game Object → Align With View or press Shift+Ctrl+F (Shift+Cmd+F on Mac).
- Make a Screenshot. Important: do not exit the Play Mode.
- If you haven't Post Process Layer script on your Camera GameObject you need to add it. Then attach Post Process Debug component, set Camera GameObject to Post Process Layer field and choose Depth in Debug Overlay property.
Now your Game Window render Depth Buffer instead of full image.
- Make a Screenshot of Depth Buffer.
- Open Photoshop or another graphics editor and load your images. You need to crop them pixel-to-pixel.
- Now you have two important images — Main Image and Depth Mask.
- Rename the Main Image to image, and the Depth Mask to image_depth. Files format can be both JPEG and PNG.
- Then you need to drag and drop both files into the Facebook post creation window, as shown below.
Facebook generate 3D photo from two images; all you need to do is click the Publish button.
If you did everything right (and here it is difficult to make a mistake in something) — you got a 3D photo on Facebook, like what was shown at the beginning of the article. If you want to make 3D Effect stronger you need to make Depth Image more contrast in any graphics editor.
If you have any questions or comments — contact us on social networks or at this email address. Well, and, of course, share with friends, if it was useful!
See you again!