Exemplo n.º 1
0
        void UpdateOutputs(WirePortDataType newType)
        {
            //this only happens when on initial load
            if (newType == WirePortDataType.OBJECT)
            {
                return;
            }

            m_currentType = newType;
            switch (newType)
            {
            case WirePortDataType.OBJECT:
            {
                m_outputPorts[0].ChangeProperties(Constants.EmptyPortValue, WirePortDataType.OBJECT, false);
                m_outputPorts[0].Visible = true;
                for (int i = 1; i < m_outputPorts.Count; i++)
                {
                    m_outputPorts[i].Visible = false;
                }
            }
            break;

            case WirePortDataType.FLOAT:
            {
                m_outputPorts[0].ChangeProperties(Constants.EmptyPortValue, WirePortDataType.FLOAT, false);
                m_outputPorts[0].Visible = true;
                for (int i = 1; i < m_outputPorts.Count; i++)
                {
                    m_outputPorts[i].Visible = false;
                }
            }
            break;

            case WirePortDataType.FLOAT2:
            {
                for (int i = 0; i < 2; i++)
                {
                    m_outputPorts[i].ChangeProperties(VectorPortNames[i], WirePortDataType.FLOAT, false);
                    m_outputPorts[i].Visible = true;
                }
                for (int i = 2; i < m_outputPorts.Count; i++)
                {
                    m_outputPorts[i].Visible = false;
                }
            }
            break;

            case WirePortDataType.FLOAT3:
            {
                for (int i = 0; i < 3; i++)
                {
                    m_outputPorts[i].ChangeProperties(VectorPortNames[i], WirePortDataType.FLOAT, false);
                    m_outputPorts[i].Visible = true;
                }
                for (int i = 3; i < m_outputPorts.Count; i++)
                {
                    m_outputPorts[i].Visible = false;
                }
            }
            break;

            case WirePortDataType.FLOAT4:
            {
                for (int i = 0; i < 4; i++)
                {
                    m_outputPorts[i].ChangeProperties(VectorPortNames[i], WirePortDataType.FLOAT, false);
                    m_outputPorts[i].Visible = true;
                }
                for (int i = 4; i < m_outputPorts.Count; i++)
                {
                    m_outputPorts[i].Visible = false;
                }
            }
            break;

            case WirePortDataType.FLOAT3x3:
            {
                for (int i = 0; i < 9; i++)
                {
                    m_outputPorts[i].ChangeProperties("[" + ( int )(i / 3) + "][" + i % 3 + "]", WirePortDataType.FLOAT, false);
                    m_outputPorts[i].Visible = true;
                }
                for (int i = 9; i < m_outputPorts.Count; i++)
                {
                    m_outputPorts[i].Visible = false;
                }
            }
            break;

            case WirePortDataType.FLOAT4x4:
            {
                for (int i = 0; i < 16; i++)
                {
                    m_outputPorts[i].ChangeProperties("[" + ( int )(i / 4) + "][" + i % 4 + "]", WirePortDataType.FLOAT, false);
                    m_outputPorts[i].Visible = true;
                }
            }
            break;

            case WirePortDataType.COLOR:
            {
                for (int i = 0; i < 4; i++)
                {
                    m_outputPorts[i].ChangeProperties(ColorPortNames[i], WirePortDataType.FLOAT, false);
                    m_outputPorts[i].Visible = true;
                }
                for (int i = 4; i < m_outputPorts.Count; i++)
                {
                    m_outputPorts[i].Visible = false;
                }
            }
            break;

            case WirePortDataType.INT:
            {
                m_outputPorts[0].Visible = true;
                m_outputPorts[0].ChangeProperties(Constants.EmptyPortValue, WirePortDataType.INT, false);
                for (int i = 1; i < m_outputPorts.Count; i++)
                {
                    m_outputPorts[i].Visible = false;
                }
            }
            break;
            }
            m_sizeIsDirty = true;
        }
Exemplo n.º 2
0
        public static bool CheckIfCompatibles(WirePortDataType first, WirePortDataType second)
        {
            switch (first)
            {
            case WirePortDataType.OBJECT:
                return(true);

            case WirePortDataType.FLOAT:
            case WirePortDataType.FLOAT2:
            case WirePortDataType.FLOAT3:
            case WirePortDataType.FLOAT4:
            case WirePortDataType.COLOR:
            case WirePortDataType.INT:
            {
                switch (second)
                {
                case WirePortDataType.FLOAT3x3:
                case WirePortDataType.FLOAT4x4:
                case WirePortDataType.SAMPLER1D:
                case WirePortDataType.SAMPLER2D:
                case WirePortDataType.SAMPLER3D:
                case WirePortDataType.SAMPLERCUBE:
                    return(false);
                }
            }
            break;

            case WirePortDataType.FLOAT3x3:
            case WirePortDataType.FLOAT4x4:
            {
                switch (second)
                {
                case WirePortDataType.FLOAT:
                case WirePortDataType.FLOAT2:
                case WirePortDataType.FLOAT3:
                case WirePortDataType.FLOAT4:
                case WirePortDataType.COLOR:
                case WirePortDataType.INT:
                case WirePortDataType.SAMPLER1D:
                case WirePortDataType.SAMPLER2D:
                case WirePortDataType.SAMPLER3D:
                case WirePortDataType.SAMPLERCUBE:
                    return(false);
                }
            }
            break;

            case WirePortDataType.SAMPLER1D:
            case WirePortDataType.SAMPLER2D:
            case WirePortDataType.SAMPLER3D:
            case WirePortDataType.SAMPLERCUBE:
            {
                switch (second)
                {
                case WirePortDataType.FLOAT:
                case WirePortDataType.FLOAT2:
                case WirePortDataType.FLOAT3:
                case WirePortDataType.FLOAT4:
                case WirePortDataType.FLOAT3x3:
                case WirePortDataType.FLOAT4x4:
                case WirePortDataType.COLOR:
                case WirePortDataType.INT:
                    return(false);
                }
            }
            break;
            }
            return(true);
        }
Exemplo n.º 3
0
 public override void OnConnectedOutputNodeChanges(int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type)
 {
     base.OnConnectedOutputNodeChanges(outputPortId, otherNodeId, otherPortId, name, type);
     m_inputPorts[0].MatchPortToConnection();
     m_outputPorts[0].ChangeType(m_inputPorts[0].DataType, false);
 }
