Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public virtual void StartRender()
        {
            if (context.Data == null || frames == null)
            {
                return;
            }

            frames.delayDuration = (context.Data.unplugged == false && context.Data.outputMode == MixCastData.OutputMode.Buffered) ? context.Data.bufferTime : 0;
            frames.Update();

            ProcessTexture();

            if (blitMaterial != null && ProcessedTexture != null)
            {
                blitMaterial.mainTexture = ProcessedTexture;

                if (context.Data.croppingData.active)
                {
                    blitMaterial.EnableKeyword(KEYWORD_CROP_PLAYER);
                }

                FramePlayerData oldFrameData = frames.OldestFrameData;
                if (oldFrameData != null)
                {
                    blitMaterial.SetFloat("_PlayerDist", oldFrameData.playerDist);
                    blitMaterial.SetVector("_PlayerHeadPos", oldFrameData.playerHeadPos);
                    blitMaterial.SetVector("_PlayerLeftHandPos", oldFrameData.playerLeftHandPos);
                    blitMaterial.SetVector("_PlayerRightHandPos", oldFrameData.playerRightHandPos);
                    blitMaterial.SetVector("_PlayerBasePos", oldFrameData.playerBasePos);
                }

                float scale = MixCastCameras.Instance.RoomTransform != null?MixCastCameras.Instance.RoomTransform.TransformVector(Vector3.forward).magnitude : 1;

                blitMaterial.SetFloat("_PlayerScale", scale);

                blitMaterial.SetFloat("_PlayerHeadCropRadius", context.Data.croppingData.headRadius);
                blitMaterial.SetFloat("_PlayerHandCropRadius", context.Data.croppingData.handRadius);
                blitMaterial.SetFloat("_PlayerFootCropRadius", context.Data.croppingData.baseRadius);

                //update the player's depth for the material
                FrameDelayQueue <FramePlayerData> .Frame <FramePlayerData> nextFrame = frames.GetNewFrame();
                if (nextFrame.data == null)
                {
                    nextFrame.data = new FramePlayerData();
                }

                FillTrackingData(nextFrame);
            }

            if (OnRenderStarted != null)
            {
                OnRenderStarted();
            }
        }
        public override void RenderScene()
        {
            frames.delayDuration = context.Data.bufferTime;
            frames.Update();

            GameFrame newFrame = PrepareNewFrame();

            newFrame.playerDepth      = CalculatePlayerDistance();
            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 < ActiveFeeds.Count; i++)
            {
                BlitFeed(ActiveFeeds[i]);
            }

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

            Graphics.SetRenderTarget(Output as RenderTexture);
            Graphics.Blit(null, postBlit);
            Graphics.SetRenderTarget(null);

            RenderFinalPass();

            CompleteFrame();
        }
Exemplo n.º 4
0
        protected virtual void UpdateTransform()
        {
            frames.delayDuration = (delayWithBuffer == true && context.Data.unplugged == false && context.Data.outputMode == MixCastData.OutputMode.Buffered) ? context.Data.bufferTime : 0;
            frames.Update();

            if (context.Data != null)
            {
                FrameDelayQueue <TransformData> .Frame <TransformData> newFrame = frames.GetNewFrame();
                if (newFrame.data == null)
                {
                    newFrame.data = new TransformData();
                }
                GetCameraTransform(out newFrame.data.pos, out newFrame.data.rot);

                TransformData oldFrame = frames.OldestFrameData;
                SetTransformFromTarget(oldFrame.pos, oldFrame.rot);
            }
        }
        private void HandleRenderStarted()
        {
            frames.delayDuration = feed.context.Data.outputMode == MixCastData.OutputMode.Buffered ? feed.context.Data.bufferTime : 0;
            frames.Update();

            if (!feed.context.Data.lightingData.isEnabled ||
                feed.context.Data.lightingData.effectAmount <= 0)
            {
                return;
            }

            feed.blitMaterial.EnableKeyword("LIGHTING_FLAT");

            FrameLightingData nextFrame = PrepareNextFrame();

            CalculateCurrentLightsData(nextFrame);

            FrameLightingData oldFrame = frames.OldestFrameData;

            feed.blitMaterial.SetFloat("_PlayerLightingFactor", feed.context.Data.lightingData.effectAmount);
            feed.blitMaterial.SetFloat("_PlayerLightingBase", feed.context.Data.lightingData.baseLighting);
            feed.blitMaterial.SetFloat("_PlayerLightingPower", feed.context.Data.lightingData.powerMultiplier);

            feed.blitMaterial.SetInt(DIR_LIGHT_ARRAY_SIZE, oldFrame.directionalLightCount);
            feed.blitMaterial.SetVectorArray(DIR_LIGHT_DIRECTIONS, oldFrame.directionalLightDirections);
            feed.blitMaterial.SetVectorArray(DIR_LIGHT_COLORS, oldFrame.directionalLightColors);

            feed.blitMaterial.SetInt(POINT_LIGHT_ARRAY_SIZE, oldFrame.pointLightCount);
            feed.blitMaterial.SetVectorArray(POINT_LIGHT_POSITIONS_AND_RANGE, oldFrame.pointLightPositions);
            feed.blitMaterial.SetVectorArray(POINT_LIGHT_COLORS, oldFrame.pointLightColors);

            feed.blitMaterial.SetInt(SPOT_LIGHT_ARRAY_SIZE, oldFrame.spotLightCount);
            feed.blitMaterial.SetVectorArray(SPOT_LIGHT_POSITION_AND_RANGE, oldFrame.spotLightPositions);
            feed.blitMaterial.SetVectorArray(SPOT_LIGHT_DIRECTIONS_AND_ANGLE, oldFrame.spotLightDirections);
            feed.blitMaterial.SetVectorArray(SPOT_LIGHT_COLORS, oldFrame.spotLightColors);
        }
Exemplo n.º 6
0
        public virtual void StartRender()
        {
            if (context.Data == null || frames == null)
            {
                return;
            }

            frames.delayDuration = context.Data.outputMode == MixCastData.OutputMode.Buffered ? context.Data.bufferTime : 0;
            frames.Update();

            if (blitMaterial != null)
            {
                blitMaterial.mainTexture = Texture;

                //Tell the material if linear color space needs to be corrected
                blitMaterial.SetFloat(COLOR_SPACE_EXP_PROP, QualitySettings.activeColorSpace == ColorSpace.Linear ? 2.2f : 1);

                if (Texture != null && cam.Output != null)
                {
                    //set transform to correct for different aspect ratios between screen and camera texture
                    float ratioRatio = ((float)Texture.width / Texture.height) / ((float)cam.Output.width / cam.Output.height);
                    blitMaterial.SetVector("_TextureTransform", new Vector4(1f / ratioRatio, 1, 0.5f * (1f - 1f / ratioRatio), 0));
                }

                //update the player's depth for the material
                FrameDelayQueue <FramePlayerData> .Frame <FramePlayerData> nextFrame = frames.GetNewFrame();
                if (nextFrame.data == null)
                {
                    nextFrame.data = new FramePlayerData();
                }

                if (cam.gameCamera != null)
                {
                    nextFrame.data.playerDepth = CalculatePlayerDepth();
                }

                Transform roomTransform = Camera.main.transform.parent;
                nextFrame.data.playerHeadPos      = Camera.main.transform.position;
                nextFrame.data.playerBasePos      = roomTransform.TransformPoint(new Vector3(Camera.main.transform.localPosition.x, 0, Camera.main.transform.localPosition.z));
                nextFrame.data.playerLeftHandPos  = roomTransform.TransformPoint(GetTrackingPosition(UnityEngine.XR.XRNode.LeftHand));
                nextFrame.data.playerRightHandPos = roomTransform.TransformPoint(GetTrackingPosition(UnityEngine.XR.XRNode.RightHand));

                FramePlayerData oldFrameData = frames.OldestFrameData;

                blitMaterial.SetFloat("_PlayerDepth", oldFrameData.playerDepth);
                blitMaterial.SetVector("_PlayerHeadPos", oldFrameData.playerHeadPos);
                blitMaterial.SetVector("_PlayerLeftHandPos", oldFrameData.playerLeftHandPos);
                blitMaterial.SetVector("_PlayerRightHandPos", oldFrameData.playerRightHandPos);
                blitMaterial.SetVector("_PlayerBasePos", oldFrameData.playerBasePos);

                blitMaterial.SetFloat("_PlayerScale", Camera.main.transform.parent.TransformVector(Vector3.forward).magnitude);

                blitMaterial.SetFloat("_PlayerHeadCropRadius", context.Data.croppingData.headRadius);
                blitMaterial.SetFloat("_PlayerHandCropRadius", context.Data.croppingData.handRadius);
                blitMaterial.SetFloat("_PlayerFootCropRadius", context.Data.croppingData.baseRadius);


                if (context.Data.croppingData.active)
                {
                    blitMaterial.EnableKeyword(KEYWORD_CROP_PLAYER);
                }
                else
                {
                    blitMaterial.DisableKeyword(KEYWORD_CROP_PLAYER);
                }


                if (cam is ImmediateMixCastCamera)
                {
                    blitMaterial.EnableKeyword(KEYWORD_WRITE_DEPTH);
                }
                else
                {
                    blitMaterial.DisableKeyword(KEYWORD_WRITE_DEPTH);
                }
            }

            if (OnRenderStarted != null)
            {
                OnRenderStarted();
            }
        }