/// <inheritdoc/> protected internal override void NewFrameStarting(RecordingSession session) { m_InputStrategy.UnsetupCamera(); switch (cbSettings.Source) { case ImageSource.ActiveCamera: { if (TargetCamera == null) { var displayGO = new GameObject(); displayGO.name = "CameraHostGO-" + displayGO.GetInstanceID(); displayGO.transform.parent = session.recorderGameObject.transform; var camera = displayGO.AddComponent <Camera>(); camera.clearFlags = CameraClearFlags.Nothing; camera.cullingMask = 0; camera.renderingPath = RenderingPath.DeferredShading; camera.targetDisplay = 0; camera.rect = new Rect(0, 0, 1, 1); camera.depth = float.MaxValue; TargetCamera = camera; } break; } case ImageSource.MainCamera: { TargetCamera = Camera.main; break; } case ImageSource.TaggedCamera: { var tag = ((CameraInputSettings)settings).CameraTag; try { var objs = GameObject.FindGameObjectsWithTag(tag); var cams = objs.Select(obj => obj.GetComponent <Camera>()).Where(c => c != null); if (cams.Count() > 1) { Debug.LogWarning("More than one camera has the requested target tag '" + tag + "'"); } TargetCamera = cams.FirstOrDefault(); } catch (UnityException) { Debug.LogWarning("No camera has the requested target tag '" + tag + "'"); TargetCamera = null; } break; } } PrepFrameRenderTexture(session); bool needToFlip = true; var movieRecorderSettings = session.recorder.settings as MovieRecorderSettings; if (movieRecorderSettings != null) { var encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip; needToFlip = encoderAlreadyFlips; } if (UnityHelpers.UsingLegacyRP()) { m_InputStrategy.flipVertically = needToFlip; // regular pipeline } else { m_InputStrategy.flipVertically = !needToFlip; // scriptable render pipeline already flips input } m_InputStrategy.SetupCamera(OutputRenderTexture); }
/// <inheritdoc/> protected internal override void BeginRecording(RecordingSession session) { if (cbSettings.FlipFinalOutput) { m_VFlipper = new TextureFlipper(); } if (UnityHelpers.UsingLegacyRP()) { m_InputStrategy = new CameraCommandBufferLegacyInputStrategy(cbSettings.RecordTransparency); } else { m_InputStrategy = new CaptureCallbackSRPInputStrategy(cbSettings.RecordTransparency); } switch (cbSettings.Source) { case ImageSource.ActiveCamera: case ImageSource.MainCamera: case ImageSource.TaggedCamera: { OutputWidth = cbSettings.OutputWidth; OutputHeight = cbSettings.OutputHeight; if (cbSettings.outputImageHeight != ImageHeight.Window) { var size = GameViewSize.SetCustomSize(OutputWidth, OutputHeight); if (size == null) { size = GameViewSize.AddSize(OutputWidth, OutputHeight); } if (GameViewSize.modifiedResolutionCount == 0) { GameViewSize.BackupCurrentSize(); } else { if (size != GameViewSize.currentSize) { Debug.LogError($"Requesting a resolution change (to {OutputWidth}x{OutputHeight}) while a recorder's input has already requested one! Undefined behaviour. Count: {GameViewSize.modifiedResolutionCount}"); } } GameViewSize.modifiedResolutionCount++; m_ModifiedResolution = true; GameViewSize.SelectSize(size); } break; } default: throw new ArgumentOutOfRangeException(); } if (cbSettings.CaptureUI) { var uiGO = new GameObject(); uiGO.name = "UICamera"; uiGO.transform.parent = session.recorderGameObject.transform; m_UICamera = uiGO.AddComponent <Camera>(); m_UICamera.cullingMask = 1 << 5; m_UICamera.clearFlags = CameraClearFlags.Depth; m_UICamera.renderingPath = RenderingPath.DeferredShading; m_UICamera.targetTexture = OutputRenderTexture; m_UICamera.enabled = false; } }