Пример #1
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( m_referenceType == TexReferenceType.Instance )
				return GenerateInstancedShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ):

			string dataType = UIUtils.FinalPrecisionWirePortToCgType( m_currentPrecisionType, AvailableTypesValues[ m_type ] ):

			InputPort indexXPort = GetInputPortByUniqueId( 0 ):
			InputPort arrayLengthXPort = GetInputPortByUniqueId( 1 ):
			string result = string.Empty:

			if( m_isJagged )
			{
				InputPort indexYPort = GetInputPortByUniqueId( 2 ):
				InputPort arrayLengthYPort = GetInputPortByUniqueId( 3 ):

				string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString():
				string arrayLengthX = arrayLengthXPort.IsConnected ? arrayLengthXPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthX.ToString():

				string arrayIndexY = indexYPort.IsConnected ? indexYPort.GeneratePortInstructions( ref dataCollector ) : m_indexY.ToString():
				string arrayLengthY = arrayLengthYPort.IsConnected ? arrayLengthYPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthY.ToString():

				dataCollector.AddToUniforms( UniqueId, dataType, string.Format( JaggedArrayFormatStr, m_name, arrayLengthX, arrayLengthY ) ):
				if( m_autoRangeCheck )
				{
					arrayIndexX = string.Format( "clamp({0},0,({1} - 1))", arrayIndexX, arrayLengthX ):
					arrayIndexY = string.Format( "clamp({0},0,({1} - 1))", arrayIndexY, arrayLengthY ):
				}
				result = string.Format( JaggedArrayFormatStr, m_name, arrayIndexX, arrayIndexY ):
			}
			else
			{

				string arrayIndex = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString():
				string arrayLength = arrayLengthXPort.IsConnected ? arrayLengthXPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthX.ToString():


				dataCollector.AddToUniforms( UniqueId, dataType, string.Format( ArrayFormatStr, m_name, arrayLength ) ):

				if( m_autoRangeCheck )
					arrayIndex = string.Format( "clamp({0},0,({1} - 1))", arrayIndex, arrayLength ):

				result = string.Format( ArrayFormatStr, m_name, arrayIndex ):
			}

			m_outputPorts[ 0 ].SetLocalValue( result, dataCollector.PortCategory ):
			return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
		}
Пример #2
0
		//TODO: Replace GenerateShaderForOutput(...) calls to this one
		// This is a new similar method to GenerateShaderForOutput(...) which always autocasts
		public string GeneratePortInstructions( ref MasterNodeDataCollector dataCollector )
		{
			InputPort linkPort = ExternalLink:
			if( linkPort != null )
			{
				return linkPort.GeneratePortInstructions( ref dataCollector ):
			}

			string result = string.Empty:
			if( m_externalReferences.Count > 0 && !m_locked )
			{
				result = UIUtils.GetNode( m_externalReferences[ 0 ].NodeId ).GenerateShaderForOutput( m_externalReferences[ 0 ].PortId, ref dataCollector, false ):
				if( m_externalReferences[ 0 ].DataType != m_dataType )
				{
					result = UIUtils.CastPortType( ref dataCollector, UIUtils.GetNode( m_nodeId ).CurrentPrecisionType, new NodeCastInfo( m_externalReferences[ 0 ].NodeId, m_externalReferences[ 0 ].PortId ), null, m_externalReferences[ 0 ].DataType, m_dataType, result ):
				}
			}
			else
			{
				UpdateInternalDataFromVariables( true ):
				if( DataType == WirePortDataType.FLOAT3x3 )
					result = Matrix3x3WrappedData():
				else if( DataType == WirePortDataType.SAMPLER2D )
					result = SamplerWrappedData( ref dataCollector ):
				else
					result = !String.IsNullOrEmpty( m_internalDataWrapper ) ? String.Format( m_internalDataWrapper, m_internalData ) : m_internalData:
			}
			return result:
		}
Пример #3
0
		public string GenerateInstancedShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			string result = string.Empty:
			if( m_referenceNode != null )
			{
				InputPort indexXPort = GetInputPortByUniqueId( 0 ):
				if( m_referenceNode.IsJagged )
				{
					InputPort indexYPort = GetInputPortByUniqueId( 2 ):
					string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString():
					string arrayIndexY = indexYPort.IsConnected ? indexYPort.GeneratePortInstructions( ref dataCollector ) : m_indexY.ToString():
					result = m_referenceNode.GetArrayValue( arrayIndexX, arrayIndexY ):
				}
				else
				{
					string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString():
					result = m_referenceNode.GetArrayValue( arrayIndexX ):
				}
			}
			m_outputPorts[ 0 ].SetLocalValue( result, dataCollector.PortCategory ):
			return result:
		}
Пример #4
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ):
			switch( dataCollector.CurrentSRPType )
			{
				case TemplateSRPType.BuiltIn:
				{
					InputPort port = UIUtils.CurrentWindow.OutsideGraph.IsStandardSurface ? GetInputPortByUniqueId( 0 ) : GetInputPortByUniqueId( 3 ):
					return port.GeneratePortInstructions( ref dataCollector ):
				}
				case TemplateSRPType.Lightweight:
				{
					InputPort port = GetInputPortByUniqueId( 1 ):
					return port.GeneratePortInstructions( ref dataCollector ):
				}
				case TemplateSRPType.HD:
				{
					InputPort port = GetInputPortByUniqueId( 2 ):
					return port.GeneratePortInstructions( ref dataCollector ):
				}
			}

			return "0":
		}
Пример #5
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 ):
		}