Esempio n. 1
0
        public FXNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA)
        {
            Name = "FX";

            Id = Guid.NewGuid().ToString();

            tileX = tileY = 1;

            width  = w;
            height = h;

            internalPixelType    = p;
            luminosity           = 1.0f;
            luminosityRandomness = 0.0f;

            iterations  = 1;
            translation = new MVector();
            scale       = new MVector(1, 1);
            rotation    = 0;

            blending = FXBlend.Blend;

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

            q1 = new NodeInput(NodeType.Color | NodeType.Gray, this, "Quadrant");
            q2 = new NodeInput(NodeType.Color | NodeType.Gray, this, "Quadrant");
            q3 = new NodeInput(NodeType.Color | NodeType.Gray, this, "Quadrant");
            q4 = new NodeInput(NodeType.Color | NodeType.Gray, this, "Quadrant");

            Output = new NodeOutput(NodeType.Color | NodeType.Gray, this);

            q1.OnInputAdded   += Input_OnInputAdded;
            q1.OnInputRemoved += Input_OnInputRemoved;
            q1.OnInputChanged += Input_OnInputChanged;

            q2.OnInputAdded   += Input_OnInputAdded;
            q2.OnInputRemoved += Input_OnInputRemoved;
            q2.OnInputChanged += Input_OnInputChanged;

            q3.OnInputAdded   += Input_OnInputAdded;
            q3.OnInputRemoved += Input_OnInputRemoved;
            q3.OnInputChanged += Input_OnInputChanged;

            q4.OnInputAdded   += Input_OnInputAdded;
            q4.OnInputRemoved += Input_OnInputRemoved;
            q4.OnInputChanged += Input_OnInputChanged;

            Inputs = new List <NodeInput>();
            Inputs.Add(q1);
            Inputs.Add(q2);
            Inputs.Add(q3);
            Inputs.Add(q4);

            Outputs = new List <NodeOutput>();
            Outputs.Add(Output);
        }
Esempio n. 2
0
 public FXQuadData(int q, FXBlend blend, FXPivot piv, float lum, float ang, MVector trans, MVector scal)
 {
     quadrant    = q;
     blending    = blend;
     pivot       = piv;
     luminosity  = lum;
     angle       = ang;
     translation = trans;
     scale       = scal;
 }
Esempio n. 3
0
        public override void FromJson(string data)
        {
            FXNodeData d = JsonConvert.DeserializeObject <FXNodeData>(data);

            SetBaseNodeDate(d);
            iterations   = d.iterations;
            rotation     = d.rotation;
            translation  = new MVector(d.tx, d.ty);
            scale        = new MVector(d.sx, d.sy);
            patternPivot = (FXPivot)d.pivot;
            blending     = (FXBlend)d.blending;
        }
Esempio n. 4
0
        FXQuadData GetQuad(float i, float x, float y, float imax, int quad)
        {
            MVector pTrans = translation;
            MVector pScale = scale;
            float   pRot   = rotation;

            FXPivot pivot = PatternPivot;
            FXBlend blend = blending;

            float luminosity           = Luminosity;
            float luminosityRandomness = LuminosityRandomness;

            GetQuadParams(i, imax, x, y, ref pTrans, ref pScale, ref pRot, ref pivot, ref blend, ref luminosity, ref luminosityRandomness);

            float rlum = CalculateRandomLuminosity(i, luminosityRandomness);

            luminosity += rlum;
            luminosity  = Math.Min(1.0f, Math.Max(0, luminosity));

            float angle = (float)(pRot * (Math.PI / 180.0f));

            return(new FXQuadData(quad, blend, pivot, luminosity, angle, pTrans, pScale));
        }
