private void CognitiveVR_Manager_InitEvent(Error initError) { if (initError == Error.None) { var buf = new CommandBuffer(); buf.name = "cognitive depth"; if (GameplayReferences.HMD == null) { CognitiveVR.Util.logWarning("HMD is null! Command Gaze will not function"); return; } GameplayReferences.HMDCameraComponent.depthTextureMode = DepthTextureMode.Depth; GameplayReferences.HMDCameraComponent.AddCommandBuffer(camevent, buf); var material = new Material(Shader.Find("Hidden/Cognitive/CommandDepth")); //buf.SetGlobalFloat(Shader.PropertyToID("_DepthScale"), 1f / 1); //buf.Blit((Texture)null, BuiltinRenderTextureType.CameraTarget, material, (int)0); #if SRP_LW3_0_0 rt = new RenderTexture(Screen.width, Screen.height, 0); #else //rt = new RenderTexture(256, 256, 0); rt = new RenderTexture(256, 256, 24, RenderTextureFormat.ARGBFloat); #endif buf.Blit(BuiltinRenderTextureType.CurrentActive, rt, material, (int)0); //buf.Blit(blitTo, rt); Core.TickEvent += CognitiveVR_Manager_TickEvent; helper = GameplayReferences.HMD.gameObject.AddComponent <CommandBufferHelper>(); helper.Initialize(rt, GameplayReferences.HMDCameraComponent, OnHelperPostRender, this); } }
private void CognitiveVR_Manager_InitEvent(Error initError) { if (initError == Error.Success) { var buf = new CommandBuffer(); buf.name = "cognitive depth"; CameraComponent.depthTextureMode = DepthTextureMode.Depth; CameraComponent.AddCommandBuffer(camevent, buf); var material = new Material(Shader.Find("Hidden/Cognitive/CommandDepth")); buf.SetGlobalFloat(Shader.PropertyToID("_DepthScale"), 1f / 1); buf.Blit((Texture)null, BuiltinRenderTextureType.CameraTarget, material, (int)0); #if SRP_LW3_0_0 rt = new RenderTexture(Screen.width, Screen.height, 0); #else rt = new RenderTexture(256, 256, 0); #endif buf.Blit(blitTo, rt); CognitiveVR_Manager.TickEvent += CognitiveVR_Manager_TickEvent; helper = CameraTransform.gameObject.AddComponent <CommandBufferHelper>(); helper.Initialize(rt, CameraComponent, OnHelperPostRender); } }
private void CognitiveVR_Manager_TickEvent() { if (helper == null) //if there's a scene change and camera is destroyed, replace helper { helper = CameraTransform.gameObject.AddComponent <CommandBufferHelper>(); helper.Initialize(rt, CameraComponent, OnHelperPostRender); } Vector3 viewport = GetViewportGazePoint(); viewport.z = 100; var viewportray = CameraComponent.ViewportPointToRay(viewport); helper.Begin(GetViewportGazePoint(), viewportray); }
private void CognitiveVR_Manager_InitEvent(Error initError) { if (initError == Error.Success) { //should reparent to camera or add helper component? var buf = new CommandBuffer(); buf.name = "cognitive depth"; CameraComponent.depthTextureMode = DepthTextureMode.Depth; CameraComponent.AddCommandBuffer(camevent, buf); //stolen from debugview var material = new Material(Shader.Find("Hidden/Cognitive/CommandDepth")); //var settings = model.settings.depth; buf.SetGlobalFloat(Shader.PropertyToID("_DepthScale"), 1f / 1); buf.Blit((Texture)null, BuiltinRenderTextureType.CameraTarget, material, (int)0); //cam.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, buf); rt = new RenderTexture(256, 256, 24); buf.Blit(blitTo, rt); //buf.Blit(rt, (RenderTexture)null); //StartCoroutine(EndOfFrame()); //if (debugImage != null) // debugImage.texture = readTexture; CognitiveVR_Manager.TickEvent += CognitiveVR_Manager_TickEvent; helper = CameraTransform.gameObject.AddComponent <CommandBufferHelper>(); helper.Initialize(rt, CameraComponent, OnHelperPostRender); //enable command buffer helper //let it do its thing //register a callback with parameters when it's finished } }