Ejemplo n.º 1
0
        protected override void Process(TextureGraphData graphData)
        {
            var reds    = graphData.GetArray <float>();
            var greens  = graphData.GetArray <float>();
            var blues   = graphData.GetArray <float>();
            var alphas  = graphData.GetArray <float>();
            var vectors = graphData.GetArray <Vector4>();

            GetInput <Vector4>(vectors, graphData);
            for (var i = 0; i < vectors.Length; ++i)
            {
                reds[i]   = vectors[i].x;
                greens[i] = vectors[i].y;
                blues[i]  = vectors[i].z;
                alphas[i] = vectors[i].w;
            }
            var port = outputContainer.Q <Port>("Red");

            graphData.portDatas[port.persistenceKey] = reds;
            port = outputContainer.Q <Port>("Green");
            graphData.portDatas[port.persistenceKey] = greens;
            port = outputContainer.Q <Port>("Blue");
            graphData.portDatas[port.persistenceKey] = blues;
            port = outputContainer.Q <Port>("Alpha");
            graphData.portDatas[port.persistenceKey] = alphas;
        }
Ejemplo n.º 2
0
        protected override void Process(TextureGraphData graphData)
        {
            var inputs  = graphData.GetArray <Vector4>();
            var outputs = graphData.GetArray <Vector4>();

            GetInput <Vector4>(inputs, graphData);
            switch (m_EnumField.enumValue)
            {
            case BumpMapType.Normal:
                var width   = graphData.width;
                var height  = graphData.height;
                var length  = width * height;
                var heights = inputs.Select(v => ConvertToHeight(v).x).ToArray();
                outputs = heights.Select((h, i) => ConvertToNormal(heights[(i - width + length) % length], heights[(i + width) % length], heights[(i + 1) - (i % width == width - 1 ? width : 0)], heights[(i - 1) + (i % width == 0 ? width : 0)], width, height)).ToArray();
                break;

            case BumpMapType.Height:
                outputs = inputs.Select(ConvertToHeight).ToArray();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(BumpMapType));
            }
            var port = outputContainer.Q <Port>();

            graphData.portDatas[port.persistenceKey] = outputs;
        }
Ejemplo n.º 3
0
        protected override void Process(TextureGraphData graphData)
        {
            var vectors = graphData.GetArray <Vector4>();

            GetInput <Vector4>(vectors, graphData);
            m_Colors = Array.ConvertAll(vectors, v => (Color)v);
        }
Ejemplo n.º 4
0
        protected override void Process(TextureGraphData graphData)
        {
            var valueA = graphData.GetArray <Vector4>();
            var valueB = graphData.GetArray <Vector4>();
            var result = graphData.GetArray <Vector4>();

            GetInput <Vector4>(valueA, graphData, "A");
            GetInput <Vector4>(valueB, graphData, "B");
            switch (m_EnumField.enumValue)
            {
            case BlendMode.Normal:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => a)).ToArray();
                break;

            case BlendMode.Addition:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => a + b)).ToArray();
                break;

            case BlendMode.Difference:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => Math.Abs(a - b))).ToArray();
                break;

            case BlendMode.Multiply:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => a * b)).ToArray();
                break;

            case BlendMode.Screen:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => 1f - (1f - a) * (1f - b))).ToArray();
                break;

            case BlendMode.Overlay:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => Overlay(a, b))).ToArray();
                break;

            case BlendMode.HardLight:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => Overlay(b, a))).ToArray();
                break;

            case BlendMode.SoftLight:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => SoftLight(a, b))).ToArray();
                break;

            case BlendMode.Dodge:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => SafetyDivide(b, (1f - a)))).ToArray();
                break;

            case BlendMode.Burn:
                result = valueA.Zip(valueB, (va, vb) => BlendEachChannel(va, vb, m_Slider.value, (a, b) => 1f - SafetyDivide(1f - b, a))).ToArray();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(BlendMode));
            }
            var port = outputContainer.Q <Port>();

            graphData.portDatas[port.persistenceKey] = result;
        }
Ejemplo n.º 5
0
        protected override void Process(TextureGraphData graphData)
        {
            var inputs = graphData.GetArray <Vector4>();

            GetInput <Vector4>(inputs, graphData);
            var outputs = inputs.Select(v => new Vector4(m_RCurveField.value.Evaluate(v.x), m_GCurveField.value.Evaluate(v.y), m_BCurveField.value.Evaluate(v.z), m_ACurveField.value.Evaluate(v.w))).ToArray();
            var port    = outputContainer.Q <Port>();

            graphData.portDatas[port.persistenceKey] = outputs;
        }
Ejemplo n.º 6
0
        protected override void Process(TextureGraphData graphData)
        {
            var width   = graphData.width;
            var height  = graphData.height;
            var inputs  = graphData.GetArray <Vector4>();
            var outputs = graphData.GetArray <Vector4>();

            GetInput <Vector4>(inputs, graphData);
            var index = 0;

            switch (m_EnumField.enumValue)
            {
            case RotationType.Right90:
                for (var j = 0; j < width; ++j)
                {
                    for (var i = width - 1 - j; i < inputs.Length; i += width)
                    {
                        outputs[index++] = inputs[i];
                    }
                }
                break;

            case RotationType.Left90:
                for (var j = 0; j < width; ++j)
                {
                    for (var i = width * (height - 1) + j; i >= 0; i -= width)
                    {
                        outputs[index++] = inputs[i];
                    }
                }
                break;

            case RotationType.Rotate180:
                outputs = inputs.Reverse().ToArray();
                break;

            case RotationType.Horizontal:
                outputs = inputs.Select((v, i) => inputs[i / width * 2 * width + width - 1 - i]).ToArray();
                break;

            case RotationType.Vertical:
                outputs = inputs.Select((v, i) => inputs[i % width * 2 + width * (height - 1) - i]).ToArray();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(RotationType));
            }
            var port = outputContainer.Q <Port>();

            graphData.portDatas[port.persistenceKey] = outputs;
        }
