@babylonjs/smart-filters-blocks 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 (147) hide show
  1. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.d.ts.map +1 -1
  2. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js +5 -5
  3. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js.map +1 -1
  4. package/dist/blocks/babylon/demo/effects/blurBlock.d.ts.map +1 -1
  5. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts +1 -1
  6. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts.map +1 -1
  7. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js +3 -5
  8. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js.map +1 -1
  9. package/dist/blocks/babylon/demo/effects/blurBlock.js +8 -13
  10. package/dist/blocks/babylon/demo/effects/blurBlock.js.map +1 -1
  11. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts +1 -1
  12. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts.map +1 -1
  13. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.js +1 -1
  14. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts +7 -7
  15. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts.map +1 -1
  16. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts +1 -1
  17. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts.map +1 -1
  18. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js +2 -3
  19. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js.map +1 -1
  20. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts +4 -2
  21. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts.map +1 -1
  22. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js +5 -2
  23. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js.map +1 -1
  24. package/dist/blocks/babylon/demo/effects/compositionBlock.js +2 -6
  25. package/dist/blocks/babylon/demo/effects/compositionBlock.js.map +1 -1
  26. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts +1 -1
  27. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts.map +1 -1
  28. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.js +1 -1
  29. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts +1 -1
  30. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts.map +1 -1
  31. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js +6 -6
  32. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js.map +1 -1
  33. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts +1 -1
  34. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts.map +1 -1
  35. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js +6 -6
  36. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js.map +1 -1
  37. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts +3 -1
  38. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts.map +1 -1
  39. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts +1 -1
  40. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts.map +1 -1
  41. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js +4 -5
  42. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js.map +1 -1
  43. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js +32 -37
  44. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js.map +1 -1
  45. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts +1 -1
  46. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts.map +1 -1
  47. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.js +1 -1
  48. package/dist/blocks/babylon/demo/effects/exposureBlock.block.d.ts.map +1 -1
  49. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js +7 -7
  50. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js.map +1 -1
  51. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.d.ts.map +1 -1
  52. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js +11 -11
  53. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js.map +1 -1
  54. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts +6 -1
  55. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts.map +1 -1
  56. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js +71 -71
  57. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js.map +1 -1
  58. package/dist/blocks/babylon/demo/effects/maskBlock.block.d.ts.map +1 -1
  59. package/dist/blocks/babylon/demo/effects/maskBlock.block.js +7 -7
  60. package/dist/blocks/babylon/demo/effects/maskBlock.block.js.map +1 -1
  61. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts +2 -2
  62. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts.map +1 -1
  63. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js +8 -8
  64. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js.map +1 -1
  65. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts +1 -1
  66. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts.map +1 -1
  67. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js +6 -6
  68. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js.map +1 -1
  69. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts +5 -5
  70. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts.map +1 -1
  71. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts +4 -2
  72. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts.map +1 -1
  73. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js +5 -2
  74. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js.map +1 -1
  75. package/dist/blocks/babylon/demo/effects/spritesheetBlock.js.map +1 -1
  76. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts +1 -1
  77. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts.map +1 -1
  78. package/dist/blocks/babylon/demo/effects/tintBlock.js +10 -10
  79. package/dist/blocks/babylon/demo/effects/tintBlock.js.map +1 -1
  80. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.d.ts.map +1 -1
  81. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js +9 -9
  82. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js.map +1 -1
  83. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.d.ts.map +1 -1
  84. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js +5 -5
  85. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js.map +1 -1
  86. package/dist/blocks/blockNamespaces.d.ts.map +1 -1
  87. package/dist/blocks/blockNamespaces.js +2 -0
  88. package/dist/blocks/blockNamespaces.js.map +1 -1
  89. package/dist/blocks/blockTypes.d.ts.map +1 -1
  90. package/dist/blocks/blockTypes.js +2 -0
  91. package/dist/blocks/blockTypes.js.map +1 -1
  92. package/dist/blocks/index.d.ts.map +1 -1
  93. package/dist/blocks/index.js +1 -0
  94. package/dist/blocks/index.js.map +1 -1
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +1 -0
  97. package/dist/index.js.map +1 -1
  98. package/dist/registration/IBlockRegistration.d.ts +1 -1
  99. package/dist/registration/IBlockRegistration.d.ts.map +1 -1
  100. package/dist/registration/blockSerializers.d.ts.map +1 -1
  101. package/dist/registration/blockSerializers.js +6 -8
  102. package/dist/registration/blockSerializers.js.map +1 -1
  103. package/dist/registration/builtInBlockRegistrations.d.ts +1 -1
  104. package/dist/registration/builtInBlockRegistrations.d.ts.map +1 -1
  105. package/dist/registration/builtInBlockRegistrations.js +50 -52
  106. package/dist/registration/builtInBlockRegistrations.js.map +1 -1
  107. package/dist/registration/index.d.ts +1 -0
  108. package/dist/registration/index.d.ts.map +1 -1
  109. package/dist/registration/index.js +2 -0
  110. package/dist/registration/index.js.map +1 -1
  111. package/license.md +21 -21
  112. package/package.json +15 -13
  113. package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.ts +8 -7
  114. package/src/blocks/babylon/demo/effects/blurBlock.deserializer.ts +37 -37
  115. package/src/blocks/babylon/demo/effects/blurBlock.serializer.ts +31 -31
  116. package/src/blocks/babylon/demo/effects/blurBlock.ts +115 -122
  117. package/src/blocks/babylon/demo/effects/compositionBlock.deserializer.ts +31 -31
  118. package/src/blocks/babylon/demo/effects/compositionBlock.fragment.ts +7 -3
  119. package/src/blocks/babylon/demo/effects/compositionBlock.serializer.ts +28 -28
  120. package/src/blocks/babylon/demo/effects/compositionBlock.ts +211 -243
  121. package/src/blocks/babylon/demo/effects/contrastBlock.block.ts +9 -8
  122. package/src/blocks/babylon/demo/effects/desaturateBlock.block.ts +9 -8
  123. package/src/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.ts +43 -46
  124. package/src/blocks/babylon/demo/effects/directionalBlurBlock.serializer.ts +30 -30
  125. package/src/blocks/babylon/demo/effects/directionalBlurBlock.ts +192 -196
  126. package/src/blocks/babylon/demo/effects/exposureBlock.block.ts +10 -9
  127. package/src/blocks/babylon/demo/effects/greenScreenBlock.block.ts +14 -13
  128. package/src/blocks/babylon/demo/effects/index.ts +14 -14
  129. package/src/blocks/babylon/demo/effects/kaleidoscopeBlock.ts +188 -192
  130. package/src/blocks/babylon/demo/effects/maskBlock.block.ts +10 -9
  131. package/src/blocks/babylon/demo/effects/pixelateBlock.block.ts +11 -10
  132. package/src/blocks/babylon/demo/effects/posterizeBlock.block.ts +9 -8
  133. package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.ts +7 -3
  134. package/src/blocks/babylon/demo/effects/spritesheetBlock.ts +135 -138
  135. package/src/blocks/babylon/demo/effects/tintBlock.ts +51 -51
  136. package/src/blocks/babylon/demo/transitions/index.ts +1 -1
  137. package/src/blocks/babylon/demo/transitions/wipeBlock.block.ts +12 -11
  138. package/src/blocks/babylon/demo/utilities/index.ts +1 -1
  139. package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.ts +8 -7
  140. package/src/blocks/blockNamespaces.ts +6 -4
  141. package/src/blocks/blockTypes.ts +23 -21
  142. package/src/blocks/index.ts +6 -5
  143. package/src/index.ts +3 -2
  144. package/src/registration/IBlockRegistration.ts +43 -48
  145. package/src/registration/blockSerializers.ts +50 -52
  146. package/src/registration/builtInBlockRegistrations.ts +293 -403
  147. package/src/registration/index.ts +4 -2
