protected override void FileTypeAndFormatGUI()
        {
            EditorGUILayout.PropertyField(m_OutputFormat, Styles.FormatLabel);
            var imageSettings = (ImageRecorderSettings)target;

            if (!UnityHelpers.UsingURP())
            {
                using (new EditorGUI.DisabledScope(!imageSettings.CanCaptureAlpha()))
                {
                    EditorGUILayout.PropertyField(m_CaptureAlpha, Styles.CaptureAlphaLabel);
                }
            }

            string[] list_of_colorspaces = new[] { "sRGB, sRGB", "Linear, sRGB (unclamped)" };

            if (imageSettings.CanCaptureHDRFrames())
            {
                m_ColorSpace.intValue =
                    EditorGUILayout.Popup(Styles.ColorSpace, m_ColorSpace.intValue, list_of_colorspaces);
            }
            else
            {
                // Disable the dropdown but show sRGB
                using (new EditorGUI.DisabledScope(!imageSettings.CanCaptureHDRFrames()))
                    EditorGUILayout.Popup(Styles.ColorSpace, 0, list_of_colorspaces);
            }

            if ((ImageRecorderSettings.ImageRecorderOutputFormat)m_OutputFormat.enumValueIndex ==
                ImageRecorderSettings.ImageRecorderOutputFormat.EXR)
            {
                EditorGUILayout.PropertyField(m_EXRCompression, Styles.CLabel);
            }
        }
 void CleanupSettingsAsset()
 {
     UnityHelpers.Destroy(m_WindowSettingsAsset, true);
     m_WindowSettingsAsset = ScriptableObject.CreateInstance <RecorderWindowSettings>();
     AssetDatabase.CreateAsset(m_WindowSettingsAsset, FRPackagerPaths.GetRecorderRootPath() + "/RecorderWindowSettings.asset");
     AssetDatabase.Refresh();
 }
        IEnumerator FrameRequest()
        {
            yield return(new WaitForEndOfFrame());

            if (currentState == State.WaitingForFirstFrame)
            {
                #if HDRP_AVAILABLE
                if (UnityHelpers.UsingHDRP())
                {
                    Camera[] cams = Camera.allCameras;
                    foreach (var c in cams)
                    {
                        HDCamera hdcam = HDCamera.GetOrCreate(c);
                        HDAdditionalCameraData hdCameraData = c.GetComponent <HDAdditionalCameraData>();
                        if (hdcam != null && hdCameraData != null && hdCameraData.antialiasing == HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing)
                        {
                            hdcam.Reset();
                        }
                    }
                }
                #endif
                // We need to wait one more frame to overcome the GameView resolution change
                // REC-589
                yield return(new WaitForEndOfFrame());
            }

            FrameReady();

            if (currentState == State.WaitingForFirstFrame)
            {
                EnterRunningState();
            }

            frameProducedCount++;
        }
Пример #4
0
        void BuildInputEditors()
        {
            var rs = target as RecorderSettings;

            if (!rs.inputsSettings.hasBrokenBindings && rs.inputsSettings.Count == m_InputEditors.Count)
            {
                return;
            }

            if (rs.inputsSettings.hasBrokenBindings)
            {
                rs.BindSceneInputSettings();
            }

            foreach (var editor in m_InputEditors)
            {
                UnityHelpers.Destroy(editor.editor);
            }
            m_InputEditors.Clear();

            foreach (var input in rs.inputsSettings)
            {
                m_InputEditors.Add(new InputEditorState(GetFieldDisplayState, input)
                {
                    visible = true
                });
            }
        }
Пример #5
0
        static Texture2D LoadIcon(string iconName)
        {
            if (string.IsNullOrEmpty(iconName))
            {
                return(null);
            }

            Texture2D icon;

            if (s_IconCache.TryGetValue(iconName, out icon))
            {
                return(icon);
            }

            if (EditorGUIUtility.isProSkin)
            {
                icon = UnityHelpers.LoadLocalPackageAsset <Texture2D>($"d_{iconName}.png", false);
            }

            if (icon == null)
            {
                icon = UnityHelpers.LoadLocalPackageAsset <Texture2D>($"{iconName}.png", false);
            }

            s_IconCache[iconName] = icon;

            return(icon);
        }
