Esempio n. 1
0
        private Color[] ReadBack(RenderTexture renderTexture)
        {
            Color[] inputs  = VFXToolboxUtility.ReadBack(renderTexture);
            Color[] outputs = new Color[inputs.Length];

            for (int j = 0; j < inputs.Length; j++)
            {
                if (QualitySettings.activeColorSpace == ColorSpace.Gamma)
                {
                    outputs[j] = inputs[j];
                }
                else
                {
                    if ((!m_CurrentAsset.exportSettings.sRGB) || m_CurrentAsset.exportSettings.highDynamicRange)
                    {
                        outputs[j] = inputs[j];
                    }
                    else
                    {
                        outputs[j] = inputs[j].gamma;
                    }
                }
            }

            return(outputs);
        }
        private bool HandleDropData()
        {
            if(m_CurrentAsset == null)
                return false;

            if(sidePanelViewMode == SidePanelMode.InputFrames && DragAndDrop.paths.Length > 0)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                if( Event.current.type == EventType.DragExited)
                {
                    List<string> texturePaths = new List<string>();
                    foreach(string path in DragAndDrop.paths)
                    {
                        if (VFXToolboxUtility.IsDirectory(path))
                            texturePaths.AddRange(VFXToolboxUtility.GetAllTexturesInPath(path));
                        else
                        {
                            VFXToolboxGUIUtility.DisplayProgressBar("Image Sequencer", "Discovering Assets...", 0.5f);
                            Texture2D t = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
                            if(t != null)
                                texturePaths.Add(path);
                        }
                    }
                    AddInputFrame(m_InputFramesReorderableList, texturePaths);
                    VFXToolboxGUIUtility.ClearProgressBar();
                    return true;
                }
            }
            return false;
        }
Esempio n. 3
0
        private void FindProperValues(float threshold, ref SerializedProperty top, ref SerializedProperty bottom, ref SerializedProperty left, ref SerializedProperty right)
        {
            int width  = InputSequence.width;
            int height = InputSequence.height;

            int minX = width;
            int maxX = 0;
            int minY = height;
            int maxY = 0;

            Color[]       colors;
            RenderTexture tempRT = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);

            for (int i = 0; i < InputSequence.frames.Count; i++)
            {
                ProcessingFrame f = InputSequence.frames[i];

                VFXToolboxGUIUtility.DisplayProgressBar("Crop processor", "Evaluating closest bound (Frame #" + i + " on " + InputSequence.frames.Count + "...)", (float)i / InputSequence.frames.Count);
                if (InputSequence.processor != null)
                {
                    f.Process();
                    colors = VFXToolboxUtility.ReadBack(f.texture as RenderTexture);
                }
                else
                {
                    Graphics.Blit(f.texture, tempRT);
                    colors = VFXToolboxUtility.ReadBack(tempRT);
                }

                // Check frame
                for (int j = 0; j < colors.Length; j++)
                {
                    int x = j % width;
                    int y = j / width;
                    if (colors[j].a >= threshold)
                    {
                        minX = Mathf.Min(minX, x);
                        maxX = Mathf.Max(maxX, x);
                        minY = Mathf.Min(minY, y);
                        maxY = Mathf.Max(maxY, y);
                    }
                }
            }
            VFXToolboxGUIUtility.ClearProgressBar();

            bottom.intValue = minY;
            top.intValue    = height - maxY - 1;
            left.intValue   = minX;
            right.intValue  = width - maxX - 1;

            RenderTexture.ReleaseTemporary(tempRT);
        }
        public override bool OnInspectorGUI(bool changed, SerializedObject serializedObject)
        {
            var bgColor = serializedObject.FindProperty("BackgroundColor");

            EditorGUI.BeginChangeCheck();

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PropertyField(bgColor, VFXToolboxGUIUtility.Get("Background Color"));
                if (GUILayout.Button(VFXToolboxGUIUtility.Get("Grab"), GUILayout.Width(40)))
                {
                    if (inputSequenceLength > 0)
                    {
                        var texture = RequestInputTexture(0);

                        Color background;

                        if (texture is RenderTexture)
                        {
                            background = VFXToolboxUtility.ReadBack((RenderTexture)texture)[0];
                        }
                        else
                        {
                            Texture2D     inputFrame = (Texture2D)texture;
                            RenderTexture rt         = RenderTexture.GetTemporary(inputFrame.width, inputFrame.height, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
                            Graphics.Blit(inputFrame, rt);
                            background = VFXToolboxUtility.ReadBack(rt)[0];
                            RenderTexture.ReleaseTemporary(rt);
                        }

                        if (QualitySettings.activeColorSpace == ColorSpace.Linear)
                        {
                            background = background.gamma;
                        }

                        bgColor.colorValue = background;
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                UpdateOutputSize();
                Invalidate();
                changed = true;
            }
            GUILayout.Space(20);
            EditorGUILayout.HelpBox("Please select a color corresponding to the solid background of the flipbook to try to reconstruct the pixel's color. \n\nThis filter will only work if your flipbook was rendered on a solid color background. Try the Grab button to fetch the upper left pixel of the first frame, or use the color picker.", MessageType.Info);

            return(changed);
        }
        private Color[] ReadBack(RenderTexture renderTexture)
        {
            Color[] inputs = VFXToolboxUtility.ReadBack(renderTexture);

            if (QualitySettings.activeColorSpace == ColorSpace.Linear && m_CurrentAsset.exportSettings.sRGB)
            {
                Color[] outputs = new Color[inputs.Length];
                for (int j = 0; j < inputs.Length; j++)
                {
                    outputs[j] = inputs[j].gamma;
                }
                return(outputs);
            }
            return(inputs);
        }
Esempio n. 6
0
        private void AddInputFrame(ReorderableList list)
        {
            if (Selection.activeObject == null)
            {
                Debug.LogWarning("Could not add frames with no selection : please select input frames to add in the project view and click the add button. Or drag & drop directly into the Image Sequencer Editor Window");
                return;
            }

            string[]      guids;
            List <string> names = new List <string>();

            if (VFXToolboxUtility.IsDirectorySelected())
            {
                names.AddRange(VFXToolboxUtility.GetAllTexturesInPath(AssetDatabase.GetAssetPath(Selection.activeObject)));
            }
            else
            {
                guids = Selection.assetGUIDs;
                foreach (string s in guids)
                {
                    string    path = AssetDatabase.GUIDToAssetPath(s);
                    Texture2D t    = AssetDatabase.LoadAssetAtPath <Texture2D>(path);
                    if (t != null)
                    {
                        names.Add(path);
                    }
                }
            }

            if (names.Count > 0)
            {
                Undo.RecordObject(m_CurrentAsset, "Add Input Frames");
                AddInputFrame(list, names);
            }
            else
            {
                Debug.LogWarning("No suitable textures found in selection, make sure you selected either a directory containing textures or texture themselves in project view.");
            }
        }