As the name suggests, I'm trying to make vr portals, but I've run into some issues. Currently I've set it up so that the portal screen should show what's behind the portal simply to make it easier to compare if it's showing the correct thing or not. This is what I've got so far, and as you can see, it's painfully close.
Here's my code for setting up the portal camera.
leftMatrix = Camera.main.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
rightMatrix = Camera.main.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
leftMatrix[12] += Camera.main.stereoSeparation / 2;
rightMatrix[12] -= Camera.main.stereoSeparation / 2;
int dot = (int)Mathf.Sign(Vector3.Dot(myWormhole.transform.forward, myWormhole.transform.position - transform.position));
rightCam.projectionMatrix = rightMatrix;
Vector3 camSpacePos = rightCam.worldToCameraMatrix.MultiplyPoint(myWormhole.transform.position);
Vector3 camSpaceNormal = rightCam.worldToCameraMatrix.MultiplyVector(myWormhole.transform.forward) * dot;
float camSpaceDist = -Vector3.Dot(camSpacePos, camSpaceNormal);
Vector4 clipPlaneCamSpace = new Vector4(camSpaceNormal.x, camSpaceNormal.y, camSpaceNormal.z, camSpaceDist + debugDist);
rightCam.projectionMatrix = rightCam.CalculateObliqueMatrix(clipPlaneCamSpace);
rightCam.Render();
leftCam.projectionMatrix = leftMatrix;
camSpacePos = leftCam.worldToCameraMatrix.MultiplyPoint(myWormhole.transform.position);
camSpaceNormal = leftCam.worldToCameraMatrix.MultiplyVector(myWormhole.transform.forward) * dot;
camSpaceDist = -Vector3.Dot(camSpacePos, camSpaceNormal);
clipPlaneCamSpace = new Vector4(camSpaceNormal.x, camSpaceNormal.y, camSpaceNormal.z, camSpaceDist + debugDist);
leftCam.projectionMatrix = leftCam.CalculateObliqueMatrix(clipPlaneCamSpace);
leftCam.Render();
Does anyone have any idea what I'm doing wrong?
P.S. The debugDist variable is currently set to 0. I've used it at times to alter the clip plane, but the problem is that the camera is slightly misaligned.