Пример #6
0
 public void Dispose()
 {
     UnityHelpers.Destroy(m_WorkTexture);
     m_WorkTexture = null;
     UnityHelpers.Destroy(m_VFLipMaterial);
     m_VFLipMaterial = null;
 }
        public void OnRecorderSelected()
        {
            if (m_Editor != null)
            {
                UnityHelpers.Destroy(m_Editor);
                m_Editor = null;
            }

            if (m_recorderSelector.selectedRecorder == null)
            {
                return;
            }

            m_Category = m_recorderSelector.category;

            if (m_WindowSettingsAsset.m_Settings != null &&
                RecordersInventory.GetRecorderInfo(m_recorderSelector.selectedRecorder).settingsClass != m_WindowSettingsAsset.m_Settings.GetType())
            {
                CleanupSettingsAsset();
            }

            if (m_WindowSettingsAsset.m_Settings == null)
            {
                m_WindowSettingsAsset.m_Settings = RecordersInventory.GenerateRecorderInitialSettings(m_WindowSettingsAsset, m_recorderSelector.selectedRecorder);
            }
            m_Editor = Editor.CreateEditor(m_WindowSettingsAsset.m_Settings) as RecorderEditor;
            AssetDatabase.Refresh();
        }
Пример #8
0
        void DeleteRecorder(RecorderItem item)
        {
            var s = item.settings;

            m_ControllerSettings.RemoveRecorder(s);
            UnityHelpers.Destroy(item.editor, true);
            m_RecordingListItem.Remove(item);
        }
Пример #9
0
        public static string GetRecorderVersionFilePath()
        {
            var dummy = ScriptableObject.CreateInstance <RecorderVersion>();
            var path  = Application.dataPath + AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(dummy)).Substring("Assets".Length);

            UnityHelpers.Destroy(dummy);
            return(path);
        }
Пример #10
0
        public override void RecordFrame(RecordingSession session)
        {
            if (m_Inputs.Count != 1)
                throw new Exception("Unsupported number of sources");

            Texture2D tex = null;
            if (m_Inputs[0] is GameViewInput)
            {
                tex = ((GameViewInput)m_Inputs[0]).image;
                if (m_Settings.outputFormat == ImageRecorderOutputFormat.EXR)
                {
                    var textx = new Texture2D(tex.width, tex.height, TextureFormat.RGBAFloat, false);
                    textx.SetPixels(tex.GetPixels());
                    tex = textx;
                }
                else if (m_Settings.outputFormat == ImageRecorderOutputFormat.PNG)
                {
                    var textx = new Texture2D(tex.width, tex.height, TextureFormat.RGB24, false);
                    textx.SetPixels(tex.GetPixels());
                    tex = textx;
                }
            }
            else
            {
                var input = (BaseRenderTextureInput)m_Inputs[0];
                var width = input.outputRT.width;
                var height = input.outputRT.height;
                tex = new Texture2D(width, height, m_Settings.outputFormat != ImageRecorderOutputFormat.EXR ? TextureFormat.RGBA32 : TextureFormat.RGBAFloat, false);
                var backupActive = RenderTexture.active;
                RenderTexture.active = input.outputRT;
                tex.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);
                tex.Apply();
                RenderTexture.active = backupActive;
            }

            byte[] bytes;
            switch (m_Settings.outputFormat)
            {
                case ImageRecorderOutputFormat.PNG:
                    bytes = tex.EncodeToPNG();
                    break;
                case ImageRecorderOutputFormat.JPEG:
                    bytes = tex.EncodeToJPG();
                    break;
                case ImageRecorderOutputFormat.EXR:
                    bytes = tex.EncodeToEXR();
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            if(m_Inputs[0] is BaseRenderTextureInput || m_Settings.outputFormat != ImageRecorderOutputFormat.JPEG)
                UnityHelpers.Destroy(tex);

            var path = m_Settings.fileNameGenerator.BuildAbsolutePath(session);

            File.WriteAllBytes( path, bytes);
        }
        public void Dispose()
        {
            if (recorder != null)
            {
                EndRecording();

                UnityHelpers.Destroy(recorder);
            }
        }
