private void LateUpdate()
        {
            if (feed == null || !feed.isActiveAndEnabled || feed.context.Data != context.Data || feed.Texture == null)
            {
                feed = InputFeed.FindInputFeed(context);
            }

            if (feed != null)
            {
                image.texture = takeProcessed ? feed.ProcessedTexture : feed.Texture;

                if (takeProcessed)
                {
                    image.uvRect = new Rect(0, 0, 1, 1);
                }
                else
                {
                    image.uvRect = new Rect(feed.FlipX ? 1 : 0, feed.FlipY ? 1 : 0, feed.FlipX ? -1 : 1, feed.FlipY ? -1 : 1);
                }

                image.SetMaterialDirty();

                if (fitter != null && image.texture != null)
                {
                    fitter.aspectRatio = (float)image.texture.width / image.texture.height;
                }
            }
            else
            {
                image.texture = null;
            }
        }
예제 #2
0
        protected void StartProcess(InputFeed feed)
        {
            if (context.Data == null || feed.context.Data != context.Data)
            {
                return;
            }

            RealSenseInputFeed realSenseFeed = feed as RealSenseInputFeed;

            if (realSenseFeed == null)
            {
                return;
            }

            Material blitMaterial = realSenseFeed.DepthMaskMaterial;

            if (blitMaterial != null && IsPossible())
            {
                Texture depthValueTex = depthValueTexOverride != null ? depthValueTexOverride : context.Data.staticDepthData.depthValueTexture.Tex;
                blitMaterial.SetTexture(CALIB_MAP_PROP, depthValueTex);

                blitMaterial.SetFloat(MIN_CONFIDENCE_PROP, minConf);
                blitMaterial.SetFloat(MIN_OFFSET_PROP, minOffset);
            }
        }
예제 #3
0
        protected override void StartRender(InputFeed feed)
        {
            if (context.Data == null || feed.context.Data != context.Data)
            {
                return;
            }

            Material blitMaterial = feed.ProcessTextureMaterial;

            if (blitMaterial != null && IsPossible())
            {
                blitMaterial.EnableKeyword(SHADER_KEYWORD);

                //Texture midValueTex = (midValueTexOverride != null) ? midValueTexOverride : context.Data.staticSubtractionData.midValueTexture.Tex;
                //blitMaterial.SetTexture(CALIB_MIN_MAP_PROP, midValueTex);
                //Texture rangeValueTex = (rangeValueTexOverride != null) ? rangeValueTexOverride : context.Data.staticSubtractionData.rangeValueTexture.Tex;
                //blitMaterial.SetTexture(CALIB_RANGE_MAP_PROP, rangeValueTex);
                Texture cielabTex = (cielabColorMapOverride != null) ? cielabColorMapOverride : context.Data.staticSubtractionData.cielabTexture.Tex;
                blitMaterial.SetTexture(CALIB_CIELAB_COLOR_PROP, cielabTex);
                //blitMaterial.SetVector(FEATHER_PROP, context.Data.staticSubtractionData.keyHsvFeathering);

                blitMaterial.SetVector(STATIC_COLOR_TOLERANCE, context.Data.staticSubtractionData.keyTolerance);
                blitMaterial.SetFloat(STATIC_COLOR_RANGE, context.Data.staticSubtractionData.keyRange);
            }
        }
        private void LateUpdate()
        {
            if (cam == null || cam.context.Data != context.Data || !cam.isActiveAndEnabled || feed == null || !feed.isActiveAndEnabled || feed.Texture == null)
            {
                cam = MixCastCamera.ActiveCameras.Find(c => c.context.Data == context.Data);
                if (cam != null)
                {
                    feed = cam.GetComponentInChildren <InputFeed>();
                }
                else
                {
                    feed = null;
                }
            }

            if (feed != null)
            {
                image.texture = feed.Texture;
                image.SetMaterialDirty();

                if (setScale && image.texture != null)
                {
                    image.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, (float)image.texture.width / image.texture.height * image.rectTransform.rect.height);
                }
            }
            else
            {
                image.texture = null;
            }
        }
 public virtual void RegisterFeed(InputFeed feed)
 {
     if (ActiveFeeds == null)
     {
         ActiveFeeds = new List <InputFeed>();
     }
     ActiveFeeds.Add(feed);
 }
