Beispiel #1
0
        private void setupCameras()
        {
            foreach (string cameraName in cameraNamesToRender)
            {
                foreach (Camera camera in Camera.allCameras)
                {
                    if (cameraName.Equals(camera.name))
                    {
                        switch (camera.name)
                        {
                        case "GalaxyCamera":
                            O_Galaxy = camera;
                            break;

                        case "Camera ScaledSpace":
                            O_SclaledSpace = camera;
                            break;

                        case "Camera 01":
                            O_Far = camera;
                            break;

                        case "Camera 00":
                            O_Near = camera;
                            break;

                        default:
                            break;
                        }


                        camera.gameObject.AddOrGetComponent <posTracker>();

                        log("Camera:");
                        log("  Name:  " + camera.name);
                        log("  mask:  " + Convert.ToString(camera.cullingMask, 2));
                        log("  depth: " + camera.depth);
                        log("");

                        if (cameraName.Equals("InternalCamera"))
                        {
                            O_Interior = camera;
                        }
                        if (cameraName.Equals("GalaxyCamera"))
                        {
                            O_Galaxy = camera;
                        }

                        if (cameraName.Equals("Camera ScaledSpace"))
                        {
                            O_SclaledSpace = camera;
                            log("sky cam rot = " + camera.transform.rotation.eulerAngles.ToString());
                        }
                    }
                }
            }

            //Instantiate Cameras for all Layers
            camRight_Interior = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            camLeft_Interior  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            camRight_Near = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            camLeft_Near  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            camRight_Far = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            camLeft_Far  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            leftSky  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            rightSky = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            leftStars  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            rightStars = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            //copy Properties from Original Cameras
            leftSky.CopyFrom(O_SclaledSpace);
            rightSky.CopyFrom(O_SclaledSpace);
            leftStars.CopyFrom(O_Galaxy);
            rightStars.CopyFrom(O_Galaxy);
            camRight_Near.CopyFrom(O_Near);
            camLeft_Near.CopyFrom(O_Near);
            camLeft_Interior.CopyFrom(O_Interior);
            camRight_Interior.CopyFrom(O_Interior);
            camRight_Far.CopyFrom(O_Far);
            camLeft_Far.CopyFrom(O_Far);


            //set RenderTextures for Cameras
            setRenderTexturesTo(hmdLeftEyeRenderTexture, hmdRightEyeRenderTexture);

            //create left slave
            leftSlave      = camLeft_Interior.gameObject.AddOrGetComponent <RenderSlave>();
            leftSlave.left = true;

            //create right slave
            rightSlave      = camRight_Interior.gameObject.AddOrGetComponent <RenderSlave>();
            rightSlave.left = false;



            //Set Projectsions for all Cameras
            HmdMatrix44_t projLeft  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Near.nearClipPlane, camLeft_Near.farClipPlane);
            HmdMatrix44_t projRight = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Near.nearClipPlane, camRight_Near.farClipPlane);

            camLeft_Near.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft);
            camRight_Near.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight);

            HmdMatrix44_t projLeft2  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Interior.nearClipPlane, camLeft_Interior.farClipPlane);
            HmdMatrix44_t projRight2 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Interior.nearClipPlane, camRight_Interior.farClipPlane);

            camLeft_Interior.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft2);
            camRight_Interior.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight2);
            camLeft_Interior.SetStereoProjectionMatrix(Camera.StereoscopicEye.Left, MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft2));
            camLeft_Interior.SetStereoProjectionMatrix(Camera.StereoscopicEye.Right, MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft2));

            HmdMatrix44_t projLeft3  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Far.nearClipPlane, camLeft_Far.farClipPlane);
            HmdMatrix44_t projRight3 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Far.nearClipPlane, camRight_Far.farClipPlane);

            camLeft_Far.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft3);
            camRight_Far.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight3);

            HmdMatrix44_t projLeft4  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, leftSky.nearClipPlane, leftSky.farClipPlane);
            HmdMatrix44_t projRight4 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, rightSky.nearClipPlane, rightSky.farClipPlane);

            leftSky.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft4);
            rightSky.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight4);

            HmdMatrix44_t projLeft5  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, leftStars.nearClipPlane, leftStars.farClipPlane);
            HmdMatrix44_t projRight5 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, rightStars.nearClipPlane, rightStars.farClipPlane);

            leftStars.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft5);
            rightStars.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight5);


            //disable All Cameras to increase Performance
            O_SclaledSpace.enabled = false;
            O_Galaxy.enabled       = false;
            O_Near.enabled         = false;
            O_Far.enabled          = false;
            O_Interior.enabled     = false;

            camLeft_Near.enabled  = false;
            camRight_Near.enabled = false;

            camLeft_Far.enabled  = false;
            camRight_Far.enabled = false;

            leftSky.enabled  = false;
            rightSky.enabled = false;

            leftStars.enabled  = false;
            rightStars.enabled = false;

            camLeft_Interior.enabled  = false;
            camRight_Interior.enabled = false;



            //activate slaves
            posTracker.HmdOn = true;
            leftSlave.HmdOn  = true;
            rightSlave.HmdOn = true;

            //initialize active kerbal:
            activeKerbal = CameraManager.Instance.IVACameraActiveKerbal;
            lastKerbalID = CameraManager.Instance.IVACameraActiveKerbalIndex;
        }
