Ejemplo n.º 1
0
        protected override void Enable()
        {
            base.Enable();

            minMaxBuffer = new ComputeBuffer(1, sizeof(float) * 2, ComputeBufferType.Structured);
            HistogramUtility.AllocateHistogramData(histogramBucketCount, histogramMode, out histogramData);
        }
Ejemplo n.º 2
0
        protected override bool ProcessNode(CommandBuffer cmd)
        {
            if (!base.ProcessNode(cmd) || input == null)
            {
                return(false);
            }

            HistogramUtility.ComputeLuminanceMinMax(cmd, minMaxBuffer, input);
            TextureUtils.UpdateTextureFromCurve(interpolationCurve, ref curveTexture);

            var mat = tempRenderTexture.material = GetTempMaterial("Hidden/Mixture/Levels");

            mat.SetFloat("_Mode", (int)mode);
            mat.SetFloat("_ManualMin", min);
            mat.SetFloat("_ManualMax", max);
            mat.SetVector("_RcpTextureSize", new Vector4(1.0f / input.width, 1.0f / input.height, 1.0f / TextureUtils.GetSliceCount(input), 0));
            MixtureUtils.SetupDimensionKeyword(mat, tempRenderTexture.dimension);
            MixtureUtils.SetTextureWithDimension(mat, "_Input", input);
            mat.SetBuffer("_Luminance", minMaxBuffer);
            mat.SetTexture("_InterpolationCurve", curveTexture);

            tempRenderTexture.Update();
            CustomTextureManager.UpdateCustomRenderTexture(cmd, tempRenderTexture);

            output = tempRenderTexture;

            return(true);
        }
Ejemplo n.º 3
0
            protected override void ImmediateRepaint()
            {
                HistogramUtility.SetupHistogramPreviewMaterial(data);
                EditorGUI.DrawPreviewTexture(contentRect, Texture2D.whiteTexture, data.previewMaterial);

                // We can also write stuff in the histogram graph with GUI. functions
                // GUI.Label(contentRect, "Hello world");
            }
Ejemplo n.º 4
0
 protected override void Disable()
 {
     base.Disable();
     HistogramUtility.Dispose(histogramData);
     minMaxBuffer?.Dispose();
 }
Ejemplo n.º 5
0
        public override void Enable(bool fromInspector)
        {
            base.Enable(fromInspector);

            node = nodeTarget as PreviewNode;

            var colorPickerValues = new Label();

            colorPickerValues.AddToClassList("Indent");
            if (!fromInspector)
            {
                controlsContainer.Add(colorPickerValues);

                // Stop right click when the mouse is over the preview because we use it for light position
                previewContainer.RegisterCallback <ContextualMenuPopulateEvent>(e => {
                    e.StopImmediatePropagation();
                }, TrickleDown.TrickleDown);
                previewContainer.AddManipulator(new ContextualMenuManipulator(evt => {}));
            }
            else
            {
                owner.graph.afterCommandBufferExecuted += UpdateViewData;
                controlsContainer.RegisterCallback <DetachFromPanelEvent>(e => {
                    owner.graph.afterCommandBufferExecuted -= UpdateViewData;
                });
                var histogram = new HistogramView(node.histogramData, owner);
                controlsContainer.Add(histogram);
            }

            void UpdateViewData()
            {
                if (node.output != null)
                {
                    // Update histogram
                    var cmd = CommandBufferPool.Get("Update Histogram");
                    HistogramUtility.ComputeHistogram(cmd, node.output, node.histogramData);
                    Graphics.ExecuteCommandBuffer(cmd);

                    // Update color picker data
                    UpdateColorPickerValues();
                }
            }

            void UpdateColorPickerValues()
            {
                int texturePosX = Mathf.RoundToInt(node.mousePosition.x * node.output.width);
                int texturePosY = Mathf.RoundToInt(node.mousePosition.y * node.output.height);

                texturePosX = Mathf.Clamp(texturePosX, 0, node.output.width - 1);
                texturePosY = Mathf.Clamp(texturePosY, 0, node.output.height - 1);

                var a = AsyncGPUReadback.Request(node.output, 0, texturePosX, 1, texturePosY, 1, 0, 1, (data) => {
                    var colors = data.GetData <Color>();
                    if (data.hasError || colors.Length == 0)
                    {
                        return;
                    }
                    var pixel = colors[0];
                    colorPickerValues.text = $"R: {pixel.r:F3} G: {pixel.g:F3} B: {pixel.b:F3} A: {pixel.a:F3}";
                });

                schedule.Execute(() => {
                    a.Update();
                }).Until(() => a.done);
            }

            var preview = previewContainer.Q("ImGUIPreview");

            preview.RegisterCallback <MouseMoveEvent>(e => {
                var localPos       = GetPreviewMousePositionRatio(e.mousePosition);
                node.mousePosition = localPos;
                UpdateColorPickerValues();

                if (e.imguiEvent.button == 1)
                {
                    NotifyNodeChanged();
                    node.lightPosition = (new Vector2(localPos.x, 1 - localPos.y) * 2 - Vector2.one) * node.tiling;
                }
            });

            // TODO: add source mip slider

            UpdateViewData();
            UpdateColorPickerValues();
        }
Ejemplo n.º 6
0
        public override void Enable(bool fromInspector)
        {
            levelsNode = nodeTarget as Levels;

            base.Enable(fromInspector);

            var slider = new MinMaxSlider("Luminance", levelsNode.min, levelsNode.max, 0, 1);

            sliders.Add(slider);
            slider.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Changed Luminance remap");
                levelsNode.min = e.newValue.x;
                levelsNode.max = e.newValue.y;
                foreach (var s in sliders)
                {
                    if (s != null && s.parent != null)
                    {
                        s.SetValueWithoutNotify(e.newValue);
                    }
                }
                NotifyNodeChanged();
            });
            controlsContainer.Add(slider);

            var mode = this.Q <EnumField>();

            mode.RegisterValueChangedCallback((m) => {
                UpdateMinMaxSliderVisibility((Levels.Mode)m.newValue);
            });
            UpdateMinMaxSliderVisibility(levelsNode.mode);

            // Compute histogram only when the inspector is selected
            if (fromInspector)
            {
                owner.graph.afterCommandBufferExecuted += UpdateHistogram;
                controlsContainer.RegisterCallback <DetachFromPanelEvent>(e => {
                    owner.graph.afterCommandBufferExecuted -= UpdateHistogram;
                });
            }

            void UpdateHistogram()
            {
                if (levelsNode.output != null)
                {
                    var cmd = CommandBufferPool.Get("Update Histogram");
                    HistogramUtility.ComputeHistogram(cmd, levelsNode.output, levelsNode.histogramData);
                    Graphics.ExecuteCommandBuffer(cmd);
                }
            }

            UpdateHistogram();

            void UpdateMinMaxSliderVisibility(Levels.Mode mode)
            {
                if (mode == Levels.Mode.Automatic)
                {
                    slider.style.display = DisplayStyle.None;
                }
                else
                {
                    slider.style.display = DisplayStyle.Flex;
                }
            }

            if (fromInspector)
            {
                var histogram = new HistogramView(levelsNode.histogramData, owner);
                controlsContainer.Add(histogram);
            }
        }