public void Instantiate(Portal portal)
    {
        _portal    = portal;
        _cameraLib = _portal.PortalCamera.GetComponent <SKSRenderLib>();

        GameObject cameraParent = new GameObject();

        cameraParent.transform.parent        = portal.PortalCamera.RenderingCameraParent;
        cameraParent.transform.localPosition = Vector3.zero;
        cameraParent.transform.localRotation = Quaternion.identity;

        _camera              = cameraParent.AddComponent <Camera>();
        _camera.cullingMask &= ~(1 << LayerMask.NameToLayer("Portal"));
        _camera.cullingMask &= ~(1 << LayerMask.NameToLayer("PortalPlaceholder"));
        _camera.name         = "Portal Placeholder Camera";
        _camera.enabled      = false;

        placeholderTex = new RenderTexture(100, 100, 24, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Default);
    }
        private void OnWillRenderObject()
        {
#if UNITY_EDITOR
            if (!(Selection.activeGameObject == gameObject))
            {
                return;
            }

            if (!TargetController || !PortalMaterial ||
                !Mask || !SKSGlobalRenderSettings.Preview ||
                !this || Application.isPlaying)
            {
                //CleanupTemp();
                return;
            }

            MeshRenderer previewRenderer = PreviewRoot.GetComponent <MeshRenderer>();
            previewRenderer.sharedMaterial = PortalMaterial;
            //previewRenderer.enabled = true;

            SKSRenderLib lib = PreviewCamera.GetComponent <SKSRenderLib>();
            PreviewCamera.transform.localPosition = Vector3.zero;

            Camera sceneCam = SceneView.GetAllSceneCameras()[0];

            Camera cam = PreviewCamera;


            GL.Clear(true, true, Color.black);
            Graphics.SetRenderTarget(null);

            RenderProperties renderProps = new RenderProperties();

            //renderState |= RenderState.FirstRender;
            renderProps |= RenderProperties.Optimize;
            renderProps |= SKSGlobalRenderSettings.Inverted ? RenderProperties.InvertedCached : 0;
            renderProps |= !SKSGlobalRenderSettings.UvFlip ? RenderProperties.UvFlipCached : 0;
            renderProps |= RenderProperties.ObliquePlane;
            renderProps |= RenderProperties.FirstRender;
            renderProps |= RenderProperties.RipCustomSkybox;

            MeshRenderer rend  = GetComponent <MeshRenderer>();
            MeshRenderer rend2 = TargetController.GetComponent <MeshRenderer>();
            Mesh         mesh  = PreviewRoot.GetComponent <MeshFilter>().sharedMesh;
            //TargetController.PreviewRoot.GetComponent<MeshRenderer>().enabled = false;
            //TargetController.GetComponent<MeshRenderer>().enabled = false;
            cam.transform.localPosition = Vector3.zero;
            TargetController.PreviewRoot.transform.localPosition = Vector3.zero;

            cam.transform.rotation = TargetController.PreviewRoot.transform.rotation *
                                     (Quaternion.Inverse(transform.rotation) *
                                      (sceneCam.transform.rotation));

            TargetController.PreviewRoot.transform.localScale = Vector3.one;

            if (renderData == null)
            {
                renderData = new RenderData(renderProps, cam, sceneCam,
                                            sceneCam.transform.position, sceneCam.projectionMatrix, "_RightEyeTexture",
                                            PortalMaterial, new Vector2(Screen.currentResolution.width,
                                                                        Screen.currentResolution.height), previewRenderer, rend2, mesh, 1, 0, false, false);
            }
            else
            {
                renderData.Position         = sceneCam.transform.position;
                renderData.ProjectionMatrix = sceneCam.projectionMatrix;
                renderData.ScreenSize       = new Vector2(Screen.currentResolution.width,
                                                          Screen.currentResolution.height);
                renderData.RenderingCamera = PreviewCamera;
                renderData.SourceRenderer  = previewRenderer;
            }

            lib.RenderCamera(renderData);

            MaterialPropertyBlock block = new MaterialPropertyBlock();
            previewRenderer.GetPropertyBlock(block);
            RenderTexture output = (RenderTexture)block.GetTexture("_RightEyeTexture");
            //RenderTexture cachedOutput = RenderTexture.GetTemporary(output.width, output.height, output.depth, output.format);
            //cachedOutput.Create();
            //texturesToDispose.Add(cachedOutput);
            //Graphics.CopyTexture(output, cachedOutput);
            if (output)
            {
                previewRenderer.sharedMaterial.SetTexture("_RightEyeTexture", output);
            }
            if (output)
            {
                previewRenderer.sharedMaterial.SetTexture("_LeftEyeTexture", output);
            }
            if (output)
            {
                block.SetTexture("_LeftEyeTexture", output);
            }
            //PortalController.PortalMaterial.SetVector("_LeftDrawPos", PortalController.PortalMaterial.GetVector("_RightDrawPos"));

            Graphics.SetRenderTarget(null);
            lib.TerminateRender();
#endif
        }