Exemplo n.º 1
0
    void setQuadToCameraCorners(Mesh mesh, Camera cam, Camera.MonoOrStereoscopicEye eye)
    {
        Vector3[] nearPlaneCorners = new Vector3[4]; // camera returns corners in view space

        // NOTE: attaching the render plane at nearClipPlane distance leads to mis-alignment of bounding boxes and thus incorret stereo rendering.
        // this is probably due to the non-skewed projection matrices used for rendering in MegaMol.
        // until we can use the skewed VR-Projection-Matrices, use a small offset when setting the render plane.
        cam.CalculateFrustumCorners(new Rect(0, 0, 1, 1), cam.nearClipPlane + 0.32f, eye, nearPlaneCorners);
        mesh.vertices = nearPlaneCorners;

        Vector2[] uvCoords = new Vector2[4] {
            new Vector2(0.0f, 0.0f), new Vector2(0.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(1.0f, 0.0f)
        };
        mesh.uv = uvCoords;

        int[] indices = new int[6] {
            0, 1, 2, 0, 2, 3
        };
        mesh.SetIndices(indices, MeshTopology.Triangles, 0);

        // fixes disappearing of mesh when looked at from certain angles
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        mesh.RecalculateTangents();
    }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the camera's World space to Clip space matrix
        /// </summary>
        /// <param name="nearClipPlane">The near clip plane</param>
        /// <param name="farClipPlane">The far clip plane</param>
        /// <param name="matrixToFill">The allocated matrix object to write into</param>
        public static void GetWorldToClipMatrix(this Camera cameraComponent, Camera.MonoOrStereoscopicEye eye, float nearClipPlane, float farClipPlane, ref Matrix4x4 matrixToFill)
        {
            float tmpNear = cameraComponent.nearClipPlane;

            cameraComponent.nearClipPlane = nearClipPlane;
            float tmpFar = cameraComponent.farClipPlane;

            cameraComponent.farClipPlane = farClipPlane;

            Matrix4x4 worldToCameraMatrix = cameraComponent.worldToCameraMatrix;
            Matrix4x4 projectionMatrix    = cameraComponent.GetProjectionMatrix(eye);

            matrixToFill = projectionMatrix * worldToCameraMatrix; // worldToClipMatrix

            if (cameraComponent.orthographic)
            {
                matrixToFill[2, 0] = -worldToCameraMatrix[2, 0];
                matrixToFill[2, 1] = -worldToCameraMatrix[2, 1];
                matrixToFill[2, 2] = -worldToCameraMatrix[2, 2];
                matrixToFill[2, 3] = -worldToCameraMatrix[2, 3];
            }

            cameraComponent.nearClipPlane = tmpNear;
            cameraComponent.farClipPlane  = tmpFar;
        }
Exemplo n.º 3
0
        private void SaveFrameData(Camera.MonoOrStereoscopicEye eye)
        {
            switch (eye)
            {
            case Camera.MonoOrStereoscopicEye.Right:
                if (_previousFrameData.rightEyeTexture)
                {
                    RenderTexture.ReleaseTemporary(_previousFrameData.rightEyeTexture);
                }
                _camera.ResetProjectionMatrix();
                _previousFrameData.rightEyeProjectionMatrix    = _camera.projectionMatrix;
                _previousFrameData.rightEyeWorldToCameraMatrix = _camera.worldToCameraMatrix;
                _previousFrameData.rightEyeTexture             = _camera.targetTexture;
                break;

            case Camera.MonoOrStereoscopicEye.Left:
            case Camera.MonoOrStereoscopicEye.Mono:
            default:
                if (_previousFrameData.leftEyeTexture)
                {
                    RenderTexture.ReleaseTemporary(_previousFrameData.leftEyeTexture);
                }
                // Need to restore original projection matrix for rendering fake recursion
                _camera.ResetProjectionMatrix();
                _previousFrameData.leftEyeProjectionMatrix    = _camera.projectionMatrix;
                _previousFrameData.leftEyeWorldToCameraMatrix = _camera.worldToCameraMatrix;
                _previousFrameData.leftEyeTexture             = _camera.targetTexture;
                break;
            }
        }
Exemplo n.º 4
0
        private static Matrix4x4 CalculateReflectionMatrix(Vector4 plane, Camera.MonoOrStereoscopicEye eye = Camera.MonoOrStereoscopicEye.Mono)
        {
            Matrix4x4 reflectionMat = new Matrix4x4();

            reflectionMat.m00 = (1F - 2F * plane[0] * plane[0]);
            reflectionMat.m01 = (-2F * plane[0] * plane[1]);
            reflectionMat.m02 = (-2F * plane[0] * plane[2]);
            reflectionMat.m03 = (-2F * plane[3] * plane[0]);

            reflectionMat.m10 = (-2F * plane[1] * plane[0]);
            reflectionMat.m11 = (1F - 2F * plane[1] * plane[1]);
            reflectionMat.m12 = (-2F * plane[1] * plane[2]);
            reflectionMat.m13 = (-2F * plane[3] * plane[1]);

            reflectionMat.m20 = (-2F * plane[2] * plane[0]);
            reflectionMat.m21 = (-2F * plane[2] * plane[1]);
            reflectionMat.m22 = (1F - 2F * plane[2] * plane[2]);
            reflectionMat.m23 = (-2F * plane[3] * plane[2]);

            reflectionMat.m30 = 0F;
            reflectionMat.m31 = 0F;
            reflectionMat.m32 = 0F;
            reflectionMat.m33 = 1F;

            //reflectionMat = Matrix4x4.Translate(new Vector3(float0, 0, 0))*reflectionMat ;

            return(reflectionMat);
        }
    //void OnPreRender()
    void OnRenderObject()
    {
        Camera.MonoOrStereoscopicEye currentEye = cam.stereoActiveEye;

        Matrix4x4 camPose = cam.worldToCameraMatrix;


        Debug.Log(currentEye);
        switch (currentEye)
        {
        case Camera.MonoOrStereoscopicEye.Left:
        case Camera.MonoOrStereoscopicEye.Mono:
            ARMaterial.SetTexture(ARMaterialTexName, LeftCameraImage);

            //  cam.SetStereoProjectionMatrix(Camera.StereoscopicEye.Left, LeftEye.projectionMatrix);

            Matrix4x4 viewLeft = new Matrix4x4();
            viewLeft.SetTRS(LeftEye.transform.localPosition, LeftEye.transform.localRotation, Vector3.one);
            // cam.SetStereoViewMatrix(Camera.StereoscopicEye.Left, viewLeft * camPose);

            break;

        case Camera.MonoOrStereoscopicEye.Right:
            ARMaterial.SetTexture(ARMaterialTexName, RightCameraImage);

            // cam.SetStereoProjectionMatrix(Camera.StereoscopicEye.Right, RightEye.projectionMatrix);

            Matrix4x4 viewRight = new Matrix4x4();
            viewRight.SetTRS(RightEye.transform.localPosition, RightEye.transform.localRotation, Vector3.one);
            // cam.SetStereoViewMatrix(Camera.StereoscopicEye.Right, viewRight * camPose);
            break;
        }
    }
Exemplo n.º 6
0
    // MONOBEHAVIOUR.
    private void OnRenderObject()
    {
        // Check and make sure to only render particles once per camera/eye.

        Camera.MonoOrStereoscopicEye activeEye = Camera.current.stereoActiveEye;

        if (!sRenderedCameraDictionary.ContainsKey(Camera.current))
        {
            Dictionary <Camera.MonoOrStereoscopicEye, Camera.MonoOrStereoscopicEye> activeEyeDictionary = new Dictionary <Camera.MonoOrStereoscopicEye, Camera.MonoOrStereoscopicEye>();
            sRenderedCameraDictionary[Camera.current] = activeEyeDictionary;
        }

        if (!sRenderedCameraDictionary[Camera.current].ContainsKey(activeEye))
        {
            // Add camera to dictionary so we only render system once per camera.
            sRenderedCameraDictionary[Camera.current][activeEye] = activeEye;

            // Merge particle buffers.
            Merge();

            // Sort particles.
            Sort();

            // Render this frame.
            RenderSystem();
        }
    }
    public RenderTexture GetRT(Camera.MonoOrStereoscopicEye eye)
    {
#if USE_2RT
        return((eye == Camera.MonoOrStereoscopicEye.Left) ? ColorDepthLRT[delayFrame] : ColorDepthRRT[delayFrame]);
#else
        return(ColorDepthLRT[delayFrame]);
#endif
    }
Exemplo n.º 8
0
    public static bool WorldToViewportPointV3Eye(Camera camera, Vector3 pt, Camera.MonoOrStereoscopicEye eye, out float ox, out float oy, out float oz)
    {
        var v3 = camera.WorldToViewportPoint(pt, eye);

        ox = v3.x;
        oy = v3.y;
        oz = v3.z;
        return(true);
    }
Exemplo n.º 9
0
    static int ConvertToEquirect(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        RenderTexture obj  = (RenderTexture)LuaScriptMgr.GetUnityObjectSelf(L, 1, "RenderTexture");
        RenderTexture arg0 = (RenderTexture)LuaScriptMgr.GetUnityObject(L, 2, typeof(RenderTexture));

        Camera.MonoOrStereoscopicEye arg1 = (Camera.MonoOrStereoscopicEye)LuaScriptMgr.GetNetObject(L, 3, typeof(Camera.MonoOrStereoscopicEye));
        obj.ConvertToEquirect(arg0, arg1);
        return(0);
    }
Exemplo n.º 10
0
        /// <summary>
        /// Gets a point with the same screen point as the source point,
        /// but at the specified distance from camera.
        /// </summary>
        public static Vector3 WorldPointOffsetByDepth(this Camera camera,
                                                      Vector3 source,
                                                      float distanceFromCamera,
                                                      Camera.MonoOrStereoscopicEye eye = Camera.MonoOrStereoscopicEye.Mono)
        {
            var screenPoint = camera.WorldToScreenPoint(source, eye);

            return(camera.ScreenToWorldPoint(screenPoint.SetZ(distanceFromCamera),
                                             eye));
        }
Exemplo n.º 11
0
 /// <summary>
 /// Gets the projection matrix of the camera
 /// </summary>
 /// <param name="eye">The stereoscopic eye</param>
 /// <returns></returns>
 public static Matrix4x4 GetProjectionMatrix(this Camera camera, Camera.MonoOrStereoscopicEye eye)
 {
     if (eye == Camera.MonoOrStereoscopicEye.Mono)
     {
         return(camera.projectionMatrix);
     }
     else
     {
         return(camera.GetStereoProjectionMatrix((Camera.StereoscopicEye)eye));
     }
 }
Exemplo n.º 12
0
    public static bool ViewportPointToRayV2Eye(Camera camera, Vector2 pt, Camera.MonoOrStereoscopicEye eye, out float ox, out float oy, out float oz, out float dx, out float dy, out float dz)
    {
        var ray = camera.ViewportPointToRay(pt, eye);

        ox = ray.origin.x;
        oy = ray.origin.y;
        oz = ray.origin.z;
        dx = ray.direction.x;
        dy = ray.direction.y;
        dz = ray.direction.z;
        return(true);
    }
Exemplo n.º 13
0
    Vector2 GetScreenPoint(Vector3 eyePos, Vector3 localDirection, Camera.MonoOrStereoscopicEye eye)
    {
        Vector3 pos       = cameraTransform.TransformPoint(eyePos);
        Vector3 direction = cameraTransform.TransformDirection(localDirection);

        Vector2 point = camera.WorldToScreenPoint(pos + direction, eye);

        point.x /= camera.pixelWidth;
        point.y /= camera.pixelHeight;

        return(point);
    }
Exemplo n.º 14
0
 public void CalculateFrustumCorners(Rect viewport, float z, Camera.MonoOrStereoscopicEye eye, Vector3[] outCorners)
 {
     if (outCorners == null)
     {
         throw new ArgumentNullException("outCorners");
     }
     if (outCorners.Length < 4)
     {
         throw new ArgumentException("outCorners minimum size is 4", "outCorners");
     }
     this.CalculateFrustumCornersInternal(viewport, z, eye, outCorners);
 }
Exemplo n.º 15
0
    static Matrix4x4 FrustumCornersMatrix(Camera cam, Camera.MonoOrStereoscopicEye eye)
    {
        var camtr = cam.transform;

        cam.CalculateFrustumCorners(new Rect(0, 0, 1, 1), cam.farClipPlane, eye, frustumCorners);

        Matrix4x4 frustumMatrix = Matrix4x4.identity;

        frustumMatrix.SetRow(0, camtr.TransformVector(frustumCorners[0]));
        frustumMatrix.SetRow(1, camtr.TransformVector(frustumCorners[3]));
        frustumMatrix.SetRow(2, camtr.TransformVector(frustumCorners[1]));
        frustumMatrix.SetRow(3, camtr.TransformVector(frustumCorners[2]));
        return(frustumMatrix);
    }
Exemplo n.º 16
0
        /// <summary>
        /// Computes the corners of the plane parallel to the camera at given distance
        /// </summary>
        /// <param name="eye">The stereoscopic eye</param>
        /// <param name="planeDistance">The reference distance</param>
        /// <param name="planeCornersArray">The array to fill with the four corners of the intersecting plane</param>
        public static void GetFrustumPlaneCorners(this Camera camera, Camera.MonoOrStereoscopicEye eye, float planeDistance, ref Vector4[] planeCornersArray)
        {
            camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), planeDistance, eye, _tmpRetrievedFrustumPlaneCornersArray);
            for (int i = 0; i < 4; ++i)
            {
                _tmpRetrievedFrustumPlaneCornersArray[i] = camera.transform.localToWorldMatrix.MultiplyPoint(_tmpRetrievedFrustumPlaneCornersArray[i]);
            }

            Vector3 tmp = _tmpRetrievedFrustumPlaneCornersArray[0];

            planeCornersArray[0] = new Vector4(_tmpRetrievedFrustumPlaneCornersArray[1].x, _tmpRetrievedFrustumPlaneCornersArray[1].y, _tmpRetrievedFrustumPlaneCornersArray[1].z, 1.0f);
            planeCornersArray[1] = new Vector4(_tmpRetrievedFrustumPlaneCornersArray[2].x, _tmpRetrievedFrustumPlaneCornersArray[2].y, _tmpRetrievedFrustumPlaneCornersArray[2].z, 1.0f);
            planeCornersArray[2] = new Vector4(_tmpRetrievedFrustumPlaneCornersArray[3].x, _tmpRetrievedFrustumPlaneCornersArray[3].y, _tmpRetrievedFrustumPlaneCornersArray[3].z, 1.0f);
            planeCornersArray[3] = new Vector4(tmp.x, tmp.y, tmp.z, 1.0f);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Returns the camera's World space to Clip space matrix
        /// </summary>
        /// <param name="nearClipPlane">The near clip plane</param>
        /// <param name="farClipPlane">The far clip plane</param>
        /// <returns>The camera's World space to Clip space matrix</returns>
        public static Matrix4x4 GetWorldToClipMatrix(this Camera cameraComponent, Camera.MonoOrStereoscopicEye eye, float nearClipPlane, float farClipPlane)
        {
            float tmpNear = cameraComponent.nearClipPlane;

            cameraComponent.nearClipPlane = nearClipPlane;
            float tmpFar = cameraComponent.farClipPlane;

            cameraComponent.farClipPlane = farClipPlane;

            Matrix4x4 worldToCameraMatrix = cameraComponent.worldToCameraMatrix;
            Matrix4x4 projectionMatrix    = cameraComponent.GetProjectionMatrix(eye);
            Matrix4x4 worldToClipMatrix   = projectionMatrix * worldToCameraMatrix;

            cameraComponent.nearClipPlane = tmpNear;
            cameraComponent.farClipPlane  = tmpFar;

            return(worldToClipMatrix);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Computes the corners of the plane parallel to the camera at given distance
        /// </summary>
        /// <param name="eye">The stereoscopic eye</param>
        /// <param name="planeDistance">The reference distance</param>
        /// <returns>the four corners of the intersecting plane</returns>
        public static Vector4[] GetFrustumPlaneCorners(this Camera camera, Camera.MonoOrStereoscopicEye eye, float planeDistance)
        {
            Vector3[] tmpArray = new Vector3[4];
            camera.CalculateFrustumCorners(/*camera.rect*/ new Rect(0, 0, 1, 1), planeDistance, eye, tmpArray);
            for (int i = 0; i < 4; ++i)
            {
                tmpArray[i] = camera.transform.localToWorldMatrix.MultiplyPoint(tmpArray[i]);
            }

            Vector4[] planeCorners = new Vector4[4];
            Vector3   tmp          = tmpArray[0];

            planeCorners[0] = new Vector4(tmpArray[1].x, tmpArray[1].y, tmpArray[1].z, 1.0f);
            planeCorners[1] = new Vector4(tmpArray[2].x, tmpArray[2].y, tmpArray[2].z, 1.0f);
            planeCorners[2] = new Vector4(tmpArray[3].x, tmpArray[3].y, tmpArray[3].z, 1.0f);
            planeCorners[3] = new Vector4(tmp.x, tmp.y, tmp.z, 1.0f);

            return(planeCorners);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Computes the world space frustum's corners' position
        /// </summary>
        /// <param name="nearClipDistance">The desired near plane</param>
        /// <param name="farClipDistance">The desired far plane</param>
        /// <param name="floatsArrayToFill">The floats array to fill with the the positions</param>
        public static void GetFrustumCorners(this Camera camera, Camera.MonoOrStereoscopicEye eye, float nearClipDistance, float farClipDistance, ref float[] floatsArrayToFill)
        {
            camera.GetFrustumPlaneCorners(eye, nearClipDistance, ref _tmpNearPlaneCornersArray);
            for (int i = 0; i < 4; ++i)
            {
                floatsArrayToFill[i * 4]     = _tmpNearPlaneCornersArray[i].x;
                floatsArrayToFill[i * 4 + 1] = _tmpNearPlaneCornersArray[i].y;
                floatsArrayToFill[i * 4 + 2] = _tmpNearPlaneCornersArray[i].z;
                floatsArrayToFill[i * 4 + 3] = _tmpNearPlaneCornersArray[i].w;
            }

            camera.GetFrustumPlaneCorners(eye, farClipDistance, ref _tmpFarPlaneCornersArray);
            for (int i = 0; i < 4; ++i)
            {
                floatsArrayToFill[16 + i * 4]     = _tmpFarPlaneCornersArray[i].x;
                floatsArrayToFill[16 + i * 4 + 1] = _tmpFarPlaneCornersArray[i].y;
                floatsArrayToFill[16 + i * 4 + 2] = _tmpFarPlaneCornersArray[i].z;
                floatsArrayToFill[16 + i * 4 + 3] = _tmpFarPlaneCornersArray[i].w;
            }
        }
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        Camera.MonoOrStereoscopicEye eyeSide = currentCamera.stereoActiveEye;

        RenderWithARDepthMaterial.SetFloat("_CullingBaise", CullingBaise);

        RenderWithARDepthMaterial.SetTexture("_MRDepthNormal", MRDepthNormal);
        RenderWithARDepthMaterial.SetTexture("_SeeThroughColor", (eyeSide == Camera.MonoOrStereoscopicEye.Left) ? seeThroughL.GetRT() : seeThroughR.GetRT());
        RenderWithARDepthMaterial.SetTexture("_VRDepthColor", VRCamera.GetRT(eyeSide));
        //RenderWithMRDepthMaterial.SetTexture("_VRDepth", VRCamera.DepthRT);
        RenderWithARDepthMaterial.SetFloat("_softCullLength", softCullLength);
        //   RenderWithMRDepthMaterial.SetFloat("_softCullFactor", softCullFactor);

        RenderWithARDepthMaterial.SetFloat("_GlowAmount", glowAmount);
        RenderWithARDepthMaterial.SetFloat("_CoefAmount", coefAmount);

        RenderWithARDepthMaterial.SetTexture("_SoftCullingMap", softEdgeWeight.SoftEdgeWeightRT);

        Graphics.Blit(source, destination, RenderWithARDepthMaterial);
    }
 public void StartFrame()
 {
     this.textureDimensionChanged = this.UpdateFrameDimensions();
     Camera.MonoOrStereoscopicEye stereoActiveEye = this.myCam.get_stereoActiveEye();
     if (stereoActiveEye != 2)
     {
         if (stereoActiveEye != null)
         {
             if (stereoActiveEye != 1)
             {
                 return;
             }
             this.projection      = this.myCam.GetStereoProjectionMatrix((Camera.StereoscopicEye) 1);
             this.rotation        = this.myCam.GetStereoViewMatrix((Camera.StereoscopicEye) 1);
             this.inverseRotation = ((Matrix4x4) ref this.rotation).get_inverse();
         }
         else
         {
             this.projection      = this.myCam.GetStereoProjectionMatrix((Camera.StereoscopicEye) 0);
             this.rotation        = this.myCam.GetStereoViewMatrix((Camera.StereoscopicEye) 0);
             this.inverseRotation = ((Matrix4x4) ref this.rotation).get_inverse();
             if (!EnviroSky.instance.singlePassVR)
             {
                 return;
             }
             this.projectionSPVR      = this.myCam.GetStereoProjectionMatrix((Camera.StereoscopicEye) 1);
             this.rotationSPVR        = this.myCam.GetStereoViewMatrix((Camera.StereoscopicEye) 1);
             this.inverseRotationSPVR = ((Matrix4x4) ref this.rotationSPVR).get_inverse();
         }
     }
     else
     {
         if (this.resetCameraProjection)
         {
             this.myCam.ResetProjectionMatrix();
         }
         this.projection      = this.myCam.get_projectionMatrix();
         this.rotation        = this.myCam.get_worldToCameraMatrix();
         this.inverseRotation = this.myCam.get_cameraToWorldMatrix();
     }
 }
        private void CalculateFrustumAABB(out Vector3 min, out Vector3 max)
        {
            const Camera.MonoOrStereoscopicEye eye = Camera.MonoOrStereoscopicEye.Mono;

            _camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), _camera.nearClipPlane, eye, _frustumBuffer);
            min = max = _cameraTransform.TransformPoint(_frustumBuffer[0]);
            for (int i = 1; i < 4; ++i)
            {
                Vector3 testPoint = _cameraTransform.TransformPoint(_frustumBuffer[i]);
                min = Vector3.Min(min, testPoint);
                max = Vector3.Max(max, testPoint);
            }

            _camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), _camera.farClipPlane, eye, _frustumBuffer);
            for (int i = 0; i < 4; ++i)
            {
                Vector3 testPoint = _cameraTransform.TransformPoint(_frustumBuffer[i]);
                min = Vector3.Min(min, testPoint);
                max = Vector3.Max(max, testPoint);
            }
        }
