// VERTEX TANGENT
        static public string GenerateVertexTangent(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision)
        {
            string value = Constants.VertexShaderInputStr + ".tangent.xyz";

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                GenerateWorldTangent(ref dataCollector, uniqueId);
                dataCollector.AddToLocalVariables(uniqueId, precision, WirePortDataType.FLOAT3, VertexTangentStr, "mul( unity_WorldToObject, float4( " + WorldTangentStr + ", 0 ) )");
            }
            else
            {
                dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT3, VertexTangentStr, value);
            }
            return(VertexTangentStr);
        }
 // VERTEX BITANGENT
 static public string GenerateVertexBitangent(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision)
 {
     if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
     {
         GenerateWorldBitangent(ref dataCollector, uniqueId);
         dataCollector.AddToLocalVariables(uniqueId, precision, WirePortDataType.FLOAT3, VertexBitangentStr, "mul( unity_WorldToObject, float4( " + WorldBitangentStr + ", 0 ) )");
     }
     else
     {
         GenerateVertexNormal(ref dataCollector, uniqueId, precision);
         GenerateVertexTangent(ref dataCollector, uniqueId, precision);
         dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT3, VertexBitangentStr, "cross( " + VertexNormalStr + ", " + VertexTangentStr + ") * " + Constants.VertexShaderInputStr + ".tangent.w * unity_WorldTransformParams.w");
     }
     return(VertexBitangentStr);
 }
Example #3
0
        // VERTEX TANGENT SIGN
        static public string GenerateVertexTangentSign(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision)
        {
            string value = Constants.VertexShaderInputStr + ".tangent.w";

            if (dataCollector.IsFragmentCategory)
            {
                dataCollector.AddToInput(uniqueId, VertexTangentSignStr, WirePortDataType.FLOAT, PrecisionType.Fixed);
                dataCollector.AddToVertexLocalVariables(uniqueId, Constants.VertexShaderOutputStr + "." + VertexTangentSignStr + " = " + Constants.VertexShaderInputStr + ".tangent.w;");
                return(Constants.InputVarStr + "." + VertexTangentSignStr);
            }
            else
            {
                dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT, VertexTangentSignStr, value);
            }
            return(VertexTangentSignStr);
        }
Example #4
0
		// SCREEN POSITION
		static public string GenerateScreenPositionForValue( string customVertexPosition, string outputId, ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision, bool addInput = true )
		{
			if( dataCollector.IsTemplate )
				return dataCollector.TemplateDataCollectorInstance.GetScreenPosForValue( customVertexPosition, outputId ):


			string value = GenerateVertexScreenPositionForValue( customVertexPosition, outputId, ref dataCollector, uniqueId, precision ):
			string screenPosVarName = "screenPosition" + outputId:
			dataCollector.AddToInput( uniqueId, screenPosVarName, WirePortDataType.FLOAT4, precision ):
			dataCollector.AddToVertexLocalVariables( uniqueId, Constants.VertexShaderOutputStr + "." + screenPosVarName + " = " + value + ":" ):

			string screenPosVarNameOnFrag = ScreenPositionStr + outputId:
			string globalResult = Constants.InputVarStr + "." + screenPosVarName:
			dataCollector.AddLocalVariable( uniqueId, string.Format( "float4 {0} = {1}:", screenPosVarNameOnFrag, globalResult ) ):
			return screenPosVarNameOnFrag:

		}
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			string src = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
			

			bool isScaledNormal = false:
			if ( m_inputPorts[ 1 ].IsConnected )
			{
				isScaledNormal = true:
			}
			else
			{
				if ( m_inputPorts[ 1 ].FloatInternalData != 1 )
				{
					isScaledNormal = true:
				}
			}

			string normalMapUnpackMode = string.Empty:
			string scaleValue = isScaledNormal?m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):"1.0":
			normalMapUnpackMode = string.Format( TemplateHelperFunctions.CreateUnpackNormalStr( dataCollector, isScaledNormal, scaleValue ), src):
			if( isScaledNormal && !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
			{
				dataCollector.AddToIncludes( UniqueId, Constants.UnityStandardUtilsLibFuncs ):
			}
			
			int outputUsage = 0:
			for ( int i = 0: i < m_outputPorts.Count: i++ )
			{
				if ( m_outputPorts[ i ].IsConnected )
					outputUsage += 1:
			}


			if ( outputUsage > 1 )
			{
				string varName = "localUnpackNormal" + UniqueId:
				dataCollector.AddLocalVariable( UniqueId, "float3 " + varName + " = " + normalMapUnpackMode + ":" ):
				return GetOutputVectorItem( 0, outputId, varName ):
			}
			else
			{
				return GetOutputVectorItem( 0, outputId, normalMapUnpackMode ):
			}
		}
Example #6
0
        // SCREEN POSITION
        static public string GenerateScreenPosition(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision, bool addInput = true)
        {
            if (dataCollector.IsTemplate)
            {
                return(dataCollector.TemplateDataCollectorInstance.GetScreenPos());
            }

            if (addInput)
            {
                dataCollector.AddToInput(uniqueId, UIUtils.GetInputDeclarationFromType(precision, AvailableSurfaceInputs.SCREEN_POS), true);
            }

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

            dataCollector.AddLocalVariable(uniqueId, string.Format("float4 {0} = float4( {1}.xyz , {1}.w + 0.00000000001 );", ScreenPositionStr, result));

            return(ScreenPositionStr);
        }
Example #7
0
		static public string GenerateTangentToWorldMatrixPrecise( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision )
		{
			if( dataCollector.IsTemplate )
				return dataCollector.TemplateDataCollectorInstance.GetTangentToWorldMatrixPrecise( precision ):

			if( dataCollector.IsFragmentCategory )
			{
				dataCollector.ForceNormal = true:

				dataCollector.AddToInput( -1, SurfaceInputs.WORLD_NORMAL, precision ):
				dataCollector.AddToInput( -1, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
			}

			string worldToTangent = GenerateWorldToTangentMatrix( ref dataCollector, uniqueId, precision ):
			Add3x3InverseFunction( ref dataCollector, UIUtils.PrecisionWirePortToCgType( precision, WirePortDataType.FLOAT ) ):
			dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT3x3, TangentToWorldPreciseStr, string.Format( Inverse3x3Header, worldToTangent ) ):
			return TangentToWorldPreciseStr:
		}
        // VERTEX TANGENT SIGN
        static public string GenerateVertexTangentSign(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision)
        {
            string value = Constants.VertexShaderInputStr + ".tangent.w";

            if (dataCollector.IsFragmentCategory)
            {
                //GenerateWorldTangent( ref dataCollector, uniqueId );
                dataCollector.AddToInput(uniqueId, "fixed " + VertexTangentSignStr, true);
                dataCollector.AddToVertexLocalVariables(uniqueId, Constants.VertexShaderOutputStr + "." + VertexTangentSignStr + " = " + Constants.VertexShaderInputStr + ".tangent.w;");
                return(Constants.InputVarStr + "." + VertexTangentSignStr);
                //dataCollector.AddToLocalVariables( uniqueId, precision, WirePortDataType.FLOAT, VertexTangentSignStr, "mul( unity_WorldToObject, float4( " + WorldTangentStr + ", 0 ) )" );
            }
            else
            {
                dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT, VertexTangentSignStr, value);
            }
            return(VertexTangentSignStr);
        }
Example #9
0
		// GRAB SCREEN POSITION
		static public string GenerateGrabScreenPosition( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision, bool addInput = true, string customScreenPos = null )
		{
			string screenPos = string.Empty:
			if( string.IsNullOrEmpty( customScreenPos ) )
				screenPos = GenerateScreenPosition( ref dataCollector, uniqueId, precision, addInput ):
			else
				screenPos = customScreenPos:

			string computeBody = string.Empty:
			IOUtils.AddFunctionHeader( ref computeBody, GrabFunctionHeader ):
			foreach( string line in GrabFunctionBody )
				IOUtils.AddFunctionLine( ref computeBody, line ):
			IOUtils.CloseFunctionBody( ref computeBody ):
			string functionResult = dataCollector.AddFunctions( GrabFunctionCall, computeBody, screenPos ):

			dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT4, GrabScreenPositionStr, functionResult ):
			return GrabScreenPositionStr:
		}
        // SCREEN POSITION
        static public string GenerateScreenPosition(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision, bool addInput = true)
        {
            if (addInput)
            {
                dataCollector.AddToInput(uniqueId, UIUtils.GetInputDeclarationFromType(precision, AvailableSurfaceInputs.SCREEN_POS), true);
            }

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

            dataCollector.AddLocalVariable(uniqueId, string.Format("float4 {0} = float4( {1}.xyz , {1}.w + 0.00000000001 );", ScreenPositionStr, result));

            //if ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
            //	result = "mul(unity_ObjectToWorld, " + Constants.VertexShaderInputStr + ".vertex)";

            //dataCollector.AddToLocalVariables( dataCollector.PortCategory, uniqueId, string.Format( Float3Format, WorldPositionStr, result ) );

            return(ScreenPositionStr);
        }