Пример #12
0
        public static string GetFrameRecorderPath()
        {
            var dummy = ScriptableObject.CreateInstance <FRPackagerPaths>();
            var path  = Application.dataPath + AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(dummy)).Substring("Assets".Length);

            UnityHelpers.Destroy(dummy);

            return(path.Replace("/Framework/Packager/Editor/FRPackagerPaths.cs", ""));
        }
        /// <summary>
        /// This is the main entry point for drawing the Recorder editor in the inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            if (target == null)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();
            serializedObject.Update();
            if (DrawCaptureSection())
            {
                showCapture.value = DrawHeaderFoldout(Styles.CaptureLabel, showCapture, false);
                if (showCapture)
                {
                    EditorGUILayout.Separator();
                    AOVGUI();
                    ImageRenderOptionsGUI();
                    ExtraOptionsGUI();
#if HDRP_ACCUM_API
                    if (UnityHelpers.UsingHDRP())
                    {
                        AccumulationGUI();
                    }
#endif
                    EditorGUILayout.Separator();
                }
            }

            showFormat.value = DrawHeaderFoldout(Styles.FormatLabel, showFormat, false);
            if (showFormat)
            {
                EditorGUILayout.Separator();
                FileTypeAndFormatGUI();
                OnEncodingGui();
                EditorGUILayout.Separator();
            }
            showOutputFile.value = DrawHeaderFoldout(Styles.OutputFileLabel, showOutputFile, false);
            if (showOutputFile)
            {
                EditorGUILayout.Separator();
                NameAndPathGUI();
                EditorGUILayout.Separator();
            }

            EditorGUILayout.Separator();
            serializedObject.ApplyModifiedProperties();

            EditorGUI.EndChangeCheck();

            if (GUI.changed)
            {
                ((RecorderSettings)target).SelfAdjustSettings();
            }

            OnValidateSettingsGUI();
        }
Пример #14
0
 internal void Flip(RenderTexture target)
 {
     if (m_WorkTexture == null || m_WorkTexture.width != target.width || m_WorkTexture.height != target.height)
     {
         UnityHelpers.Destroy(m_WorkTexture);
         m_WorkTexture = new RenderTexture(target.width, target.height, target.depth, target.format, RenderTextureReadWrite.Linear);
     }
     Graphics.Blit(target, m_WorkTexture, m_VFLipMaterial);
     Graphics.Blit(m_WorkTexture, target);
 }
        void ResetSettings()
        {
            UnityHelpers.Destroy(m_Editor);
            m_Editor           = null;
            m_recorderSelector = null;
            var path = AssetDatabase.GetAssetPath(m_WindowSettingsAsset);

            UnityHelpers.Destroy(m_WindowSettingsAsset, true);
            AssetDatabase.DeleteAsset(path);
            AssetDatabase.Refresh(ImportAssetOptions.Default);
            m_WindowSettingsAsset = null;
        }
        // <summary>
        // Prepares a frame before recording it. Callback is invoked for every frame during the recording session, before RecordFrame.
        // </summary>
        // <param name="ctx">The current recording session.</param>
        protected internal override void PrepareNewFrame(RecordingSession ctx)
        {
            base.PrepareNewFrame(ctx);
#if HDRP_ACCUM_API
            if (UnityHelpers.CaptureAccumulation(settings))
            {
                if (RenderPipelineManager.currentPipeline is HDRenderPipeline hdPipeline)
                {
                    hdPipeline.PrepareNewSubFrame();
                }
            }
#endif
        }
Пример #17
0
        protected override void ImageRenderOptionsGUI()
        {
            var recorder = (RecorderSettings)target;

            foreach (var inputsSetting in recorder.InputsSettings)
            {
                var audioSettings = inputsSetting as AudioInputSettings;
                using (new EditorGUI.DisabledScope(audioSettings != null && UnityHelpers.CaptureAccumulation(recorder)))
                {
                    var p = GetInputSerializedProperty(serializedObject, inputsSetting);
                    EditorGUILayout.PropertyField(p, Styles.SourceLabel);
                }
            }
        }
