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.

3356 lines
117 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. //#define SHOW_TEMPLATE_HELP_BOX
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEditor;
  8. using System.Linq;
  9. namespace AmplifyShaderEditor
  10. {
  11. public enum HDSRPMaterialType
  12. {
  13. SubsurfaceScattering,
  14. Standard,
  15. Specular,
  16. Anisotropy,
  17. Iridescence,
  18. Translucent
  19. }
  20. public enum InvisibilityStatus
  21. {
  22. LockedInvisible,
  23. Invisible,
  24. Visible
  25. }
  26. public enum SetTemplateSource
  27. {
  28. NewShader,
  29. ShaderLoad,
  30. HotCodeReload
  31. };
  32. [Serializable]
  33. [NodeAttributes( "Template Master Node", "Master", "Shader Generated according to template rules", null, KeyCode.None, false )]
  34. public sealed class TemplateMultiPassMasterNode : MasterNode
  35. {
  36. private const double MaxLODEditTimestamp = 1;
  37. private static int PASS_SELECTOR_VERSION = 16200;
  38. private static int PASS_UNIQUE_ID_VERSION = 16204;
  39. private const string LodNameId = "LODName";
  40. private const string LodValueId = "LODValue";
  41. private const string LodSubtitle = "LOD( {0} )";
  42. private const string AdditionalLODsStr = "LODs";
  43. private const string SubTitleFormatterStr = "(SubShader {0} Pass {1})";
  44. private const string NoSubShaderPropertyStr = "No Sub-Shader properties available";
  45. private const string NoPassPropertyStr = "No Pass properties available";
  46. private const string WarningMessage = "Templates is a feature that is still heavily under development and users may experience some problems.\nPlease email support@amplify.pt if any issue occurs.";
  47. private const string OpenTemplateStr = "Edit Template";
  48. private const string ReloadTemplateStr = "Reload Template";
  49. private const string CommonPropertiesStr = "Common Properties ";
  50. private const string SubShaderModuleStr = "SubShader ";
  51. private const string PassModuleStr = "Pass ";
  52. private const string PassNameStr = "Name";
  53. private const string PassNameFormateStr = "Name \"{0}\"";
  54. private const string SubShaderLODValueLabel = "LOD Value";
  55. private const string SubShaderLODNameLabel = "LOD Name";
  56. private bool m_reRegisterTemplateData = false;
  57. private bool m_fireTemplateChange = false;
  58. private bool m_fetchMasterNodeCategory = false;
  59. [SerializeField]
  60. private string m_templateGUID = "4e1801f860093ba4f9eb58a4b556825b";
  61. [SerializeField]
  62. private int m_passIdx = 0;
  63. //[SerializeField]
  64. //private string m_passIdxStr = string.Empty;
  65. [SerializeField]
  66. private bool m_passFoldout = false;
  67. [SerializeField]
  68. private int m_subShaderIdx = 0;
  69. //[SerializeField]
  70. //private string m_subShaderIdxStr = string.Empty;
  71. [SerializeField]
  72. private bool m_subStringFoldout = false;
  73. [SerializeField]
  74. private bool m_lodFoldout = false;
  75. [SerializeField]
  76. private string m_mainLODName = string.Empty;
  77. //[SerializeField]
  78. //private string m_subShaderLODStr;
  79. //[SerializeField]
  80. //private bool m_mainMPMasterNode = false;
  81. [NonSerialized]
  82. private TemplateMultiPass m_templateMultiPass = null;
  83. [NonSerialized]
  84. private TemplateMultiPassMasterNode m_mainMasterNodeRef = null;
  85. [SerializeField]
  86. private TemplateModulesHelper m_subShaderModule = new TemplateModulesHelper();
  87. [SerializeField]
  88. private TemplateModulesHelper m_passModule = new TemplateModulesHelper();
  89. [SerializeField]
  90. private UsePassHelper m_usePass;
  91. [SerializeField]
  92. private string m_passName = string.Empty;
  93. [SerializeField]
  94. private string m_passUniqueId = string.Empty;
  95. [SerializeField]
  96. private string m_originalPassName = string.Empty;
  97. [SerializeField]
  98. private bool m_hasLinkPorts = false;
  99. [SerializeField]
  100. private InvisibilityStatus m_isInvisible = InvisibilityStatus.Visible;
  101. [SerializeField]
  102. private int m_invisibleOptions = 0;
  103. [SerializeField]
  104. private bool m_invalidNode = false;
  105. [SerializeField]
  106. private FallbackPickerHelper m_fallbackHelper = null;
  107. [SerializeField]
  108. private DependenciesHelper m_dependenciesHelper = new DependenciesHelper();
  109. [SerializeField]
  110. private TemplateOptionsUIHelper m_subShaderOptions = new TemplateOptionsUIHelper( true );
  111. [SerializeField]
  112. private TemplateOptionsUIHelper m_passOptions = new TemplateOptionsUIHelper( false );
  113. [SerializeField]
  114. private TemplatePassSelectorHelper m_passSelector = new TemplatePassSelectorHelper();
  115. [SerializeField]
  116. private TemplateOptionsDefinesContainer m_optionsDefineContainer = new TemplateOptionsDefinesContainer();
  117. [SerializeField]
  118. private TerrainDrawInstancedHelper m_drawInstancedHelper = new TerrainDrawInstancedHelper();
  119. // HATE THIS BELOW, MUST REMOVE HD SPECIFIC CODE FROM GENERIC MASTER NODE
  120. private const string HDSRPMaterialTypeStr = "Material Type";
  121. private const string SRPMaterialSubsurfaceScatteringKeyword = "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1";
  122. private const string SRPMaterialTransmissionKeyword = "_MATERIAL_FEATURE_TRANSMISSION 1";
  123. private const string SRPHDMaterialSpecularKeyword = "_MATERIAL_FEATURE_SPECULAR_COLOR 1";
  124. //private const string SRPLWMaterialSpecularKeyword = "_SPECULAR_SETUP 1";
  125. private const string SRPMaterialAnisotropyKeyword = "_MATERIAL_FEATURE_ANISOTROPY 1";
  126. private const string SRPMaterialIridiscenceKeyword = "_MATERIAL_FEATURE_IRIDESCENCE 1";
  127. //private const string SRPMaterialNormalMapKeyword = "_NORMALMAP 1";
  128. //private const string SRPMaterialAlphaTestKeyword = "_ALPHATEST_ON 1";
  129. //private const string SRPMaterialBlendModeAlphaClipThresholdKeyword = "_AlphaClip 1";
  130. private const string SRPMaterialTransparentKeyword = "_SURFACE_TYPE_TRANSPARENT 1";
  131. private const string SRPMaterialBlendModeAddKeyword = "_BLENDMODE_ADD 1";
  132. private const string SRPMaterialBlendModeAlphaKeyword = "_BLENDMODE_ALPHA 1";
  133. private const string SRPMaterialClearCoatKeyword = "_MATERIAL_FEATURE_CLEAR_COAT";
  134. [NonSerialized]
  135. private bool m_fetchPorts = true;
  136. [NonSerialized]
  137. private InputPort m_specularPort;
  138. [NonSerialized]
  139. private InputPort m_metallicPort;
  140. [NonSerialized]
  141. private InputPort m_coatMaskPort;
  142. [NonSerialized]
  143. private InputPort m_diffusionProfilePort;
  144. [NonSerialized]
  145. private InputPort m_subsurfaceMaskPort;
  146. [NonSerialized]
  147. private InputPort m_thicknessPort;
  148. [NonSerialized]
  149. private InputPort m_anisotropyPort;
  150. [NonSerialized]
  151. private InputPort m_iridescenceThicknessPort;
  152. [NonSerialized]
  153. private InputPort m_iridescenceMaskPort;
  154. [NonSerialized]
  155. private InputPort m_indexOfRefractionPort;
  156. [NonSerialized]
  157. private InputPort m_transmittanceColorPort;
  158. [NonSerialized]
  159. private InputPort m_transmittanceAbsorptionDistancePort;
  160. [NonSerialized]
  161. private InputPort m_transmittanceMaskPort;
  162. [SerializeField]
  163. private HDSRPMaterialType m_hdSrpMaterialType = HDSRPMaterialType.Standard;
  164. [NonSerialized]
  165. private bool m_refreshLODValueMasterNodes = false;
  166. [NonSerialized]
  167. private bool m_refocusLODValueMasterNodes = false;
  168. [NonSerialized]
  169. private double m_refreshLODValueMasterNodesTimestamp;
  170. //////////////////////////////////////////////////////////////////////////
  171. protected override void CommonInit( int uniqueId )
  172. {
  173. base.CommonInit( uniqueId );
  174. m_masterNodeCategory = 1;// First Template
  175. m_marginPreviewLeft = 20;
  176. m_shaderNameIsTitle = true;
  177. m_customInspectorName = string.Empty;
  178. m_customPrecision = true;
  179. }
  180. public override void ReleaseResources()
  181. {
  182. // Internal template resources ( for inline properties) are released by first node on the list
  183. // As it's also registered that way
  184. if( IsLODMainFirstPass )
  185. m_containerGraph.ClearInternalTemplateNodes();
  186. if( !IsLODMainMasterNode )
  187. return;
  188. TemplateMultiPass template = ( m_templateMultiPass == null ) ? m_containerGraph.ParentWindow.TemplatesManagerInstance.GetTemplate( m_templateGUID ) as TemplateMultiPass : m_templateMultiPass;
  189. //Maintained the logic of being the main master node to unregister since this method is being called
  190. //over the main master node in multiple places
  191. //but it will unregister with unique of the first master node (pass 0) since it was the one
  192. //to register it
  193. int passUniqueId = ( m_passIdx == 0 ) ? UniqueId : ContainerGraph.MultiPassMasterNodes.NodesList[ 0 ].UniqueId;
  194. if( template != null && template.AvailableShaderProperties != null )
  195. {
  196. // Unregister old template properties
  197. int oldPropertyCount = template.AvailableShaderProperties.Count;
  198. for( int i = 0; i < oldPropertyCount; i++ )
  199. {
  200. UIUtils.ReleaseUniformName( passUniqueId, template.AvailableShaderProperties[ i ].PropertyName );
  201. }
  202. }
  203. }
  204. public void CopyOptionsFrom( TemplateMultiPassMasterNode origin )
  205. {
  206. //Copy options
  207. SubShaderOptions.CopyOptionsValuesFrom( origin.SubShaderOptions );
  208. PassOptions.CopyOptionsValuesFrom( origin.PassOptions );
  209. //Copy selected passes
  210. if( IsMainOutputNode )
  211. m_passSelector.CopyFrom( origin.PassSelector );
  212. }
  213. void RegisterProperties()
  214. {
  215. //First pass must be the one to always register properties so all modules
  216. //can extract a valid negative Id when reading inline properties
  217. if( /*!IsLODMainMasterNode*/!IsLODMainFirstPass )
  218. {
  219. m_reRegisterTemplateData = false;
  220. return;
  221. }
  222. if( m_templateMultiPass != null )
  223. {
  224. m_reRegisterTemplateData = false;
  225. // Register old template properties
  226. int newPropertyCount = m_templateMultiPass.AvailableShaderProperties.Count;
  227. for( int i = 0; i < newPropertyCount; i++ )
  228. {
  229. m_containerGraph.AddInternalTemplateNode( m_templateMultiPass.AvailableShaderProperties[ i ] );
  230. int nodeId = UIUtils.CheckUniformNameOwner( m_templateMultiPass.AvailableShaderProperties[ i ].PropertyName );
  231. if( nodeId > -1 )
  232. {
  233. if( UniqueId != nodeId )
  234. {
  235. ParentNode node = m_containerGraph.GetNode( nodeId );
  236. if( node != null )
  237. {
  238. UIUtils.ShowMessage( string.Format( "Template requires property name {0} which is currently being used by {1}. Please rename it and reload template.", m_templateMultiPass.AvailableShaderProperties[ i ].PropertyName, node.Attributes.Name ) );
  239. }
  240. else
  241. {
  242. UIUtils.ShowMessage( string.Format( "Template requires property name {0} which is currently being on your graph. Please rename it and reload template.", m_templateMultiPass.AvailableShaderProperties[ i ].PropertyName ) );
  243. }
  244. }
  245. }
  246. else
  247. {
  248. UIUtils.RegisterUniformName( UniqueId, m_templateMultiPass.AvailableShaderProperties[ i ].PropertyName );
  249. }
  250. }
  251. }
  252. }
  253. public override void OnEnable()
  254. {
  255. base.OnEnable();
  256. m_reRegisterTemplateData = true;
  257. if( m_usePass == null )
  258. {
  259. m_usePass = ScriptableObject.CreateInstance<UsePassHelper>();
  260. m_usePass.Init( " Additional Use Passes" );
  261. }
  262. if( m_fallbackHelper == null )
  263. {
  264. m_fallbackHelper = ScriptableObject.CreateInstance<FallbackPickerHelper>();
  265. m_fallbackHelper.Init();
  266. }
  267. }
  268. protected override void OnUniqueIDAssigned()
  269. {
  270. base.OnUniqueIDAssigned();
  271. if( UniqueId >= 0 )
  272. {
  273. if( m_lodIndex == -1 )
  274. {
  275. m_containerGraph.MultiPassMasterNodes.AddNode( this );
  276. }
  277. else
  278. {
  279. m_containerGraph.LodMultiPassMasternodes[ m_lodIndex ].AddNode( this );
  280. }
  281. }
  282. }
  283. public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
  284. {
  285. base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
  286. m_passOptions.CheckImediateActionsForPort( this, portId );
  287. }
  288. public override void OnInputPortDisconnected( int portId )
  289. {
  290. base.OnInputPortDisconnected( portId );
  291. m_passOptions.CheckImediateActionsForPort( this, portId );
  292. }
  293. public void ForceTemplateRefresh()
  294. {
  295. SetTemplate( null, false, true, m_subShaderIdx, m_passIdx, SetTemplateSource.HotCodeReload );
  296. }
  297. public void SetTemplate( TemplateMultiPass template, bool writeDefaultData, bool fetchMasterNodeCategory, int subShaderIdx, int passIdx , SetTemplateSource source )
  298. {
  299. if( subShaderIdx > -1 )
  300. m_subShaderIdx = subShaderIdx;
  301. if( passIdx > -1 )
  302. m_passIdx = passIdx;
  303. ReleaseResources();
  304. bool hotCodeOrRead = ( template == null );
  305. m_templateMultiPass = ( hotCodeOrRead ) ? m_containerGraph.ParentWindow.TemplatesManagerInstance.GetTemplate( m_templateGUID ) as TemplateMultiPass : template;
  306. if( m_templateMultiPass != null )
  307. {
  308. string passName = string.IsNullOrEmpty( m_passUniqueId ) ? ( m_isInvisible == InvisibilityStatus.LockedInvisible ? m_passName : m_originalPassName ) : m_passUniqueId;
  309. int newPassIdx = m_passIdx;
  310. int newSubShaderIdx = m_subShaderIdx;
  311. m_templateMultiPass.GetSubShaderandPassFor( passName, ref newSubShaderIdx, ref newPassIdx );
  312. if( newPassIdx == -1 || newSubShaderIdx == -1 )
  313. {
  314. //m_containerGraph.MarkToDelete( this );
  315. ContainerGraph.ParentWindow.SetOutdatedShaderFromTemplate();
  316. m_invalidNode = true;
  317. UIUtils.ShowMessage( "Template changed drastically. Removing invalid passes." );
  318. return;
  319. }
  320. else
  321. {
  322. if( m_passIdx != newPassIdx )
  323. m_passIdx = newPassIdx;
  324. if( m_subShaderIdx != newSubShaderIdx )
  325. m_subShaderIdx = newSubShaderIdx;
  326. }
  327. m_containerGraph.CurrentSRPType = m_templateMultiPass.SRPtype;
  328. if( m_templateMultiPass.IsSinglePass )
  329. {
  330. SetAdditonalTitleText( string.Empty );
  331. }
  332. else if( m_templateMultiPass.SubShaders[ 0 ].MainPass != m_passIdx )
  333. {
  334. SetAdditonalTitleText( string.Format( SubTitleFormatterStr, m_subShaderIdx, m_passIdx ) );
  335. }
  336. m_invalidNode = false;
  337. if( m_subShaderIdx >= m_templateMultiPass.SubShaders.Count ||
  338. m_passIdx >= m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes.Count )
  339. {
  340. if( DebugConsoleWindow.DeveloperMode )
  341. Debug.LogFormat( "Inexisting pass {0}. Cancelling template fetch", m_originalPassName );
  342. return;
  343. }
  344. m_isMainOutputNode = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].IsMainPass;
  345. if( m_isMainOutputNode )
  346. {
  347. // We cannot use UIUtils.MasterNodeOnTexture.height since this method can be
  348. // called before UIUtils is initialized
  349. m_insideSize.y = 55;
  350. }
  351. else
  352. {
  353. m_insideSize.y = 0;
  354. }
  355. //IsMainOutputNode = m_mainMPMasterNode;
  356. if( source != SetTemplateSource.HotCodeReload )
  357. {
  358. //Only set this if no hotcode reload happens ( via new shader or load )
  359. m_isInvisible = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].IsInvisible ? InvisibilityStatus.LockedInvisible : InvisibilityStatus.Visible;
  360. }
  361. else
  362. {
  363. // On hot code reload we only need to verify if template pass visibility data changes
  364. // and change accordingly
  365. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].IsInvisible )
  366. {
  367. if( m_isInvisible != InvisibilityStatus.LockedInvisible )
  368. m_isInvisible = InvisibilityStatus.LockedInvisible;
  369. }
  370. else
  371. {
  372. if( m_isInvisible == InvisibilityStatus.LockedInvisible )
  373. {
  374. m_isInvisible = InvisibilityStatus.Visible;
  375. }
  376. }
  377. }
  378. m_invisibleOptions = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].InvisibleOptions;
  379. m_originalPassName = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].PassNameContainer.Data;
  380. if( !hotCodeOrRead )
  381. {
  382. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].LODContainer.Index > -1 )
  383. {
  384. //m_subShaderLODStr = m_templateMultiPass.SubShaders[ m_subShaderIdx ].LODContainer.Id;
  385. ShaderLOD = Convert.ToInt32( m_templateMultiPass.SubShaders[ m_subShaderIdx ].LODContainer.Data );
  386. }
  387. else
  388. {
  389. ShaderLOD = 0;
  390. }
  391. }
  392. m_shaderNameIsTitle = IsMainOutputNode;
  393. m_fetchMasterNodeCategory = fetchMasterNodeCategory;
  394. m_templateGUID = m_templateMultiPass.GUID;
  395. UpdatePortInfo();
  396. RegisterProperties();
  397. // template is null when hot code reloading or loading from file so inspector name shouldn't be changed
  398. if( !hotCodeOrRead )
  399. {
  400. m_customInspectorName = m_templateMultiPass.CustomInspectorContainer.Data;
  401. if( m_isMainOutputNode )
  402. {
  403. m_passSelector.Clear();
  404. m_passSelector.Setup( m_templateMultiPass.SubShaders[ m_subShaderIdx ] );
  405. }
  406. }
  407. else
  408. {
  409. //Hotcode reload or ReadFromString
  410. // Setup is only made if internal pass array is null
  411. if( m_isMainOutputNode )
  412. {
  413. m_passSelector.Setup( m_templateMultiPass.SubShaders[ m_subShaderIdx ] );
  414. }
  415. }
  416. SetupCustomOptionsFromTemplate( template != null );
  417. if( string.IsNullOrEmpty( m_fallbackHelper.RawFallbackShader ) )
  418. m_fallbackHelper.RawFallbackShader = m_templateMultiPass.FallbackContainer.Data;
  419. //bool updateInfofromTemplate = UpdatePortInfo();
  420. //if( updateInfofromTemplate )
  421. //{
  422. m_subShaderModule.FetchDataFromTemplate( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules );
  423. m_passModule.FetchDataFromTemplate( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules );
  424. //}
  425. //RegisterProperties();
  426. if( writeDefaultData )
  427. {
  428. //ShaderName = m_templateMultiPass.DefaultShaderName;
  429. ShaderName = m_shaderName;
  430. m_passName = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].PassNameContainer.Data;
  431. if( !m_templateMultiPass.IsSinglePass /*&& !m_shaderNameIsTitle*/ )
  432. {
  433. if( m_templateMultiPass.SubShaders[ 0 ].MainPass != m_passIdx )
  434. SetClippedTitle( m_passName );
  435. }
  436. }
  437. UpdateSubShaderPassStr();
  438. if( m_isMainOutputNode )
  439. m_fireTemplateChange = true;
  440. }
  441. else
  442. {
  443. m_invalidNode = true;
  444. }
  445. }
  446. public override void OnRefreshLinkedPortsComplete()
  447. {
  448. if( m_invalidNode )
  449. return;
  450. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBRHD )
  451. ConfigHDPorts();
  452. SetReadOptions();
  453. }
  454. public void SetReadOptions()
  455. {
  456. m_passOptions.SetReadOptions();
  457. if( m_isMainOutputNode )
  458. m_subShaderOptions.SetReadOptions();
  459. }
  460. bool UpdatePortInfo()
  461. {
  462. List<TemplateInputData> inputDataList = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].InputDataList;
  463. int count = inputDataList.Count;
  464. if( count != m_inputPorts.Count )
  465. {
  466. DeleteAllInputConnections( true );
  467. for( int i = 0; i < count; i++ )
  468. {
  469. InputPort port = AddInputPort( inputDataList[ i ].DataType, false, inputDataList[ i ].PortName, inputDataList[ i ].OrderId, inputDataList[ i ].PortCategory, inputDataList[ i ].PortUniqueId );
  470. port.ExternalLinkId = inputDataList[ i ].LinkId;
  471. m_hasLinkPorts = m_hasLinkPorts || !string.IsNullOrEmpty( inputDataList[ i ].LinkId );
  472. }
  473. return true;
  474. }
  475. else
  476. {
  477. for( int i = 0; i < count; i++ )
  478. {
  479. m_inputPorts[ i ].ChangeProperties( inputDataList[ i ].PortName, inputDataList[ i ].DataType, false );
  480. m_inputPorts[ i ].ExternalLinkId = inputDataList[ i ].LinkId;
  481. }
  482. return false;
  483. }
  484. }
  485. public void SetPropertyActionFromItem( TemplateModulesHelper module, TemplateActionItem item )
  486. {
  487. // this was added because when switching templates the m_mainMasterNodeRef was not properly set yet and was causing issues, there's probably a better place for this
  488. if( !m_isMainOutputNode && m_mainMasterNodeRef == null )
  489. {
  490. m_mainMasterNodeRef = m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  491. }
  492. TemplateModulesHelper subShaderModule = m_isMainOutputNode ? m_subShaderModule : m_mainMasterNodeRef.SubShaderModule;
  493. switch( item.PropertyAction )
  494. {
  495. case PropertyActionsEnum.CullMode:
  496. {
  497. if( item.CopyFromSubShader )
  498. {
  499. module.CullModeHelper.CurrentCullMode = subShaderModule.CullModeHelper.CurrentCullMode;
  500. }
  501. else
  502. {
  503. module.CullModeHelper.CurrentCullMode = item.ActionCullMode;
  504. }
  505. }
  506. break;
  507. case PropertyActionsEnum.ColorMask:
  508. {
  509. if( item.CopyFromSubShader )
  510. module.ColorMaskHelper.ColorMask = subShaderModule.ColorMaskHelper.ColorMask;
  511. else
  512. module.ColorMaskHelper.ColorMask = item.ColorMask.GetColorMask( module.ColorMaskHelper.ColorMask );
  513. }
  514. break;
  515. case PropertyActionsEnum.ColorMask1:
  516. {
  517. if( item.CopyFromSubShader )
  518. module.ColorMaskHelper1.ColorMask = subShaderModule.ColorMaskHelper1.ColorMask;
  519. else
  520. module.ColorMaskHelper1.ColorMask = item.ColorMask1.GetColorMask( module.ColorMaskHelper1.ColorMask );
  521. }
  522. break;
  523. case PropertyActionsEnum.ColorMask2:
  524. {
  525. if( item.CopyFromSubShader )
  526. module.ColorMaskHelper2.ColorMask = subShaderModule.ColorMaskHelper2.ColorMask;
  527. else
  528. module.ColorMaskHelper2.ColorMask = item.ColorMask2.GetColorMask( module.ColorMaskHelper2.ColorMask );
  529. }
  530. break;
  531. case PropertyActionsEnum.ColorMask3:
  532. {
  533. if( item.CopyFromSubShader )
  534. module.ColorMaskHelper3.ColorMask = subShaderModule.ColorMaskHelper3.ColorMask;
  535. else
  536. module.ColorMaskHelper3.ColorMask = item.ColorMask3.GetColorMask( module.ColorMaskHelper3.ColorMask );
  537. }
  538. break;
  539. case PropertyActionsEnum.ZWrite:
  540. {
  541. if( item.CopyFromSubShader )
  542. {
  543. module.DepthOphelper.ZWriteModeValue = subShaderModule.DepthOphelper.ZWriteModeValue;
  544. }
  545. else
  546. {
  547. module.DepthOphelper.ZWriteModeValue = item.ActionZWrite;
  548. }
  549. }
  550. break;
  551. case PropertyActionsEnum.ZTest:
  552. {
  553. if( item.CopyFromSubShader )
  554. {
  555. module.DepthOphelper.ZTestModeValue = subShaderModule.DepthOphelper.ZTestModeValue;
  556. }
  557. else
  558. {
  559. module.DepthOphelper.ZTestModeValue = item.ActionZTest;
  560. }
  561. }
  562. break;
  563. case PropertyActionsEnum.ZOffsetFactor:
  564. {
  565. if( item.CopyFromSubShader )
  566. {
  567. module.DepthOphelper.OffsetFactorValue = subShaderModule.DepthOphelper.OffsetFactorValue;
  568. }
  569. else
  570. {
  571. module.DepthOphelper.OffsetFactorValue = item.ActionZOffsetFactor;
  572. }
  573. }
  574. break;
  575. case PropertyActionsEnum.ZOffsetUnits:
  576. {
  577. if( item.CopyFromSubShader )
  578. {
  579. module.DepthOphelper.OffsetUnitsValue = subShaderModule.DepthOphelper.OffsetUnitsValue;
  580. }
  581. else
  582. {
  583. module.DepthOphelper.OffsetUnitsValue = item.ActionZOffsetUnits;
  584. }
  585. }
  586. break;
  587. case PropertyActionsEnum.BlendRGB:
  588. {
  589. if( item.CopyFromSubShader )
  590. {
  591. module.BlendOpHelper.SourceFactorRGB = subShaderModule.BlendOpHelper.SourceFactorRGB;
  592. module.BlendOpHelper.DestFactorRGB = subShaderModule.BlendOpHelper.DestFactorRGB;
  593. }
  594. else
  595. {
  596. module.BlendOpHelper.SourceFactorRGB = item.ActionBlendRGBSource;
  597. module.BlendOpHelper.DestFactorRGB = item.ActionBlendRGBDest;
  598. }
  599. }
  600. break;
  601. case PropertyActionsEnum.BlendRGB1:
  602. {
  603. if( item.CopyFromSubShader )
  604. {
  605. module.BlendOpHelper1.SourceFactorRGB = subShaderModule.BlendOpHelper1.SourceFactorRGB;
  606. module.BlendOpHelper1.DestFactorRGB = subShaderModule.BlendOpHelper1.DestFactorRGB;
  607. }
  608. else
  609. {
  610. module.BlendOpHelper1.SourceFactorRGB = item.ActionBlendRGBSource1;
  611. module.BlendOpHelper1.DestFactorRGB = item.ActionBlendRGBDest1;
  612. }
  613. }
  614. break;
  615. case PropertyActionsEnum.BlendRGB2:
  616. {
  617. if( item.CopyFromSubShader )
  618. {
  619. module.BlendOpHelper2.SourceFactorRGB = subShaderModule.BlendOpHelper2.SourceFactorRGB;
  620. module.BlendOpHelper2.DestFactorRGB = subShaderModule.BlendOpHelper2.DestFactorRGB;
  621. }
  622. else
  623. {
  624. module.BlendOpHelper2.SourceFactorRGB = item.ActionBlendRGBSource2;
  625. module.BlendOpHelper2.DestFactorRGB = item.ActionBlendRGBDest2;
  626. }
  627. }
  628. break;
  629. case PropertyActionsEnum.BlendRGB3:
  630. {
  631. if( item.CopyFromSubShader )
  632. {
  633. module.BlendOpHelper3.SourceFactorRGB = subShaderModule.BlendOpHelper3.SourceFactorRGB;
  634. module.BlendOpHelper3.DestFactorRGB = subShaderModule.BlendOpHelper3.DestFactorRGB;
  635. }
  636. else
  637. {
  638. module.BlendOpHelper3.SourceFactorRGB = item.ActionBlendRGBSource3;
  639. module.BlendOpHelper3.DestFactorRGB = item.ActionBlendRGBDest3;
  640. }
  641. }
  642. break;
  643. case PropertyActionsEnum.BlendAlpha:
  644. {
  645. if( item.CopyFromSubShader )
  646. {
  647. module.BlendOpHelper.SourceFactorAlpha = subShaderModule.BlendOpHelper.SourceFactorAlpha;
  648. module.BlendOpHelper.DestFactorAlpha = subShaderModule.BlendOpHelper.DestFactorAlpha;
  649. }
  650. else
  651. {
  652. module.BlendOpHelper.CurrentAlphaIndex = 1;
  653. module.BlendOpHelper.SourceFactorAlpha = item.ActionBlendAlphaSource;
  654. module.BlendOpHelper.DestFactorAlpha = item.ActionBlendAlphaDest;
  655. }
  656. }
  657. break;
  658. case PropertyActionsEnum.BlendAlpha1:
  659. {
  660. if( item.CopyFromSubShader )
  661. {
  662. module.BlendOpHelper1.SourceFactorAlpha = subShaderModule.BlendOpHelper1.SourceFactorAlpha;
  663. module.BlendOpHelper1.DestFactorAlpha = subShaderModule.BlendOpHelper1.DestFactorAlpha;
  664. }
  665. else
  666. {
  667. module.BlendOpHelper1.CurrentAlphaIndex = 1;
  668. module.BlendOpHelper1.SourceFactorAlpha = item.ActionBlendAlphaSource1;
  669. module.BlendOpHelper1.DestFactorAlpha = item.ActionBlendAlphaDest1;
  670. }
  671. }
  672. break;
  673. case PropertyActionsEnum.BlendAlpha2:
  674. {
  675. if( item.CopyFromSubShader )
  676. {
  677. module.BlendOpHelper2.SourceFactorAlpha = subShaderModule.BlendOpHelper2.SourceFactorAlpha;
  678. module.BlendOpHelper2.DestFactorAlpha = subShaderModule.BlendOpHelper2.DestFactorAlpha;
  679. }
  680. else
  681. {
  682. module.BlendOpHelper2.CurrentAlphaIndex = 1;
  683. module.BlendOpHelper2.SourceFactorAlpha = item.ActionBlendAlphaSource2;
  684. module.BlendOpHelper2.DestFactorAlpha = item.ActionBlendAlphaDest2;
  685. }
  686. }
  687. break;
  688. case PropertyActionsEnum.BlendAlpha3:
  689. {
  690. if( item.CopyFromSubShader )
  691. {
  692. module.BlendOpHelper3.SourceFactorAlpha = subShaderModule.BlendOpHelper3.SourceFactorAlpha;
  693. module.BlendOpHelper3.DestFactorAlpha = subShaderModule.BlendOpHelper3.DestFactorAlpha;
  694. }
  695. else
  696. {
  697. module.BlendOpHelper3.CurrentAlphaIndex = 1;
  698. module.BlendOpHelper3.SourceFactorAlpha = item.ActionBlendAlphaSource3;
  699. module.BlendOpHelper3.DestFactorAlpha = item.ActionBlendAlphaDest3;
  700. }
  701. }
  702. break;
  703. case PropertyActionsEnum.BlendOpRGB:
  704. {
  705. if( item.CopyFromSubShader )
  706. {
  707. module.BlendOpHelper.BlendOpRGB = subShaderModule.BlendOpHelper.BlendOpRGB;
  708. }
  709. else
  710. {
  711. module.BlendOpHelper.BlendOpRGB = item.ActionBlendOpRGB;
  712. }
  713. }
  714. break;
  715. case PropertyActionsEnum.BlendOpAlpha:
  716. {
  717. if( item.CopyFromSubShader )
  718. {
  719. module.BlendOpHelper.BlendOpAlpha = subShaderModule.BlendOpHelper.BlendOpAlpha;
  720. }
  721. else
  722. {
  723. module.BlendOpHelper.BlendOpAlpha = item.ActionBlendOpAlpha;
  724. }
  725. }
  726. break;
  727. case PropertyActionsEnum.StencilReference:
  728. {
  729. if( item.CopyFromSubShader )
  730. {
  731. module.StencilBufferHelper.ReferenceValue = subShaderModule.StencilBufferHelper.ReferenceValue;
  732. }
  733. else
  734. {
  735. module.StencilBufferHelper.ReferenceValue = item.ActionStencilReference;
  736. }
  737. }
  738. break;
  739. case PropertyActionsEnum.StencilReadMask:
  740. {
  741. if( item.CopyFromSubShader )
  742. {
  743. module.StencilBufferHelper.ReadMaskValue = subShaderModule.StencilBufferHelper.ReadMaskValue;
  744. }
  745. else
  746. {
  747. module.StencilBufferHelper.ReadMaskValue = item.ActionStencilReadMask;
  748. }
  749. }
  750. break;
  751. case PropertyActionsEnum.StencilWriteMask:
  752. {
  753. if( item.CopyFromSubShader )
  754. {
  755. module.StencilBufferHelper.WriteMaskValue = subShaderModule.StencilBufferHelper.WriteMaskValue;
  756. }
  757. else
  758. {
  759. module.StencilBufferHelper.WriteMaskValue = item.ActionStencilWriteMask;
  760. }
  761. }
  762. break;
  763. case PropertyActionsEnum.StencilComparison:
  764. {
  765. if( item.CopyFromSubShader )
  766. {
  767. module.StencilBufferHelper.ComparisonFunctionIdxValue = subShaderModule.StencilBufferHelper.ComparisonFunctionIdxValue;
  768. }
  769. else
  770. {
  771. module.StencilBufferHelper.ComparisonFunctionIdxValue = item.ActionStencilComparison;
  772. }
  773. }
  774. break;
  775. case PropertyActionsEnum.StencilPass:
  776. {
  777. if( item.CopyFromSubShader )
  778. {
  779. module.StencilBufferHelper.PassStencilOpIdxValue = subShaderModule.StencilBufferHelper.PassStencilOpIdxValue;
  780. }
  781. else
  782. {
  783. module.StencilBufferHelper.PassStencilOpIdxValue = item.ActionStencilPass;
  784. }
  785. }
  786. break;
  787. case PropertyActionsEnum.StencilFail:
  788. {
  789. if( item.CopyFromSubShader )
  790. {
  791. module.StencilBufferHelper.FailStencilOpIdxValue = subShaderModule.StencilBufferHelper.FailStencilOpIdxValue;
  792. }
  793. else
  794. {
  795. module.StencilBufferHelper.FailStencilOpIdxValue = item.ActionStencilFail;
  796. }
  797. }
  798. break;
  799. case PropertyActionsEnum.StencilZFail:
  800. {
  801. if( item.CopyFromSubShader )
  802. {
  803. module.StencilBufferHelper.ZFailStencilOpIdxValue = subShaderModule.StencilBufferHelper.ZFailStencilOpIdxValue;
  804. }
  805. else
  806. {
  807. module.StencilBufferHelper.ZFailStencilOpIdxValue = item.ActionStencilZFail;
  808. }
  809. }
  810. break;
  811. case PropertyActionsEnum.RenderType:
  812. {
  813. module.TagsHelper.AddSpecialTag( TemplateSpecialTags.RenderType, item );
  814. }
  815. break;
  816. case PropertyActionsEnum.RenderQueue:
  817. {
  818. module.TagsHelper.AddSpecialTag( TemplateSpecialTags.Queue, item );
  819. }
  820. break;
  821. case PropertyActionsEnum.DisableBatching:
  822. {
  823. module.TagsHelper.AddSpecialTag( TemplateSpecialTags.DisableBatching, item );
  824. }
  825. break;
  826. }
  827. }
  828. public void OnCustomPassOptionSelected( bool isRefreshing, bool invertAction, TemplateOptionUIItem uiItem, params TemplateActionItem[] validActions )
  829. {
  830. m_passOptions.OnCustomOptionSelected( isRefreshing, invertAction, this, uiItem, validActions );
  831. }
  832. public void OnCustomSubShaderOptionSelected( bool isRefreshing, bool invertAction, TemplateOptionUIItem uiItem, params TemplateActionItem[] validActions )
  833. {
  834. if( m_isMainOutputNode )
  835. m_subShaderOptions.OnCustomOptionSelected( isRefreshing, invertAction, this, uiItem, validActions );
  836. }
  837. void SetupCustomOptionsFromTemplate( bool newTemplate )
  838. {
  839. m_passOptions.SetupCustomOptionsFromTemplate( this, newTemplate );
  840. if( m_isMainOutputNode )
  841. m_subShaderOptions.SetupCustomOptionsFromTemplate( this, newTemplate );
  842. }
  843. void SetPassCustomOptionsInfo( TemplateMultiPassMasterNode masterNode )
  844. {
  845. TemplateMultiPassMasterNode mainMasterNode = masterNode.IsMainOutputNode ? masterNode : ( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode );
  846. mainMasterNode.SubShaderOptions.SetSubShaderCustomOptionsPortsInfo( masterNode, ref m_currentDataCollector );
  847. masterNode.PassOptions.SetCustomOptionsInfo( masterNode, ref m_currentDataCollector );
  848. }
  849. void RefreshCustomOptionsDict()
  850. {
  851. m_passOptions.RefreshCustomOptionsDict();
  852. if( m_isMainOutputNode )
  853. m_subShaderOptions.RefreshCustomOptionsDict();
  854. }
  855. void SetCategoryIdxFromTemplate()
  856. {
  857. int templateCount = m_containerGraph.ParentWindow.TemplatesManagerInstance.TemplateCount;
  858. for( int i = 0; i < templateCount; i++ )
  859. {
  860. int idx = i + 1;
  861. TemplateMultiPass templateData = m_containerGraph.ParentWindow.TemplatesManagerInstance.GetTemplate( i ) as TemplateMultiPass;
  862. if( templateData != null && m_templateMultiPass != null && m_templateMultiPass.GUID.Equals( templateData.GUID ) )
  863. m_masterNodeCategory = idx;
  864. }
  865. }
  866. public void CheckTemplateChanges()
  867. {
  868. if( m_invalidNode )
  869. return;
  870. if( IsLODMainMasterNode )
  871. {
  872. if( m_containerGraph.MultiPassMasterNodes.Count != m_templateMultiPass.MasterNodesRequired )
  873. {
  874. if( m_availableCategories == null )
  875. RefreshAvailableCategories();
  876. if( DebugConsoleWindow.DeveloperMode )
  877. Debug.Log( "Template Pass amount was changed. Rebuiling master nodes" );
  878. m_containerGraph.ParentWindow.ReplaceMasterNode( m_availableCategories[ m_masterNodeCategory ], true );
  879. }
  880. }
  881. }
  882. public override void OnNodeLogicUpdate( DrawInfo drawInfo )
  883. {
  884. if( m_invalidNode )
  885. {
  886. return;
  887. }
  888. base.OnNodeLogicUpdate( drawInfo );
  889. if( m_templateMultiPass == null )
  890. {
  891. // Hotcode reload has happened
  892. SetTemplate( null, false, true, m_subShaderIdx, m_passIdx , SetTemplateSource.HotCodeReload );
  893. CheckTemplateChanges();
  894. }
  895. if( m_reRegisterTemplateData )
  896. {
  897. RegisterProperties();
  898. }
  899. if( m_fetchMasterNodeCategory )
  900. {
  901. if( m_availableCategories != null )
  902. {
  903. m_fetchMasterNodeCategory = false;
  904. SetCategoryIdxFromTemplate();
  905. }
  906. }
  907. if( m_fireTemplateChange )
  908. {
  909. m_fireTemplateChange = false;
  910. m_containerGraph.FireMasterNodeReplacedEvent();
  911. }
  912. if( m_subShaderModule.HasValidData )
  913. {
  914. m_subShaderModule.OnLogicUpdate( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules );
  915. }
  916. if( m_passModule.HasValidData )
  917. {
  918. m_passModule.OnLogicUpdate( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules );
  919. }
  920. if( !m_isMainOutputNode && m_mainMasterNodeRef == null )
  921. {
  922. m_mainMasterNodeRef = m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  923. }
  924. if( m_refreshLODValueMasterNodes && ( EditorApplication.timeSinceStartup - m_refreshLODValueMasterNodesTimestamp ) > MaxLODEditTimestamp )
  925. {
  926. m_refreshLODValueMasterNodes = false;
  927. m_refocusLODValueMasterNodes = true;
  928. m_containerGraph.SortLODMasterNodes();
  929. }
  930. }
  931. public override void Draw( DrawInfo drawInfo )
  932. {
  933. if( m_isInvisible == InvisibilityStatus.Visible )
  934. {
  935. base.Draw( drawInfo );
  936. }
  937. }
  938. public override void OnNodeLayout( DrawInfo drawInfo )
  939. {
  940. if( m_invalidNode )
  941. {
  942. if( m_isMainOutputNode )
  943. {
  944. UIUtils.ShowMessage( "Invalid current template. Switching to Standard Surface", MessageSeverity.Error );
  945. m_shaderModelIdx = 0;
  946. m_masterNodeCategory = 0;
  947. m_containerGraph.ParentWindow.ReplaceMasterNode( new MasterNodeCategoriesData( AvailableShaderTypes.SurfaceShader, m_shaderName ), false );
  948. }
  949. return;
  950. }
  951. if( m_isInvisible != InvisibilityStatus.Visible )
  952. {
  953. return;
  954. }
  955. if( !IsMainOutputNode )
  956. {
  957. if( !IsInvisible && Docking )
  958. {
  959. m_useSquareNodeTitle = true;
  960. TemplateMultiPassMasterNode master = ContainerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  961. m_position = master.TruePosition;
  962. m_position.height = 32;
  963. int masterIndex = ContainerGraph.MultiPassMasterNodes.NodesList.IndexOf( master );
  964. int index = ContainerGraph.MultiPassMasterNodes.GetNodeRegisterIdx( UniqueId );
  965. if( index > masterIndex )
  966. {
  967. int backTracking = 0;
  968. for( int i = index - 1; i > masterIndex; i-- )
  969. {
  970. if( !ContainerGraph.MultiPassMasterNodes.NodesList[ i ].IsInvisible && ContainerGraph.MultiPassMasterNodes.NodesList[ i ].Docking )
  971. backTracking++;
  972. }
  973. m_position.y = master.TruePosition.yMax + 1 + 33 * ( backTracking );// ContainerGraph.MultiPassMasterNodes.NodesList[ index - 1 ].TruePosition.yMax;
  974. base.OnNodeLayout( drawInfo );
  975. }
  976. else
  977. {
  978. int forwardTracking = 1;
  979. for( int i = index + 1; i < masterIndex; i++ )
  980. {
  981. if( !ContainerGraph.MultiPassMasterNodes.NodesList[ i ].IsInvisible && ContainerGraph.MultiPassMasterNodes.NodesList[ i ].Docking )
  982. forwardTracking++;
  983. }
  984. m_position.y = master.TruePosition.y - 33 * ( forwardTracking );// ContainerGraph.MultiPassMasterNodes.NodesList[ index - 1 ].TruePosition.yMax;
  985. base.OnNodeLayout( drawInfo );
  986. }
  987. }
  988. else
  989. {
  990. m_useSquareNodeTitle = false;
  991. base.OnNodeLayout( drawInfo );
  992. }
  993. }
  994. else
  995. {
  996. base.OnNodeLayout( drawInfo );
  997. }
  998. }
  999. public override void OnNodeRepaint( DrawInfo drawInfo )
  1000. {
  1001. base.OnNodeRepaint( drawInfo );
  1002. if( m_invalidNode )
  1003. return;
  1004. if( m_isInvisible == InvisibilityStatus.Visible )
  1005. {
  1006. if( m_containerGraph.IsInstancedShader )
  1007. {
  1008. DrawInstancedIcon( drawInfo );
  1009. }
  1010. }
  1011. }
  1012. public override void UpdateFromShader( Shader newShader )
  1013. {
  1014. if( m_currentMaterial != null && m_currentMaterial.shader != newShader )
  1015. {
  1016. m_currentMaterial.shader = newShader;
  1017. }
  1018. CurrentShader = newShader;
  1019. }
  1020. public override void UpdateMasterNodeMaterial( Material material )
  1021. {
  1022. m_currentMaterial = material;
  1023. FireMaterialChangedEvt();
  1024. }
  1025. void DrawReloadButton()
  1026. {
  1027. if( GUILayout.Button( ReloadTemplateStr ) && m_templateMultiPass != null )
  1028. {
  1029. m_templateMultiPass.Reload();
  1030. }
  1031. }
  1032. void DrawOpenTemplateButton()
  1033. {
  1034. GUILayout.BeginHorizontal();
  1035. {
  1036. if( GUILayout.Button( OpenTemplateStr ) && m_templateMultiPass != null )
  1037. {
  1038. try
  1039. {
  1040. string pathname = AssetDatabase.GUIDToAssetPath( m_templateMultiPass.GUID );
  1041. if( !string.IsNullOrEmpty( pathname ) )
  1042. {
  1043. Shader selectedTemplate = AssetDatabase.LoadAssetAtPath<Shader>( pathname );
  1044. if( selectedTemplate != null )
  1045. {
  1046. AssetDatabase.OpenAsset( selectedTemplate, 1 );
  1047. }
  1048. }
  1049. }
  1050. catch( Exception e )
  1051. {
  1052. Debug.LogException( e );
  1053. }
  1054. }
  1055. if( GUILayout.Button( "\u25C4", GUILayout.Width( 18 ), GUILayout.Height( 18 ) ) && m_templateMultiPass != null )
  1056. {
  1057. try
  1058. {
  1059. string pathname = AssetDatabase.GUIDToAssetPath( m_templateMultiPass.GUID );
  1060. if( !string.IsNullOrEmpty( pathname ) )
  1061. {
  1062. Shader selectedTemplate = AssetDatabase.LoadAssetAtPath<Shader>( pathname );
  1063. if( selectedTemplate != null )
  1064. {
  1065. Event.current.Use();
  1066. Selection.activeObject = selectedTemplate;
  1067. EditorGUIUtility.PingObject( Selection.activeObject );
  1068. }
  1069. }
  1070. }
  1071. catch( Exception e )
  1072. {
  1073. Debug.LogException( e );
  1074. }
  1075. }
  1076. }
  1077. GUILayout.EndHorizontal();
  1078. }
  1079. public override void DrawProperties()
  1080. {
  1081. base.DrawProperties();
  1082. if( m_invalidNode )
  1083. return;
  1084. NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, CommonPropertiesStr, DrawCommonProperties );
  1085. NodeUtils.DrawPropertyGroup( ref m_subStringFoldout, SubShaderModuleStr, DrawSubShaderProperties );
  1086. NodeUtils.DrawPropertyGroup( ref m_passFoldout, PassModuleStr, DrawPassProperties );
  1087. DrawMaterialInputs( UIUtils.MenuItemToolbarStyle, false );
  1088. if( m_propertyOrderChanged )
  1089. {
  1090. List<TemplateMultiPassMasterNode> mpNodes = UIUtils.CurrentWindow.CurrentGraph.MultiPassMasterNodes.NodesList;
  1091. int count = mpNodes.Count;
  1092. for( int i = 0; i < count; i++ )
  1093. {
  1094. if( mpNodes[ i ].UniqueId != UniqueId )
  1095. {
  1096. mpNodes[ i ].CopyPropertyListFrom( this );
  1097. }
  1098. }
  1099. }
  1100. #if SHOW_TEMPLATE_HELP_BOX
  1101. EditorGUILayout.HelpBox( WarningMessage, MessageType.Warning );
  1102. #endif
  1103. }
  1104. // this will be removed later when PBR options are created
  1105. void SetExtraDefine( string define )
  1106. {
  1107. List<TemplateMultiPassMasterNode> nodes = this.ContainerGraph.MultiPassMasterNodes.NodesList;
  1108. int count = nodes.Count;
  1109. for( int nodeIdx = 0; nodeIdx < count; nodeIdx++ )
  1110. {
  1111. nodes[ nodeIdx ].OptionsDefineContainer.AddDefine( "#define " + define, false );
  1112. }
  1113. }
  1114. void AddHDKeywords()
  1115. {
  1116. if( m_templateMultiPass.CustomTemplatePropertyUI == CustomTemplatePropertyUIEnum.None )
  1117. return;
  1118. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType != TemplateSRPType.HD ||
  1119. !m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBR )
  1120. return;
  1121. switch( m_hdSrpMaterialType )
  1122. {
  1123. case HDSRPMaterialType.SubsurfaceScattering:
  1124. {
  1125. SetExtraDefine( SRPMaterialSubsurfaceScatteringKeyword );
  1126. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialSubsurfaceScatteringKeyword );
  1127. if( m_thicknessPort != null && m_thicknessPort.HasOwnOrLinkConnection )
  1128. {
  1129. SetExtraDefine( SRPMaterialTransmissionKeyword );
  1130. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialTransmissionKeyword );
  1131. }
  1132. }
  1133. break;
  1134. case HDSRPMaterialType.Standard:
  1135. break;
  1136. case HDSRPMaterialType.Specular:
  1137. {
  1138. SetExtraDefine( SRPHDMaterialSpecularKeyword );
  1139. //m_currentDataCollector.AddToDefines( UniqueId, SRPHDMaterialSpecularKeyword );
  1140. }
  1141. break;
  1142. case HDSRPMaterialType.Anisotropy:
  1143. {
  1144. SetExtraDefine( SRPMaterialAnisotropyKeyword );
  1145. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialAnisotropyKeyword );
  1146. }
  1147. break;
  1148. case HDSRPMaterialType.Iridescence:
  1149. {
  1150. SetExtraDefine( SRPMaterialIridiscenceKeyword );
  1151. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialIridiscenceKeyword );
  1152. }
  1153. break;
  1154. case HDSRPMaterialType.Translucent:
  1155. {
  1156. SetExtraDefine( SRPMaterialTransmissionKeyword );
  1157. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialTransmissionKeyword );
  1158. }
  1159. break;
  1160. }
  1161. if( m_coatMaskPort != null && m_coatMaskPort.HasOwnOrLinkConnection )
  1162. {
  1163. SetExtraDefine( SRPMaterialClearCoatKeyword );
  1164. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialClearCoatKeyword );
  1165. }
  1166. }
  1167. void FetchHDPorts()
  1168. {
  1169. if( m_fetchPorts )
  1170. {
  1171. m_fetchPorts = false;
  1172. if( m_inputPorts.Count > 4 )
  1173. {
  1174. m_specularPort = GetInputPortByUniqueId( 3 );
  1175. m_metallicPort = GetInputPortByUniqueId( 4 );
  1176. m_coatMaskPort = GetInputPortByUniqueId( 11 );
  1177. m_diffusionProfilePort = GetInputPortByUniqueId( 12 );
  1178. m_subsurfaceMaskPort = GetInputPortByUniqueId( 13 );
  1179. m_thicknessPort = GetInputPortByUniqueId( 14 );
  1180. m_anisotropyPort = GetInputPortByUniqueId( 15 );
  1181. m_iridescenceThicknessPort = GetInputPortByUniqueId( 16 );
  1182. m_iridescenceMaskPort = GetInputPortByUniqueId( 17 );
  1183. m_indexOfRefractionPort = GetInputPortByUniqueId( 18 );
  1184. m_transmittanceColorPort = GetInputPortByUniqueId( 19 );
  1185. m_transmittanceAbsorptionDistancePort = GetInputPortByUniqueId( 20 );
  1186. m_transmittanceMaskPort = GetInputPortByUniqueId( 21 );
  1187. }
  1188. }
  1189. }
  1190. void ConfigHDPorts()
  1191. {
  1192. if( m_templateMultiPass.CustomTemplatePropertyUI == CustomTemplatePropertyUIEnum.None )
  1193. return;
  1194. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType != TemplateSRPType.HD ||
  1195. !m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBR )
  1196. return;
  1197. FetchHDPorts();
  1198. if( m_inputPorts.Count > 4 )
  1199. {
  1200. switch( m_hdSrpMaterialType )
  1201. {
  1202. case HDSRPMaterialType.SubsurfaceScattering:
  1203. {
  1204. m_specularPort.Visible = false;
  1205. m_metallicPort.Visible = false;
  1206. m_coatMaskPort.Visible = true;
  1207. m_diffusionProfilePort.Visible = true;
  1208. m_subsurfaceMaskPort.Visible = true;
  1209. m_thicknessPort.Visible = true;
  1210. m_anisotropyPort.Visible = false;
  1211. m_iridescenceThicknessPort.Visible = false;
  1212. m_iridescenceMaskPort.Visible = false;
  1213. m_indexOfRefractionPort.Visible = false;
  1214. m_transmittanceColorPort.Visible = false;
  1215. m_transmittanceAbsorptionDistancePort.Visible = false;
  1216. m_transmittanceMaskPort.Visible = false;
  1217. }
  1218. break;
  1219. case HDSRPMaterialType.Standard:
  1220. {
  1221. m_specularPort.Visible = false;
  1222. m_metallicPort.Visible = true;
  1223. m_coatMaskPort.Visible = true;
  1224. m_diffusionProfilePort.Visible = false;
  1225. m_subsurfaceMaskPort.Visible = false;
  1226. m_thicknessPort.Visible = false;
  1227. m_anisotropyPort.Visible = false;
  1228. m_iridescenceThicknessPort.Visible = false;
  1229. m_iridescenceMaskPort.Visible = false;
  1230. m_indexOfRefractionPort.Visible = false;
  1231. m_transmittanceColorPort.Visible = false;
  1232. m_transmittanceAbsorptionDistancePort.Visible = false;
  1233. m_transmittanceMaskPort.Visible = false;
  1234. }
  1235. break;
  1236. case HDSRPMaterialType.Specular:
  1237. {
  1238. m_specularPort.Visible = true;
  1239. m_metallicPort.Visible = false;
  1240. m_coatMaskPort.Visible = true;
  1241. m_diffusionProfilePort.Visible = false;
  1242. m_subsurfaceMaskPort.Visible = false;
  1243. m_thicknessPort.Visible = false;
  1244. m_anisotropyPort.Visible = false;
  1245. m_iridescenceThicknessPort.Visible = false;
  1246. m_iridescenceMaskPort.Visible = false;
  1247. m_indexOfRefractionPort.Visible = false;
  1248. m_transmittanceColorPort.Visible = false;
  1249. m_transmittanceAbsorptionDistancePort.Visible = false;
  1250. m_transmittanceMaskPort.Visible = false;
  1251. }
  1252. break;
  1253. case HDSRPMaterialType.Anisotropy:
  1254. {
  1255. m_specularPort.Visible = false;
  1256. m_metallicPort.Visible = true;
  1257. m_coatMaskPort.Visible = true;
  1258. m_diffusionProfilePort.Visible = false;
  1259. m_subsurfaceMaskPort.Visible = false;
  1260. m_thicknessPort.Visible = false;
  1261. m_anisotropyPort.Visible = true;
  1262. m_iridescenceThicknessPort.Visible = false;
  1263. m_iridescenceMaskPort.Visible = false;
  1264. m_indexOfRefractionPort.Visible = false;
  1265. m_transmittanceColorPort.Visible = false;
  1266. m_transmittanceAbsorptionDistancePort.Visible = false;
  1267. m_transmittanceMaskPort.Visible = false;
  1268. }
  1269. break;
  1270. case HDSRPMaterialType.Iridescence:
  1271. {
  1272. m_specularPort.Visible = false;
  1273. m_metallicPort.Visible = true;
  1274. m_coatMaskPort.Visible = true;
  1275. m_diffusionProfilePort.Visible = false;
  1276. m_subsurfaceMaskPort.Visible = false;
  1277. m_thicknessPort.Visible = false;
  1278. m_anisotropyPort.Visible = false;
  1279. m_iridescenceThicknessPort.Visible = true;
  1280. m_iridescenceMaskPort.Visible = true;
  1281. m_indexOfRefractionPort.Visible = false;
  1282. m_transmittanceColorPort.Visible = false;
  1283. m_transmittanceAbsorptionDistancePort.Visible = false;
  1284. m_transmittanceMaskPort.Visible = false;
  1285. }
  1286. break;
  1287. case HDSRPMaterialType.Translucent:
  1288. {
  1289. m_specularPort.Visible = false;
  1290. m_metallicPort.Visible = false;
  1291. m_coatMaskPort.Visible = false;
  1292. m_diffusionProfilePort.Visible = true;
  1293. m_subsurfaceMaskPort.Visible = false;
  1294. m_thicknessPort.Visible = true;
  1295. m_anisotropyPort.Visible = false;
  1296. m_iridescenceThicknessPort.Visible = false;
  1297. m_iridescenceMaskPort.Visible = false;
  1298. m_indexOfRefractionPort.Visible = false;
  1299. m_transmittanceColorPort.Visible = false;
  1300. m_transmittanceAbsorptionDistancePort.Visible = false;
  1301. m_transmittanceMaskPort.Visible = false;
  1302. }
  1303. break;
  1304. }
  1305. }
  1306. m_sizeIsDirty = ( m_isInvisible == InvisibilityStatus.Visible );
  1307. }
  1308. public void SetShaderLODValueAndLabel( int value )
  1309. {
  1310. if( ShaderLOD != value )
  1311. ShaderLOD = value;
  1312. if( ContainerGraph.HasLODs )
  1313. {
  1314. SetClippedAdditionalTitle( string.Format( LodSubtitle, ShaderLOD ) );
  1315. }
  1316. else
  1317. {
  1318. SetAdditonalTitleText( string.Empty );
  1319. }
  1320. }
  1321. void DrawLODAddRemoveButtons()
  1322. {
  1323. DrawLODAddRemoveButtons( -2 , true );
  1324. }
  1325. void DrawLODAddRemoveButtons( int index , bool showRemove )
  1326. {
  1327. if( GUILayoutButton( string.Empty, UIUtils.PlusStyle, GUILayout.Width( 15 ) ) )
  1328. {
  1329. Vector2 minPos = Vec2Position;
  1330. //bool newNodePositionMode = false;
  1331. //if( newNodePositionMode )
  1332. //{
  1333. // for( int lod = 0; lod < ContainerGraph.LodMultiPassMasternodes.Count; lod++ )
  1334. // {
  1335. // if( ContainerGraph.LodMultiPassMasternodes[ lod ].Count != 0 )
  1336. // {
  1337. // Vector2 currPos = ContainerGraph.LodMultiPassMasternodes[ lod ].NodesList[ m_passIdx ].Vec2Position;
  1338. // if( currPos.y > minPos.y )
  1339. // {
  1340. // minPos = currPos;
  1341. // }
  1342. // }
  1343. // else
  1344. // {
  1345. // if( index < 0 )
  1346. // {
  1347. // index = lod;
  1348. // }
  1349. // break;
  1350. // }
  1351. // }
  1352. //}
  1353. //else
  1354. //{
  1355. for( int lod = ContainerGraph.LodMultiPassMasternodes.Count - 1 ; lod >= 0; lod-- )
  1356. {
  1357. if( ContainerGraph.LodMultiPassMasternodes[ lod ].Count != 0 )
  1358. {
  1359. minPos = ContainerGraph.LodMultiPassMasternodes[ lod ].NodesList[ m_passIdx ].Vec2Position;
  1360. break;
  1361. }
  1362. }
  1363. //}
  1364. minPos.y += HeightEstimate + 10;
  1365. ContainerGraph.CreateLodMasterNodes( m_templateMultiPass, index, minPos );
  1366. }
  1367. if( showRemove && GUILayoutButton( string.Empty, UIUtils.MinusStyle, GUILayout.Width( 15 ) ) )
  1368. {
  1369. ContainerGraph.DestroyLodMasterNodes( index );
  1370. }
  1371. }
  1372. void SetupLODNodeName()
  1373. {
  1374. if( IsMainOutputNode )
  1375. {
  1376. if( string.IsNullOrEmpty( m_mainLODName ) )
  1377. {
  1378. m_shaderNameIsTitle = true;
  1379. m_content.text = GenerateClippedTitle( m_croppedShaderName );
  1380. }
  1381. else
  1382. {
  1383. m_shaderNameIsTitle = false;
  1384. m_content.text = GenerateClippedTitle( m_mainLODName );
  1385. }
  1386. }
  1387. else
  1388. {
  1389. m_shaderNameIsTitle = false;
  1390. m_content.text = GenerateClippedTitle( m_passName );
  1391. }
  1392. }
  1393. public void DrawLodRowItem(bool listMode)
  1394. {
  1395. float labelWidthBuffer = EditorGUIUtility.labelWidth;
  1396. EditorGUILayout.BeginHorizontal();
  1397. if( listMode )
  1398. {
  1399. if( GUILayout.Button( "\u25b6", GUILayout.Width( 18 ), GUILayout.Height( 18 ) ) )
  1400. {
  1401. m_containerGraph.ParentWindow.FocusOnNode( this, 1, false, true );
  1402. }
  1403. EditorGUI.BeginChangeCheck();
  1404. GUI.SetNextControlName( LodValueId + m_lodIndex );
  1405. m_shaderLOD = EditorGUILayoutIntField( string.Empty, m_shaderLOD, GUILayout.Width( 50 ) );
  1406. }
  1407. else
  1408. {
  1409. EditorGUI.BeginChangeCheck();
  1410. EditorGUIUtility.labelWidth = 45;
  1411. GUI.SetNextControlName( LodValueId + m_lodIndex );
  1412. m_shaderLOD = EditorGUILayoutIntField( "LOD", ShaderLOD, GUILayout.Width(100));
  1413. EditorGUIUtility.labelWidth = labelWidthBuffer;
  1414. }
  1415. if( EditorGUI.EndChangeCheck() )
  1416. {
  1417. m_refreshLODValueMasterNodes = true;
  1418. m_refreshLODValueMasterNodesTimestamp = EditorApplication.timeSinceStartup;
  1419. if( ContainerGraph.HasLODs )
  1420. SetClippedAdditionalTitle( string.Format( LodSubtitle, ShaderLOD ) );
  1421. }
  1422. EditorGUI.BeginChangeCheck();
  1423. GUI.SetNextControlName( LodNameId + ShaderLOD );
  1424. if( listMode )
  1425. {
  1426. m_mainLODName = EditorGUILayoutTextField( string.Empty, m_mainLODName, GUILayout.Width( 100 ) );
  1427. }
  1428. else
  1429. {
  1430. GUILayout.Space( -15 );
  1431. EditorGUIUtility.labelWidth = 45;
  1432. m_mainLODName = EditorGUILayoutTextField( string.Empty, m_mainLODName );
  1433. EditorGUIUtility.labelWidth = labelWidthBuffer;
  1434. }
  1435. if( EditorGUI.EndChangeCheck() )
  1436. {
  1437. // If reorder is scheduled make sure it doesn't happen when editing LOD name
  1438. if( m_refreshLODValueMasterNodes )
  1439. m_refreshLODValueMasterNodesTimestamp = EditorApplication.timeSinceStartup;
  1440. SetupLODNodeName();
  1441. }
  1442. if( listMode )
  1443. DrawLODAddRemoveButtons( m_lodIndex, ( m_lodIndex >= 0) );
  1444. EditorGUILayout.EndHorizontal();
  1445. if( m_refocusLODValueMasterNodes )
  1446. {
  1447. m_refocusLODValueMasterNodes = false;
  1448. string focusedControl = GUI.GetNameOfFocusedControl();
  1449. if( focusedControl.Contains( LodValueId ) )
  1450. {
  1451. GUI.FocusControl( LodValueId + m_lodIndex );
  1452. TextEditor te = (TextEditor)GUIUtility.GetStateObject( typeof( TextEditor ), GUIUtility.keyboardControl );
  1453. if( te != null )
  1454. {
  1455. te.SelectTextEnd();
  1456. }
  1457. }
  1458. else if( focusedControl.Contains( LodNameId ) )
  1459. {
  1460. GUI.FocusControl( LodNameId + m_lodIndex );
  1461. TextEditor te = (TextEditor)GUIUtility.GetStateObject( typeof( TextEditor ), GUIUtility.keyboardControl );
  1462. if( te != null )
  1463. {
  1464. te.SelectTextEnd();
  1465. }
  1466. }
  1467. }
  1468. }
  1469. void DrawLOD()
  1470. {
  1471. if( m_templateMultiPass.CanAddLODs && m_lodIndex == -1 )
  1472. {
  1473. EditorGUILayout.Space();
  1474. DrawLodRowItem(true);
  1475. EditorGUILayout.Space();
  1476. for( int i = 0; i < ContainerGraph.LodMultiPassMasternodes.Count; i++ )
  1477. {
  1478. if( ContainerGraph.LodMultiPassMasternodes[ i ].NodesList.Count > 0 )
  1479. {
  1480. TemplateMultiPassMasterNode masterNode = m_containerGraph.LodMultiPassMasternodes[ i ].NodesList[ m_passIdx ];
  1481. masterNode.DrawLodRowItem( true );
  1482. EditorGUILayout.Space();
  1483. }
  1484. }
  1485. EditorGUILayout.Space();
  1486. }
  1487. }
  1488. void DrawCommonProperties()
  1489. {
  1490. if( m_isMainOutputNode )
  1491. {
  1492. //if( m_templateMultiPass.CanAddLODs && m_lodIndex == -1 )
  1493. //{
  1494. // if( GUILayoutButton( string.Empty, UIUtils.PlusStyle, GUILayout.Width( 15 ) ) )
  1495. // {
  1496. // ContainerGraph.CreateLodMasterNodes( m_templateMultiPass, Vec2Position );
  1497. // }
  1498. // if( GUILayoutButton( string.Empty, UIUtils.MinusStyle, GUILayout.Width( 15 ) ) )
  1499. // {
  1500. // ContainerGraph.DestroyLodMasterNodes();
  1501. // }
  1502. //}
  1503. //EditorGUILayout.LabelField( "LOD: " + m_lodIndex );
  1504. DrawShaderName();
  1505. DrawCurrentShaderType();
  1506. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBRHD )
  1507. {
  1508. if( m_templateMultiPass.CustomTemplatePropertyUI == CustomTemplatePropertyUIEnum.HDPBR )
  1509. {
  1510. EditorGUI.BeginChangeCheck();
  1511. CurrentHDMaterialType = (HDSRPMaterialType)EditorGUILayoutEnumPopup( HDSRPMaterialTypeStr, m_hdSrpMaterialType );
  1512. if( EditorGUI.EndChangeCheck() )
  1513. ConfigHDPorts();
  1514. }
  1515. }
  1516. EditorGUI.BeginChangeCheck();
  1517. DrawPrecisionProperty( false );
  1518. if( EditorGUI.EndChangeCheck() )
  1519. ContainerGraph.CurrentPrecision = m_currentPrecisionType;
  1520. DrawSamplingMacros();
  1521. m_drawInstancedHelper.Draw( this );
  1522. m_fallbackHelper.Draw( this );
  1523. DrawCustomInspector( m_templateMultiPass.SRPtype != TemplateSRPType.BuiltIn );
  1524. m_subShaderOptions.DrawCustomOptions( this );
  1525. m_dependenciesHelper.Draw( this, true );
  1526. }
  1527. //EditorGUILayout.LabelField( m_subShaderIdxStr );
  1528. //EditorGUILayout.LabelField( m_passIdxStr );
  1529. if( IsLODMainMasterNode && m_templateMultiPass.CanAddLODs )
  1530. {
  1531. NodeUtils.DrawNestedPropertyGroup( ref m_lodFoldout, AdditionalLODsStr, DrawLOD, DrawLODAddRemoveButtons );
  1532. }
  1533. DrawOpenTemplateButton();
  1534. if( DebugConsoleWindow.DeveloperMode )
  1535. DrawReloadButton();
  1536. }
  1537. public void DrawSubShaderProperties()
  1538. {
  1539. if( !m_isMainOutputNode )
  1540. {
  1541. m_mainMasterNodeRef.DrawSubShaderProperties();
  1542. return;
  1543. }
  1544. bool noValidData = true;
  1545. if( ShaderLOD > 0 )
  1546. {
  1547. noValidData = false;
  1548. if( m_templateMultiPass.CanAddLODs && m_containerGraph.LodMultiPassMasternodes[0].Count > 0 )
  1549. {
  1550. DrawLodRowItem( false );
  1551. }
  1552. else
  1553. {
  1554. ShaderLOD = EditorGUILayoutIntField( SubShaderLODValueLabel, ShaderLOD );
  1555. }
  1556. }
  1557. if( m_subShaderModule.HasValidData )
  1558. {
  1559. noValidData = false;
  1560. m_subShaderModule.Draw( this, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules );
  1561. //if( m_subShaderModule.IsDirty )
  1562. //{
  1563. // List<TemplateMultiPassMasterNode> mpNodes = UIUtils.CurrentWindow.CurrentGraph.MultiPassMasterNodes.NodesList;
  1564. // int count = mpNodes.Count;
  1565. // for( int i = 0; i < count; i++ )
  1566. // {
  1567. // if( mpNodes[ i ].SubShaderIdx == m_subShaderIdx && mpNodes[ i ].UniqueId != UniqueId )
  1568. // {
  1569. // mpNodes[ i ].SubShaderModule.CopyFrom( m_subShaderModule );
  1570. // }
  1571. // }
  1572. // m_subShaderModule.IsDirty = false;
  1573. //}
  1574. }
  1575. m_passSelector.Draw( this );
  1576. if( noValidData )
  1577. {
  1578. EditorGUILayout.HelpBox( NoSubShaderPropertyStr, MessageType.Info );
  1579. }
  1580. }
  1581. void DrawPassProperties()
  1582. {
  1583. EditorGUI.BeginChangeCheck();
  1584. m_passName = EditorGUILayoutTextField( PassNameStr, m_passName );
  1585. if( EditorGUI.EndChangeCheck() )
  1586. {
  1587. if( m_passName.Length > 0 )
  1588. {
  1589. m_passName = UIUtils.RemoveShaderInvalidCharacters( m_passName );
  1590. }
  1591. else
  1592. {
  1593. m_passName = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].PassNameContainer.Data;
  1594. }
  1595. //if( !m_templateMultiPass.IsSinglePass )
  1596. // SetClippedTitle( m_passName );
  1597. }
  1598. EditorGUILayout.LabelField( Pass.Modules.PassUniqueName );
  1599. if( m_passModule.HasValidData )
  1600. {
  1601. m_passModule.Draw( this, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules, m_subShaderModule );
  1602. }
  1603. m_usePass.Draw( this, false );
  1604. m_passOptions.DrawCustomOptions( this );
  1605. }
  1606. bool CreateInstructionsForList( TemplateData templateData, ref List<InputPort> ports, ref string shaderBody, ref List<string> vertexInstructions, ref List<string> fragmentInstructions )
  1607. {
  1608. if( ports.Count == 0 )
  1609. return true;
  1610. AddHDKeywords();
  1611. bool isValid = true;
  1612. //UIUtils.CurrentWindow.CurrentGraph.ResetNodesLocalVariables();
  1613. for( int i = 0; i < ports.Count; i++ )
  1614. {
  1615. TemplateInputData inputData = templateData.InputDataFromId( ports[ i ].PortId );
  1616. if( ports[ i ].HasOwnOrLinkConnection )
  1617. {
  1618. //if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType == TemplateSRPType.Lightweight )
  1619. //{
  1620. // if( ports[ i ].Name.Contains( "Normal" ) )
  1621. // {
  1622. // m_currentDataCollector.AddToDirectives( SRPMaterialNormalMapKeyword, -1, AdditionalLineType.Define );
  1623. // }
  1624. // if( ports[ i ].Name.Contains( "Alpha Clip Threshold" ) )
  1625. // {
  1626. // m_currentDataCollector.AddToDirectives( SRPMaterialBlendModeAlphaClipThresholdKeyword, -1, AdditionalLineType.Define );
  1627. // }
  1628. // if( ports[ i ].Name.Contains( "Specular" ) )
  1629. // {
  1630. // m_currentDataCollector.AddToDirectives( SRPLWMaterialSpecularKeyword, -1, AdditionalLineType.Define );
  1631. // }
  1632. //}
  1633. //else if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType == TemplateSRPType.HD )
  1634. //{
  1635. // if( ports[ i ].Name.Contains( "Normal" ) )
  1636. // {
  1637. // //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialNormalMapKeyword );
  1638. // }
  1639. // if( ports[ i ].Name.Contains( "Alpha Clip Threshold" ) )
  1640. // {
  1641. // //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialAlphaTestKeyword );
  1642. // }
  1643. //}
  1644. m_currentDataCollector.ResetInstructions();
  1645. m_currentDataCollector.ResetVertexInstructions();
  1646. m_currentDataCollector.PortCategory = ports[ i ].Category;
  1647. string newPortInstruction = ports[ i ].GeneratePortInstructions( ref m_currentDataCollector );
  1648. if( m_currentDataCollector.DirtySpecialLocalVariables )
  1649. {
  1650. string cleanVariables = m_currentDataCollector.SpecialLocalVariables.Replace( "\t", string.Empty );
  1651. m_currentDataCollector.AddInstructions( cleanVariables, false );
  1652. m_currentDataCollector.ClearSpecialLocalVariables();
  1653. }
  1654. if( m_currentDataCollector.DirtyVertexVariables )
  1655. {
  1656. string cleanVariables = m_currentDataCollector.VertexLocalVariables.Replace( "\t", string.Empty );
  1657. m_currentDataCollector.AddVertexInstruction( cleanVariables, UniqueId, false );
  1658. m_currentDataCollector.ClearVertexLocalVariables();
  1659. }
  1660. // fill functions
  1661. for( int j = 0; j < m_currentDataCollector.InstructionsList.Count; j++ )
  1662. {
  1663. fragmentInstructions.Add( m_currentDataCollector.InstructionsList[ j ].PropertyName );
  1664. }
  1665. for( int j = 0; j < m_currentDataCollector.VertexDataList.Count; j++ )
  1666. {
  1667. vertexInstructions.Add( m_currentDataCollector.VertexDataList[ j ].PropertyName );
  1668. }
  1669. m_templateMultiPass.SetPassInputData( m_subShaderIdx, m_passIdx, ports[ i ].PortId, newPortInstruction );
  1670. isValid = m_templateMultiPass.FillTemplateBody( m_subShaderIdx, m_passIdx, inputData.TagId, ref shaderBody, newPortInstruction ) && isValid;
  1671. }
  1672. else
  1673. {
  1674. m_templateMultiPass.SetPassInputData( m_subShaderIdx, m_passIdx, ports[ i ].PortId, inputData.DefaultValue );
  1675. isValid = m_templateMultiPass.FillTemplateBody( m_subShaderIdx, m_passIdx, inputData.TagId, ref shaderBody, inputData.DefaultValue ) && isValid;
  1676. }
  1677. }
  1678. return isValid;
  1679. }
  1680. public string BuildShaderBody( MasterNodeDataCollector inDataCollector, ref MasterNodeDataCollector outDataCollector )
  1681. {
  1682. List<TemplateMultiPassMasterNode> list = UIUtils.CurrentWindow.CurrentGraph.MultiPassMasterNodes.NodesList;
  1683. int currentSubshader = list[ 0 ].SubShaderIdx;
  1684. m_templateMultiPass.SetShaderName( string.Format( TemplatesManager.NameFormatter, m_shaderName ) );
  1685. if( string.IsNullOrEmpty( m_customInspectorName ) )
  1686. {
  1687. m_templateMultiPass.SetCustomInspector( string.Empty );
  1688. }
  1689. else
  1690. {
  1691. m_templateMultiPass.SetCustomInspector( CustomInspectorFormatted );
  1692. }
  1693. m_templateMultiPass.SetFallback( m_fallbackHelper.FallbackShader );
  1694. m_templateMultiPass.SetDependencies( m_dependenciesHelper.GenerateDependencies() );
  1695. if( inDataCollector != null )
  1696. outDataCollector.CopyPropertiesFromDataCollector( inDataCollector );
  1697. outDataCollector.TemplateDataCollectorInstance.CurrentSRPType = m_templateMultiPass.SRPtype;
  1698. int lastActivePass = m_passSelector.LastActivePass;
  1699. int count = list.Count;
  1700. for( int i = 0; i < count; i++ )
  1701. {
  1702. bool removePass = !m_passSelector.IsVisible( i );
  1703. list[ 0 ].CurrentTemplate.IdManager.SetPassIdUsage( i, removePass );
  1704. if( removePass )
  1705. continue;
  1706. list[ i ].CollectData();
  1707. list[ i ].FillPassData( this, outDataCollector.TemplateDataCollectorInstance );
  1708. if( list[ i ].SubShaderIdx == currentSubshader )
  1709. {
  1710. outDataCollector.CopyPropertiesFromDataCollector( list[ i ].CurrentDataCollector );
  1711. }
  1712. else
  1713. {
  1714. list[ i - 1 ].FillPropertyData( outDataCollector );
  1715. list[ i - 1 ].FillSubShaderData();
  1716. outDataCollector.Destroy();
  1717. outDataCollector = new MasterNodeDataCollector();
  1718. outDataCollector.CopyPropertiesFromDataCollector( list[ i ].CurrentDataCollector );
  1719. currentSubshader = list[ i ].SubShaderIdx;
  1720. }
  1721. // Last element must the one filling subshader data
  1722. // as only there all properties are caught
  1723. //if( i == ( count - 1 ) )
  1724. if( i == lastActivePass )
  1725. {
  1726. list[ i ].FillPropertyData( outDataCollector );
  1727. }
  1728. if( list[ i ].IsMainOutputNode )
  1729. list[ i ].FillSubShaderData();
  1730. }
  1731. outDataCollector.TemplateDataCollectorInstance.BuildCBuffer( -1 );
  1732. //Fill uniforms is set on last since we need to collect all srp batcher data ( if needed )
  1733. //To set it into each pass
  1734. for( int i = 0; i < count; i++ )
  1735. {
  1736. bool removePass = !m_passSelector.IsVisible( i );
  1737. if( removePass )
  1738. continue;
  1739. list[ i ].FillUniforms( outDataCollector.TemplateDataCollectorInstance );
  1740. }
  1741. return list[ 0 ].CurrentTemplate.IdManager.BuildShader();
  1742. }
  1743. public string BuildLOD( MasterNodeDataCollector inDataCollector, ref MasterNodeDataCollector outDataCollector )
  1744. {
  1745. UsageListTemplateMultiPassMasterNodes bufferNodesList = ContainerGraph.MultiPassMasterNodes;
  1746. int bufferMasterNodeId = ContainerGraph.CurrentMasterNodeId;
  1747. ContainerGraph.MultiPassMasterNodes = ContainerGraph.LodMultiPassMasternodes[ m_lodIndex ];
  1748. ContainerGraph.CurrentMasterNodeId = UniqueId;
  1749. m_templateMultiPass.ResetState();
  1750. base.Execute( string.Empty, false );
  1751. string shaderBody = BuildShaderBody( inDataCollector, ref outDataCollector );
  1752. ContainerGraph.MultiPassMasterNodes = bufferNodesList;
  1753. ContainerGraph.CurrentMasterNodeId = bufferMasterNodeId;
  1754. return shaderBody;
  1755. }
  1756. public override Shader Execute( string pathname, bool isFullPath )
  1757. {
  1758. ForceReordering();
  1759. MasterNodeDataCollector overallDataCollector = new MasterNodeDataCollector();
  1760. //BUILD LOD
  1761. string allLodSubShaders = string.Empty;
  1762. if( ContainerGraph.HasLODs )
  1763. {
  1764. for( int lod = 0; lod < ContainerGraph.LodMultiPassMasternodes.Count; lod++ )
  1765. {
  1766. if( ContainerGraph.LodMultiPassMasternodes[ lod ].Count == 0 )
  1767. break;
  1768. TemplateMultiPassMasterNode newMasterNode = ContainerGraph.LodMultiPassMasternodes[ lod ].NodesList.Find( ( x ) => x.IsMainOutputNode );
  1769. string lodSubShaders = newMasterNode.BuildLOD( null, ref overallDataCollector );
  1770. lodSubShaders = TemplateHelperFunctions.GetSubShaderFrom( lodSubShaders ) + "\n";
  1771. allLodSubShaders += lodSubShaders;
  1772. }
  1773. }
  1774. //BUILD MAIN
  1775. m_templateMultiPass.ResetState();
  1776. base.Execute( pathname, isFullPath );
  1777. MasterNodeDataCollector dummy = new MasterNodeDataCollector();
  1778. string shaderBody = BuildShaderBody( overallDataCollector, ref dummy );
  1779. //COMBINE LOD WITH MAIN
  1780. if( !string.IsNullOrEmpty( allLodSubShaders ) )
  1781. shaderBody = shaderBody.Replace( TemplatesManager.TemplateLODsTag, allLodSubShaders );
  1782. UpdateShaderAsset( ref pathname, ref shaderBody, isFullPath );
  1783. return m_currentShader;
  1784. }
  1785. public void CollectData()
  1786. {
  1787. if( m_inputPorts.Count == 0 )
  1788. return;
  1789. ContainerGraph.ResetNodesLocalVariables();
  1790. m_optionsDefineContainer.RemoveTemporaries();
  1791. m_currentDataCollector = new MasterNodeDataCollector( this );
  1792. m_currentDataCollector.TemplateDataCollectorInstance.SetMultipassInfo( m_templateMultiPass, m_subShaderIdx, m_passIdx, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType );
  1793. m_currentDataCollector.TemplateDataCollectorInstance.FillSpecialVariables( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ] );
  1794. SetupNodeCategories();
  1795. if( m_containerGraph.IsInstancedShader )
  1796. {
  1797. string blockName = UIUtils.RemoveInvalidCharacters( ContainerGraph.GetMainMasterNodeOfLOD( -1 ).ShaderName );
  1798. m_currentDataCollector.SetupInstancePropertiesBlock( blockName );
  1799. }
  1800. TemplateData templateData = m_templateMultiPass.CreateTemplateData( m_shaderName, string.Empty, m_subShaderIdx, m_passIdx );
  1801. m_currentDataCollector.TemplateDataCollectorInstance.BuildFromTemplateData( m_currentDataCollector, templateData );
  1802. if( m_currentDataCollector.TemplateDataCollectorInstance.InterpData.DynamicMax )
  1803. {
  1804. int interpolatorAmount = -1;
  1805. if( m_passModule.ShaderModelHelper.ValidData )
  1806. {
  1807. interpolatorAmount = m_passModule.ShaderModelHelper.InterpolatorAmount;
  1808. }
  1809. else
  1810. {
  1811. TemplateModulesHelper subShaderModule = IsMainOutputNode ? m_subShaderModule : ( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode ).SubShaderModule;
  1812. if( subShaderModule.ShaderModelHelper.ValidData )
  1813. {
  1814. interpolatorAmount = subShaderModule.ShaderModelHelper.InterpolatorAmount;
  1815. }
  1816. }
  1817. if( interpolatorAmount > -1 )
  1818. {
  1819. m_currentDataCollector.TemplateDataCollectorInstance.InterpData.RecalculateAvailableInterpolators( interpolatorAmount );
  1820. }
  1821. }
  1822. //Copy Properties
  1823. {
  1824. int shaderPropertiesAmount = m_templateMultiPass.AvailableShaderProperties.Count;
  1825. for( int i = 0; i < shaderPropertiesAmount; i++ )
  1826. {
  1827. m_currentDataCollector.SoftRegisterUniform( m_templateMultiPass.AvailableShaderProperties[ i ] );
  1828. }
  1829. }
  1830. //Copy Globals from SubShader level
  1831. {
  1832. int subShaderGlobalAmount = m_templateMultiPass.SubShaders[ m_subShaderIdx ].AvailableShaderGlobals.Count;
  1833. for( int i = 0; i < subShaderGlobalAmount; i++ )
  1834. {
  1835. m_currentDataCollector.SoftRegisterUniform( m_templateMultiPass.SubShaders[ m_subShaderIdx ].AvailableShaderGlobals[ i ] );
  1836. }
  1837. }
  1838. //Copy Globals from Pass Level
  1839. {
  1840. int passGlobalAmount = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].AvailableShaderGlobals.Count;
  1841. for( int i = 0; i < passGlobalAmount; i++ )
  1842. {
  1843. m_currentDataCollector.SoftRegisterUniform( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].AvailableShaderGlobals[ i ] );
  1844. }
  1845. }
  1846. // Check Current Options for property changes on subshader
  1847. if( m_isMainOutputNode )
  1848. {
  1849. CheckPropertyChangesOnOptions( m_subShaderOptions );
  1850. }
  1851. // Check Current Options for property changes on pass
  1852. CheckPropertyChangesOnOptions( m_passOptions );
  1853. //Set SRP info
  1854. #if UNITY_2018_3_OR_NEWER
  1855. if( m_templateMultiPass.SRPtype != TemplateSRPType.BuiltIn )
  1856. ASEPackageManagerHelper.SetSRPInfoOnDataCollector( ref m_currentDataCollector );
  1857. #endif
  1858. RegisterStandaloneFuntions();
  1859. m_containerGraph.CheckPropertiesAutoRegister( ref m_currentDataCollector );
  1860. //Sort ports by both
  1861. List<InputPort> fragmentPorts = new List<InputPort>();
  1862. List<InputPort> vertexPorts = new List<InputPort>();
  1863. SortInputPorts( ref vertexPorts, ref fragmentPorts );
  1864. string shaderBody = templateData.TemplateBody;
  1865. List<string> vertexInstructions = new List<string>();
  1866. List<string> fragmentInstructions = new List<string>();
  1867. bool validBody = true;
  1868. //validBody = CreateInstructionsForList( templateData, ref fragmentPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions ) && validBody;
  1869. //ContainerGraph.ResetNodesLocalVariablesIfNot( MasterNodePortCategory.Vertex );
  1870. //validBody = CreateInstructionsForList( templateData, ref vertexPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions ) && validBody;
  1871. validBody = CreateInstructionsForList( templateData, ref vertexPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions ) && validBody;
  1872. validBody = CreateInstructionsForList( templateData, ref fragmentPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions ) && validBody;
  1873. if( !m_isMainOutputNode && m_mainMasterNodeRef == null )
  1874. {
  1875. m_mainMasterNodeRef = m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  1876. }
  1877. TerrainDrawInstancedHelper drawInstanced = m_isMainOutputNode ? m_drawInstancedHelper : m_mainMasterNodeRef.DrawInstancedHelperInstance;
  1878. drawInstanced.UpdateDataCollectorForTemplates( ref m_currentDataCollector, ref vertexInstructions );
  1879. templateData.ResetTemplateUsageData();
  1880. // Fill vertex interpolators assignment
  1881. for( int i = 0; i < m_currentDataCollector.VertexInterpDeclList.Count; i++ )
  1882. {
  1883. vertexInstructions.Add( m_currentDataCollector.VertexInterpDeclList[ i ] );
  1884. }
  1885. vertexInstructions.AddRange( m_currentDataCollector.TemplateDataCollectorInstance.GetInterpUnusedChannels() );
  1886. //Fill common local variables and operations
  1887. validBody = m_templateMultiPass.FillVertexInstructions( m_subShaderIdx, m_passIdx, vertexInstructions.ToArray() ) && validBody;
  1888. validBody = m_templateMultiPass.FillFragmentInstructions( m_subShaderIdx, m_passIdx, fragmentInstructions.ToArray() ) && validBody;
  1889. vertexInstructions.Clear();
  1890. vertexInstructions = null;
  1891. fragmentInstructions.Clear();
  1892. fragmentInstructions = null;
  1893. // Add Instanced Properties
  1894. if( m_containerGraph.IsInstancedShader )
  1895. {
  1896. m_currentDataCollector.OptimizeInstancedProperties();
  1897. m_currentDataCollector.TabifyInstancedVars();
  1898. //string cbufferBegin = m_currentDataCollector.IsSRP ?
  1899. // string.Format( IOUtils.SRPInstancedPropertiesBegin, "UnityPerMaterial" ) :
  1900. // string.Format( IOUtils.InstancedPropertiesBegin, m_currentDataCollector.InstanceBlockName );
  1901. //string cBufferEnd = m_currentDataCollector.IsSRP ? ( string.Format( IOUtils.SRPInstancedPropertiesEnd, m_currentDataCollector.InstanceBlockName ) ) : IOUtils.InstancedPropertiesEnd;
  1902. string cbufferBegin = m_currentDataCollector.IsSRP ?
  1903. string.Format( IOUtils.LWSRPInstancedPropertiesBegin, m_currentDataCollector.InstanceBlockName ) :
  1904. string.Format( IOUtils.InstancedPropertiesBegin, m_currentDataCollector.InstanceBlockName );
  1905. string cBufferEnd = m_currentDataCollector.IsSRP ? ( string.Format( IOUtils.LWSRPInstancedPropertiesEnd, m_currentDataCollector.InstanceBlockName ) ) : IOUtils.InstancedPropertiesEnd;
  1906. m_currentDataCollector.InstancedPropertiesList.Insert( 0, new PropertyDataCollector( -1, cbufferBegin ) );
  1907. m_currentDataCollector.InstancedPropertiesList.Add( new PropertyDataCollector( -1, cBufferEnd ) );
  1908. m_currentDataCollector.UniformsList.AddRange( m_currentDataCollector.InstancedPropertiesList );
  1909. }
  1910. if( m_currentDataCollector.DotsPropertiesList.Count > 0 )
  1911. {
  1912. m_currentDataCollector.DotsPropertiesList.Insert( 0, new PropertyDataCollector( -1, "UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)" ) );
  1913. m_currentDataCollector.DotsPropertiesList.Insert( 0, new PropertyDataCollector( -1, "#ifdef UNITY_DOTS_INSTANCING_ENABLED" ) );
  1914. m_currentDataCollector.DotsPropertiesList.Insert( 0, new PropertyDataCollector( -1, "" ) );
  1915. m_currentDataCollector.DotsPropertiesList.Add( new PropertyDataCollector( -1, "UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)" ) );
  1916. m_currentDataCollector.DotsDefinesList.Add( new PropertyDataCollector( -1, "#endif" ) );
  1917. m_currentDataCollector.UniformsList.AddRange( m_currentDataCollector.DotsPropertiesList );
  1918. m_currentDataCollector.UniformsList.AddRange( m_currentDataCollector.DotsDefinesList );
  1919. }
  1920. TemplateShaderModelModule shaderModelModule = m_isMainOutputNode ? m_subShaderModule.ShaderModelHelper : m_mainMasterNodeRef.SubShaderModule.ShaderModelHelper;
  1921. string shaderModel = string.Empty;
  1922. if( m_passModule.ShaderModelHelper.ValidData )
  1923. {
  1924. shaderModel = m_passModule.ShaderModelHelper.CurrentShaderModel;
  1925. }
  1926. else if( shaderModelModule.ValidData )
  1927. {
  1928. shaderModel = shaderModelModule.CurrentShaderModel;
  1929. }
  1930. else if( m_templateMultiPass.GlobalShaderModel.IsValid )
  1931. {
  1932. shaderModel = m_templateMultiPass.GlobalShaderModel.Value;
  1933. }
  1934. else
  1935. {
  1936. shaderModel = ( m_templateMultiPass.SRPtype == TemplateSRPType.HD ) ? "4.5" : "3.0";
  1937. }
  1938. m_currentDataCollector.TemplateDataCollectorInstance.CheckInterpolatorOverflow( shaderModel, m_passName );
  1939. }
  1940. public void CheckPropertyChangesOnOptions( TemplateOptionsUIHelper optionsUI )
  1941. {
  1942. //Only Main LOD master node can change shader properties
  1943. if( !IsLODMainMasterNode )
  1944. return;
  1945. List<TemplateOptionUIItem> options = optionsUI.PassCustomOptionsUI;
  1946. for( int optionIdx = 0; optionIdx < options.Count; optionIdx++ )
  1947. {
  1948. if( options[ optionIdx ].IsVisible )
  1949. {
  1950. TemplateActionItem[] actionItems = options[ optionIdx ].CurrentOptionActions.Columns;
  1951. for( int actionIdx = 0; actionIdx < actionItems.Length; actionIdx++ )
  1952. {
  1953. if( actionItems[ actionIdx ].ActionType == AseOptionsActionType.SetShaderProperty && !string.IsNullOrEmpty( actionItems[ actionIdx ].ActionBuffer ) )
  1954. {
  1955. TemplateShaderPropertyData data = m_templateMultiPass.GetShaderPropertyData( actionItems[ actionIdx ].ActionData );
  1956. if( data != null )
  1957. {
  1958. string newPropertyValue = data.CreatePropertyForValue( actionItems[ actionIdx ].ActionBuffer );
  1959. CurrentTemplate.IdManager.SetReplacementText( data.FullValue, newPropertyValue );
  1960. }
  1961. }
  1962. }
  1963. if( options[ optionIdx ].Options.Type == AseOptionsType.Field )
  1964. {
  1965. foreach( var item in CurrentTemplate.IdManager.RegisteredTags )
  1966. {
  1967. if( item.Output.Equals( options[ optionIdx ].Options.FieldInlineName ) )
  1968. {
  1969. var node = options[ optionIdx ].Options.FieldValue.GetPropertyNode();
  1970. if( node != null && ( node.IsConnected || node.AutoRegister ) && options[ optionIdx ].Options.FieldValue.Active )
  1971. {
  1972. item.Replacement = node.PropertyName;
  1973. }
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. public void FillPropertyData( MasterNodeDataCollector dataCollector = null )
  1981. {
  1982. MasterNodeDataCollector currDataCollector = ( dataCollector == null ) ? m_currentDataCollector : dataCollector;
  1983. #if UNITY_2019_2_OR_NEWER
  1984. // Temporary hack
  1985. if( m_templateMultiPass.SRPtype != TemplateSRPType.BuiltIn && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_6_9_0 )
  1986. {
  1987. if( m_templateMultiPass.AvailableShaderProperties.Find( x => x.PropertyName.Equals( "_AlphaCutoff" ) ) == null )
  1988. {
  1989. if( !currDataCollector.ContainsProperty("_AlphaCutoff") )
  1990. {
  1991. currDataCollector.AddToProperties( UniqueId, "[HideInInspector] _AlphaCutoff(\"Alpha Cutoff \", Range(0, 1)) = 0.5", -1 );
  1992. }
  1993. }
  1994. if( m_templateMultiPass.AvailableShaderProperties.Find( x => x.PropertyName.Equals( "_EmissionColor" ) ) == null )
  1995. {
  1996. if( !currDataCollector.ContainsProperty( "_EmissionColor" ) )
  1997. {
  1998. currDataCollector.AddToProperties( UniqueId, "[HideInInspector] _EmissionColor(\"Emission Color\", Color) = (1,1,1,1)", -1 );
  1999. }
  2000. }
  2001. }
  2002. #endif
  2003. // here we add ASE attributes to the material properties that allows materials to communicate with ASE
  2004. if( m_templateMultiPass.SRPtype != TemplateSRPType.BuiltIn )
  2005. {
  2006. List<PropertyDataCollector> list = new List<PropertyDataCollector>( currDataCollector.PropertiesDict.Values );
  2007. list.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ); } );
  2008. for( int i = 0; i < list.Count; i++ )
  2009. {
  2010. if( !( list[ i ].PropertyName.Contains( "[HideInInspector]" ) || list[ i ].PropertyName.Contains( "//" ) ) )
  2011. {
  2012. list[ i ].PropertyName = "[ASEBegin]" + list[ i ].PropertyName;
  2013. break;
  2014. }
  2015. }
  2016. for( int i = list.Count - 1; i >= 0; i-- )
  2017. {
  2018. if( !( list[ i ].PropertyName.Contains( "[HideInInspector]" ) || list[ i ].PropertyName.Contains( "//" ) ) )
  2019. {
  2020. list[ i ].PropertyName = "[ASEEnd]" + list[ i ].PropertyName;
  2021. break;
  2022. }
  2023. }
  2024. }
  2025. m_templateMultiPass.SetPropertyData( currDataCollector.BuildUnformatedPropertiesStringArr() );
  2026. }
  2027. public void FillSubShaderData( /*MasterNodeDataCollector dataCollector = null */)
  2028. {
  2029. //MasterNodeDataCollector currDataCollector = ( dataCollector == null ) ? m_currentDataCollector : dataCollector;
  2030. //// SubShader Data
  2031. //m_templateMultiPass.SetPropertyData( currDataCollector.BuildUnformatedPropertiesStringArr() );
  2032. //templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModulePass, m_subShaderIdx, currDataCollector.GrabPassList );
  2033. if( ShaderLOD > -1 )
  2034. {
  2035. string lodUniqueId = m_templateMultiPass.SubShaders[ m_subShaderIdx ].UniquePrefix + "Module" + m_templateMultiPass.SubShaders[ m_subShaderIdx ].LODContainer.Id;
  2036. m_templateMultiPass.IdManager.SetReplacementText( lodUniqueId, "LOD " + ShaderLOD );
  2037. }
  2038. SetModuleData( m_subShaderModule, true );
  2039. }
  2040. public void FillPassData( TemplateMultiPassMasterNode masterNode, TemplateDataCollector mainTemplateDataCollector )
  2041. {
  2042. if( m_isInvisible != InvisibilityStatus.Visible )
  2043. {
  2044. if( masterNode.UniqueId != UniqueId )
  2045. {
  2046. if( ( m_invisibleOptions & (int)InvisibleOptionsEnum.SyncProperties ) > 0 )
  2047. {
  2048. PassModule.SyncWith( masterNode.PassModule );
  2049. }
  2050. }
  2051. int inputCount = m_inputPorts.Count;
  2052. for( int i = 0; i < inputCount; i++ )
  2053. {
  2054. if( m_inputPorts[ i ].HasExternalLink )
  2055. {
  2056. TemplateMultiPassMasterNode linkedNode = m_inputPorts[ i ].ExternalLinkNode as TemplateMultiPassMasterNode;
  2057. if( linkedNode != null )
  2058. {
  2059. SetLinkedModuleData( linkedNode.PassModule );
  2060. }
  2061. }
  2062. }
  2063. }
  2064. SetModuleData( m_passModule, false );
  2065. if( m_currentDataCollector != null )
  2066. {
  2067. if( Pass.CustomOptionsContainer.CopyOptionsFromMainPass )
  2068. {
  2069. SetPassCustomOptionsInfo( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode );
  2070. }
  2071. else
  2072. {
  2073. SetPassCustomOptionsInfo( this );
  2074. }
  2075. var inputArray = m_currentDataCollector.VertexInputList.ToArray();
  2076. m_templateMultiPass.SetPassData( TemplateModuleDataType.PassVertexData, m_subShaderIdx, m_passIdx, inputArray );
  2077. m_templateMultiPass.SetPassData( TemplateModuleDataType.PassInterpolatorData, m_subShaderIdx, m_passIdx, m_currentDataCollector.InterpolatorList.ToArray() );
  2078. SetHDInfoOnPass();
  2079. List<PropertyDataCollector> afterNativesIncludePragmaDefineList = new List<PropertyDataCollector>();
  2080. afterNativesIncludePragmaDefineList.AddRange( m_currentDataCollector.IncludesList );
  2081. afterNativesIncludePragmaDefineList.AddRange( m_currentDataCollector.DefinesList );
  2082. //includePragmaDefineList.AddRange( m_optionsDefineContainer.DefinesList );
  2083. afterNativesIncludePragmaDefineList.AddRange( m_currentDataCollector.PragmasList );
  2084. m_currentDataCollector.AddASEMacros();
  2085. afterNativesIncludePragmaDefineList.AddRange( m_currentDataCollector.AfterNativeDirectivesList );
  2086. //includePragmaDefineList.AddRange( m_currentDataCollector.MiscList );
  2087. List<PropertyDataCollector> beforeNatives = new List<PropertyDataCollector>();
  2088. beforeNatives.AddRange( m_optionsDefineContainer.DefinesList );
  2089. beforeNatives.AddRange( m_currentDataCollector.BeforeNativeDirectivesList );
  2090. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModulePragmaBefore, m_subShaderIdx, m_passIdx, beforeNatives );
  2091. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModulePragma, m_subShaderIdx, m_passIdx, afterNativesIncludePragmaDefineList );
  2092. m_currentDataCollector.TemplateDataCollectorInstance.CloseLateDirectives();
  2093. //Add Functions
  2094. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.FunctionsTag.IsValid )
  2095. {
  2096. m_currentDataCollector.FunctionsList.InsertRange( 0, m_currentDataCollector.TemplateDataCollectorInstance.LateDirectivesList );
  2097. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleFunctions, m_subShaderIdx, m_passIdx, m_currentDataCollector.FunctionsList );
  2098. }
  2099. else
  2100. {
  2101. m_currentDataCollector.UniformsList.InsertRange( 0, m_currentDataCollector.TemplateDataCollectorInstance.LateDirectivesList );
  2102. m_currentDataCollector.UniformsList.AddRange( m_currentDataCollector.FunctionsList );
  2103. }
  2104. //copy srp batch if present
  2105. //if( m_currentDataCollector.IsSRP )
  2106. //{
  2107. // m_currentDataCollector.UniformsList.AddRange( mainTemplateDataCollector.SrpBatcherPropertiesList );
  2108. //}
  2109. //m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleGlobals, m_subShaderIdx, m_passIdx, m_currentDataCollector.UniformsList );
  2110. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleInputVert, m_subShaderIdx, m_passIdx, m_currentDataCollector.TemplateDataCollectorInstance.VertexInputParamsStr );
  2111. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleInputFrag, m_subShaderIdx, m_passIdx, m_currentDataCollector.TemplateDataCollectorInstance.FragInputParamsStr );
  2112. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessVControlTag != null && m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessVControlTag.IsValid )
  2113. m_templateMultiPass.SetPassData( TemplateModuleDataType.VControl, m_subShaderIdx, m_passIdx, inputArray );
  2114. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessControlData != null && m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessControlData.IsValid )
  2115. m_templateMultiPass.SetPassData( TemplateModuleDataType.ControlData, m_subShaderIdx, m_passIdx, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessControlData.GenerateControl( m_currentDataCollector.TemplateDataCollectorInstance.VertexDataDict, m_currentDataCollector.VertexInputList ) );
  2116. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessDomainData != null && m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessDomainData.IsValid )
  2117. m_templateMultiPass.SetPassData( TemplateModuleDataType.DomainData, m_subShaderIdx, m_passIdx, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessDomainData.GenerateDomain( m_currentDataCollector.TemplateDataCollectorInstance.VertexDataDict, m_currentDataCollector.VertexInputList ) );
  2118. afterNativesIncludePragmaDefineList.Clear();
  2119. afterNativesIncludePragmaDefineList = null;
  2120. beforeNatives.Clear();
  2121. beforeNatives = null;
  2122. }
  2123. m_templateMultiPass.SetPassData( TemplateModuleDataType.PassNameData, m_subShaderIdx, m_passIdx, string.Format( PassNameFormateStr, m_passName ) );
  2124. }
  2125. public List<PropertyDataCollector> CrossCheckSoftRegisteredUniformList( List<PropertyDataCollector> uniformList )
  2126. {
  2127. List<PropertyDataCollector> newItems = new List<PropertyDataCollector>();
  2128. for( int i = 0; i < uniformList.Count; i++ )
  2129. {
  2130. if( !m_currentDataCollector.CheckIfSoftRegistered( uniformList[ i ].PropertyName ) )
  2131. {
  2132. newItems.Add( uniformList[ i ] );
  2133. }
  2134. }
  2135. return newItems;
  2136. }
  2137. public void FillUniforms( TemplateDataCollector mainTemplateDataCollector )
  2138. {
  2139. if( m_currentDataCollector.IsSRP )
  2140. {
  2141. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPBatcherTag.IsValid )
  2142. {
  2143. List<PropertyDataCollector> finalList = CrossCheckSoftRegisteredUniformList( mainTemplateDataCollector.SrpBatcherPropertiesList );
  2144. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleSRPBatcher, m_subShaderIdx, m_passIdx, finalList );
  2145. finalList.Clear();
  2146. finalList = null;
  2147. }
  2148. else
  2149. {
  2150. List<PropertyDataCollector> finalList = CrossCheckSoftRegisteredUniformList( mainTemplateDataCollector.FullSrpBatcherPropertiesList );
  2151. m_currentDataCollector.UniformsList.AddRange( finalList );
  2152. finalList.Clear();
  2153. finalList = null;
  2154. }
  2155. }
  2156. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleGlobals, m_subShaderIdx, m_passIdx, m_currentDataCollector.UniformsList );
  2157. }
  2158. void SetHDInfoOnPass()
  2159. {
  2160. #if UNITY_2019_3_OR_NEWER
  2161. if( ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_6_9_1 )
  2162. return;
  2163. #endif
  2164. if( m_currentDataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD )
  2165. {
  2166. TemplateModulesHelper subShaderHelper = null;
  2167. TemplateModulesHelper passHelper = null;
  2168. if( m_isMainOutputNode )
  2169. {
  2170. subShaderHelper = m_subShaderModule;
  2171. passHelper = m_passModule;
  2172. }
  2173. else
  2174. {
  2175. TemplateMultiPassMasterNode masterNode = m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  2176. if( masterNode != null )
  2177. {
  2178. subShaderHelper = masterNode.SubShaderModule;
  2179. passHelper = masterNode.PassModule;
  2180. }
  2181. else
  2182. {
  2183. subShaderHelper = m_subShaderModule;
  2184. passHelper = m_passModule;
  2185. }
  2186. }
  2187. RenderQueue renderQueue = RenderQueue.Geometry;
  2188. RenderType renderType = RenderType.Opaque;
  2189. if( passHelper.TagsHelper.HasRenderInfo( ref renderType, ref renderQueue ) ||
  2190. subShaderHelper.TagsHelper.HasRenderInfo( ref renderType, ref renderQueue ) )
  2191. {
  2192. if( renderType == RenderType.Transparent && renderQueue == RenderQueue.Transparent )
  2193. {
  2194. SetExtraDefine( SRPMaterialTransparentKeyword );
  2195. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialTransparentKeyword );
  2196. TemplatesBlendModule blendOpHelper = passHelper.BlendOpHelper.ValidBlendMode ? passHelper.BlendOpHelper : subShaderHelper.BlendOpHelper;
  2197. if( blendOpHelper.IsAdditiveRGB )
  2198. {
  2199. SetExtraDefine( SRPMaterialBlendModeAddKeyword );
  2200. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialBlendModeAddKeyword );
  2201. }
  2202. else if( blendOpHelper.IsAlphaBlendRGB )
  2203. {
  2204. SetExtraDefine( SRPMaterialBlendModeAlphaKeyword );
  2205. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialBlendModeAlphaKeyword );
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. void SetLinkedModuleData( TemplateModulesHelper linkedModule )
  2212. {
  2213. //if( linkedModule.AdditionalPragmas.ValidData )
  2214. //{
  2215. // linkedModule.AdditionalPragmas.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2216. //}
  2217. //if( linkedModule.AdditionalIncludes.ValidData )
  2218. //{
  2219. // linkedModule.AdditionalIncludes.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2220. //}
  2221. //if( linkedModule.AdditionalDefines.ValidData )
  2222. //{
  2223. // linkedModule.AdditionalDefines.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2224. //}
  2225. if( linkedModule.AdditionalDirectives.ValidData )
  2226. {
  2227. linkedModule.AdditionalDirectives.AddAllToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2228. }
  2229. }
  2230. void SetModuleData( TemplateModulesHelper module, bool isSubShader )
  2231. {
  2232. if( isSubShader )
  2233. {
  2234. //if ( module.AdditionalPragmas.ValidData )
  2235. //{
  2236. // module.AdditionalPragmas.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.IncludePragmaContainer );
  2237. //}
  2238. //if ( module.AdditionalIncludes.ValidData )
  2239. //{
  2240. // module.AdditionalIncludes.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.IncludePragmaContainer );
  2241. //}
  2242. //if ( module.AdditionalDefines.ValidData )
  2243. //{
  2244. // module.AdditionalDefines.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.IncludePragmaContainer );
  2245. //}
  2246. if( module.AdditionalDirectives.ValidData )
  2247. {
  2248. module.AdditionalDirectives.AddAllToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.IncludePragmaContainer );
  2249. }
  2250. if( module.TagsHelper.ValidData )
  2251. {
  2252. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleTag, m_subShaderIdx, module.TagsHelper.GenerateTags() );
  2253. }
  2254. if( module.AllModulesMode )
  2255. {
  2256. string body = module.GenerateAllModulesString( isSubShader );
  2257. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.AllModules, m_subShaderIdx, body.Split( '\n' ) );
  2258. }
  2259. if( module.ShaderModelHelper.ValidAndIndependent )
  2260. {
  2261. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleShaderModel, m_subShaderIdx, module.ShaderModelHelper.GenerateShaderData( isSubShader ) );
  2262. }
  2263. if( module.BlendOpHelper.IndependentModule && module.BlendOpHelper.ValidBlendMode )
  2264. {
  2265. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendMode, m_subShaderIdx, module.BlendOpHelper.CurrentBlendFactor );
  2266. }
  2267. if( module.BlendOpHelper1.IndependentModule && module.BlendOpHelper1.ValidBlendMode )
  2268. {
  2269. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendMode1, m_subShaderIdx, module.BlendOpHelper1.CurrentBlendFactor );
  2270. }
  2271. if( module.BlendOpHelper2.IndependentModule && module.BlendOpHelper2.ValidBlendMode )
  2272. {
  2273. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendMode2, m_subShaderIdx, module.BlendOpHelper2.CurrentBlendFactor );
  2274. }
  2275. if( module.BlendOpHelper3.IndependentModule && module.BlendOpHelper3.ValidBlendMode )
  2276. {
  2277. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendMode3, m_subShaderIdx, module.BlendOpHelper3.CurrentBlendFactor );
  2278. }
  2279. if( module.BlendOpHelper.IndependentModule && module.BlendOpHelper.ValidBlendOp )
  2280. {
  2281. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendOp, m_subShaderIdx, module.BlendOpHelper.CurrentBlendOp );
  2282. }
  2283. if( module.BlendOpHelper1.IndependentModule && module.BlendOpHelper1.ValidBlendOp )
  2284. {
  2285. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendOp1, m_subShaderIdx, module.BlendOpHelper1.CurrentBlendOp );
  2286. }
  2287. if( module.BlendOpHelper2.IndependentModule && module.BlendOpHelper2.ValidBlendOp )
  2288. {
  2289. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendOp2, m_subShaderIdx, module.BlendOpHelper2.CurrentBlendOp );
  2290. }
  2291. if( module.BlendOpHelper3.IndependentModule && module.BlendOpHelper3.ValidBlendOp )
  2292. {
  2293. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendOp3, m_subShaderIdx, module.BlendOpHelper3.CurrentBlendOp );
  2294. }
  2295. if( module.AlphaToMaskHelper.ValidAndIndependent )
  2296. {
  2297. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleAlphaToMask, m_subShaderIdx, module.AlphaToMaskHelper.GenerateShaderData( isSubShader ) );
  2298. }
  2299. if( module.CullModeHelper.ValidAndIndependent )
  2300. {
  2301. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleCullMode, m_subShaderIdx, module.CullModeHelper.GenerateShaderData( isSubShader ) );
  2302. }
  2303. if( module.ColorMaskHelper.ValidAndIndependent )
  2304. {
  2305. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleColorMask, m_subShaderIdx, module.ColorMaskHelper.GenerateShaderData( isSubShader ) );
  2306. }
  2307. if( module.ColorMaskHelper1.ValidAndIndependent )
  2308. {
  2309. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleColorMask1, m_subShaderIdx, module.ColorMaskHelper1.GenerateShaderData( isSubShader ) );
  2310. }
  2311. if( module.ColorMaskHelper2.ValidAndIndependent )
  2312. {
  2313. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleColorMask2, m_subShaderIdx, module.ColorMaskHelper2.GenerateShaderData( isSubShader ) );
  2314. }
  2315. if( module.ColorMaskHelper3.ValidAndIndependent )
  2316. {
  2317. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleColorMask3, m_subShaderIdx, module.ColorMaskHelper3.GenerateShaderData( isSubShader ) );
  2318. }
  2319. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidZTest )
  2320. {
  2321. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleZTest, m_subShaderIdx, module.DepthOphelper.CurrentZTestMode );
  2322. }
  2323. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidZWrite )
  2324. {
  2325. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleZwrite, m_subShaderIdx, module.DepthOphelper.CurrentZWriteMode );
  2326. }
  2327. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidOffset )
  2328. {
  2329. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleZOffset, m_subShaderIdx, module.DepthOphelper.CurrentOffset );
  2330. }
  2331. if( module.StencilBufferHelper.ValidAndIndependent )
  2332. {
  2333. CullMode cullMode = ( module.CullModeHelper.ValidData ) ? module.CullModeHelper.CurrentCullMode : CullMode.Back;
  2334. string value = module.StencilBufferHelper.CreateStencilOp( cullMode );
  2335. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleStencil, m_subShaderIdx, value.Split( '\n' ) );
  2336. }
  2337. }
  2338. else
  2339. {
  2340. //if ( module.AdditionalPragmas.ValidData )
  2341. //{
  2342. // module.AdditionalPragmas.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2343. //}
  2344. //if ( module.AdditionalIncludes.ValidData )
  2345. //{
  2346. // module.AdditionalIncludes.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2347. //}
  2348. //if ( module.AdditionalDefines.ValidData )
  2349. //{
  2350. // module.AdditionalDefines.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2351. //}
  2352. List<PropertyDataCollector> aboveUsePass = new List<PropertyDataCollector>();
  2353. List<PropertyDataCollector> belowUsePass = new List<PropertyDataCollector>();
  2354. m_usePass.BuildUsePassInfo( m_currentDataCollector, ref aboveUsePass, ref belowUsePass );
  2355. //TODO Must place this on the correct place
  2356. aboveUsePass.AddRange( belowUsePass );
  2357. //adding grab pass after use pass on purpose, so it wont be caught by them
  2358. aboveUsePass.AddRange( m_currentDataCollector.GrabPassList );
  2359. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModulePass, m_subShaderIdx, m_passIdx, aboveUsePass );
  2360. //m_templateMultiPass.SetPassData( TemplateModuleDataType.EndPass, m_subShaderIdx, m_passIdx, bellowUsePass);
  2361. if( module.AdditionalDirectives.ValidData )
  2362. {
  2363. module.AdditionalDirectives.AddAllToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2364. }
  2365. if( module.TagsHelper.ValidData )
  2366. {
  2367. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleTag, m_subShaderIdx, m_passIdx, module.TagsHelper.GenerateTags() );
  2368. }
  2369. if( module.AllModulesMode )
  2370. {
  2371. string body = module.GenerateAllModulesString( isSubShader );
  2372. m_templateMultiPass.SetPassData( TemplateModuleDataType.AllModules, m_subShaderIdx, m_passIdx, body.Split( '\n' ) );
  2373. }
  2374. if( module.ShaderModelHelper.ValidAndIndependent )
  2375. {
  2376. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleShaderModel, m_subShaderIdx, m_passIdx, module.ShaderModelHelper.GenerateShaderData( isSubShader ) );
  2377. }
  2378. if( module.BlendOpHelper.IndependentModule && module.BlendOpHelper.ValidBlendMode )
  2379. {
  2380. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendMode, m_subShaderIdx, m_passIdx, module.BlendOpHelper.CurrentBlendFactor );
  2381. }
  2382. if( module.BlendOpHelper1.IndependentModule && module.BlendOpHelper1.ValidBlendMode )
  2383. {
  2384. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendMode1, m_subShaderIdx, m_passIdx, module.BlendOpHelper1.CurrentBlendFactor );
  2385. }
  2386. if( module.BlendOpHelper2.IndependentModule && module.BlendOpHelper2.ValidBlendMode )
  2387. {
  2388. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendMode2, m_subShaderIdx, m_passIdx, module.BlendOpHelper2.CurrentBlendFactor );
  2389. }
  2390. if( module.BlendOpHelper3.IndependentModule && module.BlendOpHelper3.ValidBlendMode )
  2391. {
  2392. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendMode3, m_subShaderIdx, m_passIdx, module.BlendOpHelper3.CurrentBlendFactor );
  2393. }
  2394. if( module.BlendOpHelper.IndependentModule && module.BlendOpHelper.ValidBlendOp )
  2395. {
  2396. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendOp, m_subShaderIdx, m_passIdx, module.BlendOpHelper.CurrentBlendOp );
  2397. }
  2398. if( module.BlendOpHelper1.IndependentModule && module.BlendOpHelper1.ValidBlendOp )
  2399. {
  2400. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendOp1, m_subShaderIdx, m_passIdx, module.BlendOpHelper1.CurrentBlendOp );
  2401. }
  2402. if( module.BlendOpHelper2.IndependentModule && module.BlendOpHelper2.ValidBlendOp )
  2403. {
  2404. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendOp2, m_subShaderIdx, m_passIdx, module.BlendOpHelper2.CurrentBlendOp );
  2405. }
  2406. if( module.BlendOpHelper3.IndependentModule && module.BlendOpHelper3.ValidBlendOp )
  2407. {
  2408. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendOp3, m_subShaderIdx, m_passIdx, module.BlendOpHelper3.CurrentBlendOp );
  2409. }
  2410. if( module.AlphaToMaskHelper.ValidAndIndependent )
  2411. {
  2412. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleAlphaToMask, m_subShaderIdx, m_passIdx, module.AlphaToMaskHelper.GenerateShaderData( isSubShader ) );
  2413. }
  2414. if( module.CullModeHelper.ValidAndIndependent )
  2415. {
  2416. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleCullMode, m_subShaderIdx, m_passIdx, module.CullModeHelper.GenerateShaderData( isSubShader ) );
  2417. }
  2418. if( module.ColorMaskHelper.ValidAndIndependent )
  2419. {
  2420. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleColorMask, m_subShaderIdx, m_passIdx, module.ColorMaskHelper.GenerateShaderData( isSubShader ) );
  2421. }
  2422. if( module.ColorMaskHelper1.ValidAndIndependent )
  2423. {
  2424. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleColorMask1, m_subShaderIdx, m_passIdx, module.ColorMaskHelper1.GenerateShaderData( isSubShader ) );
  2425. }
  2426. if( module.ColorMaskHelper2.ValidAndIndependent )
  2427. {
  2428. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleColorMask2, m_subShaderIdx, m_passIdx, module.ColorMaskHelper2.GenerateShaderData( isSubShader ) );
  2429. }
  2430. if( module.ColorMaskHelper3.ValidAndIndependent )
  2431. {
  2432. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleColorMask3, m_subShaderIdx, m_passIdx, module.ColorMaskHelper3.GenerateShaderData( isSubShader ) );
  2433. }
  2434. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidZTest )
  2435. {
  2436. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleZTest, m_subShaderIdx, m_passIdx, module.DepthOphelper.CurrentZTestMode );
  2437. }
  2438. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidZWrite )
  2439. {
  2440. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleZwrite, m_subShaderIdx, m_passIdx, module.DepthOphelper.CurrentZWriteMode );
  2441. }
  2442. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidOffset )
  2443. {
  2444. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleZOffset, m_subShaderIdx, m_passIdx, module.DepthOphelper.CurrentOffset );
  2445. }
  2446. if( module.StencilBufferHelper.ValidAndIndependent )
  2447. {
  2448. CullMode cullMode = ( module.CullModeHelper.ValidData ) ? module.CullModeHelper.CurrentCullMode : CullMode.Back;
  2449. string value = module.StencilBufferHelper.CreateStencilOp( cullMode );
  2450. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleStencil, m_subShaderIdx, m_passIdx, value.Split( '\n' ) );
  2451. }
  2452. }
  2453. }
  2454. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  2455. {
  2456. return "0";
  2457. }
  2458. public override void Destroy()
  2459. {
  2460. base.Destroy();
  2461. m_drawInstancedHelper = null;
  2462. m_optionsDefineContainer.Destroy();
  2463. m_optionsDefineContainer = null;
  2464. m_passSelector.Destroy();
  2465. m_passSelector = null;
  2466. m_subShaderOptions.Destroy();
  2467. m_passOptions.Destroy();
  2468. m_fallbackHelper.Destroy();
  2469. GameObject.DestroyImmediate( m_fallbackHelper );
  2470. m_fallbackHelper = null;
  2471. m_usePass.Destroy();
  2472. GameObject.DestroyImmediate( m_usePass );
  2473. m_usePass = null;
  2474. m_dependenciesHelper.Destroy();
  2475. m_dependenciesHelper = null;
  2476. m_subShaderModule.Destroy();
  2477. m_subShaderModule = null;
  2478. m_passModule.Destroy();
  2479. m_passModule = null;
  2480. if( m_lodIndex == -1 )
  2481. {
  2482. ContainerGraph.MultiPassMasterNodes.RemoveNode( this );
  2483. }
  2484. else
  2485. {
  2486. ContainerGraph.LodMultiPassMasternodes[ m_lodIndex ].RemoveNode( this );
  2487. }
  2488. }
  2489. void UpdateSubShaderPassStr()
  2490. {
  2491. //m_subShaderIdxStr = SubShaderModuleStr + m_templateMultiPass.SubShaders[ m_subShaderIdx ].Idx;
  2492. //m_passIdxStr = PassModuleStr + m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Idx;
  2493. }
  2494. public override void ReadFromString( ref string[] nodeParams )
  2495. {
  2496. base.ReadFromString( ref nodeParams );
  2497. try
  2498. {
  2499. string currShaderName = GetCurrentParam( ref nodeParams );
  2500. if( currShaderName.Length > 0 )
  2501. currShaderName = UIUtils.RemoveShaderInvalidCharacters( currShaderName );
  2502. m_templateGUID = GetCurrentParam( ref nodeParams );
  2503. bool hasUniqueName = false;
  2504. if( UIUtils.CurrentShaderVersion() > PASS_UNIQUE_ID_VERSION )
  2505. {
  2506. hasUniqueName = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  2507. }
  2508. if( hasUniqueName )
  2509. m_passUniqueId = GetCurrentParam( ref nodeParams );
  2510. m_subShaderIdx = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  2511. m_passIdx = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  2512. if( UIUtils.CurrentShaderVersion() > LOD_SUBSHADER_VERSION )
  2513. {
  2514. if( m_lodIndex != -1 )
  2515. {
  2516. m_containerGraph.MultiPassMasterNodes.RemoveNode( this );
  2517. m_containerGraph.LodMultiPassMasternodes[ m_lodIndex ].AddNode( this );
  2518. }
  2519. }
  2520. m_passName = GetCurrentParam( ref nodeParams );
  2521. SetTemplate( null, false, true, m_subShaderIdx, m_passIdx, SetTemplateSource.ShaderLoad );
  2522. ////If value gotten from template is > -1 then it contains the LOD field
  2523. ////and we can properly write the value
  2524. //if( m_subShaderLOD > -1 )
  2525. //{
  2526. // m_subShaderLOD = subShaderLOD;
  2527. //}
  2528. // only in here, after SetTemplate, we know if shader name is to be used as title or not
  2529. ShaderName = currShaderName;
  2530. m_visiblePorts = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  2531. m_subShaderModule.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2532. m_passModule.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2533. if( UIUtils.CurrentShaderVersion() > 15308 )
  2534. {
  2535. m_fallbackHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2536. m_dependenciesHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2537. }
  2538. if( UIUtils.CurrentShaderVersion() > 15402 )
  2539. {
  2540. m_usePass.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2541. }
  2542. if( UIUtils.CurrentShaderVersion() > 15409 )
  2543. {
  2544. m_hdSrpMaterialType = (HDSRPMaterialType)Enum.Parse( typeof( HDSRPMaterialType ), GetCurrentParam( ref nodeParams ) );
  2545. }
  2546. if( UIUtils.CurrentShaderVersion() > 15501 )
  2547. {
  2548. if( m_isMainOutputNode && UIUtils.CurrentShaderVersion() > PASS_SELECTOR_VERSION )
  2549. m_subShaderOptions.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2550. m_passOptions.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2551. }
  2552. if( m_isMainOutputNode && UIUtils.CurrentShaderVersion() > PASS_SELECTOR_VERSION )
  2553. {
  2554. m_passSelector.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2555. }
  2556. if( m_isMainOutputNode && UIUtils.CurrentShaderVersion() > 16203 )
  2557. {
  2558. m_drawInstancedHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2559. }
  2560. if( m_isMainOutputNode && UIUtils.CurrentShaderVersion() > LOD_SUBSHADER_VERSION )
  2561. {
  2562. m_mainLODName = GetCurrentParam( ref nodeParams );
  2563. SetupLODNodeName();
  2564. }
  2565. else
  2566. {
  2567. m_content.text = GenerateClippedTitle( m_passName );
  2568. }
  2569. if( UIUtils.CurrentShaderVersion() > 18302 )
  2570. SamplingMacros = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  2571. else
  2572. SamplingMacros = false;
  2573. //if( m_templateMultiPass != null && !m_templateMultiPass.IsSinglePass )
  2574. //{
  2575. // SetClippedTitle( m_passName );
  2576. //}
  2577. }
  2578. catch( Exception e )
  2579. {
  2580. Debug.LogException( e, this );
  2581. }
  2582. m_containerGraph.CurrentCanvasMode = NodeAvailability.TemplateShader;
  2583. m_containerGraph.CurrentPrecision = m_currentPrecisionType;
  2584. }
  2585. public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  2586. {
  2587. base.WriteToString( ref nodeInfo, ref connectionsInfo );
  2588. IOUtils.AddFieldValueToString( ref nodeInfo, ShaderName );
  2589. IOUtils.AddFieldValueToString( ref nodeInfo, m_templateGUID );
  2590. bool hasUniquePassName = Pass.Modules.HasPassUniqueName;
  2591. IOUtils.AddFieldValueToString( ref nodeInfo, hasUniquePassName );
  2592. if( hasUniquePassName )
  2593. {
  2594. IOUtils.AddFieldValueToString( ref nodeInfo, Pass.Modules.PassUniqueName );
  2595. }
  2596. IOUtils.AddFieldValueToString( ref nodeInfo, m_subShaderIdx );
  2597. IOUtils.AddFieldValueToString( ref nodeInfo, m_passIdx );
  2598. IOUtils.AddFieldValueToString( ref nodeInfo, m_passName );
  2599. IOUtils.AddFieldValueToString( ref nodeInfo, m_visiblePorts );
  2600. m_subShaderModule.WriteToString( ref nodeInfo );
  2601. m_passModule.WriteToString( ref nodeInfo );
  2602. m_fallbackHelper.WriteToString( ref nodeInfo );
  2603. m_dependenciesHelper.WriteToString( ref nodeInfo );
  2604. m_usePass.WriteToString( ref nodeInfo );
  2605. IOUtils.AddFieldValueToString( ref nodeInfo, m_hdSrpMaterialType );
  2606. if( m_isMainOutputNode )
  2607. m_subShaderOptions.WriteToString( ref nodeInfo );
  2608. m_passOptions.WriteToString( ref nodeInfo );
  2609. if( m_isMainOutputNode )
  2610. {
  2611. m_passSelector.WriteToString( ref nodeInfo );
  2612. m_drawInstancedHelper.WriteToString( ref nodeInfo );
  2613. }
  2614. if( m_isMainOutputNode )
  2615. IOUtils.AddFieldValueToString( ref nodeInfo, m_mainLODName );
  2616. IOUtils.AddFieldValueToString( ref nodeInfo, m_samplingMacros );
  2617. }
  2618. public override void ReadFromDeprecated( ref string[] nodeParams, Type oldType = null )
  2619. {
  2620. base.ReadFromString( ref nodeParams );
  2621. try
  2622. {
  2623. string currShaderName = GetCurrentParam( ref nodeParams );
  2624. if( currShaderName.Length > 0 )
  2625. currShaderName = UIUtils.RemoveShaderInvalidCharacters( currShaderName );
  2626. string templateGUID = GetCurrentParam( ref nodeParams );
  2627. string templateShaderName = string.Empty;
  2628. if( UIUtils.CurrentShaderVersion() > 13601 )
  2629. {
  2630. templateShaderName = GetCurrentParam( ref nodeParams );
  2631. }
  2632. TemplateMultiPass template = m_containerGraph.ParentWindow.TemplatesManagerInstance.GetTemplate( templateGUID ) as TemplateMultiPass;
  2633. if( template != null )
  2634. {
  2635. m_templateGUID = templateGUID;
  2636. SetTemplate( null, false, true, 0, 0,SetTemplateSource.ShaderLoad );
  2637. }
  2638. else
  2639. {
  2640. template = m_containerGraph.ParentWindow.TemplatesManagerInstance.GetTemplateByName( templateShaderName ) as TemplateMultiPass;
  2641. if( template != null )
  2642. {
  2643. m_templateGUID = template.GUID;
  2644. SetTemplate( null, false, true, 0, 0, SetTemplateSource.ShaderLoad );
  2645. }
  2646. else
  2647. {
  2648. m_masterNodeCategory = -1;
  2649. }
  2650. }
  2651. if( m_invalidNode )
  2652. return;
  2653. // only in here, after SetTemplate, we know if shader name is to be used as title or not
  2654. ShaderName = currShaderName;
  2655. if( UIUtils.CurrentShaderVersion() > 13902 )
  2656. {
  2657. //BLEND MODULE
  2658. if( m_templateMultiPass.SubShaders[ 0 ].Modules.BlendData.ValidBlendMode )
  2659. {
  2660. m_subShaderModule.BlendOpHelper.ReadBlendModeFromString( ref m_currentReadParamIdx, ref nodeParams );
  2661. }
  2662. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.BlendData.ValidBlendMode )
  2663. {
  2664. m_passModule.BlendOpHelper.ReadBlendModeFromString( ref m_currentReadParamIdx, ref nodeParams );
  2665. }
  2666. if( m_templateMultiPass.SubShaders[ 0 ].Modules.BlendData.ValidBlendOp )
  2667. {
  2668. m_subShaderModule.BlendOpHelper.ReadBlendOpFromString( ref m_currentReadParamIdx, ref nodeParams );
  2669. }
  2670. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.BlendData.ValidBlendOp )
  2671. {
  2672. m_passModule.BlendOpHelper.ReadBlendOpFromString( ref m_currentReadParamIdx, ref nodeParams );
  2673. }
  2674. //CULL MODE
  2675. if( m_templateMultiPass.SubShaders[ 0 ].Modules.CullModeData.DataCheck == TemplateDataCheck.Valid )
  2676. {
  2677. m_subShaderModule.CullModeHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2678. }
  2679. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.CullModeData.DataCheck == TemplateDataCheck.Valid )
  2680. {
  2681. m_passModule.CullModeHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2682. }
  2683. //COLOR MASK
  2684. if( m_templateMultiPass.SubShaders[ 0 ].Modules.ColorMaskData.DataCheck == TemplateDataCheck.Valid )
  2685. {
  2686. m_subShaderModule.ColorMaskHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2687. }
  2688. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.ColorMaskData.DataCheck == TemplateDataCheck.Valid )
  2689. {
  2690. m_passModule.ColorMaskHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2691. }
  2692. //STENCIL BUFFER
  2693. if( m_templateMultiPass.SubShaders[ 0 ].Modules.StencilData.DataCheck == TemplateDataCheck.Valid )
  2694. {
  2695. m_subShaderModule.StencilBufferHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2696. }
  2697. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.StencilData.DataCheck == TemplateDataCheck.Valid )
  2698. {
  2699. m_passModule.StencilBufferHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2700. }
  2701. }
  2702. if( UIUtils.CurrentShaderVersion() > 14202 )
  2703. {
  2704. //DEPTH OPTIONS
  2705. if( m_templateMultiPass.SubShaders[ 0 ].Modules.DepthData.ValidZWrite )
  2706. {
  2707. m_subShaderModule.DepthOphelper.ReadZWriteFromString( ref m_currentReadParamIdx, ref nodeParams );
  2708. }
  2709. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.DepthData.ValidZWrite )
  2710. {
  2711. m_passModule.DepthOphelper.ReadZWriteFromString( ref m_currentReadParamIdx, ref nodeParams );
  2712. }
  2713. if( m_templateMultiPass.SubShaders[ 0 ].Modules.DepthData.ValidZTest )
  2714. {
  2715. m_subShaderModule.DepthOphelper.ReadZTestFromString( ref m_currentReadParamIdx, ref nodeParams );
  2716. }
  2717. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.DepthData.ValidZTest )
  2718. {
  2719. m_subShaderModule.DepthOphelper.ReadZTestFromString( ref m_currentReadParamIdx, ref nodeParams );
  2720. }
  2721. if( m_templateMultiPass.SubShaders[ 0 ].Modules.DepthData.ValidOffset )
  2722. {
  2723. m_subShaderModule.DepthOphelper.ReadOffsetFromString( ref m_currentReadParamIdx, ref nodeParams );
  2724. }
  2725. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.DepthData.ValidOffset )
  2726. {
  2727. m_passModule.DepthOphelper.ReadOffsetFromString( ref m_currentReadParamIdx, ref nodeParams );
  2728. }
  2729. }
  2730. //TAGS
  2731. if( UIUtils.CurrentShaderVersion() > 14301 )
  2732. {
  2733. if( m_templateMultiPass.SubShaders[ 0 ].Modules.TagData.DataCheck == TemplateDataCheck.Valid )
  2734. {
  2735. m_subShaderModule.TagsHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2736. }
  2737. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.TagData.DataCheck == TemplateDataCheck.Valid )
  2738. {
  2739. m_passModule.TagsHelper.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2740. }
  2741. }
  2742. SamplingMacros = false;
  2743. }
  2744. catch( Exception e )
  2745. {
  2746. Debug.LogException( e, this );
  2747. }
  2748. m_containerGraph.CurrentCanvasMode = NodeAvailability.TemplateShader;
  2749. }
  2750. public void ForceOptionsRefresh()
  2751. {
  2752. m_passOptions.Refresh();
  2753. if( m_isMainOutputNode )
  2754. m_subShaderOptions.Refresh();
  2755. }
  2756. public void SetPassVisible( string passName, bool visible )
  2757. {
  2758. TemplateMultiPassMasterNode node = m_containerGraph.GetMasterNodeOfPass( passName, m_lodIndex );
  2759. if( node != null )
  2760. {
  2761. m_passSelector.SetPassVisible( passName, visible );
  2762. node.IsInvisible = !visible;
  2763. }
  2764. }
  2765. public override void RefreshExternalReferences()
  2766. {
  2767. if( m_invalidNode )
  2768. return;
  2769. base.RefreshExternalReferences();
  2770. if( IsLODMainMasterNode )
  2771. {
  2772. SetMasterNodeCategoryFromGUID( m_templateGUID );
  2773. }
  2774. CheckTemplateChanges();
  2775. if( m_templateMultiPass != null && m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBRHD && UIUtils.CurrentShaderVersion() < 15410 )
  2776. {
  2777. FetchHDPorts();
  2778. m_hdSrpMaterialType = ( m_specularPort != null && m_specularPort.HasOwnOrLinkConnection ) ? HDSRPMaterialType.Specular : HDSRPMaterialType.Standard;
  2779. ConfigHDPorts();
  2780. }
  2781. if( ContainerGraph.HasLODs )
  2782. {
  2783. SetClippedAdditionalTitle( string.Format( LodSubtitle, ShaderLOD ) );
  2784. }
  2785. if( m_isMainOutputNode )
  2786. {
  2787. List<TemplateMultiPassMasterNode> masterNodes = ( m_lodIndex == -1 ) ? m_containerGraph.MultiPassMasterNodes.NodesList : m_containerGraph.LodMultiPassMasternodes[ m_lodIndex ].NodesList;
  2788. masterNodes.Sort( ( x, y ) => ( x.PassIdx.CompareTo( y.PassIdx ) ));
  2789. int passAmount = m_templateMultiPass.SubShaders[ m_subShaderIdx ].PassAmount;
  2790. if( passAmount != masterNodes.Count )
  2791. {
  2792. UIUtils.ShowMessage( "Template master nodes amount was modified. Could not set correctly its visibility options." );
  2793. }
  2794. else
  2795. {
  2796. for( int i = 0; i < passAmount; i++ )
  2797. {
  2798. if( i != m_passIdx )
  2799. {
  2800. masterNodes[ i ].IsInvisible = !m_passSelector.IsVisible( i );
  2801. }
  2802. }
  2803. }
  2804. }
  2805. }
  2806. public override void ReadInputDataFromString( ref string[] nodeParams )
  2807. {
  2808. //For a Template Master Node an input port data must be set by its template and not meta data
  2809. if( UIUtils.CurrentShaderVersion() > 17007 )
  2810. return;
  2811. int count = 0;
  2812. if( UIUtils.CurrentShaderVersion() > 7003 )
  2813. {
  2814. try
  2815. {
  2816. count = Convert.ToInt32( nodeParams[ m_currentReadParamIdx++ ] );
  2817. }
  2818. catch( Exception e )
  2819. {
  2820. Debug.LogException( e );
  2821. }
  2822. }
  2823. else
  2824. {
  2825. count = ( m_oldInputCount < 0 ) ? m_inputPorts.Count : m_oldInputCount;
  2826. }
  2827. for( int i = 0; i < count && i < nodeParams.Length && m_currentReadParamIdx < nodeParams.Length; i++ )
  2828. {
  2829. if( UIUtils.CurrentShaderVersion() < 5003 )
  2830. {
  2831. int newId = VersionConvertInputPortId( i );
  2832. if( UIUtils.CurrentShaderVersion() > 23 )
  2833. {
  2834. m_currentReadParamIdx++;
  2835. }
  2836. m_currentReadParamIdx++;
  2837. if( m_inputPorts[ newId ].IsEditable && UIUtils.CurrentShaderVersion() >= 3100 && m_currentReadParamIdx < nodeParams.Length )
  2838. {
  2839. m_currentReadParamIdx++;
  2840. }
  2841. }
  2842. else
  2843. {
  2844. m_currentReadParamIdx++;
  2845. m_currentReadParamIdx++;
  2846. m_currentReadParamIdx++;
  2847. bool isEditable = Convert.ToBoolean( nodeParams[ m_currentReadParamIdx++ ] );
  2848. if( isEditable && m_currentReadParamIdx < nodeParams.Length )
  2849. {
  2850. m_currentReadParamIdx++;
  2851. }
  2852. }
  2853. }
  2854. }
  2855. //For a Template Master Node an input port data must be set by its template and not meta data
  2856. public override void WriteInputDataToString( ref string nodeInfo ) { }
  2857. public override float HeightEstimate
  2858. {
  2859. get
  2860. {
  2861. float heightEstimate = 0;
  2862. heightEstimate = 32 + Constants.INPUT_PORT_DELTA_Y;
  2863. if( m_templateMultiPass != null && !m_templateMultiPass.IsSinglePass )
  2864. {
  2865. heightEstimate += 22;
  2866. }
  2867. float internalPortSize = 0;
  2868. for( int i = 0; i < InputPorts.Count; i++ )
  2869. {
  2870. if( InputPorts[ i ].Visible )
  2871. internalPortSize += 18 + Constants.INPUT_PORT_DELTA_Y;
  2872. }
  2873. return heightEstimate + Mathf.Max( internalPortSize, m_insideSize.y );
  2874. }
  2875. }
  2876. public HDSRPMaterialType CurrentHDMaterialType
  2877. {
  2878. get { return m_hdSrpMaterialType; }
  2879. set
  2880. {
  2881. m_hdSrpMaterialType = value;
  2882. if( m_isMainOutputNode )
  2883. {
  2884. List<TemplateMultiPassMasterNode> mpNodes = UIUtils.CurrentWindow.CurrentGraph.MultiPassMasterNodes.NodesList;
  2885. int count = mpNodes.Count;
  2886. for( int i = 0; i < count; i++ )
  2887. {
  2888. if( mpNodes[ i ].UniqueId != UniqueId )
  2889. {
  2890. mpNodes[ i ].CurrentHDMaterialType = value;
  2891. }
  2892. }
  2893. }
  2894. }
  2895. }
  2896. public TemplateSubShader SubShader { get { return m_templateMultiPass.SubShaders[ m_subShaderIdx ]; } }
  2897. public TemplatePass Pass { get { return m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ]; } }
  2898. public int SubShaderIdx { get { return m_subShaderIdx; } }
  2899. public int PassIdx { get { return m_passIdx; } }
  2900. public TemplateMultiPass CurrentTemplate { get { return m_templateMultiPass; } }
  2901. public TemplateModulesHelper SubShaderModule { get { return m_subShaderModule; } }
  2902. public TemplateModulesHelper PassModule { get { return m_passModule; } }
  2903. public string PassName { get { return m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].PassNameContainer.Data; } }
  2904. public string PassUniqueName
  2905. {
  2906. get
  2907. {
  2908. return string.IsNullOrEmpty( m_passUniqueId ) ? m_originalPassName : m_passUniqueId;
  2909. }
  2910. }
  2911. public string OriginalPassName { get { return m_originalPassName; } }
  2912. public bool HasLinkPorts { get { return m_hasLinkPorts; } }
  2913. public bool IsInvisible
  2914. {
  2915. get
  2916. {
  2917. return m_isInvisible != InvisibilityStatus.Visible;
  2918. }
  2919. set
  2920. {
  2921. if( m_isInvisible != InvisibilityStatus.LockedInvisible && !m_isMainOutputNode )
  2922. {
  2923. m_isInvisible = value ? InvisibilityStatus.Invisible : InvisibilityStatus.Visible;
  2924. if( value )
  2925. {
  2926. for( int i = 0; i < m_inputPorts.Count; i++ )
  2927. {
  2928. m_inputPorts[ i ].FullDeleteConnections();
  2929. }
  2930. }
  2931. }
  2932. }
  2933. }
  2934. public TemplatePassSelectorHelper PassSelector { get { return m_passSelector; } }
  2935. public TemplateOptionsUIHelper PassOptions { get { return m_passOptions; } }
  2936. public TemplateOptionsUIHelper SubShaderOptions { get { return m_subShaderOptions; } }
  2937. public TemplateOptionsDefinesContainer OptionsDefineContainer { get { return m_optionsDefineContainer; } }
  2938. public TerrainDrawInstancedHelper DrawInstancedHelperInstance { get { return m_drawInstancedHelper; } }
  2939. public bool InvalidNode { get { return m_invalidNode; } }
  2940. public override void SetName( string name )
  2941. {
  2942. ShaderName = name;
  2943. }
  2944. public bool IsLODMainFirstPass { get { return m_passIdx == 0 && m_lodIndex == -1; } }
  2945. }
  2946. }