public override void Stop() { var anchors = m_anchors.Values; foreach (var anchor in anchors) { DestroyAnchor(anchor); } //Unregister Callbacks UnityARSessionNativeInterface.ARAnchorAddedEvent -= AddAnchor; UnityARSessionNativeInterface.ARAnchorUpdatedEvent -= UpdateAnchor; UnityARSessionNativeInterface.ARAnchorRemovedEvent -= RemoveAnchor; UnityARSessionNativeInterface.ARFrameUpdatedEvent -= UpdateFrame; UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent -= UpdateUserAnchor; NativeInterface.Pause(); NativeInterface.SetCapturePixelData(false, IntPtr.Zero, IntPtr.Zero); m_YArrayHandle.Free(); m_UVArrayHandle.Free(); m_isTexturesInitialized = false; m_isBackgroundRendering = false; m_canRenderBackground = false; m_backgroundRenderer.backgroundMaterial = null; m_backgroundRenderer.camera = null; m_backgroundRenderer = null; IsRunning = false; }
public override void StopService() { var anchors = m_Anchors.Values; foreach (var anchor in anchors) { DestroyAnchor(anchor); } UnityARSessionNativeInterface.ARAnchorAddedEvent -= AddAnchor; UnityARSessionNativeInterface.ARAnchorUpdatedEvent -= UpdateAnchor; UnityARSessionNativeInterface.ARAnchorRemovedEvent -= RemoveAnchor; UnityARSessionNativeInterface.ARFrameUpdatedEvent -= UpdateFrame; UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent -= UpdateUserAnchor; UnityARSessionNativeInterface.GetARSessionNativeInterface().Pause(); nativeInterface.SetCapturePixelData(false, IntPtr.Zero, IntPtr.Zero); m_PinnedYArray.Free(); m_PinnedUVArray.Free(); m_TexturesInitialized = false; BackgroundRendering = false; m_CanRenderBackground = false; m_BackgroundRenderer.backgroundMaterial = null; m_BackgroundRenderer.camera = null; m_BackgroundRenderer = null; IsRunning = false; }
private void OnDisable() { if (m_BackgroundRenderer != null) { m_BackgroundRenderer.camera = null; m_BackgroundRenderer = null; } }
public override void SetupCamera(Camera camera) { m_Camera = camera; m_ClearMaterial = Resources.Load("YUVMaterial", typeof(Material)) as Material; m_BackgroundRenderer = new ARBackgroundRenderer(); m_BackgroundRenderer.backgroundMaterial = m_ClearMaterial; m_BackgroundRenderer.camera = camera; }
public override void SetupCamera(Camera _camera) { m_camera = _camera; m_clearMaterial = Resources.Load <Material>("YUVMaterial"); m_backgroundRenderer = new ARBackgroundRenderer(); m_backgroundRenderer.backgroundMaterial = m_clearMaterial; m_backgroundRenderer.camera = m_camera; }
public void ScreenCaptureParamsMessageHandler(MessageEventArgs message) { var screenCaptureParams = message.data.Deserialize <SerializableScreenCaptureParams>(); if (m_RemoteScreenYTexture == null || m_RemoteScreenYTexture.width != screenCaptureParams.width || m_RemoteScreenYTexture.height != screenCaptureParams.height) { if (m_RemoteScreenYTexture != null) { GameObject.Destroy(m_RemoteScreenYTexture); } m_RemoteScreenYTexture = new Texture2D( screenCaptureParams.width, screenCaptureParams.height, TextureFormat.R8, false, true); } if (m_RemoteScreenUVTexture == null || m_RemoteScreenUVTexture.width != screenCaptureParams.width || m_RemoteScreenUVTexture.height != screenCaptureParams.height) { if (m_RemoteScreenUVTexture != null) { GameObject.Destroy(m_RemoteScreenUVTexture); } m_RemoteScreenUVTexture = new Texture2D( screenCaptureParams.width / 2, screenCaptureParams.height / 2, TextureFormat.RG16, false, true); } Material YUVMaterial = Resources.Load("YUVMaterial", typeof(Material)) as Material; YUVMaterial.SetMatrix("_DisplayTransform", GetDisplayTransform()); YUVMaterial.SetTexture("_textureY", m_RemoteScreenYTexture); YUVMaterial.SetTexture("_textureCbCr", m_RemoteScreenUVTexture); if (m_BackgroundRenderer != null) { m_BackgroundRenderer.backgroundMaterial = null; m_BackgroundRenderer.camera = null; } m_BackgroundRenderer = new ARBackgroundRenderer(); m_BackgroundRenderer.backgroundMaterial = YUVMaterial; m_BackgroundRenderer.camera = m_CachedCamera; //Set mode and send to player BackgroundRendering = m_BackgroundRendering; m_CameraImage.width = screenCaptureParams.width; m_CameraImage.height = screenCaptureParams.height; }
public override void SetupCamera(Camera camera) { var backgroundRender = new ARBackgroundRenderer(); backgroundRender.backgroundMaterial = Resources.Load("Materials/ARBackground", typeof(Material)) as Material; backgroundRender.mode = ARRenderMode.MaterialAsBackground; backgroundRender.camera = camera; ARCoreNative.Device.backgroundRenderer = backgroundRender; }
private void OnEnable() { if (m_BackgroundRenderer == null) { m_BackgroundRenderer = new ARBackgroundRenderer(); } if (BackgroundMaterial == null) { Debug.LogError("ArCameraBackground:: No material assigned."); return; } m_Camera = GetComponent <Camera>(); m_BackgroundRenderer.backgroundMaterial = BackgroundMaterial; m_BackgroundRenderer.camera = m_Camera; m_BackgroundRenderer.mode = ARRenderMode.MaterialAsBackground; }
protected unsafe virtual void OnCameraFrameReceived(ARCameraFrameEventArgs eventArgs) { if (true) { int w = Screen.width, h = Screen.height; if (renderTexture == null || renderTexture.width != w || renderTexture.height != h) { if (renderTexture != null) { RenderTexture.ReleaseTemporary(renderTexture); } renderTexture = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.ARGB32); } cameraBackground.targetTexture = renderTexture; if (eventArgs.projectionMatrix.HasValue) { cameraBackground.projectionMatrix = eventArgs.projectionMatrix.Value; } if (rendererBackground == null) { rendererBackground = new ARBackgroundRenderer(); rendererBackground.mode = ARRenderMode.MaterialAsBackground; rendererBackground.backgroundMaterial = arBackground.material; rendererBackground.camera = cameraBackground; } // Texture texture = renderTexture; if (true) { Material mat; for (int i = 0, imax = materials?.Length ?? 0; i < imax; ++i) { mat = materials[i]; if (mat != null) { mat.mainTexture = texture; } } // if (rawImage != null) { rawImage.texture = texture; } } } }
public override void StopService() { var anchors = m_Anchors.Keys; foreach (var anchor in anchors) { DestroyAnchor(anchor); } m_ARCoreSession.enabled = false; TextureReader_destroy(); BackgroundRendering = false; m_BackgroundRenderer.backgroundMaterial = null; m_BackgroundRenderer.camera = null; m_BackgroundRenderer = null; IsRunning = false; }
private void OnEnable() { if (m_BackgroundRenderer == null) { m_BackgroundRenderer = new ARBackgroundRenderer(); } if (BackgroundMaterial == null) { return; } m_Camera = GetComponent <Camera>(); m_BackgroundRenderer.backgroundMaterial = BackgroundMaterial; m_BackgroundRenderer.camera = m_Camera; m_BackgroundRenderer.mode = ARRenderMode.MaterialAsBackground; }
IEnumerator Start() { yield return(new WaitUntil(() => Source && Source.Streaming)); using (var profile = Source.ActiveProfile.GetStream <VideoStreamProfile>(Stream.Color)) { intrinsics = profile.GetIntrinsics(); } cam = GetComponent <Camera>(); bg = new ARBackgroundRenderer() { backgroundMaterial = material, mode = ARRenderMode.MaterialAsBackground, backgroundTexture = material.mainTexture }; cam.depthTextureMode |= DepthTextureMode.Depth; // Uses the same material as above to update camera's depth texture // Unity will use it when calculating shadows var updateCamDepthTexture = new CommandBuffer() { name = "UpdateDepthTexture" }; updateCamDepthTexture.Blit(BuiltinRenderTextureType.None, BuiltinRenderTextureType.CurrentActive, material); updateCamDepthTexture.SetGlobalTexture("_ShadowMapTexture", Texture2D.whiteTexture); cam.AddCommandBuffer(CameraEvent.AfterDepthTexture, updateCamDepthTexture); // assume single directional light var light = FindObjectOfType <Light>(); // Copy resulting screenspace shadow map, ARBackgroundRenderer's material will multiply it over color image var copyScreenSpaceShadow = new CommandBuffer { name = "CopyScreenSpaceShadow" }; int shadowCopyId = Shader.PropertyToID("_ShadowMapTexture"); copyScreenSpaceShadow.GetTemporaryRT(shadowCopyId, -1, -1, 0); copyScreenSpaceShadow.CopyTexture(BuiltinRenderTextureType.CurrentActive, shadowCopyId); copyScreenSpaceShadow.SetGlobalTexture(shadowCopyId, shadowCopyId); light.AddCommandBuffer(LightEvent.AfterScreenspaceMask, copyScreenSpaceShadow); }
/** * \if english * @brief Inherit from Unity Update(). * \else * @brief Unity的Update()。 * \endif */ public void Update() { if (BackGroundMaterial == null) { return; } else if (!ARFrame.TextureIsAvailable()) { return; } const string backroundTex = "_MainTex"; const string leftTopBottom = "_UvLeftTopBottom"; const string rightTopBottom = "_UvRightTopBottom"; BackGroundMaterial.SetTexture(backroundTex, ARFrame.CameraTexture); if (ARFrame.IsDisplayGeometryChanged()) { transformedUVCoords = ARFrame.GetTransformDisplayUvCoords(QUAD_TEXCOORDS); } BackGroundMaterial.SetVector(leftTopBottom, new Vector4(transformedUVCoords[0], transformedUVCoords[1], transformedUVCoords[2], transformedUVCoords[3])); BackGroundMaterial.SetVector(rightTopBottom, new Vector4(transformedUVCoords[4], transformedUVCoords[5], transformedUVCoords[6], transformedUVCoords[7])); Pose p = ARFrame.GetPose(); m_camera.transform.position = p.position; m_camera.transform.rotation = p.rotation; m_camera.projectionMatrix = ARSession.GetProjectionMatrix(m_camera.nearClipPlane, m_camera.farClipPlane); if (m_backgroundRenderer == null) { m_backgroundRenderer = new ARBackgroundRenderer(); m_backgroundRenderer.backgroundMaterial = BackGroundMaterial; m_backgroundRenderer.camera = m_camera; m_backgroundRenderer.mode = ARRenderMode.MaterialAsBackground; } }
private void Update() { if (BackgroundMaterial == null) { Disable(); return; } Texture backgroundTexture = Frame.CameraImage.Texture; if (backgroundTexture == null) { Disable(); return; } const string mainTexVar = "_MainTex"; const string topLeftRightVar = "_UvTopLeftRight"; const string bottomLeftRightVar = "_UvBottomLeftRight"; BackgroundMaterial.SetTexture(mainTexVar, backgroundTexture); var uvQuad = Frame.CameraImage.DisplayUvCoords; BackgroundMaterial.SetVector(topLeftRightVar, new Vector4(uvQuad.TopLeft.x, uvQuad.TopLeft.y, uvQuad.TopRight.x, uvQuad.TopRight.y)); BackgroundMaterial.SetVector(bottomLeftRightVar, new Vector4(uvQuad.BottomLeft.x, uvQuad.BottomLeft.y, uvQuad.BottomRight.x, uvQuad.BottomRight.y)); m_Camera.projectionMatrix = Frame.CameraImage.GetCameraProjectionMatrix( m_Camera.nearClipPlane, m_Camera.farClipPlane); if (m_BackgroundRenderer == null) { m_BackgroundRenderer = new ARBackgroundRenderer(); m_BackgroundRenderer.backgroundMaterial = BackgroundMaterial; m_BackgroundRenderer.camera = m_Camera; m_BackgroundRenderer.mode = ARRenderMode.MaterialAsBackground; } }
private void OnEnable() { if (m_BackgroundRenderer == null) { m_BackgroundRenderer = new ARBackgroundRenderer(); } if (BackgroundMaterial == null) { Debug.LogError("ArCameraBackground:: No material assigned."); return; } LifecycleManager.Instance.OnSessionSetEnabled += _OnSessionSetEnabled; m_Camera = GetComponent <Camera>(); m_BackgroundRenderer.backgroundMaterial = BackgroundMaterial; m_BackgroundRenderer.camera = m_Camera; m_BackgroundRenderer.mode = ARRenderMode.MaterialAsBackground; m_TransitionImageTexture = Resources.Load <Texture2D>("ViewInARIcon"); BackgroundMaterial.SetTexture("_TransitionIconTex", m_TransitionImageTexture); }
private void Update() { if (BackgroundMaterial == null) { // A background rending material has not been assigned. return; } else if (Frame.CameraImage.Texture == null) { // TODO (mtsmall): Consider rendering a default background in this case. // No texture is available. return; } const string mainTexVar = "_MainTex"; const string topLeftRightVar = "_UvTopLeftRight"; const string bottomLeftRightVar = "_UvBottomLeftRight"; BackgroundMaterial.SetTexture(mainTexVar, Frame.CameraImage.Texture); ApiDisplayUvCoords uvQuad = Frame.CameraImage.DisplayUvCoords; BackgroundMaterial.SetVector(topLeftRightVar, new Vector4(uvQuad.TopLeft.x, uvQuad.TopLeft.y, uvQuad.TopRight.x, uvQuad.TopRight.y)); BackgroundMaterial.SetVector(bottomLeftRightVar, new Vector4(uvQuad.BottomLeft.x, uvQuad.BottomLeft.y, uvQuad.BottomRight.x, uvQuad.BottomRight.y)); m_Camera.projectionMatrix = Frame.CameraImage.GetCameraProjectionMatrix(m_Camera.nearClipPlane, m_Camera.farClipPlane); if (m_BackgroundRenderer == null) { m_BackgroundRenderer = new ARBackgroundRenderer(); m_BackgroundRenderer.backgroundMaterial = BackgroundMaterial; m_BackgroundRenderer.camera = m_Camera; m_BackgroundRenderer.mode = ARRenderMode.MaterialAsBackground; } }
void Awake() { backgroundRenderer = new ARBackgroundRenderer(); backgroundRenderer.camera = GetComponent <Camera>(); }