@babylonjs/smart-filters 1.0.13 → 8.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/dist/blockFoundation/aggregateBlock.d.ts +3 -3
  2. package/dist/blockFoundation/aggregateBlock.d.ts.map +1 -1
  3. package/dist/blockFoundation/aggregateBlock.js +1 -2
  4. package/dist/blockFoundation/aggregateBlock.js.map +1 -1
  5. package/dist/blockFoundation/baseBlock.d.ts +2 -2
  6. package/dist/blockFoundation/baseBlock.d.ts.map +1 -1
  7. package/dist/blockFoundation/baseBlock.js +5 -6
  8. package/dist/blockFoundation/baseBlock.js.map +1 -1
  9. package/dist/blockFoundation/customAggregateBlock.d.ts.map +1 -1
  10. package/dist/blockFoundation/customAggregateBlock.js +2 -2
  11. package/dist/blockFoundation/customAggregateBlock.js.map +1 -1
  12. package/dist/blockFoundation/customShaderBlock.d.ts +9 -0
  13. package/dist/blockFoundation/customShaderBlock.d.ts.map +1 -1
  14. package/dist/blockFoundation/customShaderBlock.js +47 -7
  15. package/dist/blockFoundation/customShaderBlock.js.map +1 -1
  16. package/dist/blockFoundation/disableableShaderBlock.d.ts.map +1 -1
  17. package/dist/blockFoundation/disableableShaderBlock.js +4 -4
  18. package/dist/blockFoundation/disableableShaderBlock.js.map +1 -1
  19. package/dist/blockFoundation/index.js +0 -2
  20. package/dist/blockFoundation/index.js.map +1 -1
  21. package/dist/blockFoundation/inputBlock.d.ts +8 -8
  22. package/dist/blockFoundation/inputBlock.d.ts.map +1 -1
  23. package/dist/blockFoundation/inputBlock.deserializer.d.ts +1 -1
  24. package/dist/blockFoundation/inputBlock.deserializer.d.ts.map +1 -1
  25. package/dist/blockFoundation/inputBlock.deserializer.js +1 -1
  26. package/dist/blockFoundation/inputBlock.deserializer.js.map +1 -1
  27. package/dist/blockFoundation/inputBlock.js +7 -7
  28. package/dist/blockFoundation/inputBlock.js.map +1 -1
  29. package/dist/blockFoundation/inputBlock.serialization.types.d.ts.map +1 -1
  30. package/dist/blockFoundation/inputBlock.serializer.d.ts +1 -1
  31. package/dist/blockFoundation/inputBlock.serializer.js +26 -28
  32. package/dist/blockFoundation/inputBlock.serializer.js.map +1 -1
  33. package/dist/blockFoundation/outputBlock.d.ts +4 -9
  34. package/dist/blockFoundation/outputBlock.d.ts.map +1 -1
  35. package/dist/blockFoundation/outputBlock.js +13 -14
  36. package/dist/blockFoundation/outputBlock.js.map +1 -1
  37. package/dist/blockFoundation/shaderBlock.d.ts +4 -4
  38. package/dist/blockFoundation/shaderBlock.d.ts.map +1 -1
  39. package/dist/blockFoundation/shaderBlock.js +13 -19
  40. package/dist/blockFoundation/shaderBlock.js.map +1 -1
  41. package/dist/blockFoundation/textureOptions.d.ts +1 -1
  42. package/dist/blockFoundation/textureOptions.js +1 -1
  43. package/dist/command/command.d.ts +1 -1
  44. package/dist/command/command.js +1 -1
  45. package/dist/command/commandBuffer.d.ts +1 -1
  46. package/dist/command/commandBuffer.d.ts.map +1 -1
  47. package/dist/command/commandBuffer.js +2 -2
  48. package/dist/command/commandBufferDebugger.d.ts +2 -2
  49. package/dist/command/commandBufferDebugger.d.ts.map +1 -1
  50. package/dist/command/commandBufferDebugger.js +1 -1
  51. package/dist/command/commandBufferDebugger.js.map +1 -1
  52. package/dist/command/index.d.ts +3 -1
  53. package/dist/command/index.d.ts.map +1 -1
  54. package/dist/command/index.js +5 -1
  55. package/dist/command/index.js.map +1 -1
  56. package/dist/connection/connectionPoint.d.ts +3 -3
  57. package/dist/connection/connectionPoint.d.ts.map +1 -1
  58. package/dist/connection/connectionPoint.js +2 -2
  59. package/dist/connection/connectionPoint.js.map +1 -1
  60. package/dist/connection/connectionPointCompatibilityState.d.ts +1 -1
  61. package/dist/connection/connectionPointCompatibilityState.js +1 -1
  62. package/dist/connection/connectionPointType.d.ts +3 -3
  63. package/dist/connection/connectionPointType.d.ts.map +1 -1
  64. package/dist/connection/connectionPointWithDefault.d.ts +3 -3
  65. package/dist/connection/connectionPointWithDefault.d.ts.map +1 -1
  66. package/dist/connection/connectionPointWithDefault.js.map +1 -1
  67. package/dist/connection/index.d.ts +2 -1
  68. package/dist/connection/index.d.ts.map +1 -1
  69. package/dist/connection/index.js +3 -3
  70. package/dist/connection/index.js.map +1 -1
  71. package/dist/editorUtils/editableInPropertyPage.d.ts +2 -2
  72. package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -1
  73. package/dist/editorUtils/editableInPropertyPage.js +2 -2
  74. package/dist/editorUtils/editableInPropertyPage.js.map +1 -1
  75. package/dist/editorUtils/index.d.ts +1 -0
  76. package/dist/editorUtils/index.d.ts.map +1 -1
  77. package/dist/editorUtils/index.js +2 -0
  78. package/dist/editorUtils/index.js.map +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +1 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/optimization/dependencyGraph.js.map +1 -1
  83. package/dist/optimization/optimizedShaderBlock.d.ts +4 -4
  84. package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -1
  85. package/dist/optimization/optimizedShaderBlock.js.map +1 -1
  86. package/dist/optimization/smartFilterOptimizer.d.ts +2 -2
  87. package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -1
  88. package/dist/optimization/smartFilterOptimizer.js +34 -57
  89. package/dist/optimization/smartFilterOptimizer.js.map +1 -1
  90. package/dist/runtime/index.d.ts +2 -1
  91. package/dist/runtime/index.d.ts.map +1 -1
  92. package/dist/runtime/index.js +3 -3
  93. package/dist/runtime/index.js.map +1 -1
  94. package/dist/runtime/renderTargetGenerator.d.ts +1 -1
  95. package/dist/runtime/renderTargetGenerator.d.ts.map +1 -1
  96. package/dist/runtime/renderTargetGenerator.js +5 -7
  97. package/dist/runtime/renderTargetGenerator.js.map +1 -1
  98. package/dist/runtime/shaderRuntime.d.ts +7 -7
  99. package/dist/runtime/shaderRuntime.d.ts.map +1 -1
  100. package/dist/runtime/shaderRuntime.js +7 -8
  101. package/dist/runtime/shaderRuntime.js.map +1 -1
  102. package/dist/runtime/smartFilterRuntime.d.ts +3 -3
  103. package/dist/runtime/smartFilterRuntime.d.ts.map +1 -1
  104. package/dist/runtime/smartFilterRuntime.js.map +1 -1
  105. package/dist/runtime/strongRef.d.ts +1 -1
  106. package/dist/runtime/strongRef.js +1 -1
  107. package/dist/serialization/importCustomBlockDefinition.d.ts +1 -1
  108. package/dist/serialization/importCustomBlockDefinition.js +8 -9
  109. package/dist/serialization/importCustomBlockDefinition.js.map +1 -1
  110. package/dist/serialization/index.d.ts +1 -0
  111. package/dist/serialization/index.d.ts.map +1 -1
  112. package/dist/serialization/index.js +3 -0
  113. package/dist/serialization/index.js.map +1 -1
  114. package/dist/serialization/serializedBlockDefinition.d.ts +2 -2
  115. package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -1
  116. package/dist/serialization/serializedShaderBlockDefinition.d.ts +1 -1
  117. package/dist/serialization/serializedShaderBlockDefinition.d.ts.map +1 -1
  118. package/dist/serialization/serializedSmartFilter.d.ts +1 -1
  119. package/dist/serialization/serializedSmartFilter.d.ts.map +1 -1
  120. package/dist/serialization/smartFilterDeserializer.d.ts +6 -6
  121. package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -1
  122. package/dist/serialization/smartFilterDeserializer.js +9 -12
  123. package/dist/serialization/smartFilterDeserializer.js.map +1 -1
  124. package/dist/serialization/smartFilterSerializer.d.ts +2 -2
  125. package/dist/serialization/smartFilterSerializer.d.ts.map +1 -1
  126. package/dist/serialization/smartFilterSerializer.js +10 -13
  127. package/dist/serialization/smartFilterSerializer.js.map +1 -1
  128. package/dist/serialization/v1/defaultBlockSerializer.d.ts +2 -2
  129. package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -1
  130. package/dist/serialization/v1/defaultBlockSerializer.js +1 -1
  131. package/dist/serialization/v1/index.d.ts +1 -0
  132. package/dist/serialization/v1/index.d.ts.map +1 -1
  133. package/dist/serialization/v1/index.js +2 -0
  134. package/dist/serialization/v1/index.js.map +1 -1
  135. package/dist/serialization/v1/shaderBlockSerialization.types.d.ts +3 -3
  136. package/dist/serialization/v1/shaderBlockSerialization.types.d.ts.map +1 -1
  137. package/dist/serialization/v1/smartFilterSerialization.types.d.ts +2 -2
  138. package/dist/serialization/v1/smartFilterSerialization.types.d.ts.map +1 -1
  139. package/dist/smartFilter.d.ts +8 -8
  140. package/dist/smartFilter.d.ts.map +1 -1
  141. package/dist/smartFilter.js +6 -7
  142. package/dist/smartFilter.js.map +1 -1
  143. package/dist/utils/buildTools/buildShaders.d.ts +3 -2
  144. package/dist/utils/buildTools/buildShaders.d.ts.map +1 -1
  145. package/dist/utils/buildTools/buildShaders.js +7 -6
  146. package/dist/utils/buildTools/buildShaders.js.map +1 -1
  147. package/dist/utils/buildTools/convertGlslIntoBlock.d.ts +4 -2
  148. package/dist/utils/buildTools/convertGlslIntoBlock.d.ts.map +1 -1
  149. package/dist/utils/buildTools/convertGlslIntoBlock.js +136 -141
  150. package/dist/utils/buildTools/convertGlslIntoBlock.js.map +1 -1
  151. package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts +4 -4
  152. package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts.map +1 -1
  153. package/dist/utils/buildTools/convertGlslIntoShaderProgram.js +55 -48
  154. package/dist/utils/buildTools/convertGlslIntoShaderProgram.js.map +1 -1
  155. package/dist/utils/buildTools/convertShaders.d.ts +8 -5
  156. package/dist/utils/buildTools/convertShaders.d.ts.map +1 -1
  157. package/dist/utils/buildTools/convertShaders.js +38 -14
  158. package/dist/utils/buildTools/convertShaders.js.map +1 -1
  159. package/dist/utils/buildTools/shaderConverter.d.ts +4 -4
  160. package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -1
  161. package/dist/utils/buildTools/shaderConverter.js +17 -21
  162. package/dist/utils/buildTools/shaderConverter.js.map +1 -1
  163. package/dist/utils/buildTools/watchShaders.d.ts +3 -2
  164. package/dist/utils/buildTools/watchShaders.d.ts.map +1 -1
  165. package/dist/utils/buildTools/watchShaders.js +10 -8
  166. package/dist/utils/buildTools/watchShaders.js.map +1 -1
  167. package/dist/utils/index.d.ts +1 -0
  168. package/dist/utils/index.d.ts.map +1 -1
  169. package/dist/utils/index.js +2 -1
  170. package/dist/utils/index.js.map +1 -1
  171. package/dist/utils/renderTargetUtils.d.ts +3 -3
  172. package/dist/utils/renderTargetUtils.d.ts.map +1 -1
  173. package/dist/utils/renderTargetUtils.js +4 -4
  174. package/dist/utils/renderTargetUtils.js.map +1 -1
  175. package/dist/utils/shaderCodeUtils.d.ts +8 -8
  176. package/dist/utils/shaderCodeUtils.d.ts.map +1 -1
  177. package/dist/utils/shaderCodeUtils.js +16 -28
  178. package/dist/utils/shaderCodeUtils.js.map +1 -1
  179. package/dist/utils/textureLoaders.d.ts +2 -2
  180. package/dist/utils/textureLoaders.d.ts.map +1 -1
  181. package/dist/utils/textureLoaders.js +2 -3
  182. package/dist/utils/textureLoaders.js.map +1 -1
  183. package/dist/utils/textureUtils.d.ts +5 -5
  184. package/dist/utils/textureUtils.d.ts.map +1 -1
  185. package/dist/utils/textureUtils.js +1 -1
  186. package/dist/utils/textureUtils.js.map +1 -1
  187. package/dist/version.d.ts +2 -2
  188. package/dist/version.js +2 -2
  189. package/license.md +21 -21
  190. package/package.json +13 -8
  191. package/src/blockFoundation/aggregateBlock.ts +148 -151
  192. package/src/blockFoundation/baseBlock.ts +339 -364
  193. package/src/blockFoundation/customAggregateBlock.ts +88 -104
  194. package/src/blockFoundation/customShaderBlock.ts +362 -326
  195. package/src/blockFoundation/disableableShaderBlock.ts +91 -100
  196. package/src/blockFoundation/index.ts +9 -9
  197. package/src/blockFoundation/inputBlock.deserializer.ts +72 -97
  198. package/src/blockFoundation/inputBlock.serialization.types.ts +126 -132
  199. package/src/blockFoundation/inputBlock.serializer.ts +150 -150
  200. package/src/blockFoundation/inputBlock.ts +181 -192
  201. package/src/blockFoundation/outputBlock.ts +144 -151
  202. package/src/blockFoundation/shaderBlock.ts +156 -163
  203. package/src/blockFoundation/textureOptions.ts +57 -57
  204. package/src/command/command.ts +59 -59
  205. package/src/command/commandBuffer.ts +71 -71
  206. package/src/command/commandBufferDebugger.ts +14 -14
  207. package/src/command/index.ts +7 -3
  208. package/src/connection/connectionPoint.ts +205 -214
  209. package/src/connection/connectionPointCompatibilityState.ts +31 -31
  210. package/src/connection/connectionPointType.ts +45 -45
  211. package/src/connection/connectionPointWithDefault.ts +27 -35
  212. package/src/connection/index.ts +8 -9
  213. package/src/editorUtils/editableInPropertyPage.ts +106 -106
  214. package/src/editorUtils/index.ts +3 -1
  215. package/src/index.ts +16 -15
  216. package/src/optimization/dependencyGraph.ts +96 -96
  217. package/src/optimization/index.ts +1 -1
  218. package/src/optimization/optimizedShaderBlock.ts +131 -134
  219. package/src/optimization/smartFilterOptimizer.ts +757 -825
  220. package/src/runtime/index.ts +8 -6
  221. package/src/runtime/renderTargetGenerator.ts +222 -248
  222. package/src/runtime/shaderRuntime.ts +174 -173
  223. package/src/runtime/smartFilterRuntime.ts +112 -112
  224. package/src/runtime/strongRef.ts +18 -18
  225. package/src/serialization/importCustomBlockDefinition.ts +86 -86
  226. package/src/serialization/index.ts +10 -7
  227. package/src/serialization/serializedBlockDefinition.ts +12 -12
  228. package/src/serialization/serializedShaderBlockDefinition.ts +7 -7
  229. package/src/serialization/serializedSmartFilter.ts +6 -6
  230. package/src/serialization/smartFilterDeserializer.ts +190 -220
  231. package/src/serialization/smartFilterSerializer.ts +110 -121
  232. package/src/serialization/v1/defaultBlockSerializer.ts +21 -21
  233. package/src/serialization/v1/index.ts +4 -2
  234. package/src/serialization/v1/shaderBlockSerialization.types.ts +85 -85
  235. package/src/serialization/v1/smartFilterSerialization.types.ts +129 -133
  236. package/src/smartFilter.ts +255 -260
  237. package/src/utils/buildTools/buildShaders.ts +14 -13
  238. package/src/utils/buildTools/convertGlslIntoBlock.ts +370 -385
  239. package/src/utils/buildTools/convertGlslIntoShaderProgram.ts +173 -172
  240. package/src/utils/buildTools/convertShaders.ts +65 -43
  241. package/src/utils/buildTools/recordVersionNumber.js +24 -0
  242. package/src/utils/buildTools/shaderConverter.ts +466 -478
  243. package/src/utils/buildTools/watchShaders.ts +44 -42
  244. package/src/utils/index.ts +4 -2
  245. package/src/utils/renderTargetUtils.ts +30 -35
  246. package/src/utils/shaderCodeUtils.ts +192 -207
  247. package/src/utils/textureLoaders.ts +31 -43
  248. package/src/utils/textureUtils.ts +28 -32
  249. package/src/version.ts +2 -2
  250. package/dist/utils/buildTools/determineVersion.d.ts +0 -36
  251. package/dist/utils/buildTools/determineVersion.d.ts.map +0 -1
  252. package/dist/utils/buildTools/determineVersion.js +0 -109
  253. package/dist/utils/buildTools/determineVersion.js.map +0 -1
  254. package/dist/utils/buildTools/versionUp.d.ts +0 -2
  255. package/dist/utils/buildTools/versionUp.d.ts.map +0 -1
  256. package/dist/utils/buildTools/versionUp.js +0 -53
  257. package/dist/utils/buildTools/versionUp.js.map +0 -1
  258. package/src/utils/buildTools/determineVersion.ts +0 -128
  259. package/src/utils/buildTools/versionUp.ts +0 -61
