Hololight Stream for Unity extension - Occlusion
Occlusion
Supported client devices
-
Apple iOS and iPadOS
| This feature is currently only available on Apple devices equipped with a LIDAR sensor. |
Detects whether Occlusion sends camera information for Apple iOS and iPadOS. Occlusion quality will increase depending on the device’s sensor depth map resolution.
Put in the room mesh, it is possible to use it with HoloLens devices.
Depth information must be enabled to use this feature. To enable depth information:
-
Navigate to Project Settings > XR Plug-in Management > Hololight Stream.
-
Set the Main Camera’s alpha to 255 to achieve non transparent blending with the background.
MRTK2 can also display the room mesh and occlude
To make things easier, there is a class called OcclusionExtension. This class manages the logic for toggling and configuring occlusion functionality on the client device.
Occlusion Extension
The occlusion manager uses the underlying occlusion data channel. This data channel sends toggle and configuration messages to the client device.
The SendToggle() function toggles occlusion. , interpreted as "on" for 1 and "off" for 0 on the client device.
public void SendToggleWrapper()
{
if (_occlusionExtension != null && _occlusionExtension.IsConnected)
{
if (_isOcclusionEnabled == 0)
{
_isOcclusionEnabled = 1;
} else
{
_isOcclusionEnabled = 0;
}
_occlusionExtension.SendToggle(_isOcclusionEnabled);
}
The camera configuration can be sent (which includes near and far plane distance values of your camera) using the SendCameraInfo() function. This function requires a Camera object to read camera information.
| SendCameraInfo() function must be called on Unity main thread, otherwise Main Camera will not be accessible. |
public void SendCameraWrapper(Camera cam)
{
if (_occlusionExtension != null && _occlusionExtension.IsConnected)
{
_occlusionExtension.SendCameraInfo(cam);
}
One important point is that you should subscribe to OnConnectionChanged event if you want to provide immediate occlusion information to your client device when connecting. You can achieve this using the method shown below:
private void OnEnable()
{
_occlusionExtension = DataChannelManager.GetDataChannel<OcclusionExtension>();
if (_occlusionExtension != null)
{
_occlusionExtension.Start();
_occlusionExtension.OnConnectionChanged += OcclusionExtension_OnConnectionChanged;
}
private void OcclusionExtension_OnConnectionChanged(bool connected)
{
_readyToSend = connected;
private void Update()
{
if (_readyToSend)
{
_occlusionExtension.SendCameraInfo(Camera.main);
_occlusionExtension.SendToggle(_isOcclusionEnabled);
_readyToSend = false;
}
Example
For further information on how to use this feature, see the OcclusionController sample within the DataChannel folder of the com.hololight.stream.examples package. This sample sends configuration and toggle messages. This script can be added to an empty object in the scene to trigger the functions to enable/disable the occlusion.