The Passthrough Transitioning motif demonstrates the transition from fully immersive VR experiences to passthrough mixed reality experiences using the Passthrough API. In this sample project, you can adjust the visibility of your surroundings by manipulating a slider, which regulates the level of passthrough. You can alternatively directly switch from one mode to another with the press of a button.
The project also shows you how to use the Boundary API to disable the guardian while in passthrough mode for a seamless MR experience.
Note: This sample will also work with the OpenXR plugin instead of the Oculus XR Plugin. However, if you plan to use the other samples in this project, make sure to check the specific requirements of the samples.
Project setup
To set up Passthrough Transitioning in your own project or scene, do the following:
Import the Passthrough Transitioning motif assets, including scripts, shaders, prefabs, and materials.
With the XR Camera Rig selected in the Hierarchy, go to the Inspector, and under OVR Manager>Quest Features, set Passthrough Support to Supported, and under OVR Manager>Insight Passthrough & Guardian Boundary, check Enable Passthrough.
Add an OVR Passthrough Layer component, and set its Compositing>Placement to Underlay.
Add the Passthrough Fader prefab to the CenterEyeAnchor.
Reference the OVR Passthrough Layer on the Passthrough Fader component.
Set up a way to call the public TogglePassthrough method of the PassthroughFader class, with either the Controller Buttons Mapper Building Block or the Menu Panel prefab.
To transition between VR and passthrough, place a sphere as a child of the main camera. Use a shader, configured at runtime with a custom fader script, to manipulate the sphere. This enables adjusting fade speed, direction, distance, and effects like dissolving the sphere in a random pattern (Perlin noise). All you need to set this up in your project is the custom PassthroughFader shader from this project and the PassthroughFader class or a similar class to manipulate the shader’s properties.
Contextual passthrough
Contextual passthrough means that passthrough should be enabled based on system recommendations. In other words, if the user is in passthrough mode in their home environment, the operating system can detect this and display the system splash screen and the Unity scene in passthrough. In VR mode, the system splash screen will be shown with a black background like before.
If you have enabled contextual passthrough and still cannot see the effect being applied, try updating your AndroidManifest.xml by navigating to Meta > Tools > Update Android Manifest file in the Unity Editor.
Note: Contextual passthrough for the system splash screen can currently only be enabled with Unity 6 or otherwise a Unity Pro license.
Splash Screen (Black)
Splash Screen (Passthrough Contextual)
Conditional passthrough
Passthrough can also be used to switch between MR and VR game modes or to conditionally show parts of the environment, such as when opening menus or changing scenes. This allows players to feel more comfortable and immersed, leading to longer play sessions.
Keep in mind that enabling passthrough is asynchronous. System resources like cameras can take a few hundred milliseconds to be activated, during which time passthrough is not yet rendered and experienced as black flicker. You can avoid this by using the passthroughLayerResumed event, which is emitted once the layer is fully initialized and passthrough is visible. Additionally, you don’t just want to immediately go from passthrough to VR but rather use a shader to smoothly transition between the two.
Passthrough transitioning sample scenes
Both scenes come with a Passthrough Fader prefab, which is located on the CenterEyeAnchor. It contains the PassthroughFader class. The prefab also contains an audio source used to play audio clips whenever you fade in or out.
PassthroughFader Underlay
PassthroughFader Selective
The passthrough fader slider scene comes with a PassthroughFaderSlider prefab, which is located on the CenterEyeAnchor. It contains the PassthroughFaderSlider component. The passthrough dissolver scene comes with a PassthroughDissolver prefab, which is located outside the CenterEyeAnchor, so that the dissolution pattern does not move with your head but instead stays anchored in the scene. It contains the PassthroughDissolver class.
PassthroughFaderSlider
PassthroughFaderDissolve
The PassthroughDissolver shader is applied to the sphere, and therefore, you need the PerlinNoiseTexture script to generate a texture, which you can easily modify by changing the values in the inspector. If you were to use the PassthroughDissolverSG ShaderGraph shader, you can simply remove the PerlinNoiseTexture component since the texture is already generated within the ShaderGraph, everything else works the same.
The PassthroughFader script is a component that contains both Underlay and Selective passthrough modes and lets the user decide which to use in the inspector.
PassthroughFader Underlay
PassthroughFader Selective
You can adjust Fade Speed and Fade Direction for both the PassthroughFaderUnderlay and PassthroughFaderSelective scripts.
For PassthroughFaderSelective, you can also change the Selective Distance, which is only relevant when using the Selective Passthrough mode. Selective Distance allows you to only show virtual content up until a predefined distance when in Passthrough. This can be useful for use cases like tabletop games or interaction where the user needs to be especially focused on their surroundings. The PassthroughFader class comes with four Unity Events that will inform you when a fade-out and fade-in was started and completed. This comes in handy when you want to, for example, play an audio clip.
The PassthroughFaderSlider script has mostly the same logic as the PassthroughFader script, but it allows you to slowly fade between VR and Passthrough manually, using a slider. Furthermore, you can turn off the guardian when a certain threshold has been crossed. The PassthroughDissolver works very similarly, except you don’t adjust the inverted alpha value with the slider, but with the dissolve level instead.
Other scripts that are part of the Passthrough Transitioning samples are the AudioController, which is responsible for reading the inverted alpha value from the material and adjusts the volume accordingly. The PerlinNoiseTexture class generates a texture with a random pattern for the PassthroughDissolver shader. With the Perlin Noise settings you can generate unique dissolve effects at runtime.
Passthrough transitioning shaders
Passthrough Transitioning utilizes a shader to achieve a smooth fading between VR and passthrough. The shader used by the Passthrough Fader and Slider is the PassthroughFader HLSL shader. The fragment shader handles fading effects by adjusting the alpha channel of the texture based on the specified fade direction and the inverted alpha value. The _InvertedAlpha parameter inverts the alpha transparency, creating a fading effect, while the _FadeDirection parameter controls the direction of the fade. The _FadeDirection modifies the alpha value by interpolating based on the UV coordinates: direction 0 uses the red channel, 1 fades from right to left, 2 fades from top to bottom, and 3 fades from the center outwards, with all transitions smoothed by smoothstep.
Note: In the sphere where you applied the shader, turn culling off (Cull Off). Also, keep the render queue at Transparent-1 (2999) to render behind transparent and opaque materials to prevent z-fighting (i.e., flickering).
To enable you to fade between VR and passthrough, and also achieve a fancy effect, the PassthroughFaderDissolve scene is included. This scene uses the PassthroughDissolver class to manipulate either the PassthroughDissolver or the PassthroughDissolverSG shader material and adjusts the level of dissolution to reveal passthrough in a pattern. The pattern in the case of PassthroughDissolver comes from the PerlinNoiseTexture script. For the PassthroughDissolverSG shader, the texture is generated inside the ShaderGraph.