private void OnEnable() { ZEDManager.OnZEDReady += ZEDReady; Shader.SetGlobalInt("ZEDGreenScreenActivated", 1); screenManager = GetComponent <ZEDRenderingPlane>(); }
private void Update() { if (textureOverlayLeft == null && manager != null) { textureOverlayLeft = manager.GetLeftCameraTransform().GetComponent <ZEDRenderingPlane>(); } }
private void OnEnable() { ZEDManager.OnZEDReady += ZEDReady; ZEDSteamVRControllerManager.ZEDOnPadIndexSet += PadReady; Shader.SetGlobalInt("ZEDGreenScreenActivated", 1); screenManager = GetComponent <ZEDRenderingPlane>(); }
/// <summary> /// Sets references not set in ZEDManager.CreateZEDRigDisplayer(), sets materials, /// adjusts final plane scale, loads the ZED calibration offset and other misc. values. /// </summary> void Start() { hasVRDevice = hasXRDevice(); //iterate until we found the ZED Manager parent... Transform ObjParent = gameObject.transform; int tries = 0; while (manager == null && tries < 50) { if (ObjParent != null) { manager = ObjParent.GetComponent <ZEDManager> (); } if (manager == null && ObjParent != null) { ObjParent = ObjParent.parent; } tries++; } if (manager != null) { manager.OnZEDReady += ZEDReady; zedCamera = manager.zedCamera; } else { return; } leftScreen = ZEDEyeLeft.GetComponent <ZEDRenderingPlane>(); rightScreen = ZEDEyeRight.GetComponent <ZEDRenderingPlane>(); finalLeftEye = finalCameraLeft.GetComponent <Camera>(); finalRightEye = finalCameraRight.GetComponent <Camera>(); rightMaterial = quadRight.GetComponent <Renderer>().material; leftMaterial = quadLeft.GetComponent <Renderer>().material; finalLeftEye.SetReplacementShader(leftMaterial.shader, ""); finalRightEye.SetReplacementShader(rightMaterial.shader, ""); float plane_dist = (float)sl.Constant.PLANE_DISTANCE; scale(quadLeft.gameObject, new Vector2(1.78f * plane_dist, 1.0f * plane_dist)); scale(quadRight.gameObject, new Vector2(1.78f * plane_dist, 1.0f * plane_dist)); zedReady = false; Camera.onPreRender += PreRender; LoadHmdToZEDCalibration(); }
private void OnEnable() { //cameraManager = gameObject.GetComponent<ZEDManager> (); cameraManager = gameObject.GetComponentInParent <ZEDManager>(); if (!cameraManager) { //cameraManager = ZEDManager.GetInstance(sl.ZED_CAMERA_ID.CAMERA_ID_01); cameraManager = FindObjectOfType <ZEDManager>(); } cameraManager.OnZEDReady += ZEDReady; Shader.SetGlobalInt("ZEDGreenScreenActivated", 1); screenManager = GetComponent <ZEDRenderingPlane>(); }
/// <summary> /// Set the rendering settings (rendering path, shaders values) for camera Left and right /// Activate/Deactivate depth occlusions, Change rendering path... /// </summary> void setRenderingSettings() { ZEDRenderingPlane textureLeftOverlay = GetLeftCameraTransform().GetComponent <ZEDRenderingPlane>(); textureLeftOverlay.SetPostProcess(postProcessing); GetLeftCameraTransform().GetComponent <Camera>().renderingPath = RenderingPath.UsePlayerSettings; Shader.SetGlobalFloat("_ZEDFactorAffectReal", m_cameraBrightness); ZEDRenderingPlane textureRightOverlay = null; if (IsStereoRig) { textureRightOverlay = GetRightCameraTransform().GetComponent <ZEDRenderingPlane>(); textureRightOverlay.SetPostProcess(postProcessing); } ZEDRenderingMode renderingPath = (ZEDRenderingMode)GetLeftCameraTransform().GetComponent <Camera>().actualRenderingPath; //Check that we are in forward or deffered if (renderingPath != ZEDRenderingMode.FORWARD && renderingPath != ZEDRenderingMode.DEFERRED) { Debug.LogError("[ZED Plugin] Only Forward and Deferred Shading rendering path are supported"); GetLeftCameraTransform().GetComponent <Camera> ().renderingPath = RenderingPath.Forward; if (IsStereoRig) { GetRightCameraTransform().GetComponent <Camera> ().renderingPath = RenderingPath.Forward; } } //Set Depth Occ if (renderingPath == ZEDRenderingMode.FORWARD) { textureLeftOverlay.ManageKeyWordPipe(!depthOcclusion, "NO_DEPTH_OCC"); if (textureRightOverlay) { textureRightOverlay.ManageKeyWordPipe(!depthOcclusion, "NO_DEPTH_OCC"); } } else if (renderingPath == ZEDRenderingMode.DEFERRED) { textureLeftOverlay.ManageKeyWordDefferedMat(!depthOcclusion, "NO_DEPTH_OCC"); if (textureRightOverlay) { textureRightOverlay.ManageKeyWordDefferedMat(!depthOcclusion, "NO_DEPTH_OCC"); } } }
/// <summary> /// Creates the duplicate camera that renders only the planes. /// Rendering targets a RenderTexture that ZEDRenderingPlane will blend in at OnRenderImage(). /// This gets called by ZEDManager.OnZEDReady when the ZED is finished initializing. /// </summary> void ZEDReady() { //Create the new GameObject and camera as a child of the corresponding ZED rig camera. GameObject go = new GameObject("PlaneCamera"); go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; cam = go.AddComponent <Camera>(); go.hideFlags = HideFlags.HideAndDontSave; //This hides the new camera from scene view. Comment this out to see it in the hierarchy. //Set the target texture to a new RenderTexture that will be passed to ZEDRenderingPlane for blending. if (sl.ZEDCamera.GetInstance().IsCameraReady) { planeTex = new RenderTexture(sl.ZEDCamera.GetInstance().ImageWidth, sl.ZEDCamera.GetInstance().ImageHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default); planeTex.Create(); } //Set the camera's parameters. cam.enabled = false; cam.cullingMask = (1 << sl.ZEDCamera.TagOneObject); //Layer set aside for planes and spatial mapping meshes. cam.targetTexture = planeTex; cam.nearClipPlane = 0.1f; cam.farClipPlane = 100.0f; cam.fieldOfView = sl.ZEDCamera.GetInstance().GetFOV() * Mathf.Rad2Deg; cam.projectionMatrix = sl.ZEDCamera.GetInstance().Projection; cam.backgroundColor = new Color(0, 0, 0, 0); cam.clearFlags = CameraClearFlags.Color; cam.renderingPath = RenderingPath.VertexLit; cam.depth = 0; cam.depthTextureMode = DepthTextureMode.None; #if UNITY_5_6_OR_NEWER cam.allowMSAA = false; cam.allowHDR = false; #endif cam.useOcclusionCulling = false; //Set the ZEDRenderingPlane blend texture to the one the new camera renders to. renderingPlane = GetComponent <ZEDRenderingPlane>(); renderingPlane.SetTextureOverlayMapping(planeTex); isReady = true; }
//Creates a camera to render only the Mesh void ZEDReady() { GameObject go = new GameObject("MeshCamera"); go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; cam = go.AddComponent <Camera>(); go.hideFlags = HideFlags.HideAndDontSave; if (sl.ZEDCamera.GetInstance().IsCameraReady) { meshTex = new RenderTexture(sl.ZEDCamera.GetInstance().ImageWidth, sl.ZEDCamera.GetInstance().ImageHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default); meshTex.Create(); } cam.enabled = false; cam.cullingMask = (1 << sl.ZEDCamera.TagOneObject); cam.targetTexture = meshTex; cam.nearClipPlane = 0.1f; cam.farClipPlane = 500.0f; cam.fieldOfView = sl.ZEDCamera.GetInstance().GetFOV() * Mathf.Rad2Deg; cam.projectionMatrix = sl.ZEDCamera.GetInstance().Projection; cam.backgroundColor = new Color(0, 0, 0, 0); cam.clearFlags = CameraClearFlags.Color; cam.renderingPath = RenderingPath.VertexLit; cam.depth = 0; cam.depthTextureMode = DepthTextureMode.None; #if UNITY_5_6_OR_NEWER cam.allowMSAA = false; cam.allowHDR = false; #endif cam.useOcclusionCulling = false; shaderWireframe = (Resources.Load("Materials/SpatialMapping/Mat_ZED_Wireframe_Video_Overlay") as Material).shader; textureOverlay = GetComponent <ZEDRenderingPlane>(); textureOverlay.SetTextureSpatialMapping(meshTex); }
/// <summary> /// Start this instance. /// </summary> void Start() { hasVRDevice = VRDevice.isPresent; manager = transform.parent.GetComponent <ZEDManager>(); zedCamera = sl.ZEDCamera.GetInstance(); leftScreen = ZEDEyeLeft.GetComponent <ZEDRenderingPlane>(); rightScreen = ZEDEyeRight.GetComponent <ZEDRenderingPlane>(); finalLeftEye = finalCameraLeft.GetComponent <Camera>(); finalRightEye = finalCameraRight.GetComponent <Camera>(); rightMaterial = quadRight.GetComponent <Renderer>().material; leftMaterial = quadLeft.GetComponent <Renderer>().material; finalLeftEye.SetReplacementShader(leftMaterial.shader, ""); finalRightEye.SetReplacementShader(rightMaterial.shader, ""); float plane_dist = (float)sl.Constant.PLANE_DISTANCE; scale(quadLeft.gameObject, finalLeftEye, new Vector2(1.78f * plane_dist, 1.0f * plane_dist)); scale(quadRight.gameObject, finalRightEye, new Vector2(1.78f * plane_dist, 1.0f * plane_dist)); zedReady = false; Camera.onPreRender += PreRender; LoadHmdToZEDCalibration(); }
/// <summary> /// Create the Mesh Rendering pipe /// </summary> public void Create() { Transform ObjParent = gameObject.transform; int tries = 0; while (zedManager == null && tries < 5) { if (ObjParent != null) { zedManager = ObjParent.GetComponent <ZEDManager> (); } if (zedManager == null && ObjParent != null) { ObjParent = ObjParent.parent; } tries++; } if (zedManager == null) { return; } //Create the new GameObject and camera as a child of the corresponding ZED rig camera. GameObject go = new GameObject("MeshCamera"); go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; cam = go.AddComponent <Camera>(); go.hideFlags = HideFlags.HideAndDontSave; //This hides the new camera from scene view. Comment this out to see it in the hierarchy. //Set the target texture to a new RenderTexture that will be passed to ZEDRenderingPlane for blending. if (zedManager.zedCamera.IsCameraReady) { meshTex = new RenderTexture(zedManager.zedCamera.ImageWidth, zedManager.zedCamera.ImageHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default); meshTex.Create(); } //Set the camera's parameters. cam.enabled = false; cam.cullingMask = (1 << zedManager.zedCamera.TagOneObject); //Layer set aside for planes and spatial mapping meshes. cam.targetTexture = meshTex; cam.nearClipPlane = 0.1f; cam.farClipPlane = 500.0f; cam.fieldOfView = zedManager.zedCamera.GetFOV() * Mathf.Rad2Deg; cam.projectionMatrix = zedManager.zedCamera.Projection; cam.backgroundColor = new Color(0, 0, 0, 0); cam.clearFlags = CameraClearFlags.Color; cam.renderingPath = RenderingPath.VertexLit; cam.depth = 0; cam.depthTextureMode = DepthTextureMode.None; #if UNITY_5_6_OR_NEWER cam.allowMSAA = false; cam.allowHDR = false; #endif cam.useOcclusionCulling = false; shaderWireframe = (Resources.Load("Materials/SpatialMapping/Mat_ZED_Wireframe_Video_Overlay") as Material).shader; //Set the ZEDRenderingPlane blend texture to the one the new camera renders to. renderingPlane = GetComponent <ZEDRenderingPlane>(); renderingPlane.SetTextureOverlayMapping(meshTex); hasStarted = true; }
void Awake() { instance = this; zedReady = false; //If you want the ZEDRig not to be destroyed DontDestroyOnLoad(transform.root); //Init the first parameters initParameters = new sl.InitParameters(); initParameters.cameraFPS = FPS; initParameters.resolution = resolution; initParameters.depthMode = depthMode; initParameters.depthStabilization = depthStabilizer; //Check if the AR is needed and if possible to add CheckStereoMode(); //Init the other options isZEDTracked = enableTracking; initialPosition = transform.localPosition; initialRotation = transform.localRotation; zedPosition = initialPosition; zedOrientation = Quaternion.identity; //Create a camera and return an error message if the dependencies are not detected zedCamera = sl.ZEDCamera.GetInstance(); LastInitStatus = sl.ERROR_CODE.ERROR_CODE_LAST; zedSVOManager = GetComponent <ZEDSVOManager>(); zedCamera.CreateCamera(wrapperVerbose); if (zedSVOManager != null) { //Create a camera if ((zedSVOManager.read || zedSVOManager.record) && zedSVOManager.videoFile.Length == 0) { zedSVOManager.record = false; zedSVOManager.read = false; } if (zedSVOManager.read) { zedSVOManager.record = false; initParameters.pathSVO = zedSVOManager.videoFile; initParameters.svoRealTimeMode = true; initParameters.depthStabilization = depthStabilizer; } } versionZED = "[SDK]: " + sl.ZEDCamera.GetSDKVersion().ToString() + " [Plugin]: " + sl.ZEDCamera.PluginVersion.ToString(); ZEDRenderingPlane textureLeftOverlay = GetLeftCameraTransform().GetComponent <ZEDRenderingPlane>(); textureLeftOverlay.SetPostProcess(postProcessing); GetLeftCameraTransform().GetComponent <Camera>().renderingPath = (RenderingPath)(int)renderingPath; Shader.SetGlobalFloat("_ZEDFactorAffectReal", cameraBrightness); if (IsStereoRig) { ZEDRenderingPlane textureRightOverlay = GetRightCameraTransform().GetComponent <ZEDRenderingPlane>(); textureRightOverlay.SetPostProcess(postProcessing); GetRightCameraTransform().GetComponent <Camera>().renderingPath = (RenderingPath)(int)renderingPath; } //Set the ZED Tracking frame as Left eye SetTrackingRef(sl.TRACKING_FRAME.LEFT_EYE); if (isStereoRig) { //Creates a CameraRig (the 2 last cameras) GameObject o = CreateZEDRigDisplayer(); o.hideFlags = HideFlags.HideAndDontSave; o.transform.parent = transform; //Force some initParameters that are required for MR experience initParameters.enableRightSideMeasure = isStereoRig; initParameters.depthMinimumDistance = 0.1f; initParameters.depthMode = sl.DEPTH_MODE.PERFORMANCE; initParameters.depthStabilization = depthStabilizer; //Create the mirror, the texture from the firsts cameras is rendered to avoid a black border CreateMirror(); } //Start the co routine to initialize the ZED and avoid to block the user LastInitStatus = sl.ERROR_CODE.ERROR_CODE_LAST; openingLaunched = false; StartCoroutine("InitZED"); }
void OnValidate() { if (zedCamera != null) { if (!isTrackingEnable && enableTracking) { //Enables the tracking and initializes the first position of the camera Quaternion quat = Quaternion.identity; Vector3 vec = new Vector3(0, 0, 0); enablePoseSmoothing = enableSpatialMemory; if (!(enableTracking = (zedCamera.EnableTracking(ref quat, ref vec, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS))) { isZEDTracked = false; throw new Exception(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_NOT_INITIALIZED)); } else { isZEDTracked = true; isTrackingEnable = true; } } if (isTrackingEnable && !enableTracking) { isZEDTracked = false; lock (grabLock) { zedCamera.DisableTracking(); } isTrackingEnable = false; } //Create ZEDTextureOverlay object to handle left images ZEDRenderingPlane textureLeftOverlay = GetLeftCameraTransform().GetComponent <ZEDRenderingPlane>(); textureLeftOverlay.SetPostProcess(postProcessing); Shader.SetGlobalFloat("_ZEDFactorAffectReal", cameraBrightness); //Create ZEDTextureOverlay object to handle Right images if a right camera is present if (IsStereoRig) { ZEDRenderingPlane textureRightOverlay = GetRightCameraTransform().GetComponent <ZEDRenderingPlane>(); textureRightOverlay.SetPostProcess(postProcessing); } if (renderingPath == ZEDRenderingMode.FORWARD) { if (depthOcclusion) { textureLeftOverlay.ManageKeyWordPipe(false, "NO_DEPTH_OCC"); if (IsStereoRig) { textureLeftOverlay.ManageKeyWordPipe(false, "NO_DEPTH_OCC"); } } else { textureLeftOverlay.ManageKeyWordPipe(true, "NO_DEPTH_OCC"); if (IsStereoRig) { textureLeftOverlay.ManageKeyWordPipe(true, "NO_DEPTH_OCC"); } } } else if (renderingPath == ZEDRenderingMode.DEFERRED) { if (depthOcclusion) { textureLeftOverlay.ManageKeyWordDefferedMat(false, "NO_DEPTH_OCC"); if (IsStereoRig) { textureLeftOverlay.ManageKeyWordDefferedMat(false, "NO_DEPTH_OCC"); } } else { textureLeftOverlay.ManageKeyWordDefferedMat(true, "NO_DEPTH_OCC"); if (IsStereoRig) { textureLeftOverlay.ManageKeyWordDefferedMat(true, "NO_DEPTH_OCC"); } } } } }