Ejemplo n.º 1
0
        /////////////////////////////////////////////////////////////////////////////////
        // render related

        public void InvokeStereoRenderers(VRRenderEventDetector detector)
        {
            // render registored stereo cameras
            for (int renderIter = 0; renderIter < stereoRendererList.Count; renderIter++)
            {
                StereoRenderer stereoRenderer = stereoRendererList[renderIter];

                if (stereoRenderer.shouldRender)
                {
                    stereoRenderer.Render(detector);
                }
            }
        }
Ejemplo n.º 2
0
        public void MoveStereoCameraBasedOnHmdPose(VRRenderEventDetector detector)
        {
            Vector3    mainCamPos = detector.transform.position;
            Quaternion mainCamRot = detector.transform.rotation;

            if (isMirror)
            {
                // get reflection plane -- assume +y as normal
                float   offset          = 0.07f;
                float   d               = -Vector3.Dot(canvasOriginUp, canvasOriginPos) - offset;
                Vector4 reflectionPlane = new Vector4(canvasOriginUp.x, canvasOriginUp.y, canvasOriginUp.z, d);

                // get reflection matrix
                reflectionMat = Matrix4x4.zero;
                CalculateReflectionMatrix(ref reflectionMat, reflectionPlane);

                // set head position
                Vector3 reflectedPos = reflectionMat.MultiplyPoint(mainCamPos);
                stereoCameraHead.transform.position = reflectedPos;

                // set head orientation
                stereoCameraHead.transform.rotation = mainCamRot;
            }
            else
            {
                Vector3 posCanvasToMainCam = mainCamPos - canvasOriginPos;

                // compute the rotation between the portal entry and the portal exit
                Quaternion rotCanvasToAnchor = anchorRot * Quaternion.Inverse(canvasOriginRot);

                // move remote camera position
                Vector3 posAnchorToStereoCam = rotCanvasToAnchor * posCanvasToMainCam;
                stereoCameraHead.transform.position = anchorPos + posAnchorToStereoCam;

                // rotate remote camera
                stereoCameraHead.transform.rotation = rotCanvasToAnchor * mainCamRot;
            }
        }
Ejemplo n.º 3
0
        private void RenderToOneStereoTexture(VRRenderEventDetector detector)
        {
            // get eye poses
            if (detector.eye == 0)
            {
                Vector3    leftEyeOffset   = StereoRenderManager.Instance.paramFactory.GetEyeSeperation(0);
                Quaternion leftEyeRotation = StereoRenderManager.Instance.paramFactory.GetEyeLocalRotation(0);

                RenderEye(
                    leftEyeOffset, leftEyeRotation,
                    leftProjMatrix, detector.unityCamera.worldToCameraMatrix,
                    leftEyeTexture, "_MainTexture");
            }
            else
            {
                Vector3    rightEyeOffset   = StereoRenderManager.Instance.paramFactory.GetEyeSeperation(1);
                Quaternion rightEyeRotation = StereoRenderManager.Instance.paramFactory.GetEyeLocalRotation(1);

                RenderEye(
                    rightEyeOffset, rightEyeRotation,
                    rightProjMatrix, detector.unityCamera.worldToCameraMatrix,
                    rightEyeTexture, "_MainTexture");
            }
        }
Ejemplo n.º 4
0
        private void RenderToTwoStereoTextures(VRRenderEventDetector detector)
        {
            // get eye poses
            var leftEyeOffset   = StereoRenderManager.Instance.paramFactory.GetEyeSeperation(0);
            var leftEyeRotation = StereoRenderManager.Instance.paramFactory.GetEyeLocalRotation(0);

            var rightEyeOffset   = StereoRenderManager.Instance.paramFactory.GetEyeSeperation(1);
            var rightEyeRotation = StereoRenderManager.Instance.paramFactory.GetEyeLocalRotation(1);

            // render stereo textures
            RenderEye(
                leftEyeOffset, leftEyeRotation,
                leftProjMatrix, detector.unityCamera.worldToCameraMatrix,
                leftEyeTexture, "_LeftEyeTexture");

            var rightEyeWorldToCameraMatrix = detector.unityCamera.worldToCameraMatrix;

            rightEyeWorldToCameraMatrix.m03 -= 2.0f * Mathf.Abs(leftEyeOffset.x);

            RenderEye(
                rightEyeOffset, rightEyeRotation,
                rightProjMatrix, rightEyeWorldToCameraMatrix,
                rightEyeTexture, "_RightEyeTexture");
        }
