TextureCoordinatesNode.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace AmplifyShaderEditor
  8. {
  9. [Serializable]
  10. [NodeAttributes( "Texture Coordinates", "UV Coordinates", "Texture UV coordinates set, if <b>Tex</b> is connected to a texture object it will use that texture scale factors, otherwise uses <b>Tilling</b> and <b>Offset</b> port values", null, KeyCode.U, tags: "uv" )]
  11. public sealed class TextureCoordinatesNode : ParentNode
  12. {
  13. private const string DummyPropertyDec = "[HideInInspector] _DummyTex{0}( \"\", 2D ) = \"white\"";
  14. private const string DummyUniformDec = "uniform sampler2D _DummyTex{0};";
  15. private const string DummyTexCoordDef = "uv{0}_DummyTex{0}";
  16. private const string DummyTexCoordSurfDef = "float2 texCoordDummy{0} = {1}.uv{2}_DummyTex{2}*{3} + {4};";
  17. private const string DummyTexCoordSurfVar = "texCoordDummy{0}";
  18. private readonly string[] Dummy = { string.Empty };
  19. private const string TilingStr = "Tiling";
  20. private const string OffsetStr = "Offset";
  21. private const string TexCoordStr = "texcoord_";
  22. [SerializeField]
  23. private int m_referenceArrayId = -1;
  24. [SerializeField]
  25. private int m_referenceNodeId = -1;
  26. [SerializeField]
  27. private int m_textureCoordChannel = 0;
  28. //[SerializeField]
  29. //private int m_texcoordId = -1;
  30. [SerializeField]
  31. private int m_texcoordSize = 2;
  32. [SerializeField]
  33. private string m_surfaceTexcoordName = string.Empty;
  34. [SerializeField]
  35. private TexturePropertyNode m_inputReferenceNode = null;
  36. private Vector4Node m_texCoordsHelper;
  37. private TexturePropertyNode m_referenceNode = null;
  38. private InputPort m_texPort = null;
  39. private InputPort m_tilingPort = null;
  40. private InputPort m_offsetPort = null;
  41. protected override void CommonInit( int uniqueId )
  42. {
  43. base.CommonInit( uniqueId );
  44. AddInputPort( WirePortDataType.SAMPLER2D, false, "Tex", -1, MasterNodePortCategory.Fragment, 2 );
  45. m_texPort = m_inputPorts[ m_inputPorts.Count - 1 ];
  46. m_texPort.CreatePortRestrictions( WirePortDataType.SAMPLER1D, WirePortDataType.SAMPLER2D, WirePortDataType.SAMPLER3D, WirePortDataType.SAMPLERCUBE, WirePortDataType.SAMPLER2DARRAY, WirePortDataType.OBJECT );
  47. AddInputPort( WirePortDataType.FLOAT2, false, "Tiling", -1, MasterNodePortCategory.Fragment, 0 );
  48. m_tilingPort = m_inputPorts[ m_inputPorts.Count - 1 ];
  49. m_tilingPort.Vector2InternalData = new Vector2( 1, 1 );
  50. AddInputPort( WirePortDataType.FLOAT2, false, "Offset", -1, MasterNodePortCategory.Fragment, 1 );
  51. m_offsetPort = m_inputPorts[ m_inputPorts.Count - 1 ];
  52. AddOutputVectorPorts( WirePortDataType.FLOAT2, "UV" );
  53. m_outputPorts[ 1 ].Name = "U";
  54. m_outputPorts[ 2 ].Name = "V";
  55. AddOutputPort( WirePortDataType.FLOAT, "W" );
  56. AddOutputPort( WirePortDataType.FLOAT, "T" );
  57. m_textLabelWidth = 90;
  58. m_useInternalPortData = true;
  59. m_autoWrapProperties = true;
  60. m_hasLeftDropdown = true;
  61. m_tilingPort.Category = MasterNodePortCategory.Vertex;
  62. m_offsetPort.Category = MasterNodePortCategory.Vertex;
  63. UpdateOutput();
  64. m_previewShaderGUID = "085e462b2de441a42949be0e666cf5d2";
  65. }
  66. public override void Reset()
  67. {
  68. m_surfaceTexcoordName = string.Empty;
  69. }
  70. public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
  71. {
  72. base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
  73. if( portId == 2 )
  74. {
  75. m_texPort.MatchPortToConnection();
  76. m_inputReferenceNode = m_texPort.GetOutputNodeWhichIsNotRelay() as TexturePropertyNode;
  77. UpdatePorts();
  78. }
  79. UpdateTitle();
  80. }
  81. public override void OnInputPortDisconnected( int portId )
  82. {
  83. base.OnInputPortDisconnected( portId );
  84. if( portId == 2 )
  85. {
  86. m_inputReferenceNode = null;
  87. UpdatePorts();
  88. }
  89. UpdateTitle();
  90. }
  91. public override void OnConnectedOutputNodeChanges( int portId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
  92. {
  93. base.OnConnectedOutputNodeChanges( portId, otherNodeId, otherPortId, name, type );
  94. if( portId == 2 )
  95. {
  96. m_texPort.MatchPortToConnection();
  97. UpdateTitle();
  98. }
  99. }
  100. void UpdateTitle()
  101. {
  102. if( m_inputReferenceNode != null )
  103. {
  104. m_additionalContent.text = string.Format( "Value( {0} )", m_inputReferenceNode.PropertyInspectorName );
  105. }
  106. else if( m_referenceArrayId > -1 && m_referenceNode != null )
  107. {
  108. m_additionalContent.text = string.Format( "Value( {0} )", m_referenceNode.PropertyInspectorName );
  109. }
  110. else
  111. {
  112. m_additionalContent.text = string.Empty;
  113. }
  114. m_sizeIsDirty = true;
  115. }
  116. void UpdatePorts()
  117. {
  118. if( m_inputReferenceNode != null || m_texPort.IsConnected )
  119. {
  120. m_tilingPort.Locked = true;
  121. m_offsetPort.Locked = true;
  122. }
  123. else if( m_referenceArrayId > -1 )
  124. {
  125. m_tilingPort.Locked = true;
  126. m_offsetPort.Locked = true;
  127. }
  128. else
  129. {
  130. m_tilingPort.Locked = false;
  131. m_offsetPort.Locked = false;
  132. }
  133. }
  134. public override void DrawProperties()
  135. {
  136. bool guiEnabledBuffer = GUI.enabled;
  137. EditorGUI.BeginChangeCheck();
  138. List<string> arr = new List<string>( UIUtils.TexturePropertyNodeArr() );
  139. if( arr != null && arr.Count > 0 )
  140. {
  141. arr.Insert( 0, "None" );
  142. GUI.enabled = true && ( !m_texPort.IsConnected );
  143. m_referenceArrayId = EditorGUILayoutPopup( Constants.AvailableReferenceStr, m_referenceArrayId + 1, arr.ToArray() ) - 1;
  144. }
  145. else
  146. {
  147. m_referenceArrayId = -1;
  148. GUI.enabled = false;
  149. EditorGUILayoutPopup( Constants.AvailableReferenceStr, 0, Dummy );
  150. }
  151. GUI.enabled = guiEnabledBuffer;
  152. if( EditorGUI.EndChangeCheck() )
  153. {
  154. m_referenceNode = UIUtils.GetTexturePropertyNode( m_referenceArrayId );
  155. if( m_referenceNode != null )
  156. {
  157. m_referenceNodeId = m_referenceNode.UniqueId;
  158. }
  159. else
  160. {
  161. m_referenceNodeId = -1;
  162. m_referenceArrayId = -1;
  163. }
  164. UpdateTitle();
  165. UpdatePorts();
  166. }
  167. EditorGUI.BeginChangeCheck();
  168. m_texcoordSize = EditorGUILayoutIntPopup( Constants.AvailableUVSizesLabel, m_texcoordSize, Constants.AvailableUVSizesStr, Constants.AvailableUVSizes );
  169. if( EditorGUI.EndChangeCheck() )
  170. {
  171. UpdateOutput();
  172. }
  173. m_textureCoordChannel = EditorGUILayoutIntPopup( Constants.AvailableUVSetsLabel, m_textureCoordChannel, Constants.AvailableUVSetsStr, Constants.AvailableUVSets );
  174. if( m_referenceArrayId > -1 )
  175. GUI.enabled = false;
  176. base.DrawProperties();
  177. GUI.enabled = guiEnabledBuffer;
  178. }
  179. private void UpdateOutput()
  180. {
  181. if( m_texcoordSize == 3 )
  182. {
  183. m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
  184. m_outputPorts[ 0 ].Name = "UVW";
  185. m_outputPorts[ 3 ].Visible = true;
  186. m_outputPorts[ 4 ].Visible = false;
  187. }
  188. else if( m_texcoordSize == 4 )
  189. {
  190. m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
  191. m_outputPorts[ 0 ].Name = "UVWT";
  192. m_outputPorts[ 3 ].Visible = true;
  193. m_outputPorts[ 4 ].Visible = true;
  194. }
  195. else
  196. {
  197. m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT2, false );
  198. m_outputPorts[ 0 ].Name = "UV";
  199. m_outputPorts[ 3 ].Visible = false;
  200. m_outputPorts[ 4 ].Visible = false;
  201. }
  202. m_sizeIsDirty = true;
  203. }
  204. public override void OnNodeLogicUpdate( DrawInfo drawInfo )
  205. {
  206. base.OnNodeLogicUpdate( drawInfo );
  207. CheckReference();
  208. }
  209. //public override void Draw( DrawInfo drawInfo )
  210. //{
  211. // base.Draw( drawInfo );
  212. // //CheckReference();
  213. //}
  214. public override void Draw( DrawInfo drawInfo )
  215. {
  216. base.Draw( drawInfo );
  217. if( m_dropdownEditing )
  218. {
  219. EditorGUI.BeginChangeCheck();
  220. m_texcoordSize = EditorGUIIntPopup( m_dropdownRect, m_texcoordSize, Constants.AvailableUVSizesStr, Constants.AvailableUVSizes, UIUtils.PropertyPopUp );
  221. if( EditorGUI.EndChangeCheck() )
  222. {
  223. UpdateOutput();
  224. DropdownEditing = false;
  225. }
  226. }
  227. }
  228. void CheckReference()
  229. {
  230. if( m_referenceArrayId > -1 )
  231. {
  232. ParentNode newNode = UIUtils.GetTexturePropertyNode( m_referenceArrayId );
  233. if( newNode == null || newNode.UniqueId != m_referenceNodeId )
  234. {
  235. m_referenceNode = null;
  236. int count = UIUtils.GetTexturePropertyNodeAmount();
  237. for( int i = 0; i < count; i++ )
  238. {
  239. ParentNode node = UIUtils.GetTexturePropertyNode( i );
  240. if( node.UniqueId == m_referenceNodeId )
  241. {
  242. m_referenceNode = node as TexturePropertyNode;
  243. m_referenceArrayId = i;
  244. break;
  245. }
  246. }
  247. }
  248. }
  249. if( m_referenceNode == null && m_referenceNodeId > -1 )
  250. {
  251. m_referenceNodeId = -1;
  252. m_referenceArrayId = -1;
  253. UpdateTitle();
  254. UpdatePorts();
  255. }
  256. }
  257. public override void ReadFromString( ref string[] nodeParams )
  258. {
  259. base.ReadFromString( ref nodeParams );
  260. m_textureCoordChannel = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  261. if( UIUtils.CurrentShaderVersion() > 2402 )
  262. {
  263. if( UIUtils.CurrentShaderVersion() > 2404 )
  264. {
  265. m_referenceNodeId = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  266. }
  267. else
  268. {
  269. m_referenceArrayId = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  270. }
  271. }
  272. if( UIUtils.CurrentShaderVersion() > 5001 )
  273. {
  274. m_texcoordSize = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  275. UpdateOutput();
  276. }
  277. }
  278. public override void RefreshExternalReferences()
  279. {
  280. base.RefreshExternalReferences();
  281. if( UIUtils.CurrentShaderVersion() > 2402 )
  282. {
  283. if( UIUtils.CurrentShaderVersion() > 2404 )
  284. {
  285. m_referenceNode = UIUtils.GetNode( m_referenceNodeId ) as TexturePropertyNode;
  286. if( m_referenceNodeId > -1 )
  287. m_referenceArrayId = UIUtils.GetTexturePropertyNodeRegisterId( m_referenceNodeId );
  288. }
  289. else
  290. {
  291. m_referenceNode = UIUtils.GetTexturePropertyNode( m_referenceArrayId );
  292. if( m_referenceNode != null )
  293. {
  294. m_referenceNodeId = m_referenceNode.UniqueId;
  295. }
  296. }
  297. UpdateTitle();
  298. UpdatePorts();
  299. }
  300. }
  301. public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
  302. {
  303. if( dataCollector != null && dataCollector.TesselationActive )
  304. {
  305. base.PropagateNodeData( nodeData, ref dataCollector );
  306. return;
  307. }
  308. if( dataCollector.IsTemplate )
  309. {
  310. dataCollector.TemplateDataCollectorInstance.SetUVUsage( m_textureCoordChannel , m_texcoordSize );
  311. }
  312. else
  313. {
  314. dataCollector.SetTextureChannelSize( m_textureCoordChannel , m_outputPorts[0].DataType );
  315. if( m_textureCoordChannel > 3 )
  316. {
  317. dataCollector.AddCustomAppData( string.Format( TemplateHelperFunctions.TexUVFullSemantic , m_textureCoordChannel ) );
  318. }
  319. }
  320. UIUtils.SetCategoryInBitArray( ref m_category, nodeData.Category );
  321. MasterNodePortCategory propagateCategory = ( nodeData.Category != MasterNodePortCategory.Vertex && nodeData.Category != MasterNodePortCategory.Tessellation ) ? MasterNodePortCategory.Vertex : nodeData.Category;
  322. nodeData.Category = propagateCategory;
  323. nodeData.GraphDepth += 1;
  324. if( nodeData.GraphDepth > m_graphDepth )
  325. {
  326. m_graphDepth = nodeData.GraphDepth;
  327. }
  328. int count = m_inputPorts.Count;
  329. for( int i = 0; i < count; i++ )
  330. {
  331. if( m_inputPorts[ i ].IsConnected )
  332. {
  333. //m_inputPorts[ i ].GetOutputNode().PropagateNodeCategory( category );
  334. m_inputPorts[ i ].GetOutputNode().PropagateNodeData( nodeData, ref dataCollector );
  335. }
  336. }
  337. }
  338. public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  339. {
  340. base.WriteToString( ref nodeInfo, ref connectionsInfo );
  341. IOUtils.AddFieldValueToString( ref nodeInfo, m_textureCoordChannel );
  342. IOUtils.AddFieldValueToString( ref nodeInfo, ( ( m_referenceNode != null ) ? m_referenceNode.UniqueId : -1 ) );
  343. IOUtils.AddFieldValueToString( ref nodeInfo, m_texcoordSize );
  344. }
  345. string GetValidPropertyName()
  346. {
  347. string propertyName = string.Empty;
  348. if( m_inputReferenceNode != null )
  349. {
  350. propertyName = m_inputReferenceNode.PropertyName;
  351. }
  352. else if( m_referenceArrayId > -1 )
  353. {
  354. m_referenceNode = UIUtils.GetTexturePropertyNode( m_referenceArrayId );
  355. if( m_referenceNode != null )
  356. {
  357. propertyName = m_referenceNode.PropertyName;
  358. }
  359. }
  360. return propertyName;
  361. }
  362. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
  363. {
  364. if( dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
  365. {
  366. UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " cannot be used on Master Node Tessellation port" );
  367. return "-1";
  368. }
  369. //bool isVertex = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation );
  370. string tiling = string.Empty;
  371. string offset = string.Empty;
  372. string portProperty = string.Empty;
  373. if( m_texPort.IsConnected )
  374. {
  375. portProperty = m_texPort.GeneratePortInstructions( ref dataCollector );
  376. }
  377. else if( m_referenceArrayId > -1 )
  378. {
  379. TexturePropertyNode temp = UIUtils.GetTexturePropertyNode( m_referenceArrayId );
  380. if( temp != null )
  381. {
  382. portProperty = temp.BaseGenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalVar );
  383. }
  384. }
  385. //TEMPLATES
  386. if( dataCollector.MasterNodeCategory == AvailableShaderTypes.Template )
  387. {
  388. if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  389. return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
  390. string uvName = string.Empty;
  391. string result = string.Empty;
  392. string indexStr = m_textureCoordChannel > 0 ? ( m_textureCoordChannel + 1 ).ToString() : "";
  393. string sizeDif = string.Empty;
  394. if( m_texcoordSize == 3 )
  395. sizeDif = "3";
  396. else if( m_texcoordSize == 4 )
  397. sizeDif = "4";
  398. if( dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData( TemplateHelperFunctions.IntToUVChannelInfo[ m_textureCoordChannel ], m_outputPorts[ 0 ].DataType, PrecisionType.Float, ref result, false, dataCollector.PortCategory ) )
  399. {
  400. uvName = result;
  401. }
  402. else if( dataCollector.TemplateDataCollectorInstance.HasUV( m_textureCoordChannel ) )
  403. {
  404. uvName = dataCollector.TemplateDataCollectorInstance.GetUVName( m_textureCoordChannel, m_outputPorts[ 0 ].DataType );
  405. }
  406. else
  407. {
  408. uvName = dataCollector.TemplateDataCollectorInstance.RegisterUV( m_textureCoordChannel, m_outputPorts[ 0 ].DataType );
  409. }
  410. string currPropertyName = GetValidPropertyName();
  411. if( !string.IsNullOrEmpty( portProperty ) && portProperty != "0.0" )
  412. {
  413. currPropertyName = portProperty;
  414. }
  415. if( !string.IsNullOrEmpty( currPropertyName ) )
  416. {
  417. string finalTexCoordName = "uv" + indexStr + ( m_texcoordSize > 2 ? "s" + sizeDif : "" ) + currPropertyName;
  418. string dummyPropertyTexcoords = currPropertyName + "_ST";
  419. if( m_texCoordsHelper == null )
  420. {
  421. m_texCoordsHelper = CreateInstance<Vector4Node>();
  422. m_texCoordsHelper.ContainerGraph = ContainerGraph;
  423. m_texCoordsHelper.SetBaseUniqueId( UniqueId, true );
  424. m_texCoordsHelper.RegisterPropertyOnInstancing = false;
  425. m_texCoordsHelper.AddGlobalToSRPBatcher = true;
  426. }
  427. if( UIUtils.CurrentWindow.OutsideGraph.IsInstancedShader )
  428. {
  429. m_texCoordsHelper.CurrentParameterType = PropertyType.InstancedProperty;
  430. }
  431. else
  432. {
  433. m_texCoordsHelper.CurrentParameterType = PropertyType.Global;
  434. }
  435. m_texCoordsHelper.ResetOutputLocals();
  436. m_texCoordsHelper.SetRawPropertyName( dummyPropertyTexcoords );
  437. dummyPropertyTexcoords = m_texCoordsHelper.GenerateShaderForOutput( 0, ref dataCollector, false );
  438. if( m_texcoordSize > 2 )
  439. {
  440. dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, m_outputPorts[ 0 ].DataType, finalTexCoordName, uvName );
  441. dataCollector.AddLocalVariable( UniqueId, finalTexCoordName + ".xy", string.Format( Constants.TilingOffsetFormat, uvName + ".xy", dummyPropertyTexcoords + ".xy", dummyPropertyTexcoords + ".zw" ) + ";" );
  442. m_outputPorts[ 0 ].SetLocalValue( finalTexCoordName, dataCollector.PortCategory );
  443. }
  444. else
  445. {
  446. RegisterLocalVariable( 0, string.Format( Constants.TilingOffsetFormat, uvName, dummyPropertyTexcoords + ".xy", dummyPropertyTexcoords + ".zw" ), ref dataCollector, finalTexCoordName );
  447. }
  448. //RegisterLocalVariable( 0, string.Format( Constants.TilingOffsetFormat, uvName, dummyPropertyTexcoords+".xy", dummyPropertyTexcoords+".zw" ), ref dataCollector, finalTexCoordName );
  449. }
  450. else
  451. {
  452. string finalTexCoordName = "texCoord" + OutputId;
  453. tiling = m_tilingPort.GeneratePortInstructions( ref dataCollector );
  454. offset = m_offsetPort.GeneratePortInstructions( ref dataCollector );
  455. if( m_texcoordSize > 2 )
  456. {
  457. dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, m_outputPorts[ 0 ].DataType, finalTexCoordName, uvName );
  458. dataCollector.AddLocalVariable( UniqueId, finalTexCoordName + ".xy", string.Format( Constants.TilingOffsetFormat, uvName + ".xy", tiling, offset ) + ";" );
  459. m_outputPorts[ 0 ].SetLocalValue( finalTexCoordName, dataCollector.PortCategory );
  460. }
  461. else
  462. {
  463. RegisterLocalVariable( 0, string.Format( Constants.TilingOffsetFormat, uvName, tiling, offset ), ref dataCollector, finalTexCoordName );
  464. }
  465. //RegisterLocalVariable( 0, string.Format( Constants.TilingOffsetFormat, uvName, tiling, offset ), ref dataCollector, finalTexCoordName );
  466. }
  467. return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
  468. }
  469. //SURFACE
  470. string propertyName = GetValidPropertyName();
  471. if( !string.IsNullOrEmpty( portProperty ) && portProperty != "0.0" )
  472. {
  473. propertyName = portProperty;
  474. }
  475. if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  476. return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
  477. if( !m_tilingPort.IsConnected && m_tilingPort.Vector2InternalData == Vector2.one )
  478. tiling = null;
  479. else
  480. tiling = m_tilingPort.GeneratePortInstructions( ref dataCollector );
  481. if( !m_offsetPort.IsConnected && m_offsetPort.Vector2InternalData == Vector2.zero )
  482. offset = null;
  483. else
  484. offset = m_offsetPort.GeneratePortInstructions( ref dataCollector );
  485. if( !string.IsNullOrEmpty( propertyName ) /*m_referenceArrayId > -1*/ )
  486. {
  487. m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs( ref dataCollector, UniqueId, m_textureCoordChannel, propertyName, m_outputPorts[ 0 ].DataType, tiling, offset, OutputId );
  488. }
  489. else
  490. {
  491. m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs( ref dataCollector, UniqueId, m_textureCoordChannel, null, m_outputPorts[ 0 ].DataType, tiling, offset, OutputId );
  492. }
  493. m_outputPorts[ 0 ].SetLocalValue( m_surfaceTexcoordName, dataCollector.PortCategory );
  494. return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
  495. }
  496. public override void ReadInputDataFromString( ref string[] nodeParams )
  497. {
  498. if( UIUtils.CurrentShaderVersion() > 7003 )
  499. {
  500. base.ReadInputDataFromString( ref nodeParams );
  501. }
  502. else
  503. {
  504. for( int i = 0; i < 2 && i < nodeParams.Length && m_currentReadParamIdx < nodeParams.Length; i++ )
  505. {
  506. if( UIUtils.CurrentShaderVersion() < 5003 )
  507. {
  508. int newId = VersionConvertInputPortId( i ) + 1;
  509. if( UIUtils.CurrentShaderVersion() > 23 )
  510. {
  511. m_inputPorts[ newId ].DataType = (WirePortDataType)Enum.Parse( typeof( WirePortDataType ), nodeParams[ m_currentReadParamIdx++ ] );
  512. }
  513. m_inputPorts[ newId ].InternalData = nodeParams[ m_currentReadParamIdx++ ];
  514. if( m_inputPorts[ newId ].IsEditable && UIUtils.CurrentShaderVersion() >= 3100 && m_currentReadParamIdx < nodeParams.Length )
  515. {
  516. m_inputPorts[ newId ].Name = nodeParams[ m_currentReadParamIdx++ ];
  517. }
  518. }
  519. else
  520. {
  521. int portId = Convert.ToInt32( nodeParams[ m_currentReadParamIdx++ ] );
  522. WirePortDataType DataType = (WirePortDataType)Enum.Parse( typeof( WirePortDataType ), nodeParams[ m_currentReadParamIdx++ ] );
  523. string InternalData = nodeParams[ m_currentReadParamIdx++ ];
  524. bool isEditable = Convert.ToBoolean( nodeParams[ m_currentReadParamIdx++ ] );
  525. string Name = string.Empty;
  526. if( isEditable && m_currentReadParamIdx < nodeParams.Length )
  527. {
  528. Name = nodeParams[ m_currentReadParamIdx++ ];
  529. }
  530. InputPort inputPort = GetInputPortByUniqueId( portId );
  531. if( inputPort != null )
  532. {
  533. inputPort.DataType = DataType;
  534. inputPort.InternalData = InternalData;
  535. if( !string.IsNullOrEmpty( Name ) )
  536. {
  537. inputPort.Name = Name;
  538. }
  539. }
  540. }
  541. }
  542. }
  543. }
  544. public override void Destroy()
  545. {
  546. base.Destroy();
  547. m_referenceNode = null;
  548. if( m_texCoordsHelper != null )
  549. {
  550. //Not calling m_texCoordsHelper.Destroy() on purpose so UIUtils does not incorrectly unregister stuff
  551. DestroyImmediate( m_texCoordsHelper );
  552. m_texCoordsHelper = null;
  553. }
  554. }
  555. }
  556. }