TBCameraRig

Holden Link edited this page Feb 19, 2017 · 36 revisions

Overview

A universal camera rig for multiplatform VR games that syncs settings across the camera prefabs from each platform's SDK.

Why use this over the native Unity integration for each platform?

New features for each platform typically arrive in their SDKs long before the native integrations support them. And if you end up targeting a platform that Unity's native integration doesn't support, you can make it work through TBCameraRig with just a few lines of code.

Dependencies

Platform must be set using TBEditorBuildSettings tool.

Usage

Initial Setup

Drag the TBCameraRig platform into your scene. If developing for Steam VR, Oculus Rift, or Gear VR, drag the camera prefabs that came with the plugins for those platforms in the given fields in TBCameraRig's inspector (such as OVRCameraRig or [CameraRig]).

Using TBCenter

TBCenter is a transform created at runtime that represents the position and rotation of the player's head on every platform. If you have things that you normally keep parented to the camera prefabs that come with each SDK, parent them to TBCenter at runtime instead. If you want to billboard something to the camera, billboard it to TBCenter.

Example usage:

void Start()
{
     transform.SetParent(TBCameraRig.instance.GetTBCenter());
}

Standard Camera

For platforms that use the Unity native camera, the StandardCamera child of TBCameraRig will be used. This camera is also used as a preview for the Game window in the editor for all platforms. StandardCamera will be automatically destroyed at runtime if it is not used by your target platform.

Reference

Example of TBCameraRig's filled inspector

Camera Settings

Whenever you want to change camera settings, change them on TBCameraRig in the inspector or TBCameraRig.instance in code. Its properties are named to match the properties in Unity's standard Camera class:

Property Variable
Clear Flags CameraClearFlag clearFlags
Culling Mask LayerMask cullingMask
Background Color Color backgroundColor
Near Clip Plane float nearClipPlane
Far Clip Plane float farClipPlane
Use Occlusion Culling bool useOcclusionCulling

Example usage:

TBCameraRig.instance.backgroundColor = Color.black;
TBCameraRig.instance.farClipPlane = 200;

VR Settings

Camera Scale

Scale the camera to adjust the IPD and make the player feel bigger or smaller in the world. Does not update if changed at runtime, scale the TBCameraRig transform instead.

Use Position Tracking

Toggles position tracking on Rift and PlayStation VR. You should always leave this enabled unless you are developing for a platform that doesn't support position tracking, and you want to simulate its limitations with other headsets. Does not work on Steam VR.

Sort Mode

Adjusts the OpaqueSortMode property on the camera. If you are CPU limited and batching to optimize draw calls, you want to use No Distance Sort. If you are GPU limited, you may have better performance with Front to Back. If you aren't sure, set it to Default.

Calibration Settings

Standing

For standing or room scale experiences, set "Is Standing Experience" to true in the inspector. This will cause your tracking space to be created at TBCameraRig's position and orientation. Move TBCameraRig to move the entire tracking space. The floor is calibrated in standing mode based on the platform's capabilities:

Platform Floor Position
Oculus Rift / Steam VR TBCameraRig's Y position
All other platforms TBCameraRig's Y position + Uncalibrated Camera Height

Sitting

For seated experiences, set "Is Standing Experience" to false in the inspector to make TBCameraRig's position and orientation be exactly where the camera will spawn. Move TBCameraRig to move the camera. Preset floor settings for all platforms will be ignored.

Recenter On Load

Recenters the camera when the scene loads.

Calibration Hotkey

Allows you to set a quick hotkey for calibrating the camera's position and rotation at runtime. PC-based platforms and editor only.

Screenshot Camera

Specify an optional TBScreenshotCamera prefab to spawn in Play Mode when running in the editor.