Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

637 lines
24 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. #define CUSTOM_OPTIONS_AVAILABLE
  4. using UnityEngine;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text.RegularExpressions;
  8. namespace AmplifyShaderEditor
  9. {
  10. [Serializable]
  11. public class TemplatePass
  12. {
  13. private const string DefaultPassNameStr = "SubShader {0} Pass {1}";
  14. [SerializeField]
  15. private int m_idx = -1;
  16. [SerializeField]
  17. private bool m_isInvisible = false;
  18. [SerializeField]
  19. private int m_invisibleOptions = 0;
  20. [SerializeField]
  21. private bool m_isMainPass = false;
  22. [SerializeField]
  23. private TemplateModulesData m_modules;
  24. [SerializeField]
  25. private List<TemplateInputData> m_inputDataList = new List<TemplateInputData>();
  26. private Dictionary<int, TemplateInputData> m_inputDataDict = new Dictionary<int, TemplateInputData>();
  27. [SerializeField]
  28. private TemplateFunctionData m_vertexFunctionData;
  29. [SerializeField]
  30. private TemplateFunctionData m_fragmentFunctionData;
  31. [SerializeField]
  32. private VertexDataContainer m_vertexDataContainer;
  33. [SerializeField]
  34. private TemplateInterpData m_interpolatorDataContainer;
  35. [SerializeField]
  36. private TemplateTessVControlTag m_tessVControlTag;
  37. [SerializeField]
  38. private TemplateTessControlData m_tessControlData;
  39. [SerializeField]
  40. private TemplateTessDomainData m_tessDomainData;
  41. [SerializeField]
  42. private List<TemplateLocalVarData> m_localVarsList = new List<TemplateLocalVarData>();
  43. [SerializeField]
  44. private string m_uniquePrefix;
  45. [SerializeField]
  46. private TemplatePropertyContainer m_templateProperties = new TemplatePropertyContainer();
  47. [SerializeField]
  48. private List<TemplateShaderPropertyData> m_availableShaderGlobals = new List<TemplateShaderPropertyData>();
  49. [SerializeField]
  50. TemplateInfoContainer m_passNameContainer = new TemplateInfoContainer();
  51. #if CUSTOM_OPTIONS_AVAILABLE
  52. [SerializeField]
  53. TemplateOptionsContainer m_customOptionsContainer = new TemplateOptionsContainer();
  54. #endif
  55. public TemplatePass( TemplateMultiPass template, TemplateSubShader subShader, int subshaderIdx, int passIdx, TemplateIdManager idManager, string uniquePrefix, int offsetIdx, TemplatePassInfo passInfo, ref Dictionary<string, TemplateShaderPropertyData> duplicatesHelper )
  56. {
  57. m_idx = passIdx;
  58. m_uniquePrefix = uniquePrefix;
  59. idManager.RegisterPassId( passInfo.Data );
  60. m_isMainPass = passInfo.Data.Contains( TemplatesManager.TemplateMainPassTag );
  61. if( !m_isMainPass )
  62. {
  63. string id = string.Empty;
  64. int idIndex = 0;
  65. m_isInvisible = TemplateHelperFunctions.FetchInvisibleInfo( passInfo.Data, ref m_invisibleOptions, ref id, ref idIndex );
  66. if( m_isInvisible )
  67. {
  68. idManager.RegisterId( idIndex, uniquePrefix + id, id, true );
  69. }
  70. }
  71. FetchPassName( offsetIdx, passInfo.Data );
  72. if( m_passNameContainer.Index > -1 )
  73. {
  74. idManager.RegisterId( m_passNameContainer.Index, uniquePrefix + m_passNameContainer.Id, m_passNameContainer.Id );
  75. }
  76. else
  77. {
  78. m_passNameContainer.Data = string.Format( DefaultPassNameStr, subshaderIdx, passIdx );
  79. }
  80. #if CUSTOM_OPTIONS_AVAILABLE
  81. m_customOptionsContainer = TemplateOptionsToolsHelper.GenerateOptionsContainer( false, passInfo.Data );
  82. if( m_customOptionsContainer.Enabled )
  83. {
  84. idManager.RegisterId( m_customOptionsContainer.Index, uniquePrefix + m_customOptionsContainer.Body, m_customOptionsContainer.Body, true );
  85. }
  86. //m_customOptionsContainer.CopyPortOptionsFrom( subShader.CustomOptionsContainer, m_passNameContainer.Data );
  87. #endif
  88. m_modules = new TemplateModulesData( m_customOptionsContainer,idManager, m_templateProperties, uniquePrefix + "Module", offsetIdx, passInfo.Data, false );
  89. if( !m_modules.PassTag.IsValid )
  90. {
  91. m_modules.PassTag.StartIdx = passInfo.GlobalStartIdx;
  92. m_templateProperties.AddId( passInfo.Data, m_modules.PassTag.Id, passInfo.LocalStartIdx, false );
  93. //m_modules.PassTag.StartIdx -= m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].Indentation.Length;
  94. //m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].UseIndentationAtStart = false;
  95. idManager.RegisterId( m_modules.PassTag.StartIdx, m_modules.UniquePrefix + m_modules.PassTag.Id, string.Empty );
  96. }
  97. m_modules.SetPassUniqueNameIfUndefined( m_passNameContainer.Data );
  98. m_modules.SRPType = subShader.Modules.SRPType;
  99. if( m_modules.SRPType == TemplateSRPType.HD )
  100. {
  101. m_modules.SRPIsPBR = passInfo.Data.Contains( TemplateHelperFunctions.HDPBRTag );
  102. }
  103. Dictionary<string, TemplateShaderPropertyData> ownDuplicatesDict = new Dictionary<string, TemplateShaderPropertyData>( duplicatesHelper );
  104. TemplateHelperFunctions.CreateShaderGlobalsList( passInfo.Data, ref m_availableShaderGlobals, ref ownDuplicatesDict );
  105. if( m_modules.SRPType == TemplateSRPType.BuiltIn )
  106. {
  107. TemplateHelperFunctions.CheckUnityBuiltinGlobalMacros( passInfo.Data, ref m_availableShaderGlobals, ref ownDuplicatesDict );
  108. }
  109. // Vertex and Interpolator data
  110. FetchVertexAndInterpData( template, subShader.Modules, offsetIdx, passInfo.Data );
  111. if( m_vertexDataContainer != null )
  112. idManager.RegisterId( m_vertexDataContainer.VertexDataStartIdx, uniquePrefix + m_vertexDataContainer.VertexDataId, m_vertexDataContainer.VertexDataId );
  113. if( m_interpolatorDataContainer != null )
  114. idManager.RegisterId( m_interpolatorDataContainer.InterpDataStartIdx, uniquePrefix + m_interpolatorDataContainer.InterpDataId, m_interpolatorDataContainer.InterpDataId );
  115. //Fetch function code areas
  116. FetchCodeAreas( offsetIdx, TemplatesManager.TemplateVertexCodeBeginArea, MasterNodePortCategory.Vertex, passInfo.Data );
  117. if( m_vertexFunctionData != null )
  118. idManager.RegisterId( m_vertexFunctionData.Position, uniquePrefix + m_vertexFunctionData.Id, m_vertexFunctionData.Id );
  119. FetchCodeAreas( offsetIdx, TemplatesManager.TemplateFragmentCodeBeginArea, MasterNodePortCategory.Fragment, passInfo.Data );
  120. if( m_fragmentFunctionData != null )
  121. idManager.RegisterId( m_fragmentFunctionData.Position, uniquePrefix + m_fragmentFunctionData.Id, m_fragmentFunctionData.Id );
  122. //Fetching inputs, must be do
  123. if( m_fragmentFunctionData != null )
  124. FetchInputs( offsetIdx, MasterNodePortCategory.Fragment, passInfo.Data );
  125. if( m_vertexFunctionData != null )
  126. FetchInputs( offsetIdx, MasterNodePortCategory.Vertex, passInfo.Data );
  127. FetchTessellationData( template, subShader.Modules, offsetIdx, passInfo.Data );
  128. if( m_tessVControlTag != null )
  129. idManager.RegisterId( m_tessVControlTag.StartIdx, uniquePrefix + m_tessVControlTag.Id, m_tessVControlTag.Id );
  130. if( m_tessControlData != null )
  131. idManager.RegisterId( m_tessControlData.StartIdx, uniquePrefix + m_tessControlData.Id, m_tessControlData.Id );
  132. if( m_tessDomainData != null )
  133. idManager.RegisterId( m_tessDomainData.StartIdx, uniquePrefix + m_tessDomainData.Id, m_tessDomainData.Id );
  134. TemplateHelperFunctions.FetchInlineVars( passInfo.Data, ref idManager );
  135. //Fetch local variables must be done after fetching code areas as it needs them to see is variable is on vertex or fragment
  136. TemplateHelperFunctions.FetchLocalVars( passInfo.Data, ref m_localVarsList, m_vertexFunctionData, m_fragmentFunctionData );
  137. int localVarCount = m_localVarsList.Count;
  138. if( localVarCount > 0 )
  139. {
  140. idManager.RegisterTag( TemplatesManager.TemplateLocalVarTag );
  141. for( int i = 0; i < localVarCount; i++ )
  142. {
  143. if( m_localVarsList[ i ].IsSpecialVar )
  144. {
  145. idManager.RegisterTag( m_localVarsList[ i ].Id );
  146. }
  147. }
  148. }
  149. int inputsCount = m_inputDataList.Count;
  150. for( int i = 0; i < inputsCount; i++ )
  151. {
  152. if( m_inputDataList[ i ] != null )
  153. idManager.RegisterId( m_inputDataList[ i ].TagGlobalStartIdx, uniquePrefix + m_inputDataList[ i ].TagId, m_inputDataList[ i ].TagId );
  154. }
  155. //int passEndIndex = passInfo.Data.LastIndexOf( "}" );
  156. //if( passEndIndex > 0 )
  157. //{
  158. // int identationIndex = -1;
  159. // for( int i = passEndIndex; i >= 0; i-- )
  160. // {
  161. // if( passInfo.Data[ i ] == TemplatesManager.TemplateNewLine )
  162. // {
  163. // identationIndex = i + 1;
  164. // break;
  165. // }
  166. // if( i == 0 )
  167. // {
  168. // identationIndex = 0;
  169. // }
  170. // }
  171. // if( identationIndex > -1 )
  172. // {
  173. // int length = passEndIndex - identationIndex;
  174. // string indentation = ( length > 0 ) ? passInfo.Data.Substring( identationIndex, length ) : string.Empty;
  175. // TemplateProperty templateProperty = new TemplateProperty( TemplatesManager.TemplateEndPassTag, indentation, false );
  176. // m_templateProperties.AddId( templateProperty );
  177. // idManager.RegisterId( offsetIdx + passEndIndex, uniquePrefix + TemplatesManager.TemplateEndPassTag, string.Empty );
  178. // }
  179. //}
  180. ownDuplicatesDict.Clear();
  181. ownDuplicatesDict = null;
  182. }
  183. public void Destroy()
  184. {
  185. m_passNameContainer = null;
  186. #if CUSTOM_OPTIONS_AVAILABLE
  187. m_customOptionsContainer = null;
  188. #endif
  189. if( m_templateProperties != null )
  190. m_templateProperties.Destroy();
  191. m_templateProperties = null;
  192. if( m_modules != null )
  193. m_modules.Destroy();
  194. m_modules = null;
  195. if( m_inputDataList != null )
  196. m_inputDataList.Clear();
  197. m_inputDataList = null;
  198. if( m_inputDataDict != null )
  199. m_inputDataDict.Clear();
  200. m_inputDataDict = null;
  201. m_vertexFunctionData = null;
  202. m_fragmentFunctionData = null;
  203. if( m_vertexDataContainer != null )
  204. m_vertexDataContainer.Destroy();
  205. m_vertexDataContainer = null;
  206. m_tessVControlTag = null;
  207. m_tessControlData = null;
  208. m_tessDomainData = null;
  209. if( m_interpolatorDataContainer != null )
  210. m_interpolatorDataContainer.Destroy();
  211. if( m_localVarsList != null )
  212. {
  213. m_localVarsList.Clear();
  214. m_localVarsList = null;
  215. }
  216. m_interpolatorDataContainer = null;
  217. if( m_availableShaderGlobals != null )
  218. m_availableShaderGlobals.Clear();
  219. m_availableShaderGlobals = null;
  220. }
  221. public TemplateInputData InputDataFromId( int id )
  222. {
  223. if( m_inputDataDict == null )
  224. m_inputDataDict = new Dictionary<int, TemplateInputData>();
  225. if( m_inputDataDict.Count != m_inputDataList.Count )
  226. {
  227. m_inputDataDict.Clear();
  228. for( int i = 0; i < m_inputDataList.Count; i++ )
  229. {
  230. m_inputDataDict.Add( m_inputDataList[ i ].PortUniqueId, m_inputDataList[ i ] );
  231. }
  232. }
  233. if( m_inputDataDict.ContainsKey( id ) )
  234. return m_inputDataDict[ id ];
  235. return null;
  236. }
  237. void FetchPassName( int offsetIdx, string body )
  238. {
  239. Match match = Regex.Match( body, TemplateHelperFunctions.PassNamePattern );
  240. if( match != null && match.Groups.Count > 1 )
  241. {
  242. m_passNameContainer.Id = match.Groups[ 0 ].Value;
  243. m_passNameContainer.Data = match.Groups[ 1 ].Value;
  244. m_passNameContainer.Index = offsetIdx + match.Index;
  245. }
  246. }
  247. void FetchTessellationData( TemplateMultiPass template, TemplateModulesData subShaderModule, int offsetIdx, string body )
  248. {
  249. // Tessellation VControl Tag
  250. try
  251. {
  252. int vcontrolcodeBegin = body.IndexOf( TemplatesManager.TemplateTessVControlTag );
  253. if( vcontrolcodeBegin > -1 )
  254. {
  255. m_tessVControlTag = new TemplateTessVControlTag();
  256. m_tessVControlTag.Id = TemplatesManager.TemplateTessVControlTag;
  257. m_tessVControlTag.StartIdx = offsetIdx + vcontrolcodeBegin;
  258. m_templateProperties.AddId( body, m_tessVControlTag.Id );
  259. }
  260. }
  261. catch( Exception e )
  262. {
  263. Debug.LogException( e );
  264. }
  265. // Tessellation Control Data
  266. try
  267. {
  268. int controlCodeBegin = body.IndexOf( TemplatesManager.TemplateTessControlCodeArea );
  269. if( controlCodeBegin > -1 )
  270. {
  271. int beginIdx = controlCodeBegin + TemplatesManager.TemplateTessControlCodeArea.Length;
  272. int endIdx = body.IndexOf( TemplatesManager.TemplateEndOfLine, beginIdx );
  273. int length = endIdx - beginIdx;
  274. string parameters = body.Substring( beginIdx, length );
  275. string[] parametersArr = parameters.Split( IOUtils.FIELD_SEPARATOR );
  276. string id = body.Substring( controlCodeBegin, endIdx + TemplatesManager.TemplateEndOfLine.Length - controlCodeBegin );
  277. string inParameters = parametersArr[ 0 ];
  278. string outParameters = ( parametersArr.Length > 1 ) ? parametersArr[ 1 ] : string.Empty;
  279. m_tessControlData = new TemplateTessControlData( offsetIdx + controlCodeBegin, id, inParameters, outParameters );
  280. m_templateProperties.AddId( body, id );
  281. }
  282. }
  283. catch( Exception e )
  284. {
  285. Debug.LogException( e );
  286. }
  287. // Tessellation Domain Data
  288. try
  289. {
  290. int domainCodeBegin = body.IndexOf( TemplatesManager.TemplateTessDomainCodeArea );
  291. if( domainCodeBegin > -1 )
  292. {
  293. int beginIdx = domainCodeBegin + TemplatesManager.TemplateTessDomainCodeArea.Length;
  294. int endIdx = body.IndexOf( TemplatesManager.TemplateEndOfLine, beginIdx );
  295. int length = endIdx - beginIdx;
  296. string parameters = body.Substring( beginIdx, length );
  297. string[] parametersArr = parameters.Split( IOUtils.FIELD_SEPARATOR );
  298. string id = body.Substring( domainCodeBegin, endIdx + TemplatesManager.TemplateEndOfLine.Length - domainCodeBegin );
  299. string inParameters = ( parametersArr.Length > 0 ) ? parametersArr[ 0 ] : string.Empty;
  300. string outParameters = ( parametersArr.Length > 1 ) ? parametersArr[ 1 ] : string.Empty;
  301. string baryParameters = ( parametersArr.Length > 2 ) ? parametersArr[ 2 ] : string.Empty;
  302. m_tessDomainData = new TemplateTessDomainData( offsetIdx + domainCodeBegin, id, inParameters, outParameters, baryParameters );
  303. m_templateProperties.AddId( body, id );
  304. }
  305. }
  306. catch( Exception e )
  307. {
  308. Debug.LogException( e );
  309. }
  310. }
  311. void FetchVertexAndInterpData(TemplateMultiPass template, TemplateModulesData subShaderModule, int offsetIdx, string body )
  312. {
  313. // Vertex Data
  314. try
  315. {
  316. int vertexDataTagBegin = body.IndexOf( TemplatesManager.TemplateVertexDataTag );
  317. if( vertexDataTagBegin > -1 )
  318. {
  319. m_vertexDataContainer = new VertexDataContainer();
  320. m_vertexDataContainer.VertexDataStartIdx = offsetIdx + vertexDataTagBegin;
  321. int vertexDataTagEnd = body.IndexOf( TemplatesManager.TemplateEndOfLine, vertexDataTagBegin );
  322. m_vertexDataContainer.VertexDataId = body.Substring( vertexDataTagBegin, vertexDataTagEnd + TemplatesManager.TemplateEndOfLine.Length - vertexDataTagBegin );
  323. int dataBeginIdx = body.LastIndexOf( '{', vertexDataTagBegin, vertexDataTagBegin );
  324. int dataEndIdx = body.IndexOf( '}', vertexDataTagEnd );
  325. string vertexData = body.Substring( dataBeginIdx + 1, dataEndIdx - dataBeginIdx );
  326. int parametersBegin = vertexDataTagBegin + TemplatesManager.TemplateVertexDataTag.Length;
  327. string parameters = body.Substring( parametersBegin, vertexDataTagEnd - parametersBegin );
  328. m_vertexDataContainer.VertexData = TemplateHelperFunctions.CreateVertexDataList( vertexData, parameters );
  329. m_templateProperties.AddId( body, m_vertexDataContainer.VertexDataId );
  330. }
  331. }
  332. catch( Exception e )
  333. {
  334. Debug.LogException( e );
  335. }
  336. // Available interpolators
  337. try
  338. {
  339. int interpDataBegin = body.IndexOf( TemplatesManager.TemplateInterpolatorBeginTag );
  340. if( interpDataBegin > -1 )
  341. {
  342. int interpDataEnd = body.IndexOf( TemplatesManager.TemplateEndOfLine, interpDataBegin );
  343. string interpDataId = body.Substring( interpDataBegin, interpDataEnd + TemplatesManager.TemplateEndOfLine.Length - interpDataBegin );
  344. int dataBeginIdx = body.LastIndexOf( '{', interpDataBegin, interpDataBegin );
  345. int dataEndIdx = body.IndexOf( '}', interpDataEnd );
  346. string interpData = body.Substring( dataBeginIdx + 1, dataEndIdx - dataBeginIdx );
  347. int interpolatorAmount = TemplateHelperFunctions.AvailableInterpolators[ "2.5" ];
  348. if( m_modules.ShaderModel.IsValid )
  349. {
  350. interpolatorAmount = m_modules.ShaderModel.InterpolatorAmount;
  351. }
  352. else if( subShaderModule.ShaderModel.IsValid )
  353. {
  354. interpolatorAmount = subShaderModule.ShaderModel.InterpolatorAmount;
  355. }
  356. else if( template.GlobalShaderModel.IsValid )
  357. {
  358. interpolatorAmount = template.GlobalShaderModel.InterpolatorAmount;
  359. }
  360. m_interpolatorDataContainer = TemplateHelperFunctions.CreateInterpDataList( interpData, interpDataId, interpolatorAmount );
  361. m_interpolatorDataContainer.InterpDataId = interpDataId;
  362. m_interpolatorDataContainer.InterpDataStartIdx = offsetIdx + interpDataBegin;
  363. m_templateProperties.AddId( body, interpDataId );
  364. }
  365. }
  366. catch( Exception e )
  367. {
  368. Debug.LogException( e );
  369. }
  370. }
  371. void FetchCodeAreas( int offsetIdx, string begin, MasterNodePortCategory category, string body )
  372. {
  373. int areaBeginIndexes = body.IndexOf( begin );
  374. if( areaBeginIndexes > -1 )
  375. {
  376. int beginIdx = areaBeginIndexes + begin.Length;
  377. int endIdx = body.IndexOf( TemplatesManager.TemplateEndOfLine, beginIdx );
  378. int length = endIdx - beginIdx;
  379. string parameters = body.Substring( beginIdx, length );
  380. string[] parametersArr = parameters.Split( IOUtils.FIELD_SEPARATOR );
  381. string id = body.Substring( areaBeginIndexes, endIdx + TemplatesManager.TemplateEndOfLine.Length - areaBeginIndexes );
  382. string inParameters = parametersArr[ 0 ];
  383. string outParameters = ( parametersArr.Length > 1 ) ? parametersArr[ 1 ] : string.Empty;
  384. if( category == MasterNodePortCategory.Fragment )
  385. {
  386. string mainBodyName = string.Empty;
  387. int mainBodyLocalIndex = -1;
  388. Match mainBodyNameMatch = Regex.Match( body, TemplateHelperFunctions.FragmentPragmaPattern );
  389. if( mainBodyNameMatch != null && mainBodyNameMatch.Groups.Count == 2 )
  390. {
  391. mainBodyName = mainBodyNameMatch.Groups[ 1 ].Value;
  392. string pattern = string.Format( TemplateHelperFunctions.FunctionBodyStartPattern, mainBodyName );
  393. Match mainBodyIdMatch = Regex.Match( body, pattern );
  394. if( mainBodyIdMatch != null && mainBodyIdMatch.Groups.Count > 0 )
  395. {
  396. mainBodyLocalIndex = mainBodyIdMatch.Index;
  397. }
  398. }
  399. m_fragmentFunctionData = new TemplateFunctionData( mainBodyLocalIndex, mainBodyName, id, offsetIdx + areaBeginIndexes, inParameters, outParameters, category );
  400. }
  401. else
  402. {
  403. string mainBodyName = string.Empty;
  404. int mainBodyLocalIndex = -1;
  405. Match mainBodyNameMatch = Regex.Match( body, TemplateHelperFunctions.VertexPragmaPattern );
  406. if( mainBodyNameMatch != null && mainBodyNameMatch.Groups.Count == 2 )
  407. {
  408. mainBodyName = mainBodyNameMatch.Groups[ 1 ].Value;
  409. string pattern = string.Format( TemplateHelperFunctions.FunctionBodyStartPattern, mainBodyName );
  410. Match mainBodyIdMatch = Regex.Match( body, pattern );
  411. if( mainBodyIdMatch != null && mainBodyIdMatch.Groups.Count > 0 )
  412. {
  413. mainBodyLocalIndex = mainBodyIdMatch.Index;
  414. }
  415. }
  416. m_vertexFunctionData = new TemplateFunctionData( mainBodyLocalIndex, mainBodyName, id, offsetIdx + areaBeginIndexes, inParameters, outParameters, category );
  417. }
  418. m_templateProperties.AddId( body, id, true );
  419. }
  420. }
  421. void FetchInputs( int offset, MasterNodePortCategory portCategory, string body )
  422. {
  423. string beginTag = ( portCategory == MasterNodePortCategory.Fragment ) ? TemplatesManager.TemplateInputsFragBeginTag : TemplatesManager.TemplateInputsVertBeginTag;
  424. int[] inputBeginIndexes = body.AllIndexesOf( beginTag );
  425. if( inputBeginIndexes != null && inputBeginIndexes.Length > 0 )
  426. {
  427. for( int i = 0; i < inputBeginIndexes.Length; i++ )
  428. {
  429. int inputEndIdx = body.IndexOf( TemplatesManager.TemplateEndSectionTag, inputBeginIndexes[ i ] );
  430. int defaultValueBeginIdx = inputEndIdx + TemplatesManager.TemplateEndSectionTag.Length;
  431. int endLineIdx = body.IndexOf( TemplatesManager.TemplateFullEndTag, defaultValueBeginIdx );
  432. string defaultValue = body.Substring( defaultValueBeginIdx, endLineIdx - defaultValueBeginIdx );
  433. string tagId = body.Substring( inputBeginIndexes[ i ], endLineIdx + TemplatesManager.TemplateFullEndTag.Length - inputBeginIndexes[ i ] );
  434. int beginIndex = inputBeginIndexes[ i ] + beginTag.Length;
  435. int length = inputEndIdx - beginIndex;
  436. string inputData = body.Substring( beginIndex, length );
  437. string[] inputDataArray = inputData.Split( IOUtils.FIELD_SEPARATOR );
  438. if( inputDataArray != null && inputDataArray.Length > 0 )
  439. {
  440. try
  441. {
  442. string portName = inputDataArray[ (int)TemplatePortIds.Name ];
  443. WirePortDataType dataType = (WirePortDataType)Enum.Parse( typeof( WirePortDataType ), inputDataArray[ (int)TemplatePortIds.DataType ].ToUpper() );
  444. if( inputDataArray.Length == 3 )
  445. {
  446. int portOrderId = m_inputDataList.Count;
  447. int portUniqueId = -1;
  448. bool isInt = int.TryParse( inputDataArray[ 2 ], out portUniqueId );
  449. if( isInt )
  450. {
  451. if( portUniqueId < 0 )
  452. portUniqueId = m_inputDataList.Count;
  453. m_inputDataList.Add( new TemplateInputData( inputBeginIndexes[ i ], offset + inputBeginIndexes[ i ], tagId, portName, defaultValue, dataType, portCategory, portUniqueId, portOrderId, string.Empty ) );
  454. m_templateProperties.AddId( body, tagId, false );
  455. }
  456. else
  457. {
  458. portUniqueId = m_inputDataList.Count;
  459. m_inputDataList.Add( new TemplateInputData( inputBeginIndexes[ i ], offset + inputBeginIndexes[ i ], tagId, portName, defaultValue, dataType, portCategory, portUniqueId, portOrderId, inputDataArray[ 2 ] ) );
  460. m_templateProperties.AddId( body, tagId, false );
  461. }
  462. }
  463. else
  464. {
  465. int portUniqueIDArrIdx = (int)TemplatePortIds.UniqueId;
  466. int portUniqueId = ( portUniqueIDArrIdx < inputDataArray.Length ) ? Convert.ToInt32( inputDataArray[ portUniqueIDArrIdx ] ) : -1;
  467. if( portUniqueId < 0 )
  468. portUniqueId = m_inputDataList.Count;
  469. int portOrderArrayIdx = (int)TemplatePortIds.OrderId;
  470. int portOrderId = ( portOrderArrayIdx < inputDataArray.Length ) ? Convert.ToInt32( inputDataArray[ portOrderArrayIdx ] ) : -1;
  471. if( portOrderId < 0 )
  472. portOrderId = m_inputDataList.Count;
  473. int portLinkIdx = (int)TemplatePortIds.Link;
  474. string linkId = ( portLinkIdx < inputDataArray.Length ) ? inputDataArray[ portLinkIdx ] : string.Empty;
  475. m_inputDataList.Add( new TemplateInputData( inputBeginIndexes[ i ], offset + inputBeginIndexes[ i ], tagId, portName, defaultValue, dataType, portCategory, portUniqueId, portOrderId, linkId ) );
  476. m_templateProperties.AddId( body, tagId, false );
  477. }
  478. }
  479. catch( Exception e )
  480. {
  481. Debug.LogException( e );
  482. }
  483. }
  484. }
  485. }
  486. }
  487. #if CUSTOM_OPTIONS_AVAILABLE
  488. public TemplateOptionsContainer CustomOptionsContainer { get { return m_customOptionsContainer; } }
  489. #endif
  490. public TemplateModulesData Modules { get { return m_modules; } }
  491. public List<TemplateInputData> InputDataList { get { return m_inputDataList; } }
  492. public TemplateFunctionData VertexFunctionData { get { return m_vertexFunctionData; } }
  493. public TemplateFunctionData FragmentFunctionData { get { return m_fragmentFunctionData; } }
  494. public VertexDataContainer VertexDataContainer { get { return m_vertexDataContainer; } }
  495. public TemplateInterpData InterpolatorDataContainer { get { return m_interpolatorDataContainer; } }
  496. public TemplateTessVControlTag TessVControlTag { get { return m_tessVControlTag; } }
  497. public TemplateTessControlData TessControlData { get { return m_tessControlData; } }
  498. public TemplateTessDomainData TessDomainData { get { return m_tessDomainData; } }
  499. public string UniquePrefix { get { return m_uniquePrefix; } }
  500. public TemplatePropertyContainer TemplateProperties { get { return m_templateProperties; } }
  501. public List<TemplateShaderPropertyData> AvailableShaderGlobals { get { return m_availableShaderGlobals; } }
  502. public List<TemplateLocalVarData> LocalVarsList { get { return m_localVarsList; } }
  503. public TemplateInfoContainer PassNameContainer { get { return m_passNameContainer; } }
  504. public bool IsMainPass { get { return m_isMainPass; } set { m_isMainPass = value; } }
  505. public bool IsInvisible { get { return m_isInvisible; } }
  506. public int InvisibleOptions { get { return m_invisibleOptions; } }
  507. public int Idx { get { return m_idx; } }
  508. public bool AddToList
  509. {
  510. get
  511. {
  512. if( m_isInvisible )
  513. {
  514. return ( m_inputDataList.Count > 0 );
  515. }
  516. return true;
  517. }
  518. }
  519. public bool HasValidFunctionBody
  520. {
  521. get
  522. {
  523. if( m_fragmentFunctionData != null || m_vertexFunctionData != null )
  524. return true;
  525. return false;
  526. }
  527. }
  528. }
  529. }