Exemplo n.º 23
0
        private void OnPreRenderCamera(Camera currentCamera)
        {
            if (!enabled)
            {
                return;
            }

            UpdateCameraSettings(currentCamera);

            Camera.MonoOrStereoscopicEye activeEye = currentCamera.stereoActiveEye;

            if (activeEye == Camera.MonoOrStereoscopicEye.Left ||
                activeEye == Camera.MonoOrStereoscopicEye.Mono)
            {
                RenderReflectionForEye(leftTextureId, currentCamera);
            }
            else if (activeEye == Camera.MonoOrStereoscopicEye.Right)
            {
                RenderReflectionForEye(rightTextureId, currentCamera);
            }
        }
Exemplo n.º 24
0
 public bool RenderToCubemap(RenderTexture cubemap, int faceMask, Camera.MonoOrStereoscopicEye stereoEye)
 {
     return(this.RenderToCubemapImpl(cubemap, faceMask, stereoEye));
 }
Exemplo n.º 25
0
 extern public void ConvertToEquirect(RenderTexture equirect, Camera.MonoOrStereoscopicEye eye = Camera.MonoOrStereoscopicEye.Mono);
Exemplo n.º 26
0
        public RenderTexture RenderToTexture(Camera.MonoOrStereoscopicEye eye, Rect viewportRect, bool renderBackface)
        {
            _framesSinceLastUse = 0;

            // Copy parent camera's settings
            CopyCameraSettings(_parent, _camera);
            //_camera.farClipPlane = _parent.farClipPlane * _portal.PortalScaleAverage();

            Matrix4x4 projectionMatrix;
            Matrix4x4 worldToCameraMatrix;

            switch (eye)
            {
            case Camera.MonoOrStereoscopicEye.Left:
                projectionMatrix    = _parent.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
                worldToCameraMatrix = _parent.GetStereoViewMatrix(Camera.StereoscopicEye.Left);
                break;

            case Camera.MonoOrStereoscopicEye.Right:
                projectionMatrix    = _parent.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
                worldToCameraMatrix = _parent.GetStereoViewMatrix(Camera.StereoscopicEye.Right);
                break;

            case Camera.MonoOrStereoscopicEye.Mono:
            default:
                projectionMatrix    = _parent.projectionMatrix;
                worldToCameraMatrix = _parent.worldToCameraMatrix;
                break;
            }
            _camera.transform.position = _portal.TeleportPoint(_parent.transform.position);
            _camera.transform.rotation = _portal.TeleportRotation(_parent.transform.rotation);
            _camera.projectionMatrix   = projectionMatrix;
            //_camera.worldToCameraMatrix = worldToCameraMatrix * _portal.PortalMatrix().inverse;
            _camera.ResetWorldToCameraMatrix();

            Matrix4x4 defaultProjection = _camera.projectionMatrix;

            if (_portal.UseObliqueProjectionMatrix)
            {
                _camera.ResetProjectionMatrix();
                _camera.projectionMatrix = CalculateObliqueProjectionMatrix(projectionMatrix);
            }
            else
            {
                _camera.ResetProjectionMatrix();
            }

            if (_portal.UseScissorRect)
            {
                _camera.rect             = viewportRect;
                _camera.projectionMatrix = MathUtil.ScissorsMatrix(_camera.projectionMatrix, viewportRect);
            }
            else
            {
                _camera.rect = new Rect(0, 0, 1, 1);
            }

            if (_portal.UseOcclusionMatrix)
            {
                _camera.cullingMatrix = CalculateCullingMatrix();
            }
            else
            {
                _camera.cullingMatrix = _camera.projectionMatrix * _camera.worldToCameraMatrix;
            }

            if (_portal.DebuggingEnabled)
            {
                //Util.DrawDebugFrustum3(_camera.projectionMatrix * _camera.worldToCameraMatrix, Color.white);

                if (_portal.UseOcclusionMatrix)
                {
                    Util.DrawDebugFrustum3(_camera.cullingMatrix, Color.blue);
                }
            }


            if (_portal.UseRaycastOcclusion)
            {
                _camera.useOcclusionCulling = false;
            }

            RenderTexture texture = GetTemporaryRT();

            if (_portal.FakeInfiniteRecursion)
            {
                // RenderTexture must be cleared when using fake infinite recursion because
                // we might sometimes sample uninitialized garbage pixels otherwise, which can
                // cause significant visual artifacts.
                ClearRenderTexture(texture);
            }

            _camera.targetTexture = texture;
            _camera.Render();

            SaveFrameData(eye);

            return(texture);
        }
Exemplo n.º 27
0
 private void CalculateFrustumCornersInternal(Rect viewport, float z, Camera.MonoOrStereoscopicEye eye, [Out] Vector3[] outCorners)
 {
     this.CalculateFrustumCornersInternal_Injected(ref viewport, z, eye, outCorners);
 }
Exemplo n.º 28
0
 private extern bool RenderToCubemapImpl(RenderTexture cubemap, int faceMask, Camera.MonoOrStereoscopicEye stereoEye);
Exemplo n.º 29
0
 private static extern void INTERNAL_CALL_CalculateFrustumCornersInternal(Camera self, ref Rect viewport, float z, Camera.MonoOrStereoscopicEye eye, Vector3[] outCorners);
Exemplo n.º 30
0
 private void CalculateFrustumCornersInternal(Rect viewport, float z, Camera.MonoOrStereoscopicEye eye, Vector3[] outCorners)
 {
     Camera.INTERNAL_CALL_CalculateFrustumCornersInternal(this, ref viewport, z, eye, outCorners);
 }