@@ -1,243 +1,211 @@
1
- import type { Effect } from "@babylonjs/core/Materials/effect";
2
- import {
3
- DisableableShaderBinding,
4
- type RuntimeData,
5
- ConnectionPointType,
6
- type IDisableableBlock,
7
- DisableableShaderBlock,
8
- type SmartFilter,
9
- createStrongRef,
10
- PropertyTypeForEdition,
11
- editableInPropertyPage,
12
- } from "@babylonjs/smart-filters";
13
- import { compositionBlockType } from "../../../blockTypes.js";
14
- import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
15
- import { uniforms, shaderProgram } from "./compositionBlock.fragment.js";
16
-
17
- /** Defines that alpha blending is disabled */
18
- export const ALPHA_DISABLE = 0;
19
- /** Defines that alpha blending is SRC ALPHA * SRC + DEST */
20
- export const ALPHA_ADD = 1;
21
- /** Defines that alpha blending is SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */
22
- export const ALPHA_COMBINE = 2;
23
- /** Defines that alpha blending is DEST - SRC * DEST */
24
- export const ALPHA_SUBTRACT = 3;
25
- /** Defines that alpha blending is SRC * DEST */
26
- export const ALPHA_MULTIPLY = 4;
27
-
28
- /**
29
- * The shader bindings for the Composition block.
30
- * This demonstrates how multiple input connection point values can be packed into a single
31
- * uniform.
32
- */
33
- export class CompositionShaderBinding extends DisableableShaderBinding {
34
- private readonly _backgroundTexture: RuntimeData<ConnectionPointType.Texture>;
35
- private readonly _foregroundTexture: RuntimeData<ConnectionPointType.Texture>;
36
- private readonly _foregroundTop: RuntimeData<ConnectionPointType.Float>;
37
- private readonly _foregroundLeft: RuntimeData<ConnectionPointType.Float>;
38
- private readonly _foregroundWidth: RuntimeData<ConnectionPointType.Float>;
39
- private readonly _foregroundHeight: RuntimeData<ConnectionPointType.Float>;
40
- private readonly _foregroundAlphaScale: RuntimeData<ConnectionPointType.Float>;
41
- private readonly _alphaMode: number;
42
-
43
- /**
44
- * Creates a new shader binding instance for the Composition block.
45
- * @param parentBlock - The parent block
46
- * @param backgroundTexture - the background texture
47
- * @param foregroundTexture - the foreground texture
48
- * @param foregroundTop - the top position of the foreground texture
49
- * @param foregroundLeft - the left position of the foreground texture
50
- * @param foregroundWidth - the width of the foreground texture
51
- * @param foregroundHeight - the height of the foreground texture
52
- * @param foregroundAlphaScale - the alpha scale of the foreground texture
53
- * @param alphaMode - the alpha mode to use
54
- */
55
- constructor(
56
- parentBlock: IDisableableBlock,
57
- backgroundTexture: RuntimeData<ConnectionPointType.Texture>,
58
- foregroundTexture: RuntimeData<ConnectionPointType.Texture>,
59
- foregroundTop: RuntimeData<ConnectionPointType.Float>,
60
- foregroundLeft: RuntimeData<ConnectionPointType.Float>,
61
- foregroundWidth: RuntimeData<ConnectionPointType.Float>,
62
- foregroundHeight: RuntimeData<ConnectionPointType.Float>,
63
- foregroundAlphaScale: RuntimeData<ConnectionPointType.Float>,
64
- alphaMode: number
65
- ) {
66
- super(parentBlock);
67
- this._backgroundTexture = backgroundTexture;
68
- this._foregroundTexture = foregroundTexture;
69
- this._foregroundTop = foregroundTop;
70
- this._foregroundLeft = foregroundLeft;
71
- this._foregroundWidth = foregroundWidth;
72
- this._foregroundHeight = foregroundHeight;
73
- this._foregroundAlphaScale = foregroundAlphaScale;
74
- this._alphaMode = alphaMode;
75
- }
76
-
77
- /**
78
- * Binds all the required data to the shader when rendering.
79
- * @param effect - defines the effect to bind the data to
80
- * @param width - defines the width of the output
81
- * @param height - defines the height of the output
82
- */
83
- public override bind(effect: Effect, width: number, height: number): void {
84
- super.bind(effect, width, height);
85
-
86
- const background = this._backgroundTexture.value;
87
- const foreground = this._foregroundTexture.value;
88
- const foregroundTop = this._foregroundTop.value;
89
- const foregroundLeft = this._foregroundLeft.value;
90
- const foregroundWidth = this._foregroundWidth.value;
91
- const foregroundHeight = this._foregroundHeight.value;
92
- const foregroundAlphaScale = this._foregroundAlphaScale.value;
93
- const alphaMode = this._alphaMode;
94
-
95
- effect.setFloat(this.getRemappedName(uniforms.alphaMode), alphaMode);
96
- effect.setTexture(this.getRemappedName(uniforms.background), background);
97
- effect.setTexture(this.getRemappedName(uniforms.foreground), foreground);
98
-
99
- // NOTE: textures may always be undefined if connected to another shader block when the graph is optimized
100
-
101
- effect.setFloat2(this.getRemappedName(uniforms.scaleUV), foregroundWidth, foregroundHeight);
102
- effect.setFloat2(this.getRemappedName(uniforms.translateUV), -1 * foregroundLeft, foregroundTop);
103
- effect.setFloat(this.getRemappedName(uniforms.foregroundAlphaScale), foregroundAlphaScale);
104
- }
105
- }
106
-
107
- /**
108
- * A simple compositing Block letting the filter "blend" 2 different layers.
109
- * It demonstrates how a block can use properties for values which will not change at runtime (alphaMode)
110
- *
111
- * The alpha mode of the block can be set to one of the following:
112
- * - ALPHA_DISABLE: alpha blending is disabled
113
- * - ALPHA_ADD: alpha blending is SRC ALPHA * SRC + DEST
114
- * - ALPHA_COMBINE: alpha blending is SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST
115
- * - ALPHA_SUBTRACT: alpha blending is DEST - SRC * DEST
116
- * - ALPHA_MULTIPLY: alpha blending is SRC * DEST
117
- */
118
- export class CompositionBlock extends DisableableShaderBlock {
119
- /**
120
- * The class name of the block.
121
- */
122
- public static override ClassName = compositionBlockType;
123
-
124
- /**
125
- * The namespace of the block.
126
- */
127
- public static override Namespace = babylonDemoEffectsNamespace;
128
-
129
- /**
130
- * The background texture to composite on to.
131
- */
132
- public readonly background = this._registerInput(uniforms.background, ConnectionPointType.Texture);
133
-
134
- /**
135
- * The foreground texture to composite in.
136
- */
137
- public readonly foreground = this._registerOptionalInput(
138
- uniforms.foreground,
139
- ConnectionPointType.Texture,
140
- createStrongRef(null)
141
- );
142
-
143
- /**
144
- * Defines where the top of the texture to composite in should be displayed. (between 0 and 1).
145
- */
146
- public readonly foregroundTop = this._registerOptionalInput(
147
- "foregroundTop",
148
- ConnectionPointType.Float,
149
- createStrongRef(0.0)
150
- );
151
-
152
- /**
153
- * Defines where the left of the texture to composite in should be displayed. (between 0 and 1).
154
- */
155
- public readonly foregroundLeft = this._registerOptionalInput(
156
- "foregroundLeft",
157
- ConnectionPointType.Float,
158
- createStrongRef(0.0)
159
- );
160
-
161
- /**
162
- * Defines the width of the texture in the composition.
163
- */
164
- public readonly foregroundWidth = this._registerOptionalInput(
165
- "foregroundWidth",
166
- ConnectionPointType.Float,
167
- createStrongRef(1.0)
168
- );
169
-
170
- /**
171
- * Defines the height of the texture in the composition.
172
- */
173
- public readonly foregroundHeight = this._registerOptionalInput(
174
- "foregroundHeight",
175
- ConnectionPointType.Float,
176
- createStrongRef(1.0)
177
- );
178
-
179
- /**
180
- * Defines a multiplier applied to the foreground's alpha channel.
181
- */
182
- public readonly foregroundAlphaScale = this._registerOptionalInput(
183
- uniforms.foregroundAlphaScale,
184
- ConnectionPointType.Float,
185
- createStrongRef(1.0)
186
- );
187
-
188
- /**
189
- * Defines blend mode of the composition.
190
- */
191
- @editableInPropertyPage("Alpha Mode", PropertyTypeForEdition.List, "PROPERTIES", {
192
- notifiers: { rebuild: true },
193
- options: [
194
- { label: "Disable", value: ALPHA_DISABLE },
195
- { label: "Add", value: ALPHA_ADD },
196
- { label: "Combine", value: ALPHA_COMBINE },
197
- { label: "Subtract", value: ALPHA_SUBTRACT },
198
- { label: "Multiply", value: ALPHA_MULTIPLY },
199
- ],
200
- })
201
- public alphaMode: number = ALPHA_COMBINE;
202
-
203
- /**
204
- * The shader program (vertex and fragment code) to use to render the block
205
- */
206
- public static override ShaderCode = shaderProgram;
207
-
208
- /**
209
- * Instantiates a new Block.
210
- * @param smartFilter - The smart filter this block belongs to
211
- * @param name - The friendly name of the block
212
- */
213
- constructor(smartFilter: SmartFilter, name: string) {
214
- super(smartFilter, name, true);
215
- }
216
-
217
- /**
218
- * Get the class instance that binds all the required data to the shader (effect) when rendering.
219
- * @returns The class instance that binds the data to the effect
220
- */
221
- public getShaderBinding(): DisableableShaderBinding {
222
- const background = this._confirmRuntimeDataSupplied(this.background);
223
- const foreground = this._confirmRuntimeDataSupplied(this.foreground);
224
- const foregroundWidth = this.foregroundWidth.runtimeData;
225
- const foregroundLeft = this.foregroundLeft.runtimeData;
226
- const foregroundHeight = this.foregroundHeight.runtimeData;
227
- const foregroundTop = this.foregroundTop.runtimeData;
228
- const foregroundAlphaScale = this.foregroundAlphaScale.runtimeData;
229
- const alphaMode = this.alphaMode;
230
-
231
- return new CompositionShaderBinding(
232
- this,
233
- background,
234
- foreground,
235
- foregroundTop,
236
- foregroundLeft,
237
- foregroundWidth,
238
- foregroundHeight,
239
- foregroundAlphaScale,
240
- alphaMode
241
- );
242
- }
243
- }
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+
3
+ import type { Effect } from "core/Materials/effect.js";
4
+ import {
5
+ DisableableShaderBinding,
6
+ type RuntimeData,
7
+ ConnectionPointType,
8
+ type IDisableableBlock,
9
+ DisableableShaderBlock,
10
+ type SmartFilter,
11
+ createStrongRef,
12
+ PropertyTypeForEdition,
13
+ editableInPropertyPage,
14
+ } from "smart-filters";
15
+ import { compositionBlockType } from "../../../blockTypes.js";
16
+ import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
17
+ import { uniforms, shaderProgram } from "./compositionBlock.fragment.js";
18
+
19
+ /** Defines that alpha blending is disabled */
20
+ export const ALPHA_DISABLE = 0;
21
+ /** Defines that alpha blending is SRC ALPHA * SRC + DEST */
22
+ export const ALPHA_ADD = 1;
23
+ /** Defines that alpha blending is SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */
24
+ export const ALPHA_COMBINE = 2;
25
+ /** Defines that alpha blending is DEST - SRC * DEST */
26
+ export const ALPHA_SUBTRACT = 3;
27
+ /** Defines that alpha blending is SRC * DEST */
28
+ export const ALPHA_MULTIPLY = 4;
29
+
30
+ /**
31
+ * The shader bindings for the Composition block.
32
+ * This demonstrates how multiple input connection point values can be packed into a single
33
+ * uniform.
34
+ */
35
+ export class CompositionShaderBinding extends DisableableShaderBinding {
36
+ private readonly _backgroundTexture: RuntimeData<ConnectionPointType.Texture>;
37
+ private readonly _foregroundTexture: RuntimeData<ConnectionPointType.Texture>;
38
+ private readonly _foregroundTop: RuntimeData<ConnectionPointType.Float>;
39
+ private readonly _foregroundLeft: RuntimeData<ConnectionPointType.Float>;
40
+ private readonly _foregroundWidth: RuntimeData<ConnectionPointType.Float>;
41
+ private readonly _foregroundHeight: RuntimeData<ConnectionPointType.Float>;
42
+ private readonly _foregroundAlphaScale: RuntimeData<ConnectionPointType.Float>;
43
+ private readonly _alphaMode: number;
44
+
45
+ /**
46
+ * Creates a new shader binding instance for the Composition block.
47
+ * @param parentBlock - The parent block
48
+ * @param backgroundTexture - the background texture
49
+ * @param foregroundTexture - the foreground texture
50
+ * @param foregroundTop - the top position of the foreground texture
51
+ * @param foregroundLeft - the left position of the foreground texture
52
+ * @param foregroundWidth - the width of the foreground texture
53
+ * @param foregroundHeight - the height of the foreground texture
54
+ * @param foregroundAlphaScale - the alpha scale of the foreground texture
55
+ * @param alphaMode - the alpha mode to use
56
+ */
57
+ constructor(
58
+ parentBlock: IDisableableBlock,
59
+ backgroundTexture: RuntimeData<ConnectionPointType.Texture>,
60
+ foregroundTexture: RuntimeData<ConnectionPointType.Texture>,
61
+ foregroundTop: RuntimeData<ConnectionPointType.Float>,
62
+ foregroundLeft: RuntimeData<ConnectionPointType.Float>,
63
+ foregroundWidth: RuntimeData<ConnectionPointType.Float>,
64
+ foregroundHeight: RuntimeData<ConnectionPointType.Float>,
65
+ foregroundAlphaScale: RuntimeData<ConnectionPointType.Float>,
66
+ alphaMode: number
67
+ ) {
68
+ super(parentBlock);
69
+ this._backgroundTexture = backgroundTexture;
70
+ this._foregroundTexture = foregroundTexture;
71
+ this._foregroundTop = foregroundTop;
72
+ this._foregroundLeft = foregroundLeft;
73
+ this._foregroundWidth = foregroundWidth;
74
+ this._foregroundHeight = foregroundHeight;
75
+ this._foregroundAlphaScale = foregroundAlphaScale;
76
+ this._alphaMode = alphaMode;
77
+ }
78
+
79
+ /**
80
+ * Binds all the required data to the shader when rendering.
81
+ * @param effect - defines the effect to bind the data to
82
+ * @param width - defines the width of the output
83
+ * @param height - defines the height of the output
84
+ */
85
+ public override bind(effect: Effect, width: number, height: number): void {
86
+ super.bind(effect, width, height);
87
+
88
+ const background = this._backgroundTexture.value;
89
+ const foreground = this._foregroundTexture.value;
90
+ const foregroundTop = this._foregroundTop.value;
91
+ const foregroundLeft = this._foregroundLeft.value;
92
+ const foregroundWidth = this._foregroundWidth.value;
93
+ const foregroundHeight = this._foregroundHeight.value;
94
+ const foregroundAlphaScale = this._foregroundAlphaScale.value;
95
+ const alphaMode = this._alphaMode;
96
+
97
+ effect.setFloat(this.getRemappedName(uniforms.alphaMode), alphaMode);
98
+ effect.setTexture(this.getRemappedName(uniforms.background), background);
99
+ effect.setTexture(this.getRemappedName(uniforms.foreground), foreground);
100
+
101
+ // NOTE: textures may always be undefined if connected to another shader block when the graph is optimized
102
+
103
+ effect.setFloat2(this.getRemappedName(uniforms.scaleUV), foregroundWidth, foregroundHeight);
104
+ effect.setFloat2(this.getRemappedName(uniforms.translateUV), -1 * foregroundLeft, foregroundTop);
105
+ effect.setFloat(this.getRemappedName(uniforms.foregroundAlphaScale), foregroundAlphaScale);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * A simple compositing Block letting the filter "blend" 2 different layers.
111
+ * It demonstrates how a block can use properties for values which will not change at runtime (alphaMode)
112
+ *
113
+ * The alpha mode of the block can be set to one of the following:
114
+ * - ALPHA_DISABLE: alpha blending is disabled
115
+ * - ALPHA_ADD: alpha blending is SRC ALPHA * SRC + DEST
116
+ * - ALPHA_COMBINE: alpha blending is SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST
117
+ * - ALPHA_SUBTRACT: alpha blending is DEST - SRC * DEST
118
+ * - ALPHA_MULTIPLY: alpha blending is SRC * DEST
119
+ */
120
+ export class CompositionBlock extends DisableableShaderBlock {
121
+ /**
122
+ * The class name of the block.
123
+ */
124
+ public static override ClassName = compositionBlockType;
125
+
126
+ /**
127
+ * The namespace of the block.
128
+ */
129
+ public static override Namespace = babylonDemoEffectsNamespace;
130
+
131
+ /**
132
+ * The background texture to composite on to.
133
+ */
134
+ public readonly background = this._registerInput(uniforms.background, ConnectionPointType.Texture);
135
+
136
+ /**
137
+ * The foreground texture to composite in.
138
+ */
139
+ public readonly foreground = this._registerOptionalInput(uniforms.foreground, ConnectionPointType.Texture, createStrongRef(null));
140
+
141
+ /**
142
+ * Defines where the top of the texture to composite in should be displayed. (between 0 and 1).
143
+ */
144
+ public readonly foregroundTop = this._registerOptionalInput("foregroundTop", ConnectionPointType.Float, createStrongRef(0.0));
145
+
146
+ /**
147
+ * Defines where the left of the texture to composite in should be displayed. (between 0 and 1).
148
+ */
149
+ public readonly foregroundLeft = this._registerOptionalInput("foregroundLeft", ConnectionPointType.Float, createStrongRef(0.0));
150
+
151
+ /**
152
+ * Defines the width of the texture in the composition.
153
+ */
154
+ public readonly foregroundWidth = this._registerOptionalInput("foregroundWidth", ConnectionPointType.Float, createStrongRef(1.0));
155
+
156
+ /**
157
+ * Defines the height of the texture in the composition.
158
+ */
159
+ public readonly foregroundHeight = this._registerOptionalInput("foregroundHeight", ConnectionPointType.Float, createStrongRef(1.0));
160
+
161
+ /**
162
+ * Defines a multiplier applied to the foreground's alpha channel.
163
+ */
164
+ public readonly foregroundAlphaScale = this._registerOptionalInput(uniforms.foregroundAlphaScale, ConnectionPointType.Float, createStrongRef(1.0));
165
+
166
+ /**
167
+ * Defines blend mode of the composition.
168
+ */
169
+ @editableInPropertyPage("Alpha Mode", PropertyTypeForEdition.List, "PROPERTIES", {
170
+ notifiers: { rebuild: true },
171
+ options: [
172
+ { label: "Disable", value: ALPHA_DISABLE },
173
+ { label: "Add", value: ALPHA_ADD },
174
+ { label: "Combine", value: ALPHA_COMBINE },
175
+ { label: "Subtract", value: ALPHA_SUBTRACT },
176
+ { label: "Multiply", value: ALPHA_MULTIPLY },
177
+ ],
178
+ })
179
+ public alphaMode: number = ALPHA_COMBINE;
180
+
181
+ /**
182
+ * The shader program (vertex and fragment code) to use to render the block
183
+ */
184
+ public static override ShaderCode = shaderProgram;
185
+
186
+ /**
187
+ * Instantiates a new Block.
188
+ * @param smartFilter - The smart filter this block belongs to
189
+ * @param name - The friendly name of the block
190
+ */
191
+ constructor(smartFilter: SmartFilter, name: string) {
192
+ super(smartFilter, name, true);
193
+ }
194
+
195
+ /**
196
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
197
+ * @returns The class instance that binds the data to the effect
198
+ */
199
+ public getShaderBinding(): DisableableShaderBinding {
200
+ const background = this._confirmRuntimeDataSupplied(this.background);
201
+ const foreground = this._confirmRuntimeDataSupplied(this.foreground);
202
+ const foregroundWidth = this.foregroundWidth.runtimeData;
203
+ const foregroundLeft = this.foregroundLeft.runtimeData;
204
+ const foregroundHeight = this.foregroundHeight.runtimeData;
205
+ const foregroundTop = this.foregroundTop.runtimeData;
206
+ const foregroundAlphaScale = this.foregroundAlphaScale.runtimeData;
207
+ const alphaMode = this.alphaMode;
208
+
209
+ return new CompositionShaderBinding(this, background, foreground, foregroundTop, foregroundLeft, foregroundWidth, foregroundHeight, foregroundAlphaScale, alphaMode);
210
+ }
211
+ }
@@ -8,7 +8,7 @@
8
8
  // to the block. This file will get overwritten when the build
9
9
  // is run or during a watch when the .glsl file is updated.
10
10
 
11
- import type { Effect } from "@babylonjs/core/Materials/effect";
11
+ import type { Effect } from "core/Materials/effect.js";
12
12
 
13
13
  import {
14
14
  DisableableShaderBinding,
@@ -19,12 +19,12 @@ import {
19
19
  type ShaderProgram,
20
20
  createStrongRef,
21
21
  type IDisableableBlock,
22
- BlockDisableStrategy} from "@babylonjs/smart-filters";
22
+ BlockDisableStrategy} from "smart-filters";
23
23
 
24
24
  /**
25
25
  * The shader program for the block.
26
26
  */
27
- const shaderProgram: ShaderProgram = {
27
+ const BlockShaderProgram: ShaderProgram = {
28
28
  vertex: undefined,
29
29
  fragment: {
30
30
  uniform: `
@@ -81,11 +81,12 @@ const shaderProgram: ShaderProgram = {
81
81
  * The uniform names for this shader, to be used in the shader binding so
82
82
  * that the names are always in sync.
83
83
  */
84
- const uniforms = {
84
+ const Uniforms = {
85
85
  input: "input",
86
86
  intensity: "intensity",
87
87
  };
88
88
 
89
+
89
90
  /**
90
91
  * The shader binding for the ContrastBlock, used by the runtime
91
92
  */
@@ -115,8 +116,8 @@ class ContrastBlockShaderBinding extends DisableableShaderBinding {
115
116
  */
116
117
  public override bind(effect: Effect): void {
117
118
  super.bind(effect);
118
- effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
119
- effect.setFloat(this.getRemappedName(uniforms.intensity), this._intensity.value);
119
+ effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
120
+ effect.setFloat(this.getRemappedName(Uniforms.intensity), this._intensity.value);
120
121
  }
121
122
  }
122
123
 
@@ -137,7 +138,7 @@ export class ContrastBlock extends DisableableShaderBlock {
137
138
  /**
138
139
  * The input connection point.
139
140
  */
140
- public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
141
+ public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
141
142
 
142
143
  /**
143
144
  /**
@@ -152,7 +153,7 @@ export class ContrastBlock extends DisableableShaderBlock {
152
153
  /**
153
154
  * The shader program (vertex and fragment code) to use to render the block
154
155
  */
155
- public static override ShaderCode = shaderProgram;
156
+ public static override ShaderCode = BlockShaderProgram;
156
157
 
157
158
  /**
158
159
  * Instantiates a new ContrastBlock.
@@ -8,7 +8,7 @@
8
8
  // to the block. This file will get overwritten when the build
9
9
  // is run or during a watch when the .glsl file is updated.
10
10
 
11
- import type { Effect } from "@babylonjs/core/Materials/effect";
11
+ import type { Effect } from "core/Materials/effect.js";
12
12
 
13
13
  import {
14
14
  DisableableShaderBinding,
@@ -19,12 +19,12 @@ import {
19
19
  type ShaderProgram,
20
20
  createStrongRef,
21
21
  type IDisableableBlock,
22
- BlockDisableStrategy} from "@babylonjs/smart-filters";
22
+ BlockDisableStrategy} from "smart-filters";
23
23
 
24
24
  /**
25
25
  * The shader program for the block.
26
26
  */
27
- const shaderProgram: ShaderProgram = {
27
+ const BlockShaderProgram: ShaderProgram = {
28
28
  vertex: undefined,
29
29
  fragment: {
30
30
  uniform: `
@@ -58,11 +58,12 @@ const shaderProgram: ShaderProgram = {
58
58
  * The uniform names for this shader, to be used in the shader binding so
59
59
  * that the names are always in sync.
60
60
  */
61
- const uniforms = {
61
+ const Uniforms = {
62
62
  input: "input",
63
63
  intensity: "intensity",
64
64
  };
65
65
 
66
+
66
67
  /**
67
68
  * The shader binding for the DesaturateBlock, used by the runtime
68
69
  */
@@ -92,8 +93,8 @@ class DesaturateBlockShaderBinding extends DisableableShaderBinding {
92
93
  */
93
94
  public override bind(effect: Effect): void {
94
95
  super.bind(effect);
95
- effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
96
- effect.setFloat(this.getRemappedName(uniforms.intensity), this._intensity.value);
96
+ effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
97
+ effect.setFloat(this.getRemappedName(Uniforms.intensity), this._intensity.value);
97
98
  }
98
99
  }
99
100
 
@@ -114,7 +115,7 @@ export class DesaturateBlock extends DisableableShaderBlock {
114
115
  /**
115
116
  * The input connection point.
116
117
  */
117
- public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
118
+ public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
118
119
 
119
120
  /**
120
121
  /**
@@ -129,7 +130,7 @@ export class DesaturateBlock extends DisableableShaderBlock {
129
130
  /**
130
131
  * The shader program (vertex and fragment code) to use to render the block
131
132
  */
132
- public static override ShaderCode = shaderProgram;
133
+ public static override ShaderCode = BlockShaderProgram;
133
134
 
134
135
  /**
135
136
  * Instantiates a new DesaturateBlock.