示例#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);
        }
示例#2
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);
        }