MasterNodeDataCollector.cs 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEditor;
  7. using System.Text.RegularExpressions;
  8. namespace AmplifyShaderEditor
  9. {
  10. public class PropertyDataCollector
  11. {
  12. public int NodeId;
  13. public int OrderIndex;
  14. public string PropertyName;
  15. public WirePortDataType DataType;
  16. public bool IsDirective;
  17. public PropertyDataCollector( int nodeId, string propertyName, int orderIndex = -1, bool isDirective = false )
  18. {
  19. NodeId = nodeId;
  20. PropertyName = propertyName;
  21. OrderIndex = orderIndex;
  22. IsDirective = isDirective;
  23. }
  24. }
  25. public class InputCoordsCollector
  26. {
  27. public int NodeId;
  28. public string CoordName;
  29. public WirePortDataType DataType;
  30. public PrecisionType Precision;
  31. public int TextureSlot;
  32. public int TextureIndex;
  33. public InputCoordsCollector( int nodeId, string coordName, WirePortDataType dataType, PrecisionType precision, int textureSlot, int textureIndex )
  34. {
  35. NodeId = nodeId;
  36. CoordName = coordName;
  37. DataType = dataType;
  38. Precision = precision;
  39. TextureSlot = textureSlot;
  40. TextureIndex = textureIndex;
  41. }
  42. }
  43. public class TextureDefaultsDataColector
  44. {
  45. private List<string> m_names = new List<string>();
  46. private List<Texture> m_values = new List<Texture>();
  47. public void AddValue( string newName, Texture newValue )
  48. {
  49. m_names.Add( newName );
  50. m_values.Add( newValue );
  51. }
  52. public void Destroy()
  53. {
  54. m_names.Clear();
  55. m_names = null;
  56. m_values.Clear();
  57. m_values = null;
  58. }
  59. public string[] NamesArr { get { return m_names.ToArray(); } }
  60. public Texture[] ValuesArr { get { return m_values.ToArray(); } }
  61. }
  62. public enum TextureChannelUsage
  63. {
  64. Not_Used,
  65. Used,
  66. Required
  67. }
  68. [Flags]
  69. public enum MacrosMask
  70. {
  71. NONE = 0,
  72. AUTO = 1 << 1,
  73. LOD = 1 << 2,
  74. BIAS = 1 << 3,
  75. GRAD = 1 << 4,
  76. }
  77. public class MasterNodeDataCollector
  78. {
  79. private bool m_showDebugMessages = false;
  80. private string m_input;
  81. private string m_customInput;
  82. private string m_properties;
  83. private string m_instancedProperties;
  84. private string m_instanceBlockName;
  85. private string m_uniforms;
  86. private string m_includes;
  87. private string m_pragmas;
  88. private string m_defines;
  89. private string m_instructions;
  90. private string m_localVariables;
  91. private string m_vertexLocalVariables;
  92. private string m_specialLocalVariables;
  93. private string m_vertexData;
  94. private string m_customOutput;
  95. private string m_functions;
  96. private string m_grabPass;
  97. private List<PropertyDataCollector> m_inputList;
  98. private List<PropertyDataCollector> m_customInputList;
  99. private List<PropertyDataCollector> m_propertiesList;
  100. private List<PropertyDataCollector> m_instancedPropertiesList;
  101. private List<PropertyDataCollector> m_dotsPropertiesList;
  102. private List<PropertyDataCollector> m_dotsDefinesList;
  103. private List<PropertyDataCollector> m_uniformsList;
  104. private List<PropertyDataCollector> m_includesList;
  105. private List<PropertyDataCollector> m_additionalDirectivesList;
  106. //private List<PropertyDataCollector> m_tagsList;
  107. private List<PropertyDataCollector> m_pragmasList;
  108. private List<PropertyDataCollector> m_definesList;
  109. private List<PropertyDataCollector> m_instructionsList;
  110. private List<PropertyDataCollector> m_localVariablesList;
  111. private List<PropertyDataCollector> m_vertexLocalVariablesList;
  112. private List<PropertyDataCollector> m_specialLocalVariablesList;
  113. private List<PropertyDataCollector> m_vertexDataList;
  114. private List<PropertyDataCollector> m_customOutputList;
  115. private List<PropertyDataCollector> m_functionsList;
  116. private List<PropertyDataCollector> m_grabPassList;
  117. private List<PropertyDataCollector> m_aboveUsePassesList;
  118. private List<PropertyDataCollector> m_belowUsePassesList;
  119. private bool m_surfaceCustomShadowCaster = false;
  120. private List<InputCoordsCollector> m_customShadowCoordsList;
  121. private List<int> m_packSlotsList;
  122. private string m_customAppDataItems;
  123. private Dictionary<string, PropertyDataCollector> m_inputDict;
  124. private Dictionary<string, PropertyDataCollector> m_customInputDict;
  125. private Dictionary<string, PropertyDataCollector> m_propertiesDict;
  126. private Dictionary<string, PropertyDataCollector> m_instancedPropertiesDict;
  127. private Dictionary<string, PropertyDataCollector> m_dotsPropertiesDict;
  128. private Dictionary<string, PropertyDataCollector> m_uniformsDict;
  129. private Dictionary<string, PropertyDataCollector> m_softRegisteredUniformsDict;
  130. private Dictionary<string, PropertyDataCollector> m_includesDict;
  131. private Dictionary<string, PropertyDataCollector> m_additionalDirectivesDict;
  132. private Dictionary<string, string> m_includesExclusionDict;
  133. //private Dictionary<string, PropertyDataCollector> m_tagsDict;
  134. private Dictionary<string, PropertyDataCollector> m_pragmasDict;
  135. private Dictionary<string, PropertyDataCollector> m_definesDict;
  136. private Dictionary<string, int> m_virtualCoordinatesDict;
  137. private Dictionary<string, string> m_virtualVariablesDict;
  138. private Dictionary<string, PropertyDataCollector> m_localVariablesDict;
  139. private Dictionary<string, PropertyDataCollector> m_localVariablesByNameDict;
  140. private Dictionary<string, PropertyDataCollector> m_vertexLocalVariablesDict;
  141. private Dictionary<string, PropertyDataCollector> m_vertexLocalVariablesByNameDict;
  142. private Dictionary<string, PropertyDataCollector> m_specialLocalVariablesDict;
  143. private Dictionary<string, PropertyDataCollector> m_specialLocalVariablesByNameDict;
  144. private Dictionary<string, PropertyDataCollector> m_vertexDataDict;
  145. private Dictionary<string, PropertyDataCollector> m_customOutputDict;
  146. private Dictionary<string, PropertyDataCollector> m_customOutputByNameDict;
  147. private Dictionary<string, string> m_localFunctions;
  148. private Dictionary<string, string> m_grabPassDict;
  149. private Dictionary<string, string> m_usePassesDict;
  150. private Dictionary<string, string> m_customAppDataItemsDict;
  151. private Dictionary<string, InputCoordsCollector> m_customShadowCoordsDict;
  152. private TextureChannelUsage[] m_requireTextureProperty = { TextureChannelUsage.Not_Used, TextureChannelUsage.Not_Used, TextureChannelUsage.Not_Used, TextureChannelUsage.Not_Used };
  153. private WirePortDataType[] m_textureChannelSize =
  154. {
  155. WirePortDataType.FLOAT2,
  156. WirePortDataType.FLOAT2,
  157. WirePortDataType.FLOAT2,
  158. WirePortDataType.FLOAT2,
  159. WirePortDataType.FLOAT2,
  160. WirePortDataType.FLOAT2,
  161. WirePortDataType.FLOAT2,
  162. WirePortDataType.FLOAT2
  163. };
  164. private bool m_dirtyAppData;
  165. private bool m_dirtyInputs;
  166. private bool m_dirtyCustomInputs;
  167. private bool m_dirtyFunctions;
  168. private bool m_dirtyProperties;
  169. private bool m_dirtyInstancedProperties;
  170. private bool m_dirtyUniforms;
  171. private bool m_dirtyIncludes;
  172. private bool m_dirtyPragmas;
  173. private bool m_dirtyDefines;
  174. private bool m_dirtyAdditionalDirectives;
  175. private bool m_dirtyInstructions;
  176. private bool m_dirtyLocalVariables;
  177. private bool m_dirtyVertexLocalVariables;
  178. private bool m_dirtySpecialLocalVariables;
  179. private bool m_dirtyPerVertexData;
  180. private bool m_dirtyNormal;
  181. private bool m_forceNormal;
  182. private bool m_usingInternalData;
  183. private bool m_usingVertexColor;
  184. private bool m_usingWorldPosition;
  185. private bool m_usingWorldNormal;
  186. private bool m_usingScreenPos;
  187. private bool m_usingWorldReflection;
  188. private bool m_usingViewDirection;
  189. private bool m_usingLightAttenuation;
  190. private bool m_usingArrayDerivatives;
  191. private bool m_usingTextureArrays;
  192. private bool m_usingExtraStandardMacros;
  193. private MacrosMask m_using2DMacrosMask;
  194. private MacrosMask m_using3DMacrosMask;
  195. private MacrosMask m_usingCUBEMacrosMask;
  196. private MacrosMask m_using2DArrayMacrosMask;
  197. private bool m_usingExtra3DSRPMacros;
  198. private bool m_usingHigherSizeTexcoords;
  199. private bool m_usingCustomScreenPos;
  200. private bool m_usingCustomOutlineColor;
  201. private bool m_usingCustomOutlineWidth;
  202. private bool m_usingCustomOutlineAlpha;
  203. private int m_customOutlineSelectedAlpha = 0;
  204. private bool m_usingCustomOutput;
  205. private bool m_safeNormalizeLightDir;
  206. private bool m_safeNormalizeViewDir;
  207. private bool m_isOutlineDataCollector = false;
  208. private bool m_forceNormalIsDirty;
  209. private bool m_grabPassIsDirty;
  210. private bool m_tesselationActive;
  211. private Dictionary<int, PropertyNode> m_propertyNodes;
  212. private MasterNode m_masterNode;
  213. private int m_availableVertexTempId = 0;
  214. private int m_availableFragTempId = 0;
  215. private MasterNodePortCategory m_portCategory;
  216. private PortGenType m_genType;
  217. private RenderPath m_renderPath = RenderPath.All;
  218. private NodeAvailability m_currentCanvasMode = NodeAvailability.SurfaceShader;
  219. //Templates specific data
  220. private AvailableShaderTypes m_masterNodeCategory;
  221. private List<string> m_vertexInputList;
  222. private Dictionary<string, string> m_vertexInputDict;
  223. private List<string> m_interpolatorsList;
  224. private Dictionary<string, string> m_interpolatorsDict;
  225. private List<string> m_vertexInterpDeclList;
  226. private Dictionary<string, string> m_vertexInterpDeclDict;
  227. private TemplateDataCollector m_templateDataCollector;
  228. public MasterNodeDataCollector( MasterNode masterNode ) : this()
  229. {
  230. m_masterNode = masterNode;
  231. m_masterNodeCategory = masterNode.CurrentMasterNodeCategory;
  232. m_currentCanvasMode = masterNode.ContainerGraph.CurrentCanvasMode;
  233. }
  234. public MasterNodeDataCollector()
  235. {
  236. //m_masterNode = masterNode;
  237. m_input = "struct Input\n\t\t{\n";
  238. m_customInput = "\t\tstruct SurfaceOutput{0}\n\t\t{\n";
  239. m_properties = IOUtils.PropertiesBegin;//"\tProperties\n\t{\n";
  240. m_uniforms = string.Empty;
  241. m_instructions = string.Empty;
  242. m_includes = string.Empty;
  243. m_pragmas = string.Empty;
  244. m_defines = string.Empty;
  245. m_localVariables = string.Empty;
  246. m_specialLocalVariables = string.Empty;
  247. m_customOutput = string.Empty;
  248. m_inputList = new List<PropertyDataCollector>();
  249. m_customInputList = new List<PropertyDataCollector>();
  250. m_propertiesList = new List<PropertyDataCollector>();
  251. m_instancedPropertiesList = new List<PropertyDataCollector>();
  252. m_dotsPropertiesList = new List<PropertyDataCollector>();
  253. m_dotsDefinesList = new List<PropertyDataCollector>();
  254. m_uniformsList = new List<PropertyDataCollector>();
  255. m_includesList = new List<PropertyDataCollector>();
  256. m_additionalDirectivesList = new List<PropertyDataCollector>();
  257. //m_tagsList = new List<PropertyDataCollector>();
  258. m_pragmasList = new List<PropertyDataCollector>();
  259. m_definesList = new List<PropertyDataCollector>();
  260. m_instructionsList = new List<PropertyDataCollector>();
  261. m_localVariablesList = new List<PropertyDataCollector>();
  262. m_vertexLocalVariablesList = new List<PropertyDataCollector>();
  263. m_specialLocalVariablesList = new List<PropertyDataCollector>();
  264. m_vertexDataList = new List<PropertyDataCollector>();
  265. m_customOutputList = new List<PropertyDataCollector>();
  266. m_functionsList = new List<PropertyDataCollector>();
  267. m_grabPassList = new List<PropertyDataCollector>();
  268. m_aboveUsePassesList = new List<PropertyDataCollector>();
  269. m_belowUsePassesList = new List<PropertyDataCollector>();
  270. m_customAppDataItems = string.Empty;
  271. m_customAppDataItemsDict = new Dictionary<string, string>();
  272. m_customShadowCoordsList = new List<InputCoordsCollector>();
  273. m_packSlotsList = new List<int>();
  274. m_inputDict = new Dictionary<string, PropertyDataCollector>();
  275. m_customInputDict = new Dictionary<string, PropertyDataCollector>();
  276. m_propertiesDict = new Dictionary<string, PropertyDataCollector>();
  277. m_instancedPropertiesDict = new Dictionary<string, PropertyDataCollector>();
  278. m_dotsPropertiesDict = new Dictionary<string, PropertyDataCollector>();
  279. m_uniformsDict = new Dictionary<string, PropertyDataCollector>();
  280. m_softRegisteredUniformsDict = new Dictionary<string, PropertyDataCollector>();
  281. m_includesDict = new Dictionary<string, PropertyDataCollector>();
  282. m_additionalDirectivesDict = new Dictionary<string, PropertyDataCollector>();
  283. m_includesExclusionDict = new Dictionary<string, string>();
  284. //m_tagsDict = new Dictionary<string, PropertyDataCollector>();
  285. m_pragmasDict = new Dictionary<string, PropertyDataCollector>();
  286. m_definesDict = new Dictionary<string, PropertyDataCollector>();
  287. m_virtualCoordinatesDict = new Dictionary<string, int>();
  288. m_localVariablesDict = new Dictionary<string, PropertyDataCollector>();
  289. m_localVariablesByNameDict = new Dictionary<string, PropertyDataCollector>();
  290. m_virtualVariablesDict = new Dictionary<string, string>();
  291. m_specialLocalVariablesDict = new Dictionary<string, PropertyDataCollector>();
  292. m_specialLocalVariablesByNameDict = new Dictionary<string, PropertyDataCollector>();
  293. m_vertexLocalVariablesDict = new Dictionary<string, PropertyDataCollector>();
  294. m_vertexLocalVariablesByNameDict = new Dictionary<string, PropertyDataCollector>();
  295. m_localFunctions = new Dictionary<string, string>();
  296. m_vertexDataDict = new Dictionary<string, PropertyDataCollector>();
  297. m_customOutputDict = new Dictionary<string, PropertyDataCollector>();
  298. m_customOutputByNameDict = new Dictionary<string, PropertyDataCollector>();
  299. m_grabPassDict = new Dictionary<string, string>();
  300. m_usePassesDict = new Dictionary<string, string>();
  301. m_customShadowCoordsDict = new Dictionary<string, InputCoordsCollector>();
  302. m_dirtyAppData = false;
  303. m_dirtyInputs = false;
  304. m_dirtyCustomInputs = false;
  305. m_dirtyProperties = false;
  306. m_dirtyInstancedProperties = false;
  307. m_dirtyUniforms = false;
  308. m_dirtyInstructions = false;
  309. m_dirtyIncludes = false;
  310. m_dirtyPragmas = false;
  311. m_dirtyDefines = false;
  312. m_dirtyAdditionalDirectives = false;
  313. m_dirtyLocalVariables = false;
  314. m_dirtySpecialLocalVariables = false;
  315. m_grabPassIsDirty = false;
  316. m_portCategory = MasterNodePortCategory.Fragment;
  317. m_propertyNodes = new Dictionary<int, PropertyNode>();
  318. m_showDebugMessages = ( m_showDebugMessages && DebugConsoleWindow.DeveloperMode );
  319. //templates
  320. //m_masterNodeCategory = masterNode.CurrentMasterNodeCategory;
  321. m_vertexInputList = new List<string>();
  322. m_vertexInputDict = new Dictionary<string, string>();
  323. m_interpolatorsList = new List<string>();
  324. m_interpolatorsDict = new Dictionary<string, string>();
  325. m_vertexInterpDeclList = new List<string>();
  326. m_vertexInterpDeclDict = new Dictionary<string, string>();
  327. m_templateDataCollector = new TemplateDataCollector();
  328. }
  329. public void CopyTextureChannelSizeFrom( ref MasterNodeDataCollector dataCollector )
  330. {
  331. for( int i = 0 ; i < m_textureChannelSize.Length ; i++ )
  332. {
  333. SetTextureChannelSize( i , dataCollector.GetMaxTextureChannelSize( i ) );
  334. }
  335. }
  336. public void SetTextureChannelSize( int channelIdx , WirePortDataType size )
  337. {
  338. if( size > m_textureChannelSize[ channelIdx ] )
  339. {
  340. m_textureChannelSize[ channelIdx ] = size;
  341. }
  342. }
  343. public WirePortDataType GetMaxTextureChannelSize( int channelIdx )
  344. {
  345. return m_textureChannelSize[ channelIdx ];
  346. }
  347. public void SetChannelUsage( int channelId, TextureChannelUsage usage )
  348. {
  349. if( channelId > -1 && channelId < 4 )
  350. m_requireTextureProperty[ channelId ] = usage;
  351. }
  352. public TextureChannelUsage GetChannelUsage( int channelId )
  353. {
  354. if( channelId > -1 && channelId < 4 )
  355. return m_requireTextureProperty[ channelId ];
  356. return TextureChannelUsage.Not_Used;
  357. }
  358. public void OpenPerVertexHeader( bool includeCustomData )
  359. {
  360. string appData = "inout " + ( m_dirtyAppData ? Constants.CustomAppDataFullName : Constants.AppDataFullName ) + " ";
  361. if( m_dirtyPerVertexData )
  362. return;
  363. m_dirtyPerVertexData = true;
  364. if( m_tesselationActive )
  365. {
  366. m_vertexData = "\t\tvoid " + Constants.VertexDataFunc + "( " + appData + Constants.VertexShaderInputStr + " )\n\t\t{\n";
  367. }
  368. else
  369. {
  370. m_vertexData = "\t\tvoid " + Constants.VertexDataFunc + "( " + appData + Constants.VertexShaderInputStr + ( includeCustomData ? ( string.Format( ", out Input {0}", Constants.VertexShaderOutputStr ) ) : string.Empty ) + " )\n\t\t{\n";
  371. if( includeCustomData )
  372. m_vertexData += string.Format( "\t\t\tUNITY_INITIALIZE_OUTPUT( Input, {0} );\n", Constants.VertexShaderOutputStr );
  373. }
  374. }
  375. public void ClosePerVertexHeader()
  376. {
  377. if( m_dirtyPerVertexData )
  378. m_vertexData += "\t\t}\n\n";
  379. }
  380. public void AddToVertexDisplacement( string value, VertexMode vertexMode )
  381. {
  382. if( string.IsNullOrEmpty( value ) )
  383. return;
  384. if( !m_dirtyPerVertexData )
  385. {
  386. OpenPerVertexHeader( true );
  387. }
  388. switch( vertexMode )
  389. {
  390. default:
  391. case VertexMode.Relative:
  392. {
  393. m_vertexData += "\t\t\t" + Constants.VertexShaderInputStr + ".vertex.xyz += " + value + ";\n";
  394. }
  395. break;
  396. case VertexMode.Absolute:
  397. {
  398. m_vertexData += "\t\t\t" + Constants.VertexShaderInputStr + ".vertex.xyz = " + value + ";\n";
  399. }
  400. break;
  401. }
  402. m_vertexData += "\t\t\t" + Constants.VertexShaderInputStr + ".vertex.w = 1;\n";
  403. }
  404. public void AddToVertexNormal( string value )
  405. {
  406. if( string.IsNullOrEmpty( value ) )
  407. return;
  408. if( !m_dirtyPerVertexData )
  409. {
  410. OpenPerVertexHeader( true );
  411. }
  412. m_vertexData += "\t\t\t" + Constants.VertexShaderInputStr + ".normal = " + value + ";\n";
  413. }
  414. public void AddToVertexTangent( string value )
  415. {
  416. if ( string.IsNullOrEmpty( value ) )
  417. return;
  418. if ( !m_dirtyPerVertexData )
  419. {
  420. OpenPerVertexHeader( true );
  421. }
  422. m_vertexData += "\t\t\t" + Constants.VertexShaderInputStr + ".tangent = " + value + ";\n";
  423. }
  424. public void AddVertexInstruction( string value, int nodeId = -1, bool addDelimiters = true )
  425. {
  426. if( !m_dirtyPerVertexData && !IsOutlineDataCollector/*&& !(m_usingCustomOutlineColor || m_usingCustomOutlineWidth)*/ )
  427. {
  428. OpenPerVertexHeader( true );
  429. }
  430. if( !m_vertexDataDict.ContainsKey( value ) )
  431. {
  432. m_vertexDataDict.Add( value, new PropertyDataCollector( nodeId, value ) );
  433. m_vertexDataList.Add( m_vertexDataDict[ value ] );
  434. m_vertexData += ( addDelimiters ? ( "\t\t\t" + value + ";\n" ) : value );
  435. }
  436. }
  437. public bool ContainsInput( string value )
  438. {
  439. return m_inputDict.ContainsKey( value );
  440. }
  441. public void AddToInput( int nodeId, string interpName, WirePortDataType dataType, PrecisionType precision = PrecisionType.Float, bool addSemiColon = true )
  442. {
  443. string value = UIUtils.PrecisionWirePortToCgType( precision, dataType ) + " " + interpName;
  444. AddToInput( nodeId, value, addSemiColon );
  445. if( !m_customShadowCoordsDict.ContainsKey( interpName ) )
  446. {
  447. int slot = 0;
  448. int index = 0;
  449. int size = UIUtils.GetChannelsAmount( dataType );
  450. if( m_packSlotsList.Count == 0 )
  451. m_packSlotsList.Add( 4 );
  452. for( int i = 0; i < m_packSlotsList.Count; i++ )
  453. {
  454. slot = i;
  455. if( m_packSlotsList[ i ] >= size )
  456. {
  457. index = 4 - m_packSlotsList[ i ];
  458. m_packSlotsList[ i ] -= size;
  459. break;
  460. }
  461. else if( i == m_packSlotsList.Count - 1 )
  462. {
  463. m_packSlotsList.Add( 4 );
  464. }
  465. }
  466. m_customShadowCoordsDict.Add( interpName, new InputCoordsCollector( nodeId, interpName, dataType, precision, slot, index ) );
  467. m_customShadowCoordsList.Add( m_customShadowCoordsDict[ interpName ] );
  468. }
  469. }
  470. public void AddToInput( int nodeId, SurfaceInputs surfaceInput, PrecisionType precision = PrecisionType.Float, bool addSemiColon = true )
  471. {
  472. switch( surfaceInput )
  473. {
  474. case SurfaceInputs.VIEW_DIR:
  475. UsingViewDirection = true;
  476. break;
  477. case SurfaceInputs.SCREEN_POS:
  478. UsingScreenPos = true;
  479. break;
  480. case SurfaceInputs.WORLD_POS:
  481. UsingWorldPosition = true;
  482. break;
  483. case SurfaceInputs.WORLD_REFL:
  484. UsingWorldReflection = true;
  485. break;
  486. case SurfaceInputs.WORLD_NORMAL:
  487. UsingWorldNormal = true;
  488. break;
  489. case SurfaceInputs.INTERNALDATA:
  490. UsingInternalData = true;
  491. break;
  492. case SurfaceInputs.COLOR:
  493. UsingVertexColor = true;
  494. break;
  495. }
  496. AddToInput( nodeId, UIUtils.GetInputDeclarationFromType( precision, surfaceInput ), addSemiColon );
  497. }
  498. /// <summary>
  499. /// Direct access to inputs, plese use another overload
  500. /// </summary>
  501. /// <param name="nodeId"></param>
  502. /// <param name="value"></param>
  503. /// <param name="addSemiColon"></param>
  504. public void AddToInput( int nodeId, string value, bool addSemiColon )
  505. {
  506. if( string.IsNullOrEmpty( value ) )
  507. return;
  508. if( !m_inputDict.ContainsKey( value ) )
  509. {
  510. m_inputDict.Add( value, new PropertyDataCollector( nodeId, value ,-1, !addSemiColon) );
  511. m_inputList.Add( m_inputDict[ value ] );
  512. m_input += "\t\t\t" + value + ( ( addSemiColon ) ? ( ";\n" ) : "\n" );
  513. m_dirtyInputs = true;
  514. }
  515. }
  516. public void CloseInputs()
  517. {
  518. m_input += "\t\t};";
  519. }
  520. public void ChangeCustomInputHeader( string value )
  521. {
  522. m_customInput = m_customInput.Replace( "{0}", value );
  523. }
  524. public void AddToCustomInput( int nodeId, string value, bool addSemiColon )
  525. {
  526. if( string.IsNullOrEmpty( value ) )
  527. return;
  528. if( !m_customInputDict.ContainsKey( value ) )
  529. {
  530. m_customInputDict.Add( value, new PropertyDataCollector( nodeId, value ) );
  531. m_customInputList.Add( m_customInputDict[ value ] );
  532. m_customInput += "\t\t\t" + value + ( ( addSemiColon ) ? ( ";\n" ) : "\n" );
  533. m_dirtyCustomInputs = true;
  534. }
  535. }
  536. public void CloseCustomInputs()
  537. {
  538. m_customInput += "\t\t};";
  539. }
  540. // Used by Template Master Node to add tabs into variable declaration
  541. public void TabifyInstancedVars()
  542. {
  543. for( int i = 0; i < m_instancedPropertiesList.Count; i++ )
  544. {
  545. m_instancedPropertiesList[ i ].PropertyName = '\t' + m_instancedPropertiesList[ i ].PropertyName;
  546. }
  547. }
  548. private int GetWeightForInstancedType( WirePortDataType type )
  549. {
  550. switch( type )
  551. {
  552. case WirePortDataType.INT:
  553. case WirePortDataType.FLOAT: return -1;
  554. case WirePortDataType.FLOAT2: return -2;
  555. case WirePortDataType.FLOAT3: return -3;
  556. case WirePortDataType.COLOR:
  557. case WirePortDataType.FLOAT4: return -4;
  558. case WirePortDataType.FLOAT3x3: return -9;
  559. case WirePortDataType.FLOAT4x4: return -16;
  560. default:
  561. case WirePortDataType.OBJECT:
  562. case WirePortDataType.SAMPLER1D:
  563. case WirePortDataType.SAMPLER2D:
  564. case WirePortDataType.SAMPLER3D:
  565. case WirePortDataType.SAMPLERCUBE:
  566. case WirePortDataType.SAMPLER2DARRAY:
  567. case WirePortDataType.SAMPLERSTATE:
  568. return 0;
  569. }
  570. }
  571. public void OptimizeInstancedProperties()
  572. {
  573. if( m_instancedPropertiesList.Count > 0 )
  574. {
  575. m_instancedProperties = string.Empty;
  576. m_instancedPropertiesList.Sort( ( x, y ) => { return GetWeightForInstancedType( x.DataType ).CompareTo( GetWeightForInstancedType( y.DataType ) ); } );
  577. int count = m_instancedPropertiesList.Count;
  578. for( int i = 0; i < count; i++ )
  579. {
  580. m_instancedProperties += m_instancedPropertiesList[ i ].PropertyName;
  581. }
  582. }
  583. }
  584. // Instanced properties
  585. public void SetupInstancePropertiesBlock( string blockName )
  586. {
  587. m_instanceBlockName = blockName;
  588. if( IsTemplate )
  589. {
  590. //if( DebugConsoleWindow.DeveloperMode )
  591. // Debug.LogWarning( "SetupInstancePropertiesBlock should not be used during template mode" );
  592. return;
  593. }
  594. OptimizeInstancedProperties();
  595. if( m_dirtyInstancedProperties )
  596. {
  597. m_instancedProperties = string.Format( IOUtils.InstancedPropertiesBeginTabs, blockName ) + m_instancedProperties + IOUtils.InstancedPropertiesEndTabs;
  598. }
  599. }
  600. public void AddToDotsProperties( WirePortDataType dataType, int nodeId, string value, int orderIndex, PrecisionType precision )
  601. {
  602. if( string.IsNullOrEmpty( value ) )
  603. return;
  604. string prop = string.Format( IOUtils.DotsInstancedPropertiesData, UIUtils.PrecisionWirePortToCgType( precision, dataType ), value );
  605. string define = string.Format( IOUtils.DotsInstancedDefinesData, UIUtils.PrecisionWirePortToCgType( precision, dataType ), value );
  606. if( !m_dotsPropertiesDict.ContainsKey( value ) )
  607. {
  608. PropertyDataCollector dataColl = new PropertyDataCollector( nodeId, prop, orderIndex );
  609. dataColl.DataType = dataType;
  610. m_dotsPropertiesDict.Add( value, dataColl );
  611. m_dotsPropertiesList.Add( dataColl );
  612. dataColl = new PropertyDataCollector( nodeId, define, orderIndex );
  613. m_dotsDefinesList.Add( dataColl );
  614. }
  615. }
  616. public void AddToInstancedProperties( WirePortDataType dataType, int nodeId, string value, int orderIndex )
  617. {
  618. if( string.IsNullOrEmpty( value ) )
  619. return;
  620. string uniformValue = value.Contains( "uniform" ) ? value : "uniform " + value;
  621. if( !m_instancedPropertiesDict.ContainsKey( value ) &&
  622. !m_uniformsDict.ContainsKey( value ) &&
  623. !m_uniformsDict.ContainsKey( uniformValue )
  624. )
  625. {
  626. PropertyDataCollector dataColl = new PropertyDataCollector( nodeId, value, orderIndex );
  627. dataColl.DataType = dataType;
  628. m_instancedPropertiesDict.Add( value, dataColl );
  629. m_instancedPropertiesList.Add( dataColl );
  630. m_instancedProperties += value;
  631. m_dirtyInstancedProperties = true;
  632. }
  633. }
  634. public void CloseInstancedProperties()
  635. {
  636. if( m_dirtyInstancedProperties )
  637. {
  638. m_instancedProperties += IOUtils.InstancedPropertiesEnd;
  639. }
  640. }
  641. // Properties
  642. public void CopyPropertiesFromDataCollector( MasterNodeDataCollector dataCollector )
  643. {
  644. if( dataCollector == null )
  645. return;
  646. int propertyCount = dataCollector.PropertiesList.Count;
  647. for( int i = 0; i < propertyCount; i++ )
  648. {
  649. AddToProperties( dataCollector.PropertiesList[ i ].NodeId,
  650. dataCollector.PropertiesList[ i ].PropertyName,
  651. dataCollector.PropertiesList[ i ].OrderIndex );
  652. }
  653. foreach( KeyValuePair<string, string> kvp in dataCollector.GrabPassDict )
  654. {
  655. AddGrabPass( kvp.Value );
  656. }
  657. m_templateDataCollector.CopySRPPropertiesFromDataCollector( -1, dataCollector.TemplateDataCollectorInstance );
  658. }
  659. public void AddToProperties( int nodeId, string value, int orderIndex )
  660. {
  661. if( string.IsNullOrEmpty( value ) )
  662. return;
  663. if( !m_propertiesDict.ContainsKey( value ) )
  664. {
  665. //Debug.Log( UIUtils );
  666. m_propertiesDict.Add( value, new PropertyDataCollector( nodeId, value, orderIndex ) );
  667. m_propertiesList.Add( m_propertiesDict[ value ] );
  668. m_properties += string.Format( IOUtils.PropertiesElement, value );
  669. m_dirtyProperties = true;
  670. }
  671. }
  672. public string BuildPropertiesString()
  673. {
  674. List<PropertyDataCollector> list = new List<PropertyDataCollector>( m_propertiesDict.Values );
  675. //for ( int i = 0; i < list.Count; i++ )
  676. //{
  677. // Debug.Log( list[ i ].OrderIndex + " " + list[ i ].PropertyName );
  678. //}
  679. list.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ); } );
  680. CleanUpList( ref list );
  681. m_properties = IOUtils.PropertiesBegin;
  682. for( int i = 0; i < list.Count; i++ )
  683. {
  684. m_properties += string.Format( IOUtils.PropertiesElement, list[ i ].PropertyName );
  685. //Debug.Log()
  686. }
  687. m_properties += IOUtils.PropertiesEnd;
  688. return m_properties;
  689. }
  690. public bool ContainsProperty( string propertyName )
  691. {
  692. // TODO: this needs to change, find the property should be dependant of have a "("
  693. List<PropertyDataCollector> list = new List<PropertyDataCollector>( m_propertiesDict.Values );
  694. return list.Find( x => x.PropertyName.Contains( propertyName+"(" ) ) != null;
  695. }
  696. public string[] BuildUnformatedPropertiesStringArr()
  697. {
  698. List<PropertyDataCollector> list = new List<PropertyDataCollector>( m_propertiesDict.Values );
  699. list.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ); } );
  700. CleanUpList( ref list );
  701. string[] arr = new string[ list.Count ];
  702. for( int i = 0; i < list.Count; i++ )
  703. {
  704. arr[ i ] = list[ i ].PropertyName;
  705. }
  706. return arr;
  707. }
  708. //This clean up was set to remove Header attributes from shader functions which would be last on the property list
  709. //Thus creating a label on the inspector with no properties below
  710. public void CleanUpList( ref List<PropertyDataCollector> list )
  711. {
  712. if( list.Count == 0 )
  713. return;
  714. if( list[ list.Count - 1 ].PropertyName.Contains( "[Header(" ) )
  715. {
  716. //Check if this is a complete property or just a standalone header
  717. Match match = Regex.Match( list[ list.Count - 1 ].PropertyName, TemplateHelperFunctions.PropertiesPatternI );
  718. if( !match.Success )
  719. {
  720. list.RemoveAt( list.Count - 1 );
  721. CleanUpList( ref list );
  722. }
  723. }
  724. }
  725. public void CloseProperties()
  726. {
  727. if( m_dirtyProperties )
  728. {
  729. m_properties += IOUtils.PropertiesEnd;
  730. }
  731. }
  732. public void AddUsePass( string value, bool above )
  733. {
  734. if( m_usePassesDict.ContainsKey( value ) )
  735. return;
  736. m_usePassesDict.Add( value, value );
  737. if( above )
  738. {
  739. m_aboveUsePassesList.Add( new PropertyDataCollector( -1, value ) );
  740. }
  741. else
  742. {
  743. m_belowUsePassesList.Add( new PropertyDataCollector( -1, value ) );
  744. }
  745. }
  746. public void AddGrabPass( string value )
  747. {
  748. if( m_grabPassDict.ContainsKey( value ) )
  749. return;
  750. m_grabPassDict.Add( value, value );
  751. if( string.IsNullOrEmpty( value ) )
  752. {
  753. if( !m_grabPassIsDirty )
  754. m_grabPass += IOUtils.GrabPassEmpty;
  755. }
  756. else
  757. {
  758. m_grabPass += IOUtils.GrabPassBegin + value + IOUtils.GrabPassEnd;
  759. }
  760. m_grabPassList.Add( new PropertyDataCollector( -1, m_grabPass.Replace( "\t", string.Empty ).Replace( "\n", string.Empty ) ) );
  761. m_grabPassIsDirty = true;
  762. }
  763. // This is used by templates global variables to register already existing globals/properties
  764. //public void SoftRegisterUniform( string dataName )
  765. //{
  766. // if( !m_uniformsDict.ContainsKey( dataName ) )
  767. // {
  768. // m_uniformsDict.Add( dataName, new PropertyDataCollector( -1, dataName ) );
  769. // }
  770. //}
  771. public string GenerateInstanced(PrecisionType precisionType, WirePortDataType dataType,string propertyName )
  772. {
  773. if( IsSRP )
  774. {
  775. return string.Format( IOUtils.LWSRPInstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( precisionType, dataType ), propertyName );
  776. }
  777. else
  778. {
  779. return string.Format( IOUtils.InstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( precisionType, dataType ), propertyName );
  780. }
  781. }
  782. public bool CheckIfSoftRegistered( string name )
  783. {
  784. return m_softRegisteredUniformsDict.ContainsKey( name );
  785. }
  786. public void SoftRegisterUniform( TemplateShaderPropertyData data )
  787. {
  788. bool excludeUniformKeyword = ( data.PropertyType == PropertyType.InstancedProperty ) || IsSRP;
  789. string uniformName = data.IsMacro? data.PropertyName:
  790. UIUtils.GenerateUniformName( excludeUniformKeyword, data.PropertyDataType, data.PropertyName );
  791. if( !m_uniformsDict.ContainsKey( uniformName ) )
  792. {
  793. PropertyDataCollector newEntry = new PropertyDataCollector( -1, uniformName );
  794. m_uniformsDict.Add( uniformName, newEntry );
  795. m_softRegisteredUniformsDict.Add( uniformName, newEntry );
  796. }
  797. string instancedUniform = GenerateInstanced( PrecisionType.Float, data.PropertyDataType, data.PropertyName );
  798. if( !m_uniformsDict.ContainsKey( instancedUniform ) )
  799. {
  800. PropertyDataCollector newEntry = new PropertyDataCollector( -1, instancedUniform );
  801. m_uniformsDict.Add( instancedUniform, newEntry );
  802. m_softRegisteredUniformsDict.Add( instancedUniform, newEntry );
  803. }
  804. instancedUniform = GenerateInstanced( PrecisionType.Half, data.PropertyDataType, data.PropertyName );
  805. if( !m_uniformsDict.ContainsKey( instancedUniform ) )
  806. {
  807. PropertyDataCollector newEntry = new PropertyDataCollector( -1, instancedUniform );
  808. m_uniformsDict.Add( instancedUniform, newEntry );
  809. m_softRegisteredUniformsDict.Add( instancedUniform, newEntry );
  810. }
  811. }
  812. public void AddToUniforms( int nodeId, string dataType, string dataName, bool checkSRPBatch = false, bool excludeUniform = false )
  813. {
  814. if( string.IsNullOrEmpty( dataName ) || string.IsNullOrEmpty( dataType ) )
  815. return;
  816. string value = UIUtils.GenerateUniformName( IsSRP || excludeUniform, dataType, dataName );
  817. if( !m_uniformsDict.ContainsKey( value ) && !m_uniformsDict.ContainsKey( dataName ) )
  818. {
  819. m_uniformsDict.Add( value, new PropertyDataCollector( nodeId, value ) );
  820. if( IsSRP && checkSRPBatch )
  821. {
  822. m_templateDataCollector.AddSRPBatcherProperty( nodeId, value );
  823. }
  824. else
  825. {
  826. m_uniforms += "\t\t" + value + '\n';
  827. m_uniformsList.Add( m_uniformsDict[ value ] );
  828. }
  829. m_dirtyUniforms = true;
  830. }
  831. }
  832. public void AddToUniforms( int nodeId, string value, bool checkSRPBatch = false )
  833. {
  834. if( string.IsNullOrEmpty( value ) )
  835. return;
  836. if( !m_uniformsDict.ContainsKey( value ) )
  837. {
  838. m_uniformsDict.Add( value, new PropertyDataCollector( nodeId, value ) );
  839. if( IsSRP && checkSRPBatch )
  840. {
  841. m_templateDataCollector.AddSRPBatcherProperty( nodeId, value );
  842. }
  843. else
  844. {
  845. m_uniforms += "\t\t" + value + '\n';
  846. m_uniformsList.Add( m_uniformsDict[ value ] );
  847. }
  848. m_dirtyUniforms = true;
  849. }
  850. }
  851. public void AddASEMacros()
  852. {
  853. if( Using2DMacrosMask == MacrosMask.NONE && Using3DMacrosMask == MacrosMask.NONE && UsingCUBEMacrosMask == MacrosMask.NONE && Using2DArrayMacrosMask == MacrosMask.NONE )
  854. return;
  855. ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph;
  856. //Debug.Log( UsingMacrosMask );
  857. AddToDirectives( Constants.CustomASEStandarSamplingMacrosHelper[ 0 ], 1 );
  858. if( ( Using2DMacrosMask & MacrosMask.AUTO ) == MacrosMask.AUTO )
  859. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 0 ], 1 );
  860. if( ( Using2DMacrosMask & MacrosMask.LOD ) == MacrosMask.LOD )
  861. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 1 ], 1 );
  862. if( ( Using2DMacrosMask & MacrosMask.BIAS ) == MacrosMask.BIAS )
  863. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 2 ], 1 );
  864. if( ( Using2DMacrosMask & MacrosMask.GRAD ) == MacrosMask.GRAD )
  865. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 3 ], 1 );
  866. if( ( Using3DMacrosMask & MacrosMask.AUTO ) == MacrosMask.AUTO )
  867. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 4 ], 1 );
  868. if( ( Using3DMacrosMask & MacrosMask.LOD ) == MacrosMask.LOD )
  869. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 5 ], 1 );
  870. if( ( Using3DMacrosMask & MacrosMask.BIAS ) == MacrosMask.BIAS )
  871. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 6 ], 1 );
  872. if( ( Using3DMacrosMask & MacrosMask.GRAD ) == MacrosMask.GRAD )
  873. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 7 ], 1 );
  874. if( ( UsingCUBEMacrosMask & MacrosMask.AUTO ) == MacrosMask.AUTO )
  875. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 8 ], 1 );
  876. if( ( UsingCUBEMacrosMask & MacrosMask.LOD ) == MacrosMask.LOD )
  877. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 9 ], 1 );
  878. if( ( UsingCUBEMacrosMask & MacrosMask.BIAS ) == MacrosMask.BIAS )
  879. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 10 ], 1 );
  880. if( ( UsingCUBEMacrosMask & MacrosMask.GRAD ) == MacrosMask.GRAD )
  881. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 11 ], 1 );
  882. if( ( Using2DArrayMacrosMask & MacrosMask.AUTO ) == MacrosMask.AUTO )
  883. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 12 ], 1 );
  884. if( ( Using2DArrayMacrosMask & MacrosMask.LOD ) == MacrosMask.LOD )
  885. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 13 ], 1 );
  886. if( ( Using2DArrayMacrosMask & MacrosMask.BIAS ) == MacrosMask.BIAS )
  887. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 14 ], 1 );
  888. if( ( Using2DArrayMacrosMask & MacrosMask.GRAD ) == MacrosMask.GRAD )
  889. AddToDirectives( Constants.CustomASEStandarSamplingMacrosRecent[ 15 ], 1 );
  890. AddToDirectives( Constants.CustomASEStandarSamplingMacrosHelper[ 1 ], 1 );
  891. if( ( Using2DMacrosMask & MacrosMask.AUTO ) == MacrosMask.AUTO )
  892. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 0 ], 1 );
  893. if( ( Using2DMacrosMask & MacrosMask.LOD ) == MacrosMask.LOD )
  894. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 1 ], 1 );
  895. if( ( Using2DMacrosMask & MacrosMask.BIAS ) == MacrosMask.BIAS )
  896. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 2 ], 1 );
  897. if( ( Using2DMacrosMask & MacrosMask.GRAD ) == MacrosMask.GRAD )
  898. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 3 ], 1 );
  899. if( ( Using3DMacrosMask & MacrosMask.AUTO ) == MacrosMask.AUTO )
  900. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 4 ], 1 );
  901. if( ( Using3DMacrosMask & MacrosMask.LOD ) == MacrosMask.LOD )
  902. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 5 ], 1 );
  903. if( ( Using3DMacrosMask & MacrosMask.BIAS ) == MacrosMask.BIAS )
  904. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 6 ], 1 );
  905. if( ( Using3DMacrosMask & MacrosMask.GRAD ) == MacrosMask.GRAD )
  906. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 7 ], 1 );
  907. if( ( UsingCUBEMacrosMask & MacrosMask.AUTO ) == MacrosMask.AUTO )
  908. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 8 ], 1 );
  909. if( ( UsingCUBEMacrosMask & MacrosMask.LOD ) == MacrosMask.LOD )
  910. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 9 ], 1 );
  911. if( ( UsingCUBEMacrosMask & MacrosMask.BIAS ) == MacrosMask.BIAS )
  912. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 10 ], 1 );
  913. if( ( UsingCUBEMacrosMask & MacrosMask.GRAD ) == MacrosMask.GRAD )
  914. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 11 ], 1 );
  915. if( ( Using2DArrayMacrosMask & MacrosMask.AUTO ) == MacrosMask.AUTO )
  916. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 12 ], 1 );
  917. if( ( Using2DArrayMacrosMask & MacrosMask.LOD ) == MacrosMask.LOD )
  918. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 13 ], 1 );
  919. if( ( Using2DArrayMacrosMask & MacrosMask.BIAS ) == MacrosMask.BIAS )
  920. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 14 ], 1 );
  921. if( ( Using2DArrayMacrosMask & MacrosMask.GRAD ) == MacrosMask.GRAD )
  922. AddToDirectives( Constants.CustomASEStandarSamplingMacrosOlder[ 15 ], 1 );
  923. AddToDirectives( Constants.CustomASEStandarSamplingMacrosHelper[ 2 ], 1 );
  924. }
  925. public void AddToDirectives( string value, int orderIndex = -1 , AdditionalLineType type = AdditionalLineType.Custom )
  926. {
  927. if( string.IsNullOrEmpty( value ) )
  928. return;
  929. switch( type )
  930. {
  931. case AdditionalLineType.Include:value = "#include " + value;break;
  932. case AdditionalLineType.Define:value = "#define " + value; break;
  933. case AdditionalLineType.Pragma:value = "#pragma " + value; break;
  934. }
  935. if( !m_additionalDirectivesDict.ContainsKey( value ) )
  936. {
  937. PropertyDataCollector data = new PropertyDataCollector( -1, value, orderIndex );
  938. m_additionalDirectivesDict.Add( value, data );
  939. m_additionalDirectivesList.Add( data );
  940. m_dirtyAdditionalDirectives = true;
  941. }
  942. }
  943. public void AddToIncludes( int nodeId, string value )
  944. {
  945. if( string.IsNullOrEmpty( value ) )
  946. return;
  947. if( m_includesExclusionDict.ContainsKey( value ) )
  948. {
  949. return;
  950. }
  951. if( IsTemplate )
  952. {
  953. if( m_templateDataCollector.HasDirective( AdditionalLineType.Include, value ) )
  954. return;
  955. }
  956. if( !m_includesDict.ContainsKey( value ) )
  957. {
  958. PropertyDataCollector data = new PropertyDataCollector( nodeId, "#include \"" + value + "\"" );
  959. m_includesDict.Add( value, data );
  960. m_includesList.Add( data );
  961. m_includes += "\t\t#include \"" + value + "\"\n";
  962. m_dirtyIncludes = true;
  963. }
  964. else
  965. {
  966. if( m_showDebugMessages ) UIUtils.ShowMessage( "AddToIncludes:Attempting to add duplicate " + value, MessageSeverity.Warning );
  967. }
  968. }
  969. public void RemoveFromIncludes( string value )
  970. {
  971. if( string.IsNullOrEmpty( value ) )
  972. return;
  973. if( !m_includesExclusionDict.ContainsKey( value ) )
  974. {
  975. m_includesExclusionDict.Add( value, value );
  976. }
  977. if( m_includesDict.ContainsKey( value ) )
  978. {
  979. PropertyDataCollector data = m_includesDict[ value ];
  980. m_includesDict.Remove( value );
  981. m_includesList.Remove( data );
  982. m_dirtyIncludes = true;
  983. string finalValueName = "\t\t#include \"" + value + "\"\n";
  984. m_includes = m_includes.Replace( finalValueName, string.Empty );
  985. }
  986. }
  987. //public void AddToTags( int nodeId, string name, string value )
  988. //{
  989. // if( string.IsNullOrEmpty( name ) || string.IsNullOrEmpty( value ) )
  990. // return;
  991. // if( !m_tagsDict.ContainsKey( name ) )
  992. // {
  993. // string finalResult = string.Format( "\"{0}\"=\"{1}\"", name, value );
  994. // m_tagsDict.Add( name, new PropertyDataCollector( nodeId, finalResult ) );
  995. // m_tagsList.Add( new PropertyDataCollector( nodeId, finalResult ) );
  996. // }
  997. //}
  998. public bool ContainsPragma( string value )
  999. {
  1000. return m_pragmasDict.ContainsKey( value );
  1001. }
  1002. public void AddToPragmas( int nodeId, string value )
  1003. {
  1004. if( string.IsNullOrEmpty( value ) )
  1005. return;
  1006. if( IsTemplate )
  1007. {
  1008. if( m_templateDataCollector.HasDirective( AdditionalLineType.Pragma, value ) )
  1009. return;
  1010. }
  1011. if( !m_pragmasDict.ContainsKey( value ) )
  1012. {
  1013. string finalValue = "#pragma " + value;
  1014. PropertyDataCollector dataCollector = new PropertyDataCollector( nodeId , finalValue );
  1015. //Adding both versions to dict so check can take both into account
  1016. m_pragmasDict.Add( value, dataCollector );
  1017. m_pragmasDict.Add( finalValue , dataCollector );
  1018. m_pragmasList.Add( m_pragmasDict[ value ] );
  1019. m_pragmas += "\t\t#pragma " + value + "\n";
  1020. m_dirtyPragmas = true;
  1021. }
  1022. else
  1023. {
  1024. if( m_showDebugMessages ) UIUtils.ShowMessage( "AddToPragmas:Attempting to add duplicate " + value, MessageSeverity.Warning );
  1025. }
  1026. }
  1027. public bool ContainsDefine( string value )
  1028. {
  1029. return m_definesDict.ContainsKey( value );
  1030. }
  1031. public void AddToDefines( int nodeId, string value, bool define = true )
  1032. {
  1033. if( string.IsNullOrEmpty( value ) )
  1034. return;
  1035. if( IsTemplate )
  1036. {
  1037. if( m_templateDataCollector.HasDirective( AdditionalLineType.Define, value ) )
  1038. return;
  1039. }
  1040. if( !m_definesDict.ContainsKey( value ) )
  1041. {
  1042. string defineValue = ( define ? "#define " : "#undef " ) + value;
  1043. PropertyDataCollector dataCollector = new PropertyDataCollector( nodeId , defineValue );
  1044. //Adding both versions to dict so check can take both into account
  1045. m_definesDict.Add( value, dataCollector );
  1046. m_definesDict.Add( defineValue , dataCollector );
  1047. m_definesList.Add( m_definesDict[ value ] );
  1048. m_defines += "\t\t" + defineValue + "\n";
  1049. m_dirtyDefines = true;
  1050. }
  1051. else
  1052. {
  1053. if( m_showDebugMessages ) UIUtils.ShowMessage( "AddToDefines:Attempting to add duplicate " + value, MessageSeverity.Warning );
  1054. }
  1055. }
  1056. public int GetVirtualCoordinatesId( int nodeId, string coord, string lodBias )
  1057. {
  1058. if( !m_virtualCoordinatesDict.ContainsKey( coord ) )
  1059. {
  1060. m_virtualCoordinatesDict.Add( coord, nodeId );
  1061. AddLocalVariable( nodeId, "VirtualCoord " + Constants.VirtualCoordNameStr + nodeId + " = VTComputeVirtualCoord" + lodBias + "(" + coord + ");" );
  1062. return nodeId;
  1063. }
  1064. else
  1065. {
  1066. int fetchedId = 0;
  1067. m_virtualCoordinatesDict.TryGetValue( coord, out fetchedId );
  1068. return fetchedId;
  1069. }
  1070. }
  1071. public bool AddToLocalVariables( MasterNodePortCategory category, int nodeId, PrecisionType precisionType, WirePortDataType type, string varName, string varValue )
  1072. {
  1073. if( string.IsNullOrEmpty( varName ) || string.IsNullOrEmpty( varValue ) )
  1074. return false;
  1075. string value = UIUtils.PrecisionWirePortToCgType( precisionType, type ) + " " + varName + " = " + varValue + ";";
  1076. return AddToLocalVariables( category, nodeId, value, varName: varName );
  1077. }
  1078. public bool AddToLocalVariables( int nodeId, PrecisionType precisionType, WirePortDataType type, string varName, string varValue )
  1079. {
  1080. if( string.IsNullOrEmpty( varName ) || string.IsNullOrEmpty( varValue ) )
  1081. return false;
  1082. string value = UIUtils.PrecisionWirePortToCgType( precisionType, type ) + " " + varName + " = " + varValue + ";";
  1083. return AddToFragmentLocalVariables( nodeId, value, varName: varName );
  1084. }
  1085. public bool AddToLocalVariables( MasterNodePortCategory category, int nodeId, string value, bool ignoreDuplicates = false, string varName = "" )
  1086. {
  1087. if( string.IsNullOrEmpty( value ) )
  1088. return false;
  1089. switch( category )
  1090. {
  1091. case MasterNodePortCategory.Vertex:
  1092. case MasterNodePortCategory.Tessellation:
  1093. {
  1094. return AddToVertexLocalVariables( nodeId, value, ignoreDuplicates, varName );
  1095. }
  1096. case MasterNodePortCategory.Fragment:
  1097. case MasterNodePortCategory.Debug:
  1098. {
  1099. return AddToFragmentLocalVariables( nodeId, value, ignoreDuplicates, varName );
  1100. }
  1101. }
  1102. return false;
  1103. }
  1104. public bool AddLocalVariable( int nodeId, string customType, string varName, string varValue )
  1105. {
  1106. if( string.IsNullOrEmpty( varName ) || string.IsNullOrEmpty( varValue ) )
  1107. return false;
  1108. string value = customType + " " + varName + " = " + varValue + ";";
  1109. return AddLocalVariable( nodeId, value, varName: varName );
  1110. }
  1111. private bool ValidadeLocalVariable( PrecisionType precisionType, WirePortDataType type, string varName, string varValue, ref string result )
  1112. {
  1113. Array enumValues = Enum.GetValues( typeof( PrecisionType ) );
  1114. foreach( PrecisionType currPrecision in enumValues)
  1115. {
  1116. string value = UIUtils.PrecisionWirePortToTypeValue( currPrecision, type, varName ) + " = " + varValue + ";";
  1117. if( HasLocalVariable( value ) )
  1118. return false;
  1119. if( precisionType == currPrecision )
  1120. result = value;
  1121. }
  1122. return true;
  1123. }
  1124. public bool AddLocalVariable( int nodeId, PrecisionType precisionType, WirePortDataType type, string varName, string varValue )
  1125. {
  1126. if ( string.IsNullOrEmpty( varName ) || string.IsNullOrEmpty( varValue ) )
  1127. {
  1128. return false;
  1129. }
  1130. string value = string.Empty;
  1131. if ( ValidadeLocalVariable( precisionType, type, varName, varValue, ref value ) )
  1132. {
  1133. return AddLocalVariable( nodeId, value, varName: varName );
  1134. }
  1135. return false;
  1136. }
  1137. public bool AddLocalVariable( int nodeId, string varName, string varValue, bool ignoreDuplicates = false, bool addSemiColon = false )
  1138. {
  1139. string finalValue = addSemiColon ? varName + " = " + varValue + ";" : varName + " = " + varValue;
  1140. return AddLocalVariable( nodeId, finalValue, ignoreDuplicates, varName: varName );
  1141. }
  1142. public bool AddLocalVariable( int nodeId, string value, bool ignoreDuplicates = false, string varName = "" )
  1143. {
  1144. if ( string.IsNullOrEmpty( value ) )
  1145. {
  1146. return false;
  1147. }
  1148. switch ( m_portCategory )
  1149. {
  1150. case MasterNodePortCategory.Vertex:
  1151. case MasterNodePortCategory.Tessellation:
  1152. {
  1153. return AddToVertexLocalVariables( nodeId, value, ignoreDuplicates, varName );
  1154. }
  1155. case MasterNodePortCategory.Fragment:
  1156. case MasterNodePortCategory.Debug:
  1157. {
  1158. return AddToFragmentLocalVariables( nodeId, value, ignoreDuplicates, varName );
  1159. }
  1160. }
  1161. return false;
  1162. }
  1163. public string AddVirtualLocalVariable( int nodeId, string variable, string value )
  1164. {
  1165. if( string.IsNullOrEmpty( value ) )
  1166. return string.Empty;
  1167. string result = string.Empty;
  1168. if( !m_virtualVariablesDict.ContainsKey( value ) )
  1169. {
  1170. m_virtualVariablesDict.Add( value, variable );
  1171. result = variable;
  1172. }
  1173. else
  1174. {
  1175. m_virtualVariablesDict.TryGetValue( value, out result );
  1176. }
  1177. return result;
  1178. }
  1179. public void AddCodeComments( bool forceForwardSlash, params string[] comments )
  1180. {
  1181. if( m_portCategory == MasterNodePortCategory.Tessellation || m_portCategory == MasterNodePortCategory.Vertex )
  1182. {
  1183. AddToVertexLocalVariables( 0, IOUtils.CreateCodeComments( forceForwardSlash, comments ) );
  1184. }
  1185. else
  1186. {
  1187. AddToFragmentLocalVariables( 0, IOUtils.CreateCodeComments( forceForwardSlash, comments ) );
  1188. }
  1189. }
  1190. public bool HasLocalVariable( string value )
  1191. {
  1192. return HasLocalVariable( value, m_portCategory );
  1193. }
  1194. public bool HasLocalVariable( string value, MasterNodePortCategory category )
  1195. {
  1196. switch( category )
  1197. {
  1198. case MasterNodePortCategory.Vertex:
  1199. case MasterNodePortCategory.Tessellation:
  1200. {
  1201. return m_vertexLocalVariablesDict.ContainsKey( value );
  1202. }
  1203. case MasterNodePortCategory.Fragment:
  1204. case MasterNodePortCategory.Debug:
  1205. {
  1206. if( m_usingCustomOutput )
  1207. {
  1208. return m_customOutputDict.ContainsKey( value );
  1209. }
  1210. else
  1211. {
  1212. return m_localVariablesDict.ContainsKey( value );
  1213. }
  1214. }
  1215. }
  1216. return false;
  1217. }
  1218. public bool HasLocalVariableByName( string varName )
  1219. {
  1220. return HasLocalVariableByName( varName, m_portCategory );
  1221. }
  1222. public bool HasLocalVariableByName( string varName, MasterNodePortCategory category )
  1223. {
  1224. switch ( category )
  1225. {
  1226. case MasterNodePortCategory.Vertex:
  1227. case MasterNodePortCategory.Tessellation:
  1228. {
  1229. return m_vertexLocalVariablesByNameDict.ContainsKey( varName );
  1230. }
  1231. case MasterNodePortCategory.Fragment:
  1232. case MasterNodePortCategory.Debug:
  1233. {
  1234. if ( m_usingCustomOutput )
  1235. {
  1236. return m_customOutputByNameDict.ContainsKey( varName );
  1237. }
  1238. else
  1239. {
  1240. return m_localVariablesByNameDict.ContainsKey( varName );
  1241. }
  1242. }
  1243. }
  1244. return false;
  1245. }
  1246. public bool AddToFragmentLocalVariables( int nodeId, string value, bool ignoreDuplicates = false, string varName = "" )
  1247. {
  1248. if ( string.IsNullOrEmpty( value ) )
  1249. {
  1250. return false;
  1251. }
  1252. if ( m_usingCustomOutput )
  1253. {
  1254. if ( !m_customOutputDict.ContainsKey( value ) || ignoreDuplicates )
  1255. {
  1256. if ( !m_customOutputDict.TryGetValue( value, out PropertyDataCollector property ) )
  1257. {
  1258. property = new PropertyDataCollector( nodeId, value );
  1259. m_customOutputDict.Add( value, property );
  1260. }
  1261. if ( !string.IsNullOrEmpty( varName ) && !m_customOutputByNameDict.ContainsKey( varName ) )
  1262. {
  1263. m_customOutputByNameDict.Add( varName, property );
  1264. }
  1265. m_customOutputList.Add( m_customOutputDict[ value ] );
  1266. m_customOutput += "\t\t\t" + value + '\n';
  1267. return true;
  1268. }
  1269. else
  1270. {
  1271. if ( m_showDebugMessages ) UIUtils.ShowMessage( "AddToLocalVariables:Attempting to add duplicate " + value, MessageSeverity.Warning );
  1272. }
  1273. }
  1274. else
  1275. {
  1276. if ( !m_localVariablesDict.ContainsKey( value ) || ignoreDuplicates )
  1277. {
  1278. if ( !m_localVariablesDict.TryGetValue( value, out PropertyDataCollector property ) )
  1279. {
  1280. property = new PropertyDataCollector( nodeId, value );
  1281. m_localVariablesDict.Add( value, property );
  1282. }
  1283. if ( !string.IsNullOrEmpty( varName ) && !m_localVariablesByNameDict.ContainsKey( varName ) )
  1284. {
  1285. m_localVariablesByNameDict.Add( varName, property );
  1286. }
  1287. m_localVariablesList.Add( m_localVariablesDict[ value ] );
  1288. AddToSpecialLocalVariables( nodeId, value, ignoreDuplicates );
  1289. return true;
  1290. }
  1291. else
  1292. {
  1293. if ( m_showDebugMessages ) UIUtils.ShowMessage( "AddToLocalVariables:Attempting to add duplicate " + value, MessageSeverity.Warning );
  1294. }
  1295. }
  1296. return false;
  1297. }
  1298. public void AddToSpecialLocalVariables( int nodeId, string value, bool ignoreDuplicates = false, string varName = "" )
  1299. {
  1300. if ( string.IsNullOrEmpty( value ) )
  1301. return;
  1302. if ( m_usingCustomOutput )
  1303. {
  1304. if ( !m_customOutputDict.ContainsKey( value ) || ignoreDuplicates )
  1305. {
  1306. if ( !m_customOutputDict.TryGetValue( value, out PropertyDataCollector property ) )
  1307. {
  1308. property = new PropertyDataCollector( nodeId, value );
  1309. m_customOutputDict.Add( value, property );
  1310. }
  1311. if ( !string.IsNullOrEmpty( varName ) && !m_customOutputByNameDict.ContainsKey( varName ) )
  1312. {
  1313. m_customOutputByNameDict.Add( varName, property );
  1314. }
  1315. m_customOutputList.Add( m_customOutputDict[ value ] );
  1316. m_customOutput += "\t\t\t" + value + '\n';
  1317. m_dirtySpecialLocalVariables = true;
  1318. }
  1319. else
  1320. {
  1321. if ( m_showDebugMessages ) UIUtils.ShowMessage( "AddToSpecialLocalVariables:Attempting to add duplicate " + value, MessageSeverity.Warning );
  1322. }
  1323. }
  1324. else
  1325. {
  1326. if ( !m_specialLocalVariablesDict.ContainsKey( value ) || ignoreDuplicates )
  1327. {
  1328. if ( !m_specialLocalVariablesDict.TryGetValue( value, out PropertyDataCollector property ) )
  1329. {
  1330. property = new PropertyDataCollector( nodeId, value );
  1331. m_specialLocalVariablesDict.Add( value, property );
  1332. }
  1333. if ( !string.IsNullOrEmpty( varName ) && !m_specialLocalVariablesByNameDict.ContainsKey( varName ) )
  1334. {
  1335. m_specialLocalVariablesByNameDict.Add( value, property );
  1336. }
  1337. m_specialLocalVariablesList.Add( m_specialLocalVariablesDict[ value ] );
  1338. m_specialLocalVariables += "\t\t\t" + value + '\n';
  1339. m_dirtySpecialLocalVariables = true;
  1340. }
  1341. else
  1342. {
  1343. if ( m_showDebugMessages ) UIUtils.ShowMessage( "AddToSpecialLocalVariables:Attempting to add duplicate " + value, MessageSeverity.Warning );
  1344. }
  1345. }
  1346. }
  1347. public void ClearSpecialLocalVariables()
  1348. {
  1349. //m_specialLocalVariablesDict.Clear();
  1350. m_specialLocalVariables = string.Empty;
  1351. m_dirtySpecialLocalVariables = false;
  1352. }
  1353. public bool AddToVertexLocalVariables( int nodeId, string varName, string varValue )
  1354. {
  1355. if ( string.IsNullOrEmpty( varName ) || string.IsNullOrEmpty( varValue ) )
  1356. return false;
  1357. string value = varName + " = " + varValue + ";";
  1358. return AddToVertexLocalVariables( nodeId, value, varName: varName );
  1359. }
  1360. public bool AddToVertexLocalVariables( int nodeId, PrecisionType precisionType, WirePortDataType type, string varName, string varValue )
  1361. {
  1362. if ( string.IsNullOrEmpty( varName ) || string.IsNullOrEmpty( varValue ) )
  1363. return false;
  1364. string value = UIUtils.PrecisionWirePortToCgType( precisionType, type ) + " " + varName + " = " + varValue + ";";
  1365. return AddToVertexLocalVariables( nodeId, value, varName: varName );
  1366. }
  1367. public bool AddToVertexLocalVariables( int nodeId, string value, bool ignoreDuplicates = false, string varName = "" )
  1368. {
  1369. if ( string.IsNullOrEmpty( value ) )
  1370. return false;
  1371. if ( !m_vertexLocalVariablesDict.ContainsKey( value ) || ignoreDuplicates )
  1372. {
  1373. if ( !m_vertexLocalVariablesDict.TryGetValue( value, out PropertyDataCollector property ) )
  1374. {
  1375. property = new PropertyDataCollector( nodeId, value );
  1376. m_vertexLocalVariablesDict.Add( value, property );
  1377. }
  1378. if ( !string.IsNullOrEmpty( varName ) && !m_vertexLocalVariablesByNameDict.ContainsKey( value ) )
  1379. {
  1380. m_vertexLocalVariablesByNameDict.Add( value, property );
  1381. }
  1382. m_vertexLocalVariablesList.Add( m_vertexLocalVariablesDict[ value ] );
  1383. m_vertexLocalVariables += "\t\t\t" + value + '\n';
  1384. m_dirtyVertexLocalVariables = true;
  1385. return true;
  1386. }
  1387. else
  1388. {
  1389. if ( m_showDebugMessages ) UIUtils.ShowMessage( "AddToVertexLocalVariables:Attempting to add duplicate " + value, MessageSeverity.Warning );
  1390. }
  1391. return false;
  1392. }
  1393. public void ClearVertexLocalVariables()
  1394. {
  1395. //m_vertexLocalVariablesDict.Clear();
  1396. m_vertexLocalVariables = string.Empty;
  1397. m_dirtyVertexLocalVariables = false;
  1398. }
  1399. public bool CheckFunction( string header )
  1400. {
  1401. return m_localFunctions.ContainsKey( header );
  1402. }
  1403. public string AddFunctions( string header, string body, params object[] inParams )
  1404. {
  1405. if( !m_localFunctions.ContainsKey( header ) )
  1406. {
  1407. m_localFunctions.Add( header, body );
  1408. m_functionsList.Add( new PropertyDataCollector( -1, body.Replace( "\t\t", string.Empty ) ) );
  1409. m_functions += "\n" + body + "\n";
  1410. m_dirtyFunctions = true;
  1411. }
  1412. return String.Format( header, inParams );
  1413. }
  1414. public string AddFunctions( string header, string[] bodyLines, bool addNewLine, params object[] inParams )
  1415. {
  1416. if( !m_localFunctions.ContainsKey( header ) )
  1417. {
  1418. string body = string.Empty;
  1419. for( int i = 0; i < bodyLines.Length; i++ )
  1420. {
  1421. body += ( m_masterNodeCategory == AvailableShaderTypes.Template ) ? bodyLines[ i ] : "\t\t" + bodyLines[ i ];
  1422. if( addNewLine )
  1423. body += '\n';
  1424. }
  1425. m_localFunctions.Add( header, body );
  1426. m_functionsList.Add( new PropertyDataCollector( -1, body ) );
  1427. m_functions += "\n" + body + "\n";
  1428. m_dirtyFunctions = true;
  1429. }
  1430. return String.Format( header, inParams );
  1431. }
  1432. public bool HasFunction( string functionId )
  1433. {
  1434. return m_localFunctions.ContainsKey( functionId );
  1435. }
  1436. public void AddFunction( string functionId, string body )
  1437. {
  1438. if( !m_localFunctions.ContainsKey( functionId ) )
  1439. {
  1440. m_functionsList.Add( new PropertyDataCollector( -1, body ) );
  1441. m_localFunctions.Add( functionId, body );
  1442. m_functions += "\n" + body + "\n";
  1443. m_dirtyFunctions = true;
  1444. }
  1445. }
  1446. public void AddFunction( string functionId, string[] bodyLines, bool addNewline )
  1447. {
  1448. if( !m_localFunctions.ContainsKey( functionId ) )
  1449. {
  1450. string body = string.Empty;
  1451. for( int i = 0; i < bodyLines.Length; i++ )
  1452. {
  1453. body += ( m_masterNodeCategory == AvailableShaderTypes.Template ) ? bodyLines[ i ] : "\t\t" + bodyLines[ i ];
  1454. if( addNewline )
  1455. body += '\n';
  1456. }
  1457. m_functionsList.Add( new PropertyDataCollector( -1, body ) );
  1458. m_localFunctions.Add( functionId, body );
  1459. m_functions += "\n" + body + "\n";
  1460. m_dirtyFunctions = true;
  1461. }
  1462. }
  1463. public void AddInstructions( string value, bool addTabs = false, bool addLineEnding = false )
  1464. {
  1465. m_instructionsList.Add( new PropertyDataCollector( -1, value ) );
  1466. m_instructions += addTabs ? "\t\t\t" + value : value;
  1467. if( addLineEnding )
  1468. {
  1469. m_instructions += '\n';
  1470. }
  1471. m_dirtyInstructions = true;
  1472. }
  1473. public void AddInstructions( bool addLineEnding, bool addTabs, params string[] values )
  1474. {
  1475. for( int i = 0; i < values.Length; i++ )
  1476. {
  1477. m_instructionsList.Add( new PropertyDataCollector( -1, values[ i ] ) );
  1478. m_instructions += addTabs ? "\t\t\t" + values[ i ] : values[ i ];
  1479. if( addLineEnding )
  1480. {
  1481. m_instructions += '\n';
  1482. }
  1483. }
  1484. m_dirtyInstructions = true;
  1485. }
  1486. public void AddToStartInstructions( string value )
  1487. {
  1488. if( string.IsNullOrEmpty( value ) )
  1489. return;
  1490. m_instructions = value + m_instructions;
  1491. m_dirtyInstructions = true;
  1492. }
  1493. public void ResetInstructions()
  1494. {
  1495. m_instructionsList.Clear();
  1496. m_instructions = string.Empty;
  1497. m_dirtyInstructions = false;
  1498. }
  1499. public void ResetVertexInstructions()
  1500. {
  1501. m_vertexDataList.Clear();
  1502. m_vertexData = string.Empty;
  1503. m_dirtyPerVertexData = false;
  1504. }
  1505. public void AddPropertyNode( PropertyNode node )
  1506. {
  1507. if( !m_propertyNodes.ContainsKey( node.UniqueId ) )
  1508. {
  1509. m_propertyNodes.Add( node.UniqueId, node );
  1510. }
  1511. }
  1512. public void UpdateMaterialOnPropertyNodes( Material material )
  1513. {
  1514. m_masterNode.UpdateMaterial( material );
  1515. foreach( KeyValuePair<int, PropertyNode> kvp in m_propertyNodes )
  1516. {
  1517. kvp.Value.UpdateMaterial( material );
  1518. }
  1519. }
  1520. public void AddToVertexInput( string value )
  1521. {
  1522. if( !m_vertexInputDict.ContainsKey( value ) )
  1523. {
  1524. m_vertexInputDict.Add( value, value );
  1525. m_vertexInputList.Add( value );
  1526. }
  1527. }
  1528. public void AddToInterpolators( string value )
  1529. {
  1530. if( !m_interpolatorsDict.ContainsKey( value ) )
  1531. {
  1532. m_interpolatorsDict.Add( value, value );
  1533. m_interpolatorsList.Add( value );
  1534. }
  1535. }
  1536. public void AddToVertexInterpolatorsDecl( string value )
  1537. {
  1538. if( !m_vertexInterpDeclDict.ContainsKey( value ) )
  1539. {
  1540. m_vertexInterpDeclDict.Add( value, value );
  1541. m_vertexInterpDeclList.Add( value );
  1542. }
  1543. }
  1544. public void UpdateShaderImporter( ref Shader shader )
  1545. {
  1546. ShaderImporter importer = (ShaderImporter)ShaderImporter.GetAtPath( AssetDatabase.GetAssetPath( shader ) );
  1547. if( m_propertyNodes.Count > 0 )
  1548. {
  1549. try
  1550. {
  1551. bool hasContents = false;
  1552. TextureDefaultsDataColector defaultCol = new TextureDefaultsDataColector();
  1553. foreach( KeyValuePair<int, PropertyNode> kvp in m_propertyNodes )
  1554. {
  1555. hasContents = kvp.Value.UpdateShaderDefaults( ref shader, ref defaultCol ) || hasContents;
  1556. }
  1557. if( hasContents )
  1558. {
  1559. importer.SetDefaultTextures( defaultCol.NamesArr, defaultCol.ValuesArr );
  1560. defaultCol.Destroy();
  1561. defaultCol = null;
  1562. }
  1563. }
  1564. catch( Exception e )
  1565. {
  1566. Debug.LogException( e );
  1567. }
  1568. }
  1569. importer.SaveAndReimport();
  1570. }
  1571. public void AddCustomAppData( string value )
  1572. {
  1573. if( m_customAppDataItemsDict.ContainsKey( value ) )
  1574. return;
  1575. m_customAppDataItemsDict.Add( value, value );
  1576. m_customAppDataItems += "\t\t\t" + value + "\n";
  1577. m_dirtyAppData = true;
  1578. }
  1579. public void ForceCustomAppDataUsage()
  1580. {
  1581. m_dirtyAppData = true;
  1582. }
  1583. //public string CustomAppDataName { get { return m_dirtyAppData ? Constants.CustomAppDataFullName : Constants.AppDataFullName; } }
  1584. public string SurfaceVertexStructure { get { return ( m_dirtyAppData ? Constants.CustomAppDataFullName : Constants.AppDataFullName ); } }
  1585. public string CustomAppData
  1586. {
  1587. get
  1588. {
  1589. if( m_dirtyPerVertexData )
  1590. {
  1591. return Constants.CustomAppDataFullBody + m_customAppDataItems + "\t\t};\n";
  1592. }
  1593. else if ( m_dirtyAppData )
  1594. {
  1595. return Constants.CustomAppDataFullBody + "\t\t};\n";
  1596. }
  1597. return string.Empty;
  1598. }
  1599. }
  1600. public void Destroy()
  1601. {
  1602. m_masterNode = null;
  1603. m_customAppDataItemsDict.Clear();
  1604. m_customAppDataItemsDict = null;
  1605. m_inputList.Clear();
  1606. m_inputList = null;
  1607. m_customInputList.Clear();
  1608. m_customInputList = null;
  1609. m_propertiesList.Clear();
  1610. m_propertiesList = null;
  1611. m_instancedPropertiesList.Clear();
  1612. m_instancedPropertiesList = null;
  1613. m_dotsPropertiesList.Clear();
  1614. m_dotsPropertiesList = null;
  1615. m_dotsDefinesList.Clear();
  1616. m_dotsDefinesList = null;
  1617. m_uniformsList.Clear();
  1618. m_uniformsList = null;
  1619. m_additionalDirectivesList.Clear();
  1620. m_additionalDirectivesList = null;
  1621. m_includesList.Clear();
  1622. m_includesList = null;
  1623. //m_tagsList.Clear();
  1624. //m_tagsList = null;
  1625. m_pragmasList.Clear();
  1626. m_pragmasList = null;
  1627. m_definesList.Clear();
  1628. m_definesList = null;
  1629. m_instructionsList.Clear();
  1630. m_instructionsList = null;
  1631. m_localVariablesList.Clear();
  1632. m_localVariablesList = null;
  1633. m_vertexLocalVariablesList.Clear();
  1634. m_vertexLocalVariablesList = null;
  1635. m_specialLocalVariablesList.Clear();
  1636. m_specialLocalVariablesList = null;
  1637. m_vertexDataList.Clear();
  1638. m_vertexDataList = null;
  1639. m_customOutputList.Clear();
  1640. m_customOutputList = null;
  1641. m_functionsList.Clear();
  1642. m_functionsList = null;
  1643. m_grabPassList.Clear();
  1644. m_grabPassList = null;
  1645. m_aboveUsePassesList.Clear();
  1646. m_aboveUsePassesList = null;
  1647. m_belowUsePassesList.Clear();
  1648. m_belowUsePassesList = null;
  1649. m_grabPassDict.Clear();
  1650. m_grabPassDict = null;
  1651. m_usePassesDict.Clear();
  1652. m_usePassesDict = null;
  1653. m_propertyNodes.Clear();
  1654. m_propertyNodes = null;
  1655. m_inputDict.Clear();
  1656. m_inputDict = null;
  1657. m_customInputDict.Clear();
  1658. m_customInputDict = null;
  1659. m_propertiesDict.Clear();
  1660. m_propertiesDict = null;
  1661. m_dotsPropertiesDict.Clear();
  1662. m_dotsPropertiesDict = null;
  1663. m_instancedPropertiesDict.Clear();
  1664. m_instancedPropertiesDict = null;
  1665. m_uniformsDict.Clear();
  1666. m_uniformsDict = null;
  1667. m_softRegisteredUniformsDict.Clear();
  1668. m_softRegisteredUniformsDict = null;
  1669. m_includesDict.Clear();
  1670. m_includesDict = null;
  1671. m_additionalDirectivesDict.Clear();
  1672. m_additionalDirectivesDict = null;
  1673. m_includesExclusionDict.Clear();
  1674. m_includesExclusionDict = null;
  1675. //m_tagsDict.Clear();
  1676. //m_tagsDict = null;
  1677. m_pragmasDict.Clear();
  1678. m_pragmasDict = null;
  1679. m_definesDict.Clear();
  1680. m_definesDict = null;
  1681. m_virtualCoordinatesDict.Clear();
  1682. m_virtualCoordinatesDict = null;
  1683. m_virtualVariablesDict.Clear();
  1684. m_virtualVariablesDict = null;
  1685. m_localVariablesDict.Clear();
  1686. m_localVariablesDict = null;
  1687. m_localVariablesByNameDict.Clear();
  1688. m_localVariablesByNameDict = null;
  1689. m_specialLocalVariablesDict.Clear();
  1690. m_specialLocalVariablesDict = null;
  1691. m_specialLocalVariablesByNameDict.Clear();
  1692. m_specialLocalVariablesByNameDict = null;
  1693. m_vertexLocalVariablesDict.Clear();
  1694. m_vertexLocalVariablesDict = null;
  1695. m_vertexLocalVariablesByNameDict.Clear();
  1696. m_vertexLocalVariablesByNameDict = null;
  1697. m_localFunctions.Clear();
  1698. m_localFunctions = null;
  1699. m_vertexDataDict.Clear();
  1700. m_vertexDataDict = null;
  1701. m_customOutputDict.Clear();
  1702. m_customOutputDict = null;
  1703. m_customOutputByNameDict.Clear();
  1704. m_customOutputByNameDict = null;
  1705. //templates
  1706. m_vertexInputList.Clear();
  1707. m_vertexInputList = null;
  1708. m_vertexInputDict.Clear();
  1709. m_vertexInputDict = null;
  1710. m_interpolatorsList.Clear();
  1711. m_interpolatorsList = null;
  1712. m_interpolatorsDict.Clear();
  1713. m_interpolatorsDict = null;
  1714. m_vertexInterpDeclList.Clear();
  1715. m_vertexInterpDeclList = null;
  1716. m_vertexInterpDeclDict.Clear();
  1717. m_vertexInterpDeclDict = null;
  1718. m_templateDataCollector.Destroy();
  1719. m_templateDataCollector = null;
  1720. m_customShadowCoordsDict.Clear();
  1721. m_customShadowCoordsDict = null;
  1722. m_customShadowCoordsList.Clear();
  1723. m_customShadowCoordsDict = null;
  1724. m_packSlotsList.Clear();
  1725. m_packSlotsList = null;
  1726. }
  1727. public string Inputs { get { return m_input; } }
  1728. public string CustomInput { get { return m_customInput; } }
  1729. public string Properties { get { return m_properties; } }
  1730. public string InstanceBlockName { get { return m_instanceBlockName; } }
  1731. public string InstancedProperties { get { return m_instancedProperties; } }
  1732. public string Uniforms { get { return m_uniforms; } }
  1733. public string Instructions { get { return m_instructions; } }
  1734. public string Includes { get { return m_includes; } }
  1735. public string Pragmas { get { return m_pragmas; } }
  1736. public string Defines { get { return m_defines; } }
  1737. public string LocalVariables { get { return m_localVariables; } }
  1738. public string SpecialLocalVariables { get { return m_specialLocalVariables; } }
  1739. public string VertexLocalVariables { get { return m_vertexLocalVariables; } }
  1740. //public string VertexLocalVariablesFromList
  1741. //{
  1742. // get
  1743. // {
  1744. // string result = string.Empty;
  1745. // int count = m_vertexLocalVariablesList.Count;
  1746. // for( int i = 0; i < count; i++ )
  1747. // {
  1748. // result += m_vertexLocalVariablesList[ i ].PropertyName + "\n";
  1749. // }
  1750. // return result;
  1751. // }
  1752. //}
  1753. public string VertexData { get { return m_vertexData; } }
  1754. public string CustomOutput { get { return m_customOutput; } }
  1755. public string Functions { get { return m_functions; } }
  1756. public string GrabPass { get { return m_grabPass; } }
  1757. public bool DirtyAppData { get { return m_dirtyAppData; } }
  1758. public bool DirtyInstructions { get { return m_dirtyInstructions; } }
  1759. public bool DirtyUniforms { get { return m_dirtyUniforms; } }
  1760. public bool DirtyProperties { get { return m_dirtyProperties; } }
  1761. public bool DirtyInstancedProperties { get { return m_dirtyInstancedProperties; } }
  1762. public bool DirtyInputs { get { return m_dirtyInputs; } }
  1763. public bool DirtyCustomInput { get { return m_dirtyCustomInputs; } }
  1764. public bool DirtyIncludes { get { return m_dirtyIncludes; } }
  1765. public bool DirtyPragmas { get { return m_dirtyPragmas; } }
  1766. public bool DirtyDefines { get { return m_dirtyDefines; } }
  1767. public bool DirtyAdditionalDirectives { get { return m_dirtyAdditionalDirectives; } }
  1768. public bool DirtyLocalVariables { get { return m_dirtyLocalVariables; } }
  1769. public bool DirtyVertexVariables { get { return m_dirtyVertexLocalVariables; } }
  1770. public bool DirtySpecialLocalVariables { get { return m_dirtySpecialLocalVariables; } }
  1771. public bool DirtyPerVertexData { get { return m_dirtyPerVertexData; } }
  1772. public bool DirtyFunctions { get { return m_dirtyFunctions; } }
  1773. public bool DirtyGrabPass { get { return m_grabPassIsDirty; } }
  1774. public int LocalVariablesAmount { get { return m_localVariablesDict.Count; } }
  1775. public int SpecialLocalVariablesAmount { get { return m_specialLocalVariablesDict.Count; } }
  1776. public int VertexLocalVariablesAmount { get { return m_vertexLocalVariablesDict.Count; } }
  1777. public bool TesselationActive { set { m_tesselationActive = value; } get { return m_tesselationActive; } }
  1778. public int AvailableVertexTempId { get { return m_availableVertexTempId++; } }
  1779. public int AvailableFragTempId { get { return m_availableFragTempId++; } }
  1780. /// <summary>
  1781. /// Returns true if Normal output is being written by something else
  1782. /// </summary>
  1783. public bool DirtyNormal
  1784. {
  1785. get { return m_dirtyNormal; }
  1786. set { m_dirtyNormal = value; }
  1787. }
  1788. public bool IsFragmentCategory
  1789. {
  1790. get { return m_portCategory == MasterNodePortCategory.Fragment || m_portCategory == MasterNodePortCategory.Debug; }
  1791. }
  1792. public MasterNodePortCategory PortCategory
  1793. {
  1794. get { return m_portCategory; }
  1795. set { m_portCategory = value; }
  1796. }
  1797. public PortGenType GenType
  1798. {
  1799. get { return m_genType; }
  1800. set { m_genType = value; }
  1801. }
  1802. public bool IsTemplate { get { return m_masterNodeCategory == AvailableShaderTypes.Template; } }
  1803. public bool IsSRP { get { return ( TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.URP || TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HDRP ); } }
  1804. public AvailableShaderTypes MasterNodeCategory
  1805. {
  1806. get { return m_masterNodeCategory; }
  1807. set { m_masterNodeCategory = value; }
  1808. }
  1809. public string CurrentPassName
  1810. {
  1811. get
  1812. {
  1813. var multiPassMasterNode = m_masterNode as TemplateMultiPassMasterNode;
  1814. return ( multiPassMasterNode != null ) ? multiPassMasterNode.PassName : string.Empty;
  1815. }
  1816. }
  1817. /// <summary>
  1818. /// Forces write to Normal output when the output is not connected
  1819. /// </summary>
  1820. public bool ForceNormal
  1821. {
  1822. get { return m_forceNormal; }
  1823. set
  1824. {
  1825. if( value )
  1826. {
  1827. if( !m_forceNormalIsDirty )
  1828. {
  1829. m_forceNormal = value;
  1830. m_forceNormalIsDirty = value;
  1831. }
  1832. }
  1833. else
  1834. {
  1835. m_forceNormal = value;
  1836. }
  1837. }
  1838. }
  1839. public bool UsingVertexColor
  1840. {
  1841. get { return m_usingVertexColor; }
  1842. set { m_usingVertexColor = value; }
  1843. }
  1844. public bool UsingInternalData
  1845. {
  1846. get { return m_usingInternalData; }
  1847. set { m_usingInternalData = value; }
  1848. }
  1849. public bool UsingScreenPos
  1850. {
  1851. get { return m_usingScreenPos; }
  1852. set { m_usingScreenPos = value; }
  1853. }
  1854. public bool UsingCustomScreenPos
  1855. {
  1856. get { return m_usingCustomScreenPos; }
  1857. set { m_usingCustomScreenPos = value; }
  1858. }
  1859. public bool UsingWorldNormal
  1860. {
  1861. get { return m_usingWorldNormal; }
  1862. set { m_usingWorldNormal = value; }
  1863. }
  1864. public bool UsingWorldReflection
  1865. {
  1866. get { return m_usingWorldReflection; }
  1867. set { m_usingWorldReflection = value; }
  1868. }
  1869. public bool UsingWorldPosition
  1870. {
  1871. get { return m_usingWorldPosition; }
  1872. set { m_usingWorldPosition = value; }
  1873. }
  1874. public bool UsingViewDirection
  1875. {
  1876. get { return m_usingViewDirection; }
  1877. set { m_usingViewDirection = value; }
  1878. }
  1879. public bool IsOutlineDataCollector
  1880. {
  1881. get { return m_isOutlineDataCollector; }
  1882. set { m_isOutlineDataCollector = value; }
  1883. }
  1884. public bool UsingCustomOutlineColor
  1885. {
  1886. get { return m_usingCustomOutlineColor; }
  1887. set { m_usingCustomOutlineColor = value; }
  1888. }
  1889. public bool UsingCustomOutlineWidth
  1890. {
  1891. get { return m_usingCustomOutlineWidth; }
  1892. set { m_usingCustomOutlineWidth = value; }
  1893. }
  1894. public bool UsingCustomOutlineAlpha
  1895. {
  1896. get { return m_usingCustomOutlineAlpha; }
  1897. set { m_usingCustomOutlineAlpha = value; }
  1898. }
  1899. public int CustomOutlineSelectedAlpha
  1900. {
  1901. get { return m_customOutlineSelectedAlpha; }
  1902. set { m_customOutlineSelectedAlpha = value; }
  1903. }
  1904. public bool UsingCustomOutput
  1905. {
  1906. get { return m_usingCustomOutput; }
  1907. set { m_usingCustomOutput = value; }
  1908. }
  1909. public bool UsingHigherSizeTexcoords
  1910. {
  1911. get { return m_usingHigherSizeTexcoords; }
  1912. set { m_usingHigherSizeTexcoords = value; }
  1913. }
  1914. public bool UsingLightAttenuation
  1915. {
  1916. get { return m_usingLightAttenuation; }
  1917. set { m_usingLightAttenuation = value; }
  1918. }
  1919. public bool UsingTextureArrays
  1920. {
  1921. get { return m_usingTextureArrays; }
  1922. set { m_usingTextureArrays = value; }
  1923. }
  1924. public bool UsingExtraStandardMacros
  1925. {
  1926. get { return m_usingExtraStandardMacros; }
  1927. set { m_usingExtraStandardMacros = value; }
  1928. }
  1929. public MacrosMask Using2DMacrosMask
  1930. {
  1931. get { return m_using2DMacrosMask; }
  1932. set { m_using2DMacrosMask = value; }
  1933. }
  1934. public MacrosMask Using3DMacrosMask
  1935. {
  1936. get { return m_using3DMacrosMask; }
  1937. set { m_using3DMacrosMask = value; }
  1938. }
  1939. public MacrosMask UsingCUBEMacrosMask
  1940. {
  1941. get { return m_usingCUBEMacrosMask; }
  1942. set { m_usingCUBEMacrosMask = value; }
  1943. }
  1944. public MacrosMask Using2DArrayMacrosMask
  1945. {
  1946. get { return m_using2DArrayMacrosMask; }
  1947. set { m_using2DArrayMacrosMask = value; }
  1948. }
  1949. public bool UsingExtra3DSRPMacros
  1950. {
  1951. get { return m_usingExtra3DSRPMacros; }
  1952. set { m_usingExtra3DSRPMacros = value; }
  1953. }
  1954. public bool UsingArrayDerivatives
  1955. {
  1956. get { return m_usingArrayDerivatives; }
  1957. set { m_usingArrayDerivatives = value; }
  1958. }
  1959. public bool SafeNormalizeLightDir
  1960. {
  1961. get { return m_safeNormalizeLightDir; }
  1962. set { m_safeNormalizeLightDir = value; }
  1963. }
  1964. public bool SafeNormalizeViewDir
  1965. {
  1966. get { return m_safeNormalizeViewDir; }
  1967. set { m_safeNormalizeViewDir = value; }
  1968. }
  1969. public string StandardAdditionalDirectives
  1970. {
  1971. get
  1972. {
  1973. string body = string.Empty;
  1974. int count = m_additionalDirectivesList.Count;
  1975. for( int i = 0; i < count; i++ )
  1976. {
  1977. body += "\t\t" + m_additionalDirectivesList[ i ].PropertyName + "\n";
  1978. }
  1979. return body;
  1980. }
  1981. }
  1982. public bool SurfaceCustomShadowCaster
  1983. {
  1984. get { return m_surfaceCustomShadowCaster; }
  1985. set { m_surfaceCustomShadowCaster = value; }
  1986. }
  1987. public bool CustomOutline { get { return UsingCustomOutlineColor || UsingCustomOutlineWidth || UsingCustomOutlineAlpha; } }
  1988. public List<PropertyDataCollector> InputList { get { return m_inputList; } }
  1989. public List<PropertyDataCollector> CustomInputList { get { return m_customInputList; } }
  1990. public List<PropertyDataCollector> PropertiesList { get { return m_propertiesList; } }
  1991. public List<PropertyDataCollector> InstancedPropertiesList { get { return m_instancedPropertiesList; } }
  1992. public List<PropertyDataCollector> DotsPropertiesList { get { return m_dotsPropertiesList; } }
  1993. public List<PropertyDataCollector> DotsDefinesList { get { return m_dotsDefinesList; } }
  1994. public List<PropertyDataCollector> UniformsList { get { return m_uniformsList; } }
  1995. public List<PropertyDataCollector> MiscList { get { return m_additionalDirectivesList; } }
  1996. public List<PropertyDataCollector> BeforeNativeDirectivesList { get { return m_additionalDirectivesList.FindAll( obj => obj.OrderIndex < 0 ); } }
  1997. public List<PropertyDataCollector> AfterNativeDirectivesList { get { return m_additionalDirectivesList.FindAll( obj => obj.OrderIndex > 0 ); } }
  1998. public List<PropertyDataCollector> IncludesList { get { return m_includesList; } }
  1999. //public List<PropertyDataCollector> TagsList { get { return m_tagsList; } }
  2000. public List<PropertyDataCollector> PragmasList { get { return m_pragmasList; } }
  2001. public List<PropertyDataCollector> DefinesList { get { return m_definesList; } }
  2002. public List<PropertyDataCollector> InstructionsList { get { return m_instructionsList; } }
  2003. public List<PropertyDataCollector> LocalVariablesList { get { return m_localVariablesList; } }
  2004. public List<PropertyDataCollector> VertexLocalVariablesList { get { return m_vertexLocalVariablesList; } }
  2005. public List<PropertyDataCollector> SpecialLocalVariablesList { get { return m_specialLocalVariablesList; } }
  2006. public List<PropertyDataCollector> VertexDataList { get { return m_vertexDataList; } }
  2007. public List<PropertyDataCollector> CustomOutputList { get { return m_customOutputList; } }
  2008. public List<PropertyDataCollector> FunctionsList { get { return m_functionsList; } }
  2009. public List<PropertyDataCollector> GrabPassList { get { return m_grabPassList; } }
  2010. public Dictionary<string, string> GrabPassDict { get { return m_grabPassDict; } }
  2011. public List<PropertyDataCollector> AboveUsePassesList { get { return m_aboveUsePassesList; } }
  2012. public List<PropertyDataCollector> BelowUsePassesList { get { return m_belowUsePassesList; } }
  2013. public Dictionary<string, string> AboveUsePassesDict { get { return m_usePassesDict; } }
  2014. public List<InputCoordsCollector> CustomShadowCoordsList { get { return m_customShadowCoordsList; } }
  2015. public List<int> PackSlotsList { get { return m_packSlotsList; } }
  2016. public Dictionary<string, string> LocalFunctions { get { return m_localFunctions; } }
  2017. //Templates
  2018. public List<string> VertexInputList { get { return m_vertexInputList; } }
  2019. public List<string> InterpolatorList { get { return m_interpolatorsList; } }
  2020. public List<string> VertexInterpDeclList { get { return m_vertexInterpDeclList; } }
  2021. public TemplateDataCollector TemplateDataCollectorInstance { get { return m_templateDataCollector; } }
  2022. public RenderPath CurrentRenderPath
  2023. {
  2024. get { return m_renderPath; }
  2025. set { m_renderPath = value; }
  2026. }
  2027. public NodeAvailability CurrentCanvasMode { get { return m_currentCanvasMode; } set { m_currentCanvasMode = value; } }
  2028. public TemplateSRPType CurrentSRPType
  2029. {
  2030. get
  2031. {
  2032. if( IsTemplate )
  2033. return m_templateDataCollector.CurrentSRPType;
  2034. return TemplateSRPType.BiRP;
  2035. }
  2036. }
  2037. public Dictionary<string, PropertyDataCollector> PropertiesDict { get { return m_propertiesDict; } }
  2038. }
  2039. }