@@ -1,385 +1,370 @@
1
- import * as fs from "fs";
2
- import { extractShaderProgramFromGlsl } from "./convertGlslIntoShaderProgram.js";
3
- import { ConnectionPointType } from "../../connection/connectionPointType.js";
4
- import { BlockDisableStrategy } from "../../blockFoundation/disableableShaderBlock.js";
5
-
6
- const EXTRA_IMPORTS = "@EXTRA_IMPORTS@";
7
- const SHADER_PROGRAM = "@SHADER_PROGRAM@";
8
- const BLOCK_NAME = "@BLOCK_NAME@";
9
- const NAMESPACE = "@NAMESPACE@";
10
- const SHADER_BINDING_PRIVATE_VARIABLES = "@SHADER_BINDING_PRIVATE_VARIABLES@";
11
- const CAMEL_CASE_UNIFORM = "@CAMEL_CASE_UNIFORM@";
12
- const CONNECTION_POINT_TYPE = "@CONNECTION_POINT_TYPE@";
13
- const CONNECTION_POINT_DEFAULT_VALUE = "@CONNECTION_POINT_DEFAULT_VALUE@";
14
- const SHADER_BINDING_EXTENDS = "@SHADER_BINDING_EXTENDS@";
15
- const SHADER_BINDING_CTOR_DOCSTRING_PARAMS = "@SHADER_BINDING_CTOR_DOCSTRING_PARAMS@";
16
- const SHADER_BINDING_CTOR_PARAMS = "@SHADER_CTOR_PARAMS@";
17
- const SHADER_BINDING_SUPER_PARAMS = "@SHADER_BINDING_SUPER_PARAMS@";
18
- const SHADER_BINDING_CTOR = "@SHADER_BINDING_CTOR@";
19
- const SHADER_BINDING_BIND = "@SHADER_BINDING_BIND@";
20
- const SHADER_BLOCK_EXTENDS = "@SHADER_BLOCK_EXTENDS@";
21
- const BLOCK_INPUT_PROPERTIES = "@BLOCK_INPUT_PROPERTIES@";
22
- const BLOCK_DISABLE_OPTIMIZATION = "@BLOCK_DISABLE_OPTIMIZATION@";
23
- const BLOCK_DISABLE_STRATEGY = "@BLOCK_DISABLE_STRATEGY@";
24
- const BLOCK_GET_SHADER_BINDING_VARS = "@BLOCK_SHADER_BINDING_BIND_VARS@";
25
- const BLOCK_GET_SHADER_PARAM_LIST = "@BLOCK_GET_SHADER_PARAM_LIST@";
26
- const EFFECT_SETTER = "@EFFECT_SETTER@";
27
- const EFFECT_VALUE = "@EFFECT_VALUE@";
28
- const EXTRA_BIND_DOCSTRING = "@EXTRA_BIND_DOCSTRING@";
29
- const EXTRA_BIND_PARAMS = "@EXTRA_BIND_PARAMS@";
30
-
31
- const ShaderBindingPrivateVariablesTemplate = ` private readonly _${CAMEL_CASE_UNIFORM}: RuntimeData<ConnectionPointType.${CONNECTION_POINT_TYPE}>;`;
32
- const ShaderBindingCtorDocstringParams = ` * @param ${CAMEL_CASE_UNIFORM} - The ${CAMEL_CASE_UNIFORM} runtime value`;
33
- const ShaderBindingCtorParams = ` ${CAMEL_CASE_UNIFORM}: RuntimeData<ConnectionPointType.${CONNECTION_POINT_TYPE}>`;
34
- const ShaderBindingCtor = ` this._${CAMEL_CASE_UNIFORM} = ${CAMEL_CASE_UNIFORM};`;
35
- const ShaderBindingBind = ` effect.${EFFECT_SETTER}(this.getRemappedName(uniforms.${CAMEL_CASE_UNIFORM}), ${EFFECT_VALUE});`;
36
- const ShaderBindingBindRegularValue = `this._${CAMEL_CASE_UNIFORM}.value`;
37
-
38
- const BlockInputProperty = ` /**
39
- * The ${CAMEL_CASE_UNIFORM} connection point.
40
- */
41
- public readonly ${CAMEL_CASE_UNIFORM} = this._registerInput(uniforms.${CAMEL_CASE_UNIFORM}, ConnectionPointType.${CONNECTION_POINT_TYPE});
42
- `;
43
- const BlockInputOptionalProperty = ` /**
44
- /**
45
- * The ${CAMEL_CASE_UNIFORM} connection point.
46
- */
47
- public readonly ${CAMEL_CASE_UNIFORM} = this._registerOptionalInput(
48
- "${CAMEL_CASE_UNIFORM}",
49
- ConnectionPointType.${CONNECTION_POINT_TYPE},
50
- createStrongRef(${CONNECTION_POINT_DEFAULT_VALUE})
51
- );
52
- `;
53
- const BlockGetShaderBindingVars = ` const ${CAMEL_CASE_UNIFORM} = this._confirmRuntimeDataSupplied(this.${CAMEL_CASE_UNIFORM});`;
54
-
55
- const FileTemplate = `/* eslint-disable prettier/prettier */
56
- // ************************************************************
57
- // Note: this file is auto-generated, do not modify it directly
58
- // ************************************************************
59
-
60
- // It was generated by convertGlslIntoBlock() from
61
- // an annotated .glsl file. Modify the .glsl file to make changes
62
- // to the block. This file will get overwritten when the build
63
- // is run or during a watch when the .glsl file is updated.
64
-
65
- import type { Effect } from "@babylonjs/core/Materials/effect";
66
-
67
- import {
68
- ${SHADER_BINDING_EXTENDS},
69
- type RuntimeData,
70
- ConnectionPointType,
71
- type SmartFilter,
72
- ${SHADER_BLOCK_EXTENDS},
73
- type ShaderProgram,
74
- ${EXTRA_IMPORTS}} from "@babylonjs/smart-filters";${SHADER_PROGRAM}
75
- /**
76
- * The shader binding for the ${BLOCK_NAME}, used by the runtime
77
- */
78
- class ${BLOCK_NAME}ShaderBinding extends ${SHADER_BINDING_EXTENDS} {
79
- ${SHADER_BINDING_PRIVATE_VARIABLES}
80
-
81
- /**
82
- * Creates a new shader binding instance for the block.
83
- ${SHADER_BINDING_CTOR_DOCSTRING_PARAMS}
84
- */
85
- constructor(
86
- ${SHADER_BINDING_CTOR_PARAMS}
87
- ) {
88
- super(${SHADER_BINDING_SUPER_PARAMS});
89
- ${SHADER_BINDING_CTOR}
90
- }
91
-
92
- /**
93
- * Binds all the required data to the shader when rendering.
94
- * @param effect - defines the effect to bind the data to${EXTRA_BIND_DOCSTRING}
95
- */
96
- public override bind(effect: Effect${EXTRA_BIND_PARAMS}): void {
97
- ${SHADER_BINDING_BIND}
98
- }
99
- }
100
-
101
- /**
102
- * The implementation of the ${BLOCK_NAME}
103
- */
104
- export class ${BLOCK_NAME} extends ${SHADER_BLOCK_EXTENDS} {
105
- /**
106
- * The class name of the block.
107
- */
108
- public static override ClassName = "${BLOCK_NAME}";
109
-
110
- /**
111
- * The namespace of the block.
112
- */
113
- public static override Namespace = "${NAMESPACE}";
114
-
115
- ${BLOCK_INPUT_PROPERTIES}
116
- /**
117
- * The shader program (vertex and fragment code) to use to render the block
118
- */
119
- public static override ShaderCode = shaderProgram;
120
-
121
- /**
122
- * Instantiates a new ${BLOCK_NAME}.
123
- * @param smartFilter - The smart filter this block belongs to
124
- * @param name - The friendly name of the block
125
- */
126
- constructor(smartFilter: SmartFilter, name: string) {
127
- super(smartFilter, name, ${BLOCK_DISABLE_OPTIMIZATION}${BLOCK_DISABLE_STRATEGY});
128
- }
129
-
130
- /**
131
- * Get the class instance that binds all the required data to the shader (effect) when rendering.
132
- * @returns The class instance that binds the data to the effect
133
- */
134
- public getShaderBinding(): ${SHADER_BINDING_EXTENDS} {
135
- ${BLOCK_GET_SHADER_BINDING_VARS}
136
-
137
- return new ${BLOCK_NAME}ShaderBinding(${BLOCK_GET_SHADER_PARAM_LIST});
138
- }
139
- }
140
-
141
- `;
142
-
143
- /**
144
- * Converts a single shader to a .ts file which exports a Smart Filter block
145
- * @param fragmentShaderPath - The path to the fragment file for the shader
146
- * @param importPath - The path to import the ShaderProgram type from
147
- */
148
- export function convertGlslIntoBlock(fragmentShaderPath: string, importPath: string): void {
149
- const extraImports: string[] = [];
150
-
151
- const { shaderProgramCode, fragmentShaderInfo } = extractShaderProgramFromGlsl(
152
- fragmentShaderPath,
153
- importPath,
154
- false,
155
- false
156
- );
157
-
158
- // Validation
159
- if (!fragmentShaderInfo.blockType) {
160
- throw new Error("The glsl file must contain a header comment with a smartFilterBlockType value");
161
- }
162
-
163
- // Generate shader binding private variables
164
- const shaderBindingPrivateVariables = fragmentShaderInfo.uniforms
165
- .map((uniform) => {
166
- return uniform.properties?.autoBind
167
- ? null
168
- : ShaderBindingPrivateVariablesTemplate.replace(CAMEL_CASE_UNIFORM, uniform.name).replace(
169
- CONNECTION_POINT_TYPE,
170
- getConnectionPointTypeString(uniform.type)
171
- );
172
- })
173
- .filter((line) => line !== null);
174
-
175
- // Generate the shader binding constructor docstring params
176
- const shaderBindingCtorDocstringParams = fragmentShaderInfo.uniforms
177
- .map((uniform) => {
178
- return uniform.properties?.autoBind
179
- ? null
180
- : ShaderBindingCtorDocstringParams.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
181
- })
182
- .filter((param) => param !== null);
183
-
184
- // Generate the shader binding constructor params
185
- const shaderBindingCtorParams = fragmentShaderInfo.uniforms
186
- .map((uniform) => {
187
- return uniform.properties?.autoBind
188
- ? null
189
- : ShaderBindingCtorParams.replace(CAMEL_CASE_UNIFORM, uniform.name).replace(
190
- CONNECTION_POINT_TYPE,
191
- getConnectionPointTypeString(uniform.type)
192
- );
193
- })
194
- .filter((param) => param !== null);
195
-
196
- // Generate the shader binding constructor
197
- const shaderBindingCtor = fragmentShaderInfo.uniforms
198
- .map((uniform) => {
199
- return uniform.properties?.autoBind
200
- ? null
201
- : ShaderBindingCtor.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
202
- })
203
- .filter((line) => line !== null);
204
-
205
- // Generate the shader binding bind
206
- let needWidthHeightParams = false;
207
- const shaderBindingBind = fragmentShaderInfo.uniforms.map((uniform) => {
208
- let effectValue: string;
209
- let effectSetter = getEffectSetter(uniform.type);
210
-
211
- switch (uniform.properties?.autoBind) {
212
- case "outputResolution":
213
- {
214
- effectValue = "width, height";
215
- effectSetter = "setFloat2";
216
- needWidthHeightParams = true;
217
- }
218
- break;
219
- case "outputAspectRatio":
220
- {
221
- effectValue = "width / height, height / width";
222
- effectSetter = "setFloat2";
223
- needWidthHeightParams = true;
224
- }
225
- break;
226
- default:
227
- effectValue = ShaderBindingBindRegularValue;
228
- }
229
- return ShaderBindingBind.replace(EFFECT_VALUE, effectValue)
230
- .replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name)
231
- .replace(EFFECT_SETTER, effectSetter);
232
- });
233
-
234
- // Add extra params to the bind method if needed
235
- let extraBindParams = "";
236
- let extraBindDocstring = "";
237
- if (needWidthHeightParams) {
238
- extraBindDocstring = `
239
- * @param width - defines the width of the output
240
- * @param height - defines the height of the output`;
241
- extraBindParams = `, width: number, height: number`;
242
- }
243
-
244
- // Generate the block input properties
245
- const blockInputProperties = fragmentShaderInfo.uniforms
246
- .map((uniform) => {
247
- if (uniform.properties?.autoBind) {
248
- return null;
249
- } else if (uniform.properties?.default !== undefined) {
250
- if (extraImports.indexOf(" createStrongRef") === -1) {
251
- extraImports.push(" createStrongRef");
252
- }
253
- return BlockInputOptionalProperty.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name)
254
- .replace(CONNECTION_POINT_TYPE, getConnectionPointTypeString(uniform.type))
255
- .replace(CONNECTION_POINT_DEFAULT_VALUE, uniform.properties.default);
256
- } else {
257
- return BlockInputProperty.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name).replace(
258
- CONNECTION_POINT_TYPE,
259
- getConnectionPointTypeString(uniform.type)
260
- );
261
- }
262
- })
263
- .filter((property) => property !== null);
264
-
265
- // Generate the block get shader binding vars
266
- const blockGetShaderBindingVars = fragmentShaderInfo.uniforms
267
- .map((uniform) => {
268
- return uniform.properties?.autoBind
269
- ? null
270
- : BlockGetShaderBindingVars.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
271
- })
272
- .filter((line) => line !== null);
273
-
274
- // Handle the disable optimization flag
275
- const disableOptimization = fragmentShaderInfo.disableOptimization === true ? "true" : "false";
276
-
277
- // Generate the block get shader param list
278
- const blockGetShaderParamList = fragmentShaderInfo.uniforms
279
- .map((uniform) => {
280
- return uniform.properties?.autoBind ? null : uniform.name;
281
- })
282
- .filter((param) => param !== null);
283
-
284
- // Decide if this is a disableable block or not
285
- let shaderBlockExtends = "ShaderBlock";
286
- let shaderBindingExtends = "ShaderBinding";
287
- let blockDisableStrategy = "";
288
- let shaderBindingSuperParams = "";
289
- if (fragmentShaderInfo.blockDisableStrategy) {
290
- shaderBlockExtends = "DisableableShaderBlock";
291
- shaderBindingExtends = "DisableableShaderBinding";
292
- blockDisableStrategy = `, BlockDisableStrategy.${BlockDisableStrategy[fragmentShaderInfo.blockDisableStrategy]}`;
293
- shaderBindingSuperParams = "parentBlock";
294
-
295
- shaderBindingCtorDocstringParams.unshift(" * @param parentBlock - IDisableableBlock");
296
- shaderBindingCtorParams.unshift(" parentBlock: IDisableableBlock");
297
- blockGetShaderParamList.unshift("this");
298
-
299
- extraImports.push(" type IDisableableBlock");
300
- extraImports.push(" BlockDisableStrategy");
301
-
302
- shaderBindingBind.unshift(" super.bind(effect);");
303
- }
304
-
305
- // Additional validation
306
- if (
307
- fragmentShaderInfo.blockDisableStrategy !== undefined &&
308
- fragmentShaderInfo.blockDisableStrategy !== BlockDisableStrategy.Manual
309
- ) {
310
- if (fragmentShaderInfo.uniforms.findIndex((uniform) => uniform.name === "disabled") !== -1) {
311
- throw new Error(
312
- "A block that uses a BlockDisableStrategy other than Manual should not declare its own 'disabled' uniform"
313
- );
314
- }
315
- }
316
-
317
- // Generate final contents
318
- const finalContents = FileTemplate.replace(SHADER_PROGRAM, shaderProgramCode)
319
- .replace(EXTRA_IMPORTS, extraImports.join(",\n"))
320
- .replace(new RegExp(BLOCK_NAME, "g"), fragmentShaderInfo.blockType)
321
- .replace(NAMESPACE, fragmentShaderInfo.namespace || "Other")
322
- .replace(new RegExp(SHADER_BINDING_EXTENDS, "g"), shaderBindingExtends)
323
- .replace(SHADER_BINDING_PRIVATE_VARIABLES, shaderBindingPrivateVariables.join("\n"))
324
- .replace(SHADER_BINDING_CTOR_DOCSTRING_PARAMS, shaderBindingCtorDocstringParams.join("\n"))
325
- .replace(SHADER_BINDING_CTOR_PARAMS, shaderBindingCtorParams.join(",\n"))
326
- .replace(SHADER_BINDING_CTOR, shaderBindingCtor.join("\n"))
327
- .replace(SHADER_BINDING_SUPER_PARAMS, shaderBindingSuperParams)
328
- .replace(SHADER_BINDING_BIND, shaderBindingBind.join("\n"))
329
- .replace(EXTRA_BIND_DOCSTRING, extraBindDocstring)
330
- .replace(EXTRA_BIND_PARAMS, extraBindParams)
331
- .replace(new RegExp(SHADER_BLOCK_EXTENDS, "g"), shaderBlockExtends)
332
- .replace(BLOCK_INPUT_PROPERTIES, blockInputProperties.join("\n"))
333
- .replace(BLOCK_DISABLE_OPTIMIZATION, disableOptimization)
334
- .replace(BLOCK_DISABLE_STRATEGY, blockDisableStrategy)
335
- .replace(BLOCK_GET_SHADER_BINDING_VARS, blockGetShaderBindingVars.join("\n"))
336
- .replace(BLOCK_GET_SHADER_PARAM_LIST, blockGetShaderParamList.join(","));
337
-
338
- // Write the block class TS file
339
- const outputFullPathAndFileName = fragmentShaderPath.replace(".glsl", ".ts");
340
- fs.writeFileSync(outputFullPathAndFileName, finalContents);
341
- }
342
-
343
- /**
344
- * Get the string representation of a connection point type
345
- * @param type - The connection point type
346
- * @returns - The string representation of the connection point type
347
- */
348
- function getConnectionPointTypeString(type: ConnectionPointType): string {
349
- switch (type) {
350
- case ConnectionPointType.Float:
351
- return "Float";
352
- case ConnectionPointType.Texture:
353
- return "Texture";
354
- case ConnectionPointType.Color3:
355
- return "Color3";
356
- case ConnectionPointType.Color4:
357
- return "Color4";
358
- case ConnectionPointType.Vector2:
359
- return "Vector2";
360
- case ConnectionPointType.Boolean:
361
- return "Boolean";
362
- }
363
- }
364
-
365
- /**
366
- * Get the effect setter for a connection point type
367
- * @param type - The connection point type
368
- * @returns - The effect setter for the connection point type
369
- */
370
- function getEffectSetter(type: ConnectionPointType): string {
371
- switch (type) {
372
- case ConnectionPointType.Float:
373
- return "setFloat";
374
- case ConnectionPointType.Texture:
375
- return "setTexture";
376
- case ConnectionPointType.Color3:
377
- return "setColor3";
378
- case ConnectionPointType.Color4:
379
- return "setDirectColor4";
380
- case ConnectionPointType.Vector2:
381
- return "setVector2";
382
- case ConnectionPointType.Boolean:
383
- return "setBool";
384
- }
385
- }
1
+ import * as fs from "fs";
2
+ import { ExtractShaderProgramFromGlsl } from "./convertGlslIntoShaderProgram.js";
3
+ import { ConnectionPointType } from "../../connection/connectionPointType.js";
4
+ import { BlockDisableStrategy } from "../../blockFoundation/disableableShaderBlock.js";
5
+
6
+ // eslint-disable-next-line @typescript-eslint/naming-convention
7
+ const EXTRA_IMPORTS = "@EXTRA_IMPORTS@";
8
+ // eslint-disable-next-line @typescript-eslint/naming-convention
9
+ const BABYLON_CORE_PATH = "@BABYLON_CORE_PATH@";
10
+ // eslint-disable-next-line @typescript-eslint/naming-convention
11
+ const SMART_FILTER_CORE_IMPORT = "@SMART_FILTER_CORE_IMPORT@";
12
+ const SHADER_PROGRAM = "@SHADER_PROGRAM@";
13
+ const BLOCK_NAME = "@BLOCK_NAME@";
14
+ const NAMESPACE = "@NAMESPACE@";
15
+ // eslint-disable-next-line @typescript-eslint/naming-convention
16
+ const SHADER_BINDING_PRIVATE_VARIABLES = "@SHADER_BINDING_PRIVATE_VARIABLES@";
17
+ const CAMEL_CASE_UNIFORM = "@CAMEL_CASE_UNIFORM@";
18
+ const CONNECTION_POINT_TYPE = "@CONNECTION_POINT_TYPE@";
19
+ const CONNECTION_POINT_DEFAULT_VALUE = "@CONNECTION_POINT_DEFAULT_VALUE@";
20
+ const SHADER_BINDING_EXTENDS = "@SHADER_BINDING_EXTENDS@";
21
+ const SHADER_BINDING_CTOR_DOCSTRING_PARAMS = "@SHADER_BINDING_CTOR_DOCSTRING_PARAMS@";
22
+ const SHADER_BINDING_CTOR_PARAMS = "@SHADER_CTOR_PARAMS@";
23
+ const SHADER_BINDING_SUPER_PARAMS = "@SHADER_BINDING_SUPER_PARAMS@";
24
+ const SHADER_BINDING_CTOR = "@SHADER_BINDING_CTOR@";
25
+ const SHADER_BINDING_BIND = "@SHADER_BINDING_BIND@";
26
+ const SHADER_BLOCK_EXTENDS = "@SHADER_BLOCK_EXTENDS@";
27
+ // eslint-disable-next-line @typescript-eslint/naming-convention
28
+ const BLOCK_INPUT_PROPERTIES = "@BLOCK_INPUT_PROPERTIES@";
29
+ // eslint-disable-next-line @typescript-eslint/naming-convention
30
+ const BLOCK_DISABLE_OPTIMIZATION = "@BLOCK_DISABLE_OPTIMIZATION@";
31
+ const BLOCK_DISABLE_STRATEGY = "@BLOCK_DISABLE_STRATEGY@";
32
+ const BLOCK_GET_SHADER_BINDING_VARS = "@BLOCK_SHADER_BINDING_BIND_VARS@";
33
+ const BLOCK_GET_SHADER_PARAM_LIST = "@BLOCK_GET_SHADER_PARAM_LIST@";
34
+ const EFFECT_SETTER = "@EFFECT_SETTER@";
35
+ const EFFECT_VALUE = "@EFFECT_VALUE@";
36
+ const EXTRA_BIND_DOCSTRING = "@EXTRA_BIND_DOCSTRING@";
37
+ const EXTRA_BIND_PARAMS = "@EXTRA_BIND_PARAMS@";
38
+
39
+ const ShaderBindingPrivateVariablesTemplate = ` private readonly _${CAMEL_CASE_UNIFORM}: RuntimeData<ConnectionPointType.${CONNECTION_POINT_TYPE}>;`;
40
+ const ShaderBindingCtorDocstringParams = ` * @param ${CAMEL_CASE_UNIFORM} - The ${CAMEL_CASE_UNIFORM} runtime value`;
41
+ const ShaderBindingCtorParams = ` ${CAMEL_CASE_UNIFORM}: RuntimeData<ConnectionPointType.${CONNECTION_POINT_TYPE}>`;
42
+ const ShaderBindingCtor = ` this._${CAMEL_CASE_UNIFORM} = ${CAMEL_CASE_UNIFORM};`;
43
+ const ShaderBindingBind = ` effect.${EFFECT_SETTER}(this.getRemappedName(Uniforms.${CAMEL_CASE_UNIFORM}), ${EFFECT_VALUE});`;
44
+ const ShaderBindingBindRegularValue = `this._${CAMEL_CASE_UNIFORM}.value`;
45
+
46
+ const BlockInputProperty = ` /**
47
+ * The ${CAMEL_CASE_UNIFORM} connection point.
48
+ */
49
+ public readonly ${CAMEL_CASE_UNIFORM} = this._registerInput(Uniforms.${CAMEL_CASE_UNIFORM}, ConnectionPointType.${CONNECTION_POINT_TYPE});
50
+ `;
51
+ const BlockInputOptionalProperty = ` /**
52
+ /**
53
+ * The ${CAMEL_CASE_UNIFORM} connection point.
54
+ */
55
+ public readonly ${CAMEL_CASE_UNIFORM} = this._registerOptionalInput(
56
+ "${CAMEL_CASE_UNIFORM}",
57
+ ConnectionPointType.${CONNECTION_POINT_TYPE},
58
+ createStrongRef(${CONNECTION_POINT_DEFAULT_VALUE})
59
+ );
60
+ `;
61
+ const BlockGetShaderBindingVars = ` const ${CAMEL_CASE_UNIFORM} = this._confirmRuntimeDataSupplied(this.${CAMEL_CASE_UNIFORM});`;
62
+
63
+ const FileTemplate = `/* eslint-disable prettier/prettier */
64
+ // ************************************************************
65
+ // Note: this file is auto-generated, do not modify it directly
66
+ // ************************************************************
67
+
68
+ // It was generated by convertGlslIntoBlock() from
69
+ // an annotated .glsl file. Modify the .glsl file to make changes
70
+ // to the block. This file will get overwritten when the build
71
+ // is run or during a watch when the .glsl file is updated.
72
+
73
+ import type { Effect } from "${BABYLON_CORE_PATH}/Materials/effect.js";
74
+
75
+ import {
76
+ ${SHADER_BINDING_EXTENDS},
77
+ type RuntimeData,
78
+ ConnectionPointType,
79
+ type SmartFilter,
80
+ ${SHADER_BLOCK_EXTENDS},
81
+ type ShaderProgram,
82
+ ${EXTRA_IMPORTS}} from "${SMART_FILTER_CORE_IMPORT}";${SHADER_PROGRAM}
83
+ /**
84
+ * The shader binding for the ${BLOCK_NAME}, used by the runtime
85
+ */
86
+ class ${BLOCK_NAME}ShaderBinding extends ${SHADER_BINDING_EXTENDS} {
87
+ ${SHADER_BINDING_PRIVATE_VARIABLES}
88
+
89
+ /**
90
+ * Creates a new shader binding instance for the block.
91
+ ${SHADER_BINDING_CTOR_DOCSTRING_PARAMS}
92
+ */
93
+ constructor(
94
+ ${SHADER_BINDING_CTOR_PARAMS}
95
+ ) {
96
+ super(${SHADER_BINDING_SUPER_PARAMS});
97
+ ${SHADER_BINDING_CTOR}
98
+ }
99
+
100
+ /**
101
+ * Binds all the required data to the shader when rendering.
102
+ * @param effect - defines the effect to bind the data to${EXTRA_BIND_DOCSTRING}
103
+ */
104
+ public override bind(effect: Effect${EXTRA_BIND_PARAMS}): void {
105
+ ${SHADER_BINDING_BIND}
106
+ }
107
+ }
108
+
109
+ /**
110
+ * The implementation of the ${BLOCK_NAME}
111
+ */
112
+ export class ${BLOCK_NAME} extends ${SHADER_BLOCK_EXTENDS} {
113
+ /**
114
+ * The class name of the block.
115
+ */
116
+ public static override ClassName = "${BLOCK_NAME}";
117
+
118
+ /**
119
+ * The namespace of the block.
120
+ */
121
+ public static override Namespace = "${NAMESPACE}";
122
+
123
+ ${BLOCK_INPUT_PROPERTIES}
124
+ /**
125
+ * The shader program (vertex and fragment code) to use to render the block
126
+ */
127
+ public static override ShaderCode = BlockShaderProgram;
128
+
129
+ /**
130
+ * Instantiates a new ${BLOCK_NAME}.
131
+ * @param smartFilter - The smart filter this block belongs to
132
+ * @param name - The friendly name of the block
133
+ */
134
+ constructor(smartFilter: SmartFilter, name: string) {
135
+ super(smartFilter, name, ${BLOCK_DISABLE_OPTIMIZATION}${BLOCK_DISABLE_STRATEGY});
136
+ }
137
+
138
+ /**
139
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
140
+ * @returns The class instance that binds the data to the effect
141
+ */
142
+ public getShaderBinding(): ${SHADER_BINDING_EXTENDS} {
143
+ ${BLOCK_GET_SHADER_BINDING_VARS}
144
+
145
+ return new ${BLOCK_NAME}ShaderBinding(${BLOCK_GET_SHADER_PARAM_LIST});
146
+ }
147
+ }
148
+
149
+ `;
150
+
151
+ /**
152
+ * Converts a single shader to a .ts file which exports a Smart Filter block
153
+ * @param fragmentShaderPath - The path to the fragment file for the shader
154
+ * @param smartFiltersCorePath - The path to import the Smart Filters core from
155
+ * @param babylonCorePath - The path to import the Babylon core from (optional)
156
+
157
+ */
158
+ export function ConvertGlslIntoBlock(fragmentShaderPath: string, smartFiltersCorePath: string, babylonCorePath?: string): void {
159
+ const extraImports: string[] = [];
160
+
161
+ const { shaderProgramCode, fragmentShaderInfo } = ExtractShaderProgramFromGlsl(fragmentShaderPath, smartFiltersCorePath, false, false);
162
+
163
+ // Validation
164
+ if (!fragmentShaderInfo.blockType) {
165
+ throw new Error("The glsl file must contain a header comment with a smartFilterBlockType value");
166
+ }
167
+
168
+ // Generate shader binding private variables
169
+ const shaderBindingPrivateVariables = fragmentShaderInfo.uniforms
170
+ .map((uniform) => {
171
+ return uniform.properties?.autoBind
172
+ ? null
173
+ : ShaderBindingPrivateVariablesTemplate.replace(CAMEL_CASE_UNIFORM, uniform.name).replace(CONNECTION_POINT_TYPE, GetConnectionPointTypeString(uniform.type));
174
+ })
175
+ .filter((line) => line !== null);
176
+
177
+ // Generate the shader binding constructor docstring params
178
+ const shaderBindingCtorDocstringParams = fragmentShaderInfo.uniforms
179
+ .map((uniform) => {
180
+ return uniform.properties?.autoBind ? null : ShaderBindingCtorDocstringParams.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
181
+ })
182
+ .filter((param) => param !== null);
183
+
184
+ // Generate the shader binding constructor params
185
+ const shaderBindingCtorParams = fragmentShaderInfo.uniforms
186
+ .map((uniform) => {
187
+ return uniform.properties?.autoBind
188
+ ? null
189
+ : ShaderBindingCtorParams.replace(CAMEL_CASE_UNIFORM, uniform.name).replace(CONNECTION_POINT_TYPE, GetConnectionPointTypeString(uniform.type));
190
+ })
191
+ .filter((param) => param !== null);
192
+
193
+ // Generate the shader binding constructor
194
+ const shaderBindingCtor = fragmentShaderInfo.uniforms
195
+ .map((uniform) => {
196
+ return uniform.properties?.autoBind ? null : ShaderBindingCtor.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
197
+ })
198
+ .filter((line) => line !== null);
199
+
200
+ // Generate the shader binding bind
201
+ let needWidthHeightParams = false;
202
+ const shaderBindingBind = fragmentShaderInfo.uniforms.map((uniform) => {
203
+ let effectValue: string;
204
+ let effectSetter = GetEffectSetter(uniform.type);
205
+
206
+ switch (uniform.properties?.autoBind) {
207
+ case "outputResolution":
208
+ {
209
+ effectValue = "width, height";
210
+ effectSetter = "setFloat2";
211
+ needWidthHeightParams = true;
212
+ }
213
+ break;
214
+ case "outputAspectRatio":
215
+ {
216
+ effectValue = "width / height, height / width";
217
+ effectSetter = "setFloat2";
218
+ needWidthHeightParams = true;
219
+ }
220
+ break;
221
+ default:
222
+ effectValue = ShaderBindingBindRegularValue;
223
+ }
224
+ return ShaderBindingBind.replace(EFFECT_VALUE, effectValue).replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name).replace(EFFECT_SETTER, effectSetter);
225
+ });
226
+
227
+ // Add extra params to the bind method if needed
228
+ let extraBindParams = "";
229
+ let extraBindDocstring = "";
230
+ if (needWidthHeightParams) {
231
+ extraBindDocstring = `
232
+ * @param width - defines the width of the output
233
+ * @param height - defines the height of the output`;
234
+ extraBindParams = `, width: number, height: number`;
235
+ }
236
+
237
+ // Generate the block input properties
238
+ const blockInputProperties = fragmentShaderInfo.uniforms
239
+ .map((uniform) => {
240
+ if (uniform.properties?.autoBind) {
241
+ return null;
242
+ } else if (uniform.properties?.default !== undefined) {
243
+ if (extraImports.indexOf(" createStrongRef") === -1) {
244
+ extraImports.push(" createStrongRef");
245
+ }
246
+ return BlockInputOptionalProperty.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name)
247
+ .replace(CONNECTION_POINT_TYPE, GetConnectionPointTypeString(uniform.type))
248
+ .replace(CONNECTION_POINT_DEFAULT_VALUE, uniform.properties.default);
249
+ } else {
250
+ return BlockInputProperty.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name).replace(CONNECTION_POINT_TYPE, GetConnectionPointTypeString(uniform.type));
251
+ }
252
+ })
253
+ .filter((property) => property !== null);
254
+
255
+ // Generate the block get shader binding vars
256
+ const blockGetShaderBindingVars = fragmentShaderInfo.uniforms
257
+ .map((uniform) => {
258
+ return uniform.properties?.autoBind ? null : BlockGetShaderBindingVars.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
259
+ })
260
+ .filter((line) => line !== null);
261
+
262
+ // Handle the disable optimization flag
263
+ const disableOptimization = fragmentShaderInfo.disableOptimization === true ? "true" : "false";
264
+
265
+ // Generate the block get shader param list
266
+ const blockGetShaderParamList = fragmentShaderInfo.uniforms
267
+ .map((uniform) => {
268
+ return uniform.properties?.autoBind ? null : uniform.name;
269
+ })
270
+ .filter((param) => param !== null);
271
+
272
+ // Decide if this is a disableable block or not
273
+ let shaderBlockExtends = "ShaderBlock";
274
+ let shaderBindingExtends = "ShaderBinding";
275
+ let blockDisableStrategy = "";
276
+ let shaderBindingSuperParams = "";
277
+ if (fragmentShaderInfo.blockDisableStrategy) {
278
+ shaderBlockExtends = "DisableableShaderBlock";
279
+ shaderBindingExtends = "DisableableShaderBinding";
280
+ blockDisableStrategy = `, BlockDisableStrategy.${BlockDisableStrategy[fragmentShaderInfo.blockDisableStrategy]}`;
281
+ shaderBindingSuperParams = "parentBlock";
282
+
283
+ shaderBindingCtorDocstringParams.unshift(" * @param parentBlock - IDisableableBlock");
284
+ shaderBindingCtorParams.unshift(" parentBlock: IDisableableBlock");
285
+ blockGetShaderParamList.unshift("this");
286
+
287
+ extraImports.push(" type IDisableableBlock");
288
+ extraImports.push(" BlockDisableStrategy");
289
+
290
+ shaderBindingBind.unshift(" super.bind(effect);");
291
+ }
292
+
293
+ // Additional validation
294
+ if (fragmentShaderInfo.blockDisableStrategy !== undefined && fragmentShaderInfo.blockDisableStrategy !== BlockDisableStrategy.Manual) {
295
+ if (fragmentShaderInfo.uniforms.findIndex((uniform) => uniform.name === "disabled") !== -1) {
296
+ throw new Error("A block that uses a BlockDisableStrategy other than Manual should not declare its own 'disabled' uniform");
297
+ }
298
+ }
299
+
300
+ // Generate final contents
301
+ const finalContents = FileTemplate.replace(SHADER_PROGRAM, shaderProgramCode)
302
+ .replace(EXTRA_IMPORTS, extraImports.join(",\n"))
303
+ .replace(BABYLON_CORE_PATH, babylonCorePath || "@babylonjs/core")
304
+ .replace(SMART_FILTER_CORE_IMPORT, smartFiltersCorePath)
305
+ .replace(new RegExp(BLOCK_NAME, "g"), fragmentShaderInfo.blockType)
306
+ .replace(NAMESPACE, fragmentShaderInfo.namespace || "Other")
307
+ .replace(new RegExp(SHADER_BINDING_EXTENDS, "g"), shaderBindingExtends)
308
+ .replace(SHADER_BINDING_PRIVATE_VARIABLES, shaderBindingPrivateVariables.join("\n"))
309
+ .replace(SHADER_BINDING_CTOR_DOCSTRING_PARAMS, shaderBindingCtorDocstringParams.join("\n"))
310
+ .replace(SHADER_BINDING_CTOR_PARAMS, shaderBindingCtorParams.join(",\n"))
311
+ .replace(SHADER_BINDING_CTOR, shaderBindingCtor.join("\n"))
312
+ .replace(SHADER_BINDING_SUPER_PARAMS, shaderBindingSuperParams)
313
+ .replace(SHADER_BINDING_BIND, shaderBindingBind.join("\n"))
314
+ .replace(EXTRA_BIND_DOCSTRING, extraBindDocstring)
315
+ .replace(EXTRA_BIND_PARAMS, extraBindParams)
316
+ .replace(new RegExp(SHADER_BLOCK_EXTENDS, "g"), shaderBlockExtends)
317
+ .replace(BLOCK_INPUT_PROPERTIES, blockInputProperties.join("\n"))
318
+ .replace(BLOCK_DISABLE_OPTIMIZATION, disableOptimization)
319
+ .replace(BLOCK_DISABLE_STRATEGY, blockDisableStrategy)
320
+ .replace(BLOCK_GET_SHADER_BINDING_VARS, blockGetShaderBindingVars.join("\n"))
321
+ .replace(BLOCK_GET_SHADER_PARAM_LIST, blockGetShaderParamList.join(","));
322
+
323
+ // Write the block class TS file
324
+ const outputFullPathAndFileName = fragmentShaderPath.replace(".glsl", ".ts");
325
+ fs.writeFileSync(outputFullPathAndFileName, finalContents);
326
+ }
327
+
328
+ /**
329
+ * Get the string representation of a connection point type
330
+ * @param type - The connection point type
331
+ * @returns - The string representation of the connection point type
332
+ */
333
+ function GetConnectionPointTypeString(type: ConnectionPointType): string {
334
+ switch (type) {
335
+ case ConnectionPointType.Float:
336
+ return "Float";
337
+ case ConnectionPointType.Texture:
338
+ return "Texture";
339
+ case ConnectionPointType.Color3:
340
+ return "Color3";
341
+ case ConnectionPointType.Color4:
342
+ return "Color4";
343
+ case ConnectionPointType.Vector2:
344
+ return "Vector2";
345
+ case ConnectionPointType.Boolean:
346
+ return "Boolean";
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Get the effect setter for a connection point type
352
+ * @param type - The connection point type
353
+ * @returns - The effect setter for the connection point type
354
+ */
355
+ function GetEffectSetter(type: ConnectionPointType): string {
356
+ switch (type) {
357
+ case ConnectionPointType.Float:
358
+ return "setFloat";
359
+ case ConnectionPointType.Texture:
360
+ return "setTexture";
361
+ case ConnectionPointType.Color3:
362
+ return "setColor3";
363
+ case ConnectionPointType.Color4:
364
+ return "setDirectColor4";
365
+ case ConnectionPointType.Vector2:
366
+ return "setVector2";
367
+ case ConnectionPointType.Boolean:
368
+ return "setBool";
369
+ }
370
+ }