// Update is called once per frame void Update() { if (!done) { ARTextureHandles handles = arSession.GetARVideoTextureHandles(); if (handles.textureY != System.IntPtr.Zero) { ReadQRCode(handles.textureY.ToInt64()); } } }
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); } }
public override void UpdateCamera(Camera camera) { camera.projectionMatrix = nativeInterface.GetCameraProjection(); if (!m_BackgroundRendering) { return; } ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles(); if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero) { m_CanRenderBackground = false; return; } m_CanRenderBackground = true; BackgroundRendering = m_BackgroundRendering; 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", m_DisplayTransform); }
private void Update() { // We only classify a new image if no other vision requests are in progress if (_vision.InProgress) { return; } // Use the Y plane of the YCbCr texture to render the current camera frame. ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles(); if (handles.textureY != System.IntPtr.Zero) { // This is the call where we pass in the handle to the metal texture to be analysed _vision.EvaluateBuffer(handles.textureY, ImageDataType.MetalTexture); } }
private void Update() { // We only classify a new image if no other vision requests are in progress if (_vision.InProgress) { return; } // Instead of using ARKit's capturedImage (CVPixelBuffer), like we did in the first example, // this time we use the Y plane of the YCbCr texture Unity uses to render the current camera frame. ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles(); if (handles.textureY != System.IntPtr.Zero) { // This is the call where we pass in the handle to the metal texture to be analysed _vision.EvaluateBuffer(handles.textureY, ImageDataType.MetalTexture); } }
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); }
public void OnPreRender() { if (_unityWebCamInUse) { return; } ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles(); if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero) { return; } if (!_bCommandBufferInitialized) { InitializeCommandBuffer(); } //TODO: This resolution should be same as Native ArKit texture resolution(1280 * 720). //We will set the GetWidth() and getHeight() to this resolution _arKitNativeResolution = Screen.currentResolution; //HACK if (Screen.orientation == ScreenOrientation.Landscape) { _arKitNativeResolution.width = 1280; _arKitNativeResolution.height = 720; } else if (Screen.orientation == ScreenOrientation.Portrait) { _arKitNativeResolution.width = 720; _arKitNativeResolution.height = 1280; } // Texture Y if (_videoTextureY == null) { _videoTextureY = Texture2D.CreateExternalTexture(_arKitNativeResolution.width, _arKitNativeResolution.height, TextureFormat.R8, false, false, (System.IntPtr)handles.textureY); _videoTextureY.filterMode = FilterMode.Bilinear; _videoTextureY.wrapMode = TextureWrapMode.Repeat; ClearMaterial.SetTexture("_textureY", _videoTextureY); } // Texture CbCr if (_videoTextureCbCr == null) { _videoTextureCbCr = Texture2D.CreateExternalTexture(_arKitNativeResolution.width, _arKitNativeResolution.height, TextureFormat.RG16, false, false, (System.IntPtr)handles.textureCbCr); _videoTextureCbCr.filterMode = FilterMode.Bilinear; _videoTextureCbCr.wrapMode = TextureWrapMode.Repeat; ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr); } _videoTextureY.UpdateExternalTexture(handles.textureY); _videoTextureCbCr.UpdateExternalTexture(handles.textureCbCr); ClearMaterial.SetMatrix("_DisplayTransform", _displayTransform); }