// 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 * " + scale + " + " + offset + ";");
                }
                else
                {
                    dataCollector.AddToLocalVariables(dataCollector.PortCategory, uniqueId, PrecisionType.Float, size, varName, result + " * " + scale + " + " + offset);
                }

                result = varName;
            }

            return(result);
        }
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting )
				return "float3(0,0,0)":

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

			string specularMode = string.Empty:
			if( m_workflow == ASEStandardSurfaceWorkflow.Specular )
				specularMode = "Specular":

			dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ):

			if( dataCollector.DirtyNormal )
			{
				dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
				dataCollector.ForceNormal = true:
			}

			dataCollector.AddLocalVariable( UniqueId, "SurfaceOutputStandard" + specularMode + " s" + OutputId + " = (SurfaceOutputStandard" + specularMode + " ) 0:" ):
			dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Albedo = " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + ":" ):

			string normal = string.Empty:

			if( m_inputPorts[ 1 ].IsConnected )
			{
				normal = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):
				if( m_normalSpace == ViewSpace.Tangent )
				{
					normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )":
				}
			}
			else
			{
				normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId ):
			}



			dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Normal = "+ normal + ":" ):
			dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Emission = " + m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ) + ":" ):
			if( m_workflow == ASEStandardSurfaceWorkflow.Specular )
				dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Specular = " + m_inputPorts[ 3 ].GeneratePortInstructions( ref dataCollector ) + ":" ):
			else
				dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Metallic = " + m_inputPorts[ 3 ].GeneratePortInstructions( ref dataCollector ) + ":" ):
			dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Smoothness = " + m_inputPorts[ 4 ].GeneratePortInstructions( ref dataCollector ) + ":" ):
			dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Occlusion = " + m_inputPorts[ 5 ].GeneratePortInstructions( ref dataCollector ) + ":\n" ):

			dataCollector.AddLocalVariable( UniqueId, "data.light = gi.light:\n", true ):

			dataCollector.AddLocalVariable( UniqueId, "UnityGI gi" + OutputId + " = gi:" ):
			dataCollector.AddLocalVariable( UniqueId, "#ifdef UNITY_PASS_FORWARDBASE", true ):
		
			dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( s" + OutputId + ".Smoothness, data.worldViewDir, s" + OutputId + ".Normal, float3(0,0,0)):" ):
			dataCollector.AddLocalVariable( UniqueId, "gi" + OutputId + " = UnityGlobalIllumination( data, s" + OutputId + ".Occlusion, s" + OutputId + ".Normal, g" + OutputId + " ):" ):
			dataCollector.AddLocalVariable( UniqueId, "#endif\n", true ):
			dataCollector.AddLocalVariable( UniqueId, "float3 surfResult" + OutputId + " = LightingStandard" + specularMode + " ( s" + OutputId + ", viewDir, gi" + OutputId + " ).rgb:" ):
			//Emission must be always added to trick Unity, so it knows what needs to be created p.e. world pos
			dataCollector.AddLocalVariable( UniqueId, "surfResult" + OutputId + " += s" + OutputId + ".Emission:\n" ):

			m_outputPorts[ 0 ].SetLocalValue( "surfResult" + OutputId, dataCollector.PortCategory ):
			
			//Remove emission contribution from Forward Add
			dataCollector.AddLocalVariable( UniqueId, "#ifdef UNITY_PASS_FORWARDADD//" + OutputId ):
			dataCollector.AddLocalVariable( UniqueId, string.Format( "surfResult{0} -= s{0}.Emission:", OutputId )):
			dataCollector.AddLocalVariable( UniqueId, "#endif//" + OutputId ):

			return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
		}
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( dataCollector.IsTemplate )
			{
				if( !dataCollector.IsSRP )
				{
					dataCollector.AddToIncludes( UniqueId, Constants.UnityLightingLib ):
					string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos():
					string worldViewDir = dataCollector.TemplateDataCollectorInstance.GetViewDir( false, MasterNodePortCategory.Fragment ):

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

					string tempsmoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):
					string tempocclusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ):

					dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data:" ):
					dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data ):" ):
					dataCollector.AddLocalVariable( UniqueId, "data.worldPos = " + worldPos + ":" ):
					dataCollector.AddLocalVariable( UniqueId, "data.worldViewDir = " + worldViewDir + ":" ):
					dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[0] = unity_SpecCube0_HDR:" ):
					dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[1] = unity_SpecCube1_HDR:" ):
					dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION //specdataif0" ):
					dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMin[0] = unity_SpecCube0_BoxMin:" ):
					dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif0" ):
					dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BOX_PROJECTION //specdataif1" ):
					dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMax[0] = unity_SpecCube0_BoxMax:" ):
					dataCollector.AddLocalVariable( UniqueId, "\tdata.probePosition[0] = unity_SpecCube0_ProbePosition:" ):
					dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMax[1] = unity_SpecCube1_BoxMax:" ):
					dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMin[1] = unity_SpecCube1_BoxMin:" ):
					dataCollector.AddLocalVariable( UniqueId, "\tdata.probePosition[1] = unity_SpecCube1_ProbePosition:" ):
					dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif1" ):

					dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( " + tempsmoothness + ", " + worldViewDir + ", " + worldNormal + ", float3(0,0,0)):" ):
					dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, "indirectSpecular" + OutputId, "UnityGI_IndirectSpecular( data, " + tempocclusion + ", " + worldNormal + ", g" + OutputId + " )" ):
					return "indirectSpecular" + OutputId:
				}
				else
				{
					if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight )
					{
						string worldViewDir = dataCollector.TemplateDataCollectorInstance.GetViewDir( false, MasterNodePortCategory.Fragment ):
						string worldNormal = string.Empty:
						if( m_inputPorts[ 0 ].IsConnected )
						{
							if( m_normalSpace == ViewSpace.Tangent )
								worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, m_currentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ):
							else
								worldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
						}
						else
						{
							worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ):
						}

						string tempsmoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):
						string tempocclusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ):

						dataCollector.AddLocalVariable( UniqueId, "half3 reflectVector" + OutputId + " = reflect( -" + worldViewDir + ", " + worldNormal + " ):" ):
						dataCollector.AddLocalVariable( UniqueId, "float3 indirectSpecular" + OutputId + " = GlossyEnvironmentReflection( reflectVector" + OutputId + ", 1.0 - " + tempsmoothness + ", " + tempocclusion + " ):" ):
						return "indirectSpecular" + OutputId:
					}
					else if( dataCollector.CurrentSRPType == TemplateSRPType.HD )
					{
						UIUtils.ShowMessage( "Indirect Specular Light node currently not supported on HDRP" ):
						return "float3(0,0,0)":
					}
				}
			}

			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 + " )":

				dataCollector.AddLocalVariable( UniqueId, "float3 indirectNormal" + OutputId + " = " + normal + ":" ):
				normal = "indirectNormal" + OutputId:
			}
			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 ):
			}

			string smoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):
			string occlusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ):
			string viewDir = "data.worldViewDir":

			if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
			{
				string worldPos = GeneratorUtils.GenerateWorldPosition( ref dataCollector, UniqueId ):
				viewDir = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId ):

				dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data:" ):
				dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data ):" ):
				dataCollector.AddLocalVariable( UniqueId, "data.worldPos = " + worldPos + ":" ):
				dataCollector.AddLocalVariable( UniqueId, "data.worldViewDir = " + viewDir + ":" ):
				dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[0] = unity_SpecCube0_HDR:" ):
				dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[1] = unity_SpecCube1_HDR:" ):
				dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION //specdataif0" ):
				dataCollector.AddLocalVariable( UniqueId, "data.boxMin[0] = unity_SpecCube0_BoxMin:" ):
				dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif0" ):
				dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BOX_PROJECTION //specdataif1" ):
				dataCollector.AddLocalVariable( UniqueId, "data.boxMax[0] = unity_SpecCube0_BoxMax:" ):
				dataCollector.AddLocalVariable( UniqueId, "data.probePosition[0] = unity_SpecCube0_ProbePosition:" ):
				dataCollector.AddLocalVariable( UniqueId, "data.boxMax[1] = unity_SpecCube1_BoxMax:" ):
				dataCollector.AddLocalVariable( UniqueId, "data.boxMin[1] = unity_SpecCube1_BoxMin:" ):
				dataCollector.AddLocalVariable( UniqueId, "data.probePosition[1] = unity_SpecCube1_ProbePosition:" ):
				dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif1" ):
			}

			dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( " + smoothness + ", " + viewDir + ", " + normal + ", float3(0,0,0)):" ):
			dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, "indirectSpecular" + OutputId, "UnityGI_IndirectSpecular( data, " + occlusion + ", " + normal + ", g" + OutputId + " )" ):

			return "indirectSpecular" + OutputId:
		}
Exemple #4
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( dataCollector.IsTemplate )
			{
				if( m_inputPorts[ 0 ].IsConnected )
				{
					if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
						return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):


					string value = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, m_currentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ):
					if( m_normalize )
					{
						value = string.Format( NormalizeFunc, value ):
					}
					RegisterLocalVariable( 0, value, ref dataCollector, "worldNormal" + OutputId ):
					return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):
				}
				else
				{
					string value = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( m_currentPrecisionType ):
					string name:
					if( m_normalize )
					{
						name = "normalizedWorldNormal":
						value = string.Format( NormalizeFunc, value ):
						RegisterLocalVariable( 0, value, ref dataCollector, name ):
					}
					else
					{
						name = value:
					}
					return GetOutputVectorItem( 0, outputId, name ):
				}
			}

			if( dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug )
			{
				dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ):

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

					result = "(WorldNormalVector( " + Constants.InputVarStr + " , " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + " ))":
					if( m_normalize )
					{
						result = string.Format( NormalizeFunc, result ):
					}

					int connCount = 0:
					for( int i = 0: i < m_outputPorts.Count: i++ )
					{
						connCount += m_outputPorts[ i ].ConnectionCount:
					}

					if( connCount > 1 )
					{
						dataCollector.AddToLocalVariables( UniqueId, string.Format( NormalVecDecStr, NormalVecValStr + OutputId, result ) ):
						return GetOutputVectorItem( 0, outputId, NormalVecValStr + OutputId ):
					}
				}
				else
				{
					if( !dataCollector.DirtyNormal )
					{
						result = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId, m_normalize ):
					}
					else
					{
						dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
						result = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId, m_normalize ):
						dataCollector.ForceNormal = true:
					}
				}

				return GetOutputVectorItem( 0, outputId, result ):
			}
			else
			{
				if( m_inputPorts[ 0 ].IsConnected )
				{
					string inputTangent = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):

					string normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId ):
					string tangent = GeneratorUtils.GenerateWorldTangent( ref dataCollector, UniqueId ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "float3x3 tangentToWorld = CreateTangentToWorldPerVertex( " + normal + ", " + tangent + ", " + Constants.VertexShaderInputStr + ".tangent.w ):" ):
					dataCollector.AddToVertexLocalVariables( UniqueId, "float3 tangentNormal" + OutputId + " = " + inputTangent + ":" ):
					string result = "(tangentToWorld[0] * tangentNormal" + OutputId + ".x + tangentToWorld[1] * tangentNormal" + OutputId + ".y + tangentToWorld[2] * tangentNormal" + OutputId + ".z)":
					if( m_normalize )
					{
						result = string.Format( NormalizeFunc, result ):
					}
					dataCollector.AddToVertexLocalVariables( UniqueId, "float3 modWorldNormal" + OutputId + " = " + result + ":" ):
					return GetOutputVectorItem( 0, outputId, "modWorldNormal" + OutputId ):
				}
				else
				{
					string result = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId, m_normalize ):
					return GetOutputVectorItem( 0, outputId, result ):
				}
			}
		}
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( dataCollector.IsTemplate )
			{
				if( m_inputPorts[ 0 ].IsConnected )
				{
					string space = string.Empty:
					if( m_viewSpaceInt == 1 )
						space = " * _ProjectionParams.w":

					string varName = "customSurfaceDepth" + OutputId:
					GenerateInputInVertex( ref dataCollector, 0, varName, false ):
					string instruction = "-UnityObjectToViewPos( " + varName + " ).z" + space:
					if( dataCollector.IsSRP )
						instruction = "-TransformWorldToView(TransformObjectToWorld( " + varName + " )).z" + space:
					string eyeVarName = "customEye" + OutputId:
					dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData( eyeVarName, WirePortDataType.FLOAT, m_currentPrecisionType, instruction ):
					return eyeVarName:
				}
				else
				{
					return dataCollector.TemplateDataCollectorInstance.GetEyeDepth( m_currentPrecisionType, true, MasterNodePortCategory.Fragment, m_viewSpaceInt ):
				}
			}

			if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
			{
				string vertexVarName = string.Empty:
				if( m_inputPorts[ 0 ].IsConnected )
				{
					vertexVarName = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
				}
				else
				{
					vertexVarName = Constants.VertexShaderInputStr + ".vertex.xyz":
				}

				string vertexSpace = m_viewSpaceInt == 1 ? " * _ProjectionParams.w" : "":
				string vertexInstruction = "-UnityObjectToViewPos( " + vertexVarName + " ).z" + vertexSpace:
				dataCollector.AddVertexInstruction( "float " + m_vertexNameStr[ m_viewSpaceInt ] + " = " + vertexInstruction, UniqueId ):

				return m_vertexNameStr[ m_viewSpaceInt ]:
			}

			dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables ):


			if( dataCollector.TesselationActive )
			{
				if( m_inputPorts[ 0 ].IsConnected )
				{
					string space = string.Empty:
					if( m_viewSpaceInt == 1 )
						space = " * _ProjectionParams.w":

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

					string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
					RegisterLocalVariable( 0, string.Format( "-UnityObjectToViewPos( {0} ).z", value ) + space, ref dataCollector, "customSurfaceDepth" + OutputId ):
					return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
				}
				else
				{
					string eyeDepth = GeneratorUtils.GenerateScreenDepthOnFrag( ref dataCollector, UniqueId, m_currentPrecisionType ):
					if( m_viewSpaceInt == 1 )
					{
						dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, m_vertexNameStr[ 1 ], eyeDepth + " * _ProjectionParams.w" ):
						return m_vertexNameStr[ 1 ]:
					}
					else
					{
						return eyeDepth:
					}
				}
			}
			else
			{

				string space = string.Empty:
				if( m_viewSpaceInt == 1 )
					space = " * _ProjectionParams.w":

				if( m_inputPorts[ 0 ].IsConnected )
				{
					string varName = "customSurfaceDepth" + OutputId:
					GenerateInputInVertex( ref dataCollector, 0, varName, false ):
					dataCollector.AddToInput( UniqueId, varName, WirePortDataType.FLOAT ):
					string instruction = "-UnityObjectToViewPos( " + varName + " ).z" + space:
					dataCollector.AddToVertexLocalVariables( UniqueId , Constants.VertexShaderOutputStr + "." + varName + " = " + instruction+":" ):
					return Constants.InputVarStr + "." + varName:
				}
				else
				{
					dataCollector.AddToInput( UniqueId, m_vertexNameStr[ m_viewSpaceInt ], WirePortDataType.FLOAT ):
					string instruction = "-UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z" + space:
					dataCollector.AddToVertexLocalVariables( UniqueId , Constants.VertexShaderOutputStr + "." + m_vertexNameStr[ m_viewSpaceInt ] + " = " + instruction+":" ):
					return Constants.InputVarStr + "." + m_vertexNameStr[ m_viewSpaceInt ]:
				}
			}
		}