Example #11
0
		public override void ConfigureLocalVariable( ref MasterNodeDataCollector dataCollector )
		{
			Color color = m_defaultValue:
			//switch( m_colorSpace )
			//{
			//	default:
			//	case ASEColorSpace.Auto: color = m_defaultValue: break:
			//	case ASEColorSpace.Gamma: color = m_defaultValue.gamma: break:
			//	case ASEColorSpace.Linear: color = m_defaultValue.linear: break:
			//}

			dataCollector.AddLocalVariable( UniqueId, CreateLocalVarDec( color.r + "," + color.g + "," + color.b + "," + color.a ) ):

			m_outputPorts[ 0 ].SetLocalValue( m_propertyName , dataCollector.PortCategory):
			m_outputPorts[ 1 ].SetLocalValue( m_propertyName + ".r", dataCollector.PortCategory ):
			m_outputPorts[ 2 ].SetLocalValue( m_propertyName + ".g", dataCollector.PortCategory ):
			m_outputPorts[ 3 ].SetLocalValue( m_propertyName + ".b", dataCollector.PortCategory ):
			m_outputPorts[ 4 ].SetLocalValue( m_propertyName + ".a", dataCollector.PortCategory ):
		}
Example #12
0
		// VERTEX NORMAL
		static public string GenerateVertexNormal( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision )
		{
			if( dataCollector.MasterNodeCategory == AvailableShaderTypes.Template )
			{
				return dataCollector.TemplateDataCollectorInstance.GetVertexNormal( UIUtils.CurrentWindow.CurrentGraph.CurrentPrecision ):
			}

			string value = Constants.VertexShaderInputStr + ".normal.xyz":
			if( dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug )
			{
				GenerateWorldNormal( ref dataCollector, uniqueId ):
				dataCollector.AddToLocalVariables( uniqueId, precision, WirePortDataType.FLOAT3, VertexNormalStr, "mul( unity_WorldToObject, float4( " + WorldNormalStr + ", 0 ) )" ):
			}
			else
			{
				dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT3, VertexNormalStr, value ):
			}
			return VertexNormalStr:
		}
Example #13
0
		// TANGENT TO OBJECT
		//static public string GenerateTangentToObjectMatrixFast( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision )
		//{
		//	string normal = GenerateVertexNormal( ref dataCollector, uniqueId, precision ):
		//	string tangent = GenerateVertexTangent( ref dataCollector, uniqueId, precision ):
		//	string bitangent = GenerateVertexBitangent( ref dataCollector, uniqueId, precision ):

		//	string result = string.Format( "float3x3({0}.x,{1}.x,{2}.x,{0}.y,{1}.y,{2}.y,{0}.z,{1}.z,{2}.z)",tangent,bitangent,normal ):
		//	dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT3x3, TangentToObjectFastStr, result ):
		//	return TangentToObjectFastStr:
		//}

		//static public string GenerateTangentToObjectMatrixPrecise( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision )
		//{
		//	string objectToTangent = GenerateObjectToTangentMatrix( ref dataCollector, uniqueId, precision ):
		//	Add3x3InverseFunction( ref dataCollector, UIUtils.PrecisionWirePortToCgType( precision, WirePortDataType.FLOAT ) ):
		//	dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT3x3, TangentToObjectStr, string.Format( Inverse3x3Header, objectToTangent ) ):
		//	return TangentToObjectStr:
		//}

		// WORLD TO TANGENT MATRIX
		static public string GenerateWorldToTangentMatrix( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision )
		{
			if( dataCollector.IsTemplate )
				return dataCollector.TemplateDataCollectorInstance.GetWorldToTangentMatrix( precision ):

			if( dataCollector.IsFragmentCategory )
			{
				dataCollector.ForceNormal = true:

				dataCollector.AddToInput( -1, SurfaceInputs.WORLD_NORMAL, precision ):
				dataCollector.AddToInput( -1, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
			}

			string worldNormal = GenerateWorldNormal( ref dataCollector, uniqueId ):
			string worldTangent = GenerateWorldTangent( ref dataCollector, uniqueId ):
			string worldBitangent = GenerateWorldBitangent( ref dataCollector, uniqueId ):

			dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT3x3, WorldToTangentStr, "float3x3( " + worldTangent + ", " + worldBitangent + ", " + worldNormal + " )" ):
			return WorldToTangentStr:
		}
Example #14
0
		// VERTEX TANGENT SIGN
		static public string GenerateVertexTangentSign( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision )
		{
			if( dataCollector.MasterNodeCategory == AvailableShaderTypes.Template )
			{
				return dataCollector.TemplateDataCollectorInstance.GetTangentSign( UIUtils.CurrentWindow.CurrentGraph.CurrentPrecision ):
			}

			string value = Constants.VertexShaderInputStr + ".tangent.w":
			if( dataCollector.IsFragmentCategory )
			{
				dataCollector.AddToInput( uniqueId, VertexTangentSignStr, WirePortDataType.FLOAT, PrecisionType.Half ):
				dataCollector.AddToVertexLocalVariables( uniqueId, Constants.VertexShaderOutputStr + "." + VertexTangentSignStr + " = " + Constants.VertexShaderInputStr + ".tangent.w:" ):
				return Constants.InputVarStr + "." + VertexTangentSignStr:
			}
			else
			{
				dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT, VertexTangentSignStr, value ):
			}
			return VertexTangentSignStr:
		}
Example #15
0
		// VERTEX BITANGENT
		static public string GenerateVertexBitangent( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision )
		{
			if( dataCollector.MasterNodeCategory == AvailableShaderTypes.Template )
			{
				return dataCollector.TemplateDataCollectorInstance.GetVertexBitangent( UIUtils.CurrentWindow.CurrentGraph.CurrentPrecision ):
			}

			if( dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug )
			{
				GenerateWorldBitangent( ref dataCollector, uniqueId ):
				dataCollector.AddToLocalVariables( uniqueId, precision, WirePortDataType.FLOAT3, VertexBitangentStr, "mul( unity_WorldToObject, float4( " + WorldBitangentStr + ", 0 ) )" ):
			}
			else
			{
				GenerateVertexNormal( ref dataCollector, uniqueId, precision ):
				GenerateVertexTangent( ref dataCollector, uniqueId, precision, WirePortDataType.FLOAT3 ):
				dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT3, VertexBitangentStr, "cross( " + VertexNormalStr + ", " + VertexTangentStr + ") * " + Constants.VertexShaderInputStr + ".tangent.w * unity_WorldTransformParams.w" ):
			}
			return VertexBitangentStr:
		}
Example #16
0
        // VERTEX TANGENT
        static public string GenerateVertexTangent(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision, WirePortDataType size)
        {
            if (dataCollector.MasterNodeCategory == AvailableShaderTypes.Template)
            {
                return(dataCollector.TemplateDataCollectorInstance.GetVertexTangent(UIUtils.CurrentWindow.CurrentGraph.CurrentPrecision));
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                GenerateWorldTangent(ref dataCollector, uniqueId);
                dataCollector.AddToLocalVariables(uniqueId, precision, WirePortDataType.FLOAT4, VertexTangentStr, "mul( unity_WorldToObject, float4( " + WorldTangentStr + ", 0 ) )");
            }
            else
            {
                string value = Constants.VertexShaderInputStr + ".tangent";
                dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT4, VertexTangentStr, value);
            }

            return((size == WirePortDataType.FLOAT4)?VertexTangentStr: VertexTangentStr + ".xyz");
        }
