TemplatesStencilBufferModule.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace AmplifyShaderEditor
  6. {
  7. [Serializable]
  8. public sealed class TemplatesStencilBufferModule : TemplateModuleParent
  9. {
  10. private const string FoldoutLabelStr = " Stencil Buffer";
  11. private GUIContent ReferenceValueContent = new GUIContent( "Reference", "The value to be compared against (if Comparison is anything else than always) and/or the value to be written to the buffer (if either Pass, Fail or ZFail is set to replace)" );
  12. private GUIContent ReadMaskContent = new GUIContent( "Read Mask", "An 8 bit mask as an 0-255 integer, used when comparing the reference value with the contents of the buffer (referenceValue & readMask) comparisonFunction (stencilBufferValue & readMask)" );
  13. private GUIContent WriteMaskContent = new GUIContent( "Write Mask", "An 8 bit mask as an 0-255 integer, used when writing to the buffer" );
  14. private const string ComparisonStr = "Comparison";
  15. private const string PassStr = "Pass";
  16. private const string FailStr = "Fail";
  17. private const string ZFailStr = "ZFail";
  18. private const string ComparisonFrontStr = "Comp. Front";
  19. private const string PassFrontStr = "Pass Front";
  20. private const string FailFrontStr = "Fail Front";
  21. private const string ZFailFrontStr = "ZFail Front";
  22. private const string ComparisonBackStr = "Comp. Back";
  23. private const string PassBackStr = "Pass Back";
  24. private const string FailBackStr = "Fail Back";
  25. private const string ZFailBackStr = "ZFail Back";
  26. private Dictionary<string, int> m_comparisonDict = new Dictionary<string, int>();
  27. private Dictionary<string, int> m_stencilOpsDict = new Dictionary<string, int>();
  28. [SerializeField]
  29. private bool m_active = true;
  30. private const int ReferenceDefaultValue = 0;
  31. [SerializeField] private InlineProperty m_reference = new InlineProperty( ReferenceDefaultValue );
  32. // Read Mask
  33. private const int ReadMaskDefaultValue = 255;
  34. [SerializeField] private InlineProperty m_readMask = new InlineProperty( ReadMaskDefaultValue );
  35. //Write Mask
  36. private const int WriteMaskDefaultValue = 255;
  37. [SerializeField] private InlineProperty m_writeMask = new InlineProperty( WriteMaskDefaultValue );
  38. //Comparison Function
  39. [NonSerialized] private int ComparisonDefaultValue = 0;
  40. [SerializeField] private InlineProperty m_comparisonFunctionFrontIdx;
  41. [SerializeField] private InlineProperty m_comparisonFunctionBackIdx;
  42. //Pass Stencil Op
  43. [NonSerialized] private int PassStencilOpDefaultValue = 0;
  44. [SerializeField] private InlineProperty m_passStencilOpFrontIdx;
  45. [SerializeField] private InlineProperty m_passStencilOpBackIdx;
  46. //Fail Stencil Op
  47. [NonSerialized] private int FailStencilOpDefaultValue = 0;
  48. [SerializeField] private InlineProperty m_failStencilOpFrontIdx;
  49. [SerializeField] private InlineProperty m_failStencilOpBackIdx;
  50. //ZFail Stencil Op
  51. [NonSerialized] private int ZFailStencilOpDefaultValue = 0;
  52. [SerializeField] private InlineProperty m_zFailStencilOpFrontIdx;
  53. [SerializeField] private InlineProperty m_zFailStencilOpBackIdx;
  54. public TemplatesStencilBufferModule() : base("Stencil Buffer")
  55. {
  56. for( int i = 0; i < StencilBufferOpHelper.StencilComparisonValues.Length; i++ )
  57. {
  58. m_comparisonDict.Add( StencilBufferOpHelper.StencilComparisonValues[ i ].ToLower(), i );
  59. }
  60. for( int i = 0; i < StencilBufferOpHelper.StencilOpsValues.Length; i++ )
  61. {
  62. m_stencilOpsDict.Add( StencilBufferOpHelper.StencilOpsValues[ i ].ToLower(), i );
  63. }
  64. m_comparisonFunctionFrontIdx = new InlineProperty( ComparisonDefaultValue );
  65. m_comparisonFunctionBackIdx = new InlineProperty( ComparisonDefaultValue );
  66. m_passStencilOpFrontIdx = new InlineProperty( PassStencilOpDefaultValue );
  67. m_passStencilOpBackIdx = new InlineProperty( PassStencilOpDefaultValue );
  68. m_failStencilOpFrontIdx = new InlineProperty( FailStencilOpDefaultValue );
  69. m_failStencilOpBackIdx = new InlineProperty( FailStencilOpDefaultValue );
  70. m_zFailStencilOpFrontIdx = new InlineProperty( ZFailStencilOpDefaultValue );
  71. m_zFailStencilOpBackIdx = new InlineProperty( ZFailStencilOpDefaultValue );
  72. }
  73. public void CopyFrom( TemplatesStencilBufferModule other , bool allData )
  74. {
  75. if( allData )
  76. m_independentModule = other.IndependentModule;
  77. m_active = other.Active;
  78. m_reference.CopyFrom( other.Reference );
  79. m_readMask.CopyFrom( other.ReadMask );
  80. m_writeMask.CopyFrom( other.WriteMask );
  81. m_comparisonFunctionFrontIdx.CopyFrom( other.ComparisonFunctionIdx );
  82. m_comparisonFunctionBackIdx.CopyFrom( other.ComparisonFunctionBackIdx );
  83. m_passStencilOpFrontIdx.CopyFrom( other.PassStencilOpIdx );
  84. m_passStencilOpBackIdx.CopyFrom( other.PassStencilOpBackIdx );
  85. m_failStencilOpFrontIdx.CopyFrom( other.FailStencilOpIdx );
  86. m_failStencilOpBackIdx.CopyFrom( other.FailStencilOpBackIdx );
  87. m_zFailStencilOpFrontIdx.CopyFrom( other.ZFailStencilOpIdx );
  88. m_zFailStencilOpBackIdx.CopyFrom( other.ZFailStencilOpBackIdx );
  89. }
  90. public void ConfigureFromTemplateData( TemplateStencilData stencilData )
  91. {
  92. bool newValidData = ( stencilData.DataCheck == TemplateDataCheck.Valid );
  93. if( newValidData && m_validData != newValidData )
  94. {
  95. m_active = stencilData.Active;
  96. m_independentModule = stencilData.IndependentModule;
  97. if( string.IsNullOrEmpty( stencilData.ReferenceInline ) )
  98. {
  99. m_reference.IntValue = stencilData.Reference;
  100. m_reference.ResetProperty();
  101. }
  102. else
  103. {
  104. m_reference.SetInlineByName( stencilData.ReferenceInline );
  105. }
  106. if( string.IsNullOrEmpty( stencilData.ReadMaskInline ) )
  107. {
  108. m_readMask.IntValue = stencilData.ReadMask;
  109. m_readMask.ResetProperty();
  110. }
  111. else
  112. {
  113. m_readMask.SetInlineByName( stencilData.ReadMaskInline );
  114. }
  115. if( string.IsNullOrEmpty( stencilData.WriteMaskInline ) )
  116. {
  117. m_writeMask.IntValue = stencilData.WriteMask;
  118. m_writeMask.ResetProperty();
  119. }
  120. else
  121. {
  122. m_writeMask.SetInlineByName( stencilData.WriteMaskInline );
  123. }
  124. // Front
  125. if( string.IsNullOrEmpty( stencilData.ComparisonFrontInline ) )
  126. {
  127. if( !string.IsNullOrEmpty( stencilData.ComparisonFront ) )
  128. {
  129. m_comparisonFunctionFrontIdx.IntValue = m_comparisonDict[ stencilData.ComparisonFront.ToLower() ];
  130. }
  131. else
  132. {
  133. m_comparisonFunctionFrontIdx.IntValue = ComparisonDefaultValue;
  134. }
  135. m_comparisonFunctionFrontIdx.ResetProperty();
  136. }
  137. else
  138. {
  139. m_comparisonFunctionFrontIdx.SetInlineByName( stencilData.ComparisonFrontInline );
  140. }
  141. if( string.IsNullOrEmpty( stencilData.PassFrontInline ) )
  142. {
  143. if( !string.IsNullOrEmpty( stencilData.PassFront ) )
  144. {
  145. m_passStencilOpFrontIdx.IntValue = m_stencilOpsDict[ stencilData.PassFront.ToLower() ];
  146. }
  147. else
  148. {
  149. m_passStencilOpFrontIdx.IntValue = PassStencilOpDefaultValue;
  150. }
  151. m_passStencilOpFrontIdx.ResetProperty();
  152. }
  153. else
  154. {
  155. m_passStencilOpFrontIdx.SetInlineByName( stencilData.PassFrontInline );
  156. }
  157. if( string.IsNullOrEmpty( stencilData.FailFrontInline ) )
  158. {
  159. if( !string.IsNullOrEmpty( stencilData.FailFront ) )
  160. {
  161. m_failStencilOpFrontIdx.IntValue = m_stencilOpsDict[ stencilData.FailFront.ToLower() ];
  162. }
  163. else
  164. {
  165. m_failStencilOpFrontIdx.IntValue = FailStencilOpDefaultValue;
  166. }
  167. m_failStencilOpFrontIdx.ResetProperty();
  168. }
  169. else
  170. {
  171. m_failStencilOpFrontIdx.SetInlineByName( stencilData.FailFrontInline );
  172. }
  173. if( string.IsNullOrEmpty( stencilData.ZFailFrontInline ) )
  174. {
  175. if( !string.IsNullOrEmpty( stencilData.ZFailFront ) )
  176. {
  177. m_zFailStencilOpFrontIdx.IntValue = m_stencilOpsDict[ stencilData.ZFailFront.ToLower() ];
  178. }
  179. else
  180. {
  181. m_zFailStencilOpFrontIdx.IntValue = ZFailStencilOpDefaultValue;
  182. }
  183. m_zFailStencilOpFrontIdx.ResetProperty();
  184. }
  185. else
  186. {
  187. m_zFailStencilOpFrontIdx.SetInlineByName( stencilData.ZFailFrontInline );
  188. }
  189. // Back
  190. if ( string.IsNullOrEmpty( stencilData.ComparisonBackInline ) )
  191. {
  192. if( !string.IsNullOrEmpty( stencilData.ComparisonBack ) )
  193. {
  194. m_comparisonFunctionBackIdx.IntValue = m_comparisonDict[ stencilData.ComparisonBack.ToLower() ];
  195. }
  196. else
  197. {
  198. m_comparisonFunctionBackIdx.IntValue = ComparisonDefaultValue;
  199. }
  200. m_comparisonFunctionBackIdx.ResetProperty();
  201. }
  202. else
  203. {
  204. m_comparisonFunctionBackIdx.SetInlineByName( stencilData.ComparisonBackInline );
  205. }
  206. if( string.IsNullOrEmpty( stencilData.PassBackInline ) )
  207. {
  208. if( !string.IsNullOrEmpty( stencilData.PassBack ) )
  209. {
  210. m_passStencilOpBackIdx.IntValue = m_stencilOpsDict[ stencilData.PassBack.ToLower() ];
  211. }
  212. else
  213. {
  214. m_passStencilOpBackIdx.IntValue = PassStencilOpDefaultValue;
  215. }
  216. m_passStencilOpBackIdx.ResetProperty();
  217. }
  218. else
  219. {
  220. m_passStencilOpBackIdx.SetInlineByName( stencilData.PassBackInline );
  221. }
  222. if( string.IsNullOrEmpty( stencilData.FailBackInline ) )
  223. {
  224. if( !string.IsNullOrEmpty( stencilData.FailBack ) )
  225. {
  226. m_failStencilOpBackIdx.IntValue = m_stencilOpsDict[ stencilData.FailBack.ToLower() ];
  227. }
  228. else
  229. {
  230. m_failStencilOpBackIdx.IntValue = FailStencilOpDefaultValue;
  231. }
  232. m_failStencilOpBackIdx.ResetProperty();
  233. }
  234. else
  235. {
  236. m_failStencilOpBackIdx.SetInlineByName( stencilData.FailBackInline );
  237. }
  238. if( string.IsNullOrEmpty( stencilData.ZFailBackInline ) )
  239. {
  240. if( !string.IsNullOrEmpty( stencilData.ZFailBack ) )
  241. {
  242. m_zFailStencilOpBackIdx.IntValue = m_stencilOpsDict[ stencilData.ZFailBack.ToLower() ];
  243. }
  244. else
  245. {
  246. m_zFailStencilOpBackIdx.IntValue = ZFailStencilOpDefaultValue;
  247. }
  248. m_zFailStencilOpBackIdx.ResetProperty();
  249. }
  250. else
  251. {
  252. m_zFailStencilOpBackIdx.SetInlineByName( stencilData.ZFailBackInline );
  253. }
  254. }
  255. m_validData = newValidData;
  256. }
  257. public string CreateStencilOp( CullMode cullMode )
  258. {
  259. if( !m_active )
  260. return string.Empty;
  261. string result = "Stencil\n{\n";
  262. result += string.Format( "\tRef {0}\n", m_reference.GetValueOrProperty() );
  263. if( m_readMask.IsValid || m_readMask.IntValue != ReadMaskDefaultValue )
  264. {
  265. result += string.Format( "\tReadMask {0}\n", m_readMask.GetValueOrProperty() );
  266. }
  267. if( m_writeMask.IsValid || m_writeMask.IntValue != WriteMaskDefaultValue )
  268. {
  269. result += string.Format( "\tWriteMask {0}\n", m_writeMask.GetValueOrProperty() );
  270. }
  271. if( cullMode == CullMode.Off &&
  272. ( m_comparisonFunctionBackIdx.IsValid || m_comparisonFunctionBackIdx.IntValue != ComparisonDefaultValue ||
  273. m_passStencilOpBackIdx.IsValid || m_passStencilOpBackIdx.IntValue != PassStencilOpDefaultValue ||
  274. m_failStencilOpBackIdx.IsValid || m_failStencilOpBackIdx.IntValue != FailStencilOpDefaultValue ||
  275. m_zFailStencilOpBackIdx.IsValid || m_zFailStencilOpBackIdx.IntValue != ZFailStencilOpDefaultValue ) )
  276. {
  277. if( m_comparisonFunctionFrontIdx.IsValid || m_comparisonFunctionFrontIdx.IntValue != ComparisonDefaultValue )
  278. result += string.Format( "\tCompFront {0}\n", m_comparisonFunctionFrontIdx.GetValueOrProperty( StencilBufferOpHelper.StencilComparisonValues[ m_comparisonFunctionFrontIdx.IntValue ] ) );
  279. if( m_passStencilOpFrontIdx.IsValid || m_passStencilOpFrontIdx.IntValue != PassStencilOpDefaultValue )
  280. result += string.Format( "\tPassFront {0}\n", m_passStencilOpFrontIdx.GetValueOrProperty( StencilBufferOpHelper.StencilOpsValues[ m_passStencilOpFrontIdx.IntValue ] ) );
  281. if( m_failStencilOpFrontIdx.IsValid || m_failStencilOpFrontIdx.IntValue != FailStencilOpDefaultValue )
  282. result += string.Format( "\tFailFront {0}\n", m_failStencilOpFrontIdx.GetValueOrProperty( StencilBufferOpHelper.StencilOpsValues[ m_failStencilOpFrontIdx.IntValue ] ) );
  283. if( m_zFailStencilOpFrontIdx.IsValid || m_zFailStencilOpFrontIdx.IntValue != ZFailStencilOpDefaultValue )
  284. result += string.Format( "\tZFailFront {0}\n", m_zFailStencilOpFrontIdx.GetValueOrProperty( StencilBufferOpHelper.StencilOpsValues[ m_zFailStencilOpFrontIdx.IntValue ] ) );
  285. if( m_comparisonFunctionBackIdx.IsValid || m_comparisonFunctionBackIdx.IntValue != ComparisonDefaultValue )
  286. result += string.Format( "\tCompBack {0}\n", m_comparisonFunctionBackIdx.GetValueOrProperty( StencilBufferOpHelper.StencilComparisonValues[ m_comparisonFunctionBackIdx.IntValue ] ) );
  287. if( m_passStencilOpBackIdx.IsValid || m_passStencilOpBackIdx.IntValue != PassStencilOpDefaultValue )
  288. result += string.Format( "\tPassBack {0}\n", m_passStencilOpBackIdx.GetValueOrProperty( StencilBufferOpHelper.StencilOpsValues[ m_passStencilOpBackIdx.IntValue ] ) );
  289. if( m_failStencilOpBackIdx.IsValid || m_failStencilOpBackIdx.IntValue != FailStencilOpDefaultValue )
  290. result += string.Format( "\tFailBack {0}\n", m_failStencilOpBackIdx.GetValueOrProperty( StencilBufferOpHelper.StencilOpsValues[ m_failStencilOpBackIdx.IntValue ] ));
  291. if( m_zFailStencilOpBackIdx.IsValid || m_zFailStencilOpBackIdx.IntValue != ZFailStencilOpDefaultValue )
  292. result += string.Format( "\tZFailBack {0}\n", m_zFailStencilOpBackIdx.GetValueOrProperty( StencilBufferOpHelper.StencilOpsValues[ m_zFailStencilOpBackIdx.IntValue ] ));
  293. }
  294. else
  295. {
  296. if( m_comparisonFunctionFrontIdx.IsValid || m_comparisonFunctionFrontIdx.IntValue != ComparisonDefaultValue )
  297. result += string.Format( "\tComp {0}\n", m_comparisonFunctionFrontIdx.GetValueOrProperty(StencilBufferOpHelper.StencilComparisonValues[ m_comparisonFunctionFrontIdx.IntValue ] ));
  298. if( m_passStencilOpFrontIdx.IsValid || m_passStencilOpFrontIdx.IntValue != PassStencilOpDefaultValue )
  299. result += string.Format( "\tPass {0}\n", m_passStencilOpFrontIdx.GetValueOrProperty( StencilBufferOpHelper.StencilOpsValues[ m_passStencilOpFrontIdx.IntValue ] ));
  300. if( m_failStencilOpFrontIdx.IsValid || m_failStencilOpFrontIdx.IntValue != FailStencilOpDefaultValue )
  301. result += string.Format( "\tFail {0}\n", m_failStencilOpFrontIdx.GetValueOrProperty( StencilBufferOpHelper.StencilOpsValues[ m_failStencilOpFrontIdx.IntValue ] ));
  302. if( m_zFailStencilOpFrontIdx.IsValid || m_zFailStencilOpFrontIdx.IntValue != ZFailStencilOpDefaultValue )
  303. result += string.Format( "\tZFail {0}\n", m_zFailStencilOpFrontIdx.GetValueOrProperty(StencilBufferOpHelper.StencilOpsValues[ m_zFailStencilOpFrontIdx.IntValue ] ));
  304. }
  305. result += "}";
  306. return result;
  307. }
  308. public override void ShowUnreadableDataMessage( ParentNode owner )
  309. {
  310. bool foldout = owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedStencilOptions;
  311. NodeUtils.DrawPropertyGroup( ref foldout, FoldoutLabelStr, base.ShowUnreadableDataMessage );
  312. owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedStencilOptions = foldout;
  313. }
  314. public void Draw( UndoParentNode owner, CullMode cullMode , bool style = true )
  315. {
  316. bool foldout = owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedStencilOptions;
  317. if( style )
  318. {
  319. NodeUtils.DrawPropertyGroup( ref foldout, FoldoutLabelStr, () =>
  320. {
  321. DrawBlock( owner, cullMode );
  322. } );
  323. }
  324. else
  325. {
  326. NodeUtils.DrawNestedPropertyGroup( owner, ref foldout, ref m_active, FoldoutLabelStr, () =>
  327. {
  328. DrawBlock( owner, cullMode );
  329. } );
  330. }
  331. owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedStencilOptions = foldout;
  332. }
  333. void DrawBlock( UndoParentNode owner, CullMode cullMode )
  334. {
  335. bool guiEnabled = GUI.enabled;
  336. GUI.enabled = m_active;
  337. EditorGUI.BeginChangeCheck();
  338. {
  339. var cache = EditorGUIUtility.labelWidth;
  340. EditorGUIUtility.labelWidth = EditorGUIUtility.labelWidth - 20;
  341. m_reference.IntSlider( ref owner, ReferenceValueContent, 0, 255 );
  342. m_readMask.IntSlider( ref owner, ReadMaskContent, 0, 255 );
  343. m_writeMask.IntSlider( ref owner, WriteMaskContent, 0, 255 );
  344. if( cullMode == CullMode.Off )
  345. {
  346. m_comparisonFunctionFrontIdx.EnumTypePopup( ref owner, ComparisonFrontStr, StencilBufferOpHelper.StencilComparisonLabels );
  347. m_passStencilOpFrontIdx.EnumTypePopup( ref owner, PassFrontStr, StencilBufferOpHelper.StencilOpsLabels );
  348. m_failStencilOpFrontIdx.EnumTypePopup( ref owner, FailFrontStr, StencilBufferOpHelper.StencilOpsLabels );
  349. m_zFailStencilOpFrontIdx.EnumTypePopup( ref owner, ZFailFrontStr, StencilBufferOpHelper.StencilOpsLabels );
  350. EditorGUILayout.Separator();
  351. m_comparisonFunctionBackIdx.EnumTypePopup( ref owner, ComparisonBackStr, StencilBufferOpHelper.StencilComparisonLabels );
  352. m_passStencilOpBackIdx.EnumTypePopup( ref owner, PassBackStr, StencilBufferOpHelper.StencilOpsLabels );
  353. m_failStencilOpBackIdx.EnumTypePopup( ref owner, FailBackStr, StencilBufferOpHelper.StencilOpsLabels );
  354. m_zFailStencilOpBackIdx.EnumTypePopup( ref owner, ZFailBackStr, StencilBufferOpHelper.StencilOpsLabels );
  355. }
  356. else
  357. {
  358. m_comparisonFunctionFrontIdx.EnumTypePopup( ref owner, ComparisonStr, StencilBufferOpHelper.StencilComparisonLabels );
  359. m_passStencilOpFrontIdx.EnumTypePopup( ref owner, PassFrontStr, StencilBufferOpHelper.StencilOpsLabels );
  360. m_failStencilOpFrontIdx.EnumTypePopup( ref owner, FailFrontStr, StencilBufferOpHelper.StencilOpsLabels );
  361. m_zFailStencilOpFrontIdx.EnumTypePopup( ref owner, ZFailFrontStr, StencilBufferOpHelper.StencilOpsLabels );
  362. }
  363. EditorGUIUtility.labelWidth = cache;
  364. }
  365. if( EditorGUI.EndChangeCheck() )
  366. {
  367. m_isDirty = true;
  368. CustomEdited = true;
  369. }
  370. GUI.enabled = guiEnabled;
  371. }
  372. public override void ReadFromString( ref uint index, ref string[] nodeParams )
  373. {
  374. base.ReadFromString( ref index, ref nodeParams );
  375. bool validDataOnMeta = m_validData;
  376. if( UIUtils.CurrentShaderVersion() > TemplatesManager.MPShaderVersion )
  377. {
  378. validDataOnMeta = Convert.ToBoolean( nodeParams[ index++ ] );
  379. }
  380. if( validDataOnMeta )
  381. {
  382. if( UIUtils.CurrentShaderVersion() > 15307 )
  383. {
  384. m_active = Convert.ToBoolean( nodeParams[ index++ ] );
  385. }
  386. if( UIUtils.CurrentShaderVersion() < 15304 )
  387. {
  388. m_reference.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  389. m_readMask.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  390. m_writeMask.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  391. m_comparisonFunctionFrontIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  392. m_passStencilOpFrontIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  393. m_failStencilOpFrontIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  394. m_zFailStencilOpFrontIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  395. m_comparisonFunctionBackIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  396. m_passStencilOpBackIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  397. m_failStencilOpBackIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  398. m_zFailStencilOpBackIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  399. }
  400. else
  401. {
  402. m_reference.ReadFromString( ref index, ref nodeParams );
  403. m_readMask.ReadFromString( ref index, ref nodeParams );
  404. m_writeMask.ReadFromString( ref index, ref nodeParams );
  405. m_comparisonFunctionFrontIdx.ReadFromString( ref index, ref nodeParams );
  406. m_passStencilOpFrontIdx.ReadFromString( ref index, ref nodeParams );
  407. m_failStencilOpFrontIdx.ReadFromString( ref index, ref nodeParams );
  408. m_zFailStencilOpFrontIdx.ReadFromString( ref index, ref nodeParams );
  409. m_comparisonFunctionBackIdx.ReadFromString( ref index, ref nodeParams );
  410. m_passStencilOpBackIdx.ReadFromString( ref index, ref nodeParams );
  411. m_failStencilOpBackIdx.ReadFromString( ref index, ref nodeParams );
  412. m_zFailStencilOpBackIdx.ReadFromString( ref index, ref nodeParams );
  413. }
  414. }
  415. }
  416. public override void WriteToString( ref string nodeInfo )
  417. {
  418. base.WriteToString( ref nodeInfo );
  419. IOUtils.AddFieldValueToString( ref nodeInfo, m_validData );
  420. if( m_validData )
  421. {
  422. IOUtils.AddFieldValueToString( ref nodeInfo, m_active );
  423. m_reference.WriteToString( ref nodeInfo );
  424. m_readMask.WriteToString( ref nodeInfo );
  425. m_writeMask.WriteToString( ref nodeInfo );
  426. m_comparisonFunctionFrontIdx.WriteToString( ref nodeInfo );
  427. m_passStencilOpFrontIdx.WriteToString( ref nodeInfo );
  428. m_failStencilOpFrontIdx.WriteToString( ref nodeInfo );
  429. m_zFailStencilOpFrontIdx.WriteToString( ref nodeInfo );
  430. m_comparisonFunctionBackIdx.WriteToString( ref nodeInfo );
  431. m_passStencilOpBackIdx.WriteToString( ref nodeInfo );
  432. m_failStencilOpBackIdx.WriteToString( ref nodeInfo );
  433. m_zFailStencilOpBackIdx.WriteToString( ref nodeInfo );
  434. }
  435. }
  436. public override void Destroy()
  437. {
  438. m_comparisonDict.Clear();
  439. m_comparisonDict = null;
  440. m_stencilOpsDict.Clear();
  441. m_stencilOpsDict = null;
  442. m_reference = null;
  443. m_readMask = null;
  444. m_writeMask = null;
  445. m_comparisonFunctionFrontIdx = null;
  446. m_passStencilOpFrontIdx = null;
  447. m_failStencilOpFrontIdx = null;
  448. m_zFailStencilOpFrontIdx = null;
  449. m_comparisonFunctionBackIdx = null;
  450. m_passStencilOpBackIdx = null;
  451. m_failStencilOpBackIdx = null;
  452. m_zFailStencilOpBackIdx = null;
  453. }
  454. public bool Active { get { return m_active; } }
  455. public InlineProperty Reference { get { return m_reference; } }
  456. public InlineProperty ReadMask { get { return m_readMask; } }
  457. public InlineProperty WriteMask { get { return m_writeMask; } }
  458. public InlineProperty ComparisonFunctionIdx { get { return m_comparisonFunctionFrontIdx; } }
  459. public InlineProperty ComparisonFunctionBackIdx { get { return m_comparisonFunctionBackIdx; } }
  460. public InlineProperty PassStencilOpIdx { get { return m_passStencilOpFrontIdx; } }
  461. public InlineProperty PassStencilOpBackIdx { get { return m_passStencilOpBackIdx; } }
  462. public InlineProperty FailStencilOpIdx { get { return m_failStencilOpFrontIdx; } }
  463. public InlineProperty FailStencilOpBackIdx { get { return m_failStencilOpBackIdx; } }
  464. public InlineProperty ZFailStencilOpIdx { get { return m_zFailStencilOpFrontIdx; } }
  465. public InlineProperty ZFailStencilOpBackIdx { get { return m_zFailStencilOpBackIdx; } }
  466. public int ReferenceValue
  467. {
  468. set
  469. {
  470. m_reference.IntValue = value;
  471. m_reference.Active = false;
  472. }
  473. get
  474. {
  475. return m_reference.IntValue;
  476. }
  477. }
  478. public int ReadMaskValue
  479. {
  480. set
  481. {
  482. m_readMask.IntValue = value;
  483. m_reference.Active = false;
  484. }
  485. get
  486. {
  487. return m_readMask.IntValue;
  488. }
  489. }
  490. public int WriteMaskValue
  491. {
  492. set
  493. {
  494. m_writeMask.IntValue = value;
  495. m_writeMask.Active = false;
  496. }
  497. get
  498. {
  499. return m_writeMask.IntValue;
  500. }
  501. }
  502. public int ComparisonFunctionIdxValue
  503. {
  504. set
  505. {
  506. m_comparisonFunctionFrontIdx.IntValue = value;
  507. m_comparisonFunctionFrontIdx.Active = false;
  508. }
  509. get
  510. {
  511. return m_comparisonFunctionFrontIdx.IntValue;
  512. }
  513. }
  514. public int ComparisonFunctionBackIdxValue
  515. {
  516. set
  517. {
  518. m_comparisonFunctionBackIdx.IntValue = value;
  519. m_comparisonFunctionBackIdx.Active = false;
  520. }
  521. get
  522. {
  523. return m_comparisonFunctionBackIdx.IntValue;
  524. }
  525. }
  526. public int PassStencilOpIdxValue
  527. {
  528. set
  529. {
  530. m_passStencilOpFrontIdx.IntValue = value;
  531. m_passStencilOpFrontIdx.Active = false;
  532. }
  533. get
  534. {
  535. return m_passStencilOpFrontIdx.IntValue;
  536. }
  537. }
  538. public int PassStencilOpBackIdxValue
  539. {
  540. set
  541. {
  542. m_passStencilOpBackIdx.IntValue = value;
  543. m_passStencilOpBackIdx.Active = false;
  544. }
  545. get
  546. {
  547. return m_passStencilOpBackIdx.IntValue;
  548. }
  549. }
  550. public int FailStencilOpIdxValue
  551. {
  552. set
  553. {
  554. m_failStencilOpFrontIdx.IntValue = value;
  555. m_failStencilOpFrontIdx.Active = false;
  556. }
  557. get
  558. {
  559. return m_failStencilOpFrontIdx.IntValue;
  560. }
  561. }
  562. public int FailStencilOpBackIdxValue
  563. {
  564. set
  565. {
  566. m_failStencilOpBackIdx.IntValue = value;
  567. m_failStencilOpBackIdx.Active = false;
  568. }
  569. get
  570. {
  571. return m_failStencilOpBackIdx.IntValue;
  572. }
  573. }
  574. public int ZFailStencilOpIdxValue
  575. {
  576. set
  577. {
  578. m_zFailStencilOpFrontIdx.IntValue = value;
  579. m_zFailStencilOpFrontIdx.Active = false;
  580. }
  581. get
  582. {
  583. return m_zFailStencilOpFrontIdx.IntValue;
  584. }
  585. }
  586. public int ZFailStencilOpBackIdxValue
  587. {
  588. set
  589. {
  590. m_zFailStencilOpBackIdx.IntValue = value;
  591. m_zFailStencilOpBackIdx.Active = false;
  592. }
  593. get
  594. {
  595. return m_zFailStencilOpBackIdx.IntValue;
  596. }
  597. }
  598. }
  599. }