Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

666 lines
24 KiB

  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. [SerializeField]
  31. private InlineProperty m_reference = new InlineProperty();
  32. // Read Mask
  33. private const int ReadMaskDefaultValue = 255;
  34. [SerializeField]
  35. private InlineProperty m_readMask = new InlineProperty( ReadMaskDefaultValue );
  36. //Write Mask
  37. private const int WriteMaskDefaultValue = 255;
  38. [SerializeField]
  39. private InlineProperty m_writeMask = new InlineProperty( WriteMaskDefaultValue );
  40. //Comparison Function
  41. private const int ComparisonDefaultValue = 0;
  42. [SerializeField]
  43. private InlineProperty m_comparisonFunctionFrontIdx = new InlineProperty( ComparisonDefaultValue );
  44. [SerializeField]
  45. private InlineProperty m_comparisonFunctionBackIdx = new InlineProperty( ComparisonDefaultValue );
  46. //Pass Stencil Op
  47. private const int PassStencilOpDefaultValue = 0;
  48. [SerializeField]
  49. private InlineProperty m_passStencilOpFrontIdx = new InlineProperty( PassStencilOpDefaultValue );
  50. [SerializeField]
  51. private InlineProperty m_passStencilOpBackIdx = new InlineProperty( PassStencilOpDefaultValue );
  52. //Fail Stencil Op
  53. private const int FailStencilOpDefaultValue = 0;
  54. [SerializeField]
  55. private InlineProperty m_failStencilOpFrontIdx = new InlineProperty( FailStencilOpDefaultValue );
  56. [SerializeField]
  57. private InlineProperty m_failStencilOpBackIdx = new InlineProperty( FailStencilOpDefaultValue );
  58. //ZFail Stencil Op
  59. private const int ZFailStencilOpDefaultValue = 0;
  60. [SerializeField]
  61. private InlineProperty m_zFailStencilOpFrontIdx = new InlineProperty( ZFailStencilOpDefaultValue );
  62. [SerializeField]
  63. private InlineProperty m_zFailStencilOpBackIdx = new InlineProperty( ZFailStencilOpDefaultValue );
  64. public TemplatesStencilBufferModule() : base("Stencil Buffer")
  65. {
  66. for( int i = 0; i < StencilBufferOpHelper.StencilComparisonValues.Length; i++ )
  67. {
  68. m_comparisonDict.Add( StencilBufferOpHelper.StencilComparisonValues[ i ].ToLower(), i );
  69. }
  70. for( int i = 0; i < StencilBufferOpHelper.StencilOpsValues.Length; i++ )
  71. {
  72. m_stencilOpsDict.Add( StencilBufferOpHelper.StencilOpsValues[ i ].ToLower(), i );
  73. }
  74. }
  75. public void CopyFrom( TemplatesStencilBufferModule other , bool allData )
  76. {
  77. if( allData )
  78. m_independentModule = other.IndependentModule;
  79. m_active = other.Active;
  80. m_reference.CopyFrom( other.Reference );
  81. m_readMask.CopyFrom( other.ReadMask );
  82. m_writeMask.CopyFrom( other.WriteMask );
  83. m_comparisonFunctionFrontIdx.CopyFrom( other.ComparisonFunctionIdx );
  84. m_comparisonFunctionBackIdx.CopyFrom( other.ComparisonFunctionBackIdx );
  85. m_passStencilOpFrontIdx.CopyFrom( other.PassStencilOpIdx );
  86. m_passStencilOpBackIdx.CopyFrom( other.PassStencilOpBackIdx );
  87. m_failStencilOpFrontIdx.CopyFrom( other.FailStencilOpIdx );
  88. m_failStencilOpBackIdx.CopyFrom( other.FailStencilOpBackIdx );
  89. m_zFailStencilOpFrontIdx.CopyFrom( other.ZFailStencilOpIdx );
  90. m_zFailStencilOpBackIdx.CopyFrom( other.ZFailStencilOpBackIdx );
  91. }
  92. public void ConfigureFromTemplateData( TemplateStencilData stencilData )
  93. {
  94. bool newValidData = ( stencilData.DataCheck == TemplateDataCheck.Valid );
  95. if( newValidData && m_validData != newValidData )
  96. {
  97. m_active = stencilData.Active;
  98. m_independentModule = stencilData.IndependentModule;
  99. if( string.IsNullOrEmpty( stencilData.ReferenceInline ) )
  100. {
  101. m_reference.IntValue = stencilData.Reference;
  102. m_reference.ResetProperty();
  103. }
  104. else
  105. {
  106. m_reference.SetInlineByName( stencilData.ReferenceInline );
  107. }
  108. if( string.IsNullOrEmpty( stencilData.ReadMaskInline ) )
  109. {
  110. m_readMask.IntValue = stencilData.ReadMask;
  111. m_readMask.ResetProperty();
  112. }
  113. else
  114. {
  115. m_readMask.SetInlineByName( stencilData.ReadMaskInline );
  116. }
  117. if( string.IsNullOrEmpty( stencilData.WriteMaskInline ) )
  118. {
  119. m_writeMask.IntValue = stencilData.WriteMask;
  120. m_writeMask.ResetProperty();
  121. }
  122. else
  123. {
  124. m_writeMask.SetInlineByName( stencilData.WriteMaskInline );
  125. }
  126. if( string.IsNullOrEmpty( stencilData.ComparisonFrontInline ) )
  127. {
  128. if( !string.IsNullOrEmpty( stencilData.ComparisonFront ) )
  129. {
  130. m_comparisonFunctionFrontIdx.IntValue = m_comparisonDict[ stencilData.ComparisonFront.ToLower() ];
  131. }
  132. else
  133. {
  134. m_comparisonFunctionFrontIdx.IntValue = m_comparisonDict[ "always" ];
  135. }
  136. m_comparisonFunctionFrontIdx.ResetProperty();
  137. }
  138. else
  139. {
  140. m_comparisonFunctionFrontIdx.SetInlineByName( stencilData.ComparisonFrontInline );
  141. }
  142. if( string.IsNullOrEmpty( stencilData.PassFrontInline ) )
  143. {
  144. if( !string.IsNullOrEmpty( stencilData.PassFront ) )
  145. {
  146. m_passStencilOpFrontIdx.IntValue = m_stencilOpsDict[ stencilData.PassFront.ToLower() ];
  147. }
  148. else
  149. {
  150. m_passStencilOpFrontIdx.IntValue = m_stencilOpsDict[ "keep" ];
  151. }
  152. m_passStencilOpFrontIdx.ResetProperty();
  153. }
  154. else
  155. {
  156. m_passStencilOpFrontIdx.SetInlineByName( stencilData.PassFrontInline );
  157. }
  158. if( string.IsNullOrEmpty( stencilData.FailFrontInline ) )
  159. {
  160. if( !string.IsNullOrEmpty( stencilData.FailFront ) )
  161. {
  162. m_failStencilOpFrontIdx.IntValue = m_stencilOpsDict[ stencilData.FailFront.ToLower() ];
  163. }
  164. else
  165. {
  166. m_failStencilOpFrontIdx.IntValue = m_stencilOpsDict[ "keep" ];
  167. }
  168. m_failStencilOpFrontIdx.ResetProperty();
  169. }
  170. else
  171. {
  172. m_failStencilOpFrontIdx.SetInlineByName( stencilData.FailFrontInline );
  173. }
  174. if( string.IsNullOrEmpty( stencilData.ZFailFrontInline ) )
  175. {
  176. if( !string.IsNullOrEmpty( stencilData.ZFailFront ) )
  177. {
  178. m_zFailStencilOpFrontIdx.IntValue = m_stencilOpsDict[ stencilData.ZFailFront.ToLower() ];
  179. }
  180. else
  181. {
  182. m_zFailStencilOpFrontIdx.IntValue = m_stencilOpsDict[ "keep" ];
  183. }
  184. m_zFailStencilOpFrontIdx.ResetProperty();
  185. }
  186. else
  187. {
  188. m_zFailStencilOpFrontIdx.SetInlineByName( stencilData.ZFailFrontInline );
  189. }
  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 = m_comparisonDict[ "always" ];
  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 = m_stencilOpsDict[ "keep" ];
  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 = m_stencilOpsDict[ "keep" ];
  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 = m_stencilOpsDict[ "keep" ];
  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. }
  369. GUI.enabled = guiEnabled;
  370. }
  371. public override void ReadFromString( ref uint index, ref string[] nodeParams )
  372. {
  373. bool validDataOnMeta = m_validData;
  374. if( UIUtils.CurrentShaderVersion() > TemplatesManager.MPShaderVersion )
  375. {
  376. validDataOnMeta = Convert.ToBoolean( nodeParams[ index++ ] );
  377. }
  378. if( validDataOnMeta )
  379. {
  380. if( UIUtils.CurrentShaderVersion() > 15307 )
  381. {
  382. m_active = Convert.ToBoolean( nodeParams[ index++ ] );
  383. }
  384. if( UIUtils.CurrentShaderVersion() < 15304 )
  385. {
  386. m_reference.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  387. m_readMask.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  388. m_writeMask.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  389. m_comparisonFunctionFrontIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  390. m_passStencilOpFrontIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  391. m_failStencilOpFrontIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  392. m_zFailStencilOpFrontIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  393. m_comparisonFunctionBackIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  394. m_passStencilOpBackIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  395. m_failStencilOpBackIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  396. m_zFailStencilOpBackIdx.IntValue = Convert.ToInt32( nodeParams[ index++ ] );
  397. }
  398. else
  399. {
  400. m_reference.ReadFromString( ref index, ref nodeParams );
  401. m_readMask.ReadFromString( ref index, ref nodeParams );
  402. m_writeMask.ReadFromString( ref index, ref nodeParams );
  403. m_comparisonFunctionFrontIdx.ReadFromString( ref index, ref nodeParams );
  404. m_passStencilOpFrontIdx.ReadFromString( ref index, ref nodeParams );
  405. m_failStencilOpFrontIdx.ReadFromString( ref index, ref nodeParams );
  406. m_zFailStencilOpFrontIdx.ReadFromString( ref index, ref nodeParams );
  407. m_comparisonFunctionBackIdx.ReadFromString( ref index, ref nodeParams );
  408. m_passStencilOpBackIdx.ReadFromString( ref index, ref nodeParams );
  409. m_failStencilOpBackIdx.ReadFromString( ref index, ref nodeParams );
  410. m_zFailStencilOpBackIdx.ReadFromString( ref index, ref nodeParams );
  411. }
  412. }
  413. }
  414. public override void WriteToString( ref string nodeInfo )
  415. {
  416. IOUtils.AddFieldValueToString( ref nodeInfo, m_validData );
  417. if( m_validData )
  418. {
  419. IOUtils.AddFieldValueToString( ref nodeInfo, m_active );
  420. m_reference.WriteToString( ref nodeInfo );
  421. m_readMask.WriteToString( ref nodeInfo );
  422. m_writeMask.WriteToString( ref nodeInfo );
  423. m_comparisonFunctionFrontIdx.WriteToString( ref nodeInfo );
  424. m_passStencilOpFrontIdx.WriteToString( ref nodeInfo );
  425. m_failStencilOpFrontIdx.WriteToString( ref nodeInfo );
  426. m_zFailStencilOpFrontIdx.WriteToString( ref nodeInfo );
  427. m_comparisonFunctionBackIdx.WriteToString( ref nodeInfo );
  428. m_passStencilOpBackIdx.WriteToString( ref nodeInfo );
  429. m_failStencilOpBackIdx.WriteToString( ref nodeInfo );
  430. m_zFailStencilOpBackIdx.WriteToString( ref nodeInfo );
  431. }
  432. }
  433. public override void Destroy()
  434. {
  435. m_comparisonDict.Clear();
  436. m_comparisonDict = null;
  437. m_stencilOpsDict.Clear();
  438. m_stencilOpsDict = null;
  439. m_reference = null;
  440. m_readMask = null;
  441. m_writeMask = null;
  442. m_comparisonFunctionFrontIdx = null;
  443. m_passStencilOpFrontIdx = null;
  444. m_failStencilOpFrontIdx = null;
  445. m_zFailStencilOpFrontIdx = null;
  446. m_comparisonFunctionBackIdx = null;
  447. m_passStencilOpBackIdx = null;
  448. m_failStencilOpBackIdx = null;
  449. m_zFailStencilOpBackIdx = null;
  450. }
  451. public bool Active { get { return m_active; } }
  452. public InlineProperty Reference { get { return m_reference; } }
  453. public InlineProperty ReadMask { get { return m_readMask; } }
  454. public InlineProperty WriteMask { get { return m_writeMask; } }
  455. public InlineProperty ComparisonFunctionIdx { get { return m_comparisonFunctionFrontIdx; } }
  456. public InlineProperty ComparisonFunctionBackIdx { get { return m_comparisonFunctionBackIdx; } }
  457. public InlineProperty PassStencilOpIdx { get { return m_passStencilOpFrontIdx; } }
  458. public InlineProperty PassStencilOpBackIdx { get { return m_passStencilOpBackIdx; } }
  459. public InlineProperty FailStencilOpIdx { get { return m_failStencilOpFrontIdx; } }
  460. public InlineProperty FailStencilOpBackIdx { get { return m_failStencilOpBackIdx; } }
  461. public InlineProperty ZFailStencilOpIdx { get { return m_zFailStencilOpFrontIdx; } }
  462. public InlineProperty ZFailStencilOpBackIdx { get { return m_zFailStencilOpBackIdx; } }
  463. public int ReferenceValue
  464. {
  465. set
  466. {
  467. m_reference.IntValue = value;
  468. m_reference.Active = false;
  469. }
  470. get
  471. {
  472. return m_reference.IntValue;
  473. }
  474. }
  475. public int ReadMaskValue
  476. {
  477. set
  478. {
  479. m_readMask.IntValue = value;
  480. m_reference.Active = false;
  481. }
  482. get
  483. {
  484. return m_readMask.IntValue;
  485. }
  486. }
  487. public int WriteMaskValue
  488. {
  489. set
  490. {
  491. m_writeMask.IntValue = value;
  492. m_writeMask.Active = false;
  493. }
  494. get
  495. {
  496. return m_writeMask.IntValue;
  497. }
  498. }
  499. public int ComparisonFunctionIdxValue
  500. {
  501. set
  502. {
  503. m_comparisonFunctionFrontIdx.IntValue = value;
  504. m_comparisonFunctionFrontIdx.Active = false;
  505. }
  506. get
  507. {
  508. return m_comparisonFunctionFrontIdx.IntValue;
  509. }
  510. }
  511. public int ComparisonFunctionBackIdxValue
  512. {
  513. set
  514. {
  515. m_comparisonFunctionBackIdx.IntValue = value;
  516. m_comparisonFunctionBackIdx.Active = false;
  517. }
  518. get
  519. {
  520. return m_comparisonFunctionBackIdx.IntValue;
  521. }
  522. }
  523. public int PassStencilOpIdxValue
  524. {
  525. set
  526. {
  527. m_passStencilOpFrontIdx.IntValue = value;
  528. m_passStencilOpFrontIdx.Active = false;
  529. }
  530. get
  531. {
  532. return m_passStencilOpFrontIdx.IntValue;
  533. }
  534. }
  535. public int PassStencilOpBackIdxValue
  536. {
  537. set
  538. {
  539. m_passStencilOpBackIdx.IntValue = value;
  540. m_passStencilOpBackIdx.Active = false;
  541. }
  542. get
  543. {
  544. return m_passStencilOpBackIdx.IntValue;
  545. }
  546. }
  547. public int FailStencilOpIdxValue
  548. {
  549. set
  550. {
  551. m_failStencilOpFrontIdx.IntValue = value;
  552. m_failStencilOpFrontIdx.Active = false;
  553. }
  554. get
  555. {
  556. return m_failStencilOpFrontIdx.IntValue;
  557. }
  558. }
  559. public int FailStencilOpBackIdxValue
  560. {
  561. set
  562. {
  563. m_failStencilOpBackIdx.IntValue = value;
  564. m_failStencilOpBackIdx.Active = false;
  565. }
  566. get
  567. {
  568. return m_failStencilOpBackIdx.IntValue;
  569. }
  570. }
  571. public int ZFailStencilOpIdxValue
  572. {
  573. set
  574. {
  575. m_zFailStencilOpFrontIdx.IntValue = value;
  576. m_zFailStencilOpFrontIdx.Active = false;
  577. }
  578. get
  579. {
  580. return m_zFailStencilOpFrontIdx.IntValue;
  581. }
  582. }
  583. public int ZFailStencilOpBackIdxValue
  584. {
  585. set
  586. {
  587. m_zFailStencilOpBackIdx.IntValue = value;
  588. m_zFailStencilOpBackIdx.Active = false;
  589. }
  590. get
  591. {
  592. return m_zFailStencilOpBackIdx.IntValue;
  593. }
  594. }
  595. }
  596. }