Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
knchaffin's avatar
knchaffin
Explorer
11 years ago

Displaying Oculus Rift Unity Content on a 3DTV

A few weeks ago I developed a technique for viewing Oculus enabled Unity content on a 3D TV. This is a fairly simple scripting chore and may be of interest to others. It should work for any display device that can accept "squashed side by side" stereoscopic 3D. In my case this is a Panasonic passive polarized glasses 3D TV with HDMI input. As I have scripted this, the same Unity scene can be used to display on the Oculus Rift or on the 3D TV if the Rift is not attached to the computer. If the Rift is attached, the lens distortions get applied. If the Rift is not attached, the lens distortions do not get applied, giving side by side images that need a bit of tweaking as described below.

To do this you will need to create a camera.cs script as shown below and add this script to your OVRPlayerController game object. This script will find the Oculus cameras and adjust the OVRDevice.LensSeparationDistance to .075f, and will modify the cameras' projection matrix by multiplying by Matrix4x4.Scale(new Vector3 (0.5f, 1, 1). This introduces a horizontal .5 scaling factor for each camera image, essentially changing the horizontal FOV. This must be done so that the side by side images are scaled properly so that when the TV expands each side to the screen width, the FOV is back to normal. The LensSeparationDistance must be adjusted or the 3D separation is too extreme for image convergence.

This script assumes that you are alreday able to display your computer output on your 3D TV. In my case I am outputting video from an NVIDIA Quadroplex 7000 with DVI to HDMI adapter. You may need to change the graphics resolution to suit the TV versus the Rift. I run the TV graphics at 1920x1080 for HD compatibility on the TV.

Ken Chaffin - Texas Tech University Media Lab



using UnityEngine;
using System.Collections;

public class CameraScript : MonoBehaviour {

protected OVRCameraController myOculusCameraControllerObject;
protected OVRDevice myOculusDeviceObject;
protected OVRPlayerController myOculusPlayerControllerObject;
bool enableCursor=true; // for Oculus Rift , optional
int numOculusCameras=0;
Camera myOculusCameraLeft;
Camera myOculusCameraRight;

void Start () {

myOculusCameraControllerObject= UnityEngine.Object.FindObjectOfType<OVRCameraController>();
myOculusDeviceObject= UnityEngine.Object.FindObjectOfType<OVRDevice>();
myOculusPlayerControllerObject= UnityEngine.Object.FindObjectOfType<OVRPlayerController>();

if ((myOculusCameraControllerObject!=null)&&(myOculusDeviceObject!=null)) // the Oculus controller script is active
{
if (OVRDevice.SensorCount == 0) // we have an Oculus script but no HMD is attached
{
Debug.Log("the Oculus controller script is active but the Oculus device is not connected!");
// if (myOculusPlayerControllerObject!=null) // optional
// myOculusPlayerControllerObject.enabled=false; // turn off mouse look without click

OVRDevice.LensSeparationDistance=.075f;
myOculusCameraControllerObject.InitCameraControllerVariables();;

Camera[] cameras = FindObjectsOfType(typeof(Camera)) as Camera[];

numOculusCameras=cameras.Length;
Debug.Log ("num cameras=" + numOculusCameras);

if (numOculusCameras==2)
{
myOculusCameraLeft=cameras[0];
myOculusCameraRight=cameras[1];

}

}
}

}


void Update () {

// this code produces squashed side by side stereoscopic images by scaling the projection matrix in X
if (numOculusCameras==2) // tried this in OnPreCull() but was overridden by Oculus code
{
myOculusCameraLeft.ResetWorldToCameraMatrix ();
myOculusCameraLeft.ResetProjectionMatrix ();
myOculusCameraLeft.projectionMatrix = myOculusCameraLeft.projectionMatrix * Matrix4x4.Scale(new Vector3 (0.5f, 1, 1));

myOculusCameraRight.ResetWorldToCameraMatrix ();
myOculusCameraRight.ResetProjectionMatrix ();
myOculusCameraRight.projectionMatrix = myOculusCameraRight.projectionMatrix * Matrix4x4.Scale(new Vector3 (0.5f, 1, 1));
}


if ((myOculusCameraControllerObject!=null)&&(enableCursor))
{
// Screen.showCursor=true; // optional
// Screen.lockCursor = false;
}

}

}


1 Reply

Replies have been turned off for this discussion