Ejemplo n.º 7
0
        protected override void Process(TextureGraphData graphData)
        {
            var inputs = graphData.GetArray <Vector4>();

            GetInput <Vector4>(inputs, graphData);
            var outputs = inputs.Select(vector =>
            {
                Color.RGBToHSV(vector, out float h, out float s, out float v);
                var c = Color.HSVToRGB((h + m_HueSlider.value + 1f) % 1, s * m_SaturationSlider.value, v * m_ValueSlider.value, true);
                return(new Vector4(c.r, c.g, c.b, vector.w));
            }).ToArray();
            var port = outputContainer.Q <Port>();

            graphData.portDatas[port.persistenceKey] = outputs;
        }
Ejemplo n.º 8
0
        protected override void Process(TextureGraphData graphData)
        {
            var reds   = graphData.GetArray <float>();
            var greens = graphData.GetArray <float>();
            var blues  = graphData.GetArray <float>();
            var alphas = graphData.GetArray <float>();

            GetInput <float>(reds, graphData, "Red");
            GetInput <float>(greens, graphData, "Green");
            GetInput <float>(blues, graphData, "Blue");
            GetInput <float>(alphas, graphData, "Alpha");
            var port = outputContainer.Q <Port>();

            graphData.portDatas[port.persistenceKey] = reds.Select((r, i) => new Vector4(r, greens[i], blues[i], alphas[i])).ToArray();
        }
Ejemplo n.º 9
0
        protected void GetInput <T>(T[] inputValue, TextureGraphData graphData, string portName = null)
        {
            if (inputValue == null)
            {
                throw new ArgumentNullException(nameof(inputValue));
            }
            var port = inputContainer.Q <Port>(portName);

            foreach (var edge in port.connections)
            {
                if (edge.output == null)
                {
                    continue;
                }
                var outPort = edge.output;
                while (!(outPort.node is TextureGraphNode))
                {
                    var token = outPort.node as TokenNode;
                    foreach (var e in token.input.connections)
                    {
                        outPort = e.output;
                    }
                }
                if (!graphData.portDatas.TryGetValue(outPort.persistenceKey, out var rawData))
                {
                    var graphNode = outPort.node as TextureGraphNode;
                    graphNode.Process(graphData);
                    rawData = graphData.portDatas[outPort.persistenceKey];
                }
                if (rawData is T[] rawTData)
                {
                    Array.Copy(rawTData, inputValue, rawTData.Length);
                }
                else
                {
                    var adapter     = new NodeAdapter();
                    var adapterInfo = adapter.GetTypeAdapter(outPort.portType, typeof(T));
                    var index       = 0;
                    foreach (var item in rawData)
                    {
                        inputValue[index] = (T)adapterInfo.Invoke(null, new object[] { item });
                        ++index;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        protected override void Process(TextureGraphData graphData)
        {
            if (m_Width != graphData.width || m_Height != graphData.height)
            {
                ReloadTexture();
            }
            var port = outputContainer.Q <Port>();

            if (image.image.value != null)
            {
                graphData.portDatas[port.persistenceKey] = Array.ConvertAll((image.image.value as Texture2D)?.GetPixels(), c => (Vector4)c);
            }
            else
            {
                graphData.portDatas[port.persistenceKey] = graphData.GetArray <Vector4>();
            }
        }
Ejemplo n.º 11
0
        protected override void Process(TextureGraphData graphData)
        {
            var valueA = graphData.GetArray <float>();
            var valueB = graphData.GetArray <float>();
            var result = graphData.GetArray <float>();

            GetInput <float>(valueA, graphData, "A");
            GetInput <float>(valueB, graphData, "B");
            switch (m_EnumField.enumValue)
            {
            case CalculateMode.Add:
                result = valueA.Zip(valueB, (a, b) => a + b).ToArray();
                break;

            case CalculateMode.Subtract:
                result = valueA.Zip(valueB, (a, b) => a - b).ToArray();
                break;

            case CalculateMode.Multiply:
                result = valueA.Zip(valueB, (a, b) => a * b).ToArray();
                break;

            case CalculateMode.Divide:
                result = valueA.Zip(valueB, (a, b) => b == 0 ? 0 : a / b).ToArray();
                break;

            case CalculateMode.Surplus:
                result = valueA.Zip(valueB, (a, b) => b == 0 ? 0 : a % b).ToArray();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(CalculateMode));
            }
            var port = outputContainer.Q <Port>();

            graphData.portDatas[port.persistenceKey] = result;
        }
Ejemplo n.º 12
0
        protected override void Process(TextureGraphData graphData)
        {
            var port = outputContainer.Q <Port>();

            graphData.portDatas[port.persistenceKey] = Enumerable.Repeat(m_FloatField.value, graphData.width * graphData.height).ToArray();
        }
Ejemplo n.º 13
0
 protected abstract void Process(TextureGraphData graphData);
Ejemplo n.º 14
0
 public void StartProcess(TextureGraphData graphData)
 {
     Process(graphData);
 }