@babylonjs/smart-filters 1.0.12 → 8.18.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.map +1 -1
  13. package/dist/blockFoundation/customShaderBlock.js +4 -6
  14. package/dist/blockFoundation/customShaderBlock.js.map +1 -1
  15. package/dist/blockFoundation/disableableShaderBlock.d.ts.map +1 -1
  16. package/dist/blockFoundation/disableableShaderBlock.js +4 -4
  17. package/dist/blockFoundation/disableableShaderBlock.js.map +1 -1
  18. package/dist/blockFoundation/index.js +0 -2
  19. package/dist/blockFoundation/index.js.map +1 -1
  20. package/dist/blockFoundation/inputBlock.d.ts +8 -8
  21. package/dist/blockFoundation/inputBlock.d.ts.map +1 -1
  22. package/dist/blockFoundation/inputBlock.deserializer.d.ts +1 -1
  23. package/dist/blockFoundation/inputBlock.deserializer.d.ts.map +1 -1
  24. package/dist/blockFoundation/inputBlock.deserializer.js +1 -1
  25. package/dist/blockFoundation/inputBlock.deserializer.js.map +1 -1
  26. package/dist/blockFoundation/inputBlock.js +7 -7
  27. package/dist/blockFoundation/inputBlock.js.map +1 -1
  28. package/dist/blockFoundation/inputBlock.serialization.types.d.ts.map +1 -1
  29. package/dist/blockFoundation/inputBlock.serializer.d.ts +1 -1
  30. package/dist/blockFoundation/inputBlock.serializer.js +26 -28
  31. package/dist/blockFoundation/inputBlock.serializer.js.map +1 -1
  32. package/dist/blockFoundation/outputBlock.d.ts +4 -9
  33. package/dist/blockFoundation/outputBlock.d.ts.map +1 -1
  34. package/dist/blockFoundation/outputBlock.js +13 -14
  35. package/dist/blockFoundation/outputBlock.js.map +1 -1
  36. package/dist/blockFoundation/shaderBlock.d.ts +4 -4
  37. package/dist/blockFoundation/shaderBlock.d.ts.map +1 -1
  38. package/dist/blockFoundation/shaderBlock.js +13 -19
  39. package/dist/blockFoundation/shaderBlock.js.map +1 -1
  40. package/dist/blockFoundation/textureOptions.d.ts +1 -1
  41. package/dist/blockFoundation/textureOptions.js +1 -1
  42. package/dist/command/command.d.ts +1 -1
  43. package/dist/command/command.js +1 -1
  44. package/dist/command/commandBuffer.d.ts +1 -1
  45. package/dist/command/commandBuffer.d.ts.map +1 -1
  46. package/dist/command/commandBuffer.js +2 -2
  47. package/dist/command/commandBufferDebugger.d.ts +2 -2
  48. package/dist/command/commandBufferDebugger.d.ts.map +1 -1
  49. package/dist/command/commandBufferDebugger.js +1 -1
  50. package/dist/command/commandBufferDebugger.js.map +1 -1
  51. package/dist/command/index.d.ts +3 -1
  52. package/dist/command/index.d.ts.map +1 -1
  53. package/dist/command/index.js +5 -1
  54. package/dist/command/index.js.map +1 -1
  55. package/dist/connection/connectionPoint.d.ts +3 -3
  56. package/dist/connection/connectionPoint.d.ts.map +1 -1
  57. package/dist/connection/connectionPoint.js +2 -2
  58. package/dist/connection/connectionPoint.js.map +1 -1
  59. package/dist/connection/connectionPointCompatibilityState.d.ts +1 -1
  60. package/dist/connection/connectionPointCompatibilityState.js +1 -1
  61. package/dist/connection/connectionPointType.d.ts +3 -3
  62. package/dist/connection/connectionPointType.d.ts.map +1 -1
  63. package/dist/connection/connectionPointWithDefault.d.ts +3 -3
  64. package/dist/connection/connectionPointWithDefault.d.ts.map +1 -1
  65. package/dist/connection/connectionPointWithDefault.js.map +1 -1
  66. package/dist/connection/index.d.ts +2 -1
  67. package/dist/connection/index.d.ts.map +1 -1
  68. package/dist/connection/index.js +3 -3
  69. package/dist/connection/index.js.map +1 -1
  70. package/dist/editorUtils/editableInPropertyPage.d.ts +2 -2
  71. package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -1
  72. package/dist/editorUtils/editableInPropertyPage.js +2 -2
  73. package/dist/editorUtils/editableInPropertyPage.js.map +1 -1
  74. package/dist/editorUtils/index.d.ts +1 -0
  75. package/dist/editorUtils/index.d.ts.map +1 -1
  76. package/dist/editorUtils/index.js +2 -0
  77. package/dist/editorUtils/index.js.map +1 -1
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +1 -1
  80. package/dist/index.js.map +1 -1
  81. package/dist/optimization/dependencyGraph.js.map +1 -1
  82. package/dist/optimization/optimizedShaderBlock.d.ts +4 -4
  83. package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -1
  84. package/dist/optimization/optimizedShaderBlock.js.map +1 -1
  85. package/dist/optimization/smartFilterOptimizer.d.ts +2 -2
  86. package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -1
  87. package/dist/optimization/smartFilterOptimizer.js +34 -57
  88. package/dist/optimization/smartFilterOptimizer.js.map +1 -1
  89. package/dist/runtime/index.d.ts +2 -1
  90. package/dist/runtime/index.d.ts.map +1 -1
  91. package/dist/runtime/index.js +3 -3
  92. package/dist/runtime/index.js.map +1 -1
  93. package/dist/runtime/renderTargetGenerator.d.ts +1 -1
  94. package/dist/runtime/renderTargetGenerator.d.ts.map +1 -1
  95. package/dist/runtime/renderTargetGenerator.js +5 -7
  96. package/dist/runtime/renderTargetGenerator.js.map +1 -1
  97. package/dist/runtime/shaderRuntime.d.ts +7 -7
  98. package/dist/runtime/shaderRuntime.d.ts.map +1 -1
  99. package/dist/runtime/shaderRuntime.js +7 -8
  100. package/dist/runtime/shaderRuntime.js.map +1 -1
  101. package/dist/runtime/smartFilterRuntime.d.ts +3 -3
  102. package/dist/runtime/smartFilterRuntime.d.ts.map +1 -1
  103. package/dist/runtime/smartFilterRuntime.js.map +1 -1
  104. package/dist/runtime/strongRef.d.ts +1 -1
  105. package/dist/runtime/strongRef.js +1 -1
  106. package/dist/serialization/importCustomBlockDefinition.d.ts +1 -1
  107. package/dist/serialization/importCustomBlockDefinition.js +8 -9
  108. package/dist/serialization/importCustomBlockDefinition.js.map +1 -1
  109. package/dist/serialization/index.d.ts +1 -0
  110. package/dist/serialization/index.d.ts.map +1 -1
  111. package/dist/serialization/index.js +3 -0
  112. package/dist/serialization/index.js.map +1 -1
  113. package/dist/serialization/serializedBlockDefinition.d.ts +2 -2
  114. package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -1
  115. package/dist/serialization/serializedShaderBlockDefinition.d.ts +1 -1
  116. package/dist/serialization/serializedShaderBlockDefinition.d.ts.map +1 -1
  117. package/dist/serialization/serializedSmartFilter.d.ts +1 -1
  118. package/dist/serialization/serializedSmartFilter.d.ts.map +1 -1
  119. package/dist/serialization/smartFilterDeserializer.d.ts +6 -6
  120. package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -1
  121. package/dist/serialization/smartFilterDeserializer.js +14 -12
  122. package/dist/serialization/smartFilterDeserializer.js.map +1 -1
  123. package/dist/serialization/smartFilterSerializer.d.ts +2 -2
  124. package/dist/serialization/smartFilterSerializer.d.ts.map +1 -1
  125. package/dist/serialization/smartFilterSerializer.js +10 -13
  126. package/dist/serialization/smartFilterSerializer.js.map +1 -1
  127. package/dist/serialization/v1/defaultBlockSerializer.d.ts +2 -2
  128. package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -1
  129. package/dist/serialization/v1/defaultBlockSerializer.js +3 -1
  130. package/dist/serialization/v1/defaultBlockSerializer.js.map +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 +5 -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 +14 -9
  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 +312 -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 -214
  231. package/src/serialization/smartFilterSerializer.ts +110 -121
  232. package/src/serialization/v1/defaultBlockSerializer.ts +21 -19
  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 -129
  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 +17 -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,326 +1,312 @@
