TriplanarNode.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace AmplifyShaderEditor
  6. {
  7. [Serializable]
  8. [NodeAttributes( "Triplanar Sample", "Textures", "Triplanar Mapping" )]
  9. public sealed class TriplanarNode : ParentNode
  10. {
  11. [SerializeField]
  12. private string m_uniqueName;
  13. private bool m_editPropertyNameMode = false;
  14. [SerializeField]
  15. private string m_propertyInspectorName = "Triplanar Sampler";
  16. private enum TriplanarType { Spherical, Cylindrical }
  17. [SerializeField]
  18. private TriplanarType m_selectedTriplanarType = TriplanarType.Spherical;
  19. private enum TriplanarSpace { Object, World }
  20. [SerializeField]
  21. private TriplanarSpace m_selectedTriplanarSpace = TriplanarSpace.World;
  22. [SerializeField]
  23. private bool m_normalCorrection = false;
  24. [SerializeField]
  25. private ViewSpace m_normalSpace = ViewSpace.Tangent;
  26. [SerializeField]
  27. private TexturePropertyNode m_topTexture;
  28. [SerializeField]
  29. private TexturePropertyNode m_midTexture;
  30. [SerializeField]
  31. private TexturePropertyNode m_botTexture;
  32. bool m_texturesInitialize = false;
  33. [SerializeField]
  34. private string m_tempTopInspectorName = string.Empty;
  35. [SerializeField]
  36. private string m_tempTopName = string.Empty;
  37. private TexturePropertyValues m_tempTopDefaultValue = TexturePropertyValues.white;
  38. private int m_tempTopOrderIndex = -1;
  39. private Texture2D m_tempTopDefaultTexture = null;
  40. private string m_tempMidInspectorName = string.Empty;
  41. private string m_tempMidName = string.Empty;
  42. private TexturePropertyValues m_tempMidDefaultValue = TexturePropertyValues.white;
  43. private int m_tempMidOrderIndex = -1;
  44. private Texture2D m_tempMidDefaultTexture = null;
  45. private string m_tempBotInspectorName = string.Empty;
  46. private string m_tempBotName = string.Empty;
  47. private TexturePropertyValues m_tempBotDefaultValue = TexturePropertyValues.white;
  48. private int m_tempBotOrderIndex = -1;
  49. private Texture2D m_tempBotDefaultTexture = null;
  50. private bool m_topTextureFoldout = true;
  51. private bool m_midTextureFoldout = true;
  52. private bool m_botTextureFoldout = true;
  53. private InputPort m_topTexPort;
  54. private InputPort m_midTexPort;
  55. private InputPort m_botTexPort;
  56. private InputPort m_tilingPort;
  57. private InputPort m_falloffPort;
  58. private InputPort m_topIndexPort;
  59. private InputPort m_midIndexPort;
  60. private InputPort m_botIndexPort;
  61. private InputPort m_scalePort;
  62. private InputPort m_posPort;
  63. private readonly string m_functionCall = "TriplanarSampling{0}( {1} )";
  64. private readonly string m_functionHeader = "inline {0} TriplanarSampling{1}( {2}float3 worldPos, float3 worldNormal, float falloff, float2 tiling, float3 normalScale, float3 index )";
  65. private readonly List<string> m_functionSamplingBodyProj = new List<string>() {
  66. "float3 projNormal = ( pow( abs( worldNormal ), falloff ) );",
  67. "projNormal /= ( projNormal.x + projNormal.y + projNormal.z ) + 0.00001;",// 0.00001 is to prevent division by 0
  68. "float3 nsign = sign( worldNormal );"
  69. };
  70. private readonly List<string> m_functionSamplingBodyNegProj = new List<string>() {
  71. "float negProjNormalY = max( 0, projNormal.y * -nsign.y );",
  72. "projNormal.y = max( 0, projNormal.y * nsign.y );"
  73. };
  74. private readonly List<string> m_functionSamplingBodySignsSphere = new List<string>() {
  75. "xNorm.xyz = half3( {0}( xNorm{1} ).xy * float2( nsign.x, 1.0 ) + worldNormal.zy, worldNormal.x ).zyx;",
  76. "yNorm.xyz = half3( {0}( yNorm{1} ).xy * float2( nsign.y, 1.0 ) + worldNormal.xz, worldNormal.y ).xzy;",
  77. "zNorm.xyz = half3( {0}( zNorm{1} ).xy * float2( -nsign.z, 1.0 ) + worldNormal.xy, worldNormal.z ).xyz;"
  78. };
  79. private readonly List<string> m_functionSamplingBodySignsSphereScale = new List<string>() {
  80. "xNorm.xyz = half3( {0}( xNorm, normalScale.y ).xy * float2( nsign.x, 1.0 ) + worldNormal.zy, worldNormal.x ).zyx;",
  81. "yNorm.xyz = half3( {0}( yNorm, normalScale.x ).xy * float2( nsign.y, 1.0 ) + worldNormal.xz, worldNormal.y ).xzy;",
  82. "zNorm.xyz = half3( {0}( zNorm, normalScale.y ).xy * float2( -nsign.z, 1.0 ) + worldNormal.xy, worldNormal.z ).xyz;"
  83. };
  84. private readonly List<string> m_functionSamplingBodySignsCylinder = new List<string>() {
  85. "yNormN.xyz = half3( {0}( yNormN {1}).xy * float2( nsign.y, 1.0 ) + worldNormal.xz, worldNormal.y ).xzy;"
  86. };
  87. private readonly List<string> m_functionSamplingBodySignsCylinderScale = new List<string>() {
  88. "yNormN.xyz = half3( {0}( yNormN, normalScale.z ).xy * float2( nsign.y, 1.0 ) + worldNormal.xz, worldNormal.y ).xzy;"
  89. };
  90. private readonly List<string> m_functionSamplingBodyReturnSphereNormalize = new List<string>() {
  91. "return normalize( xNorm.xyz * projNormal.x + yNorm.xyz * projNormal.y + zNorm.xyz * projNormal.z );"
  92. };
  93. private readonly List<string> m_functionSamplingBodyReturnCylinderNormalize = new List<string>() {
  94. "return normalize( xNorm.xyz * projNormal.x + yNorm.xyz * projNormal.y + yNormN.xyz * negProjNormalY + zNorm.xyz * projNormal.z );"
  95. };
  96. private readonly List<string> m_functionSamplingBodyReturnSphere = new List<string>() {
  97. "return xNorm * projNormal.x + yNorm * projNormal.y + zNorm * projNormal.z;"
  98. };
  99. private readonly List<string> m_functionSamplingBodyReturnCylinder = new List<string>() {
  100. "return xNorm * projNormal.x + yNorm * projNormal.y + yNormN * negProjNormalY + zNorm * projNormal.z;"
  101. };
  102. private Rect m_allPicker;
  103. private Rect m_startPicker;
  104. private Rect m_pickerButton;
  105. private bool m_editing;
  106. void ConvertListTo( MasterNodeDataCollector dataCollector, bool scaleInfo, List<string> original, List<string> dest )
  107. {
  108. int count = original.Count;
  109. string scale = string.Empty;
  110. string func = string.Empty;
  111. bool applyScale = false;
  112. if( dataCollector.IsTemplate && dataCollector.IsSRP )
  113. {
  114. if( dataCollector.TemplateDataCollectorInstance.IsHDRP )
  115. {
  116. func = "UnpackNormalmapRGorAG";
  117. }
  118. else
  119. {
  120. func = "UnpackNormalScale";
  121. }
  122. if( !scaleInfo )
  123. {
  124. scale = " , 1.0";
  125. applyScale = true;
  126. }
  127. }
  128. else
  129. {
  130. func = scaleInfo ? "UnpackScaleNormal" : "UnpackNormal";
  131. applyScale = !scaleInfo;
  132. }
  133. for( int i = 0; i < count; i++ )
  134. {
  135. if( applyScale )
  136. dest.Add( string.Format( original[ i ], func, scale ) );
  137. else
  138. dest.Add( string.Format( original[ i ], func ) );
  139. }
  140. }
  141. protected override void CommonInit( int uniqueId )
  142. {
  143. base.CommonInit( uniqueId );
  144. AddInputPort( WirePortDataType.SAMPLER2D, false, "Top", -1, MasterNodePortCategory.Fragment, 0 );
  145. m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.SAMPLER2D, WirePortDataType.SAMPLER2DARRAY );
  146. AddInputPort( WirePortDataType.FLOAT, false, "Top Index", -1, MasterNodePortCategory.Fragment, 5 );
  147. AddInputPort( WirePortDataType.SAMPLER2D, false, "Middle", -1, MasterNodePortCategory.Fragment, 1 );
  148. m_inputPorts[ 2 ].CreatePortRestrictions( WirePortDataType.SAMPLER2D, WirePortDataType.SAMPLER2DARRAY );
  149. AddInputPort( WirePortDataType.FLOAT, false, "Mid Index", -1, MasterNodePortCategory.Fragment, 6 );
  150. AddInputPort( WirePortDataType.SAMPLER2D, false, "Bottom", -1, MasterNodePortCategory.Fragment, 2 );
  151. m_inputPorts[ 4 ].CreatePortRestrictions( WirePortDataType.SAMPLER2D, WirePortDataType.SAMPLER2DARRAY );
  152. AddInputPort( WirePortDataType.FLOAT, false, "Bot Index", -1, MasterNodePortCategory.Fragment, 7 );
  153. AddInputPort( WirePortDataType.FLOAT3, false, "Pos", -1, MasterNodePortCategory.Fragment, 9 );
  154. AddInputPort( WirePortDataType.FLOAT3, false, "Scale", -1, MasterNodePortCategory.Fragment, 8 );
  155. AddInputPort( WirePortDataType.FLOAT2, false, "Tiling", -1, MasterNodePortCategory.Fragment, 3 );
  156. AddInputPort( WirePortDataType.FLOAT, false, "Falloff", -1, MasterNodePortCategory.Fragment, 4 );
  157. AddOutputColorPorts( "RGBA" );
  158. m_useInternalPortData = true;
  159. m_topTexPort = InputPorts[ 0 ];
  160. m_topIndexPort = InputPorts[ 1 ];
  161. m_midTexPort = InputPorts[ 2 ];
  162. m_midIndexPort = InputPorts[ 3 ];
  163. m_botTexPort = InputPorts[ 4 ];
  164. m_botIndexPort = InputPorts[ 5 ];
  165. m_posPort = InputPorts[ 6 ];
  166. m_scalePort = InputPorts[ 7 ];
  167. m_tilingPort = InputPorts[ 8 ];
  168. m_falloffPort = InputPorts[ 9 ];
  169. m_scalePort.Visible = false;
  170. m_scalePort.Vector3InternalData = Vector3.one;
  171. m_tilingPort.FloatInternalData = 1;
  172. m_tilingPort.Vector2InternalData = Vector2.one;
  173. m_topIndexPort.FloatInternalData = 1;
  174. m_falloffPort.FloatInternalData = 1;
  175. m_topIndexPort.Visible = false;
  176. m_selectedLocation = PreviewLocation.TopCenter;
  177. m_marginPreviewLeft = 43;
  178. m_drawPreviewAsSphere = true;
  179. m_drawPreviewExpander = false;
  180. m_drawPreview = true;
  181. m_showPreview = true;
  182. m_autoDrawInternalPortData = false;
  183. m_textLabelWidth = 125;
  184. //m_propertyInspectorName = "Triplanar Sampler";
  185. m_previewShaderGUID = "8723015ec59743143aadfbe480e34391";
  186. }
  187. public void ReadPropertiesData()
  188. {
  189. // Top
  190. if( UIUtils.IsUniformNameAvailable( m_tempTopName ) )
  191. {
  192. UIUtils.ReleaseUniformName( UniqueId, m_topTexture.PropertyName );
  193. if( !string.IsNullOrEmpty( m_tempTopInspectorName ) )
  194. {
  195. m_topTexture.SetInspectorName( m_tempTopInspectorName );
  196. }
  197. if( !string.IsNullOrEmpty( m_tempTopName ) )
  198. m_topTexture.SetPropertyName( m_tempTopName );
  199. UIUtils.RegisterUniformName( UniqueId, m_topTexture.PropertyName );
  200. }
  201. m_topTexture.DefaultTextureValue = m_tempTopDefaultValue;
  202. m_topTexture.OrderIndex = m_tempTopOrderIndex;
  203. m_topTexture.DefaultValue = m_tempTopDefaultTexture;
  204. //m_topTexture.SetMaterialMode( UIUtils.CurrentWindow.CurrentGraph.CurrentMaterial, true );
  205. // Mid
  206. if( UIUtils.IsUniformNameAvailable( m_tempMidName ) )
  207. {
  208. UIUtils.ReleaseUniformName( UniqueId, m_midTexture.PropertyName );
  209. if( !string.IsNullOrEmpty( m_tempMidInspectorName ) )
  210. m_midTexture.SetInspectorName( m_tempMidInspectorName );
  211. if( !string.IsNullOrEmpty( m_tempMidName ) )
  212. m_midTexture.SetPropertyName( m_tempMidName );
  213. UIUtils.RegisterUniformName( UniqueId, m_midTexture.PropertyName );
  214. }
  215. m_midTexture.DefaultTextureValue = m_tempMidDefaultValue;
  216. m_midTexture.OrderIndex = m_tempMidOrderIndex;
  217. m_midTexture.DefaultValue = m_tempMidDefaultTexture;
  218. // Bot
  219. if( UIUtils.IsUniformNameAvailable( m_tempBotName ) )
  220. {
  221. UIUtils.ReleaseUniformName( UniqueId, m_botTexture.PropertyName );
  222. if( !string.IsNullOrEmpty( m_tempBotInspectorName ) )
  223. m_botTexture.SetInspectorName( m_tempBotInspectorName );
  224. if( !string.IsNullOrEmpty( m_tempBotName ) )
  225. m_botTexture.SetPropertyName( m_tempBotName );
  226. UIUtils.RegisterUniformName( UniqueId, m_botTexture.PropertyName );
  227. }
  228. m_botTexture.DefaultTextureValue = m_tempBotDefaultValue;
  229. m_botTexture.OrderIndex = m_tempBotOrderIndex;
  230. m_botTexture.DefaultValue = m_tempBotDefaultTexture;
  231. }
  232. public override void SetMaterialMode( Material mat, bool fetchMaterialValues )
  233. {
  234. base.SetMaterialMode( mat, fetchMaterialValues );
  235. if( !m_texturesInitialize )
  236. return;
  237. m_topTexture.SetMaterialMode( mat, fetchMaterialValues );
  238. m_midTexture.SetMaterialMode( mat, fetchMaterialValues );
  239. m_botTexture.SetMaterialMode( mat, fetchMaterialValues );
  240. }
  241. public void Init()
  242. {
  243. if( m_texturesInitialize )
  244. return;
  245. else
  246. m_texturesInitialize = true;
  247. // Top
  248. if( m_topTexture == null )
  249. {
  250. m_topTexture = ScriptableObject.CreateInstance<TexturePropertyNode>();
  251. }
  252. m_topTexture.ContainerGraph = ContainerGraph;
  253. m_topTexture.CustomPrefix = "Top Texture ";
  254. m_topTexture.UniqueId = UniqueId;
  255. m_topTexture.DrawAutocast = false;
  256. m_topTexture.CurrentParameterType = PropertyType.Property;
  257. // Mid
  258. if( m_midTexture == null )
  259. {
  260. m_midTexture = ScriptableObject.CreateInstance<TexturePropertyNode>();
  261. }
  262. m_midTexture.ContainerGraph = ContainerGraph;
  263. m_midTexture.CustomPrefix = "Mid Texture ";
  264. m_midTexture.UniqueId = UniqueId;
  265. m_midTexture.DrawAutocast = false;
  266. m_midTexture.CurrentParameterType = PropertyType.Property;
  267. // Bot
  268. if( m_botTexture == null )
  269. {
  270. m_botTexture = ScriptableObject.CreateInstance<TexturePropertyNode>();
  271. }
  272. m_botTexture.ContainerGraph = ContainerGraph;
  273. m_botTexture.CustomPrefix = "Bot Texture ";
  274. m_botTexture.UniqueId = UniqueId;
  275. m_botTexture.DrawAutocast = false;
  276. m_botTexture.CurrentParameterType = PropertyType.Property;
  277. if( m_materialMode )
  278. SetDelayedMaterialMode( ContainerGraph.CurrentMaterial );
  279. if( m_nodeAttribs != null )
  280. m_uniqueName = m_nodeAttribs.Name + UniqueId;
  281. ConfigurePorts();
  282. ReRegisterPorts();
  283. }
  284. public override void Destroy()
  285. {
  286. base.Destroy();
  287. //UIUtils.UnregisterPropertyNode( m_topTexture );
  288. //UIUtils.UnregisterTexturePropertyNode( m_topTexture );
  289. //UIUtils.UnregisterPropertyNode( m_midTexture );
  290. //UIUtils.UnregisterTexturePropertyNode( m_midTexture );
  291. //UIUtils.UnregisterPropertyNode( m_botTexture );
  292. //UIUtils.UnregisterTexturePropertyNode( m_botTexture );
  293. if( m_topTexture != null )
  294. m_topTexture.Destroy();
  295. m_topTexture = null;
  296. if( m_midTexture != null )
  297. m_midTexture.Destroy();
  298. m_midTexture = null;
  299. if( m_botTexture != null )
  300. m_botTexture.Destroy();
  301. m_botTexture = null;
  302. m_tempTopDefaultTexture = null;
  303. m_tempMidDefaultTexture = null;
  304. m_tempBotDefaultTexture = null;
  305. m_topTexPort = null;
  306. m_midTexPort = null;
  307. m_botTexPort = null;
  308. m_tilingPort = null;
  309. m_falloffPort = null;
  310. m_topIndexPort = null;
  311. m_midIndexPort = null;
  312. m_botIndexPort = null;
  313. }
  314. public override void SetPreviewInputs()
  315. {
  316. base.SetPreviewInputs();
  317. if( m_topTexture == null )
  318. return;
  319. if( m_topTexPort.IsConnected )
  320. {
  321. PreviewMaterial.SetTexture( "_A", m_topTexPort.InputPreviewTexture( ContainerGraph ) );
  322. }
  323. else
  324. {
  325. PreviewMaterial.SetTexture( "_A", m_topTexture.Value );
  326. }
  327. if( m_selectedTriplanarType == TriplanarType.Cylindrical && m_midTexture != null )
  328. {
  329. if( m_midTexPort.IsConnected )
  330. PreviewMaterial.SetTexture( "_B", m_midTexPort.InputPreviewTexture( ContainerGraph ) );
  331. else
  332. PreviewMaterial.SetTexture( "_B", m_midTexture.Value );
  333. if( m_botTexPort.IsConnected )
  334. PreviewMaterial.SetTexture( "_C", m_botTexPort.InputPreviewTexture( ContainerGraph ) );
  335. else
  336. PreviewMaterial.SetTexture( "_C", m_botTexture.Value );
  337. }
  338. PreviewMaterial.SetFloat( "_IsNormal", ( m_normalCorrection ? 1 : 0 ) );
  339. PreviewMaterial.SetFloat( "_IsTangent", ( m_normalSpace == ViewSpace.Tangent ? 1 : 0 ) );
  340. PreviewMaterial.SetFloat( "_IsSpherical", ( m_selectedTriplanarType == TriplanarType.Spherical ? 1 : 0 ) );
  341. }
  342. public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
  343. {
  344. base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
  345. if( portId == 0 )
  346. m_topTexPort.MatchPortToConnection();
  347. if( portId == 1 )
  348. m_midTexPort.MatchPortToConnection();
  349. if( portId == 2 )
  350. m_botTexPort.MatchPortToConnection();
  351. if( m_texturesInitialize )
  352. ReRegisterPorts();
  353. ConfigurePorts();
  354. }
  355. public override void OnInputPortDisconnected( int portId )
  356. {
  357. base.OnInputPortDisconnected( portId );
  358. if( m_texturesInitialize )
  359. ReRegisterPorts();
  360. }
  361. public override void OnConnectedOutputNodeChanges( int portId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
  362. {
  363. base.OnConnectedOutputNodeChanges( portId, otherNodeId, otherPortId, name, type );
  364. if( portId == 0 )
  365. {
  366. if( !m_topTexPort.CheckValidType( type ) )
  367. {
  368. m_topTexPort.FullDeleteConnections();
  369. UIUtils.ShowMessage( UniqueId, "Triplanar Sampler node only accepts SAMPLER2D and SAMPLER2DARRAY input types.\nTexture Object connected changed to " + type + ", connection was lost, please review and update accordingly.", MessageSeverity.Warning );
  370. }
  371. else
  372. {
  373. m_topTexPort.MatchPortToConnection();
  374. }
  375. }
  376. if( portId == 1 )
  377. {
  378. if( !m_midTexPort.CheckValidType( type ) )
  379. {
  380. m_midTexPort.FullDeleteConnections();
  381. UIUtils.ShowMessage( UniqueId, "Triplanar Sampler node only accepts SAMPLER2D and SAMPLER2DARRAY input types.\nTexture Object connected changed to " + type + ", connection was lost, please review and update accordingly.", MessageSeverity.Warning );
  382. }
  383. else
  384. {
  385. m_midTexPort.MatchPortToConnection();
  386. }
  387. }
  388. if( portId == 2 )
  389. {
  390. if( !m_botTexPort.CheckValidType( type ) )
  391. {
  392. m_botTexPort.FullDeleteConnections();
  393. UIUtils.ShowMessage( UniqueId, "Triplanar Sampler node only accepts SAMPLER2D and SAMPLER2DARRAY input types.\nTexture Object connected changed to " + type + ", connection was lost, please review and update accordingly.", MessageSeverity.Warning );
  394. }
  395. else
  396. {
  397. m_botTexPort.MatchPortToConnection();
  398. }
  399. }
  400. if( m_texturesInitialize )
  401. ReRegisterPorts();
  402. ConfigurePorts();
  403. }
  404. public void ReRegisterPorts()
  405. {
  406. if( m_topTexPort.IsConnected )
  407. {
  408. UIUtils.UnregisterPropertyNode( m_topTexture );
  409. UIUtils.UnregisterTexturePropertyNode( m_topTexture );
  410. }
  411. else if( m_topTexPort.Visible )
  412. {
  413. UIUtils.RegisterPropertyNode( m_topTexture );
  414. UIUtils.RegisterTexturePropertyNode( m_topTexture );
  415. }
  416. if( m_midTexPort.IsConnected || m_selectedTriplanarType == TriplanarType.Spherical )
  417. {
  418. UIUtils.UnregisterPropertyNode( m_midTexture );
  419. UIUtils.UnregisterTexturePropertyNode( m_midTexture );
  420. }
  421. else if( m_midTexPort.Visible && m_selectedTriplanarType == TriplanarType.Cylindrical )
  422. {
  423. UIUtils.RegisterPropertyNode( m_midTexture );
  424. UIUtils.RegisterTexturePropertyNode( m_midTexture );
  425. }
  426. if( m_botTexPort.IsConnected || m_selectedTriplanarType == TriplanarType.Spherical )
  427. {
  428. UIUtils.UnregisterPropertyNode( m_botTexture );
  429. UIUtils.UnregisterTexturePropertyNode( m_botTexture );
  430. }
  431. else if( m_botTexPort.Visible && m_selectedTriplanarType == TriplanarType.Cylindrical )
  432. {
  433. UIUtils.RegisterPropertyNode( m_botTexture );
  434. UIUtils.RegisterTexturePropertyNode( m_botTexture );
  435. }
  436. }
  437. public void ConfigurePorts()
  438. {
  439. switch( m_selectedTriplanarType )
  440. {
  441. case TriplanarType.Spherical:
  442. m_topTexPort.Name = "Tex";
  443. m_midTexPort.Visible = false;
  444. m_botTexPort.Visible = false;
  445. m_scalePort.ChangeType( WirePortDataType.FLOAT, false );
  446. break;
  447. case TriplanarType.Cylindrical:
  448. m_topTexPort.Name = "Top";
  449. m_midTexPort.Visible = true;
  450. m_botTexPort.Visible = true;
  451. m_scalePort.ChangeType( WirePortDataType.FLOAT3, false );
  452. break;
  453. }
  454. if( m_normalCorrection )
  455. {
  456. m_outputPorts[ 0 ].ChangeProperties( "XYZ", WirePortDataType.FLOAT3, false );
  457. m_outputPorts[ 1 ].ChangeProperties( "X", WirePortDataType.FLOAT, false );
  458. m_outputPorts[ 2 ].ChangeProperties( "Y", WirePortDataType.FLOAT, false );
  459. m_outputPorts[ 3 ].ChangeProperties( "Z", WirePortDataType.FLOAT, false );
  460. m_outputPorts[ 4 ].Visible = false;
  461. m_scalePort.Visible = true;
  462. }
  463. else
  464. {
  465. m_outputPorts[ 0 ].ChangeProperties( "RGBA", WirePortDataType.FLOAT4, false );
  466. m_outputPorts[ 1 ].ChangeProperties( "R", WirePortDataType.FLOAT, false );
  467. m_outputPorts[ 2 ].ChangeProperties( "G", WirePortDataType.FLOAT, false );
  468. m_outputPorts[ 3 ].ChangeProperties( "B", WirePortDataType.FLOAT, false );
  469. m_outputPorts[ 4 ].ChangeProperties( "A", WirePortDataType.FLOAT, false );
  470. m_outputPorts[ 4 ].Visible = true;
  471. m_scalePort.Visible = false;
  472. }
  473. if( m_topTexPort.DataType == WirePortDataType.SAMPLER2DARRAY )
  474. m_topIndexPort.Visible = true;
  475. else
  476. m_topIndexPort.Visible = false;
  477. if( m_midTexPort.DataType == WirePortDataType.SAMPLER2DARRAY && m_selectedTriplanarType == TriplanarType.Cylindrical )
  478. m_midIndexPort.Visible = true;
  479. else
  480. m_midIndexPort.Visible = false;
  481. if( m_botTexPort.DataType == WirePortDataType.SAMPLER2DARRAY && m_selectedTriplanarType == TriplanarType.Cylindrical )
  482. m_botIndexPort.Visible = true;
  483. else
  484. m_botIndexPort.Visible = false;
  485. if( m_selectedTriplanarSpace == TriplanarSpace.World )
  486. m_posPort.Name = "World Pos";
  487. else
  488. m_posPort.Name = "Local Pos";
  489. m_outputPorts[ 0 ].DirtyLabelSize = true;
  490. m_sizeIsDirty = true;
  491. }
  492. public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
  493. {
  494. base.PropagateNodeData( nodeData, ref dataCollector );
  495. dataCollector.DirtyNormal = true;
  496. }
  497. public override void DrawProperties()
  498. {
  499. base.DrawProperties();
  500. NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, "Parameters", DrawMainOptions );
  501. DrawInternalDataGroup();
  502. if( m_selectedTriplanarType == TriplanarType.Spherical && !m_topTexPort.IsConnected )
  503. NodeUtils.DrawPropertyGroup( ref m_topTextureFoldout, "Texture", DrawTopTextureOptions );
  504. else if( !m_topTexPort.IsConnected )
  505. NodeUtils.DrawPropertyGroup( ref m_topTextureFoldout, "Top Texture", DrawTopTextureOptions );
  506. if( m_selectedTriplanarType == TriplanarType.Cylindrical )
  507. {
  508. if( !m_midTexPort.IsConnected )
  509. NodeUtils.DrawPropertyGroup( ref m_midTextureFoldout, "Middle Texture", DrawMidTextureOptions );
  510. if( !m_botTexPort.IsConnected )
  511. NodeUtils.DrawPropertyGroup( ref m_botTextureFoldout, "Bottom Texture", DrawBotTextureOptions );
  512. }
  513. }
  514. void DrawMainOptions()
  515. {
  516. EditorGUI.BeginChangeCheck();
  517. m_propertyInspectorName = EditorGUILayoutTextField( "Name", m_propertyInspectorName );
  518. m_selectedTriplanarType = (TriplanarType)EditorGUILayoutEnumPopup( "Mapping", m_selectedTriplanarType );
  519. m_selectedTriplanarSpace = (TriplanarSpace)EditorGUILayoutEnumPopup( "Space", m_selectedTriplanarSpace );
  520. m_normalCorrection = EditorGUILayoutToggle( "Normal Map", m_normalCorrection );
  521. if( m_normalCorrection )
  522. m_normalSpace = (ViewSpace)EditorGUILayoutEnumPopup( "Output Normal Space", m_normalSpace );
  523. if( EditorGUI.EndChangeCheck() )
  524. {
  525. SetTitleText( m_propertyInspectorName );
  526. ConfigurePorts();
  527. ReRegisterPorts();
  528. }
  529. }
  530. void DrawTopTextureOptions()
  531. {
  532. EditorGUI.BeginChangeCheck();
  533. m_topTexture.ShowPropertyInspectorNameGUI();
  534. m_topTexture.ShowPropertyNameGUI( true );
  535. m_topTexture.ShowToolbar();
  536. if( EditorGUI.EndChangeCheck() )
  537. {
  538. m_topTexture.BeginPropertyFromInspectorCheck();
  539. if( m_materialMode )
  540. m_requireMaterialUpdate = true;
  541. }
  542. m_topTexture.CheckPropertyFromInspector();
  543. }
  544. void DrawMidTextureOptions()
  545. {
  546. if( m_midTexture == null )
  547. return;
  548. EditorGUI.BeginChangeCheck();
  549. m_midTexture.ShowPropertyInspectorNameGUI();
  550. m_midTexture.ShowPropertyNameGUI( true );
  551. m_midTexture.ShowToolbar();
  552. if( EditorGUI.EndChangeCheck() )
  553. {
  554. m_midTexture.BeginPropertyFromInspectorCheck();
  555. if( m_materialMode )
  556. m_requireMaterialUpdate = true;
  557. }
  558. m_midTexture.CheckPropertyFromInspector();
  559. }
  560. void DrawBotTextureOptions()
  561. {
  562. if( m_botTexture == null )
  563. return;
  564. EditorGUI.BeginChangeCheck();
  565. m_botTexture.ShowPropertyInspectorNameGUI();
  566. m_botTexture.ShowPropertyNameGUI( true );
  567. m_botTexture.ShowToolbar();
  568. if( EditorGUI.EndChangeCheck() )
  569. {
  570. m_botTexture.BeginPropertyFromInspectorCheck();
  571. if( m_materialMode )
  572. m_requireMaterialUpdate = true;
  573. }
  574. m_botTexture.CheckPropertyFromInspector();
  575. }
  576. public override void OnEnable()
  577. {
  578. base.OnEnable();
  579. //if( !m_afterDeserialize )
  580. //Init(); //Generate texture properties
  581. //else
  582. //m_afterDeserialize = false;
  583. //if( m_topTexture != null )
  584. // m_topTexture.ReRegisterName = true;
  585. //if( m_selectedTriplanarType == TriplanarType.Cylindrical )
  586. //{
  587. // if( m_midTexture != null )
  588. // m_midTexture.ReRegisterName = true;
  589. // if( m_botTexture != null )
  590. // m_botTexture.ReRegisterName = true;
  591. //}
  592. }
  593. //bool m_afterDeserialize = false;
  594. //public override void OnAfterDeserialize()
  595. //{
  596. // base.OnAfterDeserialize();
  597. // m_afterDeserialize = true;
  598. //}
  599. public override void OnNodeLogicUpdate( DrawInfo drawInfo )
  600. {
  601. base.OnNodeLogicUpdate( drawInfo );
  602. Init();
  603. if( m_topTexture.ReRegisterName )
  604. {
  605. m_topTexture.ReRegisterName = false;
  606. UIUtils.RegisterUniformName( UniqueId, m_topTexture.PropertyName );
  607. }
  608. m_topTexture.CheckDelayedDirtyProperty();
  609. m_topTexture.CheckPropertyFromInspector();
  610. m_topTexture.CheckDuplicateProperty();
  611. if( m_selectedTriplanarType == TriplanarType.Cylindrical )
  612. {
  613. if( m_midTexture.ReRegisterName )
  614. {
  615. m_midTexture.ReRegisterName = false;
  616. UIUtils.RegisterUniformName( UniqueId, m_midTexture.PropertyName );
  617. }
  618. m_midTexture.CheckDelayedDirtyProperty();
  619. m_midTexture.CheckPropertyFromInspector();
  620. m_midTexture.CheckDuplicateProperty();
  621. if( m_botTexture.ReRegisterName )
  622. {
  623. m_botTexture.ReRegisterName = false;
  624. UIUtils.RegisterUniformName( UniqueId, m_botTexture.PropertyName );
  625. }
  626. m_botTexture.CheckDelayedDirtyProperty();
  627. m_botTexture.CheckPropertyFromInspector();
  628. m_botTexture.CheckDuplicateProperty();
  629. }
  630. }
  631. public override void OnNodeLayout( DrawInfo drawInfo )
  632. {
  633. base.OnNodeLayout( drawInfo );
  634. m_allPicker = m_previewRect;
  635. m_allPicker.x -= 43 * drawInfo.InvertedZoom;
  636. m_allPicker.width = 43 * drawInfo.InvertedZoom;
  637. m_startPicker = m_previewRect;
  638. m_startPicker.x -= 43 * drawInfo.InvertedZoom;
  639. m_startPicker.width = 43 * drawInfo.InvertedZoom;
  640. m_startPicker.height = 43 * drawInfo.InvertedZoom;
  641. m_pickerButton = m_startPicker;
  642. m_pickerButton.width = 30 * drawInfo.InvertedZoom;
  643. m_pickerButton.x = m_startPicker.xMax - m_pickerButton.width - 2;
  644. m_pickerButton.height = 10 * drawInfo.InvertedZoom;
  645. m_pickerButton.y = m_startPicker.yMax - m_pickerButton.height - 2;
  646. }
  647. public override void DrawGUIControls( DrawInfo drawInfo )
  648. {
  649. base.DrawGUIControls( drawInfo );
  650. if( !( drawInfo.CurrentEventType == EventType.MouseDown || drawInfo.CurrentEventType == EventType.MouseUp || drawInfo.CurrentEventType == EventType.ExecuteCommand || drawInfo.CurrentEventType == EventType.DragPerform ) )
  651. return;
  652. bool insideBox = m_allPicker.Contains( drawInfo.MousePosition );
  653. if( insideBox )
  654. {
  655. m_editing = true;
  656. }
  657. else if( m_editing && !insideBox && drawInfo.CurrentEventType != EventType.ExecuteCommand )
  658. {
  659. GUI.FocusControl( null );
  660. m_editing = false;
  661. }
  662. }
  663. private int m_pickId = 0;
  664. public override void Draw( DrawInfo drawInfo )
  665. {
  666. base.Draw( drawInfo );
  667. Rect pickerButtonClone = m_pickerButton;
  668. Rect startPickerClone = m_startPicker;
  669. if( m_editing )
  670. {
  671. if( GUI.Button( pickerButtonClone, string.Empty, GUIStyle.none ) )
  672. {
  673. int controlID = EditorGUIUtility.GetControlID( FocusType.Passive );
  674. EditorGUIUtility.ShowObjectPicker<Texture2D>( m_topTexture.Value, false, "", controlID );
  675. m_pickId = 0;
  676. }
  677. if( m_selectedTriplanarType == TriplanarType.Cylindrical )
  678. {
  679. pickerButtonClone.y += startPickerClone.height;
  680. if( GUI.Button( pickerButtonClone, string.Empty, GUIStyle.none ) )
  681. {
  682. int controlID = EditorGUIUtility.GetControlID( FocusType.Passive );
  683. EditorGUIUtility.ShowObjectPicker<Texture2D>( m_midTexture.Value, false, "", controlID );
  684. m_pickId = 1;
  685. }
  686. pickerButtonClone.y += startPickerClone.height;
  687. if( GUI.Button( pickerButtonClone, string.Empty, GUIStyle.none ) )
  688. {
  689. int controlID = EditorGUIUtility.GetControlID( FocusType.Passive );
  690. EditorGUIUtility.ShowObjectPicker<Texture2D>( m_botTexture.Value, false, "", controlID );
  691. m_pickId = 2;
  692. }
  693. }
  694. string commandName = Event.current.commandName;
  695. UnityEngine.Object newValue = null;
  696. if( commandName.Equals( "ObjectSelectorUpdated" ) || commandName.Equals( "ObjectSelectorClosed" ) )
  697. {
  698. newValue = EditorGUIUtility.GetObjectPickerObject();
  699. if( m_pickId == 2 )
  700. {
  701. if( newValue != (UnityEngine.Object)m_botTexture.Value )
  702. {
  703. PreviewIsDirty = true;
  704. UndoRecordObject( "Changing value EditorGUIObjectField on node Triplanar Node" );
  705. m_botTexture.Value = newValue != null ? (Texture2D)newValue : null;
  706. if( m_materialMode )
  707. m_requireMaterialUpdate = true;
  708. }
  709. }
  710. else if( m_pickId == 1 )
  711. {
  712. if( newValue != (UnityEngine.Object)m_midTexture.Value )
  713. {
  714. PreviewIsDirty = true;
  715. UndoRecordObject( "Changing value EditorGUIObjectField on node Triplanar Node" );
  716. m_midTexture.Value = newValue != null ? (Texture2D)newValue : null;
  717. if( m_materialMode )
  718. m_requireMaterialUpdate = true;
  719. }
  720. }
  721. else
  722. {
  723. if( newValue != (UnityEngine.Object)m_topTexture.Value )
  724. {
  725. PreviewIsDirty = true;
  726. UndoRecordObject( "Changing value EditorGUIObjectField on node Triplanar Node" );
  727. m_topTexture.Value = newValue != null ? (Texture2D)newValue : null;
  728. if( m_materialMode )
  729. m_requireMaterialUpdate = true;
  730. }
  731. }
  732. if( commandName.Equals( "ObjectSelectorClosed" ) )
  733. m_editing = false;
  734. }
  735. if( GUI.Button( startPickerClone, string.Empty, GUIStyle.none ) )
  736. {
  737. if( m_topTexPort.IsConnected )
  738. {
  739. UIUtils.FocusOnNode( m_topTexPort.GetOutputNode( 0 ), 1, true );
  740. }
  741. else
  742. {
  743. if( m_topTexture.Value != null )
  744. {
  745. Selection.activeObject = m_topTexture.Value;
  746. EditorGUIUtility.PingObject( Selection.activeObject );
  747. }
  748. }
  749. m_editing = false;
  750. }
  751. if( m_selectedTriplanarType == TriplanarType.Cylindrical )
  752. {
  753. startPickerClone.y += startPickerClone.height;
  754. if( GUI.Button( startPickerClone, string.Empty, GUIStyle.none ) )
  755. {
  756. if( m_midTexPort.IsConnected )
  757. {
  758. UIUtils.FocusOnNode( m_midTexPort.GetOutputNode( 0 ), 1, true );
  759. }
  760. else
  761. {
  762. if( m_midTexture.Value != null )
  763. {
  764. Selection.activeObject = m_midTexture.Value;
  765. EditorGUIUtility.PingObject( Selection.activeObject );
  766. }
  767. }
  768. m_editing = false;
  769. }
  770. startPickerClone.y += startPickerClone.height;
  771. if( GUI.Button( startPickerClone, string.Empty, GUIStyle.none ) )
  772. {
  773. if( m_botTexPort.IsConnected )
  774. {
  775. UIUtils.FocusOnNode( m_botTexPort.GetOutputNode( 0 ), 1, true );
  776. }
  777. else
  778. {
  779. if( m_botTexture.Value != null )
  780. {
  781. Selection.activeObject = m_botTexture.Value;
  782. EditorGUIUtility.PingObject( Selection.activeObject );
  783. }
  784. }
  785. m_editing = false;
  786. }
  787. }
  788. }
  789. pickerButtonClone = m_pickerButton;
  790. startPickerClone = m_startPicker;
  791. if( drawInfo.CurrentEventType == EventType.Repaint )
  792. {
  793. // Top
  794. if( m_topTexPort.IsConnected )
  795. {
  796. EditorGUI.DrawPreviewTexture( startPickerClone, m_topTexPort.GetOutputConnection( 0 ).OutputPreviewTexture, null, ScaleMode.ScaleAndCrop );
  797. }
  798. else if( m_topTexture.Value != null )
  799. {
  800. EditorGUI.DrawPreviewTexture( startPickerClone, m_topTexture.Value, null, ScaleMode.ScaleAndCrop );
  801. if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
  802. GUI.Label( pickerButtonClone, "Select", UIUtils.MiniSamplerButton );
  803. }
  804. else
  805. {
  806. GUI.Label( startPickerClone, string.Empty, UIUtils.ObjectFieldThumb );
  807. if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
  808. {
  809. GUI.Label( startPickerClone, "None (Texture2D)", UIUtils.MiniObjectFieldThumbOverlay );
  810. GUI.Label( pickerButtonClone, "Select", UIUtils.MiniSamplerButton );
  811. }
  812. }
  813. GUI.Label( startPickerClone, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) );
  814. if( m_selectedTriplanarType == TriplanarType.Cylindrical )
  815. {
  816. // Mid
  817. startPickerClone.y += startPickerClone.height;
  818. pickerButtonClone.y += startPickerClone.height;
  819. if( m_midTexPort.IsConnected )
  820. {
  821. EditorGUI.DrawPreviewTexture( startPickerClone, m_midTexPort.GetOutputConnection( 0 ).OutputPreviewTexture, null, ScaleMode.ScaleAndCrop );
  822. }
  823. else if( m_midTexture.Value != null )
  824. {
  825. EditorGUI.DrawPreviewTexture( startPickerClone, m_midTexture.Value, null, ScaleMode.ScaleAndCrop );
  826. if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
  827. GUI.Label( pickerButtonClone, "Select", UIUtils.MiniSamplerButton );
  828. }
  829. else
  830. {
  831. GUI.Label( startPickerClone, string.Empty, UIUtils.ObjectFieldThumb );
  832. if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
  833. {
  834. GUI.Label( startPickerClone, "None (Texture2D)", UIUtils.MiniObjectFieldThumbOverlay );
  835. GUI.Label( pickerButtonClone, "Select", UIUtils.MiniSamplerButton );
  836. }
  837. }
  838. GUI.Label( startPickerClone, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) );
  839. // Bot
  840. startPickerClone.y += startPickerClone.height;
  841. startPickerClone.height = 42 * drawInfo.InvertedZoom;
  842. pickerButtonClone.y += startPickerClone.height;
  843. if( m_botTexPort.IsConnected )
  844. {
  845. EditorGUI.DrawPreviewTexture( startPickerClone, m_botTexPort.GetOutputConnection( 0 ).OutputPreviewTexture, null, ScaleMode.ScaleAndCrop );
  846. }
  847. else if( m_botTexture.Value != null )
  848. {
  849. EditorGUI.DrawPreviewTexture( startPickerClone, m_botTexture.Value, null, ScaleMode.ScaleAndCrop );
  850. if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
  851. GUI.Label( pickerButtonClone, "Select", UIUtils.MiniSamplerButton );
  852. }
  853. else
  854. {
  855. GUI.Label( startPickerClone, string.Empty, UIUtils.ObjectFieldThumb );
  856. if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
  857. {
  858. GUI.Label( startPickerClone, "None (Texture2D)", UIUtils.MiniObjectFieldThumbOverlay );
  859. GUI.Label( pickerButtonClone, "Select", UIUtils.MiniSamplerButton );
  860. }
  861. }
  862. GUI.Label( startPickerClone, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) );
  863. }
  864. }
  865. }
  866. public override void OnNodeDoubleClicked( Vector2 currentMousePos2D )
  867. {
  868. if( currentMousePos2D.y - m_globalPosition.y > Constants.NODE_HEADER_HEIGHT + Constants.NODE_HEADER_EXTRA_HEIGHT )
  869. {
  870. ContainerGraph.ParentWindow.ParametersWindow.IsMaximized = !ContainerGraph.ParentWindow.ParametersWindow.IsMaximized;
  871. }
  872. else
  873. {
  874. m_editPropertyNameMode = true;
  875. GUI.FocusControl( m_uniqueName );
  876. TextEditor te = (TextEditor)GUIUtility.GetStateObject( typeof( TextEditor ), GUIUtility.keyboardControl );
  877. if( te != null )
  878. {
  879. te.SelectAll();
  880. }
  881. }
  882. }
  883. public override void OnNodeSelected( bool value )
  884. {
  885. base.OnNodeSelected( value );
  886. if( !value )
  887. m_editPropertyNameMode = false;
  888. }
  889. public override void DrawTitle( Rect titlePos )
  890. {
  891. if( m_editPropertyNameMode )
  892. {
  893. titlePos.height = Constants.NODE_HEADER_HEIGHT;
  894. EditorGUI.BeginChangeCheck();
  895. GUI.SetNextControlName( m_uniqueName );
  896. m_propertyInspectorName = GUITextField( titlePos, m_propertyInspectorName, UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) );
  897. if( EditorGUI.EndChangeCheck() )
  898. {
  899. SetTitleText( m_propertyInspectorName );
  900. }
  901. if( Event.current.isKey && ( Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter ) )
  902. {
  903. m_editPropertyNameMode = false;
  904. GUIUtility.keyboardControl = 0;
  905. }
  906. }
  907. else
  908. {
  909. base.DrawTitle( titlePos );
  910. }
  911. }
  912. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  913. {
  914. if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  915. return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
  916. ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph;
  917. dataCollector.AddPropertyNode( m_topTexture );
  918. dataCollector.AddPropertyNode( m_midTexture );
  919. dataCollector.AddPropertyNode( m_botTexture );
  920. bool isVertex = ( dataCollector.PortCategory == MasterNodePortCategory.Tessellation || dataCollector.PortCategory == MasterNodePortCategory.Vertex );
  921. string texTop = string.Empty;
  922. string texMid = string.Empty;
  923. string texBot = string.Empty;
  924. string ssTop = string.Empty;
  925. string ssMid = string.Empty;
  926. string ssBot = string.Empty;
  927. if( m_topTexPort.IsConnected )
  928. {
  929. texTop = m_topTexPort.GeneratePortInstructions( ref dataCollector );
  930. }
  931. else
  932. {
  933. dataCollector.AddToUniforms( UniqueId, m_topTexture.GetTexture2DUniformValue() );
  934. dataCollector.AddToProperties( UniqueId, m_topTexture.GetTexture2DPropertyValue(), m_topTexture.OrderIndex );
  935. texTop = m_topTexture.PropertyName;
  936. }
  937. if( m_selectedTriplanarType == TriplanarType.Spherical )
  938. {
  939. texMid = texTop;
  940. texBot = texTop;
  941. if( ( outsideGraph.SamplingMacros || m_topTexPort.DataType == WirePortDataType.SAMPLER2DARRAY ) )
  942. ssTop = GeneratorUtils.GenerateSamplerState( ref dataCollector, UniqueId, texTop , VariableMode.Create );
  943. }
  944. else
  945. {
  946. if( m_midTexPort.IsConnected )
  947. {
  948. texMid = m_midTexPort.GeneratePortInstructions( ref dataCollector );
  949. }
  950. else
  951. {
  952. dataCollector.AddToUniforms( UniqueId, m_midTexture.GetTexture2DUniformValue() );
  953. dataCollector.AddToProperties( UniqueId, m_midTexture.GetTexture2DPropertyValue(), m_midTexture.OrderIndex );
  954. texMid = m_midTexture.PropertyName;
  955. }
  956. if( m_botTexPort.IsConnected )
  957. {
  958. texBot = m_botTexPort.GeneratePortInstructions( ref dataCollector );
  959. }
  960. else
  961. {
  962. dataCollector.AddToUniforms( UniqueId, m_botTexture.GetTexture2DUniformValue() );
  963. dataCollector.AddToProperties( UniqueId, m_botTexture.GetTexture2DPropertyValue(), m_botTexture.OrderIndex );
  964. texBot = m_botTexture.PropertyName;
  965. }
  966. if( ( outsideGraph.SamplingMacros || m_topTexPort.DataType == WirePortDataType.SAMPLER2DARRAY ) )
  967. ssTop = GeneratorUtils.GenerateSamplerState( ref dataCollector, UniqueId, texTop , VariableMode.Create );
  968. if( ( outsideGraph.SamplingMacros || m_midTexPort.DataType == WirePortDataType.SAMPLER2DARRAY ) )
  969. ssMid = GeneratorUtils.GenerateSamplerState( ref dataCollector, UniqueId, texMid , VariableMode.Create );
  970. if( ( outsideGraph.SamplingMacros || m_botTexPort.DataType == WirePortDataType.SAMPLER2DARRAY ) )
  971. ssBot = GeneratorUtils.GenerateSamplerState( ref dataCollector, UniqueId, texBot , VariableMode.Create );
  972. }
  973. if( !isVertex )
  974. {
  975. dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS );
  976. dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, UIUtils.CurrentWindow.CurrentGraph.CurrentPrecision );
  977. dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
  978. dataCollector.ForceNormal = true;
  979. }
  980. string topIndex = "0";
  981. string midIndex = "0";
  982. string botIndex = "0";
  983. if( m_topIndexPort.Visible )
  984. topIndex = m_topIndexPort.GeneratePortInstructions( ref dataCollector );
  985. if( m_midIndexPort.Visible )
  986. midIndex = m_midIndexPort.GeneratePortInstructions( ref dataCollector );
  987. if( m_botIndexPort.Visible )
  988. botIndex = m_botIndexPort.GeneratePortInstructions( ref dataCollector );
  989. string tiling = m_tilingPort.GeneratePortInstructions( ref dataCollector );
  990. string falloff = m_falloffPort.GeneratePortInstructions( ref dataCollector );
  991. bool scaleNormals = false;
  992. if( m_scalePort.IsConnected || ( m_scalePort.IsConnected && ( m_scalePort.Vector3InternalData == Vector3.one || m_scalePort.FloatInternalData == 1 ) ) )
  993. scaleNormals = true;
  994. MipType mip = isVertex ? MipType.MipLevel : MipType.Auto;
  995. string samplingTriplanar = string.Empty;
  996. string headerID = string.Empty;
  997. string header = string.Empty;
  998. string callHeader = string.Empty;
  999. string samplers = string.Empty;
  1000. string extraArguments = string.Empty;
  1001. List<string> triplanarBody = new List<string>();
  1002. triplanarBody.AddRange( m_functionSamplingBodyProj );
  1003. headerID += OutputId;
  1004. if( m_selectedTriplanarType == TriplanarType.Spherical )
  1005. {
  1006. samplers = GeneratorUtils.GetPropertyDeclaraction( "topTexMap", m_topTexPort.DataType, ", " ) + GeneratorUtils.GetSamplerDeclaraction( "samplertopTexMap", m_topTexPort.DataType, ", " );
  1007. string array1 = "";
  1008. string array2 = "";
  1009. if( m_topTexPort.DataType == WirePortDataType.SAMPLER2DARRAY )
  1010. {
  1011. if( outsideGraph.IsSRP )
  1012. {
  1013. array1 = "";
  1014. array2 = ", index.x";
  1015. }
  1016. else
  1017. {
  1018. array1 = "float3( ";
  1019. array2 = ", index.x )";
  1020. }
  1021. }
  1022. triplanarBody.Add( "half4 xNorm; half4 yNorm; half4 zNorm;" );
  1023. triplanarBody.Add( "xNorm = " + GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_topTexPort.DataType, "topTexMap", "samplertopTexMap", string.Format( "{0}tiling * worldPos.zy * float2( nsign.x, 1.0 ){1}", array1, array2 ), mip, "0" ) + ";" );
  1024. triplanarBody.Add( "yNorm = " + GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_topTexPort.DataType, "topTexMap", "samplertopTexMap", string.Format( "{0}tiling * worldPos.xz * float2( nsign.y, 1.0 ){1}", array1, array2 ), mip, "0" ) + ";" );
  1025. triplanarBody.Add( "zNorm = " + GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_topTexPort.DataType, "topTexMap", "samplertopTexMap", string.Format( "{0}tiling * worldPos.xy * float2( -nsign.z, 1.0 ){1}", array1, array2 ), mip, "0" ) + ";" );
  1026. if( m_normalCorrection )
  1027. {
  1028. if( scaleNormals )
  1029. {
  1030. ConvertListTo( dataCollector, true, m_functionSamplingBodySignsSphereScale, triplanarBody );
  1031. }
  1032. else
  1033. {
  1034. ConvertListTo( dataCollector, false, m_functionSamplingBodySignsSphere, triplanarBody );
  1035. }
  1036. triplanarBody.AddRange( m_functionSamplingBodyReturnSphereNormalize );
  1037. }
  1038. else
  1039. {
  1040. triplanarBody.AddRange( m_functionSamplingBodyReturnSphere );
  1041. }
  1042. }
  1043. else
  1044. {
  1045. string topArgs = GeneratorUtils.GetPropertyDeclaraction( "topTexMap", m_topTexPort.DataType, ", " ) + GeneratorUtils.GetSamplerDeclaraction( "samplertopTexMap", m_topTexPort.DataType, ", " );
  1046. string midArgs = GeneratorUtils.GetPropertyDeclaraction( "midTexMap", m_midTexPort.DataType, ", " ) + GeneratorUtils.GetSamplerDeclaraction( "samplermidTexMap", m_midTexPort.DataType, ", " );
  1047. string botArgs = GeneratorUtils.GetPropertyDeclaraction( "botTexMap", m_botTexPort.DataType, ", " ) + GeneratorUtils.GetSamplerDeclaraction( "samplerbotTexMap", m_botTexPort.DataType, ", " );
  1048. samplers = topArgs + midArgs + botArgs;
  1049. string uvTop = "tiling * worldPos.xz * float2( nsign.y, 1.0 )";
  1050. if( m_topTexPort.DataType == WirePortDataType.SAMPLER2DARRAY )
  1051. uvTop = outsideGraph.IsSRP ? uvTop + ", index.x" : "float3( " + uvTop + ", index.x )";
  1052. string uvMid = "tiling * worldPos.zy * float2( nsign.x, 1.0 )";
  1053. if( m_midTexPort.DataType == WirePortDataType.SAMPLER2DARRAY )
  1054. uvMid = outsideGraph.IsSRP ? uvMid + ", index.y" : "float3( " + uvMid + ", index.y )";
  1055. string uvMidNeg = "tiling * worldPos.xy * float2( -nsign.z, 1.0 )";
  1056. if( m_midTexPort.DataType == WirePortDataType.SAMPLER2DARRAY )
  1057. uvMidNeg = outsideGraph.IsSRP ? uvMidNeg + ", index.y" : "float3( " + uvMidNeg + ", index.y )";
  1058. string uvBot = "tiling * worldPos.xz * float2( nsign.y, 1.0 )";
  1059. if( m_botTexPort.DataType == WirePortDataType.SAMPLER2DARRAY )
  1060. uvBot = outsideGraph.IsSRP ? uvBot + ", index.z" : "float3( " + uvBot + ", index.z )";
  1061. extraArguments = ", {7}, {8}";
  1062. triplanarBody.AddRange( m_functionSamplingBodyNegProj );
  1063. triplanarBody.Add( "half4 xNorm; half4 yNorm; half4 yNormN; half4 zNorm;" );
  1064. triplanarBody.Add( "xNorm = " + GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_midTexPort.DataType, "midTexMap", "samplermidTexMap", uvMid, mip, "0" ) + ";" );
  1065. triplanarBody.Add( "yNorm = " + GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_topTexPort.DataType, "topTexMap", "samplertopTexMap", uvTop, mip, "0" ) + ";" );
  1066. triplanarBody.Add( "yNormN = " + GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_botTexPort.DataType, "botTexMap", "samplerbotTexMap", uvBot, mip, "0" ) + ";" );
  1067. triplanarBody.Add( "zNorm = " + GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_midTexPort.DataType, "midTexMap", "samplermidTexMap", uvMidNeg, mip, "0" ) + ";" );
  1068. if( m_normalCorrection )
  1069. {
  1070. if( scaleNormals )
  1071. {
  1072. if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
  1073. {
  1074. dataCollector.AddToIncludes( UniqueId, Constants.UnityStandardUtilsLibFuncs );
  1075. }
  1076. ConvertListTo( dataCollector, true, m_functionSamplingBodySignsSphereScale, triplanarBody );
  1077. ConvertListTo( dataCollector, true, m_functionSamplingBodySignsCylinderScale, triplanarBody );
  1078. }
  1079. else
  1080. {
  1081. ConvertListTo( dataCollector, false, m_functionSamplingBodySignsSphere, triplanarBody );
  1082. ConvertListTo( dataCollector, false, m_functionSamplingBodySignsCylinder, triplanarBody );
  1083. }
  1084. triplanarBody.AddRange( m_functionSamplingBodyReturnCylinderNormalize );
  1085. }
  1086. else
  1087. {
  1088. triplanarBody.AddRange( m_functionSamplingBodyReturnCylinder );
  1089. }
  1090. }
  1091. string type = UIUtils.WirePortToCgType( m_outputPorts[ 0 ].DataType );
  1092. header = string.Format( m_functionHeader, type, headerID, samplers );
  1093. callHeader = string.Format( m_functionCall, headerID, "{0}, {1}, {2}, {3}, {4}, {5}, {6}" + extraArguments );
  1094. IOUtils.AddFunctionHeader( ref samplingTriplanar, header );
  1095. foreach( string line in triplanarBody )
  1096. IOUtils.AddFunctionLine( ref samplingTriplanar, line );
  1097. IOUtils.CloseFunctionBody( ref samplingTriplanar );
  1098. string pos = GeneratorUtils.GenerateWorldPosition( ref dataCollector, UniqueId );
  1099. string norm = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId );
  1100. string worldToTangent = string.Empty;
  1101. if( m_normalCorrection && m_normalSpace == ViewSpace.Tangent )
  1102. worldToTangent = GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType );
  1103. if( m_selectedTriplanarSpace == TriplanarSpace.Object )
  1104. {
  1105. if( m_normalCorrection && m_normalSpace == ViewSpace.Tangent )
  1106. {
  1107. string vt = GeneratorUtils.GenerateVertexTangent( ref dataCollector, UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3 );
  1108. string vbt = GeneratorUtils.GenerateVertexBitangent( ref dataCollector, UniqueId, CurrentPrecisionType );
  1109. norm = GeneratorUtils.GenerateVertexNormal( ref dataCollector, UniqueId, CurrentPrecisionType );
  1110. dataCollector.AddLocalVariable( UniqueId, "float3x3 objectToTangent = float3x3("+ vt + ", "+ vbt + ", "+ norm + ");" );
  1111. pos = GeneratorUtils.GenerateVertexPosition( ref dataCollector, UniqueId, WirePortDataType.FLOAT3 );
  1112. worldToTangent = "objectToTangent";
  1113. }
  1114. else
  1115. {
  1116. pos = GeneratorUtils.GenerateVertexPosition( ref dataCollector, UniqueId, WirePortDataType.FLOAT3 );
  1117. norm = GeneratorUtils.GenerateVertexNormal( ref dataCollector, UniqueId, CurrentPrecisionType );
  1118. }
  1119. }
  1120. if( m_posPort.IsConnected )
  1121. {
  1122. pos = m_posPort.GeneratePortInstructions( ref dataCollector );
  1123. }
  1124. string call = string.Empty;
  1125. string normalScale = m_scalePort.GeneratePortInstructions( ref dataCollector );
  1126. if( !string.IsNullOrEmpty( ssTop ) )
  1127. ssTop = ", " + ssTop;
  1128. if( !string.IsNullOrEmpty( ssMid ) )
  1129. ssMid = ", " + ssMid;
  1130. if( !string.IsNullOrEmpty( ssBot ) )
  1131. ssBot = ", " + ssBot;
  1132. if( m_selectedTriplanarType == TriplanarType.Spherical )
  1133. call = dataCollector.AddFunctions( callHeader, samplingTriplanar, texTop + ssTop, pos, norm, falloff, tiling, normalScale, topIndex );
  1134. else
  1135. call = dataCollector.AddFunctions( callHeader, samplingTriplanar, texTop + ssTop, texMid + ssMid, texBot + ssBot, pos, norm, falloff, tiling, normalScale, "float3(" + topIndex + "," + midIndex + "," + botIndex + ")" );
  1136. string triplanarVarName = "triplanar" + OutputId;
  1137. dataCollector.AddToLocalVariables( dataCollector.PortCategory, UniqueId, type + " "+ triplanarVarName + " = " + call + ";" );
  1138. if( m_normalCorrection && m_normalSpace == ViewSpace.Tangent )
  1139. {
  1140. string tanTriplanarVarName = "tanTriplanarNormal" + OutputId;
  1141. dataCollector.AddToLocalVariables( dataCollector.PortCategory, UniqueId, "float3 " + tanTriplanarVarName + " = mul( " + worldToTangent + ", "+ triplanarVarName + " );" );
  1142. m_outputPorts[ 0 ].SetLocalValue( tanTriplanarVarName, dataCollector.PortCategory );
  1143. return GetOutputVectorItem( 0, outputId, tanTriplanarVarName );
  1144. }
  1145. else
  1146. {
  1147. m_outputPorts[ 0 ].SetLocalValue( triplanarVarName , dataCollector.PortCategory );
  1148. return GetOutputVectorItem( 0, outputId, triplanarVarName );
  1149. }
  1150. }
  1151. public override void UpdateMaterial( Material mat )
  1152. {
  1153. base.UpdateMaterial( mat );
  1154. m_topTexture.OnPropertyNameChanged();
  1155. if( mat.HasProperty( m_topTexture.PropertyName ) && !InsideShaderFunction )
  1156. {
  1157. mat.SetTexture( m_topTexture.PropertyName, m_topTexture.MaterialValue );
  1158. }
  1159. m_midTexture.OnPropertyNameChanged();
  1160. if( mat.HasProperty( m_midTexture.PropertyName ) && !InsideShaderFunction )
  1161. {
  1162. mat.SetTexture( m_midTexture.PropertyName, m_midTexture.MaterialValue );
  1163. }
  1164. m_botTexture.OnPropertyNameChanged();
  1165. if( mat.HasProperty( m_botTexture.PropertyName ) && !InsideShaderFunction )
  1166. {
  1167. mat.SetTexture( m_botTexture.PropertyName, m_botTexture.MaterialValue );
  1168. }
  1169. }
  1170. public void SetDelayedMaterialMode( Material mat )
  1171. {
  1172. m_topTexture.SetMaterialMode( mat, false );
  1173. if( mat.HasProperty( m_topTexture.PropertyName ) )
  1174. {
  1175. m_topTexture.MaterialValue = mat.GetTexture( m_topTexture.PropertyName );
  1176. }
  1177. m_midTexture.SetMaterialMode( mat, false );
  1178. if( mat.HasProperty( m_midTexture.PropertyName ) )
  1179. {
  1180. m_midTexture.MaterialValue = mat.GetTexture( m_midTexture.PropertyName );
  1181. }
  1182. m_botTexture.SetMaterialMode( mat, false );
  1183. if( mat.HasProperty( m_botTexture.PropertyName ) )
  1184. {
  1185. m_botTexture.MaterialValue = mat.GetTexture( m_botTexture.PropertyName );
  1186. }
  1187. }
  1188. public override void ForceUpdateFromMaterial( Material material )
  1189. {
  1190. base.ForceUpdateFromMaterial( material );
  1191. if( material.HasProperty( m_topTexture.PropertyName ) )
  1192. {
  1193. m_topTexture.MaterialValue = material.GetTexture( m_topTexture.PropertyName );
  1194. PreviewIsDirty = true;
  1195. }
  1196. if( material.HasProperty( m_midTexture.PropertyName ) )
  1197. {
  1198. m_midTexture.MaterialValue = material.GetTexture( m_midTexture.PropertyName );
  1199. PreviewIsDirty = true;
  1200. }
  1201. if( material.HasProperty( m_botTexture.PropertyName ) )
  1202. {
  1203. m_botTexture.MaterialValue = material.GetTexture( m_botTexture.PropertyName );
  1204. PreviewIsDirty = true;
  1205. }
  1206. }
  1207. public override void ReadFromString( ref string[] nodeParams )
  1208. {
  1209. base.ReadFromString( ref nodeParams );
  1210. m_selectedTriplanarType = (TriplanarType)Enum.Parse( typeof( TriplanarType ), GetCurrentParam( ref nodeParams ) );
  1211. m_selectedTriplanarSpace = (TriplanarSpace)Enum.Parse( typeof( TriplanarSpace ), GetCurrentParam( ref nodeParams ) );
  1212. m_normalCorrection = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  1213. m_tempTopInspectorName = GetCurrentParam( ref nodeParams );
  1214. m_tempTopName = GetCurrentParam( ref nodeParams );
  1215. m_tempTopDefaultValue = (TexturePropertyValues)Enum.Parse( typeof( TexturePropertyValues ), GetCurrentParam( ref nodeParams ) );
  1216. m_tempTopOrderIndex = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1217. m_tempTopDefaultTexture = AssetDatabase.LoadAssetAtPath<Texture2D>( GetCurrentParam( ref nodeParams ) );
  1218. m_tempMidInspectorName = GetCurrentParam( ref nodeParams );
  1219. m_tempMidName = GetCurrentParam( ref nodeParams );
  1220. m_tempMidDefaultValue = (TexturePropertyValues)Enum.Parse( typeof( TexturePropertyValues ), GetCurrentParam( ref nodeParams ) );
  1221. m_tempMidOrderIndex = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1222. m_tempMidDefaultTexture = AssetDatabase.LoadAssetAtPath<Texture2D>( GetCurrentParam( ref nodeParams ) );
  1223. m_tempBotInspectorName = GetCurrentParam( ref nodeParams );
  1224. m_tempBotName = GetCurrentParam( ref nodeParams );
  1225. m_tempBotDefaultValue = (TexturePropertyValues)Enum.Parse( typeof( TexturePropertyValues ), GetCurrentParam( ref nodeParams ) );
  1226. m_tempBotOrderIndex = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1227. m_tempBotDefaultTexture = AssetDatabase.LoadAssetAtPath<Texture2D>( GetCurrentParam( ref nodeParams ) );
  1228. if( UIUtils.CurrentShaderVersion() > 6102 )
  1229. m_propertyInspectorName = GetCurrentParam( ref nodeParams );
  1230. if( UIUtils.CurrentShaderVersion() <= 18301 )
  1231. Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  1232. if( UIUtils.CurrentShaderVersion() > 18201 )
  1233. m_normalSpace = (ViewSpace)Enum.Parse( typeof( ViewSpace ), GetCurrentParam( ref nodeParams ) );
  1234. SetTitleText( m_propertyInspectorName );
  1235. ConfigurePorts();
  1236. }
  1237. public override void RefreshExternalReferences()
  1238. {
  1239. base.RefreshExternalReferences();
  1240. Init();
  1241. ReadPropertiesData();
  1242. ConfigurePorts();
  1243. }
  1244. public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  1245. {
  1246. base.WriteToString( ref nodeInfo, ref connectionsInfo );
  1247. IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedTriplanarType );
  1248. IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedTriplanarSpace );
  1249. IOUtils.AddFieldValueToString( ref nodeInfo, m_normalCorrection );
  1250. IOUtils.AddFieldValueToString( ref nodeInfo, m_topTexture.PropertyInspectorName );
  1251. IOUtils.AddFieldValueToString( ref nodeInfo, m_topTexture.PropertyName );
  1252. IOUtils.AddFieldValueToString( ref nodeInfo, m_topTexture.DefaultTextureValue );
  1253. IOUtils.AddFieldValueToString( ref nodeInfo, m_topTexture.OrderIndex.ToString() );
  1254. IOUtils.AddFieldValueToString( ref nodeInfo, ( m_topTexture.DefaultValue != null ) ? AssetDatabase.GetAssetPath( m_topTexture.DefaultValue ) : Constants.NoStringValue );
  1255. IOUtils.AddFieldValueToString( ref nodeInfo, m_midTexture.PropertyInspectorName );
  1256. IOUtils.AddFieldValueToString( ref nodeInfo, m_midTexture.PropertyName );
  1257. IOUtils.AddFieldValueToString( ref nodeInfo, m_midTexture.DefaultTextureValue );
  1258. IOUtils.AddFieldValueToString( ref nodeInfo, m_midTexture.OrderIndex.ToString() );
  1259. IOUtils.AddFieldValueToString( ref nodeInfo, ( m_midTexture.DefaultValue != null ) ? AssetDatabase.GetAssetPath( m_midTexture.DefaultValue ) : Constants.NoStringValue );
  1260. IOUtils.AddFieldValueToString( ref nodeInfo, m_botTexture.PropertyInspectorName );
  1261. IOUtils.AddFieldValueToString( ref nodeInfo, m_botTexture.PropertyName );
  1262. IOUtils.AddFieldValueToString( ref nodeInfo, m_botTexture.DefaultTextureValue );
  1263. IOUtils.AddFieldValueToString( ref nodeInfo, m_botTexture.OrderIndex.ToString() );
  1264. IOUtils.AddFieldValueToString( ref nodeInfo, ( m_botTexture.DefaultValue != null ) ? AssetDatabase.GetAssetPath( m_botTexture.DefaultValue ) : Constants.NoStringValue );
  1265. IOUtils.AddFieldValueToString( ref nodeInfo, m_propertyInspectorName );
  1266. //IOUtils.AddFieldValueToString( ref nodeInfo, m_arraySupport );
  1267. IOUtils.AddFieldValueToString( ref nodeInfo, m_normalSpace );
  1268. }
  1269. public override void RefreshOnUndo()
  1270. {
  1271. base.RefreshOnUndo();
  1272. if( m_topTexture != null )
  1273. {
  1274. m_topTexture.BeginPropertyFromInspectorCheck();
  1275. }
  1276. if( m_midTexture != null )
  1277. {
  1278. m_midTexture.BeginPropertyFromInspectorCheck();
  1279. }
  1280. if( m_botTexture != null )
  1281. {
  1282. m_botTexture.BeginPropertyFromInspectorCheck();
  1283. }
  1284. }
  1285. }
  1286. }