TerrainDrawInstancedHelper.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace AmplifyShaderEditor
  8. {
  9. [Serializable]
  10. public class TerrainDrawInstancedHelper
  11. {
  12. private readonly string[] InstancedPragmas =
  13. {
  14. "multi_compile_instancing",
  15. "instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap forwardadd"
  16. };
  17. private readonly string[] InstancedPragmasSRP =
  18. {
  19. "multi_compile_instancing",
  20. "instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap"
  21. };
  22. private readonly string[] InstancedGlobalsSRP =
  23. {
  24. "#ifdef UNITY_INSTANCING_ENABLED//ASE Terrain Instancing",
  25. "\tTEXTURE2D(_TerrainHeightmapTexture);//ASE Terrain Instancing",
  26. "\tTEXTURE2D( _TerrainNormalmapTexture);//ASE Terrain Instancing",
  27. "\tSAMPLER(sampler_TerrainNormalmapTexture);//ASE Terrain Instancing",
  28. "#endif//ASE Terrain Instancing",
  29. "UNITY_INSTANCING_BUFFER_START( Terrain )//ASE Terrain Instancing",
  30. "\tUNITY_DEFINE_INSTANCED_PROP( float4, _TerrainPatchInstanceData )//ASE Terrain Instancing",
  31. "UNITY_INSTANCING_BUFFER_END( Terrain)//ASE Terrain Instancing",
  32. "CBUFFER_START( UnityTerrain)//ASE Terrain Instancing",
  33. "\t#ifdef UNITY_INSTANCING_ENABLED//ASE Terrain Instancing",
  34. "\t\tfloat4 _TerrainHeightmapRecipSize;//ASE Terrain Instancing",
  35. "\t\tfloat4 _TerrainHeightmapScale;//ASE Terrain Instancing",
  36. "\t#endif//ASE Terrain Instancing",
  37. "CBUFFER_END//ASE Terrain Instancing"
  38. };
  39. private readonly string[] InstancedGlobalsDefault =
  40. {
  41. "#ifdef UNITY_INSTANCING_ENABLED//ASE Terrain Instancing",
  42. "\tsampler2D _TerrainHeightmapTexture;//ASE Terrain Instancing",
  43. "\tsampler2D _TerrainNormalmapTexture;//ASE Terrain Instancing",
  44. "#endif//ASE Terrain Instancing",
  45. "UNITY_INSTANCING_BUFFER_START( Terrain )//ASE Terrain Instancing",
  46. "\tUNITY_DEFINE_INSTANCED_PROP( float4, _TerrainPatchInstanceData )//ASE Terrain Instancing",
  47. "UNITY_INSTANCING_BUFFER_END( Terrain)//ASE Terrain Instancing",
  48. "CBUFFER_START( UnityTerrain)//ASE Terrain Instancing",
  49. "\t#ifdef UNITY_INSTANCING_ENABLED//ASE Terrain Instancing",
  50. "\t\tfloat4 _TerrainHeightmapRecipSize;//ASE Terrain Instancing",
  51. "\t\tfloat4 _TerrainHeightmapScale;//ASE Terrain Instancing",
  52. "\t#endif//ASE Terrain Instancing",
  53. "CBUFFER_END//ASE Terrain Instancing"
  54. };
  55. private readonly string ApplyMeshModificationInstruction = "{0} = ApplyMeshModification({0});";
  56. private readonly string[] ApplyMeshModificationFunctionSRP =
  57. {
  58. /*0 - struct name 1 - var name*/"{0} ApplyMeshModification( {0} {1} )\n",
  59. "{\n",
  60. "#ifdef UNITY_INSTANCING_ENABLED\n",
  61. /* 0 vertex position*/"\tfloat2 patchVertex = {0}.xy;\n",
  62. "\tfloat4 instanceData = UNITY_ACCESS_INSTANCED_PROP( Terrain, _TerrainPatchInstanceData );\n",
  63. "\tfloat2 sampleCoords = ( patchVertex.xy + instanceData.xy ) * instanceData.z;\n",
  64. "\tfloat height = UnpackHeightmap( _TerrainHeightmapTexture.Load( int3( sampleCoords, 0 ) ) );\n",
  65. /*0 - vertex position*/"\t{0}.xz = sampleCoords* _TerrainHeightmapScale.xz;\n",
  66. /*0 - vertex position*/"\t{0}.y = height* _TerrainHeightmapScale.y;\n",
  67. "\t#ifdef ENABLE_TERRAIN_PERPIXEL_NORMAL\n",
  68. /* 0 - vertex normal*/"\t\t{0} = float3(0, 1, 0);\n",
  69. "\t#else\n",
  70. /* 0 - vertex normal*/"\t\t{0} = _TerrainNormalmapTexture.Load(int3(sampleCoords, 0)).rgb* 2 - 1;\n",
  71. "\t#endif\n",
  72. "",//"#ifdef ENABLE_TERRAIN_PERPIXEL_NORMAL\n",
  73. "",///* 0 - tex coord*/"\t{0}.xy = sampleCoords;\n",
  74. "",//"#else\n",
  75. /* 0 - tex coord*/"\t{0}.xy = sampleCoords* _TerrainHeightmapRecipSize.zw;\n",
  76. "",//"#endif\n",
  77. "#endif\n",
  78. /* 0 - var name*/"\treturn {0};\n",
  79. "}\n"
  80. };
  81. //{
  82. // /*0 - struct name 1 - var name*/"{0} ApplyMeshModification( {0} {1} )\n",
  83. // "{\n",
  84. // "#ifdef UNITY_INSTANCING_ENABLED\n",
  85. // /* 0 vertex position*/"\tfloat2 patchVertex = {0}.xy;\n",
  86. // "\t\tfloat4 instanceData = UNITY_ACCESS_INSTANCED_PROP( Terrain, _TerrainPatchInstanceData );\n",
  87. // "\t\tfloat2 sampleCoords = ( patchVertex.xy + instanceData.xy ) * instanceData.z;\n",
  88. // "\t\tfloat height = UnpackHeightmap( _TerrainHeightmapTexture.Load( int3( sampleCoords, 0 ) ) );\n",
  89. // /*0 - vertex position*/"\t\t{0}.xz = sampleCoords* _TerrainHeightmapScale.xz;\n",
  90. // /*0 - vertex position*/"\t\t{0}.y = height* _TerrainHeightmapScale.y;\n",
  91. // "# ifdef ATTRIBUTES_NEED_NORMAL\n",
  92. // /* 0 - vertex normal*/"\t\t{0} = _TerrainNormalmapTexture.Load(int3(sampleCoords, 0)).rgb* 2 - 1;\n",
  93. // "\t#endif\n",
  94. // "\t#if defined(VARYINGS_NEED_TEXCOORD0) || defined(VARYINGS_DS_NEED_TEXCOORD0)\n",
  95. // "\t\t#ifdef ENABLE_TERRAIN_PERPIXEL_NORMAL\n",
  96. // /* 0 - tex coord*/"\t\t\t{0} = sampleCoords;\n",
  97. // "\t\t#else\n",
  98. // /* 0 - tex coord*/"\t\t\t{0}.xy = sampleCoords* _TerrainHeightmapRecipSize.zw;\n",
  99. // "\t\t#endif\n",
  100. // "\t#endif\n",
  101. // "#endif\n",
  102. // "#ifdef ATTRIBUTES_NEED_TANGENT\n",
  103. // /* 0 - tangent 1 - normal*/"\t\t{0}.xyz = cross( {1}, float3(0, 0, 1));\n",
  104. // /*0 - tangent*/"\t{0}.w = -1;\n",
  105. // "#endif\n",
  106. // /* 0 - var name*/"\treturn {0};\n",
  107. // "}\n"
  108. //};
  109. private readonly string[] ApplyMeshModificationFunctionDefaultTemplate =
  110. {
  111. /* 0 vertex struct */"{0} ApplyMeshModification( {0} {1} )",
  112. "{\n",
  113. "#ifdef UNITY_INSTANCING_ENABLED\n",
  114. /*0 - vertex pos*/"\tfloat2 patchVertex = {0}.xy;\n",
  115. "\tfloat4 instanceData = UNITY_ACCESS_INSTANCED_PROP( Terrain, _TerrainPatchInstanceData );\n",
  116. "\tfloat4 uvscale = instanceData.z * _TerrainHeightmapRecipSize;\n" +
  117. "\tfloat4 uvoffset = instanceData.xyxy * uvscale;\n" +
  118. "\tuvoffset.xy += 0.5f * _TerrainHeightmapRecipSize.xy;\n" +
  119. "\tfloat2 sampleCoords = (patchVertex.xy * uvscale.xy + uvoffset.xy);\n",
  120. /* 0 - tex coords*/"\t{0} = float4(patchVertex.xy * uvscale.zw + uvoffset.zw, 0, 0);\n",
  121. /* 0 - tex coords*/"\tfloat height = UnpackHeightmap( tex2Dlod( _TerrainHeightmapTexture, float4(sampleCoords, 0, 0) ) );\n",
  122. /* 0 - vertex pos*/"\t{0}.xz = (patchVertex.xy + instanceData.xy) * _TerrainHeightmapScale.xz * instanceData.z;\n",
  123. /* 0 - vertex pos*/"\t{0}.y = height * _TerrainHeightmapScale.y;\n",
  124. /* 0 - normal 1 - tex coord*/"\t{0} = tex2Dlod( _TerrainNormalmapTexture, {1} ).rgb * 2 - 1;\n",
  125. "#endif\n",
  126. /* var name*/"return {0};\n",
  127. "}\n"
  128. };
  129. private readonly string ApplyMeshModificationInstructionStandard = "ApplyMeshModification({0});";
  130. private readonly string[] ApplyMeshModificationFunctionStandard =
  131. {
  132. "void ApplyMeshModification( inout {0} v )",
  133. "#if defined(UNITY_INSTANCING_ENABLED) && !defined(SHADER_API_D3D11_9X)",
  134. "\tfloat2 patchVertex = v.vertex.xy;",
  135. "\tfloat4 instanceData = UNITY_ACCESS_INSTANCED_PROP(Terrain, _TerrainPatchInstanceData);",
  136. "\t",
  137. "\tfloat4 uvscale = instanceData.z * _TerrainHeightmapRecipSize;",
  138. "\tfloat4 uvoffset = instanceData.xyxy * uvscale;",
  139. "\tuvoffset.xy += 0.5f * _TerrainHeightmapRecipSize.xy;",
  140. "\tfloat2 sampleCoords = (patchVertex.xy * uvscale.xy + uvoffset.xy);",
  141. "\t",
  142. "\tfloat hm = UnpackHeightmap(tex2Dlod(_TerrainHeightmapTexture, float4(sampleCoords, 0, 0)));",
  143. "\tv.vertex.xz = (patchVertex.xy + instanceData.xy) * _TerrainHeightmapScale.xz * instanceData.z;",
  144. "\tv.vertex.y = hm * _TerrainHeightmapScale.y;",
  145. "\tv.vertex.w = 1.0f;",
  146. "\t",
  147. "\tv.texcoord.xy = (patchVertex.xy * uvscale.zw + uvoffset.zw);",
  148. "\tv.texcoord3 = v.texcoord2 = v.texcoord1 = v.texcoord;",
  149. "\t",
  150. "\t#ifdef TERRAIN_INSTANCED_PERPIXEL_NORMAL",
  151. "\t\tv.normal = float3(0, 1, 0);",
  152. "\t\t//data.tc.zw = sampleCoords;",
  153. "\t#else",
  154. "\t\tfloat3 nor = tex2Dlod(_TerrainNormalmapTexture, float4(sampleCoords, 0, 0)).xyz;",
  155. "\t\tv.normal = 2.0f * nor - 1.0f;",
  156. "\t#endif",
  157. "#endif",
  158. };
  159. private readonly string[] AdditionalUsePasses =
  160. {
  161. "Hidden/Nature/Terrain/Utilities/PICKING",
  162. "Hidden/Nature/Terrain/Utilities/SELECTION"
  163. };
  164. private readonly string DrawInstancedLabel = "Instanced Terrain";
  165. [SerializeField]
  166. private bool m_enable = false;
  167. public void Draw( UndoParentNode owner )
  168. {
  169. m_enable = owner.EditorGUILayoutToggle( DrawInstancedLabel, m_enable );
  170. }
  171. public void UpdateDataCollectorForTemplates( ref MasterNodeDataCollector dataCollector, ref List<string> vertexInstructions )
  172. {
  173. if( m_enable )
  174. {
  175. for( int i = 0; i < AdditionalUsePasses.Length; i++ )
  176. {
  177. dataCollector.AddUsePass( AdditionalUsePasses[ i ], false );
  178. }
  179. string[] instancedPragmas = dataCollector.IsSRP ? InstancedPragmasSRP : InstancedPragmas;
  180. for( int i = 0; i < instancedPragmas.Length; i++ )
  181. {
  182. dataCollector.AddToPragmas( -1, instancedPragmas[ i ] );
  183. }
  184. if( dataCollector.IsSRP )
  185. {
  186. TemplateFunctionData functionData = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData;
  187. string uvCoord = dataCollector.TemplateDataCollectorInstance.GetUV( 0, MasterNodePortCategory.Vertex );
  188. string vertexNormal = dataCollector.TemplateDataCollectorInstance.GetVertexNormal( PrecisionType.Float, false, MasterNodePortCategory.Vertex );
  189. //string vertexTangent = dataCollector.TemplateDataCollectorInstance.GetVertexTangent( WirePortDataType.FLOAT4, PrecisionType.Float, false, MasterNodePortCategory.Vertex );
  190. string vertexPos = dataCollector.TemplateDataCollectorInstance.GetVertexPosition( WirePortDataType.OBJECT, PrecisionType.Float, false, MasterNodePortCategory.Vertex );
  191. string functionHeader = string.Format( ApplyMeshModificationFunctionSRP[ 0 ], functionData.InVarType, functionData.InVarName );
  192. //string functionBody = functionHeader +
  193. // ApplyMeshModificationFunctionSRP[ 1 ] +
  194. // ApplyMeshModificationFunctionSRP[ 2 ] +
  195. // string.Format( ApplyMeshModificationFunctionSRP[ 3 ], vertexPos ) +
  196. // ApplyMeshModificationFunctionSRP[ 4 ] +
  197. // ApplyMeshModificationFunctionSRP[ 5 ] +
  198. // ApplyMeshModificationFunctionSRP[ 6 ] +
  199. // string.Format( ApplyMeshModificationFunctionSRP[ 7 ], vertexPos ) +
  200. // string.Format( ApplyMeshModificationFunctionSRP[ 8 ], vertexPos ) +
  201. // ApplyMeshModificationFunctionSRP[ 9 ] +
  202. // string.Format( ApplyMeshModificationFunctionSRP[ 10 ], vertexNormal ) +
  203. // ApplyMeshModificationFunctionSRP[ 11 ] +
  204. // ApplyMeshModificationFunctionSRP[ 12 ] +
  205. // ApplyMeshModificationFunctionSRP[ 13 ] +
  206. // string.Format( ApplyMeshModificationFunctionSRP[ 14 ], uvCoord ) +
  207. // ApplyMeshModificationFunctionSRP[ 15 ] +
  208. // string.Format( ApplyMeshModificationFunctionSRP[ 16 ], uvCoord ) +
  209. // ApplyMeshModificationFunctionSRP[ 17 ] +
  210. // ApplyMeshModificationFunctionSRP[ 18 ] +
  211. // ApplyMeshModificationFunctionSRP[ 19 ] +
  212. // ApplyMeshModificationFunctionSRP[ 20 ] +
  213. // string.Format( ApplyMeshModificationFunctionSRP[ 21 ], vertexTangent, vertexNormal ) +
  214. // string.Format( ApplyMeshModificationFunctionSRP[ 22 ], vertexTangent ) +
  215. // ApplyMeshModificationFunctionSRP[ 23 ] +
  216. // string.Format( ApplyMeshModificationFunctionSRP[ 24 ], functionData.InVarName ) +
  217. // ApplyMeshModificationFunctionSRP[ 25 ];
  218. string functionBody = functionHeader +
  219. ApplyMeshModificationFunctionSRP[ 1 ] +
  220. ApplyMeshModificationFunctionSRP[ 2 ] +
  221. string.Format( ApplyMeshModificationFunctionSRP[ 3 ], vertexPos ) +
  222. ApplyMeshModificationFunctionSRP[ 4 ] +
  223. ApplyMeshModificationFunctionSRP[ 5 ] +
  224. ApplyMeshModificationFunctionSRP[ 6 ] +
  225. string.Format( ApplyMeshModificationFunctionSRP[ 7 ], vertexPos ) +
  226. string.Format( ApplyMeshModificationFunctionSRP[ 8 ], vertexPos ) +
  227. ApplyMeshModificationFunctionSRP[ 9 ] +
  228. string.Format( ApplyMeshModificationFunctionSRP[ 10 ], vertexNormal ) +
  229. ApplyMeshModificationFunctionSRP[ 11 ] +
  230. string.Format( ApplyMeshModificationFunctionSRP[ 12 ], vertexNormal ) +
  231. ApplyMeshModificationFunctionSRP[ 13 ] +
  232. ApplyMeshModificationFunctionSRP[ 14 ] +
  233. string.Format( ApplyMeshModificationFunctionSRP[ 15 ], uvCoord ) +
  234. ApplyMeshModificationFunctionSRP[ 16 ] +
  235. string.Format( ApplyMeshModificationFunctionSRP[ 17 ], uvCoord ) +
  236. ApplyMeshModificationFunctionSRP[ 18 ] +
  237. ApplyMeshModificationFunctionSRP[ 19 ] +
  238. string.Format( ApplyMeshModificationFunctionSRP[ 20 ], functionData.InVarName ) +
  239. ApplyMeshModificationFunctionSRP[ 21 ];
  240. dataCollector.AddFunction( functionHeader, functionBody );
  241. for( int i = 0; i < InstancedGlobalsSRP.Length; i++ )
  242. {
  243. dataCollector.AddToUniforms( -1, InstancedGlobalsSRP[ i ] );
  244. }
  245. string vertexVarName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.InVarName;
  246. vertexInstructions.Insert( 0, string.Format( ApplyMeshModificationInstruction, vertexVarName ) );
  247. }
  248. else
  249. {
  250. TemplateFunctionData functionData = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData;
  251. string uvCoord = dataCollector.TemplateDataCollectorInstance.GetUV( 0, MasterNodePortCategory.Vertex );
  252. string vertexNormal = dataCollector.TemplateDataCollectorInstance.GetVertexNormal( PrecisionType.Float, false, MasterNodePortCategory.Vertex );
  253. string vertexPos = dataCollector.TemplateDataCollectorInstance.GetVertexPosition( WirePortDataType.OBJECT, PrecisionType.Float, false, MasterNodePortCategory.Vertex );
  254. string functionHeader = string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 0 ], functionData.InVarType, functionData.InVarName );
  255. string functionBody = functionHeader +
  256. ApplyMeshModificationFunctionDefaultTemplate[ 1 ] +
  257. ApplyMeshModificationFunctionDefaultTemplate[ 2 ] +
  258. string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 3 ], vertexPos ) +
  259. ApplyMeshModificationFunctionDefaultTemplate[ 4 ] +
  260. ApplyMeshModificationFunctionDefaultTemplate[ 5 ] +
  261. string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 6 ], uvCoord ) +
  262. string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 7 ], uvCoord ) +
  263. string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 8 ], vertexPos ) +
  264. string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 9 ], vertexPos ) +
  265. string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 10 ], vertexNormal, uvCoord ) +
  266. ApplyMeshModificationFunctionDefaultTemplate[ 11 ] +
  267. string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 12 ], functionData.InVarName ) +
  268. ApplyMeshModificationFunctionDefaultTemplate[ 13 ];
  269. dataCollector.AddFunction( functionHeader, functionBody );
  270. for( int i = 0; i < InstancedGlobalsDefault.Length; i++ )
  271. {
  272. dataCollector.AddToUniforms( -1, InstancedGlobalsDefault[ i ] );
  273. }
  274. string vertexVarName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.InVarName;
  275. vertexInstructions.Insert( 0, string.Format( ApplyMeshModificationInstruction, vertexVarName ) );
  276. }
  277. }
  278. }
  279. public void UpdateDataCollectorForStandard( ref MasterNodeDataCollector dataCollector )
  280. {
  281. if( m_enable )
  282. {
  283. for( int i = 0; i < AdditionalUsePasses.Length; i++ )
  284. {
  285. dataCollector.AddUsePass( AdditionalUsePasses[ i ], false );
  286. }
  287. for( int i = 0; i < InstancedPragmas.Length; i++ )
  288. {
  289. dataCollector.AddToPragmas( -1, InstancedPragmas[ i ] );
  290. }
  291. string functionBody = string.Empty;
  292. string functionHeader = string.Format( ApplyMeshModificationFunctionStandard[ 0 ], dataCollector.SurfaceVertexStructure );
  293. IOUtils.AddFunctionHeader( ref functionBody, functionHeader );
  294. for( int i = 1; i < ApplyMeshModificationFunctionStandard.Length; i++ )
  295. {
  296. IOUtils.AddFunctionLine( ref functionBody, ApplyMeshModificationFunctionStandard[ i ] );
  297. }
  298. IOUtils.CloseFunctionBody( ref functionBody );
  299. //string inputName = "input";
  300. //string uvCoord = "input.texcoord";
  301. //string vertexNormal = "input.normal";
  302. //string vertexPos = "input.vertex";
  303. //string functionHeader = string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 0 ], dataCollector.SurfaceVertexStructure, inputName );
  304. //IOUtils.AddFunctionHeader( ref functionBody, functionHeader );
  305. //IOUtils.AddFunctionLine( ref functionBody, ApplyMeshModificationFunctionDefaultTemplate[ 1 ] );
  306. //IOUtils.AddFunctionLine( ref functionBody,ApplyMeshModificationFunctionDefaultTemplate[ 2 ] );
  307. //IOUtils.AddFunctionLine( ref functionBody,string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 3 ], vertexPos ) );
  308. //IOUtils.AddFunctionLine( ref functionBody,ApplyMeshModificationFunctionDefaultTemplate[ 4 ] );
  309. //IOUtils.AddFunctionLine( ref functionBody,ApplyMeshModificationFunctionDefaultTemplate[ 5 ] );
  310. //IOUtils.AddFunctionLine( ref functionBody,string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 6 ], uvCoord ) );
  311. //IOUtils.AddFunctionLine( ref functionBody,string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 7 ], uvCoord ) );
  312. //IOUtils.AddFunctionLine( ref functionBody,string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 8 ], vertexPos ) );
  313. //IOUtils.AddFunctionLine( ref functionBody,string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 9 ], vertexPos ) );
  314. //IOUtils.AddFunctionLine( ref functionBody,string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 10 ], vertexNormal, uvCoord ) );
  315. //IOUtils.AddFunctionLine( ref functionBody,ApplyMeshModificationFunctionDefaultTemplate[ 11 ] );
  316. //IOUtils.AddFunctionLine( ref functionBody,string.Format( ApplyMeshModificationFunctionDefaultTemplate[ 12 ], inputName ) );
  317. //IOUtils.AddFunctionLine( ref functionBody, ApplyMeshModificationFunctionDefaultTemplate[ 13 ] );
  318. //IOUtils.CloseFunctionBody( ref functionBody );
  319. dataCollector.AddFunction( functionHeader, functionBody );
  320. for( int i = 0; i < InstancedGlobalsDefault.Length; i++ )
  321. {
  322. dataCollector.AddToUniforms( -1, InstancedGlobalsDefault[ i ] );
  323. }
  324. dataCollector.AddVertexInstruction( string.Format( ApplyMeshModificationInstructionStandard, "v" ) );
  325. }
  326. }
  327. public void ReadFromString( ref uint index, ref string[] nodeParams )
  328. {
  329. m_enable = Convert.ToBoolean( nodeParams[ index++ ] );
  330. }
  331. public void WriteToString( ref string nodeInfo )
  332. {
  333. IOUtils.AddFieldValueToString( ref nodeInfo, m_enable );
  334. }
  335. public bool Enabled { get { return m_enable; } }
  336. }
  337. }