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.

642 lines
21 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEditor;
  7. namespace AmplifyShaderEditor
  8. {
  9. [Serializable]
  10. public sealed class TessellationOpHelper
  11. {
  12. public const string TessellationPortStr = "Tessellation";
  13. public const string TessSurfParam = "tessellate:tessFunction";
  14. public const string TessInclude = "Tessellation.cginc";
  15. //public const string CustomAppData = "\t\tstruct appdata\n" +
  16. // "\t\t{\n" +
  17. // "\t\t\tfloat4 vertex : POSITION;\n" +
  18. // "\t\t\tfloat4 tangent : TANGENT;\n" +
  19. // "\t\t\tfloat3 normal : NORMAL;\n" +
  20. // "\t\t\tfloat4 texcoord : TEXCOORD0;\n" +
  21. // "\t\t\tfloat4 texcoord1 : TEXCOORD1;\n" +
  22. // "\t\t\tfloat4 texcoord2 : TEXCOORD2;\n" +
  23. // "\t\t\tfloat4 texcoord3 : TEXCOORD3;\n" +
  24. // "\t\t\tfixed4 color : COLOR;\n" +
  25. // "\t\t\tUNITY_VERTEX_INPUT_INSTANCE_ID\n" +
  26. // "\t\t};\n\n";
  27. private const string TessUniformName = "_TessValue";
  28. private const string TessMinUniformName = "_TessMin";
  29. private const string TessMaxUniformName = "_TessMax";
  30. //private GUIContent EnableTessContent = new GUIContent( "Tessellation", "Activates the use of tessellation which subdivides polygons to increase geometry detail using a set of rules\nDefault: OFF" );
  31. private GUIContent TessFactorContent = new GUIContent( "Tess", "Tessellation factor\nDefault: 4" );
  32. private GUIContent TessMinDistanceContent = new GUIContent( "Min", "Minimum tessellation distance\nDefault: 10" );
  33. private GUIContent TessMaxDistanceContent = new GUIContent( "Max", "Maximum tessellation distance\nDefault: 25" );
  34. private readonly int[] TesselationTypeValues = { 0, 1, 2, 3 };
  35. private readonly string[] TesselationTypeLabels = { "Distance-based", "Fixed", "Edge Length", "Edge Length Cull" };
  36. private readonly string TesselationTypeStr = "Type";
  37. private const string TessProperty = "_TessValue( \"Max Tessellation\", Range( 1, 32 ) ) = {0}";
  38. private const string TessMinProperty = "_TessMin( \"Tess Min Distance\", Float ) = {0}";
  39. private const string TessMaxProperty = "_TessMax( \"Tess Max Distance\", Float ) = {0}";
  40. private const string TessFunctionOpen = "\t\tfloat4 tessFunction( appdata_full v0, appdata_full v1, appdata_full v2 )\n\t\t{\n";
  41. private const string TessFunctionClose = "\t\t}\n";
  42. // Custom function
  43. private const string CustomFunctionBody = "\t\t\treturn {0};\n";
  44. // Distance based function
  45. private const string DistBasedTessFunctionBody = "\t\t\treturn UnityDistanceBasedTess( v0.vertex, v1.vertex, v2.vertex, _TessMin, _TessMax, _TessValue );\n";
  46. // Fixed amount function
  47. private const string FixedAmountTessFunctionOpen = "\t\tfloat4 tessFunction( )\n\t\t{\n";
  48. private const string FixedAmountTessFunctionBody = "\t\t\treturn _TessValue;\n";
  49. // Edge Length
  50. private GUIContent EdgeLengthContent = new GUIContent( "Edge Length", "Tessellation levels ccomputed based on triangle edge length on the screen\nDefault: 4" );
  51. private const string EdgeLengthTessProperty = "_EdgeLength ( \"Edge length\", Range( 2, 50 ) ) = {0}";
  52. private const string EdgeLengthTessUniformName = "_EdgeLength";
  53. private const string EdgeLengthTessFunctionBody = "\t\t\treturn UnityEdgeLengthBasedTess (v0.vertex, v1.vertex, v2.vertex, _EdgeLength);\n";
  54. private const string EdgeLengthTessCullFunctionBody = "\t\t\treturn UnityEdgeLengthBasedTessCull (v0.vertex, v1.vertex, v2.vertex, _EdgeLength , _TessMaxDisp );\n";
  55. private const string EdgeLengthTessMaxDispProperty = "_TessMaxDisp( \"Max Displacement\", Float ) = {0}";
  56. private const string EdgeLengthTessMaxDispUniformName = "_TessMaxDisp";
  57. private GUIContent EdgeLengthTessMaxDisplacementContent = new GUIContent( "Max Disp.", "Max Displacement" );
  58. // Phong
  59. private GUIContent PhongEnableContent = new GUIContent( "Phong", "Modifies positions of the subdivided faces so that the resulting surface follows the mesh normals a bit\nDefault: OFF" );
  60. private GUIContent PhongStrengthContent = new GUIContent( "Strength", "Strength\nDefault: 0.5" );
  61. public const string PhongStrengthParam = "tessphong:_TessPhongStrength";
  62. private const string PhongStrengthProperty = "_TessPhongStrength( \"Phong Tess Strength\", Range( 0, 1 ) ) = {0}";
  63. private const string PhongStrengthUniformName = "_TessPhongStrength";
  64. [SerializeField]
  65. private bool m_enabled = false;
  66. //private bool m_expanded = false;
  67. [SerializeField]
  68. private int m_tessType = 2;
  69. [SerializeField]
  70. private float m_tessMinDistance = 10f;
  71. [SerializeField]
  72. private float m_tessMaxDistance = 25f;
  73. [SerializeField]
  74. private float m_tessFactor = 15f;
  75. [SerializeField]
  76. private float m_phongStrength = 0.5f;
  77. [SerializeField]
  78. private bool m_phongEnabled = false;
  79. [SerializeField]
  80. private string[] m_customData = { string.Empty, string.Empty, string.Empty };
  81. [SerializeField]
  82. private bool m_hasCustomFunction = false;
  83. [SerializeField]
  84. private string m_customFunction = String.Empty;
  85. [SerializeField]
  86. private string m_additionalData = string.Empty;
  87. [SerializeField]
  88. private StandardSurfaceOutputNode m_parentSurface;
  89. private Dictionary<string, bool> m_additionalDataDict = new Dictionary<string, bool>();
  90. private int m_masterNodeIndexPort = 0;
  91. private int m_vertexOffsetIndexPort = 0;
  92. //private int m_orderIndex = 1000;
  93. public void Draw( UndoParentNode owner, GUIStyle toolbarstyle, Material mat, bool connectedInput )
  94. {
  95. Color cachedColor = GUI.color;
  96. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
  97. EditorGUILayout.BeginHorizontal( toolbarstyle );
  98. GUI.color = cachedColor;
  99. EditorGUI.BeginChangeCheck();
  100. m_parentSurface.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedTesselation = GUILayout.Toggle( m_parentSurface.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedTesselation, " Tessellation", UIUtils.MenuItemToggleStyle, GUILayout.ExpandWidth( true ) );
  101. if ( EditorGUI.EndChangeCheck() )
  102. {
  103. EditorPrefs.SetBool( "ExpandedTesselation", m_parentSurface.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedTesselation );
  104. }
  105. EditorGUI.BeginChangeCheck();
  106. m_enabled = owner.EditorGUILayoutToggle( string.Empty, m_enabled, UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) );
  107. if ( EditorGUI.EndChangeCheck() )
  108. {
  109. if ( m_enabled )
  110. UpdateToMaterial( mat, !connectedInput );
  111. UIUtils.RequestSave();
  112. }
  113. EditorGUILayout.EndHorizontal();
  114. m_enabled = m_enabled || connectedInput;
  115. if ( m_parentSurface.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedTesselation )
  116. {
  117. cachedColor = GUI.color;
  118. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
  119. EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
  120. GUI.color = cachedColor;
  121. EditorGUILayout.Separator();
  122. EditorGUI.BeginDisabledGroup( !m_enabled );
  123. EditorGUI.indentLevel += 1;
  124. m_phongEnabled = owner.EditorGUILayoutToggle( PhongEnableContent, m_phongEnabled );
  125. if ( m_phongEnabled )
  126. {
  127. EditorGUI.indentLevel += 1;
  128. EditorGUI.BeginChangeCheck();
  129. m_phongStrength = owner.EditorGUILayoutSlider( PhongStrengthContent, m_phongStrength, 0.0f, 1.0f );
  130. if ( EditorGUI.EndChangeCheck() && mat != null )
  131. {
  132. if ( mat.HasProperty( PhongStrengthUniformName ) )
  133. mat.SetFloat( PhongStrengthUniformName, m_phongStrength );
  134. }
  135. EditorGUI.indentLevel -= 1;
  136. }
  137. bool guiEnabled = GUI.enabled;
  138. GUI.enabled = !connectedInput && m_enabled;
  139. m_tessType = owner.EditorGUILayoutIntPopup( TesselationTypeStr, m_tessType, TesselationTypeLabels, TesselationTypeValues );
  140. switch ( m_tessType )
  141. {
  142. case 0:
  143. {
  144. EditorGUI.BeginChangeCheck();
  145. m_tessFactor = owner.EditorGUILayoutSlider( TessFactorContent, m_tessFactor, 1, 32 );
  146. if ( EditorGUI.EndChangeCheck() && mat != null )
  147. {
  148. if ( mat.HasProperty( TessUniformName ) )
  149. mat.SetFloat( TessUniformName, m_tessFactor );
  150. }
  151. EditorGUI.BeginChangeCheck();
  152. m_tessMinDistance = owner.EditorGUILayoutFloatField( TessMinDistanceContent, m_tessMinDistance );
  153. if ( EditorGUI.EndChangeCheck() && mat != null )
  154. {
  155. if ( mat.HasProperty( TessMinUniformName ) )
  156. mat.SetFloat( TessMinUniformName, m_tessMinDistance );
  157. }
  158. EditorGUI.BeginChangeCheck();
  159. m_tessMaxDistance = owner.EditorGUILayoutFloatField( TessMaxDistanceContent, m_tessMaxDistance );
  160. if ( EditorGUI.EndChangeCheck() && mat != null )
  161. {
  162. if ( mat.HasProperty( TessMaxUniformName ) )
  163. mat.SetFloat( TessMaxUniformName, m_tessMaxDistance );
  164. }
  165. }
  166. break;
  167. case 1:
  168. {
  169. EditorGUI.BeginChangeCheck();
  170. m_tessFactor = owner.EditorGUILayoutSlider( TessFactorContent, m_tessFactor, 1, 32 );
  171. if ( EditorGUI.EndChangeCheck() && mat != null )
  172. {
  173. if ( mat.HasProperty( TessUniformName ) )
  174. mat.SetFloat( TessUniformName, m_tessFactor );
  175. }
  176. }
  177. break;
  178. case 2:
  179. {
  180. EditorGUI.BeginChangeCheck();
  181. m_tessFactor = owner.EditorGUILayoutSlider( EdgeLengthContent, m_tessFactor, 2, 50 );
  182. if ( EditorGUI.EndChangeCheck() && mat != null )
  183. {
  184. if ( mat.HasProperty( EdgeLengthTessUniformName ) )
  185. mat.SetFloat( EdgeLengthTessUniformName, m_tessFactor );
  186. }
  187. }
  188. break;
  189. case 3:
  190. {
  191. EditorGUI.BeginChangeCheck();
  192. m_tessFactor = owner.EditorGUILayoutSlider( EdgeLengthContent, m_tessFactor, 2, 50 );
  193. if ( EditorGUI.EndChangeCheck() && mat != null )
  194. {
  195. if ( mat.HasProperty( EdgeLengthTessUniformName ) )
  196. mat.SetFloat( EdgeLengthTessUniformName, m_tessFactor );
  197. }
  198. EditorGUI.BeginChangeCheck();
  199. m_tessMaxDistance = owner.EditorGUILayoutFloatField( EdgeLengthTessMaxDisplacementContent, m_tessMaxDistance );
  200. if ( EditorGUI.EndChangeCheck() && mat != null )
  201. {
  202. if ( mat.HasProperty( TessMinUniformName ) )
  203. mat.SetFloat( TessMinUniformName, m_tessMaxDistance );
  204. }
  205. }
  206. break;
  207. }
  208. GUI.enabled = guiEnabled;
  209. EditorGUI.indentLevel -= 1;
  210. EditorGUI.EndDisabledGroup();
  211. EditorGUILayout.Separator();
  212. EditorGUILayout.EndVertical();
  213. }
  214. }
  215. public void UpdateToMaterial( Material mat, bool updateInternals )
  216. {
  217. if ( mat == null )
  218. return;
  219. if ( m_phongEnabled )
  220. {
  221. if ( mat.HasProperty( PhongStrengthUniformName ) )
  222. mat.SetFloat( PhongStrengthUniformName, m_phongStrength );
  223. }
  224. if ( updateInternals )
  225. {
  226. switch ( m_tessType )
  227. {
  228. case 0:
  229. {
  230. if ( mat.HasProperty( TessUniformName ) )
  231. mat.SetFloat( TessUniformName, m_tessFactor );
  232. if ( mat.HasProperty( TessMinUniformName ) )
  233. mat.SetFloat( TessMinUniformName, m_tessMinDistance );
  234. if ( mat.HasProperty( TessMaxUniformName ) )
  235. mat.SetFloat( TessMaxUniformName, m_tessMaxDistance );
  236. }
  237. break;
  238. case 1:
  239. {
  240. if ( mat.HasProperty( TessUniformName ) )
  241. mat.SetFloat( TessUniformName, m_tessFactor );
  242. }
  243. break;
  244. case 2:
  245. {
  246. if ( mat.HasProperty( EdgeLengthTessUniformName ) )
  247. mat.SetFloat( EdgeLengthTessUniformName, m_tessFactor );
  248. }
  249. break;
  250. case 3:
  251. {
  252. if ( mat.HasProperty( EdgeLengthTessUniformName ) )
  253. mat.SetFloat( EdgeLengthTessUniformName, m_tessFactor );
  254. if ( mat.HasProperty( TessMinUniformName ) )
  255. mat.SetFloat( TessMinUniformName, m_tessMaxDistance );
  256. }
  257. break;
  258. }
  259. }
  260. }
  261. public void ReadFromString( ref uint index, ref string[] nodeParams )
  262. {
  263. m_enabled = Convert.ToBoolean( nodeParams[ index++ ] );
  264. m_tessType = Convert.ToInt32( nodeParams[ index++ ] );
  265. m_tessFactor = Convert.ToSingle( nodeParams[ index++ ] );
  266. m_tessMinDistance = Convert.ToSingle( nodeParams[ index++ ] );
  267. m_tessMaxDistance = Convert.ToSingle( nodeParams[ index++ ] );
  268. if ( UIUtils.CurrentShaderVersion() > 3001 )
  269. {
  270. m_phongEnabled = Convert.ToBoolean( nodeParams[ index++ ] );
  271. m_phongStrength = Convert.ToSingle( nodeParams[ index++ ] );
  272. }
  273. }
  274. public void WriteToString( ref string nodeInfo )
  275. {
  276. IOUtils.AddFieldValueToString( ref nodeInfo, m_enabled );
  277. IOUtils.AddFieldValueToString( ref nodeInfo, m_tessType );
  278. IOUtils.AddFieldValueToString( ref nodeInfo, m_tessFactor );
  279. IOUtils.AddFieldValueToString( ref nodeInfo, m_tessMinDistance );
  280. IOUtils.AddFieldValueToString( ref nodeInfo, m_tessMaxDistance );
  281. IOUtils.AddFieldValueToString( ref nodeInfo, m_phongEnabled );
  282. IOUtils.AddFieldValueToString( ref nodeInfo, m_phongStrength );
  283. }
  284. public string Uniforms()
  285. {
  286. string uniforms = string.Empty;
  287. switch( m_tessType )
  288. {
  289. case 0:
  290. {
  291. if( !m_hasCustomFunction )
  292. {
  293. //Tess
  294. uniforms += "\t\tuniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + TessUniformName + ";\n";
  295. //Min
  296. uniforms += "\t\tuniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + TessMinUniformName + ";\n";
  297. //Max
  298. uniforms += "\t\tuniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + TessMaxUniformName + ";\n";
  299. }
  300. }
  301. break;
  302. case 1:
  303. //Tess
  304. if( !m_hasCustomFunction )
  305. {
  306. uniforms += "\t\tuniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + TessUniformName + ";\n";
  307. }
  308. break;
  309. }
  310. if( m_phongEnabled )
  311. {
  312. uniforms += "\t\tuniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + PhongStrengthUniformName + ";\n" ;
  313. }
  314. return uniforms;
  315. }
  316. public void AddToDataCollector( ref MasterNodeDataCollector dataCollector, int reorder )
  317. {
  318. int orderIndex = reorder;
  319. switch ( m_tessType )
  320. {
  321. case 0:
  322. {
  323. dataCollector.AddToIncludes( -1, TessellationOpHelper.TessInclude );
  324. if ( !m_hasCustomFunction )
  325. {
  326. //Tess
  327. dataCollector.AddToProperties( -1, string.Format( TessProperty, m_tessFactor ), orderIndex++ );
  328. dataCollector.AddToUniforms( -1, "uniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + TessUniformName + ";" );
  329. //Min
  330. dataCollector.AddToProperties( -1, string.Format( TessMinProperty, m_tessMinDistance ), orderIndex++ );
  331. dataCollector.AddToUniforms( -1, "uniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + TessMinUniformName + ";" );
  332. //Max
  333. dataCollector.AddToProperties( -1, string.Format( TessMaxProperty, m_tessMaxDistance ), orderIndex++ );
  334. dataCollector.AddToUniforms( -1, "uniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + TessMaxUniformName + ";" );
  335. }
  336. }
  337. break;
  338. case 1:
  339. {
  340. //Tess
  341. if ( !m_hasCustomFunction )
  342. {
  343. dataCollector.AddToProperties( -1, string.Format( TessProperty, m_tessFactor ), orderIndex++ );
  344. dataCollector.AddToUniforms( -1, "uniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + TessUniformName + ";" );
  345. }
  346. }
  347. break;
  348. case 2:
  349. {
  350. dataCollector.AddToIncludes( -1, TessellationOpHelper.TessInclude );
  351. //Tess
  352. if ( !m_hasCustomFunction )
  353. {
  354. dataCollector.AddToProperties( -1, string.Format( EdgeLengthTessProperty, m_tessFactor ), orderIndex++ );
  355. dataCollector.AddToUniforms( -1, "uniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + EdgeLengthTessUniformName + ";" );
  356. }
  357. }
  358. break;
  359. case 3:
  360. {
  361. dataCollector.AddToIncludes( -1, TessellationOpHelper.TessInclude );
  362. if ( !m_hasCustomFunction )
  363. {
  364. //Tess
  365. dataCollector.AddToProperties( -1, string.Format( EdgeLengthTessProperty, m_tessFactor ), orderIndex++ );
  366. dataCollector.AddToUniforms( -1, "uniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + EdgeLengthTessUniformName + ";" );
  367. //Max Displacement
  368. dataCollector.AddToProperties( -1, string.Format( EdgeLengthTessMaxDispProperty, m_tessMaxDistance ), orderIndex++ );
  369. dataCollector.AddToUniforms( -1, "uniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + EdgeLengthTessMaxDispUniformName + ";" );
  370. }
  371. }
  372. break;
  373. }
  374. if ( m_phongEnabled )
  375. {
  376. dataCollector.AddToProperties( -1, string.Format( PhongStrengthProperty, m_phongStrength ), orderIndex++ );
  377. dataCollector.AddToUniforms( -1, "uniform " + UIUtils.FinalPrecisionWirePortToCgType( PrecisionType.Float, WirePortDataType.FLOAT ) + " " + PhongStrengthUniformName + ";" );
  378. }
  379. }
  380. //ToDo: Optimize material property fetches to use Id instead of string
  381. public void UpdateFromMaterial( Material mat )
  382. {
  383. if ( m_enabled )
  384. {
  385. if ( m_phongEnabled )
  386. {
  387. if ( mat.HasProperty( PhongStrengthUniformName ) )
  388. m_phongStrength = mat.GetFloat( PhongStrengthUniformName );
  389. }
  390. switch ( m_tessType )
  391. {
  392. case 0:
  393. {
  394. if ( mat.HasProperty( TessUniformName ) )
  395. m_tessFactor = mat.GetFloat( TessUniformName );
  396. if ( mat.HasProperty( TessMinUniformName ) )
  397. m_tessMinDistance = mat.GetFloat( TessMinUniformName );
  398. if ( mat.HasProperty( TessMaxUniformName ) )
  399. m_tessMaxDistance = mat.GetFloat( TessMaxUniformName );
  400. }
  401. break;
  402. case 1:
  403. {
  404. if ( mat.HasProperty( TessUniformName ) )
  405. m_tessFactor = mat.GetFloat( TessUniformName );
  406. }
  407. break;
  408. case 2:
  409. {
  410. if ( mat.HasProperty( EdgeLengthTessUniformName ) )
  411. m_tessFactor = mat.GetFloat( EdgeLengthTessUniformName );
  412. }
  413. break;
  414. case 3:
  415. {
  416. if ( mat.HasProperty( EdgeLengthTessUniformName ) )
  417. m_tessFactor = mat.GetFloat( EdgeLengthTessUniformName );
  418. if ( mat.HasProperty( EdgeLengthTessMaxDispUniformName ) )
  419. m_tessMaxDistance = mat.GetFloat( EdgeLengthTessMaxDispUniformName );
  420. }
  421. break;
  422. }
  423. }
  424. }
  425. public void WriteToOptionalParams( ref string optionalParams )
  426. {
  427. optionalParams += TessellationOpHelper.TessSurfParam + Constants.OptionalParametersSep;
  428. if ( m_phongEnabled )
  429. {
  430. optionalParams += TessellationOpHelper.PhongStrengthParam + Constants.OptionalParametersSep;
  431. }
  432. }
  433. public void Reset()
  434. {
  435. m_hasCustomFunction = false;
  436. m_customFunction = string.Empty;
  437. m_additionalData = string.Empty;
  438. m_additionalDataDict.Clear();
  439. switch ( m_tessType )
  440. {
  441. case 0:
  442. {
  443. m_customData[ 0 ] = TessUniformName;
  444. m_customData[ 1 ] = TessMinUniformName;
  445. m_customData[ 2 ] = TessMaxUniformName;
  446. }
  447. break;
  448. case 1:
  449. {
  450. m_customData[ 0 ] = TessUniformName;
  451. m_customData[ 1 ] = string.Empty;
  452. m_customData[ 2 ] = string.Empty;
  453. }
  454. break;
  455. case 2:
  456. {
  457. m_customData[ 0 ] = EdgeLengthTessUniformName;
  458. m_customData[ 1 ] = string.Empty;
  459. m_customData[ 2 ] = string.Empty;
  460. }
  461. break;
  462. case 3:
  463. {
  464. m_customData[ 0 ] = EdgeLengthTessUniformName;
  465. m_customData[ 1 ] = EdgeLengthTessMaxDispUniformName;
  466. m_customData[ 2 ] = string.Empty;
  467. }
  468. break;
  469. }
  470. }
  471. public string GetCurrentTessellationFunction
  472. {
  473. get
  474. {
  475. if ( m_hasCustomFunction )
  476. {
  477. return TessFunctionOpen +
  478. m_customFunction +
  479. TessFunctionClose;
  480. }
  481. string tessFunction = string.Empty;
  482. switch ( m_tessType )
  483. {
  484. case 0:
  485. {
  486. tessFunction = TessFunctionOpen +
  487. DistBasedTessFunctionBody +
  488. TessFunctionClose;
  489. }
  490. break;
  491. case 1:
  492. {
  493. tessFunction = FixedAmountTessFunctionOpen +
  494. FixedAmountTessFunctionBody +
  495. TessFunctionClose;
  496. }
  497. break;
  498. case 2:
  499. {
  500. tessFunction = TessFunctionOpen +
  501. EdgeLengthTessFunctionBody +
  502. TessFunctionClose;
  503. }
  504. break;
  505. case 3:
  506. {
  507. tessFunction = TessFunctionOpen +
  508. EdgeLengthTessCullFunctionBody +
  509. TessFunctionClose;
  510. }
  511. break;
  512. }
  513. return tessFunction;
  514. }
  515. }
  516. public void AddAdditionalData( string data )
  517. {
  518. if ( !m_additionalDataDict.ContainsKey( data ) )
  519. {
  520. m_additionalDataDict.Add( data, true );
  521. m_additionalData += data;
  522. }
  523. }
  524. public void AddCustomFunction( string returnData )
  525. {
  526. m_hasCustomFunction = true;
  527. m_customFunction = m_additionalData + string.Format( CustomFunctionBody, returnData );
  528. }
  529. public void Destroy()
  530. {
  531. m_additionalDataDict.Clear();
  532. m_additionalDataDict = null;
  533. }
  534. public bool IsTessellationPort( int index )
  535. {
  536. return index == m_masterNodeIndexPort;
  537. }
  538. public bool EnableTesselation { get { return m_enabled; } }
  539. public int TessType { get { return m_tessType; } }
  540. public int MasterNodeIndexPort
  541. {
  542. get { return m_masterNodeIndexPort; }
  543. set { m_masterNodeIndexPort = value; }
  544. }
  545. public int VertexOffsetIndexPort
  546. {
  547. get { return m_vertexOffsetIndexPort; }
  548. set { m_vertexOffsetIndexPort = value; }
  549. }
  550. public StandardSurfaceOutputNode ParentSurface { get { return m_parentSurface; } set { m_parentSurface = value; } }
  551. }
  552. }