Using Mixed Reality Capture in WebXR requires different parts to work together. In this page we will go over the different parts and settings to make it work in a project.
Mixed Reality Capture is used to merge between the real world and the virtual world, by positioning a real camera feed inside the virtual environment and displaying the outcome in a spectator display.
In this WebXR solution, we made sure that WebXR Export can support Spectator mode and had the code of the Mixed Reality Capture feature in the WebXR Interactions package.
A configured prefab can be found in the Sample scene of WebXR Interactions named as SpectatorCameraHolder.prefab
.
The current configuration is expected for Mixed Reality Capture to work properly
- SpectatorCameraHolder
- SpectatorCamera (Components: Camera, SpectatorCamera)
- StackCameras
- SpectatorBackgroundCamera (Components: Camera)
- SpectatorWebcamLightingCamera (Components: Camera)
- SpectatorForegroundCamera (Components: Camera)
- Background (Components: MeshFilter with Quad, MeshRenderer with UnlitTransparent Material. Layer: Spectator)
- Foreground (Components: MeshFilter with Quad, MeshRenderer with UnlitTransparent Material. Layer: Spectator)
- MixedRealityCaptureController (Components: MixedRealityCaptureController)
- CameraPoint (Used as Visual reference for moving point)
- TopPoint (Used as Visual reference for moving point)
- BottomPoint (Used as Visual reference for moving point)
- WebcamHolder
- WebcamQuad (Components: PlayWebcam, MeshFilter with Quad, MeshRenderer with ChromaKeyUnlit Material. Layer: Webcam)
- WebcamLightingQuad (Components: MeshFilter with Quad, MeshRenderer with White Legacy Diffuse Material. Layer: WebcamLighting)
- CameraHint (Used as Visual reference for point on webcam)
- TopHint (Used as Visual reference for point on webcam)
- BottomHint (Used as Visual reference for point on webcam)
The SpectatorCameraHolder.prefab
sample prefab uses pre-defined layers:
- 16 Webcam
- 17 WebcamLighting
- 18 Spectator
Some general steps to follow when implementing WebXR Mixed Reality Capture in a project:
- Import the
SpectatorCameraHolder.prefab
from the sample. It's better to duplicate it and using the duplicated asset. - Add the prefab to the scene with the WebXR Camera Rig (or
WebXRCameraSet
). - If the camera rig is expected to be static, the
SpectatorCameraHolder
can be at the root of the scene, else it should be a child of the camera rig. - Make sure
MixedRealityCaptureController
is configured correctly. webcamLayer
point to the Webcam layer.mixedRealityOnLayers
are the layers that the Spectator camera would use during the capture mode, should contain the Webcam and Spectator layers.camerasBase
reference to the Cameras Transform in the camera rig hierarchy.cameraFollower
reference theCameraFollower
Transform in the camera rig hierarchy.xrCameras
reference all the XR cameras Camera components in the camera rig hierarchy.spectatorCamera
reference the Spectator camera Camera in theSpectatorCameraHolder
hierarchy.stackCameras
reference theStackCameras
GameObject in theSpectatorCameraHolder
hierarchy.spectatorBackgroundCamera
reference theSpectatorBackgroundCamera
Camera in theSpectatorCameraHolder
hierarchy.spectatorForegroundCamera
reference theSpectatorForegroundCamera
Camera in theSpectatorCameraHolder
hierarchy.spectatorWebcamLightingCamera
reference theSpectatorWebcamLightingCamera
Camera in theSpectatorCameraHolder
hierarchy.spectatorCameraTransform
reference the Spectator camera Transform in theSpectatorCameraHolder
hierarchy.spectatorCameraParent
reference theSpectatorCameraHolder
Transform.backgroundPlaneRenderer
reference theBackground
Renderer in theSpectatorCameraHolder
hierarchy.foregroundPlaneRenderer
reference theForeground
Renderer in theSpectatorCameraHolder
hierarchy.backgroundPlaneTransform
reference theBackground
Transform in theSpectatorCameraHolder
hierarchy.foregroundPlaneTransform
reference theForeground
Transform in theSpectatorCameraHolder
hierarchy.defaultPlaneMaterial
default Material used for the background and foreground planes, Unlit Transparent material.webcamParent
reference theWebcamHolder
Transform in theSpectatorCameraHolder
hierarchy.webcam
reference theWebcamQuad
PlayWebcam in theSpectatorCameraHolder
hierarchy.calibrationPointCamera
reference theCameraPoint
Transform in theSpectatorCameraHolder
hierarchy.calibrationPointTop
reference theTopPoint
Transform in theSpectatorCameraHolder
hierarchy.calibrationPointBottom
reference theBottomPoint
Transform in theSpectatorCameraHolder
hierarchy.calibrationHintCamera
reference theCameraHint
GameObject in theSpectatorCameraHolder
hierarchy.calibrationHintTop
reference theTopHint
GameObject in theSpectatorCameraHolder
hierarchy.calibrationHintBottom
reference theBottomHint
GameObject in theSpectatorCameraHolder
hierarchy.leftController
reference the left WebXRController in the camera rig hierarchy.rightController
reference the right WebXRController in the camera rig hierarchy.webcamFramesDelaySize
set the default number of delayed frames to store - Used for cases of Webcam image slower than VR movement.- Make sure that the Main Camera and XR Cameras hide or show the correct layers, the Spectator, Webcam and WebcamLighting should be hidden.
- Make sure that the Spectator camera shows the Spectator and Webcam Layers and other layers that the project should display.
- Make sure that the Spectator camera hides the WebcamLighting layer.
- Make sure that the background and foreground cameras hide the Spectator, Webcam and WebcamLighting layers.
- Make sure that the background and foreground cameras show all other layers that the project should display.
- Make sure that the SpectatorWebcamLightingCamera only shows the WebcamLighting layer.
That should handle all the configurations needed for Mixed Reality Captuer to work properly.
Once the project runs, for the feature to be enabled, both the SpectatorCamera
and MixedRealityCaptureController
should be set to be enable in XR.
Both components contains EnableInXR(bool)
method to enable their functionality when user is switching to XR mode.
There are more customization and settings that can be handle by scripts like Chroma Key min and max range, check the MixedRealityCaptureController
and PlayWebcam
code for those options.