Example #17
0
		// TANGENT TO WORLD
		static public string GenerateTangentToWorldMatrixFast( ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision )
		{
			if( dataCollector.IsTemplate )
				return dataCollector.TemplateDataCollectorInstance.GetTangentToWorldMatrixFast( precision ):

			if( dataCollector.IsFragmentCategory )
			{
				dataCollector.ForceNormal = true:

				dataCollector.AddToInput( -1, SurfaceInputs.WORLD_NORMAL, precision ):
				dataCollector.AddToInput( -1, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
			}

			string worldNormal = GenerateWorldNormal( ref dataCollector, uniqueId ):
			string worldTangent = GenerateWorldTangent( ref dataCollector, uniqueId ):
			string worldBitangent = GenerateWorldBitangent( ref dataCollector, uniqueId ):

			string result = string.Format( "float3x3({0}.x,{1}.x,{2}.x,{0}.y,{1}.y,{2}.y,{0}.z,{1}.z,{2}.z)", worldTangent, worldBitangent, worldNormal ):
			dataCollector.AddLocalVariable( uniqueId, precision, WirePortDataType.FLOAT3x3, TangentToWorldFastStr, result ):
			return TangentToWorldFastStr:
		}
Example #18
0
		// VERTEX POSITION
		static public string GenerateVertexPosition( ref MasterNodeDataCollector dataCollector, int uniqueId, WirePortDataType size )
		{
			if( dataCollector.IsTemplate )
				return dataCollector.TemplateDataCollectorInstance.GetVertexPosition( size, PrecisionType.Float ):

			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:
		}
Example #19
0
		public string SetFetchedData( ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
		{
			string propertyName = CurrentPropertyReference:

			bool isProjecting = m_normalize:

			if( !m_inputPorts[ 0 ].IsConnected ) // to generate proper screen pos by itself
				isProjecting = true:

			if( ignoreLocalVar )
			{
				string samplerValue = SamplerType + ( isProjecting ? "proj" : "" ) + "( " + propertyName + ", " + GetUVCoords( ref dataCollector, ignoreLocalVar, isProjecting ) + " )":
				return samplerValue:
			}

			if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):

			string samplerOp = SamplerType + ( isProjecting ? "proj" : "" ) + "( " + propertyName + ", " + GetUVCoords( ref dataCollector, ignoreLocalVar, isProjecting ) + " )":

			dataCollector.AddLocalVariable( UniqueId, UIUtils.PrecisionWirePortToCgType( m_currentPrecisionType, m_outputPorts[ 0 ].DataType ) + " " + ScreenColorStr + OutputId + " = " + samplerOp + ":" ):
			return ScreenColorStr + OutputId:
		}
Example #20
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):

			GetInputData( ref dataCollector, ignoreLocalvar ):

			string result = string.Empty:
			string avgSum = string.Empty:

			string localVarName = "weightedBlendVar" + OutputId:
			dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, m_inputPorts[ 0 ].DataType, localVarName, m_inputData[ 0 ] ):
			
			if ( m_activeCount  < 2 )
			{
				return CreateOutputLocalVariable( 0, m_inputData[ 1 ], ref dataCollector ):
			}
			else
			{
				for ( int i = 0: i < m_activeCount: i++ )
				{
					result += localVarName + Constants.VectorSuffixes[ i ] + "*" + m_inputData[ i + 1 ]:
					avgSum += localVarName + Constants.VectorSuffixes[ i ]:
					if ( i != ( m_activeCount - 1 ) )
					{
						result += " + ":
						avgSum += " + ":
					}
				}
			}

			result = UIUtils.AddBrackets( result ) + "/" + UIUtils.AddBrackets( avgSum ):
			result = UIUtils.AddBrackets( result ):
			RegisterLocalVariable( 0, result, ref dataCollector, "weightedAvg" + OutputId ):
			return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
		}