Пример #18
0
        void UpdateInternal()
        {
            if (!EditorApplication.isPlaying)
            {
                if (m_State == State.Recording)
                {
                    StopRecordingInternal();
                }
            }
            else if (m_State == State.WaitingForScenesData && UnityHelpers.AreAllSceneDataLoaded())
            {
                StartRecordingInternal();
            }

            var enable = !ShouldDisableRecordSettings();

            m_AddNewRecordPanel.SetEnabled(enable);
            m_ParametersControl.SetEnabled(enable && m_SelectedRecorderItem != null && m_SelectedRecorderItem.state != RecorderItem.State.HasErrors);
            m_RecordModeOptionsPanel.SetEnabled(enable);
            m_FrameRateOptionsPanel.SetEnabled(enable);

            if (HaveActiveRecordings())
            {
                if (IsRecording())
                {
                    SetRecordButtonsEnabled(EditorApplication.isPlaying && Time.frameCount - m_FrameCount > 5.0f);
                }
                else
                {
                    SetRecordButtonsEnabled(true);
                }
            }
            else
            {
                SetRecordButtonsEnabled(false);
            }

            UpdateRecordButtonText();

            if (m_State == State.Recording)
            {
                if (!m_RecorderController.IsRecording())
                {
                    StopRecordingInternal();
                }

                Repaint();
            }
        }
Пример #19
0
 void StopRecording()
 {
     if (m_Editor != null)
     {
         var settings = (RecorderSettings)m_Editor.target;
         if (settings != null)
         {
             var recorderGO = SceneHook.FindRecorder(settings);
             if (recorderGO != null)
             {
                 UnityHelpers.Destroy(recorderGO);
             }
         }
     }
 }
Пример #20
0
        void DeleteRecorder(RecorderItem item, bool prompt)
        {
            if (!prompt || EditorUtility.DisplayDialog("Delete Recoder?",
                                                       "Are you sure you want to delete '" + item.settings.name + "' ?", "Delete", "Cancel"))
            {
                var s = item.settings;
                m_ControllerSettings.RemoveRecorder(s);
                UnityHelpers.Destroy(s, true);
                UnityHelpers.Destroy(item.editor, true);
                m_RecordingListItem.Remove(item);
            }

            if (prompt)
            {
                Focus();
            }
        }
 void StopRecording()
 {
     if (m_Editor != null)
     {
         var settings = (RecorderSettings)m_Editor.target;
         if (settings != null)
         {
             var recorderGO = SceneHook.FindRecorder(settings);
             if (recorderGO != null)
             {
                 UnityHelpers.Destroy(recorderGO);
             }
         }
     }
     m_FrameCount = 0;
     m_State      = EState.Idle;
 }
        protected override void Initialize(SerializedProperty property)
        {
            if (s_OpenPathIcon == null)
            {
                var iconName = "popout_icon";
                if (EditorGUIUtility.isProSkin)
                {
                    iconName = "d_" + iconName;
                }

                s_OpenPathIcon = UnityHelpers.LoadLocalPackageAsset <Texture2D>($"{iconName}.png", true);
            }

            base.Initialize(property);

            m_FileName = property.FindPropertyRelative("m_FileName");
            m_Path     = property.FindPropertyRelative("m_Path");
        }
