protected virtual void Functions() { StringAddLine("\t\t\tfloat2 UV_RotateAround(float2 center,float2 uv,float rad)\n\t\t\t{\n\t\t\t\tfloat2 fuv = uv - center;\n\t\t\t\tfloat2x2 ma = float2x2(cos(rad),sin(rad),-sin(rad),cos(rad));\n\t\t\t\tfuv = mul(ma,fuv)+center;\n\t\t\t\treturn fuv;\n\t\t\t}"); Functions_Blur(); Functions_AnimationSheet(); Screen_Functions(); int Gradient_MaxFrameCount = SWNodeMixer.Gradient_MaxFrameCount(); if (Gradient_MaxFrameCount > 0) { StringAddLine(string.Format("\t\t\tfloat GradientEvaluate(float _listTime[{0}],float _listValue[{0}],float count,float pcg)", Gradient_MaxFrameCount)); StringAddLine("\t\t\t{\n\t\t\t\tif(count==0)\n\t\t\t\t\treturn 0;\n\t\t\t\tif(pcg<_listTime[0])\n\t\t\t\t\treturn 0;\n\t\t\t\tif(pcg>_listTime[count-1])\n\t\t\t\t\treturn 0;\n\n\t\t\t\tfor(int i= 1;i<count;i++)\n\t\t\t\t{\n\t\t\t\t\tif(pcg <= _listTime[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tfloat v1= _listValue[i-1];\n\t\t\t\t\t\tfloat v2= _listValue[i];\n\t\t\t\t\t\tfloat t1= _listTime[i-1];\n\t\t\t\t\t\tfloat t2= _listTime[i];\n\t\t\t\t\t\treturn lerp(v1,v2, (pcg - t1) / (t2-t1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t}"); } }
public override void ProcessSub(SWOutputSub sub) { int MaxCount = SWNodeMixer.Gradient_MaxFrameCount(); string alphaParam = string.Format("mixer{0}", node.data.iName); StringAddLine(string.Format("\t\t\t\tfloat {0} = {1} +{2}*({3}) + color{4}.{5};", alphaParam, node.data.effectData.pop_startValue, node.data.effectData.pop_speed, node.data.effectData.pop_Param, node.data.iName, node.data.effectData.pop_channel.ToString())); StringAddLine(string.Format("\t\t\t\t{0} = clamp({0},{1},{2});", alphaParam, node.data.effectData.pop_min, node.data.effectData.pop_max)); 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(); foreach (var op in childOutputs) { foreach (var item in op.outputs) { int index = portBelongs [item.node.data.id]; string graParam = string.Format("gra{0}_{1}", node.data.iName, index); item.opFactor = string.Format("{0}*{1}", item.opFactor, graParam); result.outputs.Add(item); } } }
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); }