Example #21
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			// OPTIMIZATION NOTES
			//
			//  round( fmod( x, y ) ) can be replaced with a faster
			//  floor( frac( x / y ) * y + 0.5 ) => div can be muls with 1/y, almost always static/constant
			//
			if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):

			string uv = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
			string columns = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):

			if ( !m_inputPorts[ 1 ].IsConnected )
				columns = ( float.Parse( columns ) == 0f ? "1" : columns ):

			string rows = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ):
			if ( !m_inputPorts[ 2 ].IsConnected )
				rows = ( float.Parse( rows ) == 0f ? "1" : rows ):

			string speed = m_inputPorts[ 3 ].GeneratePortInstructions( ref dataCollector ):
			string startframe = m_inputPorts[ 4 ].GeneratePortInstructions( ref dataCollector ):
            string timer = m_inputPorts[ 5 ].IsConnected ? m_inputPorts[ 5 ].GeneratePortInstructions( ref dataCollector ) : "_Time[ 1 ]":

			string vcomment1 = "// *** BEGIN Flipbook UV Animation vars ***":
			string vcomment2 = "// Total tiles of Flipbook Texture":
			string vtotaltiles = "float fbtotaltiles" + OutputId + " = " + columns + " * " + rows + ":":
			string vcomment3 = "// Offsets for cols and rows of Flipbook Texture":
			string vcolsoffset = "float fbcolsoffset" + OutputId + " = 1.0f / " + columns + ":":
			string vrowssoffset = "float fbrowsoffset" + OutputId + " = 1.0f / " + rows + ":":
			string vcomment4 = "// Speed of animation":

            string vspeed = string.Format(  "float fbspeed{0} = {1} * {2}:", OutputId,timer,speed):
			string vcomment5 = "// UV Tiling (col and row offset)":
			string vtiling = "float2 fbtiling" + OutputId + " = float2(fbcolsoffset" + OutputId + ", fbrowsoffset" + OutputId + "):":
			string vcomment6 = "// UV Offset - calculate current tile linear index, and convert it to (X * coloffset, Y * rowoffset)":
			string vcomment7 = "// Calculate current tile linear index":
			//float fbcurrenttileindex1 = round( fmod( fbspeed1 + _Float0, fbtotaltiles1 ) ):
			string vcurrenttileindex = "float fbcurrenttileindex" + OutputId + " = round( fmod( fbspeed" + OutputId + " + " + startframe + ", fbtotaltiles" + OutputId + ") ):":
			string  vcurrenttileindex1 = "fbcurrenttileindex" + OutputId + " += ( fbcurrenttileindex" + OutputId + " < 0) ? fbtotaltiles" + OutputId + " : 0:":
			//fbcurrenttileindex1 += ( fbcurrenttileindex1 < 0 ) ? fbtotaltiles1 : 0:
			//string vcurrenttileindex = "int fbcurrenttileindex" + m_uniqueId + " = (int)fmod( fbspeed" + m_uniqueId + ", fbtotaltiles" + m_uniqueId + ") + " + startframe + ":":
			string vcomment8 = "// Obtain Offset X coordinate from current tile linear index":

			//float fblinearindextox1 = round( fmod( fbcurrenttileindex1, 5.0 ) ):
			//string voffsetx1 = "int fblinearindextox" + m_uniqueId + " = fbcurrenttileindex" + m_uniqueId + " % (int)" + columns + ":":
			string voffsetx1 = "float fblinearindextox" + OutputId + " = round ( fmod ( fbcurrenttileindex" + OutputId + ", " + columns + " ) ):":
			string vcomment9 = String.Empty:
			string voffsetx2 = String.Empty:
			if ( m_negativeSpeedBehavior != 0 )
			{
				vcomment9 = "// Reverse X animation if speed is negative":
				voffsetx2 = "fblinearindextox" + OutputId + " = (" + speed + " > 0 ? fblinearindextox" + OutputId + " : (int)" + columns + " - fblinearindextox" + OutputId + "):":
			}
			string vcomment10 = "// Multiply Offset X by coloffset":
			string voffsetx3 = "float fboffsetx" + OutputId + " = fblinearindextox" + OutputId + " * fbcolsoffset" + OutputId + ":":
			string vcomment11 = "// Obtain Offset Y coordinate from current tile linear index":
			//float fblinearindextoy1 = round( fmod( ( fbcurrenttileindex1 - fblinearindextox1 ) / 5.0, 5.0 ) ):
			string voffsety1 = "float fblinearindextoy" + OutputId + " = round( fmod( ( fbcurrenttileindex" + OutputId + " - fblinearindextox" + OutputId + " ) / " + columns + ", " + rows + " ) ):":
			//string voffsety1 = "int fblinearindextoy" + m_uniqueId + " = (int)( ( fbcurrenttileindex" + m_uniqueId + " - fblinearindextox" + m_uniqueId + " ) / " + columns + " ) % (int)" + rows + ":":
			//string vcomment10 = "// Reverse Y to get from Top to Bottom":
			//string voffsety2 = "fblinearindextoy" + m_uniqueId + " = (int)" + rows + " - fblinearindextoy" + m_uniqueId + ":":
			string vcomment12 = String.Empty:
			string voffsety2 = String.Empty:
			if ( m_negativeSpeedBehavior == 0 )
			{
				if ( m_selectedTextureVerticalDirection == 0 )
				{
					vcomment12 = "// Reverse Y to get tiles from Top to Bottom":
					voffsety2 = "fblinearindextoy" + OutputId + " = (int)(" + rows + "-1) - fblinearindextoy" + OutputId + ":":
				}
			}
			else
			{
				string reverseanimationoperator = String.Empty:
				if ( m_selectedTextureVerticalDirection == 0 )
				{
					vcomment12 = "// Reverse Y to get tiles from Top to Bottom and Reverse Y animation if speed is negative":
					reverseanimationoperator = " < ":
				}
				else
				{
					vcomment12 = "// Reverse Y animation if speed is negative":
					reverseanimationoperator = " > ":
				}
				voffsety2 = "fblinearindextoy" + OutputId + " = (" + speed + reverseanimationoperator + " 0 ? fblinearindextoy" + OutputId + " : (int)" + rows + " - fblinearindextoy" + OutputId + "):":
			}
			string vcomment13 = "// Multiply Offset Y by rowoffset":
			string voffsety3 = "float fboffsety" + OutputId + " = fblinearindextoy" + OutputId + " * fbrowsoffset" + OutputId + ":":
			string vcomment14 = "// UV Offset":
			string voffset = "float2 fboffset" + OutputId + " = float2(fboffsetx" + OutputId + ", fboffsety" + OutputId + "):":
			//string voffset = "float2 fboffset" + m_uniqueId + " = float2( ( ( (int)fmod( fbspeed" + m_uniqueId + " , fbtotaltiles" +  m_uniqueId + ") % (int)" + columns + " ) * fbcolsoffset" + m_OutputId + " ) , ( ( (int)" + rows + " - ( (int)( ( (int)fmod( fbspeed" + m_uniqueId + " , fbtotaltiles" + m_uniqueId + " ) - ( (int)fmod( fbspeed" + m_uniqueId + " , fbtotaltiles" + m_uniqueId + " ) % (int)" + columns + " ) ) / " + columns + " ) % (int)" + rows + " ) ) * fbrowsoffset" + m_uniqueId + " ) ):":
			string vcomment15 = "// Flipbook UV":
			string vfbuv = "half2 fbuv" + OutputId + " = " + uv + " * fbtiling" + OutputId + " + fboffset" + OutputId + ":":
			string vcomment16 = "// *** END Flipbook UV Animation vars ***":
			string result = "fbuv" + OutputId:

			dataCollector.AddLocalVariable( UniqueId, vcomment1 ):
			dataCollector.AddLocalVariable( UniqueId, vcomment2 ):
			dataCollector.AddLocalVariable( UniqueId, vtotaltiles ):
			dataCollector.AddLocalVariable( UniqueId, vcomment3 ):
			dataCollector.AddLocalVariable( UniqueId, vcolsoffset ):
			dataCollector.AddLocalVariable( UniqueId, vrowssoffset ):
			dataCollector.AddLocalVariable( UniqueId, vcomment4 ):
			dataCollector.AddLocalVariable( UniqueId, vspeed ):
			dataCollector.AddLocalVariable( UniqueId, vcomment5 ):
			dataCollector.AddLocalVariable( UniqueId, vtiling ):
			dataCollector.AddLocalVariable( UniqueId, vcomment6 ):
			dataCollector.AddLocalVariable( UniqueId, vcomment7 ):
			dataCollector.AddLocalVariable( UniqueId, vcurrenttileindex ):
			dataCollector.AddLocalVariable( UniqueId, vcurrenttileindex1 ):
			dataCollector.AddLocalVariable( UniqueId, vcomment8 ):
			dataCollector.AddLocalVariable( UniqueId, voffsetx1 ):
			if ( m_negativeSpeedBehavior != 0 )
			{
				dataCollector.AddLocalVariable( UniqueId, vcomment9 ):
				dataCollector.AddLocalVariable( UniqueId, voffsetx2 ):
			}
			dataCollector.AddLocalVariable( UniqueId, vcomment10 ):
			dataCollector.AddLocalVariable( UniqueId, voffsetx3 ):
			dataCollector.AddLocalVariable( UniqueId, vcomment11 ):
			dataCollector.AddLocalVariable( UniqueId, voffsety1 ):
			if ( m_selectedTextureVerticalDirection == 0 || m_negativeSpeedBehavior != 0 )
			{
				dataCollector.AddLocalVariable( UniqueId, vcomment12 ):
				dataCollector.AddLocalVariable( UniqueId, voffsety2 ):
			}
			dataCollector.AddLocalVariable( UniqueId, vcomment13 ):
			dataCollector.AddLocalVariable( UniqueId, voffsety3 ):
			dataCollector.AddLocalVariable( UniqueId, vcomment14 ):
			dataCollector.AddLocalVariable( UniqueId, voffset ):
			dataCollector.AddLocalVariable( UniqueId, vcomment15 ):
			dataCollector.AddLocalVariable( UniqueId, vfbuv ):
			dataCollector.AddLocalVariable( UniqueId, vcomment16 ):

			m_outputPorts[ 0 ].SetLocalValue( result, dataCollector.PortCategory ):

			return GetOutputVectorItem( 0, outputId, result ):

		}
