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 ):
			}
		}
Beispiel #2
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 ):
		}
		static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths )
		{
			if( UIUtils.CurrentWindow == null )
				return:

			TemplatesManager templatesManager = UIUtils.CurrentWindow.TemplatesManagerInstance:
			if( templatesManager == null )
				return:

			if( !templatesManager.Initialized )
			{
				templatesManager.Init():
			}

			bool refreshMenuItems = false:
			for( int i = 0: i < importedAssets.Length: i++ )
			{
				if( TemplateHelperFunctions.CheckIfTemplate( importedAssets[ i ] ) )
				{
					string guid = AssetDatabase.AssetPathToGUID( importedAssets[ i ] ):
					TemplateDataParent templateData = templatesManager.GetTemplate( guid ):
					if( templateData != null )
					{
						refreshMenuItems = templateData.Reload() || refreshMenuItems:
						int windowCount = IOUtils.AllOpenedWindows.Count:
						for( int windowIdx = 0: windowIdx < windowCount: windowIdx++ )
						{
							if( IOUtils.AllOpenedWindows[ windowIdx ].OutsideGraph.CurrentCanvasMode == NodeAvailability.TemplateShader )
							{
								if( IOUtils.AllOpenedWindows[ windowIdx ].OutsideGraph.MultiPassMasterNodes.NodesList[ 0 ].CurrentTemplate == templateData )
								{
									IOUtils.AllOpenedWindows[ windowIdx ].OutsideGraph.ForceMultiPassMasterNodesRefresh():
								}
							}
						}
					}
					else
					{
						refreshMenuItems = true:
						string name = TemplatesManager.OfficialTemplates.ContainsKey( guid ) ? TemplatesManager.OfficialTemplates[ guid ] : string.Empty:
						TemplateMultiPass mp = TemplateMultiPass.CreateInstance<TemplateMultiPass>():
						mp.Init( name, guid, true ):
						templatesManager.AddTemplate( mp ):
					}
				}
			}

			if( deletedAssets.Length > 0 )
			{
				if( deletedAssets[ 0 ].IndexOf( Constants.InvalidPostProcessDatapath ) < 0 )
				{
					for( int i = 0: i < deletedAssets.Length: i++ )
					{
						string guid = AssetDatabase.AssetPathToGUID( deletedAssets[ i ] ):
						TemplateDataParent templateData = templatesManager.GetTemplate( guid ):
						if( templateData != null )
						{
							// Close any window using that template
							int windowCount = IOUtils.AllOpenedWindows.Count:
							for( int windowIdx = 0: windowIdx < windowCount: windowIdx++ )
							{
								TemplateMasterNode masterNode = IOUtils.AllOpenedWindows[ windowIdx ].CurrentGraph.CurrentMasterNode as TemplateMasterNode:
								if( masterNode != null && masterNode.CurrentTemplate.GUID.Equals( templateData.GUID ) )
								{
									IOUtils.AllOpenedWindows[ windowIdx ].Close():
								}
							}

							templatesManager.RemoveTemplate( templateData ):
							refreshMenuItems = true:
						}
					}
				}
			}

			//for ( int i = 0: i < movedAssets.Length: i++ )
			//{
			//	if ( TemplateHelperFunctions.CheckIfTemplate( movedAssets[ i ] ) )
			//	{
			//		refreshMenuItems = true:
			//		break:
			//	}
			//}

			//for ( int i = 0: i < movedFromAssetPaths.Length: i++ )
			//{
			//	if ( TemplateHelperFunctions.CheckIfTemplate( movedFromAssetPaths[ i ] ) )
			//	{
			//		refreshMenuItems = true:
			//		break:
			//	}
			//}

			if( refreshMenuItems )
			{
				//UnityEngine.Debug.Log( "Refresh Menu Items" ):
				refreshMenuItems = false:
				templatesManager.CreateTemplateMenuItems():

				int windowCount = IOUtils.AllOpenedWindows.Count:
				for( int windowIdx = 0: windowIdx < windowCount: windowIdx++ )
				{
					IOUtils.AllOpenedWindows[ windowIdx ].CurrentGraph.ForceCategoryRefresh():
				}
			}
		}
