예제 #1
0
        protected void Child_Process()
        {
            var tempNodeAll = window.NodeAll();

            foreach (var item in node.data.children)
            {
                var child = tempNodeAll[item];
                if (!child.BelongRootTree())
                {
                    continue;
                }
                SWOutput output = SWShaderCreaterBase.Instance.Process(child);
                childOutputs.Add(output);
            }

            //pass child who output color
            foreach (var item in childOutputs)
            {
                foreach (var item2 in item.outputs)
                {
                    //Sprite Light Normal mapping
                    if (item2.type == SWDataType._Color || item2.type == SWDataType._Normal)
                    {
                        result.outputs.Add(item2);
                    }
                }
            }
        }
예제 #2
0
        public override SWOutput Process(SWNodeBase _node)
        {
            node = _node;
            Child_Process();
            CommentHead();

            UVParamInit();
            //StringAddLine( string.Format("\t\t\t\tfloat2  {0} = {1};    ",uvParam,childOutputs[0].outputs[0].UVparam));

            StringAddLine(string.Format("\t\t\t\tfloat {0}A = tex2D(_{1},{0}).b*tex2D(_{1},{0}).a;",
                                        uvParam, node.TextureShaderName()));

            StringAddLine(string.Format("\t\t\t\tfloat4 color{0} = tex2D(_{2},{1});    ",
                                        node.data.iName, uvParam, node.TextureShaderName()));
            StringAddLine(string.Format("\t\t\t\tif(color{0}.b >= 0.5)", node.data.iName));
            StringAddLine(string.Format("\t\t\t\t\tcolor{0} = float4(0,color{0}.gba);", node.data.iName));


            SWOutputSub sub    = new SWOutputSub();
            SWOutput    result = new SWOutput();

            result.outputs.Add(sub);
            sub.processor = this;
            sub.type      = SWDataType._Remap;
            sub.param     = string.Format("color{0}.rg", node.data.iName);
            sub.op        = SWOutputOP.add;
            sub.opFactor  = string.Format("color{0}.a", node.data.iName);
            return(result);
        }
예제 #3
0
        public override SWOutput Process(SWNodeBase _node)
        {
            node = _node;
            //CommentHead ();

            SWOutputSub sub = new SWOutputSub();

            sub.type      = SWDataType._UV;
            sub.processor = this;
            if (node.data.coordMode == SWCoordMode.Default)
            {
                sub.param = "i._uv_MainTex";
            }
            else if (node.data.coordMode == SWCoordMode.Sprite)
            {
                sub.param = "i._uv_STD";
            }
            sub.uvOp     = node.data.effectDataUV.op;
            sub.opFactor = string.Format("{0}*({1})", sub.opFactor, node.data.effectDataUV.param);

            SWOutput sw = new SWOutput();

            sw.outputs.Add(sub);
            return(sw);
        }
예제 #4
0
        public override SWOutput Process(SWNodeBase _node)
        {
            node = _node;
            SWOutput    sw  = new SWOutput();
            SWOutputSub sub = new SWOutputSub();

            sub.type      = SWDataType._UV;
            sub.processor = this;
            sub.opFactor  = string.Format("float2( {0}*{1}*0.1 ,{2}*{3}*0.1)", node.data.blurX, node.data.blurXParam, node.data.blurY, node.data.blurYParam);
            sw.outputs.Add(sub);
            return(sw);
        }
        public override SWOutput Process(SWNodeBase _node)
        {
            node = _node;
            SWOutput    sw  = new SWOutput();
            SWOutputSub sub = new SWOutputSub();

            sub.type      = SWDataType._UV;
            sub.processor = this;
            sub.opFactor  = string.Format("({0}*({1})*0.2)", node.data.retro, node.data.retroParam);
            sw.outputs.Add(sub);
            return(sw);
        }
        public override SWOutput Process(SWNodeBase _node)
        {
            node = _node;
            Child_Process();

            SWOutput result = new SWOutput();

            foreach (var item in childOutputs)
            {
                result.outputs.AddRange(item.outputs);
            }

            foreach (var item in result.outputs)
            {
                item.opFactor = string.Format("{0}*color_{1}.{2}", item.opFactor, node.TextureShaderName(), node.data.maskChannel.ToString());
            }
            return(result);
        }
