Example #1
0
        public PixelProcessorNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA) : base()
        {
            Name = "Pixel Processor";
            Id   = Guid.NewGuid().ToString();

            width  = w;
            height = h;

            tileX = tileY = 1;

            function = new FunctionGraph("Pixel Processor Function", w, h);
            function.AssignParentNode(this);

            function.ExpectedOutput = NodeType.Float4 | NodeType.Float;

            previewProcessor = new BasicImageRenderer();
            processor        = new PixelShaderProcessor();

            internalPixelType = p;

            for (int i = 0; i < 4; ++i)
            {
                var input = new NodeInput(NodeType.Gray | NodeType.Color, this, "Input " + Inputs.Count);
                Inputs.Add(input);
            }

            output = new NodeOutput(NodeType.Color | NodeType.Gray, this);
            Outputs.Add(output);
        }
Example #2
0
        public PixelProcessorNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA)
        {
            Name = "Pixel Processor";
            Id   = Guid.NewGuid().ToString();

            width  = w;
            height = h;

            tileX = tileY = 1;

            function = new FunctionGraph("Pixel Processor Function", w, h);
            function.AssignParentNode(this);

            function.ExpectedOutput  = NodeType.Float4 | NodeType.Float;
            function.OnGraphUpdated += Function_OnGraphUpdated;

            previewProcessor = new BasicImageRenderer();
            processor        = new PixelShaderProcessor();

            internalPixelType = p;

            Inputs = new List <NodeInput>();

            AddPlaceholderInput();
            AddPlaceholderInput();
            AddPlaceholderInput();
            AddPlaceholderInput();

            Outputs = new List <NodeOutput>();
            output  = new NodeOutput(NodeType.Color | NodeType.Gray, this);
            Outputs.Add(output);
        }
Example #3
0
        public override void FromJson(string data)
        {
            PixelProcessorData d = JsonConvert.DeserializeObject <PixelProcessorData>(data);

            SetBaseNodeDate(d);

            function = new FunctionGraph("Pixel Processor Function");
            function.ExpectedOutput = NodeType.Float4 | NodeType.Float;
            function.AssignParentNode(this);
            function.FromJson(d.functionGraph);
            function.SetConnections();
        }
Example #4
0
        private void CreateFunctionParameter(FunctionGraph g)
        {
            g.AssignParentNode(Node);

            try
            {
                PropertyInfo info = null;
                if (Parameter.StartsWith("$Custom."))
                {
                    if (Node is GraphInstanceNode)
                    {
                        GraphInstanceNode gn = Node as GraphInstanceNode;

                        string cparam = Parameter.Replace("$Custom.", "");

                        var param = gn.GetCustomParameter(cparam);

                        if (param != null)
                        {
                            var cparent = Node.ParentGraph;

                            g.ExpectedOutput = param.Type;

                            if (cparent != null)
                            {
                                cparent.SetParameterValue(Node.Id, cparam, g, true, param.Type);

                                FIcon.Opacity         = 1;
                                DefaultVar.IsEnabled  = true;
                                ConstantVar.IsEnabled = false;
                                FunctionVar.IsEnabled = false;
                            }
                            else
                            {
                                Log.Warn("Failed to promote to function");
                            }
                        }
                        else
                        {
                            //log error
                            Log.Error("Could not find custom parameter: " + cparam);
                        }
                    }
                    else
                    {
                        Log.Warn("Failed to promoto to function");
                    }
                }
                else
                {
                    info = Node.GetType().GetProperty(Parameter);
                    if (info == null)
                    {
                        Log.Warn("Failed to promote to function");
                        return;
                    }

                    var pro = info.GetCustomAttribute <PromoteAttribute>();

                    if (pro != null)
                    {
                        g.ExpectedOutput = pro.ExpectedType;
                    }

                    var p = Node.ParentGraph;

                    p = p.ParentNode != null ? p.ParentNode.ParentGraph : p;

                    if (p != null)
                    {
                        p.SetParameterValue(Node.Id, Parameter, g, true, g.ExpectedOutput);

                        FIcon.Opacity         = 1;
                        DefaultVar.IsEnabled  = true;
                        ConstantVar.IsEnabled = false;
                        FunctionVar.IsEnabled = false;
                    }
                    else
                    {
                        Log.Warn("Failed to promote to function");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Example #5
0
        private void FunctionVar_Click(object sender, RoutedEventArgs e)
        {
            if (Node == null || string.IsNullOrEmpty(Parameter))
            {
                return;
            }

            FunctionGraph g = new FunctionGraph(Node.Name + " - " + Parameter.Replace("$Custom.", "") + " Function", Node.Width, Node.Height);

            g.AssignParentNode(Node);

            try
            {
                PropertyInfo info = null;
                if (Parameter.StartsWith("$Custom."))
                {
                    if (Node is GraphInstanceNode)
                    {
                        GraphInstanceNode gn = Node as GraphInstanceNode;

                        string cparam = Parameter.Replace("$Custom.", "");

                        var param = gn.GetCustomParameter(cparam);

                        if (param != null)
                        {
                            var cparent = Node.ParentGraph;

                            if (cparent != null)
                            {
                                cparent = cparent.TopGraph();
                            }

                            g.ExpectedOutput = param.Type;

                            if (cparent != null)
                            {
                                cparent.SetParameterValue(Node.Id, cparam, g, true, param.Type);

                                FIcon.Opacity         = 1;
                                DefaultVar.IsEnabled  = true;
                                ConstantVar.IsEnabled = false;
                                FunctionVar.IsEnabled = false;
                            }
                            else
                            {
                                Log.Warn("Failed to promote to function");
                            }
                        }
                        else
                        {
                            //log error
                            Log.Error("Could not find custom parameter: " + cparam);
                        }
                    }
                    else
                    {
                        Log.Warn("Failed to promoto to function");
                    }
                }
                else
                {
                    info = Node.GetType().GetProperty(Parameter);
                    if (info == null)
                    {
                        Log.Warn("Failed to promote to function");
                        return;
                    }

                    var pro = info.GetCustomAttribute <PromoteAttribute>();

                    if (pro != null)
                    {
                        g.ExpectedOutput = pro.ExpectedType;
                    }

                    var p = Node.ParentGraph;

                    if (p != null)
                    {
                        p = p.TopGraph();
                    }

                    if (p != null)
                    {
                        var pg = p;

                        pg.SetParameterValue(Node.Id, Parameter, g, true, g.ExpectedOutput);

                        FIcon.Opacity         = 1;
                        DefaultVar.IsEnabled  = true;
                        ConstantVar.IsEnabled = false;
                        FunctionVar.IsEnabled = false;
                    }
                    else
                    {
                        Log.Warn("Failed to promote to function");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }