@babylonjs/smart-filters-blocks 0.8.1

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 (190) hide show
  1. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.d.ts +34 -0
  2. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.d.ts.map +1 -0
  3. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js +101 -0
  4. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js.map +1 -0
  5. package/dist/blocks/babylon/demo/effects/blurBlock.d.ts +53 -0
  6. package/dist/blocks/babylon/demo/effects/blurBlock.d.ts.map +1 -0
  7. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts +28 -0
  8. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts.map +1 -0
  9. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js +17 -0
  10. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js.map +1 -0
  11. package/dist/blocks/babylon/demo/effects/blurBlock.js +98 -0
  12. package/dist/blocks/babylon/demo/effects/blurBlock.js.map +1 -0
  13. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts +8 -0
  14. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts.map +1 -0
  15. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.js +28 -0
  16. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.js.map +1 -0
  17. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts +116 -0
  18. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts.map +1 -0
  19. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts +24 -0
  20. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts.map +1 -0
  21. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js +15 -0
  22. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js.map +1 -0
  23. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts +18 -0
  24. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts.map +1 -0
  25. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js +69 -0
  26. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js.map +1 -0
  27. package/dist/blocks/babylon/demo/effects/compositionBlock.js +167 -0
  28. package/dist/blocks/babylon/demo/effects/compositionBlock.js.map +1 -0
  29. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts +6 -0
  30. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts.map +1 -0
  31. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.js +25 -0
  32. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.js.map +1 -0
  33. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts +39 -0
  34. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts.map +1 -0
  35. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js +140 -0
  36. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js.map +1 -0
  37. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts +39 -0
  38. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts.map +1 -0
  39. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js +115 -0
  40. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js.map +1 -0
  41. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts +74 -0
  42. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts.map +1 -0
  43. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts +32 -0
  44. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts.map +1 -0
  45. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js +17 -0
  46. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js.map +1 -0
  47. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js +167 -0
  48. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js.map +1 -0
  49. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts +6 -0
  50. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts.map +1 -0
  51. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.js +27 -0
  52. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.js.map +1 -0
  53. package/dist/blocks/babylon/demo/effects/exposureBlock.block.d.ts +38 -0
  54. package/dist/blocks/babylon/demo/effects/exposureBlock.block.d.ts.map +1 -0
  55. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js +107 -0
  56. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js.map +1 -0
  57. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.d.ts +46 -0
  58. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.d.ts.map +1 -0
  59. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js +133 -0
  60. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js.map +1 -0
  61. package/dist/blocks/babylon/demo/effects/index.d.ts +15 -0
  62. package/dist/blocks/babylon/demo/effects/index.d.ts.map +1 -0
  63. package/dist/blocks/babylon/demo/effects/index.js +15 -0
  64. package/dist/blocks/babylon/demo/effects/index.js.map +1 -0
  65. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts +58 -0
  66. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts.map +1 -0
  67. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js +158 -0
  68. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js.map +1 -0
  69. package/dist/blocks/babylon/demo/effects/maskBlock.block.d.ts +38 -0
  70. package/dist/blocks/babylon/demo/effects/maskBlock.block.d.ts.map +1 -0
  71. package/dist/blocks/babylon/demo/effects/maskBlock.block.js +110 -0
  72. package/dist/blocks/babylon/demo/effects/maskBlock.block.js.map +1 -0
  73. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts +44 -0
  74. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts.map +1 -0
  75. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js +125 -0
  76. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js.map +1 -0
  77. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts +39 -0
  78. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts.map +1 -0
  79. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js +116 -0
  80. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js.map +1 -0
  81. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts +77 -0
  82. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts.map +1 -0
  83. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts +18 -0
  84. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts.map +1 -0
  85. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js +58 -0
  86. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js.map +1 -0
  87. package/dist/blocks/babylon/demo/effects/spritesheetBlock.js +98 -0
  88. package/dist/blocks/babylon/demo/effects/spritesheetBlock.js.map +1 -0
  89. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts +7 -0
  90. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts.map +1 -0
  91. package/dist/blocks/babylon/demo/effects/tintBlock.js +51 -0
  92. package/dist/blocks/babylon/demo/effects/tintBlock.js.map +1 -0
  93. package/dist/blocks/babylon/demo/transitions/index.d.ts +2 -0
  94. package/dist/blocks/babylon/demo/transitions/index.d.ts.map +1 -0
  95. package/dist/blocks/babylon/demo/transitions/index.js +2 -0
  96. package/dist/blocks/babylon/demo/transitions/index.js.map +1 -0
  97. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.d.ts +42 -0
  98. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.d.ts.map +1 -0
  99. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js +116 -0
  100. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js.map +1 -0
  101. package/dist/blocks/babylon/demo/utilities/index.d.ts +2 -0
  102. package/dist/blocks/babylon/demo/utilities/index.d.ts.map +1 -0
  103. package/dist/blocks/babylon/demo/utilities/index.js +2 -0
  104. package/dist/blocks/babylon/demo/utilities/index.js.map +1 -0
  105. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.d.ts +34 -0
  106. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.d.ts.map +1 -0
  107. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js +97 -0
  108. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js.map +1 -0
  109. package/dist/blocks/blockNamespaces.d.ts +5 -0
  110. package/dist/blocks/blockNamespaces.d.ts.map +1 -0
  111. package/dist/blocks/blockNamespaces.js +5 -0
  112. package/dist/blocks/blockNamespaces.js.map +1 -0
  113. package/dist/blocks/blockTypes.d.ts +22 -0
  114. package/dist/blocks/blockTypes.d.ts.map +1 -0
  115. package/dist/blocks/blockTypes.js +22 -0
  116. package/dist/blocks/blockTypes.js.map +1 -0
  117. package/dist/blocks/index.d.ts +6 -0
  118. package/dist/blocks/index.d.ts.map +1 -0
  119. package/dist/blocks/index.js +6 -0
  120. package/dist/blocks/index.js.map +1 -0
  121. package/dist/index.d.ts +3 -0
  122. package/dist/index.d.ts.map +1 -0
  123. package/dist/index.js +3 -0
  124. package/dist/index.js.map +1 -0
  125. package/dist/registration/IBlockRegistration.d.ts +34 -0
  126. package/dist/registration/IBlockRegistration.d.ts.map +1 -0
  127. package/dist/registration/IBlockRegistration.js +2 -0
  128. package/dist/registration/IBlockRegistration.js.map +1 -0
  129. package/dist/registration/blockSerializers.d.ts +13 -0
  130. package/dist/registration/blockSerializers.d.ts.map +1 -0
  131. package/dist/registration/blockSerializers.js +35 -0
  132. package/dist/registration/blockSerializers.js.map +1 -0
  133. package/dist/registration/builtInBlockRegistrations.d.ts +13 -0
  134. package/dist/registration/builtInBlockRegistrations.d.ts.map +1 -0
  135. package/dist/registration/builtInBlockRegistrations.js +269 -0
  136. package/dist/registration/builtInBlockRegistrations.js.map +1 -0
  137. package/dist/registration/index.d.ts +3 -0
  138. package/dist/registration/index.d.ts.map +1 -0
  139. package/dist/registration/index.js +3 -0
  140. package/dist/registration/index.js.map +1 -0
  141. package/license.md +21 -0
  142. package/package.json +52 -0
  143. package/readme.md +7 -0
  144. package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.glsl +18 -0
  145. package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.ts +133 -0
  146. package/src/blocks/babylon/demo/effects/blurBlock.deserializer.ts +37 -0
  147. package/src/blocks/babylon/demo/effects/blurBlock.serializer.ts +31 -0
  148. package/src/blocks/babylon/demo/effects/blurBlock.ts +122 -0
  149. package/src/blocks/babylon/demo/effects/compositionBlock.deserializer.ts +31 -0
  150. package/src/blocks/babylon/demo/effects/compositionBlock.fragment.glsl +38 -0
  151. package/src/blocks/babylon/demo/effects/compositionBlock.fragment.ts +71 -0
  152. package/src/blocks/babylon/demo/effects/compositionBlock.serializer.ts +28 -0
  153. package/src/blocks/babylon/demo/effects/compositionBlock.ts +243 -0
  154. package/src/blocks/babylon/demo/effects/contrastBlock.block.glsl +36 -0
  155. package/src/blocks/babylon/demo/effects/contrastBlock.block.ts +180 -0
  156. package/src/blocks/babylon/demo/effects/desaturateBlock.block.glsl +24 -0
  157. package/src/blocks/babylon/demo/effects/desaturateBlock.block.ts +155 -0
  158. package/src/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.ts +46 -0
  159. package/src/blocks/babylon/demo/effects/directionalBlurBlock.serializer.ts +30 -0
  160. package/src/blocks/babylon/demo/effects/directionalBlurBlock.ts +196 -0
  161. package/src/blocks/babylon/demo/effects/exposureBlock.block.glsl +15 -0
  162. package/src/blocks/babylon/demo/effects/exposureBlock.block.ts +142 -0
  163. package/src/blocks/babylon/demo/effects/greenScreenBlock.block.glsl +23 -0
  164. package/src/blocks/babylon/demo/effects/greenScreenBlock.block.ts +174 -0
  165. package/src/blocks/babylon/demo/effects/index.ts +14 -0
  166. package/src/blocks/babylon/demo/effects/kaleidoscopeBlock.ts +192 -0
  167. package/src/blocks/babylon/demo/effects/maskBlock.block.glsl +18 -0
  168. package/src/blocks/babylon/demo/effects/maskBlock.block.ts +145 -0
  169. package/src/blocks/babylon/demo/effects/pixelateBlock.block.glsl +28 -0
  170. package/src/blocks/babylon/demo/effects/pixelateBlock.block.ts +169 -0
  171. package/src/blocks/babylon/demo/effects/posterizeBlock.block.glsl +25 -0
  172. package/src/blocks/babylon/demo/effects/posterizeBlock.block.ts +156 -0
  173. package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.glsl +26 -0
  174. package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.ts +60 -0
  175. package/src/blocks/babylon/demo/effects/spritesheetBlock.ts +138 -0
  176. package/src/blocks/babylon/demo/effects/tintBlock.ts +51 -0
  177. package/src/blocks/babylon/demo/transitions/index.ts +1 -0
  178. package/src/blocks/babylon/demo/transitions/wipeBlock.block.glsl +11 -0
  179. package/src/blocks/babylon/demo/transitions/wipeBlock.block.ts +152 -0
  180. package/src/blocks/babylon/demo/utilities/index.ts +1 -0
  181. package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.glsl +14 -0
  182. package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.ts +129 -0
  183. package/src/blocks/blockNamespaces.ts +4 -0
  184. package/src/blocks/blockTypes.ts +21 -0
  185. package/src/blocks/index.ts +5 -0
  186. package/src/index.ts +2 -0
  187. package/src/registration/IBlockRegistration.ts +43 -0
  188. package/src/registration/blockSerializers.ts +52 -0
  189. package/src/registration/builtInBlockRegistrations.ts +397 -0
  190. package/src/registration/index.ts +2 -0