Exemplo n.º 4
0
        // AUTOMATIC UVS
        static public string GenerateAutoUVs(ref MasterNodeDataCollector dataCollector, int uniqueId, int index, string propertyName = null, WirePortDataType size = WirePortDataType.FLOAT2, string scale = null, string offset = null, string outputId = null)
        {
            string result  = string.Empty;
            string varName = string.Empty;

            string indexStr = index > 0 ? (index + 1).ToString() : "";

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                string sizeDif = string.Empty;
                if (size == WirePortDataType.FLOAT3)
                {
                    sizeDif = "3";
                }
                else if (size == WirePortDataType.FLOAT4)
                {
                    sizeDif = "4";
                }

                string dummyPropUV = "_tex" + sizeDif + "coord" + indexStr;
                string dummyUV     = "uv" + indexStr + dummyPropUV;

                dataCollector.AddToProperties(uniqueId, "[HideInInspector] " + dummyPropUV + "( \"\", 2D ) = \"white\" {}", 100);
                dataCollector.AddToInput(uniqueId, dummyUV, size);

                result = Constants.InputVarStr + "." + dummyUV;
            }
            else
            {
                result = Constants.VertexShaderInputStr + ".texcoord";
                if (index > 0)
                {
                    result += index.ToString();
                }

                switch (size)
                {
                default:
                case WirePortDataType.FLOAT2:
                {
                    result += ".xy";
                }
                break;

                case WirePortDataType.FLOAT3:
                {
                    result += ".xyz";
                }
                break;

                case WirePortDataType.FLOAT4: break;
                }
            }

            varName = "uv" + indexStr + "_TexCoord" + outputId;

            if (!string.IsNullOrEmpty(propertyName))
            {
                dataCollector.AddToUniforms(uniqueId, "uniform float4 " + propertyName + "_ST;");
                if (size > WirePortDataType.FLOAT2)
                {
                    dataCollector.UsingHigherSizeTexcoords = true;
                    dataCollector.AddToLocalVariables(dataCollector.PortCategory, uniqueId, PrecisionType.Float, size, "uv" + propertyName, result);
                    dataCollector.AddToLocalVariables(dataCollector.PortCategory, uniqueId, "uv" + propertyName + ".xy = " + result + ".xy * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw;");
                }
                else
                {
                    dataCollector.AddToLocalVariables(dataCollector.PortCategory, uniqueId, PrecisionType.Float, size, "uv" + propertyName, result + " * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw");
                }

                result = "uv" + propertyName;
            }
            else if (!string.IsNullOrEmpty(scale) || !string.IsNullOrEmpty(offset))
            {
                if (size > WirePortDataType.FLOAT2)
                {
                    dataCollector.UsingHigherSizeTexcoords = true;
                    dataCollector.AddToLocalVariables(dataCollector.PortCategory, uniqueId, PrecisionType.Float, size, varName, result);
                    dataCollector.AddToLocalVariables(dataCollector.PortCategory, uniqueId, varName + ".xy = " + result + ".xy" + (string.IsNullOrEmpty(scale) ? "" : " * " + scale) + (string.IsNullOrEmpty(offset) ? "" : " + " + offset) + ";");
                }
                else
                {
                    dataCollector.AddToLocalVariables(dataCollector.PortCategory, uniqueId, PrecisionType.Float, size, varName, result + (string.IsNullOrEmpty(scale) ? "" : " * " + scale) + (string.IsNullOrEmpty(offset) ? "" : " + " + offset));
                }

                result = varName;
            }
            else if (dataCollector.PortCategory == MasterNodePortCategory.Fragment)
            {
                if (size > WirePortDataType.FLOAT2)
                {
                    dataCollector.UsingHigherSizeTexcoords = true;
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        public static TemplateInterpData CreateInterpDataList(string interpData, string fullLine)
        {
            TemplateInterpData        interpDataObj  = null;
            List <TemplateVertexData> interpDataList = null;
            Dictionary <TemplateSemantics, TemplateVertexData> interpDataDict = null;
            Match rangeMatch = Regex.Match(fullLine, InterpRangePattern);

            if (rangeMatch.Groups.Count > 0)
            {
                interpDataObj = new TemplateInterpData();
                // Get range of available interpolators
                int minVal = 0;
                int maxVal = 0;
                try
                {
                    string[] minValArgs = rangeMatch.Groups[1].Value.Split(IOUtils.FLOAT_SEPARATOR);
                    minVal = Convert.ToInt32(minValArgs[0]);
                    maxVal = Convert.ToInt32(rangeMatch.Groups[2].Value);
                    if (minVal > maxVal)
                    {
                        int aux = minVal;
                        minVal = maxVal;
                        maxVal = aux;
                    }
                    for (int i = minVal; i <= maxVal; i++)
                    {
                        interpDataObj.AvailableInterpolators.Add(new TemplateInterpElement(IntToSemantic[i]));
                    }
                    if (minValArgs.Length > 1)
                    {
                        interpDataObj.AvailableInterpolators[0].SetAvailableChannelsFromString(minValArgs[1]);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }

                //Get Current interpolators
                int    parametersBeginIdx = fullLine.IndexOf(":") + 1;
                int    parametersEnd      = fullLine.IndexOf(TemplatesManager.TemplateEndOfLine);
                string parametersBody     = fullLine.Substring(parametersBeginIdx, parametersEnd - parametersBeginIdx);

                foreach (Match match in Regex.Matches(interpData, VertexDataPattern))
                {
                    if (match.Groups.Count > 1)
                    {
                        if (interpDataList == null)
                        {
                            interpDataList = new List <TemplateVertexData>();
                            interpDataDict = new Dictionary <TemplateSemantics, TemplateVertexData>();
                        }

                        WirePortDataType   dataType           = CgToWirePortType[match.Groups[1].Value];
                        string             varName            = match.Groups[2].Value;
                        TemplateSemantics  semantics          = (TemplateSemantics)Enum.Parse(typeof(TemplateSemantics), match.Groups[3].Value);
                        TemplateVertexData templateVertexData = new TemplateVertexData(semantics, dataType, varName);
                        //interpDataList.Add( templateVertexData );
                        interpDataDict.Add(semantics, templateVertexData);
                        //Check if they are also on the free channels list and update their names
                        interpDataObj.ReplaceNameOnInterpolator(semantics, varName);
                    }
                }

                // Get info for available interpolators
                string[] paramsArray = parametersBody.Split(IOUtils.FIELD_SEPARATOR);
                if (paramsArray.Length > 0)
                {
                    for (int i = 0; i < paramsArray.Length; i++)
                    {
                        string[] paramDataArr = paramsArray[i].Split(IOUtils.VALUE_SEPARATOR);
                        if (paramDataArr.Length == 2)
                        {
                            string[]          swizzleInfoArr = paramDataArr[1].Split(IOUtils.FLOAT_SEPARATOR);
                            TemplateSemantics semantic       = ShortcutToSemantic[swizzleInfoArr[0]];
                            if (interpDataDict.ContainsKey(semantic))
                            {
                                if (interpDataDict[semantic] != null)
                                {
                                    TemplateVertexData templateVertexData = new TemplateVertexData(interpDataDict[semantic]);
                                    if (swizzleInfoArr.Length > 1)
                                    {
                                        templateVertexData.DataSwizzle = "." + swizzleInfoArr[1];
                                    }
                                    templateVertexData.DataInfo  = ShortcutToInfo[paramDataArr[0]];
                                    templateVertexData.Available = true;
                                    interpDataList.Add(templateVertexData);
                                }
                            }
                        }
                    }
                }

                /*TODO:
                 * 1) Remove interpDataList.Add( templateVertexData ); from initial foreach
                 * 2) When looping though each foreach array element, create a new TemplateVertexData
                 * from the one containted on the interpDataDict and add it to interpDataList
                 */

                interpDataObj.Interpolators = interpDataList;
                interpDataDict.Clear();
                interpDataDict = null;
            }
            return(interpDataObj);
        }
Exemplo n.º 6
0
        public string GenerateShaderForOutput(ref MasterNodeDataCollector dataCollector, WirePortDataType inputPortType, bool ignoreLocalVar, bool autoCast = false)
        {
            string result = string.Empty;

            if (m_externalReferences.Count > 0 && !m_locked)
            {
                result = UIUtils.GetNode(m_externalReferences[0].NodeId).GenerateShaderForOutput(m_externalReferences[0].PortId, ref dataCollector, ignoreLocalVar);
                if (autoCast && m_externalReferences[0].DataType != inputPortType)
                {
                    result = UIUtils.CastPortType(ref dataCollector, UIUtils.GetNode(m_nodeId).CurrentPrecisionType, new NodeCastInfo(m_externalReferences[0].NodeId, m_externalReferences[0].PortId), null, m_externalReferences[0].DataType, inputPortType, result);
                }
            }
            else
            {
                UpdateInternalData();
                if (!String.IsNullOrEmpty(m_internalDataWrapper))
                {
                    if (DataType == WirePortDataType.FLOAT3x3)
                    {
                        result = Matrix3x3WrappedData();
                    }
                    else
                    {
                        result = String.Format(m_internalDataWrapper, m_internalData);
                    }
                }
                else
                {
                    result = m_internalData;
                }
            }

            return(result);
        }
Exemplo n.º 7
0
		public override void OnConnectedOutputNodeChanges( int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
		{
			base.OnConnectedOutputNodeChanges( inputPortId, otherNodeId, otherPortId, name, type );
			FunctionInput functionInput = m_refreshIdsRequired ? m_allFunctionInputs[ inputPortId ] : GetFunctionInputByUniqueId( inputPortId );
			if( functionInput.AutoCast )
			{
				InputPort inputPort = m_refreshIdsRequired ? m_inputPorts[ inputPortId ] : GetInputPortByUniqueId( inputPortId );
				inputPort.MatchPortToConnection();

				ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
				ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;
				functionInput.ChangeOutputType( inputPort.DataType, false );
				ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
			}

			for( int i = 0; i < m_allFunctionOutputs.Count; i++ )
			{
				m_outputPorts[ i ].ChangeType( m_allFunctionOutputs[ i ].InputPorts[ 0 ].DataType, false );
			}
		}
Exemplo n.º 8
0
        public override void ReadFromString(ref string[] nodeParams)
        {
            // This node is, by default, created with one input port
            base.ReadFromString(ref nodeParams);
            m_code          = GetCurrentParam(ref nodeParams);
            m_code          = m_code.Replace(LineFeedSeparator, '\n');
            m_code          = m_code.Replace(SemiColonSeparator, ';');
            m_outputTypeIdx = Convert.ToInt32(GetCurrentParam(ref nodeParams));
            m_outputPorts[0].ChangeType(AvailableWireTypes[m_outputTypeIdx], false);

            if (UIUtils.CurrentShaderVersion() > 12001)
            {
                m_callMode = Convert.ToBoolean(GetCurrentParam(ref nodeParams));
                if (m_callMode)
                {
                    m_firstAvailablePort = 1;
                    AddInputPortAt(0, WirePortDataType.FLOAT, false, DefaultInputName);
                }
            }

            int count = Convert.ToInt32(GetCurrentParam(ref nodeParams));

            if (count == 0)
            {
                DeleteInputPortByArrayIdx(0);
                m_foldoutValuesLabels.Clear();
                m_variableQualifiers.Clear();
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    bool               foldoutValue = Convert.ToBoolean(GetCurrentParam(ref nodeParams));
                    string             name         = GetCurrentParam(ref nodeParams);
                    WirePortDataType   type         = ( WirePortDataType )Enum.Parse(typeof(WirePortDataType), GetCurrentParam(ref nodeParams));
                    string             internalData = GetCurrentParam(ref nodeParams);
                    VariableQualifiers qualifier    = VariableQualifiers.In;
                    if (UIUtils.CurrentShaderVersion() > 12001)
                    {
                        qualifier = ( VariableQualifiers )Enum.Parse(typeof(VariableQualifiers), GetCurrentParam(ref nodeParams));
                    }

                    int portIdx = i + m_firstAvailablePort;
                    if (i == 0)
                    {
                        m_inputPorts[portIdx].ChangeProperties(name, type, false);
                        m_variableQualifiers[0] = qualifier;
                        m_foldoutValuesFlags[0] = foldoutValue;
                    }
                    else
                    {
                        m_foldoutValuesLabels.Add("[" + i + "]");
                        m_variableQualifiers.Add(qualifier);
                        m_foldoutValuesFlags.Add(foldoutValue);
                        AddInputPort(type, false, name);
                    }
                    m_inputPorts[i].InternalData = internalData;
                }
            }

            if (UIUtils.CurrentShaderVersion() > 7205)
            {
                m_customExpressionName = GetCurrentParam(ref nodeParams);
                SetTitleText(m_customExpressionName);
            }

            m_repopulateNameDictionary = true;
            m_functionMode             = m_code.Contains(ReturnHelper);
        }
Exemplo n.º 9
0
 public void AddInput(int tagStartIdx, string tagId, string portName, string defaultValue, WirePortDataType dataType, MasterNodePortCategory portCategory, int portUniqueId, int portOrderId)
 {
     m_inputDataList.Add(new TemplateInputData(tagStartIdx, tagId, portName, defaultValue, dataType, portCategory, portUniqueId, portOrderId));
     AddId(tagId, false);
 }
        /// <summary>
        /// Generates UV properties and uniforms and returns the varible name to use in the fragment shader
        /// </summary>
        /// <param name="dataCollector"></param>
        /// <param name="uniqueId"></param>
        /// <param name="index"></param>
        /// <returns>frag variable name</returns>
        static public string GenerateFragUVs(ref MasterNodeDataCollector dataCollector, int uniqueId, int index, string propertyName = null, WirePortDataType size = WirePortDataType.FLOAT2)
        {
            string dummyPropUV = "_texcoord" + (index > 0 ? (index + 1).ToString() : "");
            string dummyUV     = "uv" + (index > 0 ? (index + 1).ToString() : "") + dummyPropUV;

            dataCollector.AddToProperties(uniqueId, "[HideInInspector] " + dummyPropUV + "( \"\", 2D ) = \"white\" {}", 100);
            dataCollector.AddToInput(uniqueId, UIUtils.WirePortToCgType(size) + " " + dummyUV, true);

            string result = Constants.InputVarStr + "." + dummyUV;

            if (!string.IsNullOrEmpty(propertyName))
            {
                dataCollector.AddToUniforms(uniqueId, "uniform float4 " + propertyName + "_ST;");
                dataCollector.AddToLocalVariables(uniqueId, PrecisionType.Float, size, "uv" + propertyName, result + " * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw");
                result = "uv" + propertyName;
            }

            return(result);
        }
Exemplo n.º 11
0
 public override void OnConnectedOutputNodeChanges(int portId, int otherNodeId, int otherPortId, string name, WirePortDataType type)
 {
     base.OnConnectedOutputNodeChanges(portId, otherNodeId, otherPortId, name, type);
     CheckPortConnection(portId);
 }
Exemplo n.º 12
0
 public OutputPort(int nodeId, int portId, WirePortDataType dataType, string name) : base(nodeId, portId, dataType, name)
 {
     LabelSize = Vector2.zero;
 }
Exemplo n.º 13
0
 public OutputPort(int nodeId, int portId, WirePortDataType dataType, string name) : base(nodeId, portId, dataType, name)
 {
 }
Exemplo n.º 14
0
		public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( m_inputPorts[ 0 ].DataType == WirePortDataType.FLOAT3x3 ||
				m_inputPorts[ 0 ].DataType == WirePortDataType.FLOAT4x4 ||
				m_inputPorts[ 1 ].DataType == WirePortDataType.FLOAT3x3 ||
				m_inputPorts[ 1 ].DataType == WirePortDataType.FLOAT4x4 )
			{
				m_inputA = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
				m_inputB = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):


				WirePortDataType autoCast = WirePortDataType.OBJECT:
				// Check matrix on first input
				if( m_inputPorts[ 0 ].DataType == WirePortDataType.FLOAT3x3 )
				{
					switch( m_inputPorts[ 1 ].DataType )
					{
						case WirePortDataType.OBJECT:
						case WirePortDataType.FLOAT:
						case WirePortDataType.INT:
						case WirePortDataType.FLOAT2:
						case WirePortDataType.FLOAT4:
						case WirePortDataType.COLOR:
						{
							m_inputB = UIUtils.CastPortType( ref dataCollector, m_currentPrecisionType, new NodeCastInfo( UniqueId, outputId ), m_inputB, m_inputPorts[ 1 ].DataType, WirePortDataType.FLOAT3, m_inputB ):
							autoCast = WirePortDataType.FLOAT3:
						}
						break:
						case WirePortDataType.FLOAT4x4:
						{
							m_inputA = UIUtils.CastPortType( ref dataCollector, m_currentPrecisionType, new NodeCastInfo( UniqueId, outputId ), m_inputA, m_inputPorts[ 0 ].DataType, WirePortDataType.FLOAT4x4, m_inputA ):
						}
						break:
						case WirePortDataType.FLOAT3:
						case WirePortDataType.FLOAT3x3: break:
					}
				}

				if( m_inputPorts[ 0 ].DataType == WirePortDataType.FLOAT4x4 )
				{
					switch( m_inputPorts[ 1 ].DataType )
					{
						case WirePortDataType.OBJECT:
						case WirePortDataType.FLOAT:
						case WirePortDataType.INT:
						case WirePortDataType.FLOAT2:
						case WirePortDataType.FLOAT3:
						{
							m_inputB = UIUtils.CastPortType( ref dataCollector, m_currentPrecisionType, new NodeCastInfo( UniqueId, outputId ), m_inputB, m_inputPorts[ 1 ].DataType, WirePortDataType.FLOAT4, m_inputB ):
							autoCast = WirePortDataType.FLOAT4:
						}
						break:
						case WirePortDataType.FLOAT3x3:
						{
							m_inputB = UIUtils.CastPortType( ref dataCollector, m_currentPrecisionType, new NodeCastInfo( UniqueId, outputId ), m_inputB, m_inputPorts[ 1 ].DataType, WirePortDataType.FLOAT4x4, m_inputB ):
						}
						break:
						case WirePortDataType.FLOAT4x4:
						case WirePortDataType.FLOAT4:
						case WirePortDataType.COLOR: break:
					}
				}

				// Check matrix on second input
				if( m_inputPorts[ 1 ].DataType == WirePortDataType.FLOAT3x3 )
				{
					switch( m_inputPorts[ 0 ].DataType )
					{
						case WirePortDataType.OBJECT:
						case WirePortDataType.FLOAT:
						case WirePortDataType.INT:
						case WirePortDataType.FLOAT2:
						case WirePortDataType.FLOAT4:
						case WirePortDataType.COLOR:
						{
							m_inputA = UIUtils.CastPortType( ref dataCollector, m_currentPrecisionType, new NodeCastInfo( UniqueId, outputId ), m_inputA, m_inputPorts[ 0 ].DataType, WirePortDataType.FLOAT3, m_inputA ):
							autoCast = WirePortDataType.FLOAT3:
						}
						break:
						case WirePortDataType.FLOAT4x4:
						case WirePortDataType.FLOAT3:
						case WirePortDataType.FLOAT3x3: break:
					}
				}

				if( m_inputPorts[ 1 ].DataType == WirePortDataType.FLOAT4x4 )
				{
					switch( m_inputPorts[ 0 ].DataType )
					{
						case WirePortDataType.OBJECT:
						case WirePortDataType.FLOAT:
						case WirePortDataType.INT:
						case WirePortDataType.FLOAT2:
						case WirePortDataType.FLOAT3:
						{
							m_inputA = UIUtils.CastPortType( ref dataCollector, m_currentPrecisionType, new NodeCastInfo( UniqueId, outputId ), m_inputA, m_inputPorts[ 0 ].DataType, WirePortDataType.FLOAT4, m_inputA ):
							autoCast = WirePortDataType.FLOAT4:
						}
						break:
						case WirePortDataType.FLOAT3x3:
						case WirePortDataType.FLOAT4x4:
						case WirePortDataType.FLOAT4:
						case WirePortDataType.COLOR: break:
					}
				}
				string result = "mul( " + m_inputA + ", " + m_inputB + " )":
				if( autoCast != WirePortDataType.OBJECT && autoCast != m_outputPorts[ 0 ].DataType )
				{
					result = UIUtils.CastPortType( ref dataCollector, m_currentPrecisionType, new NodeCastInfo( UniqueId, outputId ), result, autoCast, m_outputPorts[ 0 ].DataType, result ):
				}
				return result:
			}
			else
			{
				base.BuildResults( outputId, ref dataCollector, ignoreLocalvar ):
				string result = "( " + m_extensibleInputResults[ 0 ]:
				for( int i = 1: i < m_extensibleInputResults.Count: i++ )
				{
					result += " * " + m_extensibleInputResults[ i ]:
				}
				result += " )":
				return result:
			}
		}
 public TemplateShaderPropertyData(string propertyInspectorName, string propertyName, WirePortDataType propertyDataType, PropertyType propertyType)
 {
     PropertyInspectorName = string.IsNullOrEmpty(propertyInspectorName)?propertyName: propertyInspectorName;
     PropertyName          = propertyName;
     PropertyDataType      = propertyDataType;
     PropertyType          = propertyType;
 }
        void FetchInputs(int offset, MasterNodePortCategory portCategory, string body)
        {
            string beginTag = (portCategory == MasterNodePortCategory.Fragment) ? TemplatesManager.TemplateInputsFragBeginTag : TemplatesManager.TemplateInputsVertBeginTag;

            int[] inputBeginIndexes = body.AllIndexesOf(beginTag);
            if (inputBeginIndexes != null && inputBeginIndexes.Length > 0)
            {
                for (int i = 0; i < inputBeginIndexes.Length; i++)
                {
                    int inputEndIdx          = body.IndexOf(TemplatesManager.TemplateEndSectionTag, inputBeginIndexes[i]);
                    int defaultValueBeginIdx = inputEndIdx + TemplatesManager.TemplateEndSectionTag.Length;
                    int endLineIdx           = body.IndexOf(TemplatesManager.TemplateFullEndTag, defaultValueBeginIdx);

                    string defaultValue = body.Substring(defaultValueBeginIdx, endLineIdx - defaultValueBeginIdx);
                    string tagId        = body.Substring(inputBeginIndexes[i], endLineIdx + TemplatesManager.TemplateFullEndTag.Length - inputBeginIndexes[i]);

                    int      beginIndex     = inputBeginIndexes[i] + beginTag.Length;
                    int      length         = inputEndIdx - beginIndex;
                    string   inputData      = body.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());
                            if (inputDataArray.Length == 3)
                            {
                                int  portOrderId  = m_inputDataList.Count;
                                int  portUniqueId = -1;
                                bool isInt        = int.TryParse(inputDataArray[2], out portUniqueId);
                                if (isInt)
                                {
                                    if (portUniqueId < 0)
                                    {
                                        portUniqueId = m_inputDataList.Count;
                                    }

                                    m_inputDataList.Add(new TemplateInputData(inputBeginIndexes[i], offset + inputBeginIndexes[i], tagId, portName, defaultValue, dataType, portCategory, portUniqueId, portOrderId, string.Empty));
                                    m_templateProperties.AddId(body, tagId, false);
                                }
                                else
                                {
                                    portUniqueId = m_inputDataList.Count;
                                    m_inputDataList.Add(new TemplateInputData(inputBeginIndexes[i], offset + inputBeginIndexes[i], tagId, portName, defaultValue, dataType, portCategory, portUniqueId, portOrderId, inputDataArray[2]));
                                    m_templateProperties.AddId(body, tagId, false);
                                }
                            }
                            else
                            {
                                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;
                                }

                                int    portLinkIdx = (int)TemplatePortIds.Link;
                                string linkId      = (portLinkIdx < inputDataArray.Length) ? inputDataArray[portLinkIdx] : string.Empty;
                                m_inputDataList.Add(new TemplateInputData(inputBeginIndexes[i], offset + inputBeginIndexes[i], tagId, portName, defaultValue, dataType, portCategory, portUniqueId, portOrderId, linkId));
                                m_templateProperties.AddId(body, tagId, false);
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
		public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
		{
			base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ):
			GetInputPortByUniqueId( outputPortId ).MatchPortToConnection():
			UpdateOutputPort():
		}
Exemplo n.º 18
0
        public override string GenerateShaderForOutput(int outputId, WirePortDataType inputPortType, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            string result = string.Empty;

            string colorTarget = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, inputPortType, ignoreLocalvar);

            WirePortDataType dataType = m_inputPorts[0].ConnectionType();

            if (dataType != WirePortDataType.COLOR && dataType != WirePortDataType.FLOAT4)
            {
                colorTarget = UIUtils.CastPortType(new NodeCastInfo(m_uniqueId, outputId), null, dataType, WirePortDataType.FLOAT4, colorTarget);
            }

            string localVarName = "ChannelBlendNode" + m_uniqueId;
            string localVar     = "float4 " + localVarName + " = " + colorTarget + ";";

            dataCollector.AddToLocalVariables(m_uniqueId, localVar);
            m_inputPorts[1].InternalData = m_inputPorts[1].IsConnected ? m_inputPorts[1].GenerateShaderForOutput(ref dataCollector, inputPortType, ignoreLocalvar) : m_defaultAmounts[0].ToString();
            m_inputPorts[2].InternalData = m_inputPorts[2].IsConnected ? m_inputPorts[2].GenerateShaderForOutput(ref dataCollector, inputPortType, ignoreLocalvar) : m_defaultAmounts[1].ToString();
            m_inputPorts[3].InternalData = m_inputPorts[3].IsConnected ? m_inputPorts[3].GenerateShaderForOutput(ref dataCollector, inputPortType, ignoreLocalvar) : m_defaultAmounts[2].ToString();
            m_inputPorts[4].InternalData = m_inputPorts[4].IsConnected ? m_inputPorts[4].GenerateShaderForOutput(ref dataCollector, inputPortType, ignoreLocalvar) : m_defaultAmounts[3].ToString();

            if (m_isLayered)
            {
                string           layerMask = m_inputPorts[4].IsConnected ? m_inputPorts[4].GenerateShaderForOutput(ref dataCollector, inputPortType, ignoreLocalvar) : m_defaultLayerFactor.ToString();
                WirePortDataType dataType4 = m_inputPorts[4].ConnectionType();
                if (dataType4 != WirePortDataType.FLOAT)
                {
                    layerMask = UIUtils.CastPortType(new NodeCastInfo(m_uniqueId, outputId), null, dataType4, WirePortDataType.FLOAT, layerMask);
                }

                if (m_activePorts == 0)
                {
                    result = colorTarget;
                }
                else if (m_activePorts == 1)
                {
                    result += "lerp( " + layerMask + "," + m_inputPorts[1].InternalData + " , " + localVarName + ".r )";
                }
                else
                {
                    result = layerMask;
                    for (int i = 0; i < m_activePorts; i++)
                    {
                        result = "lerp( " + result + " , " + m_inputPorts[i + 1].InternalData + " , " + localVarName + UIUtils.GetComponentForPosition(i, m_inputPorts[0].DataType, true) + " )";
                    }
                }
            }
            else
            {
                if (m_activePorts == 0)
                {
                    result = colorTarget;
                }
                else if (m_activePorts == 1)
                {
                    result += localVarName + "*" + m_inputPorts[1].InternalData;
                }
                else
                {
                    for (int i = 1; i < (m_activePorts + 1); i++)
                    {
                        result += localVarName + UIUtils.GetComponentForPosition(i - 1, m_inputPorts[0].DataType, true) + "*" + m_inputPorts[i].InternalData;
                        if (i != m_activePorts)
                        {
                            result += " + ";
                        }
                    }
                }
            }
            result = UIUtils.AddBrackets(result);
            return(CreateOutputLocalVariable(0, result, ref dataCollector));
        }
Exemplo n.º 19
0
        public void GetFirstAvailableName(int nodeId, WirePortDataType type, out string outProperty, out string outInspector, bool useCustomPrefix = false, string customPrefix = null)
        {
            string name = string.Empty;

            if (useCustomPrefix && customPrefix != null)
            {
                name = customPrefix;
            }
            else
            {
                switch (type)
                {
                case WirePortDataType.OBJECT:
                case WirePortDataType.FLOAT:
                {
                    name = FloatNameStr;
                }
                break;

                case WirePortDataType.INT:
                {
                    name = IntNameStr;
                }
                break;

                case WirePortDataType.FLOAT2:
                case WirePortDataType.FLOAT3:
                case WirePortDataType.FLOAT4:
                {
                    name = VectorNameStr;
                }
                break;

                case WirePortDataType.FLOAT3x3:
                case WirePortDataType.FLOAT4x4:
                {
                    name = MatrixNameStr;
                }
                break;

                case WirePortDataType.COLOR:
                {
                    name = ColorNameStr;
                }
                break;
                }
            }

            int  count     = 0;
            bool foundName = false;

            while (!foundName)
            {
                string inspectorName = name + count;
                string propertyName  = UIUtils.GeneratePropertyName(inspectorName, PropertyType.Property);

                if (IsUniformNameAvailable(propertyName))
                {
                    outInspector = inspectorName;
                    outProperty  = propertyName;
                    RegisterUniformName(nodeId, propertyName);
                    return;
                }
                count += 1;
            }
            outProperty  = string.Empty;
            outInspector = string.Empty;
            UIUtils.ShowMessage("Could not find a valid name " + MessageSeverity.Warning);
        }
Exemplo n.º 20
0
        //public override void DrawProperties()
        //{
        //	base.DrawProperties();
        //	EditorGUI.BeginChangeCheck();
        //	_isLayered = EditorGUILayout.ToggleLeft( IsLayerStr, _isLayered );
        //	if ( EditorGUI.EndChangeCheck() )
        //	{
        //		_inputPorts[ 5 ].Visible = _isLayered;
        //		if ( !_inputPorts[ 5 ].Visible && _inputPorts[ 5 ].IsConnected )
        //		{
        //			UIUtils.CurrentWindow.DeleteConnection( true, _uniqueId, 5, true );
        //		}
        //		_sizeIsDirty = true;
        //	}

        //	if ( _isLayered )
        //	{
        //		_defaultLayerFactor = EditorGUILayout.FloatField( LayerFactorStr, _defaultLayerFactor );
        //	}

        //	for ( int i = 0; i < _activePorts; i++ )
        //	{
        //		_defaultAmounts[ i ] = EditorGUILayout.FloatField( AmountsStr[ i ], _defaultAmounts[ i ] );
        //	}
        //}

        public override void OnConnectedOutputNodeChanges(int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type)
        {
            if (inputPortId == 0)
            {
                UpdateConnection(true);
            }
        }
Exemplo n.º 21
0
        private void ConfigPortsFromMaterial(bool invalidateConnections = false, Texture[] newTextures = null)
        {
            //PreviewSizeX = ( m_proceduralMaterial != null ) ? UIUtils.ObjectField.CalcSize( new GUIContent( m_proceduralMaterial.name ) ).x + 15 : 110;
            //m_insideSize.x = TexturePreviewSizeX + 5;
            SetAdditonalTitleText((m_proceduralMaterial != null) ? string.Format(Constants.PropertyValueLabel, m_proceduralMaterial.name) : "Value( <None> )");

            Texture[] textures = newTextures != null ? newTextures : ((m_proceduralMaterial != null) ? m_proceduralMaterial.GetGeneratedTextures() : null);
            if (textures != null)
            {
                string nameToRemove = m_proceduralMaterial.name + "_";
                m_textureTypes = new ProceduralOutputType[textures.Length];
                for (int i = 0; i < textures.Length; i++)
                {
                    ProceduralTexture procTex = textures[i] as ProceduralTexture;
                    m_textureTypes[i] = procTex.GetProceduralOutputType();

                    WirePortDataType portType    = (m_autoNormal && m_textureTypes[i] == ProceduralOutputType.Normal) ? WirePortDataType.FLOAT3 : WirePortDataType.COLOR;
                    string           newName     = textures[i].name.Replace(nameToRemove, string.Empty);
                    char             firstLetter = Char.ToUpper(newName[0]);
                    newName = firstLetter.ToString() + newName.Substring(1);
                    if (i < m_outputPorts.Count)
                    {
                        m_outputPorts[i].ChangeProperties(newName, portType, false);
                        if (invalidateConnections)
                        {
                            m_outputPorts[i].FullDeleteConnections();
                        }
                    }
                    else
                    {
                        AddOutputPort(portType, newName);
                    }
                }

                if (textures.Length < m_outputPorts.Count)
                {
                    int itemsToRemove = m_outputPorts.Count - textures.Length;
                    for (int i = 0; i < itemsToRemove; i++)
                    {
                        int idx = m_outputPorts.Count - 1;
                        if (m_outputPorts[idx].IsConnected)
                        {
                            m_outputPorts[idx].ForceClearConnection();
                        }
                        RemoveOutputPort(idx);
                    }
                }
            }
            else
            {
                int itemsToRemove = m_outputPorts.Count - 1;
                m_outputPorts[0].ChangeProperties(Constants.EmptyPortValue, WirePortDataType.COLOR, false);
                m_outputPorts[0].ForceClearConnection();

                for (int i = 0; i < itemsToRemove; i++)
                {
                    int idx = m_outputPorts.Count - 1;
                    if (m_outputPorts[idx].IsConnected)
                    {
                        m_outputPorts[idx].ForceClearConnection();
                    }
                    RemoveOutputPort(idx);
                }
            }

            m_sizeIsDirty = true;
            m_isDirty     = true;
            //Event.current.Use();
        }
Exemplo n.º 22
0
		public AppendData( WirePortDataType portType, int oldPortId, int newPortId )
		{
			PortType = portType:
			OldPortId = oldPortId:
			NewPortId = newPortId:
		}
Exemplo n.º 23
0
        // VERTEX POSITION
        static public string GenerateVertexPosition(ref MasterNodeDataCollector dataCollector, int uniqueId, WirePortDataType size)
        {
            string value = Constants.VertexShaderInputStr + ".vertex";

            if (size == WirePortDataType.FLOAT3)
            {
                value += ".xyz";
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                dataCollector.AddToInput(uniqueId, SurfaceInputs.WORLD_POS);
                dataCollector.AddToIncludes(uniqueId, Constants.UnityShaderVariables);

                value = "mul( unity_WorldToObject, float4( " + Constants.InputVarStr + ".worldPos , 1 ) )";
            }
            string varName = VertexPosition4Str;

            if (size == WirePortDataType.FLOAT3)
            {
                varName = VertexPosition3Str;
            }

            dataCollector.AddLocalVariable(uniqueId, PrecisionType.Float, size, varName, value);
            return(varName);
        }
Exemplo n.º 24
0
		public override void OnConnectedOutputNodeChanges( int portId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
		{
			base.OnConnectedOutputNodeChanges( portId, otherNodeId, otherPortId, name, type ):

			if( ( UIUtils.IsLoading || m_isNodeBeingCopied ) && UIUtils.CurrentShaderVersion() < 13206 )
				return:

			NewUpdateBehaviorConn( portId, ( UIUtils.IsLoading || m_isNodeBeingCopied ) ):
			RenamePorts():
		}
Exemplo n.º 25
0
        public static string AutoSwizzleData(string dataVar, WirePortDataType dataType, WirePortDataType swizzle)
        {
            switch (dataType)
            {
            case WirePortDataType.COLOR:
            case WirePortDataType.FLOAT4:
            {
                switch (swizzle)
                {
                case WirePortDataType.FLOAT3: dataVar += ".xyz"; break;

                case WirePortDataType.FLOAT2: dataVar += ".xy"; break;

                case WirePortDataType.INT:
                case WirePortDataType.FLOAT: dataVar += ".x"; break;
                }
            }
            break;

            case WirePortDataType.FLOAT3:
            {
                switch (swizzle)
                {
                case WirePortDataType.FLOAT4: dataVar = string.Format("float4({0},0)", dataVar); break;

                case WirePortDataType.FLOAT2: dataVar += ".xy"; break;

                case WirePortDataType.INT:
                case WirePortDataType.FLOAT: dataVar += ".x"; break;
                }
            }
            break;

            case WirePortDataType.FLOAT2:
            {
                switch (swizzle)
                {
                case WirePortDataType.FLOAT4: dataVar = string.Format("float4({0},0,0)", dataVar); break;

                case WirePortDataType.FLOAT3: dataVar = string.Format("float3({0},0)", dataVar); break;

                case WirePortDataType.INT:
                case WirePortDataType.FLOAT: dataVar += ".x"; break;
                }
            }
            break;

            case WirePortDataType.FLOAT:
            {
                switch (swizzle)
                {
                case WirePortDataType.FLOAT4: dataVar = string.Format("float4({0},0,0,0)", dataVar); break;

                case WirePortDataType.FLOAT3: dataVar = string.Format("float3({0},0,0)", dataVar); break;

                case WirePortDataType.FLOAT2: dataVar = string.Format("float2({0},0)", dataVar); break;
                }
            }
            break;
            }
            return(dataVar);
        }
Exemplo n.º 26
0
 public void SetReference(WirePort port)
 {
     m_nodeId   = port.NodeId;
     m_portId   = port.PortId;
     m_dataType = port.DataType;
 }
Exemplo n.º 27
0
 public override void OnConnectedOutputNodeChanges(int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type)
 {
     base.OnConnectedOutputNodeChanges(inputPortId, otherNodeId, otherPortId, name, type);
     UpdateConnections();
 }
Exemplo n.º 28
0
 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;
 }
Exemplo n.º 29
0
 public override string GenerateShaderForOutput(int outputId, WirePortDataType inputPortType, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
 {
     return(m_variableName);
 }
Exemplo n.º 30
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (!m_texPort.IsConnected)
            {
                UIUtils.ShowMessage(UniqueId, "Parallax Occlusion Mapping node only works if a Texture Object is connected to its Tex (R) port");
                return("0");
            }
            base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar);
            WirePortDataType texType = (m_pomTexType == POMTexTypes.Texture3D)?WirePortDataType.SAMPLER3D: WirePortDataType.SAMPLER2D;

            GeneratePOMfunction();
            string arrayIndex = m_arrayIndexPort.Visible?m_arrayIndexPort.GeneratePortInstructions(ref dataCollector):"0";
            string textcoords = m_uvPort.GeneratePortInstructions(ref dataCollector);

            if (m_pomTexType == POMTexTypes.Texture3D)
            {
                string texName = "pomTexCoord" + OutputId;
                dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, texName, string.Format("float3({0},{1})", textcoords, arrayIndex));
                textcoords = texName;
            }

            string texture = m_texPort.GenerateShaderForOutput(ref dataCollector, texType, false, true);
            string scale   = m_defaultScale.ToString();

            if (m_scalePort.IsConnected)
            {
                scale = m_scalePort.GeneratePortInstructions(ref dataCollector);
            }

            string viewDirTan = "";

            if (!m_viewdirTanPort.IsConnected)
            {
                if (!dataCollector.DirtyNormal)
                {
                    dataCollector.ForceNormal = true;
                }


                if (dataCollector.IsTemplate)
                {
                    viewDirTan = dataCollector.TemplateDataCollectorInstance.GetTangentViewDir(CurrentPrecisionType);
                }
                else
                {
                    viewDirTan = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, ViewSpace.Tangent);
                    //dataCollector.AddToInput( UniqueId, SurfaceInputs.VIEW_DIR, m_currentPrecisionType );
                    //viewDirTan = Constants.InputVarStr + "." + UIUtils.GetInputValueFromType( SurfaceInputs.VIEW_DIR );
                }
            }
            else
            {
                viewDirTan = m_viewdirTanPort.GeneratePortInstructions(ref dataCollector);
            }

            //generate world normal
            string normalWorld = string.Empty;

            if (dataCollector.IsTemplate)
            {
                normalWorld = dataCollector.TemplateDataCollectorInstance.GetWorldNormal(CurrentPrecisionType);
            }
            else
            {
                dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType);
                dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false);
                normalWorld = GeneratorUtils.GenerateWorldNormal(ref dataCollector, UniqueId);
            }

            //string normalWorld = "WorldNormalVector( " + Constants.InputVarStr + ", float3( 0, 0, 1 ) )";

            //generate viewDir in world space

            //string worldPos = string.Empty;
            //if( dataCollector.IsTemplate )
            //{
            //	worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos();
            //}
            //else
            //{
            //	dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS );
            //	worldPos = Constants.InputVarStr + ".worldPos";
            //}

            //if( !dataCollector.IsTemplate )
            //	dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS );

            string worldViewDir = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, ViewSpace.World);
            //dataCollector.AddToLocalVariables( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, WorldDirVarStr, TemplateHelperFunctions.WorldSpaceViewDir( dataCollector, worldPos, true ) );
            string dx = "ddx(" + textcoords + ")";
            string dy = "ddy(" + textcoords + ")";

            string refPlane = m_defaultRefPlane.ToString();

            if (m_refPlanePort.IsConnected)
            {
                refPlane = m_refPlanePort.GeneratePortInstructions(ref dataCollector);
            }


            string curvature = "float2(" + m_CurvatureVector.x + "," + m_CurvatureVector.y + ")";

            if (m_useCurvature)
            {
                dataCollector.AddToProperties(UniqueId, "[Header(Parallax Occlusion Mapping)]", 300);
                dataCollector.AddToProperties(UniqueId, "_CurvFix(\"Curvature Bias\", Range( 0 , 1)) = 1", 301);
                dataCollector.AddToUniforms(UniqueId, "uniform float _CurvFix;");

                if (m_curvaturePort.IsConnected)
                {
                    curvature = m_curvaturePort.GeneratePortInstructions(ref dataCollector);
                }
            }


            string localVarName = "OffsetPOM" + UniqueId;
            string textCoordsST = string.Empty;

            //string textureSTType = dataCollector.IsSRP ? "float4 " : "uniform float4 ";
            //dataCollector.AddToUniforms( UniqueId, textureSTType + texture +"_ST;");
            if (m_texCoordsHelper == null)
            {
                m_texCoordsHelper = CreateInstance <Vector4Node>();
                m_texCoordsHelper.ContainerGraph = ContainerGraph;
                m_texCoordsHelper.SetBaseUniqueId(UniqueId, true);
                m_texCoordsHelper.RegisterPropertyOnInstancing = false;
                m_texCoordsHelper.AddGlobalToSRPBatcher        = true;
            }

            if (UIUtils.CurrentWindow.OutsideGraph.IsInstancedShader)
            {
                m_texCoordsHelper.CurrentParameterType = PropertyType.InstancedProperty;
            }
            else
            {
                m_texCoordsHelper.CurrentParameterType = PropertyType.Global;
            }
            m_texCoordsHelper.ResetOutputLocals();
            m_texCoordsHelper.SetRawPropertyName(texture + "_ST");
            textCoordsST = m_texCoordsHelper.GenerateShaderForOutput(0, ref dataCollector, false);
            //////

            if (m_pomTexType == POMTexTypes.TextureArray)
            {
                dataCollector.UsingArrayDerivatives = true;
            }
            string textureArgs = string.Empty;

            if (m_pomTexType == POMTexTypes.TextureArray)
            {
                if (UIUtils.CurrentWindow.OutsideGraph.IsSRP)
                {
                    textureArgs = "TEXTURE2D_ARRAY_PARAM(" + texture + " , " + "sampler##" + texture + ")";
                }
                else
                {
                    textureArgs = "UNITY_PASS_TEX2DARRAY(" + texture + ")";
                }
            }
            else
            {
                bool sampleThroughMacros = UIUtils.CurrentWindow.OutsideGraph.SamplingThroughMacros;
                if (sampleThroughMacros)
                {
                    dataCollector.AddToUniforms(UniqueId, string.Format(Constants.SamplerDeclarationSRPMacros[TextureType.Texture2D], texture));
                    textureArgs = string.Format("{0},sampler{0}", texture);
                }
                else
                {
                    textureArgs = texture;
                }
            }
            //string functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, ( (m_pomTexType == POMTexTypes.TextureArray) ? "UNITY_PASS_TEX2DARRAY(" + texture + ")": texture), textcoords, dx, dy, normalWorld, worldViewDir, viewDirTan, m_minSamples, m_maxSamples, scale, refPlane, texture+"_ST.xy", curvature, arrayIndex );
            string functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, textureArgs, textcoords, dx, dy, normalWorld, worldViewDir, viewDirTan, m_inlineMinSamples.GetValueOrProperty(false), m_inlineMinSamples.GetValueOrProperty(false), scale, refPlane, textCoordsST + ".xy", curvature, arrayIndex);

            dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, m_pomUVPort.DataType, localVarName, functionResult);

            return(GetOutputVectorItem(0, outputId, localVarName));
        }