@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,142 @@
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
+ uniform float _amount_;`,
32
+ mainInputTexture: "_input_",
33
+ mainFunctionName: "_exposure_",
34
+ functions: [
35
+ {
36
+ name: "_exposure_",
37
+ code: `
38
+ vec4 _exposure_(vec2 vUV) {
39
+ vec4 color = texture2D(_input_, vUV);
40
+ return vec4(color.rgb * _amount_, color.a);
41
+ }
42
+
43
+ `,
44
+ params: "vec2 vUV",
45
+ },
46
+ ],
47
+ },
48
+ };
49
+
50
+ /**
51
+ * The uniform names for this shader, to be used in the shader binding so
52
+ * that the names are always in sync.
53
+ */
54
+ const uniforms = {
55
+ input: "input",
56
+ amount: "amount",
57
+ };
58
+
59
+ /**
60
+ * The shader binding for the ExposureBlock, used by the runtime
61
+ */
62
+ class ExposureBlockShaderBinding extends DisableableShaderBinding {
63
+ private readonly _input: RuntimeData<ConnectionPointType.Texture>;
64
+ private readonly _amount: RuntimeData<ConnectionPointType.Float>;
65
+
66
+ /**
67
+ * Creates a new shader binding instance for the block.
68
+ * @param parentBlock - IDisableableBlock
69
+ * @param input - The input runtime value
70
+ * @param amount - The amount runtime value
71
+ */
72
+ constructor(
73
+ parentBlock: IDisableableBlock,
74
+ input: RuntimeData<ConnectionPointType.Texture>,
75
+ amount: RuntimeData<ConnectionPointType.Float>
76
+ ) {
77
+ super(parentBlock);
78
+ this._input = input;
79
+ this._amount = amount;
80
+ }
81
+
82
+ /**
83
+ * Binds all the required data to the shader when rendering.
84
+ * @param effect - defines the effect to bind the data to
85
+ */
86
+ public override bind(effect: Effect): void {
87
+ super.bind(effect);
88
+ effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
89
+ effect.setFloat(this.getRemappedName(uniforms.amount), this._amount.value);
90
+ }
91
+ }
92
+
93
+ /**
94
+ * The implementation of the ExposureBlock
95
+ */
96
+ export class ExposureBlock extends DisableableShaderBlock {
97
+ /**
98
+ * The class name of the block.
99
+ */
100
+ public static override ClassName = "ExposureBlock";
101
+
102
+ /**
103
+ * The namespace of the block.
104
+ */
105
+ public static override Namespace = "Babylon.Demo.Effects";
106
+
107
+ /**
108
+ * The input connection point.
109
+ */
110
+ public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
111
+
112
+ /**
113
+ * The amount connection point.
114
+ */
115
+ public readonly amount = this._registerInput(uniforms.amount, ConnectionPointType.Float);
116
+
117
+ /**
118
+ * The shader program (vertex and fragment code) to use to render the block
119
+ */
120
+ public static override ShaderCode = shaderProgram;
121
+
122
+ /**
123
+ * Instantiates a new ExposureBlock.
124
+ * @param smartFilter - The smart filter this block belongs to
125
+ * @param name - The friendly name of the block
126
+ */
127
+ constructor(smartFilter: SmartFilter, name: string) {
128
+ super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
129
+ }
130
+
131
+ /**
132
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
133
+ * @returns The class instance that binds the data to the effect
134
+ */
135
+ public getShaderBinding(): DisableableShaderBinding {
136
+ const input = this._confirmRuntimeDataSupplied(this.input);
137
+ const amount = this._confirmRuntimeDataSupplied(this.amount);
138
+
139
+ return new ExposureBlockShaderBinding(this,input,amount);
140
+ }
141
+ }
142
+
@@ -0,0 +1,23 @@
1
+ /*
2
+ {
3
+ "smartFilterBlockType": "GreenScreenBlock",
4
+ "namespace": "Babylon.Demo.Effects",
5
+ "blockDisableStrategy": "AutoSample"
6
+ }
7
+ */
8
+
9
+ uniform sampler2D input; // main
10
+ uniform sampler2D background;
11
+ uniform vec3 reference;
12
+ uniform float distance;
13
+
14
+ vec4 greenScreen(vec2 vUV) { // main
15
+ vec4 color = texture2D(input, vUV);
16
+ vec4 background = texture2D(background, vUV);
17
+
18
+ if (length(color.rgb - reference) < distance) {
19
+ return background;
20
+ }
21
+
22
+ return color;
23
+ }
@@ -0,0 +1,174 @@
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
+ uniform sampler2D _background_;
32
+ uniform vec3 _reference_;
33
+ uniform float _distance_;`,
34
+ mainInputTexture: "_input_",
35
+ mainFunctionName: "_greenScreen_",
36
+ functions: [
37
+ {
38
+ name: "_greenScreen_",
39
+ code: `
40
+ vec4 _greenScreen_(vec2 vUV) {
41
+ vec4 color = texture2D(_input_, vUV);
42
+ vec4 _background_ = texture2D(_background_, vUV);
43
+
44
+ if (length(color.rgb - _reference_) < _distance_) {
45
+ return _background_;
46
+ }
47
+
48
+ return color;
49
+ }
50
+
51
+ `,
52
+ params: "vec2 vUV",
53
+ },
54
+ ],
55
+ },
56
+ };
57
+
58
+ /**
59
+ * The uniform names for this shader, to be used in the shader binding so
60
+ * that the names are always in sync.
61
+ */
62
+ const uniforms = {
63
+ input: "input",
64
+ background: "background",
65
+ reference: "reference",
66
+ distance: "distance",
67
+ };
68
+
69
+ /**
70
+ * The shader binding for the GreenScreenBlock, used by the runtime
71
+ */
72
+ class GreenScreenBlockShaderBinding extends DisableableShaderBinding {
73
+ private readonly _input: RuntimeData<ConnectionPointType.Texture>;
74
+ private readonly _background: RuntimeData<ConnectionPointType.Texture>;
75
+ private readonly _reference: RuntimeData<ConnectionPointType.Color3>;
76
+ private readonly _distance: RuntimeData<ConnectionPointType.Float>;
77
+
78
+ /**
79
+ * Creates a new shader binding instance for the block.
80
+ * @param parentBlock - IDisableableBlock
81
+ * @param input - The input runtime value
82
+ * @param background - The background runtime value
83
+ * @param reference - The reference runtime value
84
+ * @param distance - The distance runtime value
85
+ */
86
+ constructor(
87
+ parentBlock: IDisableableBlock,
88
+ input: RuntimeData<ConnectionPointType.Texture>,
89
+ background: RuntimeData<ConnectionPointType.Texture>,
90
+ reference: RuntimeData<ConnectionPointType.Color3>,
91
+ distance: RuntimeData<ConnectionPointType.Float>
92
+ ) {
93
+ super(parentBlock);
94
+ this._input = input;
95
+ this._background = background;
96
+ this._reference = reference;
97
+ this._distance = distance;
98
+ }
99
+
100
+ /**
101
+ * Binds all the required data to the shader when rendering.
102
+ * @param effect - defines the effect to bind the data to
103
+ */
104
+ public override bind(effect: Effect): void {
105
+ super.bind(effect);
106
+ effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
107
+ effect.setTexture(this.getRemappedName(uniforms.background), this._background.value);
108
+ effect.setColor3(this.getRemappedName(uniforms.reference), this._reference.value);
109
+ effect.setFloat(this.getRemappedName(uniforms.distance), this._distance.value);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * The implementation of the GreenScreenBlock
115
+ */
116
+ export class GreenScreenBlock extends DisableableShaderBlock {
117
+ /**
118
+ * The class name of the block.
119
+ */
120
+ public static override ClassName = "GreenScreenBlock";
121
+
122
+ /**
123
+ * The namespace of the block.
124
+ */
125
+ public static override Namespace = "Babylon.Demo.Effects";
126
+
127
+ /**
128
+ * The input connection point.
129
+ */
130
+ public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
131
+
132
+ /**
133
+ * The background connection point.
134
+ */
135
+ public readonly background = this._registerInput(uniforms.background, ConnectionPointType.Texture);
136
+
137
+ /**
138
+ * The reference connection point.
139
+ */
140
+ public readonly reference = this._registerInput(uniforms.reference, ConnectionPointType.Color3);
141
+
142
+ /**
143
+ * The distance connection point.
144
+ */
145
+ public readonly distance = this._registerInput(uniforms.distance, ConnectionPointType.Float);
146
+
147
+ /**
148
+ * The shader program (vertex and fragment code) to use to render the block
149
+ */
150
+ public static override ShaderCode = shaderProgram;
151
+
152
+ /**
153
+ * Instantiates a new GreenScreenBlock.
154
+ * @param smartFilter - The smart filter this block belongs to
155
+ * @param name - The friendly name of the block
156
+ */
157
+ constructor(smartFilter: SmartFilter, name: string) {
158
+ super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
159
+ }
160
+
161
+ /**
162
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
163
+ * @returns The class instance that binds the data to the effect
164
+ */
165
+ public getShaderBinding(): DisableableShaderBinding {
166
+ const input = this._confirmRuntimeDataSupplied(this.input);
167
+ const background = this._confirmRuntimeDataSupplied(this.background);
168
+ const reference = this._confirmRuntimeDataSupplied(this.reference);
169
+ const distance = this._confirmRuntimeDataSupplied(this.distance);
170
+
171
+ return new GreenScreenBlockShaderBinding(this,input,background,reference,distance);
172
+ }
173
+ }
174
+
@@ -0,0 +1,14 @@
1
+ export * from "./blackAndWhiteBlock.block.js";
2
+ export * from "./blurBlock.js";
3
+ export * from "./compositionBlock.js";
4
+ export * from "./contrastBlock.block.js";
5
+ export * from "./desaturateBlock.block.js";
6
+ export * from "./directionalBlurBlock.js";
7
+ export * from "./exposureBlock.block.js";
8
+ export * from "./greenScreenBlock.block.js";
9
+ export * from "./kaleidoscopeBlock.js";
10
+ export * from "./maskBlock.block.js";
11
+ export * from "./pixelateBlock.block.js";
12
+ export * from "./posterizeBlock.block.js";
13
+ export * from "./spritesheetBlock.js";
14
+ export * from "./tintBlock.js";
@@ -0,0 +1,192 @@
1
+ import type { Effect } from "@babylonjs/core/Materials/effect";
2
+
3
+ import {
4
+ type ShaderProgram,
5
+ DisableableShaderBinding,
6
+ type RuntimeData,
7
+ ConnectionPointType,
8
+ type IDisableableBlock,
9
+ DisableableShaderBlock,
10
+ type SmartFilter,
11
+ BlockDisableStrategy,
12
+ } from "@babylonjs/smart-filters";
13
+
14
+ import { kaleidoscopeBlockType } from "../../../blockTypes.js";
15
+ import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
16
+
17
+ /**
18
+ * This block uses a custom vertex shader, so it defines the ShaderProgram inline
19
+ */
20
+ const shaderProgram: ShaderProgram = {
21
+ vertex: `
22
+ // Attributes
23
+ attribute vec2 position;
24
+
25
+ // Output
26
+ varying vec2 vUV;
27
+
28
+ void main(void) {
29
+ vUV = position;
30
+ gl_Position = vec4(position, 0.0, 1.0);
31
+ }
32
+ `,
33
+
34
+ fragment: {
35
+ uniform: `
36
+ uniform sampler2D _input_;
37
+ uniform float _time_;
38
+ uniform bool _disabled_;
39
+ `,
40
+
41
+ const: `
42
+ const float _width_ = 200.;
43
+ const float _height_ = 300.;
44
+ const vec2 _imageRatio_ = vec2(700. / _width_, 1024. / _height_);
45
+ const vec2 _imageRelativeSize_ = 1. / _imageRatio_;
46
+ const float _halfDiag_ = sqrt(_imageRelativeSize_.x * _imageRelativeSize_.x + _imageRelativeSize_.y * _imageRelativeSize_.y) * 0.5;
47
+
48
+ const float _radius_ = 0.9;
49
+ const float _radius2_ = 0.4;
50
+
51
+ const float _segments_ = 6.;
52
+ const float _segmentArc_ = (2. * 3.1415926535897932384626433832795 / _segments_);
53
+ `,
54
+
55
+ mainFunctionName: "_kaleidoscope_",
56
+
57
+ mainInputTexture: "_input_",
58
+
59
+ functions: [
60
+ {
61
+ name: "_kaleidoscope_",
62
+ code: `
63
+ vec4 _kaleidoscope_(vec2 vUV) {
64
+ if (_disabled_) return texture2D(_input_, vUV);
65
+
66
+ float distanceToCircle = abs(length(vUV) - _radius_);
67
+ vec4 result = vec4(0., 0., 0., 0.);
68
+
69
+ if (distanceToCircle < _halfDiag_ * 10000.) {
70
+ float pointTheta = atan(vUV.y, vUV.x);
71
+ pointTheta += _time_;
72
+ for (float i = -1.; i < 2.; i += 1.) {
73
+ float chunk = floor(pointTheta / _segmentArc_) + i;
74
+ float chunkStart = -_time_ + chunk * _segmentArc_ + _segmentArc_ * 0.5;
75
+ vec2 chunkStartCenter = vec2(cos(chunkStart), sin(chunkStart)) * _radius_;
76
+ vec2 chunkStartPoint = vUV - chunkStartCenter;
77
+ chunkStartPoint *= _imageRatio_;
78
+ chunkStartPoint *= vec2(0.5, 0.5);
79
+ chunkStartPoint += vec2(0.5, 0.5);
80
+
81
+ if (chunkStartPoint.x > 0. && chunkStartPoint.x < 1. && chunkStartPoint.y > 0. && chunkStartPoint.y < 1.) {
82
+ result = texture2D(_input_, chunkStartPoint);
83
+ }
84
+ }
85
+
86
+ for (float i = -1.; i < 2.; i += 1.) {
87
+ float chunk = floor(pointTheta / _segmentArc_) + i;
88
+ float chunkStart = -_time_ + chunk * _segmentArc_ + _segmentArc_ * 0.5;
89
+ vec2 chunkStartCenter = vec2(cos(chunkStart), sin(chunkStart)) * _radius2_;
90
+ vec2 chunkStartPoint = vUV - chunkStartCenter;
91
+ chunkStartPoint *= _imageRatio_;
92
+ chunkStartPoint *= vec2(0.5, 0.5);
93
+ chunkStartPoint += vec2(0.5, 0.5);
94
+
95
+ if (chunkStartPoint.x > 0. && chunkStartPoint.x < 1. && chunkStartPoint.y > 0. && chunkStartPoint.y < 1.) {
96
+ vec4 top = texture2D(_input_, chunkStartPoint);
97
+ result = mix(result, top, (result.a <= 0.) ? 1. : top.a);
98
+ }
99
+ }
100
+ }
101
+
102
+ return result;
103
+ }
104
+ `,
105
+ },
106
+ ],
107
+ },
108
+ };
109
+
110
+ /**
111
+ * The shader bindings for the Kaleidoscope block.
112
+ */
113
+ export class KaleidoscopeShaderBinding extends DisableableShaderBinding {
114
+ private readonly _inputTexture: RuntimeData<ConnectionPointType.Texture>;
115
+ private readonly _time: RuntimeData<ConnectionPointType.Float>;
116
+
117
+ /**
118
+ * Creates a new shader binding instance for the Kaleidoscope block.
119
+ * @param parentBlock - The parent block
120
+ * @param inputTexture - the input texture
121
+ * @param time - the time
122
+ */
123
+ constructor(
124
+ parentBlock: IDisableableBlock,
125
+ inputTexture: RuntimeData<ConnectionPointType.Texture>,
126
+ time: RuntimeData<ConnectionPointType.Float>
127
+ ) {
128
+ super(parentBlock);
129
+ this._inputTexture = inputTexture;
130
+ this._time = time;
131
+ }
132
+
133
+ /**
134
+ * Binds all the required data to the shader when rendering.
135
+ * @param effect - defines the effect to bind the data to
136
+ */
137
+ public override bind(effect: Effect): void {
138
+ super.bind(effect);
139
+ effect.setTexture(this.getRemappedName("input"), this._inputTexture.value);
140
+ effect.setFloat(this.getRemappedName("time"), this._time.value);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * A block performing a Kaleidoscope looking like effect.
146
+ */
147
+ export class KaleidoscopeBlock extends DisableableShaderBlock {
148
+ /**
149
+ * The class name of the block.
150
+ */
151
+ public static override ClassName = kaleidoscopeBlockType;
152
+
153
+ /**
154
+ * The namespace of the block.
155
+ */
156
+ public static override Namespace = babylonDemoEffectsNamespace;
157
+
158
+ /**
159
+ * The input texture connection point.
160
+ */
161
+ public readonly input = this._registerInput("input", ConnectionPointType.Texture);
162
+
163
+ /**
164
+ * The time connection point.
165
+ */
166
+ public readonly time = this._registerInput("time", ConnectionPointType.Float);
167
+
168
+ /**
169
+ * The shader program (vertex and fragment code) to use to render the block
170
+ */
171
+ public static override ShaderCode = shaderProgram;
172
+
173
+ /**
174
+ * Instantiates a new Block.
175
+ * @param smartFilter - The smart filter this block belongs to
176
+ * @param name - The friendly name of the block
177
+ */
178
+ constructor(smartFilter: SmartFilter, name: string) {
179
+ super(smartFilter, name, false, BlockDisableStrategy.Manual);
180
+ }
181
+
182
+ /**
183
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
184
+ * @returns The class instance that binds the data to the effect
185
+ */
186
+ public getShaderBinding(): DisableableShaderBinding {
187
+ const input = this._confirmRuntimeDataSupplied(this.input);
188
+ const time = this._confirmRuntimeDataSupplied(this.time);
189
+
190
+ return new KaleidoscopeShaderBinding(this, input, time);
191
+ }
192
+ }
@@ -0,0 +1,18 @@
1
+ /*
2
+ {
3
+ "smartFilterBlockType": "MaskBlock",
4
+ "namespace": "Babylon.Demo.Effects",
5
+ "blockDisableStrategy": "AutoSample"
6
+ }
7
+ */
8
+
9
+ uniform sampler2D input; // main
10
+ uniform sampler2D mask;
11
+
12
+ vec4 maskBlock(vec2 vUV) { // main
13
+ vec4 color = texture2D(input, vUV);
14
+ vec3 maskColor = texture2D(mask, vUV).rgb;
15
+ float luminance = dot(maskColor, vec3(0.3, 0.59, 0.11));
16
+
17
+ return vec4(color.rgb * luminance, luminance * color.a);
18
+ }