Esempio n. 5
0
        void GetQuadParams(float i, float imax, float x, float y, ref MVector trans,
                           ref MVector scale, ref float rot,
                           ref FXPivot pivot, ref FXBlend blend,
                           ref float luminosity, ref float luminosityRandomness)
        {
            if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Blending"))
            {
                if (ParentGraph.IsParameterValueFunction(Id, "Blending"))
                {
                    FunctionGraph g = ParentGraph.GetParameterRaw(Id, "Blending").Value as FunctionGraph;
                    g.SetVar("pos", new MVector(x, y), NodeType.Float2);
                    g.SetVar("iteration", i, NodeType.Float);
                    g.SetVar("maxIterations", imax, NodeType.Float);
                    g.TryAndProcess();
                    blend = (FXBlend)Convert.ToInt32(g.Result);
                }
                else
                {
                    blend = (FXBlend)Convert.ToInt32(ParentGraph.GetParameterValue(Id, "Blending"));
                }
            }

            if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Luminosity"))
            {
                if (ParentGraph.IsParameterValueFunction(Id, "Luminosity"))
                {
                    FunctionGraph g = ParentGraph.GetParameterRaw(Id, "Luminosity").Value as FunctionGraph;
                    g.SetVar("pos", new MVector(x, y), NodeType.Float2);
                    g.SetVar("iteration", i, NodeType.Float);
                    g.SetVar("maxIterations", imax, NodeType.Float);
                    g.TryAndProcess();
                    luminosity = Convert.ToSingle(g.Result);
                }
                else
                {
                    luminosity = Convert.ToSingle(ParentGraph.GetParameterValue(Id, "Luminosity"));
                }
            }

            if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "LuminosityRandomness"))
            {
                if (ParentGraph.IsParameterValueFunction(Id, "LuminosityRandomness"))
                {
                    FunctionGraph g = ParentGraph.GetParameterRaw(Id, "LuminosityRandomness").Value as FunctionGraph;
                    g.SetVar("pos", new MVector(x, y), NodeType.Float2);
                    g.SetVar("iteration", i, NodeType.Float);
                    g.SetVar("maxIterations", imax, NodeType.Float);
                    g.TryAndProcess();
                    luminosityRandomness = Convert.ToSingle(g.Result);
                }
                else
                {
                    luminosityRandomness = Convert.ToSingle(ParentGraph.GetParameterValue(Id, "LuminosityRandomness"));
                }
            }

            if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "PatternPivot"))
            {
                if (ParentGraph.IsParameterValueFunction(Id, "PatternPivot"))
                {
                    FunctionGraph g = ParentGraph.GetParameterRaw(Id, "PatternPivot").Value as FunctionGraph;
                    g.SetVar("pos", new MVector(x, y), NodeType.Float2);
                    g.SetVar("iteration", i, NodeType.Float);
                    g.SetVar("maxIterations", imax, NodeType.Float);
                    g.TryAndProcess();
                    pivot = (FXPivot)Convert.ToInt32(g.Result);
                }
                else
                {
                    pivot = (FXPivot)Convert.ToInt32(ParentGraph.GetParameterValue(Id, "PatternPivot"));
                }
            }

            if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Translation"))
            {
                if (ParentGraph.IsParameterValueFunction(Id, "Translation"))
                {
                    FunctionGraph g = ParentGraph.GetParameterRaw(Id, "Translation").Value as FunctionGraph;
                    g.SetVar("pos", new MVector(x, y), NodeType.Float2);
                    g.SetVar("iteration", i, NodeType.Float);
                    g.SetVar("maxIterations", imax, NodeType.Float);
                    g.TryAndProcess();

                    object o = g.Result;
                    if (o != null && o is MVector)
                    {
                        trans = (MVector)o;
                    }
                }
                else
                {
                    object o = ParentGraph.GetParameterValue(Id, "Translation");
                    if (o != null && o is MVector)
                    {
                        trans = (MVector)o;
                    }
                }
            }

            if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Scale"))
            {
                if (ParentGraph.IsParameterValueFunction(Id, "Scale"))
                {
                    FunctionGraph g = ParentGraph.GetParameterRaw(Id, "Scale").Value as FunctionGraph;
                    g.SetVar("pos", new MVector(x, y), NodeType.Float2);
                    g.SetVar("iteration", i, NodeType.Float);
                    g.SetVar("maxIterations", imax, NodeType.Float);
                    g.TryAndProcess();

                    object o = g.Result;
                    if (o != null && o is MVector)
                    {
                        scale = (MVector)o;
                    }
                }
                else
                {
                    object o = ParentGraph.GetParameterValue(Id, "Scale");
                    if (o != null && o is MVector)
                    {
                        scale = (MVector)o;
                    }
                }
            }

            if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Rotation"))
            {
                if (ParentGraph.IsParameterValueFunction(Id, "Rotation"))
                {
                    FunctionGraph g = ParentGraph.GetParameterRaw(Id, "Rotation").Value as FunctionGraph;
                    g.SetVar("pos", new MVector(x, y), NodeType.Float2);
                    g.SetVar("iteration", i, NodeType.Float);
                    g.SetVar("maxIterations", imax, NodeType.Float);
                    g.TryAndProcess();
                    rot = Convert.ToSingle(g.Result);
                }
                else
                {
                    rot = Convert.ToSingle(ParentGraph.GetParameterValue(Id, "Rotation"));
                }
            }
        }
Esempio n. 6
0
 public FXProcessor() : base()
 {
     Blending = FXBlend.Blend;
     shader   = GetShader("image.glsl", "fx.glsl");
 }