Exemple #6
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 ):

			InputPort vertexPort = GetInputPortByUniqueId( 2 ):
			InputPort lengthPort = GetInputPortByUniqueId( 0 ):
			InputPort offsetPort = GetInputPortByUniqueId( 1 ):

			string distance = lengthPort.GeneratePortInstructions( ref dataCollector ):
			string offset = offsetPort.GeneratePortInstructions( ref dataCollector ):

			string value = string.Empty:
			string eyeDepth = string.Empty:

			if( dataCollector.IsTemplate )
			{
				if( vertexPort.IsConnected )
				{
					string varName = "customSurfaceDepth" + OutputId:
					GenerateInputInVertex( ref dataCollector, 2, varName, false ):

					string formatStr = string.Empty:
					if( dataCollector.IsSRP )
						formatStr = "-TransformWorldToView(TransformObjectToWorld({0})).z":
					else
						formatStr = "-UnityObjectToViewPos({0}).z":

					string eyeInstruction = string.Format( formatStr, varName ):
					eyeDepth = "customEye" + OutputId:
					dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData( eyeDepth, WirePortDataType.FLOAT, m_currentPrecisionType, eyeInstruction ):
				}
				else
				{
					eyeDepth = dataCollector.TemplateDataCollectorInstance.GetEyeDepth( m_currentPrecisionType ):
				}

				value = string.Format( CameraDepthFadeFormat, eyeDepth, offset, distance ):
				RegisterLocalVariable( 0, value, ref dataCollector, "cameraDepthFade" + OutputId ):
				return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
			}

			if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
			{
				string vertexVarName = string.Empty:
				if( vertexPort.IsConnected )
				{
					vertexVarName = vertexPort.GeneratePortInstructions( ref dataCollector ):
				}
				else
				{
					vertexVarName = Constants.VertexShaderInputStr + ".vertex.xyz":
				}

				//dataCollector.AddVertexInstruction( "float cameraDepthFade" + UniqueId + " = (( -UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z -_ProjectionParams.y - " + offset + " ) / " + distance + "):", UniqueId ):
				value = string.Format( CameraDepthFadeFormat, "-UnityObjectToViewPos( " + vertexVarName + " ).z", offset, distance ):
				RegisterLocalVariable( 0, value, ref dataCollector, "cameraDepthFade" + OutputId ):
				return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
			}

			dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables ):

			if( dataCollector.TesselationActive )
			{
				if( vertexPort.IsConnected )
				{
					string vertexValue = vertexPort.GeneratePortInstructions( ref dataCollector ):
					eyeDepth = "customSurfaceDepth" + OutputId:
					RegisterLocalVariable( 0, string.Format( "-UnityObjectToViewPos( {0} ).z", vertexValue ), ref dataCollector, eyeDepth ):
				}
				else
				{
					eyeDepth = GeneratorUtils.GenerateScreenDepthOnFrag( ref dataCollector, UniqueId, m_currentPrecisionType ):
				}
			}
			else
			{

				if( vertexPort.IsConnected )
				{
					string varName = "customSurfaceDepth" + OutputId:
					GenerateInputInVertex( ref dataCollector, 2, varName, false ):
					dataCollector.AddToInput( UniqueId, varName, WirePortDataType.FLOAT ):
					string vertexInstruction = "-UnityObjectToViewPos( " + varName + " ).z":
					dataCollector.AddToVertexLocalVariables( UniqueId, Constants.VertexShaderOutputStr + "." + varName + " = " + vertexInstruction + ":" ):
					eyeDepth = Constants.InputVarStr + "." + varName:
				}
				else
				{
					dataCollector.AddToInput( UniqueId, "eyeDepth", WirePortDataType.FLOAT ):
					string instruction = "-UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z":
					dataCollector.AddToVertexLocalVariables( UniqueId, Constants.VertexShaderOutputStr + ".eyeDepth = " + instruction + ":" ):
					eyeDepth = Constants.InputVarStr + ".eyeDepth":
				}
			}

			value = string.Format( CameraDepthFadeFormat, eyeDepth, offset, distance ):
			RegisterLocalVariable( 0, value, ref dataCollector, "cameraDepthFade" + OutputId ):
			//dataCollector.AddToLocalVariables( UniqueId, "float cameraDepthFade" + UniqueId + " = (( " + Constants.InputVarStr + ".eyeDepth -_ProjectionParams.y - "+ offset + " ) / " + distance + "):" ):

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