The most fundamental functionality of HoloKit Unity SDK
Stereoscopic rendering is the core functionality provided by HoloKit SDK. It can transform a screen AR project into a stereo one by using the stereoscopic camera prefab provided by the SDK.
This section is a tutorial on how to implement the sample stereoscopic rendering project. You can directly import this sample by clicking the import button as shown below.
Click the import button to import the stereoscopic rendering sample
After you import the sample, you can have a look at the prefabs and scripts used in the sample scene.
If you want to build everything from scratch, please follow the rest of the section.
There is a script called
HoloKitDriverwhich initializes some fundamental functinalities at the beginning of the application life cycle. For any HoloKit project, we first need to drag the
HoloKitDriverprefab into the scene. We can find the
Drag HoloKitDriver prefab into the scene
We first add
XROriginobjects into the scene as a normal ARFoundation project.
Add ARSession and XROrigin into the scene
Then delete the
MainCameraobject under the
XROrigin, and replace it with a
HoloKitCameraprefab. You can find the
Replace the default MainCamera with HoloKitCamera
After replacing, please make sure the
Camera GameObjectfield of the
XROriginis assigned with the new
For a HoloKit application, it can switch between two render modes, which are
Monomode, the app should look exactly like a normal screen AR app. Under
Stereomode, two viewports are rendered on the screen and you can insert your iPhone into a HoloKit to experience stereoscopic AR.
A screenshot of HoloKit App under Mono mode
A screenshot of HoloKit App under Stereo mode
We need some basic UI to control the switching between two render modes. There is already a default UI canvas in the package which does the job. Go to
Packages->HoloKit SDK->Assets->Prefabs->UIand find the
HoloKitUICanvasprefab. Drag the prefab into the scene. Also add an
EventSystemobject into the scene thus we can press the button on the canvas.
Add HoloKitUICanvas and EventSystem into the scene
If you are using Unity New Input System, don't forget to upgrade your
EventSystemto fit it.
Stereomode, the screen orientation is locked to be
Monomode, the screen orientation is really up to you. It is exactly like a normal screen AR app. But in this tutorial, let's make things easy and lock the screen orientation to be
Set Screen Orientation to LandscapeLeft in Project Settings
Believe it or not, you've done everything to setup a basic HoloKit application. The only problem is that there is no object in the scene so you cannot see anything. Let's add a cube into the scene and set its position to (0, 0, 5).
Add a cube into the scene
Now everything is ready. Build the project and you should see a cube in front of you. Press the upper-right button to switch to
Stereomode and insert your iPhone into a HoloKit. Put the HoloKit on and move around, you should see the cube fixed in that position.