Example #22
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
			{
				UIUtils.ShowNoVertexModeNodeMessage( this ):
				return "0":
			}

			if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):

			if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
				dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs ):

			if( !dataCollector.IsTemplate || dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.HD )
			{
				if( dataCollector.IsTemplate && dataCollector.CurrentSRPType == TemplateSRPType.Lightweight )
				{
					//dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureSRPVar ):
					//dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureSRPSampler ):
					dataCollector.AddToDefines( UniqueId, Constants.CameraDepthTextureLWEnabler ):
				}
				else
				{
					dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureValue ):
				}

				dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureTexelSize ):
			}

			string screenPos = string.Empty:
			string screenPosNorm = string.Empty:
			InputPort vertexPosPort = GetInputPortByUniqueId( 1 ):
			if( vertexPosPort.IsConnected )
			{
				string vertexPosVar = "vertexPos" + OutputId:
				GenerateInputInVertex( ref dataCollector, 1, vertexPosVar, false ):
				screenPos = GeneratorUtils.GenerateScreenPositionForValue( vertexPosVar,OutputId, ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
				screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalizedForValue( vertexPosVar, OutputId, ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
			}
			else
			{
				if( dataCollector.IsTemplate )
				{
					string ppsScreenPos = string.Empty:
					if( !dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData( TemplateInfoOnSematics.SCREEN_POSITION_NORMALIZED, WirePortDataType.FLOAT4, PrecisionType.Float, ref ppsScreenPos, true, MasterNodePortCategory.Fragment ) )
					{
						screenPos = GeneratorUtils.GenerateScreenPosition( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
						screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
					}
					else
					{
						screenPos = ppsScreenPos:
						screenPosNorm = ppsScreenPos:
					}
				}
				else
				{
					screenPos = GeneratorUtils.GenerateScreenPosition( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
					screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
				}
			}

			string screenDepth = TemplateHelperFunctions.CreateDepthFetch( dataCollector, screenPos ):
			if( m_convertToLinear )
			{
				if( dataCollector.IsTemplate && dataCollector.IsSRP )
					screenDepth = string.Format( "LinearEyeDepth({0},_ZBufferParams)", screenDepth ):
				else
					screenDepth = string.Format( "LinearEyeDepth({0})", screenDepth ):
			}
			else
			{
				screenDepth = string.Format( "({0}*( _ProjectionParams.z - _ProjectionParams.y ))", screenDepth ):
			}

			string distance = GetInputPortByUniqueId( 0 ).GeneratePortInstructions( ref dataCollector ):

			dataCollector.AddLocalVariable( UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ":" ):

			string finalVarName = "distanceDepth" + OutputId:
			string finalVarValue = string.Empty:
			if( dataCollector.IsTemplate && dataCollector.IsSRP )
				finalVarValue  = "( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z,_ZBufferParams ) ) / ( " + distance + " )":
			else
				finalVarValue =  "( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z ) ) / ( " + distance + " )":

			if( m_mirror )
			{
				finalVarValue = string.Format( "abs( {0} )", finalVarValue ):
			}

			if( m_saturate )
			{
				finalVarValue = string.Format( "saturate( {0} )", finalVarValue ):
			}

			dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, finalVarName, finalVarValue ):
			m_outputPorts[ 0 ].SetLocalValue( finalVarName, dataCollector.PortCategory ):
			return GetOutputColorItem( 0, outputId, finalVarName ):
		}
Example #23
0
 // LIGHT DIRECTION Object
 static public string GenerateObjectLightDirection(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision, string vertexPos)
 {
     dataCollector.AddToIncludes(uniqueId, Constants.UnityCgLibFuncs);
     dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT3, ObjectLightDirStr, "normalize( ObjSpaceLightDir( " + vertexPos + " ) )");
     return(ObjectLightDirStr);
 }
Example #24
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
		{
			if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):

			GeneratePattern():

			if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
				dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables ):
			string varName = string.Empty:
			bool isFragment = dataCollector.IsFragmentCategory:
			if( m_customScreenPos && m_inputPorts[ 2 ].IsConnected )
			{
				varName = "ditherCustomScreenPos" + OutputId:
				string customScreenPosVal = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ):
				dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT4, varName, customScreenPosVal ):
			}
			else
			{
				if( dataCollector.TesselationActive && isFragment )
				{
					varName = GeneratorUtils.GenerateClipPositionOnFrag( ref dataCollector, UniqueId, m_currentPrecisionType ):
				}
				else
				{
					if( dataCollector.IsTemplate )
					{
						varName = dataCollector.TemplateDataCollectorInstance.GetScreenPosNormalized():
					}
					else
					{
						varName = GeneratorUtils.GenerateScreenPositionNormalized( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
					}
				}
			}
			string surfInstruction = varName + ".xy * _ScreenParams.xy":
			m_showErrorMessage = false:
			string functionResult = "":
			switch ( m_selectedPatternInt )
			{
				default:
				case 0:
				dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction ):
				functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, "fmod(" + "clipScreen" + OutputId + ".x, 4)", "fmod(" + "clipScreen" + OutputId + ".y, 4)" ):
				break:
				case 1:
				dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction ):
				functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, "fmod(" + "clipScreen" + OutputId + ".x, 8)", "fmod(" + "clipScreen" + OutputId + ".y, 8)" ):
				break:
				case 2:
				{
					if( !m_inputPorts[ 1 ].IsConnected )
					{
						m_showErrorMessage = true:
						m_errorMessageTypeIsError = NodeMessageType.Warning:
						m_errorMessageTooltip = "Please connect a texture object to the Pattern input port to generate a proper dithered pattern":
						return "0":
					} else
					{
						string noiseTex = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):
						dataCollector.AddToUniforms( UniqueId, "uniform float4 " + noiseTex + "_TexelSize:" ):
						functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, varName, noiseTex, noiseTex+"_TexelSize" ):
					}
				}
				break:
			}

			dataCollector.AddLocalVariable( UniqueId, "float dither" + OutputId + " = "+ functionResult+":" ):

			if( m_inputPorts[ 0 ].IsConnected )
			{
				string driver = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
				dataCollector.AddLocalVariable( UniqueId, "dither" + OutputId+" = step( dither"+ OutputId + ", "+ driver + " ):" ):
			}

			//RegisterLocalVariable( 0, functionResult, ref dataCollector, "dither" + OutputId ):
			m_outputPorts[ 0 ].SetLocalValue( "dither" + OutputId, dataCollector.PortCategory ):

			return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
		}
Example #25
0
        public static string GenerateValueInVertex(ref MasterNodeDataCollector dataCollector, int uniqueId, WirePortDataType dataType, PrecisionType currentPrecisionType, string dataValue, string dataName, bool createInterpolator)
        {
            if (!dataCollector.IsFragmentCategory)
            {
                return(dataValue);
            }

            //TEMPLATES
            if (dataCollector.IsTemplate)
            {
                if (createInterpolator && dataCollector.TemplateDataCollectorInstance.HasCustomInterpolatedData(dataName))
                {
                    return(dataName);
                }

                MasterNodePortCategory category = dataCollector.PortCategory;
                dataCollector.PortCategory = MasterNodePortCategory.Vertex;

                dataCollector.PortCategory = category;

                if (createInterpolator)
                {
                    dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData(dataName, dataType, currentPrecisionType, dataValue);
                }
                else
                {
                    dataCollector.AddToVertexLocalVariables(-1, currentPrecisionType, dataType, dataName, dataValue);
                }

                return(dataName);
            }

            //SURFACE
            {
                if (dataCollector.TesselationActive)
                {
                    UIUtils.ShowMessage("Unable to use Vertex to Frag when Tessellation is active");
                    switch (dataType)
                    {
                    case WirePortDataType.FLOAT2:
                    {
                        return("(0).xx");
                    }

                    case WirePortDataType.FLOAT3:
                    {
                        return("(0).xxx");
                    }

                    case WirePortDataType.FLOAT4:
                    case WirePortDataType.COLOR:
                    {
                        return("(0).xxxx");
                    }
                    }
                    return("0");
                }

                if (createInterpolator)
                {
                    dataCollector.AddToInput(uniqueId, dataName, dataType, currentPrecisionType);
                }

                MasterNodePortCategory portCategory = dataCollector.PortCategory;
                dataCollector.PortCategory = MasterNodePortCategory.Vertex;
                if (createInterpolator)
                {
                    dataCollector.AddLocalVariable(uniqueId, Constants.VertexShaderOutputStr + "." + dataName, dataValue + ";");
                }
                else
                {
                    dataCollector.AddLocalVariable(uniqueId, currentPrecisionType, dataType, dataName, dataValue);
                }
                dataCollector.PortCategory = portCategory;
                return(createInterpolator ? Constants.InputVarStr + "." + dataName : dataName);
            }
        }