@@ -0,0 +1,138 @@
1
+ import type { Effect } from "@babylonjs/core/Materials/effect";
2
+
3
+ import { spritesheetBlockType } from "../../../blockTypes.js";
4
+ import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
5
+ import { shaderProgram, uniforms } from "./spritesheetBlock.fragment.js";
6
+ import {
7
+ DisableableShaderBinding,
8
+ type RuntimeData,
9
+ ConnectionPointType,
10
+ type IDisableableBlock,
11
+ DisableableShaderBlock,
12
+ type SmartFilter,
13
+ createStrongRef,
14
+ BlockDisableStrategy,
15
+ } from "@babylonjs/smart-filters";
16
+
17
+ /**
18
+ * The shader bindings for the Spritesheet block.
19
+ */
20
+ export class SpritesheetShaderBinding extends DisableableShaderBinding {
21
+ private readonly _inputTexture: RuntimeData<ConnectionPointType.Texture>;
22
+ private readonly _time: RuntimeData<ConnectionPointType.Float>;
23
+ private readonly _rows: RuntimeData<ConnectionPointType.Float>;
24
+ private readonly _cols: RuntimeData<ConnectionPointType.Float>;
25
+ private readonly _frames: RuntimeData<ConnectionPointType.Float>;
26
+
27
+ /**
28
+ * Creates a new shader binding instance for the SpriteSheet block.
29
+ * @param parentBlock - The parent block
30
+ * @param inputTexture - The input texture
31
+ * @param time - The time passed since the start of the effect
32
+ * @param rows - The number of rows in the sprite sheet
33
+ * @param cols - The number of columns in the sprite sheet
34
+ * @param frames - The number of frames to show
35
+ */
36
+ constructor(
37
+ parentBlock: IDisableableBlock,
38
+ inputTexture: RuntimeData<ConnectionPointType.Texture>,
39
+ time: RuntimeData<ConnectionPointType.Float>,
40
+ rows: RuntimeData<ConnectionPointType.Float>,
41
+ cols: RuntimeData<ConnectionPointType.Float>,
42
+ frames: RuntimeData<ConnectionPointType.Float>
43
+ ) {
44
+ super(parentBlock);
45
+ this._inputTexture = inputTexture;
46
+ this._time = time;
47
+ this._rows = rows;
48
+ this._cols = cols;
49
+ this._frames = frames;
50
+ }
51
+
52
+ /**
53
+ * Binds all the required data to the shader when rendering.
54
+ * @param effect - defines the effect to bind the data to
55
+ */
56
+ public override bind(effect: Effect): void {
57
+ super.bind(effect);
58
+ effect.setTexture(this.getRemappedName(uniforms.input), this._inputTexture.value);
59
+ effect.setFloat(this.getRemappedName(uniforms.time), this._time.value);
60
+ effect.setFloat(this.getRemappedName(uniforms.rows), this._rows.value);
61
+ effect.setFloat(this.getRemappedName(uniforms.cols), this._cols.value);
62
+
63
+ // Apply default value for frame count if it was not provided
64
+ effect.setFloat(
65
+ this.getRemappedName(uniforms.frames),
66
+ this._frames.value > 0 ? this._frames.value : this._rows.value * this._cols.value
67
+ );
68
+ }
69
+ }
70
+
71
+ /**
72
+ * A block that animates a sprite sheet texture.
73
+ */
74
+ export class SpritesheetBlock extends DisableableShaderBlock {
75
+ /**
76
+ * The class name of the block.
77
+ */
78
+ public static override ClassName = spritesheetBlockType;
79
+
80
+ /**
81
+ * The namespace of the block.
82
+ */
83
+ public static override Namespace = babylonDemoEffectsNamespace;
84
+
85
+ /**
86
+ * The input texture connection point
87
+ */
88
+ public readonly input = this._registerInput("input", ConnectionPointType.Texture);
89
+
90
+ /**
91
+ * The time connection point to animate the effect.
92
+ */
93
+ public readonly time = this._registerOptionalInput("time", ConnectionPointType.Float, createStrongRef(0.0));
94
+
95
+ /**
96
+ * The number of rows in the sprite sheet, as a connection point.
97
+ */
98
+ public readonly rows = this._registerOptionalInput("rows", ConnectionPointType.Float, createStrongRef(1.0));
99
+
100
+ /**
101
+ * The number of columns in the sprite sheet, as a connection point.
102
+ */
103
+ public readonly columns = this._registerOptionalInput("columns", ConnectionPointType.Float, createStrongRef(1.0));
104
+
105
+ /**
106
+ * The number of frames to animate from the beginning, as a connection point.
107
+ * Defaults to rows * columns at runtime.
108
+ */
109
+ public readonly frames = this._registerOptionalInput("frames", ConnectionPointType.Float, createStrongRef(0.0));
110
+
111
+ /**
112
+ * The shader program (vertex and fragment code) to use to render the block
113
+ */
114
+ public static override ShaderCode = shaderProgram;
115
+
116
+ /**
117
+ * Instantiates a new Block.
118
+ * @param smartFilter - The smart filter this block belongs to
119
+ * @param name - The friendly name of the block
120
+ */
121
+ constructor(smartFilter: SmartFilter, name: string) {
122
+ super(smartFilter, name, false, BlockDisableStrategy.Manual);
123
+ }
124
+
125
+ /**
126
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
127
+ * @returns The class instance that binds the data to the effect
128
+ */
129
+ public getShaderBinding(): DisableableShaderBinding {
130
+ const input = this._confirmRuntimeDataSupplied(this.input);
131
+ const rows = this.rows.runtimeData;
132
+ const columns = this.columns.runtimeData;
133
+ const time = this.time.runtimeData;
134
+ const frames = this.frames.runtimeData;
135
+
136
+ return new SpritesheetShaderBinding(this, input, time, rows, columns, frames);
137
+ }
138
+ }
@@ -0,0 +1,51 @@
1
+ import { ConnectionPointType, type SerializedShaderBlockDefinition } from "@babylonjs/smart-filters";
2
+
3
+ /**
4
+ * This is included to show how a serialized block definition can be loaded and used.
5
+ * This object could have been deserialized from a JSON file, for example.
6
+ */
7
+ export const deserializedTintBlockDefinition: SerializedShaderBlockDefinition = {
8
+ format: "shaderBlockDefinition",
9
+ formatVersion: 1,
10
+ blockType: "TintBlock",
11
+ namespace: "Babylon.Demo.Effects",
12
+ shaderProgram: {
13
+ fragment: {
14
+ uniform: `
15
+ uniform sampler2D _input_; // main
16
+ uniform vec3 _tint_;
17
+ uniform float _amount_;
18
+ `,
19
+ mainInputTexture: "_input_",
20
+ mainFunctionName: "_mainImage_",
21
+ functions: [
22
+ {
23
+ name: "_mainImage_",
24
+ code: `
25
+ vec4 _mainImage_(vec2 vUV) {
26
+ vec4 color = texture2D(_input_, vUV);
27
+ vec3 tinted = mix(color.rgb, _tint_, _amount_);
28
+ return vec4(tinted, color.a);
29
+ }`,
30
+ },
31
+ ],
32
+ },
33
+ },
34
+ inputConnectionPoints: [
35
+ {
36
+ name: "input",
37
+ type: ConnectionPointType.Texture,
38
+ },
39
+ {
40
+ name: "tint",
41
+ type: ConnectionPointType.Color3,
42
+ defaultValue: { r: 1, g: 0, b: 0 },
43
+ },
44
+ {
45
+ name: "amount",
46
+ type: ConnectionPointType.Float,
47
+ defaultValue: 0.25,
48
+ },
49
+ ],
50
+ disableOptimization: false,
51
+ };
@@ -0,0 +1 @@
1
+ export * from "./wipeBlock.block.js";
@@ -0,0 +1,11 @@
1
+ // { "smartFilterBlockType": "WipeBlock", "namespace": "Babylon.Demo.Transitions" }
2
+
3
+ uniform sampler2D textureA;
4
+ uniform sampler2D textureB;
5
+ uniform float progress;
6
+
7
+ vec4 wipe(vec2 vUV) { // main
8
+ vec4 colorA = texture2D(textureA, vUV);
9
+ vec4 colorB = texture2D(textureB, vUV);
10
+ return mix(colorB, colorA, step(progress, vUV.y));
11
+ }
@@ -0,0 +1,152 @@
1
+ /* eslint-disable prettier/prettier */
2
+ // ************************************************************
3
+ // Note: this file is auto-generated, do not modify it directly
4
+ // ************************************************************
5
+
6
+ // It was generated by convertGlslIntoBlock() from
7
+ // an annotated .glsl file. Modify the .glsl file to make changes
8
+ // to the block. This file will get overwritten when the build
9
+ // is run or during a watch when the .glsl file is updated.
10
+
11
+ import type { Effect } from "@babylonjs/core/Materials/effect";
12
+
13
+ import {
14
+ ShaderBinding,
15
+ type RuntimeData,
16
+ ConnectionPointType,
17
+ type SmartFilter,
18
+ ShaderBlock,
19
+ type ShaderProgram,
20
+ } from "@babylonjs/smart-filters";
21
+
22
+ /**
23
+ * The shader program for the block.
24
+ */
25
+ const shaderProgram: ShaderProgram = {
26
+ vertex: undefined,
27
+ fragment: {
28
+ uniform: `
29
+ uniform sampler2D _textureA_;
30
+ uniform sampler2D _textureB_;
31
+ uniform float _progress_;`,
32
+ mainInputTexture: "",
33
+ mainFunctionName: "_wipe_",
34
+ functions: [
35
+ {
36
+ name: "_wipe_",
37
+ code: `
38
+ vec4 _wipe_(vec2 vUV) {
39
+ vec4 colorA = texture2D(_textureA_, vUV);
40
+ vec4 colorB = texture2D(_textureB_, vUV);
41
+ return mix(colorB, colorA, step(_progress_, vUV.y));
42
+ }
43
+
44
+ `,
45
+ params: "vec2 vUV",
46
+ },
47
+ ],
48
+ },
49
+ };
50
+
51
+ /**
52
+ * The uniform names for this shader, to be used in the shader binding so
53
+ * that the names are always in sync.
54
+ */
55
+ const uniforms = {
56
+ textureA: "textureA",
57
+ textureB: "textureB",
58
+ progress: "progress",
59
+ };
60
+
61
+ /**
62
+ * The shader binding for the WipeBlock, used by the runtime
63
+ */
64
+ class WipeBlockShaderBinding extends ShaderBinding {
65
+ private readonly _textureA: RuntimeData<ConnectionPointType.Texture>;
66
+ private readonly _textureB: RuntimeData<ConnectionPointType.Texture>;
67
+ private readonly _progress: RuntimeData<ConnectionPointType.Float>;
68
+
69
+ /**
70
+ * Creates a new shader binding instance for the block.
71
+ * @param textureA - The textureA runtime value
72
+ * @param textureB - The textureB runtime value
73
+ * @param progress - The progress runtime value
74
+ */
75
+ constructor(
76
+ textureA: RuntimeData<ConnectionPointType.Texture>,
77
+ textureB: RuntimeData<ConnectionPointType.Texture>,
78
+ progress: RuntimeData<ConnectionPointType.Float>
79
+ ) {
80
+ super();
81
+ this._textureA = textureA;
82
+ this._textureB = textureB;
83
+ this._progress = progress;
84
+ }
85
+
86
+ /**
87
+ * Binds all the required data to the shader when rendering.
88
+ * @param effect - defines the effect to bind the data to
89
+ */
90
+ public override bind(effect: Effect): void {
91
+ effect.setTexture(this.getRemappedName(uniforms.textureA), this._textureA.value);
92
+ effect.setTexture(this.getRemappedName(uniforms.textureB), this._textureB.value);
93
+ effect.setFloat(this.getRemappedName(uniforms.progress), this._progress.value);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * The implementation of the WipeBlock
99
+ */
100
+ export class WipeBlock extends ShaderBlock {
101
+ /**
102
+ * The class name of the block.
103
+ */
104
+ public static override ClassName = "WipeBlock";
105
+
106
+ /**
107
+ * The namespace of the block.
108
+ */
109
+ public static override Namespace = "Babylon.Demo.Transitions";
110
+
111
+ /**
112
+ * The textureA connection point.
113
+ */
114
+ public readonly textureA = this._registerInput(uniforms.textureA, ConnectionPointType.Texture);
115
+
116
+ /**
117
+ * The textureB connection point.
118
+ */
119
+ public readonly textureB = this._registerInput(uniforms.textureB, ConnectionPointType.Texture);
120
+
121
+ /**
122
+ * The progress connection point.
123
+ */
124
+ public readonly progress = this._registerInput(uniforms.progress, ConnectionPointType.Float);
125
+
126
+ /**
127
+ * The shader program (vertex and fragment code) to use to render the block
128
+ */
129
+ public static override ShaderCode = shaderProgram;
130
+
131
+ /**
132
+ * Instantiates a new WipeBlock.
133
+ * @param smartFilter - The smart filter this block belongs to
134
+ * @param name - The friendly name of the block
135
+ */
136
+ constructor(smartFilter: SmartFilter, name: string) {
137
+ super(smartFilter, name, false);
138
+ }
139
+
140
+ /**
141
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
142
+ * @returns The class instance that binds the data to the effect
143
+ */
144
+ public getShaderBinding(): ShaderBinding {
145
+ const textureA = this._confirmRuntimeDataSupplied(this.textureA);
146
+ const textureB = this._confirmRuntimeDataSupplied(this.textureB);
147
+ const progress = this._confirmRuntimeDataSupplied(this.progress);
148
+
149
+ return new WipeBlockShaderBinding(textureA,textureB,progress);
150
+ }
151
+ }
152
+
@@ -0,0 +1 @@
1
+ export * from "./premultiplyAlphaBlock.block.js";
@@ -0,0 +1,14 @@
1
+ /*
2
+ {
3
+ "smartFilterBlockType": "PremultiplyAlphaBlock",
4
+ "namespace": "Babylon.Demo.Utilities",
5
+ "blockDisableStrategy": "AutoSample"
6
+ }
7
+ */
8
+
9
+ uniform sampler2D input; // main
10
+
11
+ vec4 premultiply(vec2 vUV) { // main
12
+ vec4 color = texture2D(input, vUV);
13
+ return vec4(color.rgb * color.a, color.a);
14
+ }
@@ -0,0 +1,129 @@
1
+ /* eslint-disable prettier/prettier */
2
+ // ************************************************************
3
+ // Note: this file is auto-generated, do not modify it directly
4
+ // ************************************************************
5
+
6
+ // It was generated by convertGlslIntoBlock() from
7
+ // an annotated .glsl file. Modify the .glsl file to make changes
8
+ // to the block. This file will get overwritten when the build
9
+ // is run or during a watch when the .glsl file is updated.
10
+
11
+ import type { Effect } from "@babylonjs/core/Materials/effect";
12
+
13
+ import {
14
+ DisableableShaderBinding,
15
+ type RuntimeData,
16
+ ConnectionPointType,
17
+ type SmartFilter,
18
+ DisableableShaderBlock,
19
+ type ShaderProgram,
20
+ type IDisableableBlock,
21
+ BlockDisableStrategy} from "@babylonjs/smart-filters";
22
+
23
+ /**
24
+ * The shader program for the block.
25
+ */
26
+ const shaderProgram: ShaderProgram = {
27
+ vertex: undefined,
28
+ fragment: {
29
+ uniform: `
30
+ uniform sampler2D _input_; // main`,
31
+ mainInputTexture: "_input_",
32
+ mainFunctionName: "_premultiply_",
33
+ functions: [
34
+ {
35
+ name: "_premultiply_",
36
+ code: `
37
+ vec4 _premultiply_(vec2 vUV) {
38
+ vec4 color = texture2D(_input_, vUV);
39
+ return vec4(color.rgb * color.a, color.a);
40
+ }
41
+
42
+ `,
43
+ params: "vec2 vUV",
44
+ },
45
+ ],
46
+ },
47
+ };
48
+
49
+ /**
50
+ * The uniform names for this shader, to be used in the shader binding so
51
+ * that the names are always in sync.
52
+ */
53
+ const uniforms = {
54
+ input: "input",
55
+ };
56
+
57
+ /**
58
+ * The shader binding for the PremultiplyAlphaBlock, used by the runtime
59
+ */
60
+ class PremultiplyAlphaBlockShaderBinding extends DisableableShaderBinding {
61
+ private readonly _input: RuntimeData<ConnectionPointType.Texture>;
62
+
63
+ /**
64
+ * Creates a new shader binding instance for the block.
65
+ * @param parentBlock - IDisableableBlock
66
+ * @param input - The input runtime value
67
+ */
68
+ constructor(
69
+ parentBlock: IDisableableBlock,
70
+ input: RuntimeData<ConnectionPointType.Texture>
71
+ ) {
72
+ super(parentBlock);
73
+ this._input = input;
74
+ }
75
+
76
+ /**
77
+ * Binds all the required data to the shader when rendering.
78
+ * @param effect - defines the effect to bind the data to
79
+ */
80
+ public override bind(effect: Effect): void {
81
+ super.bind(effect);
82
+ effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
83
+ }
84
+ }
85
+
86
+ /**
87
+ * The implementation of the PremultiplyAlphaBlock
88
+ */
89
+ export class PremultiplyAlphaBlock extends DisableableShaderBlock {
90
+ /**
91
+ * The class name of the block.
92
+ */
93
+ public static override ClassName = "PremultiplyAlphaBlock";
94
+
95
+ /**
96
+ * The namespace of the block.
97
+ */
98
+ public static override Namespace = "Babylon.Demo.Utilities";
99
+
100
+ /**
101
+ * The input connection point.
102
+ */
103
+ public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
104
+
105
+ /**
106
+ * The shader program (vertex and fragment code) to use to render the block
107
+ */
108
+ public static override ShaderCode = shaderProgram;
109
+
110
+ /**
111
+ * Instantiates a new PremultiplyAlphaBlock.
112
+ * @param smartFilter - The smart filter this block belongs to
113
+ * @param name - The friendly name of the block
114
+ */
115
+ constructor(smartFilter: SmartFilter, name: string) {
116
+ super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
117
+ }
118
+
119
+ /**
120
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
121
+ * @returns The class instance that binds the data to the effect
122
+ */
123
+ public getShaderBinding(): DisableableShaderBinding {
124
+ const input = this._confirmRuntimeDataSupplied(this.input);
125
+
126
+ return new PremultiplyAlphaBlockShaderBinding(this,input);
127
+ }
128
+ }
129
+
@@ -0,0 +1,4 @@
1
+ export const babylonDemoEffectsNamespace = "Babylon.Demo.Effects";
2
+ export const babylonDemoUtilitiesNamespace = "Babylon.Demo.Utilities";
3
+ export const babylonDemoTransitionsNamespace = "Babylon.Demo.Transitions";
4
+ export const inputsNamespace = "Inputs";
@@ -0,0 +1,21 @@
1
+ export const pixelateBlockType = "PixelateBlock";
2
+ export const blackAndWhiteBlockType = "BlackAndWhiteBlock";
3
+ export const exposureBlockType = "ExposureBlock";
4
+ export const contrastBlockType = "ContrastBlock";
5
+ export const desaturateBlockType = "DesaturateBlock";
6
+ export const posterizeBlockType = "PosterizeBlock";
7
+ export const kaleidoscopeBlockType = "KaleidoscopeBlock";
8
+ export const greenScreenBlockType = "GreenScreenBlock";
9
+ export const glassBlockType = "GlassBlock";
10
+ export const frameBlockType = "FrameBlock";
11
+ export const blurBlockType = "BlurBlock";
12
+ export const directionalBlurBlockType = "DirectionalBlurBlock";
13
+ export const compositionBlockType = "CompositionBlock";
14
+ export const glitchBlockType = "GlitchBlock";
15
+ export const tileBlockType = "TileBlock";
16
+ export const wipeBlockType = "WipeBlock";
17
+ export const maskBlockType = "MaskBlock";
18
+ export const particleBlockType = "ParticleBlock";
19
+ export const spritesheetBlockType = "SpritesheetBlock";
20
+ export const tintBlockType = "TintBlock";
21
+ export const premultiplyAlphaBlockType = "PremultiplyAlphaBlock";
@@ -0,0 +1,5 @@
1
+ export * from "./babylon/demo/effects/index.js";
2
+ export * from "./babylon/demo/transitions/index.js";
3
+ export * from "./babylon/demo/utilities/index.js";
4
+ export * from "./blockTypes.js";
5
+ export * from "./blockNamespaces.js";
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./registration/index.js";
2
+ export * from "./blocks/index.js";
@@ -0,0 +1,43 @@
1
+ import type { ThinEngine } from "@babylonjs/core/Engines/thinEngine";
2
+ import type { SmartFilter, SmartFilterDeserializer, ISerializedBlockV1, BaseBlock } from "@babylonjs/smart-filters";
3
+
4
+ /**
5
+ * An object which describes a block definition, as well as a factory for creating a new instance of the block or
6
+ * deserializing it
7
+ */
8
+ export interface IBlockRegistration {
9
+ /**
10
+ * The block type of the block
11
+ */
12
+ blockType: string;
13
+
14
+ /**
15
+ * Creates an instance of the block, either fresh or deserialized from a serialized block
16
+ * @param smartFilter - The smart filter to create the block for
17
+ * @param engine - The engine to use for creating blocks
18
+ * @param smartFilterDeserializer - The deserializer to use for deserializing blocks
19
+ * @param serializedBlock - The serialized block to deserialize, if any
20
+ * @returns - A promise for a new instance of the block
21
+ */
22
+ factory?: (
23
+ smartFilter: SmartFilter,
24
+ engine: ThinEngine,
25
+ smartFilterDeserializer: SmartFilterDeserializer,
26
+ serializedBlock?: ISerializedBlockV1
27
+ ) => Promise<BaseBlock>;
28
+
29
+ /**
30
+ * The namespace of the block
31
+ */
32
+ namespace: string;
33
+
34
+ /**
35
+ * A tooltip for the block if displayed in an editor, for instance
36
+ */
37
+ tooltip: string;
38
+
39
+ /**
40
+ * If true, this represents a custom block (not one that was programmatically included)
41
+ */
42
+ isCustom?: boolean;
43
+ }
@@ -0,0 +1,52 @@
1
+ import type { IBlockSerializerV1 } from "@babylonjs/smart-filters";
2
+ import { blurBlockSerializer } from "../blocks/babylon/demo/effects/blurBlock.serializer.js";
3
+ import { directionalBlurBlockSerializer } from "../blocks/babylon/demo/effects/directionalBlurBlock.serializer.js";
4
+ import { compositionBlockSerializer } from "../blocks/babylon/demo/effects/compositionBlock.serializer.js";
5
+ import {
6
+ blackAndWhiteBlockType,
7
+ pixelateBlockType,
8
+ exposureBlockType,
9
+ contrastBlockType,
10
+ desaturateBlockType,
11
+ posterizeBlockType,
12
+ kaleidoscopeBlockType,
13
+ greenScreenBlockType,
14
+ maskBlockType,
15
+ particleBlockType,
16
+ spritesheetBlockType,
17
+ tintBlockType,
18
+ premultiplyAlphaBlockType,
19
+ wipeBlockType,
20
+ } from "../blocks/blockTypes.js";
21
+
22
+ /**
23
+ * Any blocks that do not need to make use of ISerializedBlockV1.data can use the default serialization and
24
+ * should go in this list. If the serializer needs to store additional info in ISerializedBlockV1.data (e.g.
25
+ * webcam source name), then it should be registered in additionalBlockSerializers below.
26
+ */
27
+ export const blocksUsingDefaultSerialization: string[] = [
28
+ blackAndWhiteBlockType,
29
+ pixelateBlockType,
30
+ exposureBlockType,
31
+ contrastBlockType,
32
+ desaturateBlockType,
33
+ posterizeBlockType,
34
+ kaleidoscopeBlockType,
35
+ greenScreenBlockType,
36
+ maskBlockType,
37
+ particleBlockType,
38
+ spritesheetBlockType,
39
+ tintBlockType,
40
+ premultiplyAlphaBlockType,
41
+ wipeBlockType,
42
+ ];
43
+
44
+ /**
45
+ * Any blocks which require serializing more information than just the connections should be registered here.
46
+ * They should make use of the ISerializedBlockV1.data field to store this information.
47
+ */
48
+ export const additionalBlockSerializers: IBlockSerializerV1[] = [
49
+ blurBlockSerializer,
50
+ directionalBlurBlockSerializer,
51
+ compositionBlockSerializer,
52
+ ];