TemplateMultiPassMasterNode.cs 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633
  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. ContainerGraph.ParentWindow.DuplicatePrevBufferInstance.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 = ContainerGraph.ParentWindow.DuplicatePrevBufferInstance.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. CheckLegacyCustomInspectors();
  402. if( m_isMainOutputNode )
  403. {
  404. m_passSelector.Clear();
  405. m_passSelector.Setup( m_templateMultiPass.SubShaders[ m_subShaderIdx ] );
  406. }
  407. }
  408. else
  409. {
  410. //Hotcode reload or ReadFromString
  411. // Setup is only made if internal pass array is null
  412. if( m_isMainOutputNode )
  413. {
  414. m_passSelector.Setup( m_templateMultiPass.SubShaders[ m_subShaderIdx ] );
  415. }
  416. }
  417. SetupCustomOptionsFromTemplate( template != null );
  418. if( string.IsNullOrEmpty( m_fallbackHelper.RawFallbackShader ) )
  419. m_fallbackHelper.RawFallbackShader = m_templateMultiPass.FallbackContainer.Data;
  420. //bool updateInfofromTemplate = UpdatePortInfo();
  421. //if( updateInfofromTemplate )
  422. //{
  423. m_subShaderModule.FetchDataFromTemplate( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules );
  424. m_passModule.FetchDataFromTemplate( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules );
  425. //}
  426. //RegisterProperties();
  427. if( writeDefaultData )
  428. {
  429. //ShaderName = m_templateMultiPass.DefaultShaderName;
  430. ShaderName = m_shaderName;
  431. m_passName = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].PassNameContainer.Data;
  432. if( !m_templateMultiPass.IsSinglePass /*&& !m_shaderNameIsTitle*/ )
  433. {
  434. if( m_templateMultiPass.SubShaders[ 0 ].MainPass != m_passIdx )
  435. SetClippedTitle( m_passName );
  436. }
  437. }
  438. UpdateSubShaderPassStr();
  439. if( m_isMainOutputNode )
  440. m_fireTemplateChange = true;
  441. }
  442. else
  443. {
  444. m_invalidNode = true;
  445. }
  446. }
  447. public override void OnRefreshLinkedPortsComplete()
  448. {
  449. if( m_invalidNode )
  450. return;
  451. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBRHD )
  452. ConfigHDPorts();
  453. SetReadOptions();
  454. }
  455. public void SetReadOptions()
  456. {
  457. m_passOptions.SetReadOptions();
  458. if( m_isMainOutputNode )
  459. m_subShaderOptions.SetReadOptions();
  460. }
  461. bool UpdatePortInfo()
  462. {
  463. List<TemplateInputData> inputDataList = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].InputDataList;
  464. int count = inputDataList.Count;
  465. if( count != m_inputPorts.Count )
  466. {
  467. DeleteAllInputConnections( true );
  468. for( int i = 0 ; i < count ; i++ )
  469. {
  470. InputPort port = AddInputPort( inputDataList[ i ].DataType , false , inputDataList[ i ].PortName , inputDataList[ i ].OrderId , inputDataList[ i ].PortCategory , inputDataList[ i ].PortUniqueId );
  471. port.ExternalLinkId = inputDataList[ i ].LinkId;
  472. m_hasLinkPorts = m_hasLinkPorts || !string.IsNullOrEmpty( inputDataList[ i ].LinkId );
  473. }
  474. return true;
  475. }
  476. else
  477. {
  478. for( int i = 0 ; i < count ; i++ )
  479. {
  480. m_inputPorts[ i ].ChangeProperties( inputDataList[ i ].PortName , inputDataList[ i ].DataType , false );
  481. m_inputPorts[ i ].ExternalLinkId = inputDataList[ i ].LinkId;
  482. }
  483. return false;
  484. }
  485. }
  486. public void SetPropertyActionFromItem( bool actionFromUser , TemplateModulesHelper module , TemplateActionItem item )
  487. {
  488. // 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
  489. if( !m_isMainOutputNode && m_mainMasterNodeRef == null )
  490. {
  491. m_mainMasterNodeRef = m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  492. }
  493. TemplateModulesHelper subShaderModule = m_isMainOutputNode ? m_subShaderModule : m_mainMasterNodeRef.SubShaderModule;
  494. switch( item.PropertyAction )
  495. {
  496. case PropertyActionsEnum.CullMode:
  497. {
  498. if( item.CopyFromSubShader )
  499. {
  500. module.CullModeHelper.CurrentCullMode = subShaderModule.CullModeHelper.CurrentCullMode;
  501. }
  502. else
  503. {
  504. bool performAction = !ContainerGraph.IsLoading || !module.CullModeHelper.CustomEdited;
  505. if( performAction )
  506. {
  507. module.CullModeHelper.CustomEdited = false;
  508. module.CullModeHelper.CurrentCullMode = item.ActionCullMode;
  509. }
  510. }
  511. }
  512. break;
  513. case PropertyActionsEnum.ColorMask:
  514. {
  515. if( item.CopyFromSubShader )
  516. module.ColorMaskHelper.ColorMask = subShaderModule.ColorMaskHelper.ColorMask;
  517. else
  518. {
  519. bool performAction = !ContainerGraph.IsLoading || !module.ColorMaskHelper.CustomEdited;
  520. if( performAction )
  521. {
  522. module.ColorMaskHelper.CustomEdited = false;
  523. module.ColorMaskHelper.ColorMask = item.ColorMask.GetColorMask( module.ColorMaskHelper.ColorMask );
  524. }
  525. }
  526. }
  527. break;
  528. case PropertyActionsEnum.ColorMask1:
  529. {
  530. if( item.CopyFromSubShader )
  531. module.ColorMaskHelper1.ColorMask = subShaderModule.ColorMaskHelper1.ColorMask;
  532. else
  533. {
  534. bool performAction = !ContainerGraph.IsLoading || !module.ColorMaskHelper1.CustomEdited;
  535. if( performAction )
  536. {
  537. module.ColorMaskHelper1.CustomEdited = false;
  538. module.ColorMaskHelper1.ColorMask = item.ColorMask1.GetColorMask( module.ColorMaskHelper1.ColorMask );
  539. }
  540. }
  541. }
  542. break;
  543. case PropertyActionsEnum.ColorMask2:
  544. {
  545. if( item.CopyFromSubShader )
  546. module.ColorMaskHelper2.ColorMask = subShaderModule.ColorMaskHelper2.ColorMask;
  547. else
  548. {
  549. bool performAction = !ContainerGraph.IsLoading || !module.ColorMaskHelper2.CustomEdited;
  550. if( performAction )
  551. {
  552. module.ColorMaskHelper2.CustomEdited = false;
  553. module.ColorMaskHelper2.ColorMask = item.ColorMask2.GetColorMask( module.ColorMaskHelper2.ColorMask );
  554. }
  555. }
  556. }
  557. break;
  558. case PropertyActionsEnum.ColorMask3:
  559. {
  560. if( item.CopyFromSubShader )
  561. module.ColorMaskHelper3.ColorMask = subShaderModule.ColorMaskHelper3.ColorMask;
  562. else
  563. {
  564. bool performAction = !ContainerGraph.IsLoading || !module.ColorMaskHelper3.CustomEdited;
  565. if( performAction )
  566. {
  567. module.ColorMaskHelper3.CustomEdited = false;
  568. module.ColorMaskHelper3.ColorMask = item.ColorMask3.GetColorMask( module.ColorMaskHelper3.ColorMask );
  569. }
  570. }
  571. }
  572. break;
  573. case PropertyActionsEnum.ZWrite:
  574. {
  575. if( item.CopyFromSubShader )
  576. {
  577. module.DepthOphelper.ZWriteModeValue = subShaderModule.DepthOphelper.ZWriteModeValue;
  578. }
  579. else
  580. {
  581. bool performAction = !ContainerGraph.IsLoading || !module.DepthOphelper.CustomEdited;
  582. if( performAction )
  583. {
  584. module.DepthOphelper.CustomEdited = false;
  585. module.DepthOphelper.ZWriteModeValue = item.ActionZWrite;
  586. }
  587. }
  588. }
  589. break;
  590. case PropertyActionsEnum.ZTest:
  591. {
  592. if( item.CopyFromSubShader )
  593. {
  594. module.DepthOphelper.ZTestModeValue = subShaderModule.DepthOphelper.ZTestModeValue;
  595. }
  596. else
  597. {
  598. bool performAction = !ContainerGraph.IsLoading || !module.DepthOphelper.CustomEdited;
  599. if( performAction )
  600. {
  601. module.DepthOphelper.CustomEdited = false;
  602. module.DepthOphelper.ZTestModeValue = item.ActionZTest;
  603. }
  604. }
  605. }
  606. break;
  607. case PropertyActionsEnum.ZOffsetFactor:
  608. {
  609. if( item.CopyFromSubShader )
  610. {
  611. module.DepthOphelper.OffsetFactorValue = subShaderModule.DepthOphelper.OffsetFactorValue;
  612. }
  613. else
  614. {
  615. bool performAction = !ContainerGraph.IsLoading || !module.DepthOphelper.CustomEdited;
  616. if( performAction )
  617. {
  618. module.DepthOphelper.CustomEdited = false;
  619. module.DepthOphelper.OffsetFactorValue = item.ActionZOffsetFactor;
  620. }
  621. }
  622. }
  623. break;
  624. case PropertyActionsEnum.ZOffsetUnits:
  625. {
  626. if( item.CopyFromSubShader )
  627. {
  628. module.DepthOphelper.OffsetUnitsValue = subShaderModule.DepthOphelper.OffsetUnitsValue;
  629. }
  630. else
  631. {
  632. bool performAction = !ContainerGraph.IsLoading || !module.DepthOphelper.CustomEdited;
  633. if( performAction )
  634. {
  635. module.DepthOphelper.CustomEdited = false;
  636. module.DepthOphelper.OffsetUnitsValue = item.ActionZOffsetUnits;
  637. }
  638. }
  639. }
  640. break;
  641. case PropertyActionsEnum.BlendRGB:
  642. {
  643. if( item.CopyFromSubShader )
  644. {
  645. module.BlendOpHelper.SourceFactorRGB = subShaderModule.BlendOpHelper.SourceFactorRGB;
  646. module.BlendOpHelper.DestFactorRGB = subShaderModule.BlendOpHelper.DestFactorRGB;
  647. }
  648. else
  649. {
  650. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper.CustomEdited;
  651. if( performAction )
  652. {
  653. module.BlendOpHelper.CustomEdited = false;
  654. module.BlendOpHelper.SourceFactorRGB = item.ActionBlendRGBSource;
  655. module.BlendOpHelper.DestFactorRGB = item.ActionBlendRGBDest;
  656. }
  657. }
  658. }
  659. break;
  660. case PropertyActionsEnum.BlendRGB1:
  661. {
  662. if( item.CopyFromSubShader )
  663. {
  664. module.BlendOpHelper1.SourceFactorRGB = subShaderModule.BlendOpHelper1.SourceFactorRGB;
  665. module.BlendOpHelper1.DestFactorRGB = subShaderModule.BlendOpHelper1.DestFactorRGB;
  666. }
  667. else
  668. {
  669. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper1.CustomEdited;
  670. if( performAction )
  671. {
  672. module.BlendOpHelper1.CustomEdited = false;
  673. module.BlendOpHelper1.SourceFactorRGB = item.ActionBlendRGBSource1;
  674. module.BlendOpHelper1.DestFactorRGB = item.ActionBlendRGBDest1;
  675. }
  676. }
  677. }
  678. break;
  679. case PropertyActionsEnum.BlendRGB2:
  680. {
  681. if( item.CopyFromSubShader )
  682. {
  683. module.BlendOpHelper2.SourceFactorRGB = subShaderModule.BlendOpHelper2.SourceFactorRGB;
  684. module.BlendOpHelper2.DestFactorRGB = subShaderModule.BlendOpHelper2.DestFactorRGB;
  685. }
  686. else
  687. {
  688. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper2.CustomEdited;
  689. if( performAction )
  690. {
  691. module.BlendOpHelper2.CustomEdited = false;
  692. module.BlendOpHelper2.SourceFactorRGB = item.ActionBlendRGBSource2;
  693. module.BlendOpHelper2.DestFactorRGB = item.ActionBlendRGBDest2;
  694. }
  695. }
  696. }
  697. break;
  698. case PropertyActionsEnum.BlendRGB3:
  699. {
  700. if( item.CopyFromSubShader )
  701. {
  702. module.BlendOpHelper3.SourceFactorRGB = subShaderModule.BlendOpHelper3.SourceFactorRGB;
  703. module.BlendOpHelper3.DestFactorRGB = subShaderModule.BlendOpHelper3.DestFactorRGB;
  704. }
  705. else
  706. {
  707. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper3.CustomEdited;
  708. if( performAction )
  709. {
  710. module.BlendOpHelper3.CustomEdited = false;
  711. module.BlendOpHelper3.SourceFactorRGB = item.ActionBlendRGBSource3;
  712. module.BlendOpHelper3.DestFactorRGB = item.ActionBlendRGBDest3;
  713. }
  714. }
  715. }
  716. break;
  717. case PropertyActionsEnum.BlendAlpha:
  718. {
  719. if( item.CopyFromSubShader )
  720. {
  721. module.BlendOpHelper.SourceFactorAlpha = subShaderModule.BlendOpHelper.SourceFactorAlpha;
  722. module.BlendOpHelper.DestFactorAlpha = subShaderModule.BlendOpHelper.DestFactorAlpha;
  723. }
  724. else
  725. {
  726. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper.CustomEdited;
  727. if( performAction )
  728. {
  729. module.BlendOpHelper.CustomEdited = false;
  730. module.BlendOpHelper.CurrentAlphaIndex = 1;
  731. module.BlendOpHelper.SourceFactorAlpha = item.ActionBlendAlphaSource;
  732. module.BlendOpHelper.DestFactorAlpha = item.ActionBlendAlphaDest;
  733. }
  734. }
  735. }
  736. break;
  737. case PropertyActionsEnum.BlendAlpha1:
  738. {
  739. if( item.CopyFromSubShader )
  740. {
  741. module.BlendOpHelper1.SourceFactorAlpha = subShaderModule.BlendOpHelper1.SourceFactorAlpha;
  742. module.BlendOpHelper1.DestFactorAlpha = subShaderModule.BlendOpHelper1.DestFactorAlpha;
  743. }
  744. else
  745. {
  746. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper1.CustomEdited;
  747. if( performAction )
  748. {
  749. module.BlendOpHelper1.CustomEdited = false;
  750. module.BlendOpHelper1.CurrentAlphaIndex = 1;
  751. module.BlendOpHelper1.SourceFactorAlpha = item.ActionBlendAlphaSource1;
  752. module.BlendOpHelper1.DestFactorAlpha = item.ActionBlendAlphaDest1;
  753. }
  754. }
  755. }
  756. break;
  757. case PropertyActionsEnum.BlendAlpha2:
  758. {
  759. if( item.CopyFromSubShader )
  760. {
  761. module.BlendOpHelper2.SourceFactorAlpha = subShaderModule.BlendOpHelper2.SourceFactorAlpha;
  762. module.BlendOpHelper2.DestFactorAlpha = subShaderModule.BlendOpHelper2.DestFactorAlpha;
  763. }
  764. else
  765. {
  766. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper2.CustomEdited;
  767. if( performAction )
  768. {
  769. module.BlendOpHelper2.CustomEdited = false;
  770. module.BlendOpHelper2.CurrentAlphaIndex = 1;
  771. module.BlendOpHelper2.SourceFactorAlpha = item.ActionBlendAlphaSource2;
  772. module.BlendOpHelper2.DestFactorAlpha = item.ActionBlendAlphaDest2;
  773. }
  774. }
  775. }
  776. break;
  777. case PropertyActionsEnum.BlendAlpha3:
  778. {
  779. if( item.CopyFromSubShader )
  780. {
  781. module.BlendOpHelper3.SourceFactorAlpha = subShaderModule.BlendOpHelper3.SourceFactorAlpha;
  782. module.BlendOpHelper3.DestFactorAlpha = subShaderModule.BlendOpHelper3.DestFactorAlpha;
  783. }
  784. else
  785. {
  786. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper3.CustomEdited;
  787. if( performAction )
  788. {
  789. module.BlendOpHelper3.CustomEdited = false;
  790. module.BlendOpHelper3.CurrentAlphaIndex = 1;
  791. module.BlendOpHelper3.SourceFactorAlpha = item.ActionBlendAlphaSource3;
  792. module.BlendOpHelper3.DestFactorAlpha = item.ActionBlendAlphaDest3;
  793. }
  794. }
  795. }
  796. break;
  797. case PropertyActionsEnum.BlendOpRGB:
  798. {
  799. if( item.CopyFromSubShader )
  800. {
  801. module.BlendOpHelper.BlendOpRGB = subShaderModule.BlendOpHelper.BlendOpRGB;
  802. }
  803. else
  804. {
  805. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper.CustomEdited;
  806. if( performAction )
  807. {
  808. module.BlendOpHelper.CustomEdited = false;
  809. module.BlendOpHelper.BlendOpRGB = item.ActionBlendOpRGB;
  810. }
  811. }
  812. }
  813. break;
  814. case PropertyActionsEnum.BlendOpAlpha:
  815. {
  816. if( item.CopyFromSubShader )
  817. {
  818. module.BlendOpHelper.BlendOpAlpha = subShaderModule.BlendOpHelper.BlendOpAlpha;
  819. }
  820. else
  821. {
  822. bool performAction = !ContainerGraph.IsLoading || !module.BlendOpHelper.CustomEdited;
  823. if( performAction )
  824. {
  825. module.BlendOpHelper.CustomEdited = false;
  826. module.BlendOpHelper.BlendOpAlpha = item.ActionBlendOpAlpha;
  827. }
  828. }
  829. }
  830. break;
  831. case PropertyActionsEnum.StencilReference:
  832. {
  833. if( item.CopyFromSubShader )
  834. {
  835. module.StencilBufferHelper.ReferenceValue = subShaderModule.StencilBufferHelper.ReferenceValue;
  836. }
  837. else
  838. {
  839. bool performAction = !ContainerGraph.IsLoading || !module.StencilBufferHelper.CustomEdited;
  840. if( performAction )
  841. {
  842. module.StencilBufferHelper.CustomEdited = false;
  843. module.StencilBufferHelper.ReferenceValue = item.ActionStencilReference;
  844. }
  845. }
  846. }
  847. break;
  848. case PropertyActionsEnum.StencilReadMask:
  849. {
  850. if( item.CopyFromSubShader )
  851. {
  852. module.StencilBufferHelper.ReadMaskValue = subShaderModule.StencilBufferHelper.ReadMaskValue;
  853. }
  854. else
  855. {
  856. bool performAction = !ContainerGraph.IsLoading || !module.StencilBufferHelper.CustomEdited;
  857. if( performAction )
  858. {
  859. module.StencilBufferHelper.CustomEdited = false;
  860. module.StencilBufferHelper.ReadMaskValue = item.ActionStencilReadMask;
  861. }
  862. }
  863. }
  864. break;
  865. case PropertyActionsEnum.StencilWriteMask:
  866. {
  867. if( item.CopyFromSubShader )
  868. {
  869. module.StencilBufferHelper.WriteMaskValue = subShaderModule.StencilBufferHelper.WriteMaskValue;
  870. }
  871. else
  872. {
  873. bool performAction = !ContainerGraph.IsLoading || !module.StencilBufferHelper.CustomEdited;
  874. if( performAction )
  875. {
  876. module.StencilBufferHelper.CustomEdited = false;
  877. module.StencilBufferHelper.WriteMaskValue = item.ActionStencilWriteMask;
  878. }
  879. }
  880. }
  881. break;
  882. case PropertyActionsEnum.StencilComparison:
  883. {
  884. if( item.CopyFromSubShader )
  885. {
  886. module.StencilBufferHelper.ComparisonFunctionIdxValue = subShaderModule.StencilBufferHelper.ComparisonFunctionIdxValue;
  887. }
  888. else
  889. {
  890. bool performAction = !ContainerGraph.IsLoading || !module.StencilBufferHelper.CustomEdited;
  891. if( performAction )
  892. {
  893. module.StencilBufferHelper.CustomEdited = false;
  894. module.StencilBufferHelper.ComparisonFunctionIdxValue = item.ActionStencilComparison;
  895. }
  896. }
  897. }
  898. break;
  899. case PropertyActionsEnum.StencilPass:
  900. {
  901. if( item.CopyFromSubShader )
  902. {
  903. module.StencilBufferHelper.PassStencilOpIdxValue = subShaderModule.StencilBufferHelper.PassStencilOpIdxValue;
  904. }
  905. else
  906. {
  907. bool performAction = !ContainerGraph.IsLoading || !module.StencilBufferHelper.CustomEdited;
  908. if( performAction )
  909. {
  910. module.StencilBufferHelper.CustomEdited = false;
  911. module.StencilBufferHelper.PassStencilOpIdxValue = item.ActionStencilPass;
  912. }
  913. }
  914. }
  915. break;
  916. case PropertyActionsEnum.StencilFail:
  917. {
  918. if( item.CopyFromSubShader )
  919. {
  920. module.StencilBufferHelper.FailStencilOpIdxValue = subShaderModule.StencilBufferHelper.FailStencilOpIdxValue;
  921. }
  922. else
  923. {
  924. bool performAction = !ContainerGraph.IsLoading || !module.StencilBufferHelper.CustomEdited;
  925. if( performAction )
  926. {
  927. module.StencilBufferHelper.CustomEdited = false;
  928. module.StencilBufferHelper.FailStencilOpIdxValue = item.ActionStencilFail;
  929. }
  930. }
  931. }
  932. break;
  933. case PropertyActionsEnum.StencilZFail:
  934. {
  935. if( item.CopyFromSubShader )
  936. {
  937. module.StencilBufferHelper.ZFailStencilOpIdxValue = subShaderModule.StencilBufferHelper.ZFailStencilOpIdxValue;
  938. }
  939. else
  940. {
  941. bool performAction = !ContainerGraph.IsLoading || !module.StencilBufferHelper.CustomEdited;
  942. if( performAction )
  943. {
  944. module.StencilBufferHelper.CustomEdited = false;
  945. module.StencilBufferHelper.ZFailStencilOpIdxValue = item.ActionStencilZFail;
  946. }
  947. }
  948. }
  949. break;
  950. case PropertyActionsEnum.RenderType:
  951. {
  952. module.TagsHelper.AddSpecialTag( TemplateSpecialTags.RenderType , item );
  953. }
  954. break;
  955. case PropertyActionsEnum.RenderQueue:
  956. {
  957. module.TagsHelper.AddSpecialTag( TemplateSpecialTags.Queue , item );
  958. }
  959. break;
  960. case PropertyActionsEnum.DisableBatching:
  961. {
  962. module.TagsHelper.AddSpecialTag( TemplateSpecialTags.DisableBatching , item );
  963. }
  964. break;
  965. case PropertyActionsEnum.ChangeTagValue:
  966. {
  967. module.TagsHelper.ChangeTagValue( item.ActionData , item.ActionBuffer );
  968. }
  969. break;
  970. }
  971. }
  972. public void OnCustomPassOptionSelected( bool actionFromUser , bool isRefreshing , bool invertAction , TemplateOptionUIItem uiItem , int recursionLevel, params TemplateActionItem[] validActions )
  973. {
  974. m_passOptions.OnCustomOptionSelected( actionFromUser , isRefreshing , invertAction , this , uiItem , recursionLevel, validActions );
  975. }
  976. public void OnCustomSubShaderOptionSelected( bool actionFromUser , bool isRefreshing , bool invertAction , TemplateOptionUIItem uiItem , int recursionLevel, params TemplateActionItem[] validActions )
  977. {
  978. if( m_isMainOutputNode )
  979. m_subShaderOptions.OnCustomOptionSelected( actionFromUser , isRefreshing , invertAction , this , uiItem , recursionLevel, validActions );
  980. }
  981. void SetupCustomOptionsFromTemplate( bool newTemplate )
  982. {
  983. m_passOptions.SetupCustomOptionsFromTemplate( this , newTemplate );
  984. if( m_isMainOutputNode )
  985. m_subShaderOptions.SetupCustomOptionsFromTemplate( this , newTemplate );
  986. }
  987. void SetPassCustomOptionsInfo( TemplateMultiPassMasterNode masterNode )
  988. {
  989. TemplateMultiPassMasterNode mainMasterNode = masterNode.IsMainOutputNode ? masterNode : ( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode );
  990. mainMasterNode.SubShaderOptions.SetSubShaderCustomOptionsPortsInfo( masterNode , ref m_currentDataCollector );
  991. masterNode.PassOptions.SetCustomOptionsInfo( masterNode , ref m_currentDataCollector );
  992. }
  993. void RefreshCustomOptionsDict()
  994. {
  995. m_passOptions.RefreshCustomOptionsDict();
  996. if( m_isMainOutputNode )
  997. m_subShaderOptions.RefreshCustomOptionsDict();
  998. }
  999. void SetCategoryIdxFromTemplate()
  1000. {
  1001. int templateCount = m_containerGraph.ParentWindow.TemplatesManagerInstance.TemplateCount;
  1002. for( int i = 0 ; i < templateCount ; i++ )
  1003. {
  1004. int idx = i + 1;
  1005. TemplateMultiPass templateData = m_containerGraph.ParentWindow.TemplatesManagerInstance.GetTemplate( i ) as TemplateMultiPass;
  1006. if( templateData != null && m_templateMultiPass != null && m_templateMultiPass.GUID.Equals( templateData.GUID ) )
  1007. m_masterNodeCategory = idx;
  1008. }
  1009. }
  1010. public void CheckTemplateChanges()
  1011. {
  1012. if( m_invalidNode )
  1013. return;
  1014. if( IsLODMainMasterNode )
  1015. {
  1016. if( m_containerGraph.MultiPassMasterNodes.Count != m_templateMultiPass.MasterNodesRequired )
  1017. {
  1018. if( m_availableCategories == null )
  1019. RefreshAvailableCategories();
  1020. if( DebugConsoleWindow.DeveloperMode )
  1021. Debug.Log( "Template Pass amount was changed. Rebuiling master nodes" );
  1022. m_containerGraph.ParentWindow.ReplaceMasterNode( m_availableCategories[ m_masterNodeCategory ] , true );
  1023. }
  1024. }
  1025. }
  1026. public override void OnNodeLogicUpdate( DrawInfo drawInfo )
  1027. {
  1028. if( m_invalidNode )
  1029. {
  1030. return;
  1031. }
  1032. base.OnNodeLogicUpdate( drawInfo );
  1033. if( m_templateMultiPass == null )
  1034. {
  1035. // Hotcode reload has happened
  1036. SetTemplate( null , false , true , m_subShaderIdx , m_passIdx , SetTemplateSource.HotCodeReload );
  1037. CheckTemplateChanges();
  1038. }
  1039. if( m_reRegisterTemplateData )
  1040. {
  1041. RegisterProperties();
  1042. }
  1043. if( m_fetchMasterNodeCategory )
  1044. {
  1045. if( m_availableCategories != null )
  1046. {
  1047. m_fetchMasterNodeCategory = false;
  1048. SetCategoryIdxFromTemplate();
  1049. }
  1050. }
  1051. if( m_fireTemplateChange )
  1052. {
  1053. m_fireTemplateChange = false;
  1054. m_containerGraph.FireMasterNodeReplacedEvent();
  1055. }
  1056. if( m_subShaderModule.HasValidData )
  1057. {
  1058. m_subShaderModule.OnLogicUpdate( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules );
  1059. }
  1060. if( m_passModule.HasValidData )
  1061. {
  1062. m_passModule.OnLogicUpdate( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules );
  1063. }
  1064. if( !m_isMainOutputNode && m_mainMasterNodeRef == null )
  1065. {
  1066. m_mainMasterNodeRef = m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  1067. }
  1068. if( m_refreshLODValueMasterNodes && ( EditorApplication.timeSinceStartup - m_refreshLODValueMasterNodesTimestamp ) > MaxLODEditTimestamp )
  1069. {
  1070. m_refreshLODValueMasterNodes = false;
  1071. m_refocusLODValueMasterNodes = true;
  1072. m_containerGraph.SortLODMasterNodes();
  1073. }
  1074. }
  1075. public override void Draw( DrawInfo drawInfo )
  1076. {
  1077. if( m_isInvisible == InvisibilityStatus.Visible )
  1078. {
  1079. base.Draw( drawInfo );
  1080. }
  1081. }
  1082. public override void OnNodeLayout( DrawInfo drawInfo )
  1083. {
  1084. if( m_invalidNode )
  1085. {
  1086. if( m_isMainOutputNode )
  1087. {
  1088. string newGUID = string.Empty;
  1089. if( m_containerGraph.ParentWindow.TemplatesManagerInstance.CheckIfDeprecated( m_templateGUID , out newGUID ) )
  1090. {
  1091. m_shaderModelIdx = 0;
  1092. SetMasterNodeCategoryFromGUID( newGUID );
  1093. m_containerGraph.ParentWindow.ReplaceMasterNode( m_availableCategories[ m_masterNodeCategory ] , false );
  1094. }
  1095. else
  1096. {
  1097. UIUtils.ShowMessage( "Invalid current template. Switching to Standard Surface" , MessageSeverity.Error );
  1098. m_shaderModelIdx = 0;
  1099. m_masterNodeCategory = 0;
  1100. m_containerGraph.ParentWindow.ReplaceMasterNode( new MasterNodeCategoriesData( AvailableShaderTypes.SurfaceShader , m_shaderName ) , false );
  1101. }
  1102. }
  1103. return;
  1104. }
  1105. if( m_isInvisible != InvisibilityStatus.Visible )
  1106. {
  1107. return;
  1108. }
  1109. if( !IsMainOutputNode )
  1110. {
  1111. if( !IsInvisible && Docking )
  1112. {
  1113. m_useSquareNodeTitle = true;
  1114. TemplateMultiPassMasterNode master = ContainerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  1115. m_position = master.TruePosition;
  1116. m_position.height = 32;
  1117. int masterIndex = ContainerGraph.MultiPassMasterNodes.NodesList.IndexOf( master );
  1118. int index = ContainerGraph.MultiPassMasterNodes.GetNodeRegisterIdx( UniqueId );
  1119. if( index > masterIndex )
  1120. {
  1121. int backTracking = 0;
  1122. for( int i = index - 1 ; i > masterIndex ; i-- )
  1123. {
  1124. if( !ContainerGraph.MultiPassMasterNodes.NodesList[ i ].IsInvisible && ContainerGraph.MultiPassMasterNodes.NodesList[ i ].Docking )
  1125. backTracking++;
  1126. }
  1127. m_position.y = master.TruePosition.yMax + 1 + 33 * ( backTracking );// ContainerGraph.MultiPassMasterNodes.NodesList[ index - 1 ].TruePosition.yMax;
  1128. base.OnNodeLayout( drawInfo );
  1129. }
  1130. else
  1131. {
  1132. int forwardTracking = 1;
  1133. for( int i = index + 1 ; i < masterIndex ; i++ )
  1134. {
  1135. if( !ContainerGraph.MultiPassMasterNodes.NodesList[ i ].IsInvisible && ContainerGraph.MultiPassMasterNodes.NodesList[ i ].Docking )
  1136. forwardTracking++;
  1137. }
  1138. m_position.y = master.TruePosition.y - 33 * ( forwardTracking );// ContainerGraph.MultiPassMasterNodes.NodesList[ index - 1 ].TruePosition.yMax;
  1139. base.OnNodeLayout( drawInfo );
  1140. }
  1141. }
  1142. else
  1143. {
  1144. m_useSquareNodeTitle = false;
  1145. base.OnNodeLayout( drawInfo );
  1146. }
  1147. }
  1148. else
  1149. {
  1150. base.OnNodeLayout( drawInfo );
  1151. }
  1152. }
  1153. public override void OnNodeRepaint( DrawInfo drawInfo )
  1154. {
  1155. base.OnNodeRepaint( drawInfo );
  1156. if( m_invalidNode )
  1157. return;
  1158. if( m_isInvisible == InvisibilityStatus.Visible )
  1159. {
  1160. if( m_containerGraph.IsInstancedShader )
  1161. {
  1162. DrawInstancedIcon( drawInfo );
  1163. }
  1164. }
  1165. }
  1166. public override void UpdateFromShader( Shader newShader )
  1167. {
  1168. if( m_currentMaterial != null && m_currentMaterial.shader != newShader )
  1169. {
  1170. m_currentMaterial.shader = newShader;
  1171. }
  1172. CurrentShader = newShader;
  1173. }
  1174. public override void UpdateMasterNodeMaterial( Material material )
  1175. {
  1176. m_currentMaterial = material;
  1177. FireMaterialChangedEvt();
  1178. }
  1179. void DrawReloadButton()
  1180. {
  1181. if( GUILayout.Button( ReloadTemplateStr ) && m_templateMultiPass != null )
  1182. {
  1183. m_templateMultiPass.Reload();
  1184. }
  1185. }
  1186. void DrawOpenTemplateButton()
  1187. {
  1188. GUILayout.BeginHorizontal();
  1189. {
  1190. if( GUILayout.Button( OpenTemplateStr ) && m_templateMultiPass != null )
  1191. {
  1192. try
  1193. {
  1194. string pathname = AssetDatabase.GUIDToAssetPath( m_templateMultiPass.GUID );
  1195. if( !string.IsNullOrEmpty( pathname ) )
  1196. {
  1197. Shader selectedTemplate = AssetDatabase.LoadAssetAtPath<Shader>( pathname );
  1198. if( selectedTemplate != null )
  1199. {
  1200. AssetDatabase.OpenAsset( selectedTemplate , 1 );
  1201. }
  1202. }
  1203. }
  1204. catch( Exception e )
  1205. {
  1206. Debug.LogException( e );
  1207. }
  1208. }
  1209. if( GUILayout.Button( "\u25C4" , GUILayout.Width( 18 ) , GUILayout.Height( 18 ) ) && m_templateMultiPass != null )
  1210. {
  1211. try
  1212. {
  1213. string pathname = AssetDatabase.GUIDToAssetPath( m_templateMultiPass.GUID );
  1214. if( !string.IsNullOrEmpty( pathname ) )
  1215. {
  1216. Shader selectedTemplate = AssetDatabase.LoadAssetAtPath<Shader>( pathname );
  1217. if( selectedTemplate != null )
  1218. {
  1219. Event.current.Use();
  1220. Selection.activeObject = selectedTemplate;
  1221. EditorGUIUtility.PingObject( Selection.activeObject );
  1222. }
  1223. }
  1224. }
  1225. catch( Exception e )
  1226. {
  1227. Debug.LogException( e );
  1228. }
  1229. }
  1230. }
  1231. GUILayout.EndHorizontal();
  1232. }
  1233. public override void DrawProperties()
  1234. {
  1235. base.DrawProperties();
  1236. if( m_invalidNode )
  1237. return;
  1238. NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout , CommonPropertiesStr , DrawCommonProperties );
  1239. NodeUtils.DrawPropertyGroup( ref m_subStringFoldout , SubShaderModuleStr , DrawSubShaderProperties );
  1240. NodeUtils.DrawPropertyGroup( ref m_passFoldout , PassModuleStr , DrawPassProperties );
  1241. DrawMaterialInputs( UIUtils.MenuItemToolbarStyle , false );
  1242. if( m_propertyOrderChanged )
  1243. {
  1244. List<TemplateMultiPassMasterNode> mpNodes = ContainerGraph.MultiPassMasterNodes.NodesList;
  1245. int count = mpNodes.Count;
  1246. for( int i = 0 ; i < count ; i++ )
  1247. {
  1248. if( mpNodes[ i ].UniqueId != UniqueId )
  1249. {
  1250. mpNodes[ i ].CopyPropertyListFrom( this );
  1251. }
  1252. }
  1253. }
  1254. #if SHOW_TEMPLATE_HELP_BOX
  1255. EditorGUILayout.HelpBox( WarningMessage, MessageType.Warning );
  1256. #endif
  1257. }
  1258. // this will be removed later when PBR options are created
  1259. void SetExtraDefine( string define )
  1260. {
  1261. List<TemplateMultiPassMasterNode> nodes = this.ContainerGraph.MultiPassMasterNodes.NodesList;
  1262. int count = nodes.Count;
  1263. for( int nodeIdx = 0 ; nodeIdx < count ; nodeIdx++ )
  1264. {
  1265. nodes[ nodeIdx ].OptionsDefineContainer.AddDirective( "#define " + define , false );
  1266. }
  1267. }
  1268. void AddHDKeywords()
  1269. {
  1270. if( m_templateMultiPass.CustomTemplatePropertyUI == CustomTemplatePropertyUIEnum.None )
  1271. return;
  1272. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType != TemplateSRPType.HDRP ||
  1273. !m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBR )
  1274. return;
  1275. switch( m_hdSrpMaterialType )
  1276. {
  1277. case HDSRPMaterialType.SubsurfaceScattering:
  1278. {
  1279. SetExtraDefine( SRPMaterialSubsurfaceScatteringKeyword );
  1280. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialSubsurfaceScatteringKeyword );
  1281. if( m_thicknessPort != null && m_thicknessPort.HasOwnOrLinkConnection )
  1282. {
  1283. SetExtraDefine( SRPMaterialTransmissionKeyword );
  1284. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialTransmissionKeyword );
  1285. }
  1286. }
  1287. break;
  1288. case HDSRPMaterialType.Standard:
  1289. break;
  1290. case HDSRPMaterialType.Specular:
  1291. {
  1292. SetExtraDefine( SRPHDMaterialSpecularKeyword );
  1293. //m_currentDataCollector.AddToDefines( UniqueId, SRPHDMaterialSpecularKeyword );
  1294. }
  1295. break;
  1296. case HDSRPMaterialType.Anisotropy:
  1297. {
  1298. SetExtraDefine( SRPMaterialAnisotropyKeyword );
  1299. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialAnisotropyKeyword );
  1300. }
  1301. break;
  1302. case HDSRPMaterialType.Iridescence:
  1303. {
  1304. SetExtraDefine( SRPMaterialIridiscenceKeyword );
  1305. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialIridiscenceKeyword );
  1306. }
  1307. break;
  1308. case HDSRPMaterialType.Translucent:
  1309. {
  1310. SetExtraDefine( SRPMaterialTransmissionKeyword );
  1311. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialTransmissionKeyword );
  1312. }
  1313. break;
  1314. }
  1315. if( m_coatMaskPort != null && m_coatMaskPort.HasOwnOrLinkConnection )
  1316. {
  1317. SetExtraDefine( SRPMaterialClearCoatKeyword );
  1318. //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialClearCoatKeyword );
  1319. }
  1320. }
  1321. void FetchHDPorts()
  1322. {
  1323. if( m_fetchPorts )
  1324. {
  1325. m_fetchPorts = false;
  1326. if( m_inputPorts.Count > 4 )
  1327. {
  1328. m_specularPort = GetInputPortByUniqueId( 3 );
  1329. m_metallicPort = GetInputPortByUniqueId( 4 );
  1330. m_coatMaskPort = GetInputPortByUniqueId( 11 );
  1331. m_diffusionProfilePort = GetInputPortByUniqueId( 12 );
  1332. m_subsurfaceMaskPort = GetInputPortByUniqueId( 13 );
  1333. m_thicknessPort = GetInputPortByUniqueId( 14 );
  1334. m_anisotropyPort = GetInputPortByUniqueId( 15 );
  1335. m_iridescenceThicknessPort = GetInputPortByUniqueId( 16 );
  1336. m_iridescenceMaskPort = GetInputPortByUniqueId( 17 );
  1337. m_indexOfRefractionPort = GetInputPortByUniqueId( 18 );
  1338. m_transmittanceColorPort = GetInputPortByUniqueId( 19 );
  1339. m_transmittanceAbsorptionDistancePort = GetInputPortByUniqueId( 20 );
  1340. m_transmittanceMaskPort = GetInputPortByUniqueId( 21 );
  1341. }
  1342. }
  1343. }
  1344. void ConfigHDPorts()
  1345. {
  1346. if( m_templateMultiPass.CustomTemplatePropertyUI == CustomTemplatePropertyUIEnum.None )
  1347. return;
  1348. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType != TemplateSRPType.HDRP ||
  1349. !m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBR )
  1350. return;
  1351. FetchHDPorts();
  1352. if( m_inputPorts.Count > 4 )
  1353. {
  1354. switch( m_hdSrpMaterialType )
  1355. {
  1356. case HDSRPMaterialType.SubsurfaceScattering:
  1357. {
  1358. m_specularPort.Visible = false;
  1359. m_metallicPort.Visible = false;
  1360. m_coatMaskPort.Visible = true;
  1361. m_diffusionProfilePort.Visible = true;
  1362. m_subsurfaceMaskPort.Visible = true;
  1363. m_thicknessPort.Visible = true;
  1364. m_anisotropyPort.Visible = false;
  1365. m_iridescenceThicknessPort.Visible = false;
  1366. m_iridescenceMaskPort.Visible = false;
  1367. m_indexOfRefractionPort.Visible = false;
  1368. m_transmittanceColorPort.Visible = false;
  1369. m_transmittanceAbsorptionDistancePort.Visible = false;
  1370. m_transmittanceMaskPort.Visible = false;
  1371. }
  1372. break;
  1373. case HDSRPMaterialType.Standard:
  1374. {
  1375. m_specularPort.Visible = false;
  1376. m_metallicPort.Visible = true;
  1377. m_coatMaskPort.Visible = true;
  1378. m_diffusionProfilePort.Visible = false;
  1379. m_subsurfaceMaskPort.Visible = false;
  1380. m_thicknessPort.Visible = false;
  1381. m_anisotropyPort.Visible = false;
  1382. m_iridescenceThicknessPort.Visible = false;
  1383. m_iridescenceMaskPort.Visible = false;
  1384. m_indexOfRefractionPort.Visible = false;
  1385. m_transmittanceColorPort.Visible = false;
  1386. m_transmittanceAbsorptionDistancePort.Visible = false;
  1387. m_transmittanceMaskPort.Visible = false;
  1388. }
  1389. break;
  1390. case HDSRPMaterialType.Specular:
  1391. {
  1392. m_specularPort.Visible = true;
  1393. m_metallicPort.Visible = false;
  1394. m_coatMaskPort.Visible = true;
  1395. m_diffusionProfilePort.Visible = false;
  1396. m_subsurfaceMaskPort.Visible = false;
  1397. m_thicknessPort.Visible = false;
  1398. m_anisotropyPort.Visible = false;
  1399. m_iridescenceThicknessPort.Visible = false;
  1400. m_iridescenceMaskPort.Visible = false;
  1401. m_indexOfRefractionPort.Visible = false;
  1402. m_transmittanceColorPort.Visible = false;
  1403. m_transmittanceAbsorptionDistancePort.Visible = false;
  1404. m_transmittanceMaskPort.Visible = false;
  1405. }
  1406. break;
  1407. case HDSRPMaterialType.Anisotropy:
  1408. {
  1409. m_specularPort.Visible = false;
  1410. m_metallicPort.Visible = true;
  1411. m_coatMaskPort.Visible = true;
  1412. m_diffusionProfilePort.Visible = false;
  1413. m_subsurfaceMaskPort.Visible = false;
  1414. m_thicknessPort.Visible = false;
  1415. m_anisotropyPort.Visible = true;
  1416. m_iridescenceThicknessPort.Visible = false;
  1417. m_iridescenceMaskPort.Visible = false;
  1418. m_indexOfRefractionPort.Visible = false;
  1419. m_transmittanceColorPort.Visible = false;
  1420. m_transmittanceAbsorptionDistancePort.Visible = false;
  1421. m_transmittanceMaskPort.Visible = false;
  1422. }
  1423. break;
  1424. case HDSRPMaterialType.Iridescence:
  1425. {
  1426. m_specularPort.Visible = false;
  1427. m_metallicPort.Visible = true;
  1428. m_coatMaskPort.Visible = true;
  1429. m_diffusionProfilePort.Visible = false;
  1430. m_subsurfaceMaskPort.Visible = false;
  1431. m_thicknessPort.Visible = false;
  1432. m_anisotropyPort.Visible = false;
  1433. m_iridescenceThicknessPort.Visible = true;
  1434. m_iridescenceMaskPort.Visible = true;
  1435. m_indexOfRefractionPort.Visible = false;
  1436. m_transmittanceColorPort.Visible = false;
  1437. m_transmittanceAbsorptionDistancePort.Visible = false;
  1438. m_transmittanceMaskPort.Visible = false;
  1439. }
  1440. break;
  1441. case HDSRPMaterialType.Translucent:
  1442. {
  1443. m_specularPort.Visible = false;
  1444. m_metallicPort.Visible = false;
  1445. m_coatMaskPort.Visible = false;
  1446. m_diffusionProfilePort.Visible = true;
  1447. m_subsurfaceMaskPort.Visible = false;
  1448. m_thicknessPort.Visible = true;
  1449. m_anisotropyPort.Visible = false;
  1450. m_iridescenceThicknessPort.Visible = false;
  1451. m_iridescenceMaskPort.Visible = false;
  1452. m_indexOfRefractionPort.Visible = false;
  1453. m_transmittanceColorPort.Visible = false;
  1454. m_transmittanceAbsorptionDistancePort.Visible = false;
  1455. m_transmittanceMaskPort.Visible = false;
  1456. }
  1457. break;
  1458. }
  1459. }
  1460. m_sizeIsDirty = ( m_isInvisible == InvisibilityStatus.Visible );
  1461. }
  1462. public void SetShaderLODValueAndLabel( int value )
  1463. {
  1464. if( ShaderLOD != value )
  1465. ShaderLOD = value;
  1466. if( ContainerGraph.HasLODs )
  1467. {
  1468. SetClippedAdditionalTitle( string.Format( LodSubtitle , ShaderLOD ) );
  1469. }
  1470. else
  1471. {
  1472. SetAdditonalTitleText( string.Empty );
  1473. }
  1474. }
  1475. void DrawLODAddRemoveButtons()
  1476. {
  1477. DrawLODAddRemoveButtons( -2 , true );
  1478. }
  1479. void DrawLODAddRemoveButtons( int index , bool showRemove )
  1480. {
  1481. if( GUILayoutButton( string.Empty , UIUtils.PlusStyle , GUILayout.Width( 15 ) ) )
  1482. {
  1483. Vector2 minPos = Vec2Position;
  1484. //bool newNodePositionMode = false;
  1485. //if( newNodePositionMode )
  1486. //{
  1487. // for( int lod = 0; lod < ContainerGraph.LodMultiPassMasternodes.Count; lod++ )
  1488. // {
  1489. // if( ContainerGraph.LodMultiPassMasternodes[ lod ].Count != 0 )
  1490. // {
  1491. // Vector2 currPos = ContainerGraph.LodMultiPassMasternodes[ lod ].NodesList[ m_passIdx ].Vec2Position;
  1492. // if( currPos.y > minPos.y )
  1493. // {
  1494. // minPos = currPos;
  1495. // }
  1496. // }
  1497. // else
  1498. // {
  1499. // if( index < 0 )
  1500. // {
  1501. // index = lod;
  1502. // }
  1503. // break;
  1504. // }
  1505. // }
  1506. //}
  1507. //else
  1508. //{
  1509. for( int lod = ContainerGraph.LodMultiPassMasternodes.Count - 1 ; lod >= 0 ; lod-- )
  1510. {
  1511. if( ContainerGraph.LodMultiPassMasternodes[ lod ].Count != 0 )
  1512. {
  1513. minPos = ContainerGraph.LodMultiPassMasternodes[ lod ].NodesList[ m_passIdx ].Vec2Position;
  1514. break;
  1515. }
  1516. }
  1517. //}
  1518. minPos.y += HeightEstimate + 10;
  1519. ContainerGraph.CreateLodMasterNodes( m_templateMultiPass , index , minPos );
  1520. }
  1521. if( showRemove && GUILayoutButton( string.Empty , UIUtils.MinusStyle , GUILayout.Width( 15 ) ) )
  1522. {
  1523. ContainerGraph.DestroyLodMasterNodes( index );
  1524. }
  1525. }
  1526. void SetupLODNodeName()
  1527. {
  1528. if( IsMainOutputNode )
  1529. {
  1530. if( string.IsNullOrEmpty( m_mainLODName ) )
  1531. {
  1532. m_shaderNameIsTitle = true;
  1533. m_content.text = GenerateClippedTitle( m_croppedShaderName );
  1534. }
  1535. else
  1536. {
  1537. m_shaderNameIsTitle = false;
  1538. m_content.text = GenerateClippedTitle( m_mainLODName );
  1539. }
  1540. }
  1541. else
  1542. {
  1543. m_shaderNameIsTitle = false;
  1544. m_content.text = GenerateClippedTitle( m_passName );
  1545. }
  1546. }
  1547. public void DrawLodRowItem( bool listMode )
  1548. {
  1549. float labelWidthBuffer = EditorGUIUtility.labelWidth;
  1550. EditorGUILayout.BeginHorizontal();
  1551. if( listMode )
  1552. {
  1553. if( GUILayout.Button( "\u25b6" , GUILayout.Width( 18 ) , GUILayout.Height( 18 ) ) )
  1554. {
  1555. m_containerGraph.ParentWindow.FocusOnNode( this , 1 , false , true );
  1556. }
  1557. EditorGUI.BeginChangeCheck();
  1558. GUI.SetNextControlName( LodValueId + m_lodIndex );
  1559. m_shaderLOD = EditorGUILayoutIntField( string.Empty , m_shaderLOD , GUILayout.Width( 50 ) );
  1560. }
  1561. else
  1562. {
  1563. EditorGUI.BeginChangeCheck();
  1564. EditorGUIUtility.labelWidth = 45;
  1565. GUI.SetNextControlName( LodValueId + m_lodIndex );
  1566. m_shaderLOD = EditorGUILayoutIntField( "LOD" , ShaderLOD , GUILayout.Width( 100 ) );
  1567. EditorGUIUtility.labelWidth = labelWidthBuffer;
  1568. }
  1569. if( EditorGUI.EndChangeCheck() )
  1570. {
  1571. m_refreshLODValueMasterNodes = true;
  1572. m_refreshLODValueMasterNodesTimestamp = EditorApplication.timeSinceStartup;
  1573. if( ContainerGraph.HasLODs )
  1574. SetClippedAdditionalTitle( string.Format( LodSubtitle , ShaderLOD ) );
  1575. }
  1576. EditorGUI.BeginChangeCheck();
  1577. GUI.SetNextControlName( LodNameId + ShaderLOD );
  1578. if( listMode )
  1579. {
  1580. m_mainLODName = EditorGUILayoutTextField( string.Empty , m_mainLODName , GUILayout.Width( 100 ) );
  1581. }
  1582. else
  1583. {
  1584. GUILayout.Space( -15 );
  1585. EditorGUIUtility.labelWidth = 45;
  1586. m_mainLODName = EditorGUILayoutTextField( string.Empty , m_mainLODName );
  1587. EditorGUIUtility.labelWidth = labelWidthBuffer;
  1588. }
  1589. if( EditorGUI.EndChangeCheck() )
  1590. {
  1591. // If reorder is scheduled make sure it doesn't happen when editing LOD name
  1592. if( m_refreshLODValueMasterNodes )
  1593. m_refreshLODValueMasterNodesTimestamp = EditorApplication.timeSinceStartup;
  1594. SetupLODNodeName();
  1595. }
  1596. if( listMode )
  1597. DrawLODAddRemoveButtons( m_lodIndex , ( m_lodIndex >= 0 ) );
  1598. EditorGUILayout.EndHorizontal();
  1599. if( m_refocusLODValueMasterNodes )
  1600. {
  1601. m_refocusLODValueMasterNodes = false;
  1602. string focusedControl = GUI.GetNameOfFocusedControl();
  1603. if( focusedControl.Contains( LodValueId ) )
  1604. {
  1605. GUI.FocusControl( LodValueId + m_lodIndex );
  1606. TextEditor te = (TextEditor)GUIUtility.GetStateObject( typeof( TextEditor ) , GUIUtility.keyboardControl );
  1607. if( te != null )
  1608. {
  1609. te.SelectTextEnd();
  1610. }
  1611. }
  1612. else if( focusedControl.Contains( LodNameId ) )
  1613. {
  1614. GUI.FocusControl( LodNameId + m_lodIndex );
  1615. TextEditor te = (TextEditor)GUIUtility.GetStateObject( typeof( TextEditor ) , GUIUtility.keyboardControl );
  1616. if( te != null )
  1617. {
  1618. te.SelectTextEnd();
  1619. }
  1620. }
  1621. }
  1622. }
  1623. void DrawLOD()
  1624. {
  1625. if( m_templateMultiPass.CanAddLODs && m_lodIndex == -1 )
  1626. {
  1627. EditorGUILayout.Space();
  1628. DrawLodRowItem( true );
  1629. EditorGUILayout.Space();
  1630. for( int i = 0 ; i < ContainerGraph.LodMultiPassMasternodes.Count ; i++ )
  1631. {
  1632. if( ContainerGraph.LodMultiPassMasternodes[ i ].NodesList.Count > 0 )
  1633. {
  1634. TemplateMultiPassMasterNode masterNode = m_containerGraph.LodMultiPassMasternodes[ i ].NodesList[ m_passIdx ];
  1635. masterNode.DrawLodRowItem( true );
  1636. EditorGUILayout.Space();
  1637. }
  1638. }
  1639. EditorGUILayout.Space();
  1640. }
  1641. }
  1642. void DrawCommonProperties()
  1643. {
  1644. if( m_isMainOutputNode )
  1645. {
  1646. //if( m_templateMultiPass.CanAddLODs && m_lodIndex == -1 )
  1647. //{
  1648. // if( GUILayoutButton( string.Empty, UIUtils.PlusStyle, GUILayout.Width( 15 ) ) )
  1649. // {
  1650. // ContainerGraph.CreateLodMasterNodes( m_templateMultiPass, Vec2Position );
  1651. // }
  1652. // if( GUILayoutButton( string.Empty, UIUtils.MinusStyle, GUILayout.Width( 15 ) ) )
  1653. // {
  1654. // ContainerGraph.DestroyLodMasterNodes();
  1655. // }
  1656. //}
  1657. //EditorGUILayout.LabelField( "LOD: " + m_lodIndex );
  1658. DrawShaderName();
  1659. DrawCurrentShaderType();
  1660. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBRHD )
  1661. {
  1662. if( m_templateMultiPass.CustomTemplatePropertyUI == CustomTemplatePropertyUIEnum.HDPBR )
  1663. {
  1664. EditorGUI.BeginChangeCheck();
  1665. CurrentHDMaterialType = (HDSRPMaterialType)EditorGUILayoutEnumPopup( HDSRPMaterialTypeStr , m_hdSrpMaterialType );
  1666. if( EditorGUI.EndChangeCheck() )
  1667. ConfigHDPorts();
  1668. }
  1669. }
  1670. EditorGUI.BeginChangeCheck();
  1671. DrawPrecisionProperty( false );
  1672. if( EditorGUI.EndChangeCheck() )
  1673. ContainerGraph.CurrentPrecision = m_currentPrecisionType;
  1674. DrawSamplingMacros();
  1675. m_drawInstancedHelper.Draw( this );
  1676. m_fallbackHelper.Draw( this );
  1677. DrawCustomInspector( m_templateMultiPass.SRPtype != TemplateSRPType.BiRP );
  1678. m_subShaderOptions.DrawCustomOptions( this );
  1679. m_dependenciesHelper.Draw( this , true );
  1680. }
  1681. //EditorGUILayout.LabelField( m_subShaderIdxStr );
  1682. //EditorGUILayout.LabelField( m_passIdxStr );
  1683. if( IsLODMainMasterNode && m_templateMultiPass.CanAddLODs )
  1684. {
  1685. NodeUtils.DrawNestedPropertyGroup( ref m_lodFoldout , AdditionalLODsStr , DrawLOD , DrawLODAddRemoveButtons );
  1686. }
  1687. DrawOpenTemplateButton();
  1688. if( DebugConsoleWindow.DeveloperMode )
  1689. DrawReloadButton();
  1690. }
  1691. public void DrawSubShaderProperties()
  1692. {
  1693. if( !m_isMainOutputNode )
  1694. {
  1695. m_mainMasterNodeRef.DrawSubShaderProperties();
  1696. return;
  1697. }
  1698. bool noValidData = true;
  1699. if( ShaderLOD > 0 )
  1700. {
  1701. noValidData = false;
  1702. if( m_templateMultiPass.CanAddLODs && m_containerGraph.LodMultiPassMasternodes[ 0 ].Count > 0 )
  1703. {
  1704. DrawLodRowItem( false );
  1705. }
  1706. else
  1707. {
  1708. ShaderLOD = EditorGUILayoutIntField( SubShaderLODValueLabel , ShaderLOD );
  1709. }
  1710. }
  1711. if( m_subShaderModule.HasValidData )
  1712. {
  1713. noValidData = false;
  1714. m_subShaderModule.Draw( this , m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules );
  1715. //if( m_subShaderModule.IsDirty )
  1716. //{
  1717. // List<TemplateMultiPassMasterNode> mpNodes = UIUtils.CurrentWindow.CurrentGraph.MultiPassMasterNodes.NodesList;
  1718. // int count = mpNodes.Count;
  1719. // for( int i = 0; i < count; i++ )
  1720. // {
  1721. // if( mpNodes[ i ].SubShaderIdx == m_subShaderIdx && mpNodes[ i ].UniqueId != UniqueId )
  1722. // {
  1723. // mpNodes[ i ].SubShaderModule.CopyFrom( m_subShaderModule );
  1724. // }
  1725. // }
  1726. // m_subShaderModule.IsDirty = false;
  1727. //}
  1728. }
  1729. m_passSelector.Draw( this );
  1730. if( noValidData )
  1731. {
  1732. EditorGUILayout.HelpBox( NoSubShaderPropertyStr , MessageType.Info );
  1733. }
  1734. }
  1735. void DrawPassProperties()
  1736. {
  1737. EditorGUI.BeginChangeCheck();
  1738. m_passName = EditorGUILayoutTextField( PassNameStr , m_passName );
  1739. if( EditorGUI.EndChangeCheck() )
  1740. {
  1741. if( m_passName.Length > 0 )
  1742. {
  1743. m_passName = UIUtils.RemoveShaderInvalidCharacters( m_passName );
  1744. }
  1745. else
  1746. {
  1747. m_passName = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].PassNameContainer.Data;
  1748. }
  1749. //if( !m_templateMultiPass.IsSinglePass )
  1750. // SetClippedTitle( m_passName );
  1751. }
  1752. EditorGUILayout.LabelField( Pass.Modules.PassUniqueName );
  1753. if( m_passModule.HasValidData )
  1754. {
  1755. m_passModule.Draw( this , m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules , m_subShaderModule );
  1756. }
  1757. m_usePass.Draw( this , false );
  1758. m_passOptions.DrawCustomOptions( this );
  1759. }
  1760. bool CreateInstructionsForList( TemplateData templateData , ref List<InputPort> ports , ref string shaderBody , ref List<string> vertexInstructions , ref List<string> fragmentInstructions )
  1761. {
  1762. if( ports.Count == 0 )
  1763. return true;
  1764. AddHDKeywords();
  1765. bool isValid = true;
  1766. //UIUtils.CurrentWindow.CurrentGraph.ResetNodesLocalVariables();
  1767. for( int i = 0 ; i < ports.Count ; i++ )
  1768. {
  1769. TemplateInputData inputData = templateData.InputDataFromId( ports[ i ].PortId );
  1770. if( ports[ i ].HasOwnOrLinkConnection )
  1771. {
  1772. //if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType == TemplateSRPType.URP )
  1773. //{
  1774. // if( ports[ i ].Name.Contains( "Normal" ) )
  1775. // {
  1776. // m_currentDataCollector.AddToDirectives( SRPMaterialNormalMapKeyword, -1, AdditionalLineType.Define );
  1777. // }
  1778. // if( ports[ i ].Name.Contains( "Alpha Clip Threshold" ) )
  1779. // {
  1780. // m_currentDataCollector.AddToDirectives( SRPMaterialBlendModeAlphaClipThresholdKeyword, -1, AdditionalLineType.Define );
  1781. // }
  1782. // if( ports[ i ].Name.Contains( "Specular" ) )
  1783. // {
  1784. // m_currentDataCollector.AddToDirectives( SRPLWMaterialSpecularKeyword, -1, AdditionalLineType.Define );
  1785. // }
  1786. //}
  1787. //else if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType == TemplateSRPType.HDRP )
  1788. //{
  1789. // if( ports[ i ].Name.Contains( "Normal" ) )
  1790. // {
  1791. // //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialNormalMapKeyword );
  1792. // }
  1793. // if( ports[ i ].Name.Contains( "Alpha Clip Threshold" ) )
  1794. // {
  1795. // //m_currentDataCollector.AddToDefines( UniqueId, SRPMaterialAlphaTestKeyword );
  1796. // }
  1797. //}
  1798. m_currentDataCollector.ResetInstructions();
  1799. m_currentDataCollector.ResetVertexInstructions();
  1800. m_currentDataCollector.PortCategory = ports[ i ].Category;
  1801. string newPortInstruction = ports[ i ].GeneratePortInstructions( ref m_currentDataCollector );
  1802. if( m_currentDataCollector.DirtySpecialLocalVariables )
  1803. {
  1804. string cleanVariables = m_currentDataCollector.SpecialLocalVariables.Replace( "\t" , string.Empty );
  1805. m_currentDataCollector.AddInstructions( cleanVariables , false );
  1806. m_currentDataCollector.ClearSpecialLocalVariables();
  1807. }
  1808. if( m_currentDataCollector.DirtyVertexVariables )
  1809. {
  1810. string cleanVariables = m_currentDataCollector.VertexLocalVariables.Replace( "\t" , string.Empty );
  1811. m_currentDataCollector.AddVertexInstruction( cleanVariables , UniqueId , false );
  1812. m_currentDataCollector.ClearVertexLocalVariables();
  1813. }
  1814. // fill functions
  1815. for( int j = 0 ; j < m_currentDataCollector.InstructionsList.Count ; j++ )
  1816. {
  1817. fragmentInstructions.Add( m_currentDataCollector.InstructionsList[ j ].PropertyName );
  1818. }
  1819. for( int j = 0 ; j < m_currentDataCollector.VertexDataList.Count ; j++ )
  1820. {
  1821. vertexInstructions.Add( m_currentDataCollector.VertexDataList[ j ].PropertyName );
  1822. }
  1823. m_templateMultiPass.SetPassInputData( m_subShaderIdx , m_passIdx , ports[ i ].PortId , newPortInstruction );
  1824. isValid = m_templateMultiPass.FillTemplateBody( m_subShaderIdx , m_passIdx , inputData.TagId , ref shaderBody , newPortInstruction ) && isValid;
  1825. }
  1826. else
  1827. {
  1828. m_templateMultiPass.SetPassInputData( m_subShaderIdx , m_passIdx , ports[ i ].PortId , inputData.DefaultValue );
  1829. isValid = m_templateMultiPass.FillTemplateBody( m_subShaderIdx , m_passIdx , inputData.TagId , ref shaderBody , inputData.DefaultValue ) && isValid;
  1830. }
  1831. }
  1832. return isValid;
  1833. }
  1834. public string BuildShaderBody( MasterNodeDataCollector inDataCollector , ref MasterNodeDataCollector outDataCollector )
  1835. {
  1836. List<TemplateMultiPassMasterNode> list = ContainerGraph.MultiPassMasterNodes.NodesList;
  1837. int currentSubshader = list[ 0 ].SubShaderIdx;
  1838. m_templateMultiPass.SetShaderName( string.Format( TemplatesManager.NameFormatter , m_shaderName ) );
  1839. if( string.IsNullOrEmpty( m_customInspectorName ) )
  1840. {
  1841. m_templateMultiPass.SetCustomInspector( string.Empty );
  1842. }
  1843. else
  1844. {
  1845. m_templateMultiPass.SetCustomInspector( CustomInspectorFormatted );
  1846. }
  1847. m_templateMultiPass.SetFallback( m_fallbackHelper.FallbackShader );
  1848. m_templateMultiPass.SetDependencies( m_dependenciesHelper.GenerateDependencies() );
  1849. if( inDataCollector != null )
  1850. outDataCollector.CopyPropertiesFromDataCollector( inDataCollector );
  1851. outDataCollector.TemplateDataCollectorInstance.CurrentSRPType = m_templateMultiPass.SRPtype;
  1852. int lastActivePass = m_passSelector.LastActivePass;
  1853. int count = list.Count;
  1854. bool filledSubshaderData = false;
  1855. bool foundExcludePassName = false;
  1856. string excludePassName = string.Empty;
  1857. foundExcludePassName = CheckExcludeAllPassOptions( m_subShaderOptions , out excludePassName );
  1858. for( int i = 0 ; i < count ; i++ )
  1859. {
  1860. bool removePass = !m_passSelector.IsVisible( i ) || ( foundExcludePassName && !list[ i ].OriginalPassName.Equals( excludePassName ) );
  1861. list[ 0 ].CurrentTemplate.IdManager.SetPassIdUsage( i , removePass );
  1862. if( removePass )
  1863. {
  1864. if( m_isMainOutputNode )
  1865. {
  1866. //Make sure that property change options are set even if the main master node is invisible
  1867. CheckPropertyChangesOnOptions( m_subShaderOptions );
  1868. }
  1869. continue;
  1870. }
  1871. list[ i ].CollectData();
  1872. list[ i ].FillPassData( this , outDataCollector.TemplateDataCollectorInstance );
  1873. if( list[ i ].SubShaderIdx == currentSubshader )
  1874. {
  1875. outDataCollector.CopyPropertiesFromDataCollector( list[ i ].CurrentDataCollector );
  1876. }
  1877. else
  1878. {
  1879. list[ i - 1 ].FillPropertyData( outDataCollector );
  1880. list[ i - 1 ].FillSubShaderData();
  1881. outDataCollector.Destroy();
  1882. outDataCollector = new MasterNodeDataCollector();
  1883. outDataCollector.CopyPropertiesFromDataCollector( list[ i ].CurrentDataCollector );
  1884. currentSubshader = list[ i ].SubShaderIdx;
  1885. }
  1886. // Last element must the one filling subshader data
  1887. // as only there all properties are caught
  1888. //if( i == ( count - 1 ) )
  1889. if( i == lastActivePass )
  1890. {
  1891. list[ i ].FillPropertyData( outDataCollector );
  1892. }
  1893. if( list[ i ].IsMainOutputNode )
  1894. {
  1895. filledSubshaderData = true;
  1896. list[ i ].FillSubShaderData();
  1897. }
  1898. }
  1899. if( !filledSubshaderData )
  1900. {
  1901. FillSubShaderData();
  1902. }
  1903. outDataCollector.TemplateDataCollectorInstance.BuildCBuffer( -1 );
  1904. //Fill uniforms is set on last since we need to collect all srp batcher data ( if needed )
  1905. //To set it into each pass
  1906. for( int i = 0 ; i < count ; i++ )
  1907. {
  1908. bool removePass = !m_passSelector.IsVisible( i ) || ( foundExcludePassName && !list[ i ].OriginalPassName.Equals( excludePassName ) );
  1909. if( removePass )
  1910. continue;
  1911. list[ i ].FillUniforms( outDataCollector.TemplateDataCollectorInstance );
  1912. }
  1913. return list[ 0 ].CurrentTemplate.IdManager.BuildShader();
  1914. }
  1915. public string BuildLOD( MasterNodeDataCollector inDataCollector , ref MasterNodeDataCollector outDataCollector )
  1916. {
  1917. UsageListTemplateMultiPassMasterNodes bufferNodesList = ContainerGraph.MultiPassMasterNodes;
  1918. int bufferMasterNodeId = ContainerGraph.CurrentMasterNodeId;
  1919. ContainerGraph.MultiPassMasterNodes = ContainerGraph.LodMultiPassMasternodes[ m_lodIndex ];
  1920. ContainerGraph.CurrentMasterNodeId = UniqueId;
  1921. m_templateMultiPass.ResetState();
  1922. base.Execute( string.Empty , false );
  1923. string shaderBody = BuildShaderBody( inDataCollector , ref outDataCollector );
  1924. ContainerGraph.MultiPassMasterNodes = bufferNodesList;
  1925. ContainerGraph.CurrentMasterNodeId = bufferMasterNodeId;
  1926. return shaderBody;
  1927. }
  1928. public override Shader Execute( string pathname , bool isFullPath )
  1929. {
  1930. ForceReordering();
  1931. MasterNodeDataCollector overallDataCollector = new MasterNodeDataCollector();
  1932. //BUILD LOD
  1933. string allLodSubShaders = string.Empty;
  1934. if( m_templateMultiPass.CanAddLODs && ContainerGraph.HasLODs )
  1935. {
  1936. for( int lod = 0 ; lod < ContainerGraph.LodMultiPassMasternodes.Count ; lod++ )
  1937. {
  1938. if( ContainerGraph.LodMultiPassMasternodes[ lod ].Count == 0 )
  1939. break;
  1940. TemplateMultiPassMasterNode newMasterNode = ContainerGraph.LodMultiPassMasternodes[ lod ].NodesList.Find( ( x ) => x.IsMainOutputNode );
  1941. string lodSubShaders = newMasterNode.BuildLOD( null , ref overallDataCollector );
  1942. lodSubShaders = TemplateHelperFunctions.GetSubShaderFrom( lodSubShaders ) + "\n";
  1943. allLodSubShaders += lodSubShaders;
  1944. }
  1945. }
  1946. //BUILD MAIN
  1947. m_templateMultiPass.ResetState();
  1948. base.Execute( pathname , isFullPath );
  1949. MasterNodeDataCollector dummy = new MasterNodeDataCollector();
  1950. string shaderBody = BuildShaderBody( overallDataCollector , ref dummy );
  1951. if( m_templateMultiPass.CanAddLODs )
  1952. {
  1953. //COMBINE LOD WITH MAIN
  1954. // Commented the if out since we always want to replace the tag with something, even string.empty to clean the tag out of the final shader
  1955. //if( !string.IsNullOrEmpty( allLodSubShaders ) )
  1956. shaderBody = shaderBody.Replace( TemplatesManager.TemplateLODsTag , allLodSubShaders );
  1957. }
  1958. UpdateShaderAsset( ref pathname , ref shaderBody , isFullPath );
  1959. return m_currentShader;
  1960. }
  1961. public void CollectData()
  1962. {
  1963. if( m_inputPorts.Count == 0 )
  1964. return;
  1965. ContainerGraph.ResetNodesLocalVariables();
  1966. m_optionsDefineContainer.RemoveTemporaries();
  1967. m_currentDataCollector = new MasterNodeDataCollector( this );
  1968. m_currentDataCollector.TemplateDataCollectorInstance.SetMultipassInfo( m_templateMultiPass , m_subShaderIdx , m_passIdx , m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.SRPType );
  1969. m_currentDataCollector.TemplateDataCollectorInstance.FillSpecialVariables( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ] );
  1970. SetupNodeCategories();
  1971. if( m_containerGraph.IsInstancedShader )
  1972. {
  1973. string blockName = UIUtils.RemoveInvalidCharacters( ContainerGraph.GetMainMasterNodeOfLOD( -1 ).ShaderName );
  1974. m_currentDataCollector.SetupInstancePropertiesBlock( blockName );
  1975. }
  1976. TemplateData templateData = m_templateMultiPass.CreateTemplateData( m_shaderName , string.Empty , m_subShaderIdx , m_passIdx );
  1977. m_currentDataCollector.TemplateDataCollectorInstance.BuildFromTemplateData( m_currentDataCollector , templateData );
  1978. if( m_currentDataCollector.TemplateDataCollectorInstance.InterpData.DynamicMax )
  1979. {
  1980. int interpolatorAmount = -1;
  1981. if( m_passModule.ShaderModelHelper.ValidData )
  1982. {
  1983. interpolatorAmount = m_passModule.ShaderModelHelper.InterpolatorAmount;
  1984. }
  1985. else
  1986. {
  1987. TemplateModulesHelper subShaderModule = IsMainOutputNode ? m_subShaderModule : ( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode ).SubShaderModule;
  1988. if( subShaderModule.ShaderModelHelper.ValidData )
  1989. {
  1990. interpolatorAmount = subShaderModule.ShaderModelHelper.InterpolatorAmount;
  1991. }
  1992. }
  1993. if( interpolatorAmount > -1 )
  1994. {
  1995. m_currentDataCollector.TemplateDataCollectorInstance.InterpData.RecalculateAvailableInterpolators( interpolatorAmount );
  1996. }
  1997. }
  1998. //Copy Properties
  1999. {
  2000. int shaderPropertiesAmount = m_templateMultiPass.AvailableShaderProperties.Count;
  2001. for( int i = 0 ; i < shaderPropertiesAmount ; i++ )
  2002. {
  2003. m_currentDataCollector.SoftRegisterUniform( m_templateMultiPass.AvailableShaderProperties[ i ] );
  2004. }
  2005. }
  2006. //Copy Globals from SubShader level
  2007. {
  2008. int subShaderGlobalAmount = m_templateMultiPass.SubShaders[ m_subShaderIdx ].AvailableShaderGlobals.Count;
  2009. for( int i = 0 ; i < subShaderGlobalAmount ; i++ )
  2010. {
  2011. m_currentDataCollector.SoftRegisterUniform( m_templateMultiPass.SubShaders[ m_subShaderIdx ].AvailableShaderGlobals[ i ] );
  2012. }
  2013. }
  2014. //Copy Globals from Pass Level
  2015. {
  2016. int passGlobalAmount = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].AvailableShaderGlobals.Count;
  2017. for( int i = 0 ; i < passGlobalAmount ; i++ )
  2018. {
  2019. m_currentDataCollector.SoftRegisterUniform( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].AvailableShaderGlobals[ i ] );
  2020. }
  2021. }
  2022. // Check Current Options for property changes on subshader
  2023. if( m_isMainOutputNode )
  2024. {
  2025. CheckPropertyChangesOnOptions( m_subShaderOptions );
  2026. }
  2027. // Check Current Options for property changes on pass
  2028. CheckPropertyChangesOnOptions( m_passOptions );
  2029. // @diogo: Set ASE info
  2030. ASEPackageManagerHelper.SetASEVersionInfoOnDataCollector( ref m_currentDataCollector );
  2031. //Set SRP info
  2032. if( m_templateMultiPass.SRPtype != TemplateSRPType.BiRP )
  2033. ASEPackageManagerHelper.SetSRPInfoOnDataCollector( ref m_currentDataCollector );
  2034. RegisterStandaloneFuntions();
  2035. m_containerGraph.CheckPropertiesAutoRegister( ref m_currentDataCollector );
  2036. //Sort ports by both
  2037. List<InputPort> fragmentPorts = new List<InputPort>();
  2038. List<InputPort> vertexPorts = new List<InputPort>();
  2039. SortInputPorts( ref vertexPorts , ref fragmentPorts );
  2040. string shaderBody = templateData.TemplateBody;
  2041. List<string> vertexInstructions = new List<string>();
  2042. List<string> fragmentInstructions = new List<string>();
  2043. bool validBody = true;
  2044. //validBody = CreateInstructionsForList( templateData, ref fragmentPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions ) && validBody;
  2045. //ContainerGraph.ResetNodesLocalVariablesIfNot( MasterNodePortCategory.Vertex );
  2046. //validBody = CreateInstructionsForList( templateData, ref vertexPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions ) && validBody;
  2047. validBody = CreateInstructionsForList( templateData , ref vertexPorts , ref shaderBody , ref vertexInstructions , ref fragmentInstructions ) && validBody;
  2048. validBody = CreateInstructionsForList( templateData , ref fragmentPorts , ref shaderBody , ref vertexInstructions , ref fragmentInstructions ) && validBody;
  2049. if( !m_isMainOutputNode && m_mainMasterNodeRef == null )
  2050. {
  2051. m_mainMasterNodeRef = m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode;
  2052. }
  2053. TerrainDrawInstancedHelper drawInstanced = m_isMainOutputNode ? m_drawInstancedHelper : m_mainMasterNodeRef.DrawInstancedHelperInstance;
  2054. drawInstanced.UpdateDataCollectorForTemplates( ref m_currentDataCollector , ref vertexInstructions );
  2055. templateData.ResetTemplateUsageData();
  2056. // Fill vertex interpolators assignment
  2057. for( int i = 0 ; i < m_currentDataCollector.VertexInterpDeclList.Count ; i++ )
  2058. {
  2059. vertexInstructions.Add( m_currentDataCollector.VertexInterpDeclList[ i ] );
  2060. }
  2061. vertexInstructions.AddRange( m_currentDataCollector.TemplateDataCollectorInstance.GetInterpUnusedChannels() );
  2062. //Fill common local variables and operations
  2063. validBody = m_templateMultiPass.FillVertexInstructions( m_subShaderIdx , m_passIdx , vertexInstructions.ToArray() ) && validBody;
  2064. validBody = m_templateMultiPass.FillFragmentInstructions( m_subShaderIdx , m_passIdx , fragmentInstructions.ToArray() ) && validBody;
  2065. vertexInstructions.Clear();
  2066. vertexInstructions = null;
  2067. fragmentInstructions.Clear();
  2068. fragmentInstructions = null;
  2069. // Add Instanced Properties
  2070. if( m_containerGraph.IsInstancedShader )
  2071. {
  2072. m_currentDataCollector.OptimizeInstancedProperties();
  2073. m_currentDataCollector.TabifyInstancedVars();
  2074. //string cbufferBegin = m_currentDataCollector.IsSRP ?
  2075. // string.Format( IOUtils.SRPInstancedPropertiesBegin, "UnityPerMaterial" ) :
  2076. // string.Format( IOUtils.InstancedPropertiesBegin, m_currentDataCollector.InstanceBlockName );
  2077. //string cBufferEnd = m_currentDataCollector.IsSRP ? ( string.Format( IOUtils.SRPInstancedPropertiesEnd, m_currentDataCollector.InstanceBlockName ) ) : IOUtils.InstancedPropertiesEnd;
  2078. string cbufferBegin = m_currentDataCollector.IsSRP ?
  2079. string.Format( IOUtils.LWSRPInstancedPropertiesBegin , m_currentDataCollector.InstanceBlockName ) :
  2080. string.Format( IOUtils.InstancedPropertiesBegin , m_currentDataCollector.InstanceBlockName );
  2081. string cBufferEnd = m_currentDataCollector.IsSRP ? ( string.Format( IOUtils.LWSRPInstancedPropertiesEnd , m_currentDataCollector.InstanceBlockName ) ) : IOUtils.InstancedPropertiesEnd;
  2082. m_currentDataCollector.InstancedPropertiesList.Insert( 0 , new PropertyDataCollector( -1 , cbufferBegin ) );
  2083. m_currentDataCollector.InstancedPropertiesList.Add( new PropertyDataCollector( -1 , cBufferEnd ) );
  2084. m_currentDataCollector.UniformsList.AddRange( m_currentDataCollector.InstancedPropertiesList );
  2085. }
  2086. if( m_currentDataCollector.DotsPropertiesList.Count > 0 )
  2087. {
  2088. m_currentDataCollector.DotsPropertiesList.Insert( 0 , new PropertyDataCollector( -1 , "UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)" ) );
  2089. m_currentDataCollector.DotsPropertiesList.Insert( 0 , new PropertyDataCollector( -1 , "#ifdef UNITY_DOTS_INSTANCING_ENABLED" ) );
  2090. m_currentDataCollector.DotsPropertiesList.Insert( 0 , new PropertyDataCollector( -1 , "" ) );
  2091. m_currentDataCollector.DotsPropertiesList.Add( new PropertyDataCollector( -1 , "UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)" ) );
  2092. m_currentDataCollector.DotsDefinesList.Add( new PropertyDataCollector( -1 , "#endif" ) );
  2093. m_currentDataCollector.UniformsList.AddRange( m_currentDataCollector.DotsPropertiesList );
  2094. m_currentDataCollector.UniformsList.AddRange( m_currentDataCollector.DotsDefinesList );
  2095. }
  2096. TemplateShaderModelModule shaderModelModule = m_isMainOutputNode ? m_subShaderModule.ShaderModelHelper : m_mainMasterNodeRef.SubShaderModule.ShaderModelHelper;
  2097. string shaderModel = string.Empty;
  2098. if( m_passModule.ShaderModelHelper.ValidData )
  2099. {
  2100. shaderModel = m_passModule.ShaderModelHelper.CurrentShaderModel;
  2101. }
  2102. else if( shaderModelModule.ValidData )
  2103. {
  2104. shaderModel = shaderModelModule.CurrentShaderModel;
  2105. }
  2106. else if( m_templateMultiPass.GlobalShaderModel.IsValid )
  2107. {
  2108. shaderModel = m_templateMultiPass.GlobalShaderModel.Value;
  2109. }
  2110. else
  2111. {
  2112. shaderModel = ( m_templateMultiPass.SRPtype == TemplateSRPType.HDRP ) ? "4.5" : "3.0";
  2113. }
  2114. m_currentDataCollector.TemplateDataCollectorInstance.CheckInterpolatorOverflow( shaderModel , m_passName );
  2115. }
  2116. public bool CheckExcludeAllPassOptions( TemplateOptionsUIHelper optionsUI , out string passName )
  2117. {
  2118. List<TemplateOptionUIItem> options = optionsUI.PassCustomOptionsUI;
  2119. for( int optionIdx = 0 ; optionIdx < options.Count ; optionIdx++ )
  2120. {
  2121. if( options[ optionIdx ].IsVisible )
  2122. {
  2123. TemplateActionItem[] actionItems = options[ optionIdx ].CurrentOptionActions.Columns;
  2124. for( int actionIdx = 0 ; actionIdx < actionItems.Length ; actionIdx++ )
  2125. {
  2126. if( actionItems[ actionIdx ].ActionType == AseOptionsActionType.ExcludeAllPassesBut )
  2127. {
  2128. passName = actionItems[ actionIdx ].ActionData;
  2129. return true;
  2130. }
  2131. }
  2132. }
  2133. }
  2134. passName = string.Empty;
  2135. return false;
  2136. }
  2137. public void CheckPropertyChangesOnOptions( TemplateOptionsUIHelper optionsUI )
  2138. {
  2139. //Only Main LOD master node can change shader properties
  2140. if( !IsLODMainMasterNode )
  2141. return;
  2142. List<TemplateOptionUIItem> options = optionsUI.PassCustomOptionsUI;
  2143. for( int optionIdx = 0 ; optionIdx < options.Count ; optionIdx++ )
  2144. {
  2145. if( options[ optionIdx ].IsVisible )
  2146. {
  2147. TemplateActionItem[] actionItems = options[ optionIdx ].CurrentOptionActions.Columns;
  2148. for( int actionIdx = 0 ; actionIdx < actionItems.Length ; actionIdx++ )
  2149. {
  2150. if( actionItems[ actionIdx ].ActionType == AseOptionsActionType.SetShaderProperty && !string.IsNullOrEmpty( actionItems[ actionIdx ].ActionBuffer ) )
  2151. {
  2152. TemplateShaderPropertyData data = m_templateMultiPass.GetShaderPropertyData( actionItems[ actionIdx ].ActionData );
  2153. if( data != null )
  2154. {
  2155. string newPropertyValue = data.CreatePropertyForValue( actionItems[ actionIdx ].ActionBuffer );
  2156. CurrentTemplate.IdManager.SetReplacementText( data.FullValue , newPropertyValue );
  2157. if( CurrentMaterial != null )
  2158. {
  2159. switch( data.PropertyDataType )
  2160. {
  2161. case WirePortDataType.FLOAT:
  2162. {
  2163. float value = 0;
  2164. if( actionItems[ actionIdx ].GetFloatValueFromActionBuffer( out value ) )
  2165. {
  2166. CurrentMaterial.SetFloat( data.PropertyName , value );
  2167. }
  2168. }
  2169. break;
  2170. case WirePortDataType.INT:
  2171. {
  2172. int value = 0;
  2173. if( actionItems[ actionIdx ].GetIntValueFromActionBuffer( out value ) )
  2174. {
  2175. CurrentMaterial.SetInt( data.PropertyName , value );
  2176. }
  2177. }
  2178. break;
  2179. case WirePortDataType.UINT:
  2180. case WirePortDataType.FLOAT2:
  2181. case WirePortDataType.FLOAT3:
  2182. case WirePortDataType.FLOAT4:
  2183. case WirePortDataType.COLOR:
  2184. break;
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. if( options[ optionIdx ].Options.Type == AseOptionsType.Field )
  2191. {
  2192. foreach( var item in CurrentTemplate.IdManager.RegisteredTags )
  2193. {
  2194. if( item.Output.Equals( options[ optionIdx ].Options.FieldInlineName ) )
  2195. {
  2196. var node = options[ optionIdx ].Options.FieldValue.GetPropertyNode();
  2197. if( node != null && ( node.IsConnected || node.AutoRegister || node.UniqueId < -1 ) && options[ optionIdx ].Options.FieldValue.Active )
  2198. {
  2199. item.Replacement = node.PropertyName;
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. public void FillPropertyData( MasterNodeDataCollector dataCollector = null )
  2208. {
  2209. MasterNodeDataCollector currDataCollector = ( dataCollector == null ) ? m_currentDataCollector : dataCollector;
  2210. // Temporary hack
  2211. if( m_templateMultiPass.SRPtype != TemplateSRPType.BiRP )
  2212. {
  2213. if( m_templateMultiPass.AvailableShaderProperties.Find( x => x.PropertyName.Equals( "_AlphaCutoff" ) ) == null )
  2214. {
  2215. if( !currDataCollector.ContainsProperty("_AlphaCutoff") )
  2216. {
  2217. currDataCollector.AddToProperties( UniqueId, "[HideInInspector] _AlphaCutoff(\"Alpha Cutoff \", Range(0, 1)) = 0.5", -1 );
  2218. }
  2219. }
  2220. if( m_templateMultiPass.AvailableShaderProperties.Find( x => x.PropertyName.Equals( "_EmissionColor" ) ) == null )
  2221. {
  2222. if( !currDataCollector.ContainsProperty( "_EmissionColor" ) )
  2223. {
  2224. currDataCollector.AddToProperties( UniqueId, "[HideInInspector] _EmissionColor(\"Emission Color\", Color) = (1,1,1,1)", -1 );
  2225. }
  2226. }
  2227. }
  2228. m_templateMultiPass.SetPropertyData( currDataCollector.BuildUnformatedPropertiesStringArr() );
  2229. }
  2230. public void FillSubShaderData( /*MasterNodeDataCollector dataCollector = null */)
  2231. {
  2232. //MasterNodeDataCollector currDataCollector = ( dataCollector == null ) ? m_currentDataCollector : dataCollector;
  2233. //// SubShader Data
  2234. //m_templateMultiPass.SetPropertyData( currDataCollector.BuildUnformatedPropertiesStringArr() );
  2235. //templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModulePass, m_subShaderIdx, currDataCollector.GrabPassList );
  2236. if( ShaderLOD > -1 )
  2237. {
  2238. string lodUniqueId = m_templateMultiPass.SubShaders[ m_subShaderIdx ].UniquePrefix + "Module" + m_templateMultiPass.SubShaders[ m_subShaderIdx ].LODContainer.Id;
  2239. m_templateMultiPass.IdManager.SetReplacementText( lodUniqueId , "LOD " + ShaderLOD );
  2240. }
  2241. SetModuleData( m_subShaderModule , true );
  2242. }
  2243. public bool CheckDefineListItem( PropertyDataCollector item )
  2244. {
  2245. //The IsDirective flag in this context is used to determine if its #pragma
  2246. if( item.IsDirective )
  2247. {
  2248. return !m_currentDataCollector.ContainsPragma( item.PropertyName );
  2249. }
  2250. else
  2251. {
  2252. return !m_currentDataCollector.ContainsDefine( item.PropertyName );
  2253. }
  2254. }
  2255. public void FillPassData( TemplateMultiPassMasterNode masterNode , TemplateDataCollector mainTemplateDataCollector )
  2256. {
  2257. if( m_isInvisible != InvisibilityStatus.Visible )
  2258. {
  2259. if( masterNode.UniqueId != UniqueId )
  2260. {
  2261. if( ( m_invisibleOptions & (int)InvisibleOptionsEnum.SyncProperties ) > 0 )
  2262. {
  2263. PassModule.SyncWith( masterNode.PassModule );
  2264. }
  2265. }
  2266. int inputCount = m_inputPorts.Count;
  2267. for( int i = 0 ; i < inputCount ; i++ )
  2268. {
  2269. if( m_inputPorts[ i ].HasExternalLink )
  2270. {
  2271. TemplateMultiPassMasterNode linkedNode = m_inputPorts[ i ].ExternalLinkNode as TemplateMultiPassMasterNode;
  2272. if( linkedNode != null )
  2273. {
  2274. SetLinkedModuleData( linkedNode.PassModule );
  2275. }
  2276. }
  2277. }
  2278. }
  2279. SetModuleData( m_passModule , false );
  2280. if( m_currentDataCollector != null )
  2281. {
  2282. if( Pass.CustomOptionsContainer.CopyOptionsFromMainPass )
  2283. {
  2284. SetPassCustomOptionsInfo( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode );
  2285. }
  2286. else
  2287. {
  2288. SetPassCustomOptionsInfo( this );
  2289. }
  2290. var inputArray = m_currentDataCollector.VertexInputList.ToArray();
  2291. m_templateMultiPass.SetPassData( TemplateModuleDataType.PassVertexData , m_subShaderIdx , m_passIdx , inputArray );
  2292. m_templateMultiPass.SetPassData( TemplateModuleDataType.PassInterpolatorData , m_subShaderIdx , m_passIdx , m_currentDataCollector.InterpolatorList.ToArray() );
  2293. List<PropertyDataCollector> afterNativesIncludePragmaDefineList = new List<PropertyDataCollector>();
  2294. afterNativesIncludePragmaDefineList.AddRange( m_currentDataCollector.IncludesList );
  2295. afterNativesIncludePragmaDefineList.AddRange( m_currentDataCollector.DefinesList );
  2296. //includePragmaDefineList.AddRange( m_optionsDefineContainer.DefinesList );
  2297. afterNativesIncludePragmaDefineList.AddRange( m_currentDataCollector.PragmasList );
  2298. CheckSamplingMacrosFlag();
  2299. m_currentDataCollector.AddASEMacros();
  2300. afterNativesIncludePragmaDefineList.AddRange( m_currentDataCollector.AfterNativeDirectivesList );
  2301. //includePragmaDefineList.AddRange( m_currentDataCollector.MiscList );
  2302. List<PropertyDataCollector> beforeNatives = new List<PropertyDataCollector>();
  2303. int defineListCount = m_optionsDefineContainer.DefinesList.Count;
  2304. for( int i = 0 ; i < defineListCount ; i++ )
  2305. {
  2306. if( CheckDefineListItem( m_optionsDefineContainer.DefinesList[ i ] ) )
  2307. {
  2308. beforeNatives.Add( m_optionsDefineContainer.DefinesList[ i ] );
  2309. }
  2310. }
  2311. beforeNatives.AddRange( m_currentDataCollector.BeforeNativeDirectivesList );
  2312. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModulePragmaBefore , m_subShaderIdx , m_passIdx , beforeNatives );
  2313. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModulePragma , m_subShaderIdx , m_passIdx , afterNativesIncludePragmaDefineList );
  2314. m_currentDataCollector.TemplateDataCollectorInstance.CloseLateDirectives();
  2315. //Add Functions
  2316. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.FunctionsTag.IsValid )
  2317. {
  2318. m_currentDataCollector.FunctionsList.InsertRange( 0 , m_currentDataCollector.TemplateDataCollectorInstance.LateDirectivesList );
  2319. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleFunctions , m_subShaderIdx , m_passIdx , m_currentDataCollector.FunctionsList );
  2320. }
  2321. else
  2322. {
  2323. m_currentDataCollector.UniformsList.InsertRange( 0 , m_currentDataCollector.TemplateDataCollectorInstance.LateDirectivesList );
  2324. m_currentDataCollector.UniformsList.AddRange( m_currentDataCollector.FunctionsList );
  2325. }
  2326. //copy srp batch if present
  2327. //if( m_currentDataCollector.IsSRP )
  2328. //{
  2329. // m_currentDataCollector.UniformsList.AddRange( mainTemplateDataCollector.SrpBatcherPropertiesList );
  2330. //}
  2331. //m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleGlobals, m_subShaderIdx, m_passIdx, m_currentDataCollector.UniformsList );
  2332. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleInputVert , m_subShaderIdx , m_passIdx , m_currentDataCollector.TemplateDataCollectorInstance.VertexInputParamsStr );
  2333. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleInputFrag , m_subShaderIdx , m_passIdx , m_currentDataCollector.TemplateDataCollectorInstance.FragInputParamsStr );
  2334. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessVControlTag != null && m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessVControlTag.IsValid )
  2335. m_templateMultiPass.SetPassData( TemplateModuleDataType.VControl , m_subShaderIdx , m_passIdx , inputArray );
  2336. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessControlData != null && m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessControlData.IsValid )
  2337. 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 ) );
  2338. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessDomainData != null && m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].TessDomainData.IsValid )
  2339. 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 ) );
  2340. afterNativesIncludePragmaDefineList.Clear();
  2341. afterNativesIncludePragmaDefineList = null;
  2342. beforeNatives.Clear();
  2343. beforeNatives = null;
  2344. }
  2345. m_templateMultiPass.SetPassData( TemplateModuleDataType.PassNameData , m_subShaderIdx , m_passIdx , string.Format( PassNameFormateStr , m_passName ) );
  2346. }
  2347. public List<PropertyDataCollector> CrossCheckSoftRegisteredUniformList( List<PropertyDataCollector> uniformList )
  2348. {
  2349. List<PropertyDataCollector> newItems = new List<PropertyDataCollector>();
  2350. for( int i = 0 ; i < uniformList.Count ; i++ )
  2351. {
  2352. if( !m_currentDataCollector.CheckIfSoftRegistered( uniformList[ i ].PropertyName ) )
  2353. {
  2354. newItems.Add( uniformList[ i ] );
  2355. }
  2356. }
  2357. return newItems;
  2358. }
  2359. public void FillUniforms( TemplateDataCollector mainTemplateDataCollector )
  2360. {
  2361. if( m_currentDataCollector.IsSRP )
  2362. {
  2363. if( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPBatcherTag.IsValid )
  2364. {
  2365. List<PropertyDataCollector> finalList = CrossCheckSoftRegisteredUniformList( mainTemplateDataCollector.SrpBatcherPropertiesList );
  2366. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleSRPBatcher , m_subShaderIdx , m_passIdx , finalList );
  2367. finalList.Clear();
  2368. finalList = null;
  2369. }
  2370. else
  2371. {
  2372. List<PropertyDataCollector> finalList = CrossCheckSoftRegisteredUniformList( mainTemplateDataCollector.FullSrpBatcherPropertiesList );
  2373. m_currentDataCollector.UniformsList.AddRange( finalList );
  2374. finalList.Clear();
  2375. finalList = null;
  2376. }
  2377. }
  2378. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleGlobals , m_subShaderIdx , m_passIdx , m_currentDataCollector.UniformsList );
  2379. }
  2380. void SetLinkedModuleData( TemplateModulesHelper linkedModule )
  2381. {
  2382. //if( linkedModule.AdditionalPragmas.ValidData )
  2383. //{
  2384. // linkedModule.AdditionalPragmas.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2385. //}
  2386. //if( linkedModule.AdditionalIncludes.ValidData )
  2387. //{
  2388. // linkedModule.AdditionalIncludes.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2389. //}
  2390. //if( linkedModule.AdditionalDefines.ValidData )
  2391. //{
  2392. // linkedModule.AdditionalDefines.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2393. //}
  2394. if( linkedModule.AdditionalDirectives.ValidData )
  2395. {
  2396. var pass = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ];
  2397. linkedModule.AdditionalDirectives.AddAllToDataCollector( ref m_currentDataCollector , pass, pass.Modules.IncludePragmaContainer );
  2398. }
  2399. }
  2400. void SetModuleData( TemplateModulesHelper module , bool isSubShader )
  2401. {
  2402. if( isSubShader )
  2403. {
  2404. //if ( module.AdditionalPragmas.ValidData )
  2405. //{
  2406. // module.AdditionalPragmas.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.IncludePragmaContainer );
  2407. //}
  2408. //if ( module.AdditionalIncludes.ValidData )
  2409. //{
  2410. // module.AdditionalIncludes.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.IncludePragmaContainer );
  2411. //}
  2412. //if ( module.AdditionalDefines.ValidData )
  2413. //{
  2414. // module.AdditionalDefines.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.IncludePragmaContainer );
  2415. //}
  2416. if( module.AdditionalDirectives.ValidData )
  2417. {
  2418. module.AdditionalDirectives.AddAllToDataCollector( ref m_currentDataCollector , null, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules.IncludePragmaContainer );
  2419. }
  2420. if( module.TagsHelper.ValidData )
  2421. {
  2422. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleTag , m_subShaderIdx , module.TagsHelper.GenerateTags() );
  2423. }
  2424. if( module.AllModulesMode )
  2425. {
  2426. string body = module.GenerateAllModulesString( isSubShader );
  2427. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.AllModules , m_subShaderIdx , body.Split( '\n' ) );
  2428. }
  2429. if( module.ShaderModelHelper.ValidAndIndependent )
  2430. {
  2431. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleShaderModel , m_subShaderIdx , module.ShaderModelHelper.GenerateShaderData( isSubShader ) );
  2432. }
  2433. if( module.BlendOpHelper.IndependentModule && module.BlendOpHelper.ValidBlendMode )
  2434. {
  2435. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendMode , m_subShaderIdx , module.BlendOpHelper.CurrentBlendFactor );
  2436. }
  2437. if( module.BlendOpHelper1.IndependentModule && module.BlendOpHelper1.ValidBlendMode )
  2438. {
  2439. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendMode1 , m_subShaderIdx , module.BlendOpHelper1.CurrentBlendFactor );
  2440. }
  2441. if( module.BlendOpHelper2.IndependentModule && module.BlendOpHelper2.ValidBlendMode )
  2442. {
  2443. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendMode2 , m_subShaderIdx , module.BlendOpHelper2.CurrentBlendFactor );
  2444. }
  2445. if( module.BlendOpHelper3.IndependentModule && module.BlendOpHelper3.ValidBlendMode )
  2446. {
  2447. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendMode3 , m_subShaderIdx , module.BlendOpHelper3.CurrentBlendFactor );
  2448. }
  2449. if( module.BlendOpHelper.IndependentModule && module.BlendOpHelper.ValidBlendOp )
  2450. {
  2451. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendOp , m_subShaderIdx , module.BlendOpHelper.CurrentBlendOp );
  2452. }
  2453. if( module.BlendOpHelper1.IndependentModule && module.BlendOpHelper1.ValidBlendOp )
  2454. {
  2455. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendOp1 , m_subShaderIdx , module.BlendOpHelper1.CurrentBlendOp );
  2456. }
  2457. if( module.BlendOpHelper2.IndependentModule && module.BlendOpHelper2.ValidBlendOp )
  2458. {
  2459. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendOp2 , m_subShaderIdx , module.BlendOpHelper2.CurrentBlendOp );
  2460. }
  2461. if( module.BlendOpHelper3.IndependentModule && module.BlendOpHelper3.ValidBlendOp )
  2462. {
  2463. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleBlendOp3 , m_subShaderIdx , module.BlendOpHelper3.CurrentBlendOp );
  2464. }
  2465. if( module.AlphaToMaskHelper.ValidAndIndependent )
  2466. {
  2467. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleAlphaToMask , m_subShaderIdx , module.AlphaToMaskHelper.GenerateShaderData( isSubShader ) );
  2468. }
  2469. if( module.CullModeHelper.ValidAndIndependent )
  2470. {
  2471. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleCullMode , m_subShaderIdx , module.CullModeHelper.GenerateShaderData( isSubShader ) );
  2472. }
  2473. if( module.ColorMaskHelper.ValidAndIndependent )
  2474. {
  2475. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleColorMask , m_subShaderIdx , module.ColorMaskHelper.GenerateShaderData( isSubShader ) );
  2476. }
  2477. if( module.ColorMaskHelper1.ValidAndIndependent )
  2478. {
  2479. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleColorMask1 , m_subShaderIdx , module.ColorMaskHelper1.GenerateShaderData( isSubShader ) );
  2480. }
  2481. if( module.ColorMaskHelper2.ValidAndIndependent )
  2482. {
  2483. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleColorMask2 , m_subShaderIdx , module.ColorMaskHelper2.GenerateShaderData( isSubShader ) );
  2484. }
  2485. if( module.ColorMaskHelper3.ValidAndIndependent )
  2486. {
  2487. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleColorMask3 , m_subShaderIdx , module.ColorMaskHelper3.GenerateShaderData( isSubShader ) );
  2488. }
  2489. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidZTest )
  2490. {
  2491. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleZTest , m_subShaderIdx , module.DepthOphelper.CurrentZTestMode );
  2492. }
  2493. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidZWrite )
  2494. {
  2495. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleZwrite , m_subShaderIdx , module.DepthOphelper.CurrentZWriteMode );
  2496. }
  2497. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidOffset )
  2498. {
  2499. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleZOffset , m_subShaderIdx , module.DepthOphelper.CurrentOffset );
  2500. }
  2501. if( module.StencilBufferHelper.ValidAndIndependent )
  2502. {
  2503. CullMode cullMode = ( module.CullModeHelper.ValidData ) ? module.CullModeHelper.CurrentCullMode : CullMode.Back;
  2504. string value = module.StencilBufferHelper.CreateStencilOp( cullMode );
  2505. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleStencil , m_subShaderIdx , value.Split( '\n' ) );
  2506. }
  2507. if( module.RenderingPlatforms.LoadedFromTemplate )
  2508. {
  2509. m_templateMultiPass.SetSubShaderData( TemplateModuleDataType.ModuleRenderPlatforms , m_subShaderIdx , module.RenderingPlatforms.CreateResult(true) );
  2510. }
  2511. }
  2512. else
  2513. {
  2514. //if ( module.AdditionalPragmas.ValidData )
  2515. //{
  2516. // module.AdditionalPragmas.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2517. //}
  2518. //if ( module.AdditionalIncludes.ValidData )
  2519. //{
  2520. // module.AdditionalIncludes.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2521. //}
  2522. //if ( module.AdditionalDefines.ValidData )
  2523. //{
  2524. // module.AdditionalDefines.AddToDataCollector( ref m_currentDataCollector, m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.IncludePragmaContainer );
  2525. //}
  2526. List<PropertyDataCollector> aboveUsePass = new List<PropertyDataCollector>();
  2527. List<PropertyDataCollector> belowUsePass = new List<PropertyDataCollector>();
  2528. m_usePass.BuildUsePassInfo( m_currentDataCollector , ref aboveUsePass , ref belowUsePass );
  2529. //TODO Must place this on the correct place
  2530. aboveUsePass.AddRange( belowUsePass );
  2531. //adding grab pass after use pass on purpose, so it wont be caught by them
  2532. aboveUsePass.AddRange( m_currentDataCollector.GrabPassList );
  2533. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModulePass , m_subShaderIdx , m_passIdx , aboveUsePass );
  2534. //m_templateMultiPass.SetPassData( TemplateModuleDataType.EndPass, m_subShaderIdx, m_passIdx, bellowUsePass);
  2535. if( module.AdditionalDirectives.ValidData )
  2536. {
  2537. var pass = m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ];
  2538. module.AdditionalDirectives.AddAllToDataCollector( ref m_currentDataCollector , pass, pass.Modules.IncludePragmaContainer );
  2539. }
  2540. if( module.TagsHelper.ValidData )
  2541. {
  2542. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleTag , m_subShaderIdx , m_passIdx , module.TagsHelper.GenerateTags() );
  2543. }
  2544. if( module.AllModulesMode )
  2545. {
  2546. string body = module.GenerateAllModulesString( isSubShader );
  2547. m_templateMultiPass.SetPassData( TemplateModuleDataType.AllModules , m_subShaderIdx , m_passIdx , body.Split( '\n' ) );
  2548. }
  2549. if( module.ShaderModelHelper.ValidAndIndependent )
  2550. {
  2551. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleShaderModel , m_subShaderIdx , m_passIdx , module.ShaderModelHelper.GenerateShaderData( isSubShader ) );
  2552. }
  2553. if( module.BlendOpHelper.IndependentModule && module.BlendOpHelper.ValidBlendMode )
  2554. {
  2555. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendMode , m_subShaderIdx , m_passIdx , module.BlendOpHelper.CurrentBlendFactor );
  2556. }
  2557. if( module.BlendOpHelper1.IndependentModule && module.BlendOpHelper1.ValidBlendMode )
  2558. {
  2559. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendMode1 , m_subShaderIdx , m_passIdx , module.BlendOpHelper1.CurrentBlendFactor );
  2560. }
  2561. if( module.BlendOpHelper2.IndependentModule && module.BlendOpHelper2.ValidBlendMode )
  2562. {
  2563. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendMode2 , m_subShaderIdx , m_passIdx , module.BlendOpHelper2.CurrentBlendFactor );
  2564. }
  2565. if( module.BlendOpHelper3.IndependentModule && module.BlendOpHelper3.ValidBlendMode )
  2566. {
  2567. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendMode3 , m_subShaderIdx , m_passIdx , module.BlendOpHelper3.CurrentBlendFactor );
  2568. }
  2569. if( module.BlendOpHelper.IndependentModule && module.BlendOpHelper.ValidBlendOp )
  2570. {
  2571. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendOp , m_subShaderIdx , m_passIdx , module.BlendOpHelper.CurrentBlendOp );
  2572. }
  2573. if( module.BlendOpHelper1.IndependentModule && module.BlendOpHelper1.ValidBlendOp )
  2574. {
  2575. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendOp1 , m_subShaderIdx , m_passIdx , module.BlendOpHelper1.CurrentBlendOp );
  2576. }
  2577. if( module.BlendOpHelper2.IndependentModule && module.BlendOpHelper2.ValidBlendOp )
  2578. {
  2579. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendOp2 , m_subShaderIdx , m_passIdx , module.BlendOpHelper2.CurrentBlendOp );
  2580. }
  2581. if( module.BlendOpHelper3.IndependentModule && module.BlendOpHelper3.ValidBlendOp )
  2582. {
  2583. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleBlendOp3 , m_subShaderIdx , m_passIdx , module.BlendOpHelper3.CurrentBlendOp );
  2584. }
  2585. if( module.AlphaToMaskHelper.ValidAndIndependent )
  2586. {
  2587. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleAlphaToMask , m_subShaderIdx , m_passIdx , module.AlphaToMaskHelper.GenerateShaderData( isSubShader ) );
  2588. }
  2589. if( module.CullModeHelper.ValidAndIndependent )
  2590. {
  2591. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleCullMode , m_subShaderIdx , m_passIdx , module.CullModeHelper.GenerateShaderData( isSubShader ) );
  2592. }
  2593. if( module.ColorMaskHelper.ValidAndIndependent )
  2594. {
  2595. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleColorMask , m_subShaderIdx , m_passIdx , module.ColorMaskHelper.GenerateShaderData( isSubShader ) );
  2596. }
  2597. if( module.ColorMaskHelper1.ValidAndIndependent )
  2598. {
  2599. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleColorMask1 , m_subShaderIdx , m_passIdx , module.ColorMaskHelper1.GenerateShaderData( isSubShader ) );
  2600. }
  2601. if( module.ColorMaskHelper2.ValidAndIndependent )
  2602. {
  2603. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleColorMask2 , m_subShaderIdx , m_passIdx , module.ColorMaskHelper2.GenerateShaderData( isSubShader ) );
  2604. }
  2605. if( module.ColorMaskHelper3.ValidAndIndependent )
  2606. {
  2607. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleColorMask3 , m_subShaderIdx , m_passIdx , module.ColorMaskHelper3.GenerateShaderData( isSubShader ) );
  2608. }
  2609. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidZTest )
  2610. {
  2611. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleZTest , m_subShaderIdx , m_passIdx , module.DepthOphelper.CurrentZTestMode );
  2612. }
  2613. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidZWrite )
  2614. {
  2615. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleZwrite , m_subShaderIdx , m_passIdx , module.DepthOphelper.CurrentZWriteMode );
  2616. }
  2617. if( module.DepthOphelper.IndependentModule && module.DepthOphelper.ValidOffset )
  2618. {
  2619. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleZOffset , m_subShaderIdx , m_passIdx , module.DepthOphelper.CurrentOffset );
  2620. }
  2621. if( module.StencilBufferHelper.ValidAndIndependent )
  2622. {
  2623. CullMode cullMode = ( module.CullModeHelper.ValidData ) ? module.CullModeHelper.CurrentCullMode : CullMode.Back;
  2624. string value = module.StencilBufferHelper.CreateStencilOp( cullMode );
  2625. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleStencil , m_subShaderIdx , m_passIdx , value.Split( '\n' ) );
  2626. }
  2627. if( module.RenderingPlatforms.LoadedFromTemplate )
  2628. {
  2629. m_templateMultiPass.SetPassData( TemplateModuleDataType.ModuleRenderPlatforms , m_subShaderIdx , m_passIdx , module.RenderingPlatforms.CreateResult( true ) );
  2630. }
  2631. }
  2632. }
  2633. public override string GenerateShaderForOutput( int outputId , ref MasterNodeDataCollector dataCollector , bool ignoreLocalvar )
  2634. {
  2635. return "0";
  2636. }
  2637. public override void Destroy()
  2638. {
  2639. base.Destroy();
  2640. m_drawInstancedHelper = null;
  2641. m_optionsDefineContainer.Destroy();
  2642. m_optionsDefineContainer = null;
  2643. m_passSelector.Destroy();
  2644. m_passSelector = null;
  2645. m_subShaderOptions.Destroy();
  2646. m_passOptions.Destroy();
  2647. m_fallbackHelper.Destroy();
  2648. GameObject.DestroyImmediate( m_fallbackHelper );
  2649. m_fallbackHelper = null;
  2650. m_usePass.Destroy();
  2651. GameObject.DestroyImmediate( m_usePass );
  2652. m_usePass = null;
  2653. m_dependenciesHelper.Destroy();
  2654. m_dependenciesHelper = null;
  2655. m_subShaderModule.Destroy();
  2656. m_subShaderModule = null;
  2657. m_passModule.Destroy();
  2658. m_passModule = null;
  2659. if( m_lodIndex == -1 )
  2660. {
  2661. ContainerGraph.MultiPassMasterNodes.RemoveNode( this );
  2662. }
  2663. else
  2664. {
  2665. ContainerGraph.LodMultiPassMasternodes[ m_lodIndex ].RemoveNode( this );
  2666. }
  2667. }
  2668. void UpdateSubShaderPassStr()
  2669. {
  2670. //m_subShaderIdxStr = SubShaderModuleStr + m_templateMultiPass.SubShaders[ m_subShaderIdx ].Idx;
  2671. //m_passIdxStr = PassModuleStr + m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Idx;
  2672. }
  2673. public override void ReadFromString( ref string[] nodeParams )
  2674. {
  2675. base.ReadFromString( ref nodeParams );
  2676. string currShaderName = string.Empty;
  2677. try
  2678. {
  2679. currShaderName = GetCurrentParam( ref nodeParams );
  2680. if ( currShaderName.Length > 0 )
  2681. currShaderName = UIUtils.RemoveShaderInvalidCharacters( currShaderName );
  2682. m_templateGUID = GetCurrentParam( ref nodeParams );
  2683. bool hasUniqueName = false;
  2684. if( UIUtils.CurrentShaderVersion() > PASS_UNIQUE_ID_VERSION )
  2685. {
  2686. hasUniqueName = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  2687. }
  2688. if( hasUniqueName )
  2689. m_passUniqueId = GetCurrentParam( ref nodeParams );
  2690. m_subShaderIdx = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  2691. m_passIdx = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  2692. if( UIUtils.CurrentShaderVersion() > LOD_SUBSHADER_VERSION )
  2693. {
  2694. if( m_lodIndex != -1 )
  2695. {
  2696. m_containerGraph.MultiPassMasterNodes.RemoveNode( this );
  2697. m_containerGraph.LodMultiPassMasternodes[ m_lodIndex ].AddNode( this );
  2698. }
  2699. }
  2700. m_passName = GetCurrentParam( ref nodeParams );
  2701. SetTemplate( null, false, true, m_subShaderIdx, m_passIdx, SetTemplateSource.ShaderLoad );
  2702. }
  2703. catch ( Exception e )
  2704. {
  2705. Debug.LogException( e, this );
  2706. }
  2707. if ( !m_invalidNode ) try
  2708. {
  2709. ////If value gotten from template is > -1 then it contains the LOD field
  2710. ////and we can properly write the value
  2711. //if( m_subShaderLOD > -1 )
  2712. //{
  2713. // m_subShaderLOD = subShaderLOD;
  2714. //}
  2715. // only in here, after SetTemplate, we know if shader name is to be used as title or not
  2716. ShaderName = currShaderName;
  2717. m_visiblePorts = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  2718. m_subShaderModule.ReadFromString( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Modules, ref m_currentReadParamIdx, ref nodeParams );
  2719. m_passModule.ReadFromString( m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules, ref m_currentReadParamIdx, ref nodeParams );
  2720. if( UIUtils.CurrentShaderVersion() > 15308 )
  2721. {
  2722. m_fallbackHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2723. m_dependenciesHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2724. }
  2725. if( UIUtils.CurrentShaderVersion() > 15402 )
  2726. {
  2727. m_usePass.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2728. }
  2729. if( UIUtils.CurrentShaderVersion() > 15409 )
  2730. {
  2731. m_hdSrpMaterialType = (HDSRPMaterialType)Enum.Parse( typeof( HDSRPMaterialType ) , GetCurrentParam( ref nodeParams ) );
  2732. }
  2733. if( UIUtils.CurrentShaderVersion() > 15501 )
  2734. {
  2735. if( m_isMainOutputNode && UIUtils.CurrentShaderVersion() > PASS_SELECTOR_VERSION )
  2736. m_subShaderOptions.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2737. m_passOptions.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2738. }
  2739. if( m_isMainOutputNode && UIUtils.CurrentShaderVersion() > PASS_SELECTOR_VERSION )
  2740. {
  2741. m_passSelector.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
  2742. // @diogo: reset pass selector for any shader below version 19000 (when pass number was changed)
  2743. if ( UIUtils.CurrentShaderVersion() < 19000 )
  2744. {
  2745. m_passSelector.Reset();
  2746. }
  2747. }
  2748. if( m_isMainOutputNode && UIUtils.CurrentShaderVersion() > 16203 )
  2749. {
  2750. m_drawInstancedHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2751. }
  2752. if( m_isMainOutputNode && UIUtils.CurrentShaderVersion() > LOD_SUBSHADER_VERSION )
  2753. {
  2754. m_mainLODName = GetCurrentParam( ref nodeParams );
  2755. SetupLODNodeName();
  2756. }
  2757. else
  2758. {
  2759. m_content.text = GenerateClippedTitle( m_passName );
  2760. }
  2761. if( UIUtils.CurrentShaderVersion() > 18302 )
  2762. SamplingMacros = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  2763. else
  2764. SamplingMacros = false;
  2765. //if( m_templateMultiPass != null && !m_templateMultiPass.IsSinglePass )
  2766. //{
  2767. // SetClippedTitle( m_passName );
  2768. //}
  2769. CheckLegacyCustomInspectors();
  2770. }
  2771. catch( Exception e )
  2772. {
  2773. Debug.LogException( e , this );
  2774. }
  2775. m_containerGraph.CurrentCanvasMode = NodeAvailability.TemplateShader;
  2776. if ( m_isMainOutputNode )
  2777. {
  2778. m_containerGraph.CurrentPrecision = m_currentPrecisionType;
  2779. }
  2780. }
  2781. void CheckLegacyCustomInspectors()
  2782. {
  2783. #if UNITY_2021_2_OR_NEWER
  2784. if( m_templateMultiPass.SubShaders[ 0 ].Modules.SRPType == TemplateSRPType.HDRP && ASEPackageManagerHelper.CurrentHDRPBaseline >= ASESRPBaseline.ASE_SRP_11 )
  2785. {
  2786. if( Constants.CustomInspectorHDLegacyTo11.ContainsKey( m_customInspectorName ) )
  2787. {
  2788. UIUtils.ShowMessage( string.Format( "Detected obsolete custom inspector '{0}' in shader meta. Converting to new one '{1}'" , m_customInspectorName , Constants.CustomInspectorHDLegacyTo11[ m_customInspectorName ] ) , MessageSeverity.Warning );
  2789. m_customInspectorName = Constants.CustomInspectorHDLegacyTo11[ m_customInspectorName ];
  2790. }
  2791. }
  2792. if( m_templateMultiPass.SubShaders[ 0 ].Modules.SRPType == TemplateSRPType.URP && ASEPackageManagerHelper.CurrentURPBaseline>= ASESRPBaseline.ASE_SRP_12 )
  2793. {
  2794. if( Constants.CustomInspectorURP10To12.ContainsKey( m_customInspectorName ) )
  2795. {
  2796. string newCustomInspector = string.Empty;
  2797. if( TemplatesManager.URPLitGUID.Equals( m_templateMultiPass.GUID ))
  2798. {
  2799. newCustomInspector = "UnityEditor.ShaderGraphLitGUI";
  2800. }
  2801. else if( TemplatesManager.URPUnlitGUID.Equals( m_templateMultiPass.GUID ) )
  2802. {
  2803. newCustomInspector = "UnityEditor.ShaderGraphUnlitGUI";
  2804. }
  2805. if( !string.IsNullOrEmpty( newCustomInspector ) )
  2806. {
  2807. UIUtils.ShowMessage( string.Format( "Detected obsolete custom inspector '{0}' in shader meta. Converting to new one '{1}'" , m_customInspectorName , newCustomInspector ) , MessageSeverity.Warning );
  2808. m_customInspectorName = newCustomInspector;
  2809. }
  2810. }
  2811. }
  2812. #elif UNITY_2021_1_OR_NEWER
  2813. if( m_templateMultiPass.SubShaders[ 0 ].Modules.SRPType == TemplateSRPType.HDRP && ASEPackageManagerHelper.CurrentHDRPBaseline >= ASESRPBaseline.ASE_SRP_11 )
  2814. {
  2815. if( Constants.CustomInspectorHDLegacyTo11.ContainsKey( m_customInspectorName ) )
  2816. {
  2817. UIUtils.ShowMessage( string.Format( "Detected obsolete custom inspector '{0}' in shader meta. Converting to new one '{1}'" , m_customInspectorName , Constants.CustomInspectorHDLegacyTo11[ m_customInspectorName ] ) , MessageSeverity.Warning );
  2818. m_customInspectorName = Constants.CustomInspectorHDLegacyTo11[ m_customInspectorName ];
  2819. }
  2820. }
  2821. #elif UNITY_2020_2_OR_NEWER
  2822. if( m_templateMultiPass.SubShaders[0].Modules.SRPType == TemplateSRPType.HDRP && ASEPackageManagerHelper.CurrentHDRPBaseline >= ASESRPBaseline.ASE_SRP_10 )
  2823. {
  2824. if( Constants.CustomInspectorHD7To10.ContainsKey( m_customInspectorName ) )
  2825. {
  2826. UIUtils.ShowMessage( string.Format("Detected obsolete custom inspector '{0}' in shader meta. Converting to new one '{1}'", m_customInspectorName , Constants.CustomInspectorHD7To10[ m_customInspectorName ] ), MessageSeverity.Warning );
  2827. m_customInspectorName = Constants.CustomInspectorHD7To10[ m_customInspectorName ];
  2828. }
  2829. }
  2830. #endif
  2831. }
  2832. public override void WriteToString( ref string nodeInfo , ref string connectionsInfo )
  2833. {
  2834. base.WriteToString( ref nodeInfo , ref connectionsInfo );
  2835. IOUtils.AddFieldValueToString( ref nodeInfo , ShaderName );
  2836. IOUtils.AddFieldValueToString( ref nodeInfo , m_templateGUID );
  2837. bool hasUniquePassName = Pass.Modules.HasPassUniqueName;
  2838. IOUtils.AddFieldValueToString( ref nodeInfo , hasUniquePassName );
  2839. if( hasUniquePassName )
  2840. {
  2841. IOUtils.AddFieldValueToString( ref nodeInfo , Pass.Modules.PassUniqueName );
  2842. }
  2843. IOUtils.AddFieldValueToString( ref nodeInfo , m_subShaderIdx );
  2844. IOUtils.AddFieldValueToString( ref nodeInfo , m_passIdx );
  2845. IOUtils.AddFieldValueToString( ref nodeInfo , m_passName );
  2846. IOUtils.AddFieldValueToString( ref nodeInfo , m_visiblePorts );
  2847. m_subShaderModule.WriteToString( ref nodeInfo );
  2848. m_passModule.WriteToString( ref nodeInfo );
  2849. m_fallbackHelper.WriteToString( ref nodeInfo );
  2850. m_dependenciesHelper.WriteToString( ref nodeInfo );
  2851. m_usePass.WriteToString( ref nodeInfo );
  2852. IOUtils.AddFieldValueToString( ref nodeInfo , m_hdSrpMaterialType );
  2853. if( m_isMainOutputNode )
  2854. m_subShaderOptions.WriteToString( ref nodeInfo );
  2855. m_passOptions.WriteToString( ref nodeInfo );
  2856. if( m_isMainOutputNode )
  2857. {
  2858. m_passSelector.WriteToString( ref nodeInfo );
  2859. m_drawInstancedHelper.WriteToString( ref nodeInfo );
  2860. }
  2861. if( m_isMainOutputNode )
  2862. IOUtils.AddFieldValueToString( ref nodeInfo , m_mainLODName );
  2863. IOUtils.AddFieldValueToString( ref nodeInfo , m_samplingMacros );
  2864. }
  2865. public override void ReadFromDeprecated( ref string[] nodeParams , Type oldType = null )
  2866. {
  2867. base.ReadFromString( ref nodeParams );
  2868. try
  2869. {
  2870. string currShaderName = GetCurrentParam( ref nodeParams );
  2871. if( currShaderName.Length > 0 )
  2872. currShaderName = UIUtils.RemoveShaderInvalidCharacters( currShaderName );
  2873. string templateGUID = GetCurrentParam( ref nodeParams );
  2874. string templateShaderName = string.Empty;
  2875. if( UIUtils.CurrentShaderVersion() > 13601 )
  2876. {
  2877. templateShaderName = GetCurrentParam( ref nodeParams );
  2878. }
  2879. TemplateMultiPass template = m_containerGraph.ParentWindow.TemplatesManagerInstance.GetTemplate( templateGUID ) as TemplateMultiPass;
  2880. if( template != null )
  2881. {
  2882. m_templateGUID = templateGUID;
  2883. SetTemplate( null , false , true , 0 , 0 , SetTemplateSource.ShaderLoad );
  2884. }
  2885. else
  2886. {
  2887. template = m_containerGraph.ParentWindow.TemplatesManagerInstance.GetTemplateByName( templateShaderName ) as TemplateMultiPass;
  2888. if( template != null )
  2889. {
  2890. m_templateGUID = template.GUID;
  2891. SetTemplate( null , false , true , 0 , 0 , SetTemplateSource.ShaderLoad );
  2892. }
  2893. else
  2894. {
  2895. m_masterNodeCategory = -1;
  2896. }
  2897. }
  2898. if( m_invalidNode )
  2899. return;
  2900. // only in here, after SetTemplate, we know if shader name is to be used as title or not
  2901. ShaderName = currShaderName;
  2902. if( UIUtils.CurrentShaderVersion() > 13902 )
  2903. {
  2904. //BLEND MODULE
  2905. if( m_templateMultiPass.SubShaders[ 0 ].Modules.BlendData.ValidBlendMode )
  2906. {
  2907. m_subShaderModule.BlendOpHelper.ReadBlendModeFromString( ref m_currentReadParamIdx , ref nodeParams );
  2908. }
  2909. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.BlendData.ValidBlendMode )
  2910. {
  2911. m_passModule.BlendOpHelper.ReadBlendModeFromString( ref m_currentReadParamIdx , ref nodeParams );
  2912. }
  2913. if( m_templateMultiPass.SubShaders[ 0 ].Modules.BlendData.ValidBlendOp )
  2914. {
  2915. m_subShaderModule.BlendOpHelper.ReadBlendOpFromString( ref m_currentReadParamIdx , ref nodeParams );
  2916. }
  2917. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.BlendData.ValidBlendOp )
  2918. {
  2919. m_passModule.BlendOpHelper.ReadBlendOpFromString( ref m_currentReadParamIdx , ref nodeParams );
  2920. }
  2921. //CULL MODE
  2922. if( m_templateMultiPass.SubShaders[ 0 ].Modules.CullModeData.DataCheck == TemplateDataCheck.Valid )
  2923. {
  2924. m_subShaderModule.CullModeHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2925. }
  2926. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.CullModeData.DataCheck == TemplateDataCheck.Valid )
  2927. {
  2928. m_passModule.CullModeHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2929. }
  2930. //COLOR MASK
  2931. if( m_templateMultiPass.SubShaders[ 0 ].Modules.ColorMaskData.DataCheck == TemplateDataCheck.Valid )
  2932. {
  2933. m_subShaderModule.ColorMaskHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2934. }
  2935. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.ColorMaskData.DataCheck == TemplateDataCheck.Valid )
  2936. {
  2937. m_passModule.ColorMaskHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2938. }
  2939. //STENCIL BUFFER
  2940. if( m_templateMultiPass.SubShaders[ 0 ].Modules.StencilData.DataCheck == TemplateDataCheck.Valid )
  2941. {
  2942. m_subShaderModule.StencilBufferHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2943. }
  2944. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.StencilData.DataCheck == TemplateDataCheck.Valid )
  2945. {
  2946. m_passModule.StencilBufferHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2947. }
  2948. }
  2949. if( UIUtils.CurrentShaderVersion() > 14202 )
  2950. {
  2951. //DEPTH OPTIONS
  2952. if( m_templateMultiPass.SubShaders[ 0 ].Modules.DepthData.ValidZWrite )
  2953. {
  2954. m_subShaderModule.DepthOphelper.ReadZWriteFromString( ref m_currentReadParamIdx , ref nodeParams );
  2955. }
  2956. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.DepthData.ValidZWrite )
  2957. {
  2958. m_passModule.DepthOphelper.ReadZWriteFromString( ref m_currentReadParamIdx , ref nodeParams );
  2959. }
  2960. if( m_templateMultiPass.SubShaders[ 0 ].Modules.DepthData.ValidZTest )
  2961. {
  2962. m_subShaderModule.DepthOphelper.ReadZTestFromString( ref m_currentReadParamIdx , ref nodeParams );
  2963. }
  2964. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.DepthData.ValidZTest )
  2965. {
  2966. m_subShaderModule.DepthOphelper.ReadZTestFromString( ref m_currentReadParamIdx , ref nodeParams );
  2967. }
  2968. if( m_templateMultiPass.SubShaders[ 0 ].Modules.DepthData.ValidOffset )
  2969. {
  2970. m_subShaderModule.DepthOphelper.ReadOffsetFromString( ref m_currentReadParamIdx , ref nodeParams );
  2971. }
  2972. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.DepthData.ValidOffset )
  2973. {
  2974. m_passModule.DepthOphelper.ReadOffsetFromString( ref m_currentReadParamIdx , ref nodeParams );
  2975. }
  2976. }
  2977. //TAGS
  2978. if( UIUtils.CurrentShaderVersion() > 14301 )
  2979. {
  2980. if( m_templateMultiPass.SubShaders[ 0 ].Modules.TagData.DataCheck == TemplateDataCheck.Valid )
  2981. {
  2982. m_subShaderModule.TagsHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2983. }
  2984. else if( m_templateMultiPass.SubShaders[ 0 ].Passes[ 0 ].Modules.TagData.DataCheck == TemplateDataCheck.Valid )
  2985. {
  2986. m_passModule.TagsHelper.ReadFromString( ref m_currentReadParamIdx , ref nodeParams );
  2987. }
  2988. }
  2989. SamplingMacros = false;
  2990. }
  2991. catch( Exception e )
  2992. {
  2993. Debug.LogException( e , this );
  2994. }
  2995. m_containerGraph.CurrentCanvasMode = NodeAvailability.TemplateShader;
  2996. }
  2997. public void ForceOptionsRefresh()
  2998. {
  2999. m_passOptions.Refresh();
  3000. if( m_isMainOutputNode )
  3001. m_subShaderOptions.Refresh();
  3002. }
  3003. public void SetPassVisible( string passName , bool visible )
  3004. {
  3005. TemplateMultiPassMasterNode node = m_containerGraph.GetMasterNodeOfPass( passName , m_lodIndex );
  3006. if( node != null )
  3007. {
  3008. m_passSelector.SetPassVisible( passName , visible );
  3009. node.IsInvisible = !visible;
  3010. }
  3011. }
  3012. public override void RefreshExternalReferences()
  3013. {
  3014. if( m_invalidNode )
  3015. return;
  3016. base.RefreshExternalReferences();
  3017. if( IsLODMainMasterNode )
  3018. {
  3019. SetMasterNodeCategoryFromGUID( m_templateGUID );
  3020. }
  3021. CheckTemplateChanges();
  3022. if( m_templateMultiPass != null && m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].Modules.SRPIsPBRHD && UIUtils.CurrentShaderVersion() < 15410 )
  3023. {
  3024. FetchHDPorts();
  3025. m_hdSrpMaterialType = ( m_specularPort != null && m_specularPort.HasOwnOrLinkConnection ) ? HDSRPMaterialType.Specular : HDSRPMaterialType.Standard;
  3026. ConfigHDPorts();
  3027. }
  3028. if( ContainerGraph.HasLODs )
  3029. {
  3030. SetClippedAdditionalTitle( string.Format( LodSubtitle , ShaderLOD ) );
  3031. }
  3032. if( m_isMainOutputNode )
  3033. {
  3034. List<TemplateMultiPassMasterNode> masterNodes = ( m_lodIndex == -1 ) ? m_containerGraph.MultiPassMasterNodes.NodesList : m_containerGraph.LodMultiPassMasternodes[ m_lodIndex ].NodesList;
  3035. masterNodes.Sort( ( x , y ) => ( x.PassIdx.CompareTo( y.PassIdx ) ) );
  3036. int passAmount = m_templateMultiPass.SubShaders[ m_subShaderIdx ].PassAmount;
  3037. if( passAmount != masterNodes.Count )
  3038. {
  3039. UIUtils.ShowMessage( "Template master nodes amount was modified. Could not set correctly its visibility options." );
  3040. }
  3041. else
  3042. {
  3043. for( int i = 0 ; i < passAmount ; i++ )
  3044. {
  3045. if( i != m_passIdx )
  3046. {
  3047. masterNodes[ i ].IsInvisible = !m_passSelector.IsVisible( i );
  3048. }
  3049. }
  3050. }
  3051. }
  3052. }
  3053. public override void ReadInputDataFromString( ref string[] nodeParams )
  3054. {
  3055. if ( m_invalidNode )
  3056. return;
  3057. //For a Template Master Node an input port data must be set by its template and not meta data
  3058. if( UIUtils.CurrentShaderVersion() > 17007 )
  3059. return;
  3060. int count = 0;
  3061. if( UIUtils.CurrentShaderVersion() > 7003 )
  3062. {
  3063. try
  3064. {
  3065. count = Convert.ToInt32( nodeParams[ m_currentReadParamIdx++ ] );
  3066. }
  3067. catch( Exception e )
  3068. {
  3069. Debug.LogException( e );
  3070. }
  3071. }
  3072. else
  3073. {
  3074. count = ( m_oldInputCount < 0 ) ? m_inputPorts.Count : m_oldInputCount;
  3075. }
  3076. for( int i = 0 ; i < count && i < nodeParams.Length && m_currentReadParamIdx < nodeParams.Length ; i++ )
  3077. {
  3078. if( UIUtils.CurrentShaderVersion() < 5003 )
  3079. {
  3080. int newId = VersionConvertInputPortId( i );
  3081. if( UIUtils.CurrentShaderVersion() > 23 )
  3082. {
  3083. m_currentReadParamIdx++;
  3084. }
  3085. m_currentReadParamIdx++;
  3086. if( m_inputPorts[ newId ].IsEditable && UIUtils.CurrentShaderVersion() >= 3100 && m_currentReadParamIdx < nodeParams.Length )
  3087. {
  3088. m_currentReadParamIdx++;
  3089. }
  3090. }
  3091. else
  3092. {
  3093. m_currentReadParamIdx++;
  3094. m_currentReadParamIdx++;
  3095. m_currentReadParamIdx++;
  3096. bool isEditable = Convert.ToBoolean( nodeParams[ m_currentReadParamIdx++ ] );
  3097. if( isEditable && m_currentReadParamIdx < nodeParams.Length )
  3098. {
  3099. m_currentReadParamIdx++;
  3100. }
  3101. }
  3102. }
  3103. }
  3104. public override void ReadOutputDataFromString( ref string[] nodeParams )
  3105. {
  3106. if ( m_invalidNode )
  3107. return;
  3108. base.ReadOutputDataFromString( ref nodeParams );
  3109. }
  3110. //For a Template Master Node an input port data must be set by its template and not meta data
  3111. public override void WriteInputDataToString( ref string nodeInfo ) { }
  3112. public override float HeightEstimate
  3113. {
  3114. get
  3115. {
  3116. float heightEstimate = 0;
  3117. heightEstimate = 32 + Constants.INPUT_PORT_DELTA_Y;
  3118. if( m_templateMultiPass != null && !m_templateMultiPass.IsSinglePass )
  3119. {
  3120. heightEstimate += 22;
  3121. }
  3122. float internalPortSize = 0;
  3123. for( int i = 0 ; i < InputPorts.Count ; i++ )
  3124. {
  3125. if( InputPorts[ i ].Visible )
  3126. internalPortSize += 18 + Constants.INPUT_PORT_DELTA_Y;
  3127. }
  3128. return heightEstimate + Mathf.Max( internalPortSize , m_insideSize.y );
  3129. }
  3130. }
  3131. public HDSRPMaterialType CurrentHDMaterialType
  3132. {
  3133. get { return m_hdSrpMaterialType; }
  3134. set
  3135. {
  3136. m_hdSrpMaterialType = value;
  3137. if( m_isMainOutputNode )
  3138. {
  3139. List<TemplateMultiPassMasterNode> mpNodes = ContainerGraph.MultiPassMasterNodes.NodesList;
  3140. int count = mpNodes.Count;
  3141. for( int i = 0 ; i < count ; i++ )
  3142. {
  3143. if( mpNodes[ i ].UniqueId != UniqueId )
  3144. {
  3145. mpNodes[ i ].CurrentHDMaterialType = value;
  3146. }
  3147. }
  3148. }
  3149. }
  3150. }
  3151. public TemplateSubShader SubShader { get { return m_templateMultiPass.SubShaders[ m_subShaderIdx ]; } }
  3152. public TemplatePass Pass { get { return m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ]; } }
  3153. public int SubShaderIdx { get { return m_subShaderIdx; } }
  3154. public int PassIdx { get { return m_passIdx; } }
  3155. public TemplateMultiPass CurrentTemplate { get { return m_templateMultiPass; } }
  3156. public TemplateModulesHelper SubShaderModule { get { return m_subShaderModule; } }
  3157. public TemplateModulesHelper PassModule { get { return m_passModule; } }
  3158. public string PassName { get { return m_templateMultiPass.SubShaders[ m_subShaderIdx ].Passes[ m_passIdx ].PassNameContainer.Data; } }
  3159. public string PassUniqueName
  3160. {
  3161. get
  3162. {
  3163. return string.IsNullOrEmpty( m_passUniqueId ) ? m_originalPassName : m_passUniqueId;
  3164. }
  3165. }
  3166. public string OriginalPassName { get { return m_originalPassName; } }
  3167. public bool HasLinkPorts { get { return m_hasLinkPorts; } }
  3168. public bool IsInvisible
  3169. {
  3170. get
  3171. {
  3172. return m_isInvisible != InvisibilityStatus.Visible;
  3173. }
  3174. set
  3175. {
  3176. if( m_isInvisible != InvisibilityStatus.LockedInvisible && !m_isMainOutputNode )
  3177. {
  3178. m_isInvisible = value ? InvisibilityStatus.Invisible : InvisibilityStatus.Visible;
  3179. if( value )
  3180. {
  3181. for( int i = 0 ; i < m_inputPorts.Count ; i++ )
  3182. {
  3183. m_inputPorts[ i ].FullDeleteConnections();
  3184. }
  3185. }
  3186. }
  3187. }
  3188. }
  3189. public TemplatePassSelectorHelper PassSelector { get { return m_passSelector; } }
  3190. public TemplateOptionsUIHelper PassOptions { get { return m_passOptions; } }
  3191. public TemplateOptionsUIHelper SubShaderOptions { get { return m_subShaderOptions; } }
  3192. public TemplateOptionsDefinesContainer OptionsDefineContainer { get { return m_optionsDefineContainer; } }
  3193. public TerrainDrawInstancedHelper DrawInstancedHelperInstance { get { return m_drawInstancedHelper; } }
  3194. public bool InvalidNode { get { return m_invalidNode; } }
  3195. public override void SetName( string name )
  3196. {
  3197. ShaderName = name;
  3198. }
  3199. public bool IsLODMainFirstPass { get { return m_passIdx == 0 && m_lodIndex == -1; } }
  3200. public override AvailableShaderTypes CurrentMasterNodeCategory { get { return AvailableShaderTypes.Template; } }
  3201. }
  3202. }