@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,145 @@
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 _mask_;`,
32
+ mainInputTexture: "_input_",
33
+ mainFunctionName: "_maskBlock_",
34
+ functions: [
35
+ {
36
+ name: "_maskBlock_",
37
+ code: `
38
+ vec4 _maskBlock_(vec2 vUV) {
39
+ vec4 color = texture2D(_input_, vUV);
40
+ vec3 maskColor = texture2D(_mask_, vUV).rgb;
41
+ float luminance = dot(maskColor, vec3(0.3, 0.59, 0.11));
42
+
43
+ return vec4(color.rgb * luminance, luminance * color.a);
44
+ }
45
+
46
+ `,
47
+ params: "vec2 vUV",
48
+ },
49
+ ],
50
+ },
51
+ };
52
+
53
+ /**
54
+ * The uniform names for this shader, to be used in the shader binding so
55
+ * that the names are always in sync.
56
+ */
57
+ const uniforms = {
58
+ input: "input",
59
+ mask: "mask",
60
+ };
61
+
62
+ /**
63
+ * The shader binding for the MaskBlock, used by the runtime
64
+ */
65
+ class MaskBlockShaderBinding extends DisableableShaderBinding {
66
+ private readonly _input: RuntimeData<ConnectionPointType.Texture>;
67
+ private readonly _mask: RuntimeData<ConnectionPointType.Texture>;
68
+
69
+ /**
70
+ * Creates a new shader binding instance for the block.
71
+ * @param parentBlock - IDisableableBlock
72
+ * @param input - The input runtime value
73
+ * @param mask - The mask runtime value
74
+ */
75
+ constructor(
76
+ parentBlock: IDisableableBlock,
77
+ input: RuntimeData<ConnectionPointType.Texture>,
78
+ mask: RuntimeData<ConnectionPointType.Texture>
79
+ ) {
80
+ super(parentBlock);
81
+ this._input = input;
82
+ this._mask = mask;
83
+ }
84
+
85
+ /**
86
+ * Binds all the required data to the shader when rendering.
87
+ * @param effect - defines the effect to bind the data to
88
+ */
89
+ public override bind(effect: Effect): void {
90
+ super.bind(effect);
91
+ effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
92
+ effect.setTexture(this.getRemappedName(uniforms.mask), this._mask.value);
93
+ }
94
+ }
95
+
96
+ /**
97
+ * The implementation of the MaskBlock
98
+ */
99
+ export class MaskBlock extends DisableableShaderBlock {
100
+ /**
101
+ * The class name of the block.
102
+ */
103
+ public static override ClassName = "MaskBlock";
104
+
105
+ /**
106
+ * The namespace of the block.
107
+ */
108
+ public static override Namespace = "Babylon.Demo.Effects";
109
+
110
+ /**
111
+ * The input connection point.
112
+ */
113
+ public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
114
+
115
+ /**
116
+ * The mask connection point.
117
+ */
118
+ public readonly mask = this._registerInput(uniforms.mask, ConnectionPointType.Texture);
119
+
120
+ /**
121
+ * The shader program (vertex and fragment code) to use to render the block
122
+ */
123
+ public static override ShaderCode = shaderProgram;
124
+
125
+ /**
126
+ * Instantiates a new MaskBlock.
127
+ * @param smartFilter - The smart filter this block belongs to
128
+ * @param name - The friendly name of the block
129
+ */
130
+ constructor(smartFilter: SmartFilter, name: string) {
131
+ super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
132
+ }
133
+
134
+ /**
135
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
136
+ * @returns The class instance that binds the data to the effect
137
+ */
138
+ public getShaderBinding(): DisableableShaderBinding {
139
+ const input = this._confirmRuntimeDataSupplied(this.input);
140
+ const mask = this._confirmRuntimeDataSupplied(this.mask);
141
+
142
+ return new MaskBlockShaderBinding(this,input,mask);
143
+ }
144
+ }
145
+
@@ -0,0 +1,28 @@
1
+ /*
2
+ {
3
+ "smartFilterBlockType": "PixelateBlock",
4
+ "namespace": "Babylon.Demo.Effects",
5
+ "blockDisableStrategy": "Manual"
6
+ }
7
+ */
8
+
9
+ uniform sampler2D input; // main
10
+ // { "default": "0.3" }
11
+ uniform float intensity;
12
+ // { "default": false }
13
+ uniform bool disabled;
14
+
15
+ const float videoPixelatePower = 6.0;
16
+ const float videoPixelateMin = 10.0;
17
+ const float videoPixelateMax = 1920.0;
18
+
19
+ const float aspect = 1.72;
20
+
21
+ vec4 pixelate(vec2 vUV) { // main
22
+ if (!disabled) {
23
+ float pixelateStrength = mix(videoPixelateMin, videoPixelateMax, pow(1. - intensity, videoPixelatePower));
24
+ vec2 pixelate = vec2(pixelateStrength * aspect, pixelateStrength);
25
+ vUV = floor(pixelate * vUV) / pixelate;
26
+ }
27
+ return texture2D(input, vUV);
28
+ }
@@ -0,0 +1,169 @@
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
+ createStrongRef} 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 _input_; // main
30
+ uniform float _intensity_;
31
+ uniform bool _disabled_;`,
32
+ const: ` const float _videoPixelatePower_ = 6.0;
33
+ const float _videoPixelateMin_ = 10.0;
34
+ const float _videoPixelateMax_ = 1920.0;
35
+ const float _aspect_ = 1.72;`,
36
+ mainInputTexture: "_input_",
37
+ mainFunctionName: "_pixelate_",
38
+ functions: [
39
+ {
40
+ name: "_pixelate_",
41
+ code: `
42
+ vec4 _pixelate_(vec2 vUV) {
43
+ if (!_disabled_) {
44
+ float pixelateStrength = mix(_videoPixelateMin_, _videoPixelateMax_, pow(1. - _intensity_, _videoPixelatePower_));
45
+ vec2 _pixelate_ = vec2(pixelateStrength * _aspect_, pixelateStrength);
46
+ vUV = floor(_pixelate_ * vUV) / _pixelate_;
47
+ }
48
+ return texture2D(_input_, vUV);
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
+ intensity: "intensity",
65
+ disabled: "disabled",
66
+ };
67
+
68
+ /**
69
+ * The shader binding for the PixelateBlock, used by the runtime
70
+ */
71
+ class PixelateBlockShaderBinding extends ShaderBinding {
72
+ private readonly _input: RuntimeData<ConnectionPointType.Texture>;
73
+ private readonly _intensity: RuntimeData<ConnectionPointType.Float>;
74
+ private readonly _disabled: RuntimeData<ConnectionPointType.Boolean>;
75
+
76
+ /**
77
+ * Creates a new shader binding instance for the block.
78
+ * @param input - The input runtime value
79
+ * @param intensity - The intensity runtime value
80
+ * @param disabled - The disabled runtime value
81
+ */
82
+ constructor(
83
+ input: RuntimeData<ConnectionPointType.Texture>,
84
+ intensity: RuntimeData<ConnectionPointType.Float>,
85
+ disabled: RuntimeData<ConnectionPointType.Boolean>
86
+ ) {
87
+ super();
88
+ this._input = input;
89
+ this._intensity = intensity;
90
+ this._disabled = disabled;
91
+ }
92
+
93
+ /**
94
+ * Binds all the required data to the shader when rendering.
95
+ * @param effect - defines the effect to bind the data to
96
+ */
97
+ public override bind(effect: Effect): void {
98
+ effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
99
+ effect.setFloat(this.getRemappedName(uniforms.intensity), this._intensity.value);
100
+ effect.setBool(this.getRemappedName(uniforms.disabled), this._disabled.value);
101
+ }
102
+ }
103
+
104
+ /**
105
+ * The implementation of the PixelateBlock
106
+ */
107
+ export class PixelateBlock extends ShaderBlock {
108
+ /**
109
+ * The class name of the block.
110
+ */
111
+ public static override ClassName = "PixelateBlock";
112
+
113
+ /**
114
+ * The namespace of the block.
115
+ */
116
+ public static override Namespace = "Babylon.Demo.Effects";
117
+
118
+ /**
119
+ * The input connection point.
120
+ */
121
+ public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
122
+
123
+ /**
124
+ /**
125
+ * The intensity connection point.
126
+ */
127
+ public readonly intensity = this._registerOptionalInput(
128
+ "intensity",
129
+ ConnectionPointType.Float,
130
+ createStrongRef(0.3)
131
+ );
132
+
133
+ /**
134
+ /**
135
+ * The disabled connection point.
136
+ */
137
+ public readonly disabled = this._registerOptionalInput(
138
+ "disabled",
139
+ ConnectionPointType.Boolean,
140
+ createStrongRef(false)
141
+ );
142
+
143
+ /**
144
+ * The shader program (vertex and fragment code) to use to render the block
145
+ */
146
+ public static override ShaderCode = shaderProgram;
147
+
148
+ /**
149
+ * Instantiates a new PixelateBlock.
150
+ * @param smartFilter - The smart filter this block belongs to
151
+ * @param name - The friendly name of the block
152
+ */
153
+ constructor(smartFilter: SmartFilter, name: string) {
154
+ super(smartFilter, name, false);
155
+ }
156
+
157
+ /**
158
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
159
+ * @returns The class instance that binds the data to the effect
160
+ */
161
+ public getShaderBinding(): ShaderBinding {
162
+ const input = this._confirmRuntimeDataSupplied(this.input);
163
+ const intensity = this._confirmRuntimeDataSupplied(this.intensity);
164
+ const disabled = this._confirmRuntimeDataSupplied(this.disabled);
165
+
166
+ return new PixelateBlockShaderBinding(input,intensity,disabled);
167
+ }
168
+ }
169
+
@@ -0,0 +1,25 @@
1
+ /*
2
+ {
3
+ "smartFilterBlockType": "PosterizeBlock",
4
+ "namespace": "Babylon.Demo.Effects",
5
+ "blockDisableStrategy": "AutoSample"
6
+ }
7
+ */
8
+
9
+ uniform sampler2D input; // main
10
+ // { "default": 0.3 }
11
+ uniform float intensity;
12
+
13
+ const float posterizePower = 6.0;
14
+ const float minLevel = 2.0;
15
+ const float maxLevel = 256.0;
16
+
17
+ vec4 posterize(vec2 vUV) { // main
18
+ vec4 color = texture2D(input, vUV);
19
+
20
+ float posterizeStrength = mix(minLevel, maxLevel, pow(1. - intensity, posterizePower));
21
+ vec3 posterize = vec3(posterizeStrength);
22
+ color.rgb = floor(color.rgb / (1.0 / posterize)) * (1.0 / posterize);
23
+
24
+ return color;
25
+ }
@@ -0,0 +1,156 @@
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
+ createStrongRef,
21
+ type IDisableableBlock,
22
+ BlockDisableStrategy} from "@babylonjs/smart-filters";
23
+
24
+ /**
25
+ * The shader program for the block.
26
+ */
27
+ const shaderProgram: ShaderProgram = {
28
+ vertex: undefined,
29
+ fragment: {
30
+ uniform: `
31
+ uniform sampler2D _input_; // main
32
+ uniform float _intensity_;`,
33
+ const: ` const float _posterizePower_ = 6.0;
34
+ const float _minLevel_ = 2.0;
35
+ const float _maxLevel_ = 256.0;`,
36
+ mainInputTexture: "_input_",
37
+ mainFunctionName: "_posterize_",
38
+ functions: [
39
+ {
40
+ name: "_posterize_",
41
+ code: `
42
+ vec4 _posterize_(vec2 vUV) {
43
+ vec4 color = texture2D(_input_, vUV);
44
+
45
+ float posterizeStrength = mix(_minLevel_, _maxLevel_, pow(1. - _intensity_, _posterizePower_));
46
+ vec3 _posterize_ = vec3(posterizeStrength);
47
+ color.rgb = floor(color.rgb / (1.0 / _posterize_)) * (1.0 / _posterize_);
48
+
49
+ return color;
50
+ }
51
+
52
+ `,
53
+ params: "vec2 vUV",
54
+ },
55
+ ],
56
+ },
57
+ };
58
+
59
+ /**
60
+ * The uniform names for this shader, to be used in the shader binding so
61
+ * that the names are always in sync.
62
+ */
63
+ const uniforms = {
64
+ input: "input",
65
+ intensity: "intensity",
66
+ };
67
+
68
+ /**
69
+ * The shader binding for the PosterizeBlock, used by the runtime
70
+ */
71
+ class PosterizeBlockShaderBinding extends DisableableShaderBinding {
72
+ private readonly _input: RuntimeData<ConnectionPointType.Texture>;
73
+ private readonly _intensity: RuntimeData<ConnectionPointType.Float>;
74
+
75
+ /**
76
+ * Creates a new shader binding instance for the block.
77
+ * @param parentBlock - IDisableableBlock
78
+ * @param input - The input runtime value
79
+ * @param intensity - The intensity runtime value
80
+ */
81
+ constructor(
82
+ parentBlock: IDisableableBlock,
83
+ input: RuntimeData<ConnectionPointType.Texture>,
84
+ intensity: RuntimeData<ConnectionPointType.Float>
85
+ ) {
86
+ super(parentBlock);
87
+ this._input = input;
88
+ this._intensity = intensity;
89
+ }
90
+
91
+ /**
92
+ * Binds all the required data to the shader when rendering.
93
+ * @param effect - defines the effect to bind the data to
94
+ */
95
+ public override bind(effect: Effect): void {
96
+ super.bind(effect);
97
+ effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
98
+ effect.setFloat(this.getRemappedName(uniforms.intensity), this._intensity.value);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * The implementation of the PosterizeBlock
104
+ */
105
+ export class PosterizeBlock extends DisableableShaderBlock {
106
+ /**
107
+ * The class name of the block.
108
+ */
109
+ public static override ClassName = "PosterizeBlock";
110
+
111
+ /**
112
+ * The namespace of the block.
113
+ */
114
+ public static override Namespace = "Babylon.Demo.Effects";
115
+
116
+ /**
117
+ * The input connection point.
118
+ */
119
+ public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
120
+
121
+ /**
122
+ /**
123
+ * The intensity connection point.
124
+ */
125
+ public readonly intensity = this._registerOptionalInput(
126
+ "intensity",
127
+ ConnectionPointType.Float,
128
+ createStrongRef(0.3)
129
+ );
130
+
131
+ /**
132
+ * The shader program (vertex and fragment code) to use to render the block
133
+ */
134
+ public static override ShaderCode = shaderProgram;
135
+
136
+ /**
137
+ * Instantiates a new PosterizeBlock.
138
+ * @param smartFilter - The smart filter this block belongs to
139
+ * @param name - The friendly name of the block
140
+ */
141
+ constructor(smartFilter: SmartFilter, name: string) {
142
+ super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
143
+ }
144
+
145
+ /**
146
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
147
+ * @returns The class instance that binds the data to the effect
148
+ */
149
+ public getShaderBinding(): DisableableShaderBinding {
150
+ const input = this._confirmRuntimeDataSupplied(this.input);
151
+ const intensity = this._confirmRuntimeDataSupplied(this.intensity);
152
+
153
+ return new PosterizeBlockShaderBinding(this,input,intensity);
154
+ }
155
+ }
156
+
@@ -0,0 +1,26 @@
1
+ uniform sampler2D input; // main
2
+ uniform float time;
3
+ uniform float rows;
4
+ uniform float cols;
5
+ uniform float frames;
6
+ uniform bool disabled;
7
+
8
+ vec4 mainImage(vec2 vUV) { // main
9
+ if (!disabled) {
10
+ float invRows = 1.0 / rows;
11
+ float invCols = 1.0 / cols;
12
+
13
+ // Get offset of frame
14
+ float frame = mod(floor(time), frames);
15
+ float row = (rows - 1.0) - floor(frame * invCols); // Reverse row direction b/c UVs start from bottom
16
+ float col = mod(frame, cols);
17
+
18
+ // Add offset, then scale UV down to frame size
19
+ vUV = vec2(
20
+ (vUV.x + col) * invCols,
21
+ (vUV.y + row) * invRows
22
+ );
23
+ }
24
+
25
+ return texture2D(input, vUV);
26
+ }
@@ -0,0 +1,60 @@
1
+ import type { ShaderProgram } from "@babylonjs/smart-filters";
2
+
3
+ /**
4
+ * The shader program for the block.
5
+ */
6
+ export const shaderProgram: ShaderProgram = {
7
+ vertex: undefined,
8
+ fragment: {
9
+ uniform: `
10
+ uniform sampler2D _input_; // main
11
+ uniform float _time_;
12
+ uniform float _rows_;
13
+ uniform float _cols_;
14
+ uniform float _frames_;
15
+ uniform bool _disabled_;`,
16
+ mainInputTexture: "_input_",
17
+ mainFunctionName: "_mainImage_",
18
+ functions: [
19
+ {
20
+ name: "_mainImage_",
21
+ code: `
22
+ vec4 _mainImage_(vec2 vUV) {
23
+ if (!_disabled_) {
24
+ float invRows = 1.0 / _rows_;
25
+ float invCols = 1.0 / _cols_;
26
+
27
+ // Get offset of frame
28
+ float frame = mod(floor(_time_), _frames_);
29
+ float row = (_rows_ - 1.0) - floor(frame * invCols); // Reverse row direction b/c UVs start from bottom
30
+ float col = mod(frame, _cols_);
31
+
32
+ // Add offset, then scale UV down to frame size
33
+ vUV = vec2(
34
+ (vUV.x + col) * invCols,
35
+ (vUV.y + row) * invRows
36
+ );
37
+ }
38
+
39
+ return texture2D(_input_, vUV);
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
+ export const uniforms = {
54
+ input: "input",
55
+ time: "time",
56
+ rows: "rows",
57
+ cols: "cols",
58
+ frames: "frames",
59
+ disabled: "disabled",
60
+ };