Example #1
0
        public void OnPreRender()
        {
            ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles();

            if (handles.IsNull())
            {
                return;
            }

            if (!bCommandBufferInitialized)
            {
                InitializeCommandBuffer();
            }

            Resolution currentResolution = Screen.currentResolution;

            // Texture Y
            if (_videoTextureY == null)
            {
                _videoTextureY = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                                 TextureFormat.R8, false, false, (System.IntPtr)handles.TextureY);
                _videoTextureY.filterMode = FilterMode.Bilinear;
                _videoTextureY.wrapMode   = TextureWrapMode.Repeat;
                m_ClearMaterial.SetTexture("_textureY", _videoTextureY);
            }

            // Texture CbCr
            if (_videoTextureCbCr == null)
            {
                _videoTextureCbCr = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                                    TextureFormat.RG16, false, false, (System.IntPtr)handles.TextureCbCr);
                _videoTextureCbCr.filterMode = FilterMode.Bilinear;
                _videoTextureCbCr.wrapMode   = TextureWrapMode.Repeat;
                m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr);
            }

            _videoTextureY.UpdateExternalTexture(handles.TextureY);
            _videoTextureCbCr.UpdateExternalTexture(handles.TextureCbCr);

            m_ClearMaterial.SetMatrix("_DisplayTransform", _displayTransform);
            if (HologlaCameraManager.EyeMode.TwoEyes == UserSettings.eyeMode)
            {
                m_ClearMaterial.SetFloat("_widthRatio", 0.5f);
                m_ClearMaterial.SetFloat("_widthOffset", 0.25f);
            }
            else
            {
                m_ClearMaterial.SetFloat("_widthRatio", 1.0f);
                m_ClearMaterial.SetFloat("_widthOffset", 0.0f);
            }
        }
    void OnPreRender()
    {
        ARTextureHandles handles = ARKitManager.Instance.Session.GetARVideoTextureHandles();

        if (handles.IsNull())
        {
            return;
        }

        if (!bCommandBufferInitialized)
        {
            InitializeCommandBuffer();
        }

        Resolution currentResolution = Screen.currentResolution;

        // Texture Y
        if (_videoTextureY == null)
        {
            _videoTextureY = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                             TextureFormat.R8, false, false, (System.IntPtr)handles.TextureY);
            _videoTextureY.filterMode = FilterMode.Bilinear;
            _videoTextureY.wrapMode   = TextureWrapMode.Repeat;
            m_ClearMaterial.SetTexture("_textureY", _videoTextureY);
        }

        // Texture CbCr
        if (_videoTextureCbCr == null)
        {
            _videoTextureCbCr = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                                TextureFormat.RG16, false, false, (System.IntPtr)handles.TextureCbCr);
            _videoTextureCbCr.filterMode = FilterMode.Bilinear;
            _videoTextureCbCr.wrapMode   = TextureWrapMode.Repeat;
            m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr);
        }

        _videoTextureY.UpdateExternalTexture(handles.TextureY);
        _videoTextureCbCr.UpdateExternalTexture(handles.TextureCbCr);

        m_ClearMaterial.SetMatrix("_DisplayTransform", _displayTransform);
    }