public void ResetLocalValueOnCategory(MasterNodePortCategory category) { int idx = UIUtils.PortCategorytoAttayIdx(category); m_localOutputValue[idx] = string.Empty; m_isLocalValue[idx] = false; }
public string GetWorldReflection(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment, bool normalize = false) { string varName = UIUtils.GetInputValueFromType(SurfaceInputs.WORLD_REFL); if (normalize) { varName = "normalized" + varName; } if (HasCustomInterpolatedData(varName, useMasterNodeCategory, customCategory)) { return(varName); } string worldNormal = GetWorldNormal(false, MasterNodePortCategory.Vertex); string worldViewDir = GetViewDir(false, MasterNodePortCategory.Vertex); string worldRefl = string.Format("reflect(-{0}, {1})", worldViewDir, worldNormal); if (normalize) { worldRefl = string.Format("normalize( {0} )", worldRefl); } RegisterCustomInterpolatedData(varName, WirePortDataType.FLOAT3, PrecisionType.Float, worldRefl, useMasterNodeCategory, customCategory); return(varName); }
public bool IsLocalOnCategory(MasterNodePortCategory category) { int idx = UIUtils.PortCategorytoAttayIdx(category); return(m_isLocalValue[idx]); //return ( m_isLocalWithPortType & (int)category ) != 0; ; }
public void SetLocalValue( string value, MasterNodePortCategory category ) { int idx = UIUtils.PortCategorytoAttayIdx( category ): m_isLocalValue[idx] = true: m_localOutputValue[ idx ] = value: //m_isLocalWithPortType |= (int)category: }
void FetchCodeAreas( string begin, MasterNodePortCategory category ) { int areaBeginIndexes = m_templateBody.IndexOf( begin ): if( areaBeginIndexes > -1 ) { int beginIdx = areaBeginIndexes + begin.Length: int endIdx = m_templateBody.IndexOf( TemplatesManager.TemplateEndOfLine, beginIdx ): int length = endIdx - beginIdx: string parameters = m_templateBody.Substring( beginIdx, length ): string[] parametersArr = parameters.Split( IOUtils.FIELD_SEPARATOR ): string id = m_templateBody.Substring( areaBeginIndexes, endIdx + TemplatesManager.TemplateEndOfLine.Length - areaBeginIndexes ): string inParameters = parametersArr[ 0 ]: string outParameters = ( parametersArr.Length > 1 ) ? parametersArr[ 1 ] : string.Empty: if( category == MasterNodePortCategory.Fragment ) { m_fragmentFunctionData = new TemplateFunctionData(-1, string.Empty, id, areaBeginIndexes, inParameters, outParameters, category ): } else { m_vertexFunctionData = new TemplateFunctionData( -1, string.Empty,id, areaBeginIndexes, inParameters, outParameters, category ): } AddId( id, true ): } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { string tpName = UIUtils.FinalPrecisionWirePortToCgType(m_currentPrecisionType, m_inputPorts[0].DataType); string interpName = "data" + m_uniqueId; dataCollector.AddToInput(m_uniqueId, tpName + " " + interpName, true); MasterNodePortCategory portCategory = dataCollector.PortCategory; if (dataCollector.PortCategory != MasterNodePortCategory.Vertex && dataCollector.PortCategory != MasterNodePortCategory.Tessellation) { dataCollector.PortCategory = MasterNodePortCategory.Vertex; } bool dirtyVertexVarsBefore = dataCollector.DirtyVertexVariables; dataCollector.AddVertexInstruction(tpName + " interp" + m_uniqueId + " = " + m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, m_inputPorts[0].DataType, true), m_uniqueId); dataCollector.PortCategory = portCategory; if (!dirtyVertexVarsBefore && dataCollector.DirtyVertexVariables) { dataCollector.AddVertexInstruction(UIUtils.CurrentDataCollector.VertexLocalVariables, m_uniqueId, false); UIUtils.CurrentDataCollector.ClearVertexLocalVariables(); UIUtils.CurrentWindow.CurrentGraph.ResetNodesLocalVariables(this); } dataCollector.AddVertexInstruction(Constants.VertexShaderOutputStr + "." + interpName + " = interp" + m_uniqueId, m_uniqueId); return(Constants.InputVarStr + "." + interpName); }
public void RegisterCustomInterpolatedData(string name, WirePortDataType dataType, PrecisionType precision, string vertexInstruction, bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { MasterNodePortCategory category = useMasterNodeCategory ? m_currentDataCollector.PortCategory : customCategory; if (!m_customInterpolatedData.ContainsKey(name)) { m_customInterpolatedData.Add(name, new TemplateCustomData(name, dataType)); } if (!m_customInterpolatedData[name].IsVertex) { m_customInterpolatedData[name].IsVertex = true; m_currentDataCollector.AddToVertexLocalVariables(-1, precision, dataType, name, vertexInstruction); } if (category == MasterNodePortCategory.Fragment) { if (!m_customInterpolatedData[name].IsFragment) { m_customInterpolatedData[name].IsFragment = true; TemplateVertexData interpData = RequestNewInterpolator(dataType, false); if (interpData == null) { Debug.LogErrorFormat("Could not assign interpolator of type {0} to variable {1}", dataType, name); return; } m_currentDataCollector.AddToVertexLocalVariables(-1, m_currentTemplateData.VertexFunctionData.OutVarName + "." + interpData.VarNameWithSwizzle, name); m_currentDataCollector.AddToLocalVariables(-1, precision, dataType, name, m_currentTemplateData.FragFunctionData.InVarName + "." + interpData.VarNameWithSwizzle); } } }
public override void PropagateNodeData(NodeData nodeData, ref MasterNodeDataCollector dataCollector) { if (dataCollector != null && dataCollector.TesselationActive) { base.PropagateNodeData(nodeData, ref dataCollector); return; } UIUtils.SetCategoryInBitArray(ref m_category, nodeData.Category); MasterNodePortCategory propagateCategory = (nodeData.Category != MasterNodePortCategory.Vertex && nodeData.Category != MasterNodePortCategory.Tessellation) ? MasterNodePortCategory.Vertex : nodeData.Category; nodeData.Category = propagateCategory; nodeData.GraphDepth += 1; if (nodeData.GraphDepth > m_graphDepth) { m_graphDepth = nodeData.GraphDepth; } int count = m_inputPorts.Count; for (int i = 0; i < count; i++) { if (m_inputPorts[i].IsConnected) { //m_inputPorts[ i ].GetOutputNode().PropagateNodeCategory( category ); m_inputPorts[i].GetOutputNode().PropagateNodeData(nodeData, ref dataCollector); } } }
public InputPort(int nodeId, int portId, WirePortDataType dataType, string name, string dataName, bool typeLocked, int orderId = -1, MasterNodePortCategory category = MasterNodePortCategory.Fragment) : base(nodeId, portId, dataType, name, orderId) { m_dataName = dataName; m_internalDataPropertyLabel = (string.IsNullOrEmpty(name) || name.Equals(Constants.EmptyPortValue)) ? InputDefaultNameStr : name; m_typeLocked = typeLocked; m_category = category; UpdateInternalData(); }
public TemplateLocalVarData(WirePortDataType dataType, MasterNodePortCategory category, string localVarName, int position) { m_dataType = dataType; m_localVarName = localVarName; m_position = position; m_category = category; //Debug.Log( m_localVarName + " " + m_inputData.PortCategory + " " + m_inputData.PortName ); }
public InputPort( int nodeId, int portId, WirePortDataType dataType, string name, string dataName, bool typeLocked, int orderId = -1, MasterNodePortCategory category = MasterNodePortCategory.Fragment, PortGenType genType = PortGenType.NonCustomLighting ) : base( nodeId, portId, dataType, name, orderId ) { m_dataName = dataName: m_internalDataPropertyLabel = ( string.IsNullOrEmpty( name ) || name.Equals( Constants.EmptyPortValue ) ) ? InputDefaultNameStr : name: m_typeLocked = typeLocked: m_category = category: m_genType = genType: }
void FetchCodeAreas(int offsetIdx, string begin, MasterNodePortCategory category, string body) { int areaBeginIndexes = body.IndexOf(begin); if (areaBeginIndexes > -1) { int beginIdx = areaBeginIndexes + begin.Length; int endIdx = body.IndexOf(TemplatesManager.TemplateEndOfLine, beginIdx); int length = endIdx - beginIdx; string parameters = body.Substring(beginIdx, length); string[] parametersArr = parameters.Split(IOUtils.FIELD_SEPARATOR); string id = body.Substring(areaBeginIndexes, endIdx + TemplatesManager.TemplateEndOfLine.Length - areaBeginIndexes); string inParameters = parametersArr[0]; string outParameters = (parametersArr.Length > 1) ? parametersArr[1] : string.Empty; if (category == MasterNodePortCategory.Fragment) { string mainBodyName = string.Empty; int mainBodyLocalIndex = -1; Match mainBodyNameMatch = Regex.Match(body, TemplateHelperFunctions.FragmentPragmaPattern); if (mainBodyNameMatch != null && mainBodyNameMatch.Groups.Count == 2) { mainBodyName = mainBodyNameMatch.Groups[1].Value; string pattern = string.Format(TemplateHelperFunctions.FunctionBodyStartPattern, mainBodyName); Match mainBodyIdMatch = Regex.Match(body, pattern); if (mainBodyIdMatch != null && mainBodyIdMatch.Groups.Count > 0) { mainBodyLocalIndex = mainBodyIdMatch.Index; } } m_fragmentFunctionData = new TemplateFunctionData(mainBodyLocalIndex, mainBodyName, id, offsetIdx + areaBeginIndexes, inParameters, outParameters, category); } else { string mainBodyName = string.Empty; int mainBodyLocalIndex = -1; Match mainBodyNameMatch = Regex.Match(body, TemplateHelperFunctions.VertexPragmaPattern); if (mainBodyNameMatch != null && mainBodyNameMatch.Groups.Count == 2) { mainBodyName = mainBodyNameMatch.Groups[1].Value; string pattern = string.Format(TemplateHelperFunctions.FunctionBodyStartPattern, mainBodyName); Match mainBodyIdMatch = Regex.Match(body, pattern); if (mainBodyIdMatch != null && mainBodyIdMatch.Groups.Count > 0) { mainBodyLocalIndex = mainBodyIdMatch.Index; } } m_vertexFunctionData = new TemplateFunctionData(mainBodyLocalIndex, mainBodyName, id, offsetIdx + areaBeginIndexes, inParameters, outParameters, category); } m_templateProperties.AddId(body, id, true); } }
public bool HasCustomInterpolatedData(string name, bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { if (m_customInterpolatedData.ContainsKey(name)) { MasterNodePortCategory category = useMasterNodeCategory ? m_currentDataCollector.PortCategory : customCategory; return((category == MasterNodePortCategory.Fragment) ? m_customInterpolatedData[name].IsFragment : m_customInterpolatedData[name].IsVertex); } return(false); }
public TemplateInputData(string tagId, string portName, string defaultValue, WirePortDataType dataType, MasterNodePortCategory portCategory, int portUniqueId, int orderId) { DefaultValue = defaultValue; PortName = portName; DataType = dataType; PortCategory = portCategory; PortUniqueId = portUniqueId; OrderId = orderId; TagId = tagId; }
public bool AddToLocalVariables(MasterNodePortCategory category, int nodeId, PrecisionType precisionType, WirePortDataType type, string varName, string varValue) { if (string.IsNullOrEmpty(varName) || string.IsNullOrEmpty(varValue)) { return(false); } string value = UIUtils.PrecisionWirePortToCgType(precisionType, type) + " " + varName + " = " + varValue + ";"; return(AddToLocalVariables(category, nodeId, value)); }
public TemplateInputData(TemplateInputData other) { DefaultValue = other.DefaultValue; PortName = other.PortName; DataType = other.DataType; PortCategory = other.PortCategory; PortUniqueId = other.PortUniqueId; OrderId = other.OrderId; TagId = other.TagId; TagStartIdx = other.TagStartIdx; }
public TemplateLocalVarData(TemplateInfoOnSematics specialVarType, string id, WirePortDataType dataType, MasterNodePortCategory category, string localVarName, int position) { m_id = id; m_dataType = dataType; m_localVarName = localVarName; m_position = position; m_specialVarType = specialVarType; m_isSpecialVar = true; m_category = category; //Debug.Log( m_localVarName + " " + m_inputData.PortCategory + " " + m_inputData.PortName ); }
public void ResetLocalValueIfNot( MasterNodePortCategory category ) { int idx = UIUtils.PortCategorytoAttayIdx( category ): for( int i = 0: i < m_localOutputValue.Length: i++ ) { if( i != idx ) { m_localOutputValue[ i ] = string.Empty: m_isLocalValue[ i ] = false: } } }
public TemplateInputData(int tagLocalStartIdx, int tagGlobalStartIdx, string tagId, string portName, string defaultValue, WirePortDataType dataType, MasterNodePortCategory portCategory, int portUniqueId, int orderId, string linkId) { DefaultValue = defaultValue; PortName = portName; DataType = dataType; PortCategory = portCategory; PortUniqueId = portUniqueId; OrderId = orderId; TagId = tagId; TagGlobalStartIdx = tagGlobalStartIdx; TagLocalStartIdx = tagLocalStartIdx; LinkId = linkId; }
void FetchInputs(MasterNodePortCategory portCategory) { string beginTag = (portCategory == MasterNodePortCategory.Fragment) ? TemplatesManager.TemplateInputsFragBeginTag : TemplatesManager.TemplateInputsVertBeginTag; int[] inputBeginIndexes = m_templateBody.AllIndexesOf(beginTag); if (inputBeginIndexes != null && inputBeginIndexes.Length > 0) { for (int i = 0; i < inputBeginIndexes.Length; i++) { int inputEndIdx = m_templateBody.IndexOf(TemplatesManager.TemplateEndSectionTag, inputBeginIndexes[i]); int defaultValueBeginIdx = inputEndIdx + TemplatesManager.TemplateEndSectionTag.Length; int endLineIdx = m_templateBody.IndexOf(TemplatesManager.TemplateFullEndTag, defaultValueBeginIdx); string defaultValue = m_templateBody.Substring(defaultValueBeginIdx, endLineIdx - defaultValueBeginIdx); string tagId = m_templateBody.Substring(inputBeginIndexes[i], endLineIdx + TemplatesManager.TemplateFullEndTag.Length - inputBeginIndexes[i]); int beginIndex = inputBeginIndexes[i] + beginTag.Length; int length = inputEndIdx - beginIndex; string inputData = m_templateBody.Substring(beginIndex, length); string[] inputDataArray = inputData.Split(IOUtils.FIELD_SEPARATOR); if (inputDataArray != null && inputDataArray.Length > 0) { try { string portName = inputDataArray[(int)TemplatePortIds.Name]; WirePortDataType dataType = (WirePortDataType)Enum.Parse(typeof(WirePortDataType), inputDataArray[(int)TemplatePortIds.DataType].ToUpper()); int portUniqueIDArrIdx = (int)TemplatePortIds.UniqueId; int portUniqueId = (portUniqueIDArrIdx < inputDataArray.Length) ? Convert.ToInt32(inputDataArray[portUniqueIDArrIdx]) : -1; if (portUniqueId < 0) { portUniqueId = m_inputDataList.Count; } int portOrderArrayIdx = (int)TemplatePortIds.OrderId; int portOrderId = (portOrderArrayIdx < inputDataArray.Length) ? Convert.ToInt32(inputDataArray[portOrderArrayIdx]) : -1; if (portOrderId < 0) { portOrderId = m_inputDataList.Count; } AddInput(tagId, portName, defaultValue, dataType, portCategory, portUniqueId, portOrderId); } catch (Exception e) { Debug.LogException(e); } } } } }
public string GetVertexPosition(WirePortDataType type, bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { if (HasInfo(TemplateInfoOnSematics.POSITION, useMasterNodeCategory, customCategory)) { InterpDataHelper info = GetInfo(TemplateInfoOnSematics.POSITION, useMasterNodeCategory, customCategory); return(TemplateHelperFunctions.AutoSwizzleData(info.VarName, info.VarType, type)); } else { MasterNodePortCategory portCategory = useMasterNodeCategory ? m_currentDataCollector.PortCategory : customCategory; string name = "ase_vertex_pos"; return(RegisterInfoOnSemantic(portCategory, TemplateInfoOnSematics.POSITION, TemplateSemantics.POSITION, name, type, true)); } }
public string GetVertexNormal(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { if (HasInfo(TemplateInfoOnSematics.NORMAL, useMasterNodeCategory, customCategory)) { InterpDataHelper info = GetInfo(TemplateInfoOnSematics.NORMAL, useMasterNodeCategory, customCategory); return(TemplateHelperFunctions.AutoSwizzleData(info.VarName, info.VarType, WirePortDataType.FLOAT3)); } else { MasterNodePortCategory category = useMasterNodeCategory ? m_currentDataCollector.PortCategory : customCategory; string name = "ase_normal"; return(RegisterInfoOnSemantic(category, TemplateInfoOnSematics.NORMAL, TemplateSemantics.NORMAL, name, WirePortDataType.FLOAT3, false)); } }
public string GetVertexTangent(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { if (HasInfo(TemplateInfoOnSematics.TANGENT, useMasterNodeCategory, customCategory)) { InterpDataHelper info = GetInfo(TemplateInfoOnSematics.TANGENT, useMasterNodeCategory, customCategory); return(info.VarName); } else { MasterNodePortCategory category = useMasterNodeCategory ? m_currentDataCollector.PortCategory : customCategory; string name = "ase_tangent"; return(RegisterInfoOnSemantic(category, TemplateInfoOnSematics.TANGENT, TemplateSemantics.TANGENT, name, WirePortDataType.FLOAT4, false)); } }
public string GetEyeDepth(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { string varName = "eyeDepth"; if (HasCustomInterpolatedData(varName, useMasterNodeCategory, customCategory)) { return(varName); } string objectToView = GetObjectToViewPos(false, MasterNodePortCategory.Vertex); string eyeDepthValue = string.Format("-{0}.z", objectToView); RegisterCustomInterpolatedData(varName, WirePortDataType.FLOAT, PrecisionType.Float, eyeDepthValue, useMasterNodeCategory, customCategory); return(varName); }
public string GetObjectToViewPos(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { string varName = "objectToViewPos"; if (HasCustomInterpolatedData(varName, useMasterNodeCategory, customCategory)) { return(varName); } string vertexPos = GetVertexPosition(WirePortDataType.FLOAT3, false, MasterNodePortCategory.Vertex); string objectToViewPosValue = string.Format("UnityObjectToViewPos({0})", vertexPos); RegisterCustomInterpolatedData(varName, WirePortDataType.FLOAT3, PrecisionType.Float, objectToViewPosValue, useMasterNodeCategory, customCategory); return(varName); }
public string GetWorldTangent(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { string varName = "worldTangent"; if (HasCustomInterpolatedData(varName, useMasterNodeCategory, customCategory)) { return(varName); } string vertexTangent = GetVertexTangent(false, MasterNodePortCategory.Vertex); string worldTangentValue = string.Format("UnityObjectToWorldDir({0})", vertexTangent); RegisterCustomInterpolatedData(varName, WirePortDataType.FLOAT3, PrecisionType.Float, worldTangentValue, useMasterNodeCategory, customCategory); return(varName); }
public string GetNormalizedViewDir(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { string varName = "normViewDir"; if (HasCustomInterpolatedData(varName, useMasterNodeCategory, customCategory)) { return(varName); } string viewDir = GetViewDir(false, MasterNodePortCategory.Vertex); string normViewDir = string.Format("normalize({0})", viewDir); RegisterCustomInterpolatedData(varName, WirePortDataType.FLOAT3, PrecisionType.Float, normViewDir, useMasterNodeCategory, customCategory); return(varName); }
public string GetViewDir(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { string varName = UIUtils.GetInputValueFromType(SurfaceInputs.VIEW_DIR); if (HasCustomInterpolatedData(varName, useMasterNodeCategory, customCategory)) { return(varName); } string worldPos = GetWorldPos(false, MasterNodePortCategory.Vertex); string viewDir = string.Format("UnityWorldSpaceViewDir({0})", worldPos); RegisterCustomInterpolatedData(varName, WirePortDataType.FLOAT3, PrecisionType.Float, viewDir, useMasterNodeCategory, customCategory); return(varName); }
public string GetScreenPos(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { string varName = UIUtils.GetInputValueFromType(SurfaceInputs.SCREEN_POS); if (HasCustomInterpolatedData(varName, useMasterNodeCategory, customCategory)) { return(varName); } string clipSpacePos = GetClipPos(false, MasterNodePortCategory.Vertex); string screenPosConversion = string.Format("ComputeScreenPos({0})", clipSpacePos); RegisterCustomInterpolatedData(varName, WirePortDataType.FLOAT4, PrecisionType.Float, screenPosConversion, useMasterNodeCategory, customCategory); return(varName); }
public string GetTangentSign(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { string varName = "tangentSign"; if (HasCustomInterpolatedData(varName, useMasterNodeCategory, customCategory)) { return(varName); } string tangentValue = GetVertexTangent(false, MasterNodePortCategory.Vertex); string tangentSignValue = string.Format("{0}.w * unity_WorldTransformParams.w", tangentValue); RegisterCustomInterpolatedData(varName, WirePortDataType.FLOAT, PrecisionType.Float, tangentSignValue, useMasterNodeCategory, customCategory); return(varName); }