예제 #6
0
        public override void RenderScene()
        {
            StartFrame();

            frames.delayDuration = context.Data.unplugged == false ? context.Data.bufferTime : 0f;
            frames.Update();

            GameFrame newFrame = PrepareNewFrame();

            newFrame.playerDist       = gameCamera.transform.TransformVector(Vector3.forward).magnitude *CalculatePlayerDistance(); //Scale distance by camera scale
            newFrame.cameraToWorld    = cleanProxyCamera.cameraToWorldMatrix;
            newFrame.cameraProjection = cleanProxyCamera.projectionMatrix;

            cleanProxyCamera.CopyFrom(gameCamera);
            RenderBackground(newFrame);
            RenderForeground(newFrame);

            GameFrame bufferedFrame = frames.OldestFrameData;

            GL.LoadIdentity();
            ClearBuffer();
            BlitBackground(bufferedFrame);
            if (BackgroundRendered != null)
            {
                BackgroundRendered();
            }

            //Update shader properties for Feeds to access
            Shader.SetGlobalFloat("_CamNear", cleanProxyCamera.nearClipPlane);
            Shader.SetGlobalFloat("_CamFar", cleanProxyCamera.farClipPlane);
            Shader.SetGlobalMatrix("_WorldToCam", bufferedFrame.cameraToWorld.inverse);
            Shader.SetGlobalMatrix("_CamToWorld", bufferedFrame.cameraToWorld);
            Shader.SetGlobalMatrix("_CamProjection", bufferedFrame.cameraProjection);

            for (int i = 0; i < InputFeedProjection.ActiveProjections.Count; i++)
            {
                if (InputFeedProjection.ActiveProjections[i].context.Data == context.Data)
                {
                    InputFeed feed = InputFeedProjection.ActiveProjections[i].FindFeed();
                    if (feed != null)
                    {
                        feed.StartRender();
                        RenderInputProjection(InputFeedProjection.ActiveProjections[i]);
                        feed.StopRender();
                    }
                }
            }

            if (bufferedFrame.playerDist > 0)
            {
                BlitForeground(bufferedFrame);
            }

            Graphics.SetRenderTarget(Output as RenderTexture);
            Graphics.Blit(null, postBlit);
            RenderFinalPass();
            CompleteFrame();
        }
        void HandleRenderStarted(Camera cam)
        {
            if (!readyToRender)
            {
                MeshRenderer.enabled = false;
                return;
            }

            if (MixCastCamera.Current != null)
            {
                if (MixCastCamera.Current.context.Data == context.Data)
                {
                    MeshRenderer.enabled = MixCastCamera.Current is ImmediateMixCastCamera;
                }
                else
                {
                    MeshRenderer.enabled = context.Data.projectionData.displayToOtherCams;
                }
            }
            else if (cam == Camera.main)
            {
                MeshRenderer.enabled = context.Data.projectionData.displayToHeadset;
            }
            else    //Don't show the projection to any other Unity cameras unless they're scene cameras
            {
#if UNITY_EDITOR
                bool isSceneCam = false;
                if (MixCast.ProjectSettings.displaySubjectInScene)
                {
                    for (int i = 0; i < sceneCameras.Length; i++)
                    {
                        isSceneCam |= cam == sceneCameras[i];
                    }
                }
                MeshRenderer.enabled = isSceneCam;
#else
                MeshRenderer.enabled = false;
#endif
            }

            if (MeshRenderer.enabled)
            {
                InputFeed feed = FindFeed();

                if (feed != null && feed.ShouldRender)
                {
                    UpdateMesh(feed);
                    feed.StartRender();
                }
                else
                {
                    MeshRenderer.enabled = false; // gets re-enabled automatically when device is plugged back in.
                }
            }
        }
 void HandleRenderEnded(Camera cam)
 {
     if (MeshRenderer.enabled)
     {
         InputFeed feed = FindFeed();
         if (feed != null && feed.ShouldRender)
         {
             feed.StopRender();
         }
     }
 }
예제 #9
0
        protected override void OnEnable()
        {
            if (feed == null)
            {
                feed = GetComponentInParent <InputFeed>();
            }

            base.OnEnable();

            feed.OnRenderStarted += StartRender;
            feed.OnRenderEnded   += StopRender;
        }
예제 #10
0
        void Update()
        {
            InputFeed feed = FindFeed();

            readyToRender = feed != null && feed.isActiveAndEnabled && feed.ProcessedTexture != null;
            if (!readyToRender)
            {
                return;
            }

            UpdateMesh(feed);
            MeshRenderer.sharedMaterial.SetTexture(textureProperty, feed.ProcessedTexture);
        }
        protected override void StopRender(InputFeed feed)
        {
            if (context.Data == null || feed.context.Data != context.Data)
            {
                return;
            }

            Material blitMaterial = feed.ProcessTextureMaterial;

            if (blitMaterial != null && IsPossible())
            {
                blitMaterial.DisableKeyword(SHADER_KEYWORD);
            }
        }
        private void OnEnable()
        {
            if (feed == null)
            {
                feed = GetComponentInParent <InputFeed>();
            }

            layerNum = LayerMask.NameToLayer(playerLayerName);

            frames = new FrameDelayQueue <FrameLightingData>();

            feed.OnRenderStarted += HandleRenderStarted;
            feed.OnRenderEnded   += HandleRenderEnded;
        }