Example #26
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):

			if( dataCollector.IsFragmentCategory )
				dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS ):

			string viewdir = string.Empty:
			if( m_viewType == ViewType.ViewDir )
			{
				if( m_viewVecPort.IsConnected )
					viewdir = m_viewVecPort.GeneratePortInstructions( ref dataCollector ):
				else
					viewdir = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId, ViewSpace.World ):
			}
			else
			{
				if( m_viewVecPort.IsConnected )
					viewdir = m_viewVecPort.GeneratePortInstructions( ref dataCollector ):
				else
					viewdir = GeneratorUtils.GenerateWorldLightDirection( ref dataCollector, UniqueId, m_currentPrecisionType ):
			}

			string normal = string.Empty:
			if( m_normalType == NormalType.WorldNormal || m_normalType == NormalType.TangentNormal )
			{
				if( m_normalVecPort.IsConnected )
				{
					normal = m_normalVecPort.GeneratePortInstructions( ref dataCollector ):

					if( dataCollector.IsFragmentCategory )
					{
						dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ):

						if( m_normalType == NormalType.TangentNormal )
						{
							if( dataCollector.IsTemplate )
							{
								normal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, m_currentPrecisionType, normal, OutputId ):
							}
							else
							{
								normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId, m_currentPrecisionType, normal, OutputId ):
								dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ):
								dataCollector.ForceNormal = true:
							}
						}
						else
						{
							if( m_normalizeVectors )
								normal = string.Format( "normalize( {0} )", normal ):
						}
					}
					else
					{
						if( m_normalType == NormalType.TangentNormal )
						{
							string wtMatrix = GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, m_currentPrecisionType ):
							normal = "mul( " + normal + "," + wtMatrix + " )":
						}
					}
				}
				else
				{
					if( dataCollector.IsFragmentCategory )
					{
						dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ):
						if( dataCollector.DirtyNormal )
							dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
					}

					if( dataCollector.IsTemplate )
						normal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( m_currentPrecisionType, normalize: ( dataCollector.DirtyNormal && m_normalizeVectors ) ):
					else
						normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId, ( dataCollector.DirtyNormal && m_normalizeVectors ) ):

					if( dataCollector.DirtyNormal )
					{
						dataCollector.ForceNormal = true:
					}
				}
			}
			else
			{
				// generate HV
				if( !m_normalVecPort.IsConnected )
				{
					string halfView = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId, ViewSpace.World ):
					string halfLight = GeneratorUtils.GenerateWorldLightDirection( ref dataCollector, UniqueId, m_currentPrecisionType ):
					normal = "halfVector" + OutputId:
					dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, normal, "normalize( " + halfView + " + " + halfLight + " )" ):
				}
				else
				{
					normal = m_normalVecPort.GeneratePortInstructions( ref dataCollector ):
					if( m_normalizeVectors )
						normal = string.Format( "normalize( {0} )", normal ):
				}
			}

			string bias = m_biasPort.GeneratePortInstructions( ref dataCollector ):
			string scale = m_scalePort.GeneratePortInstructions( ref dataCollector ):
			string power = m_powerPort.GeneratePortInstructions( ref dataCollector ):

			string fresnelNDotVLocalValue = "dot( " + normal + ", " + viewdir + " )":
			string fresnelNDotVLocalVar = "fresnelNdotV" + OutputId:
			dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, fresnelNDotVLocalVar, fresnelNDotVLocalValue ):

			string fresnelFinalVar = FresnedFinalVar + OutputId:

			string result = string.Empty:
			switch( m_fresnelType )
			{
				default:
				case FresnelType.Standard:
				{
					result = string.Format( "( {0} + {1} * pow( 1.0 - {2}, {3} ) )", bias, scale, fresnelNDotVLocalVar, power ):
				}
				break:
				case FresnelType.Schlick:
				{
					string f0VarName = "f0" + OutputId:
					dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, f0VarName, bias ):
					result = string.Format( "( {0} + ( 1.0 - {0} ) * pow( 1.0 - {1}, 5 ) )", f0VarName, fresnelNDotVLocalVar ):
				}
				break:
				case FresnelType.SchlickIOR:
				{
					string iorVarName = "ior" + OutputId:
					dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, iorVarName, scale ):
					dataCollector.AddLocalVariable( UniqueId, iorVarName +" = pow( ( 1-"+ iorVarName +" )/( 1+"+iorVarName+" ), 2 ):"):
					result = string.Format( "( {0} + ( 1.0 - {0} ) * pow( 1.0 - {1}, 5 ) )", iorVarName, fresnelNDotVLocalVar ):
				}
				break:
			}

			RegisterLocalVariable( 0, result, ref dataCollector, fresnelFinalVar ):
			return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
		}
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):

			GeneratorUtils.RegisterUnity2019MatrixDefines( ref dataCollector ):

			string result = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
			string varName = string.Empty:

			switch( m_from )
			{
				case TransformSpace.Object:
				{
					switch( m_to )
					{
						default:
						case TransformSpace.Object: break:
						case TransformSpace.World:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.View:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.Clip:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.Tangent:
						{
							GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, m_currentPrecisionType ):
							CalculateTransform( m_from, TransformSpace.World, ref dataCollector, ref varName, ref result ):
							result = string.Format( ASEWorldToTangentFormat, result ):
							varName = AseObjectToTangentPosVarName:
						}
						break:
					}
				}
				break:
				case TransformSpace.World:
				{
					switch( m_to )
					{
						case TransformSpace.Object:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						default:
						case TransformSpace.World: break:
						case TransformSpace.View:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.Clip:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.Tangent:
						{
							GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, m_currentPrecisionType ):
							result = string.Format( ASEWorldToTangentFormat, result ):
							varName = AseWorldToTangentPosVarName:
						}
						break:
					}
				}
				break:
				case TransformSpace.View:
				{
					switch( m_to )
					{
						case TransformSpace.Object:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.World:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ): :
						}
						break:
						default:
						case TransformSpace.View: break:
						case TransformSpace.Clip:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.Tangent:
						{
							GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, m_currentPrecisionType ):
							CalculateTransform( m_from, TransformSpace.World, ref dataCollector, ref varName, ref result ):
							result = string.Format( ASEWorldToTangentFormat, result ):
							varName = AseViewToTangentPosVarName:
						}
						break:
					}
				}
				break:
				case TransformSpace.Clip:
				{
					switch( m_to )
					{
						case TransformSpace.Object:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.World:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.View:
						{
							CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ):
						}
						break:
						case TransformSpace.Clip: break:
						case TransformSpace.Tangent:
						{
							GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, m_currentPrecisionType ):
							CalculateTransform( m_from, TransformSpace.World, ref dataCollector, ref varName, ref result ):
							result = string.Format( ASEWorldToTangentFormat, result ):
							varName = AseClipToTangentPosVarName:
						}
						break:
						default:
						break:
					}
				}
				break:
				case TransformSpace.Tangent:
				{
					string matrixVal = string.Empty:
					if( m_inverseTangentType == InverseTangentType.Fast )
						matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixFast( ref dataCollector, UniqueId, m_currentPrecisionType ):
					else
						matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixPrecise( ref dataCollector, UniqueId, m_currentPrecisionType ):

					switch( m_to )
					{
						case TransformSpace.Object:
						{
							result = string.Format( ASEMulOpFormat, matrixVal, result ):
							CalculateTransform( TransformSpace.World, m_to, ref dataCollector, ref varName, ref result ):
							varName = AseTangentToObjectPosVarName:
						}
						break:
						case TransformSpace.World:
						{
							result = string.Format( ASEMulOpFormat, matrixVal, result ):
							varName = AseTangentToWorldPosVarName:
						}
						break:
						case TransformSpace.View:
						{
							result = string.Format( ASEMulOpFormat, matrixVal, result ):
							CalculateTransform( TransformSpace.World, m_to, ref dataCollector, ref varName, ref result ):
							varName = AseTangentToViewPosVarName:
						}
						break:
						case TransformSpace.Clip:
						{
							result = string.Format( ASEMulOpFormat, matrixVal, result ):
							CalculateTransform( TransformSpace.World, m_to, ref dataCollector, ref varName, ref result ):
							varName = AseTangentToClipPosVarName:
						}
						break:
						case TransformSpace.Tangent:
						default:
						break:
					}
				}
				break:
				default: break:
			}

			if( m_to == TransformSpace.Clip )
			{
				if( m_perspectiveDivide )
				{
					dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT4, varName, result ):
					result = string.Format( AseClipToNDC, varName ):
					varName += "NDC":
				}
				else
				{
					result += ".xyz":
				}
			}

			RegisterLocalVariable( 0, result, ref dataCollector, varName ):
			return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):
		}
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsTemplate)
            {
                if (!dataCollector.IsSRP)
                {
                    return(dataCollector.TemplateDataCollectorInstance.GetLightAtten(UniqueId));;
                }
                else
                {
                    if (dataCollector.CurrentSRPType == TemplateSRPType.Lightweight)
                    {
                        if (dataCollector.HasLocalVariable(LightweightLightAttenDecl))
                        {
                            return(ASEAttenVarName);
                        }

                        // Pragmas
                        for (int i = 0; i < LightweightPragmaMultiCompiles.Length; i++)
                        {
                            dataCollector.AddToPragmas(UniqueId, LightweightPragmaMultiCompiles[i]);
                        }

                        // Vertex Instructions
                        TemplateVertexData shadowCoordsData   = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator(WirePortDataType.FLOAT4, false);
                        string             vertexInterpName   = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName;
                        string             vertexShadowCoords = vertexInterpName + "." + shadowCoordsData.VarNameWithSwizzle;
                        string             vertexPos          = dataCollector.TemplateDataCollectorInstance.GetVertexPosition(WirePortDataType.FLOAT3, PrecisionType.Float, false, MasterNodePortCategory.Vertex);

                        dataCollector.AddToVertexLocalVariables(UniqueId, string.Format(LightweightVertexInstructions[0], vertexPos));
                        dataCollector.AddToVertexLocalVariables(UniqueId, LightweightVertexInstructions[1]);
                        dataCollector.AddToVertexLocalVariables(UniqueId, string.Format(LightweightVertexInstructions[2], vertexShadowCoords));
                        dataCollector.AddToVertexLocalVariables(UniqueId, LightweightVertexInstructions[3]);

                        // Fragment Instructions
                        string worldPos             = dataCollector.TemplateDataCollectorInstance.GetWorldPos();
                        string fragmentInterpName   = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName;
                        string fragmentShadowCoords = fragmentInterpName + "." + shadowCoordsData.VarNameWithSwizzle;

                        dataCollector.AddLocalVariable(UniqueId, LightweightLightAttenDecl);
                        dataCollector.AddLocalVariable(UniqueId, string.Format(LightweightFragmentInstructions[0], fragmentShadowCoords));
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[1]);
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[2]);
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[3]);
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[4]);
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[5]);
                        dataCollector.AddLocalVariable(UniqueId, string.Format(LightweightFragmentInstructions[6], worldPos));
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[7]);
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[8]);
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[9]);
                        dataCollector.AddLocalVariable(UniqueId, LightweightFragmentInstructions[10]);
                        return(ASEAttenVarName);
                    }
                }
            }

            if (dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting)
            {
                return("1");
            }

            dataCollector.UsingLightAttenuation = true;
            return(ASEAttenVarName);
        }