1
- import type { Effect } from "@babylonjs/core/Materials/effect";
2
- import { ConnectionPointType } from "../connection/connectionPointType.js";
3
- import { ShaderBinding } from "../runtime/shaderRuntime.js";
4
- import { createStrongRef } from "../runtime/strongRef.js";
5
- import type { SerializedShaderBlockDefinition } from "../serialization/serializedShaderBlockDefinition.js";
6
- import type { SerializedInputConnectionPointV1 } from "../serialization/v1/shaderBlockSerialization.types.js";
7
- import type { SmartFilter } from "../smartFilter.js";
8
- import type { ShaderProgram } from "../utils/shaderCodeUtils.js";
9
- import { ShaderBlock } from "./shaderBlock.js";
10
- import type { RuntimeData } from "../connection/connectionPoint.js";
11
- import type { Nullable } from "@babylonjs/core/types.js";
12
-
13
- /**
14
- * The binding for a CustomShaderBlock
15
- */
16
- class CustomShaderBlockBinding extends ShaderBinding {
17
- private readonly _bindSteps: ((effect: Effect, width: number, height: number) => void)[] = [];
18
-
19
- /**
20
- * Creates a new shader binding instance for the CustomShaderBlock block.
21
- * @param inputsWithRuntimeData - The input connection points of the block
22
- */
23
- public constructor(inputsWithRuntimeData: AnyInputWithRuntimeData[]) {
24
- super();
25
-
26
- for (const input of inputsWithRuntimeData) {
27
- switch (input.type) {
28
- case ConnectionPointType.Float:
29
- this._bindSteps.push((effect) => {
30
- effect.setFloat(this.getRemappedName(input.name), input.runtimeData.value);
31
- });
32
- break;
33
- case ConnectionPointType.Texture:
34
- this._bindSteps.push((effect) => {
35
- effect.setTexture(this.getRemappedName(input.name), input.runtimeData.value);
36
- });
37
- break;
38
- case ConnectionPointType.Color3:
39
- this._bindSteps.push((effect) => {
40
- effect.setColor3(this.getRemappedName(input.name), input.runtimeData.value);
41
- });
42
- break;
43
- case ConnectionPointType.Color4:
44
- this._bindSteps.push((effect) => {
45
- effect.setDirectColor4(this.getRemappedName(input.name), input.runtimeData.value);
46
- });
47
- break;
48
- case ConnectionPointType.Boolean:
49
- this._bindSteps.push((effect) => {
50
- effect.setBool(this.getRemappedName(input.name), input.runtimeData.value);
51
- });
52
- break;
53
- case ConnectionPointType.Vector2:
54
- switch (input.autoBind) {
55
- case "outputResolution":
56
- this._bindSteps.push((effect, width, height) => {
57
- effect.setFloat2(this.getRemappedName(input.name), width, height);
58
- });
59
- break;
60
- case "outputAspectRatio":
61
- this._bindSteps.push((effect, width, height) => {
62
- effect.setFloat2(this.getRemappedName(input.name), width / height, height / width);
63
- });
64
- break;
65
- default:
66
- this._bindSteps.push((effect) => {
67
- effect.setVector2(this.getRemappedName(input.name), input.runtimeData.value);
68
- });
69
- }
70
- break;
71
- }
72
- }
73
- }
74
-
75
- /**
76
- * Binds all the required data to the shader when rendering.
77
- * @param effect - The effect to bind the data to
78
- * @param width - defines the width of the output
79
- * @param height - defines the height of the output
80
- */
81
- public override bind(effect: Effect, width: number, height: number): void {
82
- for (let i = 0; i < this._bindSteps.length; i++) {
83
- this._bindSteps[i]!(effect, width, height);
84
- }
85
- }
86
- }
87
-
88
- /**
89
- * A block which loads a SerializedBlockDefinition for use in a SmartFilter.
90
- */
91
- export class CustomShaderBlock extends ShaderBlock {
92
- /**
93
- * Deserializes a CustomShaderBlock from a serialized block definition.
94
- * @param smartFilter - The smart filter this block belongs to
95
- * @param name - Defines the name of the block
96
- * @param blockDefinition - The serialized block definition
97
- * @returns The deserialized CustomShaderBlock instance
98
- */
99
- public static Create(
100
- smartFilter: SmartFilter,
101
- name: string,
102
- blockDefinition: SerializedShaderBlockDefinition
103
- ): CustomShaderBlock {
104
- // When a new version of SerializedBlockDefinition is created, this function should be updated to handle the new properties.
105
-
106
- return new CustomShaderBlock(
107
- smartFilter,
108
- name,
109
- blockDefinition.disableOptimization,
110
- blockDefinition.blockType,
111
- blockDefinition.namespace,
112
- blockDefinition.inputConnectionPoints,
113
- blockDefinition.shaderProgram
114
- );
115
- }
116
-
117
- /**
118
- * The class name of the block.
119
- */
120
- public static override ClassName = "CustomShaderBlock";
121
-
122
- private readonly _shaderProgram: ShaderProgram;
123
- private readonly _blockType: string;
124
- private readonly _namespace: Nullable<string>;
125
- private _autoBoundInputs: Nullable<SerializedInputConnectionPointV1[]> = null;
126
-
127
- /**
128
- * The type of the block - used when serializing / deserializing the block, and in the editor.
129
- */
130
- public override get blockType(): string {
131
- return this._blockType;
132
- }
133
-
134
- /**
135
- * The namespace of the block, which is used to reduce name collisions between blocks and also to group blocks in the editor UI.
136
- * By convention, sub namespaces are separated by a period (e.g. "Babylon.Demo.Effects").
137
- */
138
- public override get namespace(): Nullable<string> {
139
- return this._namespace;
140
- }
141
-
142
- /**
143
- * Instantiates a new custom shader block.
144
- * @param smartFilter - The smart filter this block belongs to
145
- * @param name - The name of the block
146
- * @param disableOptimization - If true, this optimizer will not attempt to optimize this block
147
- * @param blockType - The type of the block
148
- * @param namespace - The namespace of the block
149
- * @param inputConnectionPoints - The input connection points of the
150
- * @param shaderProgram - The shader program for the block
151
- */
152
- private constructor(
153
- smartFilter: SmartFilter,
154
- name: string,
155
- disableOptimization: boolean,
156
- blockType: string,
157
- namespace: Nullable<string>,
158
- inputConnectionPoints: SerializedInputConnectionPointV1[],
159
- shaderProgram: ShaderProgram
160
- ) {
161
- super(smartFilter, name, disableOptimization);
162
- this._blockType = blockType;
163
- this._namespace = namespace;
164
-
165
- for (const input of inputConnectionPoints) {
166
- this._registerSerializedInputConnectionPointV1(input);
167
- }
168
-
169
- this._shaderProgram = shaderProgram;
170
- }
171
-
172
- /**
173
- * Gets the shader program to use to render the block.
174
- * @returns The shader program to use to render the block
175
- */
176
- public override getShaderProgram() {
177
- return this._shaderProgram;
178
- }
179
-
180
- /**
181
- * Checks a specific input connection point type to see if it has a default value, and registers the input
182
- * connection point accordingly.
183
- * @param connectionPoint - The input connection point to register
184
- */
185
- private _registerSerializedInputConnectionPointV1<U extends ConnectionPointType>(
186
- connectionPoint: SerializedInputConnectionPointV1<U>
187
- ): void {
188
- if (connectionPoint.autoBind) {
189
- // Auto bound inputs are not registered as input connection points
190
- if (this._autoBoundInputs === null) {
191
- this._autoBoundInputs = [];
192
- }
193
- this._autoBoundInputs.push(connectionPoint);
194
- } else {
195
- // If not auto bound, register as an input connection point
196
- if (connectionPoint.defaultValue !== undefined) {
197
- this._registerOptionalInput(
198
- connectionPoint.name,
199
- connectionPoint.type,
200
- createStrongRef(connectionPoint.defaultValue)
201
- );
202
- } else {
203
- this._registerInput(connectionPoint.name, connectionPoint.type);
204
- }
205
- }
206
- }
207
-
208
- /**
209
- * Gets the shader binding for the custom shader block.
210
- * @returns The shader binding for the custom shader block
211
- */
212
- public override getShaderBinding(): ShaderBinding {
213
- const inputs = this.inputs;
214
-
215
- const inputsToBind: AnyInputWithRuntimeData[] = inputs.map((input) => {
216
- return {
217
- name: input.name,
218
- type: input.type,
219
- runtimeData: this._confirmRuntimeDataSupplied(input),
220
- autoBind: undefined,
221
- };
222
- });
223
-
224
- if (this._autoBoundInputs) {
225
- for (const autoBoundInput of this._autoBoundInputs) {
226
- if (
227
- (autoBoundInput.autoBind === "outputResolution" &&
228
- autoBoundInput.type == ConnectionPointType.Vector2) ||
229
- (autoBoundInput.autoBind === "outputAspectRatio" &&
230
- autoBoundInput.type == ConnectionPointType.Vector2)
231
- ) {
232
- inputsToBind.push({
233
- name: autoBoundInput.name,
234
- type: autoBoundInput.type,
235
- autoBind: autoBoundInput.autoBind,
236
- });
237
- } else {
238
- throw new Error(
239
- `Auto bound input ${autoBoundInput.name} has an unsupported type or auto bind value`
240
- );
241
- }
242
- }
243
- }
244
-
245
- return new CustomShaderBlockBinding(inputsToBind);
246
- }
247
- }
248
-
249
- /**
250
- * Represents an input with its runtime data, enforcing type safety.
251
- */
252
- type InputWithRuntimeData<U extends ConnectionPointType> = {
253
- /**
254
- * The name of the input connection point
255
- */
256
- name: string;
257
-
258
- /**
259
- * The type of the input connection point
260
- */
261
- type: U;
262
-
263
- /**
264
- * The runtime data for the input connection point
265
- */
266
- runtimeData: RuntimeData<U>;
267
-
268
- /**
269
- * Since this is an input connection point, it will not be auto bound
270
- */
271
- autoBind: undefined;
272
- };
273
-
274
- /**
275
- * Represents an input which is auto-bound to the output resolution instead of an input connection point
276
- */
277
- type AutoBindOutputResolution = {
278
- /**
279
- * The name of the input
280
- */
281
- name: string;
282
-
283
- /**
284
- * The type of the input
285
- */
286
- type: ConnectionPointType.Vector2;
287
-
288
- /**
289
- * The auto bind value for the input connection point
290
- */
291
- autoBind: "outputResolution";
292
- };
293
-
294
- /**
295
- * Represents an input which is auto-bound to the output's aspect ratio instead of an input connection point.
296
- * The x value is the aspect ratio (width / height) and the y value is the inverse aspect ratio (height / width).
297
- */
298
- type AutoBindOutputAspectRatio = {
299
- /**
300
- * The name of the input
301
- */
302
- name: string;
303
-
304
- /**
305
- * The type of the input
306
- */
307
- type: ConnectionPointType.Vector2;
308
-
309
- /**
310
- * The auto bind value for the input connection point
311
- */
312
- autoBind: "outputAspectRatio";
313
- };
314
-
315
- /**
316
- * All possible input types with runtime data.
317
- */
318
- type AnyInputWithRuntimeData =
319
- | InputWithRuntimeData<ConnectionPointType.Boolean>
320
- | InputWithRuntimeData<ConnectionPointType.Color3>
321
- | InputWithRuntimeData<ConnectionPointType.Color4>
322
- | InputWithRuntimeData<ConnectionPointType.Float>
323
- | InputWithRuntimeData<ConnectionPointType.Texture>
324
- | InputWithRuntimeData<ConnectionPointType.Vector2>
325
- | AutoBindOutputResolution
326
- | AutoBindOutputAspectRatio;
1
+ import type { Effect } from "core/Materials/effect.js";
2
+ import { ConnectionPointType } from "../connection/connectionPointType.js";
3
+ import { ShaderBinding } from "../runtime/shaderRuntime.js";
4
+ import { CreateStrongRef } from "../runtime/strongRef.js";
5
+ import type { SerializedShaderBlockDefinition } from "../serialization/serializedShaderBlockDefinition.js";
6
+ import type { SerializedInputConnectionPointV1 } from "../serialization/v1/shaderBlockSerialization.types.js";
7
+ import type { SmartFilter } from "../smartFilter.js";
8
+ import type { ShaderProgram } from "../utils/shaderCodeUtils.js";
9
+ import { ShaderBlock } from "./shaderBlock.js";
10
+ import type { RuntimeData } from "../connection/connectionPoint.js";
11
+ import type { Nullable } from "core/types.js";
12
+
13
+ /**
14
+ * The binding for a CustomShaderBlock
15
+ */
16
+ class CustomShaderBlockBinding extends ShaderBinding {
17
+ private readonly _bindSteps: ((effect: Effect, width: number, height: number) => void)[] = [];
18
+
19
+ /**
20
+ * Creates a new shader binding instance for the CustomShaderBlock block.
21
+ * @param inputsWithRuntimeData - The input connection points of the block
22
+ */
23
+ public constructor(inputsWithRuntimeData: AnyInputWithRuntimeData[]) {
24
+ super();
25
+
26
+ for (const input of inputsWithRuntimeData) {
27
+ switch (input.type) {
28
+ case ConnectionPointType.Float:
29
+ this._bindSteps.push((effect) => {
30
+ effect.setFloat(this.getRemappedName(input.name), input.runtimeData.value);
31
+ });
32
+ break;
33
+ case ConnectionPointType.Texture:
34
+ this._bindSteps.push((effect) => {
35
+ effect.setTexture(this.getRemappedName(input.name), input.runtimeData.value);
36
+ });
37
+ break;
38
+ case ConnectionPointType.Color3:
39
+ this._bindSteps.push((effect) => {
40
+ effect.setColor3(this.getRemappedName(input.name), input.runtimeData.value);
41
+ });
42
+ break;
43
+ case ConnectionPointType.Color4:
44
+ this._bindSteps.push((effect) => {
45
+ effect.setDirectColor4(this.getRemappedName(input.name), input.runtimeData.value);
46
+ });
47
+ break;
48
+ case ConnectionPointType.Boolean:
49
+ this._bindSteps.push((effect) => {
50
+ effect.setBool(this.getRemappedName(input.name), input.runtimeData.value);
51
+ });
52
+ break;
53
+ case ConnectionPointType.Vector2:
54
+ switch (input.autoBind) {
55
+ case "outputResolution":
56
+ this._bindSteps.push((effect, width, height) => {
57
+ effect.setFloat2(this.getRemappedName(input.name), width, height);
58
+ });
59
+ break;
60
+ case "outputAspectRatio":
61
+ this._bindSteps.push((effect, width, height) => {
62
+ effect.setFloat2(this.getRemappedName(input.name), width / height, height / width);
63
+ });
64
+ break;
65
+ default:
66
+ this._bindSteps.push((effect) => {
67
+ effect.setVector2(this.getRemappedName(input.name), input.runtimeData.value);
68
+ });
69
+ }
70
+ break;
71
+ }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Binds all the required data to the shader when rendering.
77
+ * @param effect - The effect to bind the data to
78
+ * @param width - defines the width of the output
79
+ * @param height - defines the height of the output
80
+ */
81
+ public override bind(effect: Effect, width: number, height: number): void {
82
+ for (let i = 0; i < this._bindSteps.length; i++) {
83
+ this._bindSteps[i]!(effect, width, height);
84
+ }
85
+ }
86
+ }
87
+
88
+ /**
89
+ * A block which loads a SerializedBlockDefinition for use in a SmartFilter.
90
+ */
91
+ export class CustomShaderBlock extends ShaderBlock {
92
+ /**
93
+ * Deserializes a CustomShaderBlock from a serialized block definition.
94
+ * @param smartFilter - The smart filter this block belongs to
95
+ * @param name - Defines the name of the block
96
+ * @param blockDefinition - The serialized block definition
97
+ * @returns The deserialized CustomShaderBlock instance
98
+ */
99
+ public static Create(smartFilter: SmartFilter, name: string, blockDefinition: SerializedShaderBlockDefinition): CustomShaderBlock {
100
+ // When a new version of SerializedBlockDefinition is created, this function should be updated to handle the new properties.
101
+
102
+ return new CustomShaderBlock(
103
+ smartFilter,
104
+ name,
105
+ blockDefinition.disableOptimization,
106
+ blockDefinition.blockType,
107
+ blockDefinition.namespace,
108
+ blockDefinition.inputConnectionPoints,
109
+ blockDefinition.shaderProgram
110
+ );
111
+ }
112
+
113
+ /**
114
+ * The class name of the block.
115
+ */
116
+ public static override ClassName = "CustomShaderBlock";
117
+
118
+ private readonly _shaderProgram: ShaderProgram;
119
+ private readonly _blockType: string;
120
+ private readonly _namespace: Nullable<string>;
121
+ private _autoBoundInputs: Nullable<SerializedInputConnectionPointV1[]> = null;
122
+
123
+ /**
124
+ * The type of the block - used when serializing / deserializing the block, and in the editor.
125
+ */
126
+ public override get blockType(): string {
127
+ return this._blockType;
128
+ }
129
+
130
+ /**
131
+ * The namespace of the block, which is used to reduce name collisions between blocks and also to group blocks in the editor UI.
132
+ * By convention, sub namespaces are separated by a period (e.g. "Babylon.Demo.Effects").
133
+ */
134
+ public override get namespace(): Nullable<string> {
135
+ return this._namespace;
136
+ }
137
+
138
+ /**
139
+ * Instantiates a new custom shader block.
140
+ * @param smartFilter - The smart filter this block belongs to
141
+ * @param name - The name of the block
142
+ * @param disableOptimization - If true, this optimizer will not attempt to optimize this block
143
+ * @param blockType - The type of the block
144
+ * @param namespace - The namespace of the block
145
+ * @param inputConnectionPoints - The input connection points of the
146
+ * @param shaderProgram - The shader program for the block
147
+ */
148
+ private constructor(
149
+ smartFilter: SmartFilter,
150
+ name: string,
151
+ disableOptimization: boolean,
152
+ blockType: string,
153
+ namespace: Nullable<string>,
154
+ inputConnectionPoints: SerializedInputConnectionPointV1[],
155
+ shaderProgram: ShaderProgram
156
+ ) {
157
+ super(smartFilter, name, disableOptimization);
158
+ this._blockType = blockType;
159
+ this._namespace = namespace;
160
+
161
+ for (const input of inputConnectionPoints) {
162
+ this._registerSerializedInputConnectionPointV1(input);
163
+ }
164
+
165
+ this._shaderProgram = shaderProgram;
166
+ }
167
+
168
+ /**
169
+ * Gets the shader program to use to render the block.
170
+ * @returns The shader program to use to render the block
171
+ */
172
+ public override getShaderProgram() {
173
+ return this._shaderProgram;
174
+ }
175
+
176
+ /**
177
+ * Checks a specific input connection point type to see if it has a default value, and registers the input
178
+ * connection point accordingly.
179
+ * @param connectionPoint - The input connection point to register
180
+ */
181
+ private _registerSerializedInputConnectionPointV1<U extends ConnectionPointType>(connectionPoint: SerializedInputConnectionPointV1<U>): void {
182
+ if (connectionPoint.autoBind) {
183
+ // Auto bound inputs are not registered as input connection points
184
+ if (this._autoBoundInputs === null) {
185
+ this._autoBoundInputs = [];
186
+ }
187
+ this._autoBoundInputs.push(connectionPoint);
188
+ } else {
189
+ // If not auto bound, register as an input connection point
190
+ if (connectionPoint.defaultValue !== undefined) {
191
+ this._registerOptionalInput(connectionPoint.name, connectionPoint.type, CreateStrongRef(connectionPoint.defaultValue));
192
+ } else {
193
+ this._registerInput(connectionPoint.name, connectionPoint.type);
194
+ }
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Gets the shader binding for the custom shader block.
200
+ * @returns The shader binding for the custom shader block
201
+ */
202
+ public override getShaderBinding(): ShaderBinding {
203
+ const inputs = this.inputs;
204
+
205
+ const inputsToBind: AnyInputWithRuntimeData[] = inputs.map((input) => {
206
+ return {
207
+ name: input.name,
208
+ type: input.type,
209
+ runtimeData: this._confirmRuntimeDataSupplied(input),
210
+ autoBind: undefined,
211
+ };
212
+ });
213
+
214
+ if (this._autoBoundInputs) {
215
+ for (const autoBoundInput of this._autoBoundInputs) {
216
+ if (
217
+ (autoBoundInput.autoBind === "outputResolution" && autoBoundInput.type == ConnectionPointType.Vector2) ||
218
+ (autoBoundInput.autoBind === "outputAspectRatio" && autoBoundInput.type == ConnectionPointType.Vector2)
219
+ ) {
220
+ inputsToBind.push({
221
+ name: autoBoundInput.name,
222
+ type: autoBoundInput.type,
223
+ autoBind: autoBoundInput.autoBind,
224
+ });
225
+ } else {
226
+ throw new Error(`Auto bound input ${autoBoundInput.name} has an unsupported type or auto bind value`);
227
+ }
228
+ }
229
+ }
230
+
231
+ return new CustomShaderBlockBinding(inputsToBind);
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Represents an input with its runtime data, enforcing type safety.
237
+ */
238
+ type InputWithRuntimeData<U extends ConnectionPointType> = {
239
+ /**
240
+ * The name of the input connection point
241
+ */
242
+ name: string;
243
+
244
+ /**
245
+ * The type of the input connection point
246
+ */
247
+ type: U;
248
+
249
+ /**
250
+ * The runtime data for the input connection point
251
+ */
252
+ runtimeData: RuntimeData<U>;
253
+
254
+ /**
255
+ * Since this is an input connection point, it will not be auto bound
256
+ */
257
+ autoBind: undefined;
258
+ };
259
+
260
+ /**
261
+ * Represents an input which is auto-bound to the output resolution instead of an input connection point
262
+ */
263
+ type AutoBindOutputResolution = {
264
+ /**
265
+ * The name of the input
266
+ */
267
+ name: string;
268
+
269
+ /**
270
+ * The type of the input
271
+ */
272
+ type: ConnectionPointType.Vector2;
273
+
274
+ /**
275
+ * The auto bind value for the input connection point
276
+ */
277
+ autoBind: "outputResolution";
278
+ };
279
+
280
+ /**
281
+ * Represents an input which is auto-bound to the output's aspect ratio instead of an input connection point.
282
+ * The x value is the aspect ratio (width / height) and the y value is the inverse aspect ratio (height / width).
283
+ */
284
+ type AutoBindOutputAspectRatio = {
285
+ /**
286
+ * The name of the input
287
+ */
288
+ name: string;
289
+
290
+ /**
291
+ * The type of the input
292
+ */
293
+ type: ConnectionPointType.Vector2;
294
+
295
+ /**
296
+ * The auto bind value for the input connection point
297
+ */
298
+ autoBind: "outputAspectRatio";
299
+ };
300
+
301
+ /**
302
+ * All possible input types with runtime data.
303
+ */
304
+ type AnyInputWithRuntimeData =
305
+ | InputWithRuntimeData<ConnectionPointType.Boolean>
306
+ | InputWithRuntimeData<ConnectionPointType.Color3>
307
+ | InputWithRuntimeData<ConnectionPointType.Color4>
308
+ | InputWithRuntimeData<ConnectionPointType.Float>
309
+ | InputWithRuntimeData<ConnectionPointType.Texture>
310
+ | InputWithRuntimeData<ConnectionPointType.Vector2>
311
+ | AutoBindOutputResolution
312
+ | AutoBindOutputAspectRatio;