예제 #13
0
        protected override void StartRender(InputFeed feed)
        {
            if (context.Data == null || feed.context.Data != context.Data)
            {
                return;
            }

            Material blitMaterial = feed.ProcessTextureMaterial;

            if (blitMaterial != null && IsPossible())
            {
                blitMaterial.EnableKeyword(SHADER_KEYWORD);
                blitMaterial.SetFloat(DEPTH_OUTLINE_SIZE_PROP, context.Data.staticDepthData.outlineSize);
                blitMaterial.SetFloat(DEPTH_OUTLINE_FADE_PROP, MAX_FADE_RANGE * Mathf.Max(0.01f, context.Data.staticDepthData.outlineFade));
            }
        }
        void BlitFeed(InputFeed feed)
        {
            if (!feed.enabled)
            {
                return;
            }

            feed.StartRender();
            Graphics.SetRenderTarget(Output as RenderTexture);

            if (feed.Texture != null)
            {
                bool oldSRGB = GL.sRGBWrite;
                GL.sRGBWrite = true;
                Graphics.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), feed.Texture, feed.blitMaterial);
                GL.sRGBWrite = oldSRGB;
            }

            feed.StopRender();
        }
        protected override void StartRender(InputFeed feed)
        {
            if (context.Data == null || feed.context.Data != context.Data)
            {
                return;
            }

            Material blitMaterial = feed.ProcessTextureMaterial;

            if (blitMaterial != null && IsPossible())
            {
                blitMaterial.EnableKeyword(SHADER_KEYWORD);

                blitMaterial.SetVector(CHROMA_MID_PROP, context.Data.chromakeying.keyHsvMid);
                blitMaterial.SetVector(CHROMA_RANGE_PROP, context.Data.chromakeying.keyHsvRange);
                blitMaterial.SetVector(CHROMA_FEATHER_PROP, context.Data.chromakeying.keyHsvFeathering);
                blitMaterial.SetFloat(CHROMA_DESAT_BAND_WIDTH_PARAM, context.Data.chromakeying.keyDesaturationBandWidth);
                blitMaterial.SetFloat(CHROMA_DESAT_FALLOFF_WIDTH_PARAM, context.Data.chromakeying.keyDesaturationFalloffWidth);
            }
        }
예제 #16
0
        void UpdateMesh(InputFeed feed)
        {
            MixCastCamera cam = MixCastCamera.FindCamera(feed.context);

            if (cam == null)
            {
                return;
            }

            float playerDist           = Mathf.Max(cam.gameCamera.nearClipPlane * (1f + NEAR_PLANE_PADDING), feed.CalculatePlayerDistance(cam.gameCamera));
            float playerQuadHalfHeight = playerDist * Mathf.Tan(feed.context.Data.deviceFoV * 0.5f * Mathf.Deg2Rad);
            float playerQuadHalfWidth  = playerQuadHalfHeight * feed.context.Data.deviceFeedWidth / feed.context.Data.deviceFeedHeight;

            vertBuffer[0] = new Vector3(-playerQuadHalfWidth, playerQuadHalfHeight, playerDist);
            vertBuffer[1] = new Vector3(playerQuadHalfWidth, playerQuadHalfHeight, playerDist);
            vertBuffer[2] = new Vector3(playerQuadHalfWidth, -playerQuadHalfHeight, playerDist);
            vertBuffer[3] = new Vector3(-playerQuadHalfWidth, -playerQuadHalfHeight, playerDist);

            projectionMesh.SetVertices(vertBuffer);
            projectionMesh.RecalculateBounds();
            projectionMesh.UploadMeshData(false);
        }
 public virtual void UnregisterFeed(InputFeed feed)
 {
     ActiveFeeds.Remove(feed);
 }
예제 #18
0
 protected abstract void StopRender(InputFeed feed);
 public override void UnregisterFeed(InputFeed feed)
 {
     base.UnregisterFeed(feed);
     RebuildFeedCommand();
 }
예제 #20
0
 protected void StopProcess(InputFeed feed)
 {
 }