Ejemplo n.º 5
0
        public void MoveStereoCameraBasedOnHmdPose(VRRenderEventDetector detector)
        {
            Vector3    mainCamPos = detector.transform.position;
            Quaternion mainCamRot = detector.transform.rotation;

            if (isMirror)
            {
                // get reflection plane -- assume +y as normal
                float   offset          = 0.07f;
                float   d               = -Vector3.Dot(canvasOriginUp, canvasOriginPos) - offset;
                Vector4 reflectionPlane = new Vector4(canvasOriginUp.x, canvasOriginUp.y, canvasOriginUp.z, d);

                // get reflection matrix
                reflectionMat = Matrix4x4.zero;
                CalculateReflectionMatrix(ref reflectionMat, reflectionPlane);

                // set head position
                Vector3 reflectedPos = reflectionMat.MultiplyPoint(mainCamPos);
                stereoCameraHead.transform.position = reflectedPos;

                // set head orientation
                stereoCameraHead.transform.rotation = mainCamRot;
            }
            else
            {
                Quaternion Rot180     = Quaternion.Euler(0, 180.0f, 0);
                Vector3    LocalPos   = canvasOrigin.InverseTransformPoint(mainCamPos);
                Vector3    RotatedPos = Rot180 * LocalPos;
                stereoCameraHead.transform.position = anchorTransform.TransformPoint(RotatedPos);
                stereoCameraHead.transform.rotation = anchorTransform.rotation * Rot180 * Quaternion.Inverse(canvasOrigin.rotation) * mainCamRot;


                // Vector3 posCanvasToMainCam = mainCamPos - canvasOriginPos;

                // // compute the rotation between the portal entry and the portal exit
                // Quaternion rotCanvasToAnchor = anchorRot * Quaternion.Inverse(canvasOriginRot);

                // // move remote camera position
                // Vector3 posAnchorToStereoCam = rotCanvasToAnchor * posCanvasToMainCam;

                // Vector3 posCanvasToMainCam = canvasOrigin

                // Vector3 invTransformPoint = canvasOrigin.InverseTransformDirection(mainCamPos);

                // Vector3 rotPos = Quaternion.Euler(0, 180.0f, 0) * invTransformPoint;

                // Debug.Log("Canvas Origin Pos: " + canvasOriginPos);
                // Debug.Log("Transform Pos:" + transform.position);
                // Debug.Log("MainCameraPos: " + mainCamPos);
                // Debug.Log("Pos Canvas To main cam:" + posCanvasToMainCam);
                // Debug.Log("invTransformPoint" + invTransformPoint);
                // Debug.Log("Rot Pos: " + rotPos);

                // stereoCameraHead.transform.position = anchorPos + rotPos;

                // Debug.Log(posCanvasTomainCam);

                // stereoCameraHead.transform.position = anchorTransform.TransformDirection(rotPos);


                // stereoCameraHead.transform.position = anchorPos + posAnchorToStereoCam;

                // // rotate remote camera
                // stereoCameraHead.transform.rotation = rotCanvasToAnchor * mainCamRot;
            }
        }
Ejemplo n.º 6
0
        public void Render(VRRenderEventDetector detector)
        {
            // move stereo camera around based on HMD pose
            MoveStereoCameraBasedOnHmdPose(detector);

            // invoke pre-render events
            if (preRenderListeners != null)
            {
                preRenderListeners.Invoke();
            }

            if (canvasVisible)
            {
                // change layer of specified objects,
                // so that they become invisible to currect camera
                ignoreObjOriginalLayer.Clear();
                for (int i = 0; i < ignoreWhenRender.Count; i++)
                {
                    ignoreObjOriginalLayer.Add(ignoreWhenRender[i].layer);

                    if (ignoreLayerNumber > 0)
                    {
                        ignoreWhenRender[i].layer = ignoreLayerNumber;
                    }
                }

                // invert backface culling when rendering a mirror
                if (isMirror)
                {
                    GL.invertCulling = true;
                }

                // render the canvas
                if (StereoRenderDevice.IsNotUnityNativeSupport(StereoRenderManager.Instance.hmdType))
                {
                    RenderToOneStereoTexture(detector);
                }
                else
                {
                    RenderToTwoStereoTextures(detector);
                }

                // reset backface culling
                if (isMirror)
                {
                    GL.invertCulling = false;
                }

                // resume object layers
                for (int i = 0; i < ignoreWhenRender.Count; i++)
                {
                    ignoreWhenRender[i].layer = ignoreObjOriginalLayer[i];
                }

                // finish this render pass, reset visibility
                canvasVisible = false;
            }

            // invoke post-render events
            if (postRenderListeners != null)
            {
                postRenderListeners.Invoke();
            }
        }