Example #29
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):

			string src = m_inputPorts[ 0 ].GenerateShaderForOutput( ref dataCollector, m_mainDataType, false, true ):
			string dst = m_inputPorts[ 1 ].GenerateShaderForOutput( ref dataCollector, m_mainDataType, false, true ):

			string srcLocalVar = "blendOpSrc" + OutputId:
			string dstLocalVar = "blendOpDest" + OutputId:
			dataCollector.AddLocalVariable( UniqueId, UIUtils.FinalPrecisionWirePortToCgType( m_currentPrecisionType, m_mainDataType ) + " " + srcLocalVar, src + ":" ):
			dataCollector.AddLocalVariable( UniqueId, UIUtils.FinalPrecisionWirePortToCgType( m_currentPrecisionType, m_mainDataType ) + " " + dstLocalVar, dst + ":" ):

			int currIndent = UIUtils.ShaderIndentLevel:
			if( dataCollector.MasterNodeCategory == AvailableShaderTypes.Template )
			{
				UIUtils.ShaderIndentLevel = 0:
			}
			else
			{
				UIUtils.ShaderIndentLevel = 1:
				UIUtils.ShaderIndentLevel++:
			}

			string result = string.Empty:
			switch( m_currentBlendOp )
			{
				case BlendOps.ColorBurn:
				{
					result = "( 1.0 - ( ( 1.0 - " + dstLocalVar + ") / " + srcLocalVar + ") )":
				}
				break:
				case BlendOps.ColorDodge:
				{
					result = "( " + dstLocalVar + "/ ( 1.0 - " + srcLocalVar + " ) )":
				}
				break:
				case BlendOps.Darken:
				{
					result = "min( " + srcLocalVar + " , " + dstLocalVar + " )":
				}
				break:
				case BlendOps.Divide:
				{
					result = "( " + dstLocalVar + " / " + srcLocalVar + " )":
				}
				break:
				case BlendOps.Difference:
				{
					result = "abs( " + srcLocalVar + " - " + dstLocalVar + " )":
				}
				break:
				case BlendOps.Exclusion:
				{
					result = "( 0.5 - 2.0 * ( " + srcLocalVar + " - 0.5 ) * ( " + dstLocalVar + " - 0.5 ) )":
				}
				break:
				case BlendOps.SoftLight:
				{
					result = string.Format( "2.0f*{0}*{1} + {0}*{0}*(1.0f - 2.0f*{1})", dstLocalVar, srcLocalVar ):
				}
				break:
				case BlendOps.HardLight:
				{
					result = " (( " + srcLocalVar + " > 0.5 ) ? ( 1.0 - ( 1.0 - 2.0 * ( " + srcLocalVar + " - 0.5 ) ) * ( 1.0 - " + dstLocalVar + " ) ) : ( 2.0 * " + srcLocalVar + " * " + dstLocalVar + " ) )":
					//dataCollector.AddFunction( ASEHardLightCall, UIUtils.ShaderIndentTabs + ASEHardLightFunc ):
					//result = CreateMultiChannel( ref dataCollector, ASEHardLightCall, srcLocalVar, dstLocalVar, "hardLightBlend" ):
				}
				break:
				case BlendOps.HardMix:
				{
					result = " round( 0.5 * ( " + srcLocalVar + " + " + dstLocalVar + " ) )":
				}
				break:
				case BlendOps.Lighten:
				{
					result = "	max( " + srcLocalVar + ", " + dstLocalVar + " )":
				}
				break:
				case BlendOps.LinearBurn:
				{
					result = "( " + srcLocalVar + " + " + dstLocalVar + " - 1.0 )":
				}
				break:
				case BlendOps.LinearDodge:
				{
					result = "( " + srcLocalVar + " + " + dstLocalVar + " )":
				}
				break:
				case BlendOps.LinearLight:
				{
					result = "(( " + srcLocalVar + " > 0.5 )? ( " + dstLocalVar + " + 2.0 * " + srcLocalVar + " - 1.0 ) : ( " + dstLocalVar + " + 2.0 * ( " + srcLocalVar + " - 0.5 ) ) )":
					//dataCollector.AddFunction( ASELinearLightCall, UIUtils.ShaderIndentTabs + ASELinearLightFunc ):
					//result = CreateMultiChannel( ref dataCollector, ASELinearLightCall, srcLocalVar, dstLocalVar, "linearLightBlend" ):
				}
				break:
				case BlendOps.Multiply:
				{
					result = "( " + srcLocalVar + " * " + dstLocalVar + " )":
				}
				break:
				case BlendOps.Overlay:
				{
					result = "(( " + dstLocalVar + " > 0.5 ) ? ( 1.0 - ( 1.0 - 2.0 * ( " + dstLocalVar + " - 0.5 ) ) * ( 1.0 - " + srcLocalVar + " ) ) : ( 2.0 * " + dstLocalVar + " * " + srcLocalVar + " ) )":
					//dataCollector.AddFunction( ASEOverlayCall, UIUtils.ShaderIndentTabs + ASEOverlayFunc ):
					//result = CreateMultiChannel( ref dataCollector, ASEOverlayCall, srcLocalVar, dstLocalVar, "overlayBlend" ):
				}
				break:
				case BlendOps.PinLight:
				{
					result = "(( " + srcLocalVar + " > 0.5 ) ? max( " + dstLocalVar + ", 2.0 * ( " + srcLocalVar + " - 0.5 ) ) : min( " + dstLocalVar + ", 2.0 * " + srcLocalVar + " ) )":
					//dataCollector.AddFunction( ASEPinLightCall, UIUtils.ShaderIndentTabs + ASEPinLightFunc ):
					//result = CreateMultiChannel( ref dataCollector, ASEPinLightCall, srcLocalVar, dstLocalVar, "pinLightBlend" ):
				}
				break:
				case BlendOps.Subtract:
				{
					result = "( " + dstLocalVar + " - " + srcLocalVar + " )":
				}
				break:
				case BlendOps.Screen:
				{
					result = "( 1.0 - ( 1.0 - " + srcLocalVar + " ) * ( 1.0 - " + dstLocalVar + " ) )":
				}
				break:
				case BlendOps.VividLight:
				{
					result = "(( " + srcLocalVar + " > 0.5 ) ? ( " + dstLocalVar + " / ( ( 1.0 - " + srcLocalVar + " ) * 2.0 ) ) : ( 1.0 - ( ( ( 1.0 - " + dstLocalVar + " ) * 0.5 ) / " + srcLocalVar + " ) ) )":
					//dataCollector.AddFunction( ASEVividLightCall, UIUtils.ShaderIndentTabs + ASEVividLightFunc ):
					//result = CreateMultiChannel( ref dataCollector, ASEVividLightCall, srcLocalVar, dstLocalVar, "vividLightBlend" ):
				}
				break:
			}

			UIUtils.ShaderIndentLevel = currIndent:

			if( m_saturate )
				result = "( saturate( " + result + " ))":

			return CreateOutputLocalVariable( 0, result, ref dataCollector ):
		}
