summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Vertex/VertexToFragmentNode.cs
blob: 844675f40c3d5e863d3f03b904c022cc3d77be99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
//
// Custom Node Vertex To Fragment
// Donated by Jason Booth - http://u3d.as/DND

using UnityEngine;

namespace AmplifyShaderEditor
{
	[System.Serializable]
	[NodeAttributes( "Vertex To Fragment", "Miscellaneous", "Pass vertex data to the pixel shader", null, KeyCode.None, true, false, null, null, "Jason Booth - http://u3d.as/DND" )]
	public sealed class VertexToFragmentNode : SingleInputOp
	{

		protected override void CommonInit( int uniqueId )
		{
			base.CommonInit( uniqueId );
			m_inputPorts[ 0 ].AddPortForbiddenTypes(	WirePortDataType.FLOAT3x3,
														WirePortDataType.FLOAT4x4,
														WirePortDataType.SAMPLER1D,
														WirePortDataType.SAMPLER2D,
														WirePortDataType.SAMPLER3D,
														WirePortDataType.SAMPLERCUBE );
			m_inputPorts[ 0 ].Name = "(VS) In";
			m_outputPorts[ 0 ].Name = "Out";
			m_useInternalPortData = false;
			m_previewShaderGUID = "74e4d859fbdb2c0468de3612145f4929";
		}

		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 varName = GenerateInputInVertex( ref dataCollector, 0, "vertexToFrag" + OutputId,true );
			m_outputPorts[ 0 ].SetLocalValue( varName, dataCollector.PortCategory );

			return varName;

			////TEMPLATES
			//if( dataCollector.IsTemplate )
			//{
			//	if( !dataCollector.IsFragmentCategory )
			//		return m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );

			//	string varName = "vertexToFrag" + OutputId;
			//	if( dataCollector.TemplateDataCollectorInstance.HasCustomInterpolatedData( varName ) )
			//		return varName;

			//	MasterNodePortCategory category = dataCollector.PortCategory;
			//	dataCollector.PortCategory = MasterNodePortCategory.Vertex;
			//	bool dirtyVertexVarsBefore = dataCollector.DirtyVertexVariables;
			//	ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Vertex );

			//	string data = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );

			//	dataCollector.PortCategory = category;
			//	if( !dirtyVertexVarsBefore && dataCollector.DirtyVertexVariables )
			//	{
			//		dataCollector.AddVertexInstruction( dataCollector.VertexLocalVariables, UniqueId, false );
			//		dataCollector.ClearVertexLocalVariables();
			//		ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Vertex );
			//	}

			//	ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Fragment );

			//	dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData( varName, m_inputPorts[ 0 ].DataType, m_currentPrecisionType, data );
			//	//return varName;

			//	m_outputPorts[ 0 ].SetLocalValue( varName );
			//	return m_outputPorts[ 0 ].LocalValue;
			//}

			////SURFACE 
			//{
			//	if( !dataCollector.IsFragmentCategory )
			//	{
			//		return m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
			//	}

			//	if( dataCollector.TesselationActive )
			//	{
			//		UIUtils.ShowMessage( "Unable to use Vertex to Frag when Tessellation is active" );
			//		return m_outputPorts[ 0 ].ErrorValue;
			//	}


			//	string interpName = "data" + OutputId;
			//	dataCollector.AddToInput( UniqueId, interpName, m_inputPorts[ 0 ].DataType, m_currentPrecisionType );

			//	MasterNodePortCategory portCategory = dataCollector.PortCategory;
			//	dataCollector.PortCategory = MasterNodePortCategory.Vertex;

			//	bool dirtyVertexVarsBefore = dataCollector.DirtyVertexVariables;

			//	ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Vertex );

			//	string vertexVarValue = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
			//	dataCollector.AddLocalVariable( UniqueId, Constants.VertexShaderOutputStr + "." + interpName, vertexVarValue + ";" );

			//	dataCollector.PortCategory = portCategory;

			//	if( !dirtyVertexVarsBefore && dataCollector.DirtyVertexVariables )
			//	{
			//		dataCollector.AddVertexInstruction( dataCollector.VertexLocalVariables, UniqueId, false );
			//		dataCollector.ClearVertexLocalVariables();
			//		ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Vertex );
			//	}

			//	ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Fragment );

			//	//return Constants.InputVarStr + "." + interpName;

			//	m_outputPorts[ 0 ].SetLocalValue( Constants.InputVarStr + "." + interpName );
			//	return m_outputPorts[ 0 ].LocalValue;
			//}
		}
	}
}