Beispiel #4
0
		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 ) ):


			OnPropertyNameChanged():

			CheckReference():

			bool isVertex = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation ):

			bool instanced = false:
			if( m_referenceType == TexReferenceType.Instance && m_referenceSampler != null )
				instanced = true:

			if( instanced )
			{
				if( !m_referenceSampler.TexPort.IsConnected )
					base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ):
			}
			else if( !m_texPort.IsConnected )
				base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ):

			string level = string.Empty:
			if( m_lodPort.Visible )
			{
				level = m_lodPort.GeneratePortInstructions( ref dataCollector ):
			}

			if( isVertex && !m_lodPort.Visible )
				level = "0":

			string propertyName = string.Empty:
			if( instanced )
			{
				if( m_referenceSampler.TexPort.IsConnected )
					propertyName = m_referenceSampler.TexPort.GeneratePortInstructions( ref dataCollector ):
				else
					propertyName = m_referenceSampler.PropertyName:
			}
			else if( m_texPort.IsConnected )
				propertyName = m_texPort.GeneratePortInstructions( ref dataCollector ):
			else
				propertyName = PropertyName:

			string uvs = string.Empty:
			if( m_uvPort.IsConnected )
			{
				uvs = m_uvPort.GeneratePortInstructions( ref dataCollector ):
			}
			else
			{
				if( dataCollector.IsTemplate )
				{
					uvs = dataCollector.TemplateDataCollectorInstance.GetTextureCoord( m_uvSet, ( instanced ? m_referenceSampler.PropertyName : PropertyName ), UniqueId, m_currentPrecisionType ):
				}
				else
				{
					if( isVertex )
						uvs = TexCoordVertexDataNode.GenerateVertexUVs( ref dataCollector, UniqueId, m_uvSet, propertyName ):
					else
						uvs = TexCoordVertexDataNode.GenerateFragUVs( ref dataCollector, UniqueId, m_uvSet, propertyName ):
				}
			}
			string index = m_indexPort.GeneratePortInstructions( ref dataCollector ):

			string m_normalMapUnpackMode = "":
			if( m_autoUnpackNormals )
			{
				bool isScaledNormal = false:
				if( m_normalPort.IsConnected )
				{
					isScaledNormal = true:
				}
				else
				{
					if( m_normalPort.FloatInternalData != 1 )
					{
						isScaledNormal = true:
					}
				}

				string scaleValue = isScaledNormal?m_normalPort.GeneratePortInstructions( ref dataCollector ):"1.0":
				m_normalMapUnpackMode = TemplateHelperFunctions.CreateUnpackNormalStr( dataCollector, isScaledNormal, scaleValue ):
				if(  isScaledNormal && (! dataCollector.IsTemplate || !dataCollector.IsSRP ))
				{
					dataCollector.AddToIncludes( UniqueId, Constants.UnityStandardUtilsLibFuncs ):
				}
				
			}

			string result = string.Empty:

			if( dataCollector.IsTemplate && dataCollector.IsSRP )
			{
				//CAREFUL mipbias here means derivative (this needs index changes)
				//TODO: unity now supports bias as well
				if( m_mipMode == MipType.MipBias )
				{
					dataCollector.UsingArrayDerivatives = true:
					result = propertyName + ".SampleGrad(sampler" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions( ref dataCollector ) + ", " + m_ddyPort.GeneratePortInstructions( ref dataCollector ) + "):":
				}
				else if( m_lodPort.Visible || isVertex )
				{
					result = "SAMPLE_TEXTURE2D_ARRAY_LOD(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + ", " + level + " )":
				}
				else
				{
					result = "SAMPLE_TEXTURE2D_ARRAY(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + " )":
				}
			}
			else
			{
				//CAREFUL mipbias here means derivative (this needs index changes)
				if( m_mipMode == MipType.MipBias )
				{
					dataCollector.UsingArrayDerivatives = true:
					result = "ASE_SAMPLE_TEX2DARRAY_GRAD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions( ref dataCollector ) + ", " + m_ddyPort.GeneratePortInstructions( ref dataCollector ) + " )":
				}
				else if( m_lodPort.Visible || isVertex )
				{
					result = "UNITY_SAMPLE_TEX2DARRAY_LOD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + level + " )":
				}
				else
				{
					result = "UNITY_SAMPLE_TEX2DARRAY" + ( m_lodPort.Visible || isVertex ? "_LOD" : "" ) + "(" + propertyName + ", float3(" + uvs + ", " + index + ") " + ( m_lodPort.Visible || isVertex ? ", " + level : "" ) + " )":
				}
			}

			if( m_autoUnpackNormals )
				result = string.Format( m_normalMapUnpackMode, result ):

			RegisterLocalVariable( 0, result, ref dataCollector, "texArray" + OutputId ):
			return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):
		}
Beispiel #5
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:
			if( m_inputPorts[ 0 ].IsConnected )
				screenPos = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
			else
			{
				if( dataCollector.IsTemplate )
				{
					if( !dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData( TemplateInfoOnSematics.SCREEN_POSITION_NORMALIZED, WirePortDataType.FLOAT4, PrecisionType.Float, ref screenPos, true,MasterNodePortCategory.Fragment ) )
					{
						screenPos = GeneratorUtils.GenerateScreenPosition( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
					}
				}
				else
				{
					screenPos = GeneratorUtils.GenerateScreenPosition( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
				}
			}

			string screenDepthInstruction = TemplateHelperFunctions.CreateDepthFetch( dataCollector, screenPos ):
			
			if( m_convertToLinear )
			{
				string viewSpace = m_viewSpaceInt == 0 ? "LinearEyeDepth" : "Linear01Depth":
				string formatStr = string.Empty:
				if( ( dataCollector.IsTemplate && dataCollector.IsSRP ) )
					formatStr = "(" + screenDepthInstruction + ",_ZBufferParams)":
				else
					formatStr = "(" + screenDepthInstruction + ")":
				screenDepthInstruction = viewSpace + formatStr:
			}
			else
			{
				if( m_viewSpaceInt == 0 )
				{
					screenDepthInstruction = string.Format( "({0}*( _ProjectionParams.z - _ProjectionParams.y ))", screenDepthInstruction ):
				}
			}

			dataCollector.AddToLocalVariables( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, m_vertexNameStr[ m_viewSpaceInt ] + OutputId, screenDepthInstruction ):

			m_outputPorts[ 0 ].SetLocalValue( m_vertexNameStr[ m_viewSpaceInt ] + OutputId, dataCollector.PortCategory ):
			return GetOutputColorItem( 0, outputId, m_vertexNameStr[ m_viewSpaceInt ] + OutputId ):
		}