Пример #23
0
        internal void Flip(RenderTexture target)
        {
            if (m_WorkTexture == null || m_WorkTexture.width != target.width || m_WorkTexture.height != target.height)
            {
                UnityHelpers.Destroy(m_WorkTexture);
                m_WorkTexture = new RenderTexture(target);
            }

            var sRGBWrite = GL.sRGBWrite;
            GL.sRGBWrite = PlayerSettings.colorSpace == ColorSpace.Linear;
            
            Graphics.Blit(target, m_WorkTexture, new Vector2(1.0f, -1.0f), new Vector2(0.0f, 1.0f));
            Graphics.Blit(m_WorkTexture, target);
            
            

            GL.sRGBWrite = sRGBWrite;
        }
        static GameObject GetSessionHooksRoot(bool createIfNecessary = true)
        {
            if (s_SessionHooksRoot == null)
            {
                s_SessionHooksRoot = GameObject.Find(k_HostGoName);

                if (s_SessionHooksRoot == null)
                {
                    if (!createIfNecessary)
                    {
                        return(null);
                    }

                    s_SessionHooksRoot = UnityHelpers.CreateRecorderGameObject(k_HostGoName);
                }
            }

            return(s_SessionHooksRoot);
        }
        protected internal override void RecordFrame(RecordingSession session)
        {
            if (m_Inputs.Count != 2)
            {
                throw new Exception("Unsupported number of sources");
            }

            if (!m_RecordingStartedProperly)
            {
                return; // error will have been triggered in BeginRecording()
            }
            base.RecordFrame(session);
            var audioInput = (AudioInput)m_Inputs[1];

            if (audioInput.audioSettings.PreserveAudio && !UnityHelpers.CaptureAccumulation(settings))
            {
                Settings.m_EncoderManager.AddSamples(m_EncoderHandle, audioInput.mainBuffer);
            }
        }
Пример #26
0
        protected override void WriteFrame(Texture2D tex)
        {
            byte[] bytes;

            Profiler.BeginSample("AOVRecorder.EncodeImage");
            try
            {
                switch (Settings.m_OutputFormat)
                {
                case ImageRecorderSettings.ImageRecorderOutputFormat.EXR:
                {
                    bytes = tex.EncodeToEXR(ImageRecorderSettings.ToNativeType(Settings.EXRCompression));
                    WriteToFile(bytes);
                    break;
                }

                case ImageRecorderSettings.ImageRecorderOutputFormat.PNG:
                    bytes = tex.EncodeToPNG();
                    WriteToFile(bytes);
                    break;

                case ImageRecorderSettings.ImageRecorderOutputFormat.JPEG:
                    bytes = tex.EncodeToJPG();
                    WriteToFile(bytes);
                    break;

                default:
                    Profiler.EndSample();
                    throw new ArgumentOutOfRangeException();
                }
            }
            finally
            {
                Profiler.EndSample();
            }

            if (m_Inputs[0] is BaseRenderTextureInput || Settings.m_OutputFormat != ImageRecorderSettings.ImageRecorderOutputFormat.JPEG)
            {
                UnityHelpers.Destroy(tex);
            }
        }
        public static void Set(string id, Object obj)
        {
            var rbs = FindRecorderBindings();

            if (obj == null)
            {
                // Remove
                foreach (var rb in rbs)
                {
                    RemoveBinding(id, rb);
                }
            }
            else
            {
                var scene = GetObjectScene(obj);

                var rb = rbs.FirstOrDefault(r => r.gameObject.scene == scene);

                if (rb == null)
                {
                    // Add
                    var gameObject = UnityHelpers.CreateRecorderGameObject(k_HostGoName);
                    rb = gameObject.AddComponent <RecorderBindings>();
                    SceneManager.MoveGameObjectToScene(rb.gameObject, scene);
                }

                // Replace
                rb.SetBindingValue(id, obj);

                foreach (var r in rbs)
                {
                    if (r == rb)
                    {
                        continue;
                    }

                    RemoveBinding(id, r);
                }
            }
        }
        /// <inheritdoc/>
        protected internal override void EndRecording(RecordingSession session)
        {
            base.EndRecording(session);
#if HDRP_ACCUM_API
            if (UnityHelpers.CaptureAccumulation(settings))
            {
                if (RenderPipelineManager.currentPipeline is HDRenderPipeline hdPipeline)
                {
                    hdPipeline.EndRecording();
                }
            }
#endif
            if (m_OngoingAsyncGPURequestsCount > 0)
            {
                Recording = true;
                m_DelayedEncoderDispose = true;
            }
            else
            {
                DisposeEncoder();
            }
        }
 /// <summary>
 /// Releases the encoder resources.
 /// </summary>
 protected virtual void DisposeEncoder()
 {
     UnityHelpers.Destroy(m_ReadbackTexture);
     Recording = false;
 }
Пример #30
0
 public void Dispose()
 {
     UnityHelpers.Destroy(m_WorkTexture);
     m_WorkTexture = null;
 }