Beispiel #2
0
        /*void LateUpdate()
         * {
         *  if (HmdOn)
         *  {
         *      foreach (int id in leftCameras)
         *      {
         *
         *          //Left camera position:##########################################################
         *          Camera.allCameras[id].transform.localRotation = hmdTransform.rot;
         *
         *          // translate the camera to match the position of the left eye, from origin
         *          Camera.allCameras[id].transform.localPosition = new Vector3(0f, 0f, 0f);
         *          Camera.allCameras[id].transform.Translate(hmdLeftEyeTransform.pos);
         *
         *          // translate the camera to match the position of the HMD
         *          Camera.allCameras[id].transform.localPosition += hmdTransform.pos;
         *
         *      }
         *  }
         * }*/



        void Update()
        {
            if (Input.GetKeyDown(KeyCode.KeypadPlus))
            {
                predict += 0.01f;
                log("predict interval set to: " + predict);
            }
            if (Input.GetKeyDown(KeyCode.KeypadMinus))
            {
                predict -= 0.01f;
                log("predict interval set to: " + predict);
            }

            /*     if (Input.GetKeyDown(KeyCode.Keypad5))
             *   {
             *       log("cameras:");
             *       foreach (Camera c in Camera.allCameras)
             *       {
             *           log("    " + c.name);
             *       }
             *   }*/

            if (Input.GetKeyDown(KeyCode.Keypad0) && HmdOn)
            {
                vrSystem.ResetSeatedZeroPose();
                log("Seated pose reset!");
            }

            if (Input.GetKeyDown(KeyCode.KeypadMultiply))
            {
                camLeft_Near.cullingMask  = camLeft_Near.cullingMask << 1;
                camRight_Near.cullingMask = camLeft_Near.cullingMask;
                log(Convert.ToString(camLeft_Near.cullingMask, 2));
                if (camLeft_Near.cullingMask == 0)
                {
                    camLeft_Near.cullingMask  = 1;
                    camRight_Near.cullingMask = 1;
                }
            }


            if (Input.GetKeyDown(KeyCode.KeypadDivide))
            {
                camLeft_Near.cullingMask  = camLeft_Near.cullingMask >> 1;
                camRight_Near.cullingMask = camLeft_Near.cullingMask;
                log(Convert.ToString(camLeft_Near.cullingMask, 2));
                if (camLeft_Near.cullingMask == 0)
                {
                    camLeft_Near.cullingMask  = 1;
                    camRight_Near.cullingMask = 1;
                }
            }
            if (Input.GetKeyDown(KeyCode.Keypad2))
            {
                log("          ScaledSpace rot = " + ScaledSpace.Instance.transform.rotation.eulerAngles.ToString());
                log("    GalaxyCubeControl rot = " + GalaxyCubeControl.Instance.transform.rotation.eulerAngles.ToString());
                log("GalaxyCubeControl tgt rot = " + GalaxyCubeControl.Instance.tgt.transform.rotation.eulerAngles.ToString());
                log("  GalaxyCameraControl rot = " + GalaxyCameraControl.Instance.transform.rotation.eulerAngles.ToString());
                log("         ScaledCamera rot = " + ScaledCamera.Instance.transform.rotation.eulerAngles.ToString());
            }

            if (HmdOn)
            {
                if (Input.GetKeyDown(KeyCode.Keypad1))
                {
                    log("L:" + Convert.ToString(camLeft_Near.cullingMask, 2));
                    log("R:" + Convert.ToString(camRight_Near.cullingMask, 2));
                }


                int tmp = 0;
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    tmp = 10;
                }
                else if (Input.GetKey(KeyCode.RightShift))
                {
                    tmp = 20;
                }
                else if (Input.GetKey(KeyCode.RightControl))
                {
                    tmp = 30;
                }

                if (Input.GetKeyDown(KeyCode.Alpha0))
                {
                    camLeft_Near.cullingMask ^= (1 << 0 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    camLeft_Near.cullingMask ^= (1 << 1 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    camLeft_Near.cullingMask ^= (1 << 2 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    camLeft_Near.cullingMask ^= (1 << 3 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    camLeft_Near.cullingMask ^= (1 << 4 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha5))
                {
                    camLeft_Near.cullingMask ^= (1 << 5 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha6))
                {
                    camLeft_Near.cullingMask ^= (1 << 6 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha7))
                {
                    camLeft_Near.cullingMask ^= (1 << 7 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha8))
                {
                    camLeft_Near.cullingMask ^= (1 << 8 + tmp);
                }
                if (Input.GetKeyDown(KeyCode.Alpha9))
                {
                    camLeft_Near.cullingMask ^= (1 << 9 + tmp);
                }
                camRight_Near.cullingMask = camLeft_Near.cullingMask;

                if (Input.GetKeyDown(KeyCode.Keypad7))
                {
                    if (camRight_Near.transparencySortMode == TransparencySortMode.Default)
                    {
                        camRight_Near.transparencySortMode = TransparencySortMode.Orthographic;
                        camLeft_Near.transparencySortMode  = TransparencySortMode.Orthographic;
                    }
                    if (camRight_Near.transparencySortMode == TransparencySortMode.Orthographic)
                    {
                        camRight_Near.transparencySortMode = TransparencySortMode.Perspective;
                        camLeft_Near.transparencySortMode  = TransparencySortMode.Perspective;
                    }
                    if (camRight_Near.transparencySortMode == TransparencySortMode.Perspective)
                    {
                        camRight_Near.transparencySortMode = TransparencySortMode.Default;
                        camLeft_Near.transparencySortMode  = TransparencySortMode.Default;
                    }
                }
                if (Input.GetKeyDown(KeyCode.Keypad8))
                {
                    if (camRight_Near.opaqueSortMode == UnityEngine.Rendering.OpaqueSortMode.Default)
                    {
                        camRight_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.FrontToBack;
                        camLeft_Near.opaqueSortMode  = UnityEngine.Rendering.OpaqueSortMode.FrontToBack;
                    }
                    if (camRight_Near.opaqueSortMode == UnityEngine.Rendering.OpaqueSortMode.FrontToBack)
                    {
                        camRight_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.NoDistanceSort;
                        camLeft_Near.opaqueSortMode  = UnityEngine.Rendering.OpaqueSortMode.NoDistanceSort;
                    }
                    if (camRight_Near.opaqueSortMode == UnityEngine.Rendering.OpaqueSortMode.NoDistanceSort)
                    {
                        camRight_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.Default;
                        camLeft_Near.opaqueSortMode  = UnityEngine.Rendering.OpaqueSortMode.Default;
                    }
                }
            }
            if (Input.GetKeyDown(KeyCode.Keypad0) && !HmdOn)
            {
                activeVessel = FlightGlobals.ActiveVessel;

                var goArray = FindObjectsOfType <GameObject>();

                /*GameObject tmp = new GameObject();
                 * tmp.transform.position = activeVessel.transform.position;
                 * tmp.transform.SetParent(activeVessel.transform);
                 * for (var i = 0; i < goArray.Length; i++)
                 * {
                 *  if (goArray[i].layer == 16 | goArray[i].layer == 20)
                 *  {
                 *      log(goArray[i].name);
                 *      //Vector3 tmp = goArray[i].transform.position;
                 *
                 *
                 *      goArray[i].transform.SetParent(tmp.transform);
                 *      interiorModelList.Add(goArray[i]);
                 *  }
                 * }
                 * tmp.transform.rotation = activeVessel.transform.rotation;
                 */
                HmdOn = true;
                log("TEST!!!!!!!!!!!!!!!!!!");
                log(ScaledSpace.Instance.transform.rotation.eulerAngles.ToString());
                //setup OpenVR
                setup();


                int    mask = 0;
                Camera pit  = Camera.main;


                uint renderTextureWidth  = 0;
                uint renderTextureHeight = 0;
                vrSystem.GetRecommendedRenderTargetSize(ref renderTextureWidth, ref renderTextureHeight);

                HmdMatrix34_t vrLeftEyeTransform  = vrSystem.GetEyeToHeadTransform(EVREye.Eye_Left);
                HmdMatrix34_t vrRightEyeTransform = vrSystem.GetEyeToHeadTransform(EVREye.Eye_Right);



                int widthDiference = (int)(Camera.main.WorldToScreenPoint(new Utils.RigidTransform(vrLeftEyeTransform).pos) - Camera.main.WorldToScreenPoint(new Utils.RigidTransform(vrRightEyeTransform).pos)).magnitude;
                widthDiference = 100; //TODO calculate corectly
                skyTexture     = new RenderTexture((int)(renderTextureWidth + widthDiference), (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32);
                skyTexture.Create();

                hmdLeftEyeRenderTexture = new RenderTexture((int)renderTextureWidth, (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32);
                hmdLeftEyeRenderTexture.Create();

                hmdRightEyeRenderTexture = new RenderTexture((int)renderTextureWidth, (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32);
                hmdRightEyeRenderTexture.Create();

                float max = 0;

                float[] distances = new float[32];

                foreach (string cameraName in cameraNamesToRender)
                {
                    foreach (Camera camera in Camera.allCameras)
                    {
                        if (cameraName.Equals(camera.name))
                        {
                            switch (camera.name)
                            {
                            case "GalaxyCamera":
                                O_Galaxy = camera;
                                break;

                            case "Camera ScaledSpace":
                                O_SclaledSpace = camera;
                                break;

                            case "Camera 01":
                                O_Far = camera;
                                break;

                            case "Camera 00":
                                O_Near = camera;
                                break;

                            default:
                                break;
                            }


                            mask |= camera.cullingMask;

                            max = Math.Max(camera.farClipPlane, max);
                            string bitMask = Convert.ToString(camera.cullingMask, 2);
                            for (int i = 0; i < distances.Length; i++)
                            {
                                distances[i] = Math.Max(distances[i], Math.Max(camera.layerCullDistances[i], camera.farClipPlane));
                            }

                            camera.gameObject.AddOrGetComponent <posTracker>();

                            log("Camera:");
                            log("  Name:  " + camera.name);
                            log("  mask:  " + Convert.ToString(camera.cullingMask, 2));
                            log("  depth: " + camera.depth);
                            log("");

                            if (cameraName.Equals("InternalCamera"))
                            {
                                pit          = camera;
                                camLeft_Near = camera;
                                //camRight = camera;
                                leftCameras.Add(camera);
                                O_Interior = camera;
                            }
                            if (cameraName.Equals("GalaxyCamera"))
                            {
                                O_Galaxy = camera;
                            }

                            if (cameraName.Equals("Camera ScaledSpace"))
                            {
                                //  sky = camera;
                                O_SclaledSpace = camera;
                                log("sky cam rot = " + camera.transform.rotation.eulerAngles.ToString());
                            }
                        }
                    }
                }

                //   camRight_Interior = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
                //   camLeft_Interior = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

                camRight_Near = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
                camLeft_Near  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

                camRight_Far = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
                camLeft_Far  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

                leftSky  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
                rightSky = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

                leftStars  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
                rightStars = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

                leftSky.CopyFrom(O_SclaledSpace);
                rightSky.CopyFrom(O_SclaledSpace);

                leftSky.transform.SetParent(activeVessel.transform);
                rightSky.transform.SetParent(activeVessel.transform);

                leftStars.CopyFrom(O_Galaxy);
                rightStars.CopyFrom(O_Galaxy);

                leftStars.transform.SetParent(activeVessel.transform);
                rightStars.transform.SetParent(activeVessel.transform);

                camRight_Near.CopyFrom(O_Near);
                camLeft_Near.CopyFrom(O_Near);

                camRight_Near.transform.SetParent(activeVessel.transform);
                camLeft_Near.transform.SetParent(activeVessel.transform);

                //     camLeft_Interior.CopyFrom(O_Interior);
                //     camRight_Interior.CopyFrom(O_Interior);

                //    camLeft_Interior.transform.SetParent(activeVessel.transform);
                //    camRight_Interior.transform.SetParent(activeVessel.transform);

                camRight_Far.CopyFrom(O_Far);
                camLeft_Far.CopyFrom(O_Far);

                camRight_Far.transform.SetParent(activeVessel.transform);
                camLeft_Far.transform.SetParent(activeVessel.transform);
                // stars.clearFlags = CameraClearFlags.Depth;
                // stars.cullingMask = (1 << 18);
                //sky.cullingMask = (1 << 9);
                leftStars.targetTexture  = hmdLeftEyeRenderTexture;
                rightStars.targetTexture = hmdRightEyeRenderTexture;
                //
                leftSky.targetTexture  = hmdLeftEyeRenderTexture;
                rightSky.targetTexture = hmdRightEyeRenderTexture;

                //skyCopySlave = rightSky.gameObject.AddComponent<copySlave>();
                // skyCopySlave.leftTarget = hmdLeftEyeRenderTexture;
                // skyCopySlave.rightTarget = hmdRightEyeRenderTexture;
                //skyCopySlave.difrence = widthDiference;

                camLeft_Near.targetTexture  = hmdLeftEyeRenderTexture;
                camRight_Near.targetTexture = hmdRightEyeRenderTexture;

                //   camLeft_Interior.targetTexture = hmdLeftEyeRenderTexture;
                //   camRight_Interior.targetTexture = hmdRightEyeRenderTexture;


                camLeft_Far.targetTexture  = hmdLeftEyeRenderTexture;
                camRight_Far.targetTexture = hmdRightEyeRenderTexture;

                leftStars.depth    += 4;
                leftSky.depth      += 4;
                camLeft_Near.depth += 4;
                camLeft_Far.depth  += 4;
                // camLeft_Interior.depth += 4;
                // camRight_Interior.depth += 4;
                //rightSky.depth = -5;
                //  camRight.targetTexture = sky.targetTexture;
                //  camLeft.targetTexture = sky.targetTexture;

                //   camera.targetTexture = hmdLeftEyeRenderTexture;
                //     camRight.cullingMask = (1 << 0) | (1 << 4) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 20) | (1 << 23);
                //    camLeft.cullingMask = (1 << 0) | (1 << 4) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 20) | (1 << 23);

                // 0: ship exterior
                //15: ground
                //16: ship interior

                //TODO change to |=
                //camRight_Near.cullingMask = 1 << 20 | (1 << 16);
                //camLeft_Near.cullingMask = 1 << 20 | (1 << 16);



                //  camLeft.clearFlags = CameraClearFlags.Depth;
                //  camRight.clearFlags = CameraClearFlags.Depth;

                // camLeft_Near.layerCullDistances = distances;
                // camRight_Near.layerCullDistances = distances;


                //  camLeft.depthTextureMode = DepthTextureMode.Depth;
                //  camRight.depthTextureMode = DepthTextureMode.Depth;
                //camRight.transparencySortMode = TransparencySortMode.Perspective;
                //create left slave
                leftSlave = camLeft_Near.gameObject.AddOrGetComponent <RenderSlave>();
                //leftSlave = sky.gameObject.AddOrGetComponent<RenderSlave>();
                leftSlave.left = true;
                // camLeft.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 18) | (1 << 20) | (1 << 23);
                //camLeft.cullingMask = (1 << 9) | (1 << 15) | (1 << 16) | (1 << 20) | (1 << 32);
                //camLeft.cullingMask = 0;
                //  camLeft.ResetCullingMatrix();
                //camLeft_Near.useOcclusionCulling = true;
                //camLeft_Near.nearClipPlane = 0.01f;
                //camLeft_Near.farClipPlane = max;

                //create right slave
                rightSlave      = camRight_Near.gameObject.AddOrGetComponent <RenderSlave>();
                rightSlave.left = false;
                // camRight.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 18) | (1 << 20) | (1 << 23);
                //   camRight.cullingMask = (1 << 9) | (1 << 15) | (1 << 16) | (1 << 20) | (1 << 32);
                //  camRight.cullingMask = 0;
                //camRight.ResetCullingMatrix();
                // camRight_Near.useOcclusionCulling = true;
                //
                // camRight_Near.nearClipPlane = 0.01f;
                // camRight_Near.farClipPlane = max;
                //set camera projections:


                //TODO rewrite
                HmdMatrix44_t projLeft  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Near.nearClipPlane, camLeft_Near.farClipPlane);
                HmdMatrix44_t projRight = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Near.nearClipPlane, camRight_Near.farClipPlane);

                camLeft_Near.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft);
                camRight_Near.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight);

                // HmdMatrix44_t projLeft2 = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Interior.nearClipPlane, camLeft_Interior.farClipPlane);
                // HmdMatrix44_t projRight2 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Interior.nearClipPlane, camRight_Interior.farClipPlane);
                //
                // camLeft_Interior.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft2);
                // camRight_Interior.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight2);

                HmdMatrix44_t projLeft3  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Far.nearClipPlane, camLeft_Far.farClipPlane);
                HmdMatrix44_t projRight3 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Far.nearClipPlane, camRight_Far.farClipPlane);

                camLeft_Far.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft3);
                camRight_Far.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight3);

                HmdMatrix44_t projLeft4  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, leftSky.nearClipPlane, leftSky.farClipPlane);
                HmdMatrix44_t projRight4 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, rightSky.nearClipPlane, rightSky.farClipPlane);

                leftSky.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft4);
                rightSky.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight4);

                HmdMatrix44_t projLeft5  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, leftStars.nearClipPlane, leftStars.farClipPlane);
                HmdMatrix44_t projRight5 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, rightStars.nearClipPlane, rightStars.farClipPlane);

                leftStars.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft5);
                rightStars.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight5);

                // camLeft_Interior.depth = 0;
                // camLeft_Interior.clearFlags = CameraClearFlags.Skybox;
                //    camLeft_Near.depth = 0;
                //    camLeft_Near.clearFlags = CameraClearFlags.Nothing;
                //    camLeft_Far.depth = -1;
                //    camLeft_Far.clearFlags = CameraClearFlags.Nothing;
                //    leftSky.depth = -2;
                //    leftSky.clearFlags = CameraClearFlags.Nothing;
                //    leftStars.depth = -3;
                //    leftStars.clearFlags = CameraClearFlags.Skybox;
                //   //
                //   // camRight_Interior.depth = 5;
                //   // camRight_Interior.clearFlags = CameraClearFlags.Skybox;
                //    camRight_Near.depth =0;
                //    camRight_Near.clearFlags = CameraClearFlags.Nothing;
                //    camRight_Far.depth = -1;
                //    camRight_Far.clearFlags = CameraClearFlags.Nothing;
                //    rightSky.depth = -2;
                //    rightSky.clearFlags = CameraClearFlags.Nothing;
                //    rightStars.depth = -3;
                //    rightStars.clearFlags = CameraClearFlags.Skybox;


                //activate slaves
                posTracker.HmdOn = true;
                leftSlave.HmdOn  = true;
                rightSlave.HmdOn = true;
            }
        }