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} ,{2}*{3})", node.data.blurX, node.data.blurXParam, node.data.blurY, node.data.blurYParam); sw.outputs.Add(sub); return(sw); }
protected void SetLayerMask(SWNodeBase node) { LayerMaskUpdate(node); if (node.data.layerMask.mask == 0) { var par = node.GetParentNodeAllAllList(); foreach (var item in par) { node.data.layerMask.Set(item.data.id, true); } } }
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 virtual void ProcessAll(SWNodeBase root) { StringAddLine("\t\t\t\tfloat4 result = float4(0,0,0,0);"); Process(root); StringAddLine("\t\t\t\tresult = result*i.color;"); StringAddLine(string.Format("\t\t\t\tclip(result.a - {0});", window.data.clipValue)); if (window.data.shaderBlend == SWShaderBlend.mul) { StringAddLine("\t\t\t\tresult = lerp(half4(1,1,1,1), result, result.a);"); } }
public SWOutput Process(SWNodeBase node) { if (node.shaderOutput != null) { return(node.shaderOutput); } SWShaderProcessBase processor = CreateProcessor(node.data.type); node.shaderOutput = processor.Process(node); return(node.shaderOutput); }
protected void PropertyDeclare_Node(SWNodeBase node) { if (!node.BelongRootTree()) { return; } if (node.HasColorAttribute()) { StringAddLine(string.Format("\t\t\tfloat4 _Color{0};", node.data.iName)); } Property_Code(node, false); }
public void GetChildNodeAllAllSub(Dictionary <string, SWNodeBase> dic, SWNodeBase e) { var tempNodeAll = window.NodeAll(); if (!dic.ContainsKey(e.data.id)) { dic.Add(e.data.id, e); } foreach (var item in data.children) { GetChildNodeAllAllSub(dic, tempNodeAll[item]); } }
public override void ProcessExtra(SWNodeBase root) { base.ProcessExtra(root); //step 1:Cal Factor StringAddLine("\t\t\t\t// First clip region"); StringAddLine("\t\t\t\tfloat2 factor = (float2(1.0, 1.0) - abs(i.worldPos.xy)) * _ClipArgs0.xy;"); StringAddLine("\t\t\t\tfloat f = min(factor.x, factor.y);"); StringAddLine("\t\t\t\t// Second clip region"); StringAddLine("\t\t\t\tfactor = (float2(1.0, 1.0) - abs(i.worldPos.zw)) * _ClipArgs1.xy;"); StringAddLine("\t\t\t\tf = min(f, min(factor.x, factor.y));"); //step 2:Mul aplha StringAddLine("\t\t\t\t// Apply clipping"); StringAddLine("\t\t\t\tresult.a *= clamp(f, 0.0, 1.0);"); }
public static void AddConnection(SWNodeBase leftNode, int leftPort, SWNodeBase rightNode, int rightPort) { //If rightNode is child node single connection limited, than remove child to this port if (rightNode.childPortSingleConnection) { while (rightNode.data.childrenPort.Contains(rightPort)) { int index = rightNode.data.childrenPort.IndexOf(rightPort); var childToRemove = SWWindowMain.Instance.NodeAll()[rightNode.data.children[index]]; RemoveConnection(rightNode, childToRemove); } } SWDataManager.AddConnection(leftNode.data, leftPort, rightNode.data, rightPort); }
protected void ShowBG_SingleTex(SWNodeBase tempNode, bool loop) { var tex = tempNode.Texture; if (tex == null) { return; } var dt = tempNode.data; Material matBot = new Material(SWEditorUI.GetShader("RectTRS")); Set_Material(matBot, -dt.effectData.t_startMove, dt.effectData.r_angle, dt.effectData.s_scale); if (loop) { Set_MaterialLoop(matBot, dt); } Graphics.DrawTexture(drawRect, tex, matBot); }
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); }
protected bool BelongRootTreeSub(Dictionary <string, SWNodeBase> allNodes, SWNodeBase node) { if (node.data.type == SWNodeType.root) { return(true); } else { foreach (var item in node.data.parent) { if (!(allNodes [item] is SWNodeRemap) && BelongRootTreeSub(allNodes, allNodes [item])) { return(true); } } } return(false); }
public override SWOutput Process(SWNodeBase _node) { //step 1: Add colors colors = new List <SWOutputSub> (); if (window.data.excludeRoot) { node = _node; Child_Process(); } else { base.Process(_node); } foreach (var item in childOutputs) { foreach (var item2 in item.outputs) { if (item2.type == SWDataType._Color) { colors.Add(item2); } } } //step 2: Process colors colors.Sort(delegate(SWOutputSub x, SWOutputSub y) { return(x.depth - y.depth); }); var c = new SWShaderProcessReceiveColor(); for (int i = 0; i < colors.Count; i++) { var item = colors [i]; c.ProcessOutputSingle(this, item, i == 0); } //step 3: Process Alpha GoOutput(SWNodeType.alpha, "final"); return(null); }
public override SWOutput Process(SWNodeBase _node) { node = _node; CommentHead(); Child_Process(); StringAddLine(string.Format("\t\t\t\tfloat4 color{0} = _Color{0};", node.data.iName)); GoOutput(SWNodeType.alpha); SWOutputSub sub = new SWOutputSub(); sub.processor = this; sub.depth = node.data.depth; sub.param = string.Format("color{0}", node.data.iName); sub.op = node.data.effectDataColor.op; sub.opFactor = string.Format("{0}*({1})", sub.opFactor, node.data.effectDataColor.param); result.outputs.Add(sub); return(result); }
protected void PropertyField_Node(SWNodeBase node) { if (!node.BelongRootTree()) { return; } if (node.HasColorAttribute()) { StringAddLine(string.Format("\t\t{0}_Color{1} (\"Color {2}\", Color) = ({3},{4},{5},{6})", node.data.effectDataColor.hdr? "[HDR]":"", node.data.iName, node.data.name, node.data.effectDataColor.color.r.ToStringEX(), node.data.effectDataColor.color.g.ToStringEX(), node.data.effectDataColor.color.b.ToStringEX(), node.data.effectDataColor.color.a.ToStringEX() )); } Property_Code(node, true); }
private void LayerMaskUpdate(SWNodeBase node) { var layerMask = node.data.layerMask; var ns = SWWindowMain.Instance.NodeAll(); foreach (var item in ns) { if (item.Value.data.id != node.data.id) { layerMask.AddKey(item.Key); } } for (int i = layerMask.strs.Count - 1; i >= 0; i--) { var item = layerMask.strs [i]; if (!ns.ContainsKey(item)) { layerMask.RemoveKey(item); } } }
protected void ShowLayerMask(SWNodeBase node) { LayerMaskUpdate(node); var layerMask = node.data.layerMask; var ns = SWWindowMain.Instance.NodeAll(); string[] strs = new string[layerMask.strs.Count]; for (int i = 0; i < strs.Length; i++) { strs [i] = ns [layerMask.strs [i]].data.name; } Rect rect = new Rect(al_leftWidth + 10, al_topHeight + 10, 73, 10); var ll = EditorGUI.MaskField(rect, layerMask.mask, strs); if (ll != layerMask.mask) { SWUndo.Record(node); layerMask.mask = ll; } }
protected void ShowLayerPopup(SWNodeBase node) { int index = 0; LayerMaskUpdate(node); var layerMask = node.data.layerMask; var ns = SWWindowMain.Instance.NodeAll(); string[] strs = new string[layerMask.strs.Count]; for (int i = 0; i < strs.Length; i++) { strs [i] = ns [layerMask.strs [i]].data.name; if (strs [i] == node.data.layerPop_str) { index = i; } } Rect rect = new Rect(al_leftWidth + 10, al_topHeight + 10, 73, 10); index = EditorGUI.Popup(rect, index, strs); node.data.layerPop_str = strs [index]; }
public static void RemoveConnection(SWNodeBase parent, SWNodeBase child) { SWDataManager.RemoveConnection(parent.data, child.data); }
public override void ProcessExtra(SWNodeBase root) { base.ProcessExtra(root); StringAddLine("\t\t\t\tresult.a *= tex2D(_ClipTex, i.clipUV).a;"); }
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); }
public override void ProcessExtra(SWNodeBase root) { base.ProcessExtra(root); StringAddLine("\t\t\t\tresult.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);"); StringAddLine("\t\t\t\t#ifdef UNITY_UI_ALPHACLIP\n\t\t\t\tclip (result.a - 0.001);\n\t\t\t\t#endif"); }
public override bool PortMatch(int port, SWNodeBase child, int childPort) { return(base.PortMatch(port, child, childPort) && (child.data.type == SWNodeType.image || child.data.type == SWNodeType.dummy)); }
public override SWOutput Process(SWNodeBase _node) { return(base.Process(_node)); }
public override bool PortMatch(int port, SWNodeBase child, int childPort) { return(base.PortMatch(port, child, childPort)); }
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 void ProcessExtra(SWNodeBase root) { base.ProcessExtra(root); StringAddLine("\t\t\t\t#if UNITY_TEXTURE_ALPHASPLIT_ALLOWED\n\t\t\t\tif (_AlphaSplitEnabled)\n\t\t\t\tresult.a = tex2D (_AlphaTex, uv).r;\n\t\t\t\t#endif "); }
/// <summary> /// Result -> Here -> Clipping /// </summary> public virtual void ProcessExtra(SWNodeBase root) { }
void CodeParamInput() { GUILayout.Label("Inputs:", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(SWGlobalSettings.LabelWidth)); Tooltip_Rec(SWTipsText.Code_Input); int toDeleteIndex = -1; for (int i = 0; i < nodeCode.dataCode.inputs.Count; i++) { var item = nodeCode.dataCode.inputs [i]; GUILayout.BeginHorizontal(); var newName = EditorGUILayout.TextField(item.name, GUILayout.Width(SWGlobalSettings.LabelWidth)); if (newName != item.name) { SWUndo.Record(this); item.name = newName; } var newType = SelectTypeInput(item.type, 50); if (newType != item.type) { SWUndo.Record(this); item.type = newType; } if (GUILayout.Button("-", GUILayout.Width(20))) { toDeleteIndex = i; } GUILayout.EndHorizontal(); if (item.type == CodeParamType.Range) { GUILayout.BeginHorizontal(); //GUILayout.Space (8); item.v = EditorGUILayout.FloatField(item.v, GUILayout.Width(28)); GUILayout.Label("Min", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(22)); item.min = EditorGUILayout.FloatField(item.min, GUILayout.Width(28)); GUILayout.Label("Max", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(27)); item.max = EditorGUILayout.FloatField(item.max, GUILayout.Width(28)); GUILayout.EndHorizontal(); item.v = Mathf.Clamp(item.v, item.min, item.max); } else if (item.type == CodeParamType.Float) { item.v = EditorGUILayout.FloatField(item.v, GUILayout.Width(28)); } GUILayout.Space(2); } if (toDeleteIndex >= 0) { SWUndo.Record(this); var allNodes = NodeAll(); for (int i = nodeCode.data.children.Count - 1; i >= 0; i--) { int port = nodeCode.data.childrenPort[i]; if (port > toDeleteIndex) { nodeCode.data.childrenPort[i]--; } else if (port == toDeleteIndex) { var id = nodeCode.data.children[i]; var childNode = allNodes[id]; SWNodeBase.RemoveConnection(nodeCode, childNode); } } nodeCode.dataCode.inputs.RemoveAt(toDeleteIndex); } GUILayout.BeginHorizontal(); GUILayout.Space(SWGlobalSettings.LabelWidth * 2 + 2); if (GUILayout.Button("+", GUILayout.Width(20))) { nodeCode.dataCode.AddParam(); } GUILayout.EndHorizontal(); }