Skip to content

Instantly share code, notes, and snippets.

@korinVR
Created March 21, 2018 08:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korinVR/b7d6fc67a54fcf2d2f4e5940d298aa7a to your computer and use it in GitHub Desktop.
Save korinVR/b7d6fc67a54fcf2d2f4e5940d298aa7a to your computer and use it in GitHub Desktop.
Use Vive Stereo Rendering Toolkit on Unity standard VR support
using UnityEngine;
using UnityEngine.XR;
namespace HTC.UnityPlugin.StereoRendering
{
public class UnityXRParamFactory : IDeviceParamFactory
{
public int GetRenderWidth()
{
return XRSettings.eyeTextureWidth;
}
public int GetRenderHeight()
{
return XRSettings.eyeTextureHeight;
}
public Vector3 GetEyeSeperation(int eye)
{
const float Ipd = 0.06567926f;
if (eye == 0)
{
return new Vector3(-Ipd / 2f, 0, 0);
}
else
{
return new Vector3(Ipd / 2f, 0, 0);
}
}
public Quaternion GetEyeLocalRotation(int eye)
{
return Quaternion.identity;
}
public Matrix4x4 GetProjectionMatrix(int eye, float nearPlane, float farPlane)
{
switch (eye)
{
case 0:
return Camera.main.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
case 1:
return Camera.main.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
}
return Matrix4x4.identity;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment