//Gets an empty frame from the pool and ensures its ready to be filled GameFrame PrepareNewFrame() { FrameDelayQueue <GameFrame> .Frame <GameFrame> newFrame = frames.GetNewFrame(); if (newFrame.data == null) { newFrame.data = new GameFrame(); } if (newFrame.data.backgroundBuffer != null && (newFrame.data.backgroundBuffer.width != Output.width || newFrame.data.backgroundBuffer.height != Output.height)) { newFrame.data.backgroundBuffer.Release(); newFrame.data.backgroundBuffer = null; } if (newFrame.data.backgroundBuffer == null) { newFrame.data.backgroundBuffer = new RenderTexture(Output.width, Output.height, 24, gameCamera.hdr ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default); } if (newFrame.data.foregroundBuffer != null && (newFrame.data.foregroundBuffer.width != Output.width || newFrame.data.foregroundBuffer.height != Output.height)) { newFrame.data.foregroundBuffer.Release(); newFrame.data.foregroundBuffer = null; } if (newFrame.data.foregroundBuffer == null) { newFrame.data.foregroundBuffer = new RenderTexture(Output.width, Output.height, 24, gameCamera.hdr ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default); } return(newFrame.data); }
//Gets an empty frame from the pool and ensures its ready to be filled GameFrame PrepareNewFrame() { FrameDelayQueue <GameFrame> .Frame <GameFrame> newFrame = frames.GetNewFrame(); if (newFrame.data == null) { newFrame.data = new GameFrame(); } if (newFrame.data.backgroundBuffer != null && (newFrame.data.backgroundBuffer.width != Output.width || newFrame.data.backgroundBuffer.height != Output.height)) { newFrame.data.backgroundBuffer.Release(); newFrame.data.backgroundBuffer = null; } if (newFrame.data.backgroundBuffer == null) { newFrame.data.backgroundBuffer = new RenderTexture(Output.width, Output.height, 24, (Output as RenderTexture).format, (Output as RenderTexture).sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear); newFrame.data.backgroundBuffer.antiAliasing = CalculateAntiAliasingValue(); } if (newFrame.data.foregroundBuffer != null && (newFrame.data.foregroundBuffer.width != Output.width || newFrame.data.foregroundBuffer.height != Output.height)) { newFrame.data.foregroundBuffer.Release(); newFrame.data.foregroundBuffer = null; } if (newFrame.data.foregroundBuffer == null) { newFrame.data.foregroundBuffer = new RenderTexture(Output.width, Output.height, 24, (Output as RenderTexture).format, (Output as RenderTexture).sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear); newFrame.data.foregroundBuffer.antiAliasing = CalculateAntiAliasingValue(); } return(newFrame.data); }
private void OnDisable() { frames = null; feed.OnRenderStarted -= HandleRenderStarted; feed.OnRenderEnded -= HandleRenderEnded; }
protected override void ReleaseOutput() { frames.unusedFrames.ForEach(f => { if (f.data != null) { f.data.Release(); } }); frames.usedFrames.ForEach(f => { if (f.data != null) { f.data.Release(); } }); frames = null; if (LastFrameAlpha != null) { LastFrameAlpha.Release(); LastFrameAlpha = null; grabAlphaCommand.Clear(); } finalizeFrameCommand.Clear(); base.ReleaseOutput(); }
protected override void OnDisable() { frames = null; ClearTexture(); base.OnDisable(); }
protected override void OnDisable() { ActiveFeeds.Remove(this); frames = null; ClearTexture(); base.OnDisable(); }
protected override void OnEnable() { frames = new FrameDelayQueue <FramePlayerData>(); ActiveFeeds.Add(this); base.OnEnable(); Invoke("HandleDataChanged", 0.01f); }
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(); } }
protected override void OnEnable() { if (cam == null) { cam = GetComponentInParent <MixCastCamera>(); } frames = new FrameDelayQueue <FramePlayerData>(); base.OnEnable(); Invoke("HandleDataChanged", 0.01f); }
private void OnEnable() { if (feed == null) { feed = GetComponentInParent <InputFeed>(); } layerNum = LayerMask.NameToLayer(playerLayerName); frames = new FrameDelayQueue <FrameLightingData>(); feed.OnRenderStarted += HandleRenderStarted; feed.OnRenderEnded += HandleRenderEnded; }
protected override void BuildOutput() { base.BuildOutput(); frames = new FrameDelayQueue <GameFrame>(); frames.delayDuration = context.Data.bufferTime; frames.AllocateFrames(); if (MixCast.ProjectSettings.grabUnfilteredAlpha) { LastFrameAlpha = new RenderTexture(Output.width, Output.height, 0); LastFrameAlpha.autoGenerateMips = LastFrameAlpha.useMipMap = false; LastFrameAlpha.Create(); grabAlphaCommand.Blit(BuiltinRenderTextureType.CurrentActive, LastFrameAlpha); } finalizeFrameCommand.Blit(Output as RenderTexture, BuiltinRenderTextureType.CurrentActive); }
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); } }
FrameLightingData PrepareNextFrame() { FrameDelayQueue <FrameLightingData> .Frame <FrameLightingData> nextFrame = frames.GetNewFrame(); if (nextFrame.data == null) { nextFrame.data = new FrameLightingData(); } if (nextFrame.data.directionalLightDirections == null || nextFrame.data.directionalLightDirections.Length != DIR_LIGHT_ARRAY_MAX) { nextFrame.data.directionalLightDirections = new Vector4[DIR_LIGHT_ARRAY_MAX]; } if (nextFrame.data.directionalLightColors == null || nextFrame.data.directionalLightColors.Length != DIR_LIGHT_ARRAY_MAX) { nextFrame.data.directionalLightColors = new Vector4[DIR_LIGHT_ARRAY_MAX]; } if (nextFrame.data.pointLightPositions == null || nextFrame.data.pointLightPositions.Length != POINT_LIGHT_ARRAY_MAX) { nextFrame.data.pointLightPositions = new Vector4[POINT_LIGHT_ARRAY_MAX]; } if (nextFrame.data.pointLightColors == null || nextFrame.data.pointLightColors.Length != POINT_LIGHT_ARRAY_MAX) { nextFrame.data.pointLightColors = new Vector4[POINT_LIGHT_ARRAY_MAX]; } if (nextFrame.data.spotLightPositions == null || nextFrame.data.spotLightPositions.Length != SPOT_LIGHT_ARRAY_MAX) { nextFrame.data.spotLightPositions = new Vector4[SPOT_LIGHT_ARRAY_MAX]; } if (nextFrame.data.spotLightDirections == null || nextFrame.data.spotLightDirections.Length != SPOT_LIGHT_ARRAY_MAX) { nextFrame.data.spotLightDirections = new Vector4[SPOT_LIGHT_ARRAY_MAX]; } if (nextFrame.data.spotLightColors == null || nextFrame.data.spotLightColors.Length != SPOT_LIGHT_ARRAY_MAX) { nextFrame.data.spotLightColors = new Vector4[SPOT_LIGHT_ARRAY_MAX]; } return(nextFrame.data); }
void FillTrackingData(FrameDelayQueue <FramePlayerData> .Frame <FramePlayerData> frame) { MixCastCamera cam = MixCastCamera.FindCamera(context); if (cam != null && cam.gameCamera != null) { frame.data.playerDist = cam.gameCamera.transform.TransformVector(Vector3.forward).magnitude *CalculatePlayerDistance(cam.gameCamera); //Scale distance by camera scale } frame.data.playerHeadPos = GetTrackingPosition(TrackedDeviceManager.DeviceRole.Head); frame.data.playerBasePos = new Vector3(frame.data.playerHeadPos.x, 0, frame.data.playerHeadPos.z); frame.data.playerLeftHandPos = GetTrackingPosition(TrackedDeviceManager.DeviceRole.LeftHand); frame.data.playerRightHandPos = GetTrackingPosition(TrackedDeviceManager.DeviceRole.RightHand); if (MixCastCameras.Instance.RoomTransform != null) { Transform roomTransform = MixCastCameras.Instance.RoomTransform; frame.data.playerHeadPos = roomTransform.TransformPoint(frame.data.playerHeadPos); frame.data.playerBasePos = roomTransform.TransformPoint(frame.data.playerBasePos); frame.data.playerLeftHandPos = roomTransform.TransformPoint(frame.data.playerLeftHandPos); frame.data.playerRightHandPos = roomTransform.TransformPoint(frame.data.playerRightHandPos); } }
protected override void ReleaseOutput() { frames.unusedFrames.ForEach(f => { if (f.data != null && f.data.backgroundBuffer != null) { f.data.backgroundBuffer.Release(); } if (f.data != null && f.data.foregroundBuffer != null) { f.data.foregroundBuffer.Release(); } }); frames.usedFrames.ForEach(f => { if (f.data != null && f.data.backgroundBuffer != null) { f.data.backgroundBuffer.Release(); } if (f.data != null && f.data.foregroundBuffer != null) { f.data.foregroundBuffer.Release(); } }); frames = null; if (lastFrameAlpha != null) { lastFrameAlpha.Release(); lastFrameAlpha = null; grabAlphaCommand.Clear(); } finalizeFrameCommand.Clear(); base.ReleaseOutput(); }
protected virtual void Awake() { processTextureMat = new Material(Shader.Find("Hidden/MixCast/Process Input")); frames = null; }
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(); } }
private void OnApplicationQuit() { frames = null; ClearTexture(); }