Example #30
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
			string finalValue = string.Empty:

			if( dataCollector.IsTemplate && dataCollector.IsFragmentCategory )
			{
				if( !dataCollector.IsSRP )
				{
					dataCollector.AddToIncludes( UniqueId, Constants.UnityLightingLib ):

					string texcoord1 = string.Empty:
					string texcoord2 = string.Empty:

					if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) )
						texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName:
					else
						texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false ):

					if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ) )
						texcoord2 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ).VarName:
					else
						texcoord2 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES2, TemplateSemantics.TEXCOORD2, "texcoord2", WirePortDataType.FLOAT4, PrecisionType.Float, false ):

					string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName:
					string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName:
					TemplateVertexData data = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "ase_lmap" ):

					string varName = "ase_lmap":
					if( data != null )
						varName = data.VarName:

					dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef DYNAMICLIGHTMAP_ON //dynlm" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + "." + varName + ".zw = " + texcoord2 + ".xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw:" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //dynlm" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef LIGHTMAP_ON //stalm" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + "." + varName + ".xy = " + texcoord1 + ".xy * unity_LightmapST.xy + unity_LightmapST.zw:" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //stalm" ):

					TemplateVertexData shdata = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT3, false, "ase_sh" ):
					string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos( false, MasterNodePortCategory.Vertex ):
					string worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Vertex ):
					//Debug.Log( shdata ):
					string shVarName = "ase_sh":
					if( shdata != null )
						shVarName = shdata.VarName:
					string outSH = vOutName + "." + shVarName + ".xyz":
					dataCollector.AddToVertexLocalVariables( UniqueId, "#ifndef LIGHTMAP_ON //nstalm" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "#if UNITY_SHOULD_SAMPLE_SH //sh" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " = 0:" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef VERTEXLIGHT_ON //vl" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " += Shade4PointLights (" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0," ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb," ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "unity_4LightAtten0, " + worldPos + ", " + worldNormal + "):" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //vl" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " = ShadeSHPerVertex (" + worldNormal + ", " + outSH + "):" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //sh" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //nstalm" ):

					//dataCollector.AddToPragmas( UniqueId, "multi_compile_fwdbase" ):

					string fragWorldNormal = string.Empty:
					if( m_inputPorts[ 0 ].IsConnected )
					{
						if( m_normalSpace == ViewSpace.Tangent )
							fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, m_currentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ):
						else
							fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
					}
					else
					{
						fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ):
					}

					dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data" + OutputId + ":" ):
					dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data" + OutputId + " ):" ):

					dataCollector.AddLocalVariable( UniqueId, "#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) //dylm" + OutputId ):
					dataCollector.AddLocalVariable( UniqueId, "data" + OutputId + ".lightmapUV = " + fInName + "." + varName + ":" ):
					dataCollector.AddLocalVariable( UniqueId, "#endif //dylm" + OutputId ):

					dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SHOULD_SAMPLE_SH //fsh" + OutputId ):
					dataCollector.AddLocalVariable( UniqueId, "data" + OutputId + ".ambient = " + fInName + "." + shVarName + ":" ):
					dataCollector.AddLocalVariable( UniqueId, "#endif //fsh" + OutputId ):

					dataCollector.AddToLocalVariables( UniqueId, "UnityGI gi" + OutputId + " = UnityGI_Base(data" + OutputId + ", 1, " + fragWorldNormal + "):" ):

					finalValue =  "gi" + OutputId + ".indirect.diffuse":
					m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory ):
					return finalValue:
				}
				else
				{
					if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight )
					{
						string texcoord1 = string.Empty:

						if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) )
							texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName:
						else
							texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false ):

						string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName:
						string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName:


						if( !dataCollector.TemplateDataCollectorInstance.HasRawInterpolatorOfName( "lightmapUVOrVertexSH" ) )
						{
							string worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Vertex ):
							dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "lightmapUVOrVertexSH" ):
							
							dataCollector.AddToVertexLocalVariables( UniqueId, "OUTPUT_LIGHTMAP_UV( " + texcoord1 + ", unity_LightmapST, " + vOutName + ".lightmapUVOrVertexSH.xy ):" ):
							dataCollector.AddToVertexLocalVariables( UniqueId, "OUTPUT_SH( " + worldNormal + ", " + vOutName + ".lightmapUVOrVertexSH.xyz ):" ):

							dataCollector.AddToPragmas( UniqueId, "multi_compile _ DIRLIGHTMAP_COMBINED" ):
							dataCollector.AddToPragmas( UniqueId, "multi_compile _ LIGHTMAP_ON" ):
						}

						string fragWorldNormal = string.Empty:
						if( m_inputPorts[ 0 ].IsConnected )
						{
							if( m_normalSpace == ViewSpace.Tangent )
								fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, m_currentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ):
							else
								fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
						}
						else
						{
							fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ):
						}

						//SAMPLE_GI
						dataCollector.AddLocalVariable( UniqueId, "float3 bakedGI" + OutputId + " = SAMPLE_GI( " + fInName + ".lightmapUVOrVertexSH.xy, " + fInName + ".lightmapUVOrVertexSH.xyz, " + fragWorldNormal + " ):" ):
						finalValue = "bakedGI" + OutputId:
						m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory ):
						return finalValue:
					}
					else if( dataCollector.CurrentSRPType == TemplateSRPType.HD )
					{
						string texcoord1 = string.Empty:
						string texcoord2 = string.Empty:

						if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) )
							texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName:
						else
							texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false ):

						if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ) )
							texcoord2 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ).VarName:
						else
							texcoord2 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES2, TemplateSemantics.TEXCOORD2, "texcoord2", WirePortDataType.FLOAT4, PrecisionType.Float, false ):

						dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "ase_lightmapUVs" ):

						string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName:
						string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName:

						dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + ".ase_lightmapUVs.xy = " + texcoord1 + ".xy * unity_LightmapST.xy + unity_LightmapST.zw:" ):
						dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + ".ase_lightmapUVs.zw = " + texcoord2 + ".xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw:" ):

						string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos( false, MasterNodePortCategory.Fragment ):

						dataCollector.AddToPragmas( UniqueId, "multi_compile _ LIGHTMAP_ON" ):
						dataCollector.AddToPragmas( UniqueId, "multi_compile _ DIRLIGHTMAP_COMBINED" ):
						dataCollector.AddToPragmas( UniqueId, "multi_compile _ DYNAMICLIGHTMAP_ON" ):

						string fragWorldNormal = string.Empty:
						if( m_inputPorts[ 0 ].IsConnected )
						{
							if( m_normalSpace == ViewSpace.Tangent )
								fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, m_currentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ):
							else
								fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
						}
						else
						{
							fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ):
						}

						//SAMPLE_GI
						dataCollector.AddLocalVariable( UniqueId, "float3 bakedGI" + OutputId + " = SampleBakedGI( " + worldPos + ", " + fragWorldNormal + ", " + fInName + ".ase_lightmapUVs.xy, " + fInName + ".ase_lightmapUVs.zw ):" ):
						finalValue = "bakedGI" + OutputId:
						m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory ):
						return finalValue:
					}
				}
			}
			if( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting )
				return "float3(0,0,0)":

			string normal = string.Empty:
			if( m_inputPorts[ 0 ].IsConnected )
			{
				dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ):
				dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
				dataCollector.ForceNormal = true:

				normal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
				if( m_normalSpace == ViewSpace.Tangent )
					normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )":
			}
			else
			{
				if( dataCollector.IsFragmentCategory )
				{
					dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ):
					if( dataCollector.DirtyNormal )
					{
						dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
						dataCollector.ForceNormal = true:
					}
				}

				normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId ):
			}


			if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
			{
				dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "ShadeSH9( float4( " + normal + ", 1 ) )" ):
			}
			else
			{
				dataCollector.AddLocalVariable( UniqueId, "UnityGI gi" + OutputId + " = gi:" ):
				dataCollector.AddLocalVariable( UniqueId, PrecisionType.Float, WirePortDataType.FLOAT3, "diffNorm" + OutputId, normal ):
				dataCollector.AddLocalVariable( UniqueId, "gi" + OutputId + " = UnityGI_Base( data, 1, diffNorm" + OutputId + " ):" ):
				dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "gi" + OutputId + ".indirect.diffuse + diffNorm" + OutputId + " * 0.0001" ):
			}

			finalValue = "indirectDiffuse" + OutputId:
			m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory ):
			return finalValue:
		}