예제 #7
0
        protected void Child_Process()
        {
            foreach (var item in node.data.children)
            {
                var      child  = window.NodeAll() [item];
                SWOutput output = SWShaderCreaterBase.Instance.Process(child);
                childOutputs.Add(output);
            }

            //pass child who output color
            foreach (var item in childOutputs)
            {
                foreach (var item2 in item.outputs)
                {
                    if (item2.type == SWDataType._Color)
                    {
                        result.outputs.Add(item2);
                    }
                }
            }
        }
예제 #8
0
        public override SWOutput Process(SWNodeBase _node)
        {
            node = _node;
            Child_Process();
            CommentHead();

            SWOutput result = new SWOutput();
            //step 0:Get Direct Child
            string directChildID = "";

            for (int i = 0; i < node.data.children.Count; i++)
            {
                int port = node.data.childrenPort [i];
                if (port == 0)
                {
                    directChildID = node.data.children [i];
                    break;
                }
            }


            //step 1: from child node, get alpha
            int    MaxCount   = SWNodeMixer.Gradient_MaxFrameCount();
            string alphaParam = string.Format("mixer{0}", node.data.iName);

            StringAddLine(string.Format("\t\t\t\tfloat {0};", alphaParam));

            foreach (var op in childOutputs)
            {
                foreach (var item in op.outputs)
                {
                    if (directChildID == item.data.id)
                    {
                        if (item.data.type == SWNodeType.alpha)
                        {
                            StringAddLine(string.Format("\t\t\t\t{0} = clamp({1}*{2},{3},{4});",
                                                        alphaParam, item.param, item.opFactor, item.data.effectData.pop_min, item.data.effectData.pop_max));
                        }
                        else
                        {
                            StringAddLine(string.Format("\t\t\t\t{0} = ({1}).a*{2};", alphaParam, item.param, item.opFactor));
                        }
                        break;
                    }
                }
            }
            StringAddLine(string.Format("\t\t\t\t{0} = clamp({0},0,1);", alphaParam));


            //step 2:keyframe calculation
            for (int i = 0; i < node.data.gradients.Count; i++)
            {
                string graParam = string.Format("gra{0}_{1}", node.data.iName, i);
                var    frames   = node.data.gradients [i].frames;
                if (frames.Count == 0)
                {
                    StringAddLine(string.Format("\t\t\t\tfloat {0} = 0;", graParam));
                }
                else
                {
                    string strList = (string.Format("\t\t\t\tfloat {0}ListTime[{1}] = {{", graParam, MaxCount));
                    for (int j = 0; j < MaxCount; j++)
                    {
                        if (j < frames.Count)
                        {
                            strList += ("" + node.data.gradients [i].frames [j].time);
                        }
                        else
                        {
                            strList += ("-1");
                        }
                        if (j != MaxCount - 1)
                        {
                            strList += (",");
                        }
                    }
                    strList += ("};");
                    StringAddLine(strList);


                    strList = (string.Format("\t\t\t\tfloat {0}ListValue[{1}] = {{", graParam, MaxCount));
                    for (int j = 0; j < MaxCount; j++)
                    {
                        if (j < frames.Count)
                        {
                            strList += ("" + node.data.gradients [i].frames [j].value);
                        }
                        else
                        {
                            strList += ("-1");
                        }
                        if (j != MaxCount - 1)
                        {
                            strList += (",");
                        }
                    }
                    strList += ("};");
                    StringAddLine(strList);

                    StringAddLine(string.Format("\t\t\t\tfloat {0} = GradientEvaluate({0}ListTime,{0}ListValue,{1},{2});", graParam, frames.Count, alphaParam));
                }
            }

            PortBelong();
            //step 3:pass to parent
            foreach (var op in childOutputs)
            {
                foreach (var item in op.outputs)
                {
                    int port = portBelongs [item.node.data.id];
                    if (port != 0)
                    {
                        string graParam = string.Format("gra{0}_{1}", node.data.iName, (port - 1));
                        item.opFactor = string.Format("{0}*{1}", item.opFactor, graParam);
                        result.outputs.Add(item);
                    }
                }
            }
            return(result);
        }
        public override SWOutput Process(SWNodeBase _node)
        {
            //1: init
            node = _node;
            Child_Process();
            CommentHead();

            //2: port belong
            PortBelong();
            SWOutputSub[] subs = new SWOutputSub[node.data.childPortNumber];
            foreach (var op in childOutputs)
            {
                foreach (var item in op.outputs)
                {
                    int port = portBelongs [item.node.data.id];
                    subs [port] = item;
                }
            }

            //3: param
            var dataCode = SWWindowMain.Instance.dataCode.CodeOfName(node.data.code);

            string param = string.Format("v{0}", node.data.iName);

            if (dataCode.output.GetType() == SWDataType._Color)
            {
                StringAddLine(string.Format("\t\t\t\tfloat4 {0} = float4(0,0,0,0);", param));
            }
            else if (dataCode.output.GetType() == SWDataType._UV)
            {
                StringAddLine(string.Format("\t\t\t\tfloat2 {0} = float2(0,0);", param));
            }
            else if (dataCode.output.GetType() == SWDataType._Alpha)
            {
                StringAddLine(string.Format("\t\t\t\tfloat {0} = 0;", param));
            }

            List <string> list      = new List <string> ();
            int           portIndex = 0;

            for (int i = 0; i < dataCode.inputs.Count; i++)
            {
                var    item = dataCode.inputs [i];
                string str  = "";
                if (item.IsParam())
                {
                    var paramUse = node.data.GetCodeParamUse(item.name);
                    if (item.type == CodeParamType.CustomParam)
                    {
                        str = paramUse.v;
                    }
                    else
                    {
                        str = string.Format("{0}_{1}", node.data.iName, paramUse.n);
                    }
                }
                else
                {
                    str = subs[portIndex].param + "*" + subs[portIndex].opFactor;
                    portIndex++;
                }
                list.Add(str);
            }

            if (dataCode.IsFunction())
            {
                string func = dataCode.name + "(";
                for (int i = 0; i < dataCode.inputs.Count; i++)
                {
                    if (i != 0)
                    {
                        func += ",";
                    }
                    func += list[i];
                }
                func += ")";

                StringAddLine(string.Format("\t\t\t\t{0} = {1};", param, func));
            }
            else
            {
                string content = "\t\t\t\t" + dataCode.code;
                content = content.Replace("\n", "\n\t\t\t\t");
                for (int i = 0; i < dataCode.inputs.Count; i++)
                {
                    content = SWRegex.ReplaceWord(content, dataCode.inputs[i].name, list[i]);
                }
                content = SWRegex.ReplaceWord(content, dataCode.output.name, param);
                StringAddLine(content);
            }



            SWOutputSub sub = new SWOutputSub();

            sub.processor = this;

            sub.type = node.data.GetCodeType();
            //sub.type = window.data.CodeOfName(node.data.code).output.type;
            sub.param = param;

            if (sub.type == SWDataType._Color)
            {
                sub.data     = new SWDataNode(SWNodeType.color);
                sub.depth    = node.data.depth;
                sub.op       = node.data.effectDataColor.op;
                sub.opFactor = string.Format("{0}*({1})", sub.opFactor, node.data.effectDataColor.param);
            }
            else if (sub.type == SWDataType._UV)
            {
                sub.data     = new SWDataNode(SWNodeType.uv);
                sub.opFactor = string.Format("{0}*({1})", sub.opFactor, node.data.effectDataUV.param);
                sub.uvOp     = node.data.effectDataUV.op;
            }
            else if (sub.type == SWDataType._Alpha)
            {
                sub.data     = new SWDataNode(SWNodeType.alpha);
                sub.op       = node.data.effectDataColor.op;
                sub.opFactor = string.Format("{0}*({1})", sub.opFactor, node.data.effectDataColor.param);
                sub.data.effectData.pop_final = node.data.effectData.pop_final;
            }
            sub.data.id = node.data.id;

            SWOutput result = new SWOutput();

            result.outputs.Add(sub);
            return(result);
        }