@babylonjs/smart-filters-blocks 1.0.13 → 8.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.d.ts.map +1 -1
  2. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js +5 -5
  3. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js.map +1 -1
  4. package/dist/blocks/babylon/demo/effects/blurBlock.d.ts.map +1 -1
  5. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts +1 -1
  6. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts.map +1 -1
  7. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js +3 -5
  8. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js.map +1 -1
  9. package/dist/blocks/babylon/demo/effects/blurBlock.js +8 -13
  10. package/dist/blocks/babylon/demo/effects/blurBlock.js.map +1 -1
  11. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts +1 -1
  12. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts.map +1 -1
  13. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.js +1 -1
  14. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts +7 -7
  15. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts.map +1 -1
  16. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts +1 -1
  17. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts.map +1 -1
  18. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js +2 -3
  19. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js.map +1 -1
  20. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts +4 -2
  21. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts.map +1 -1
  22. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js +5 -2
  23. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js.map +1 -1
  24. package/dist/blocks/babylon/demo/effects/compositionBlock.js +2 -6
  25. package/dist/blocks/babylon/demo/effects/compositionBlock.js.map +1 -1
  26. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts +1 -1
  27. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts.map +1 -1
  28. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.js +1 -1
  29. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts +1 -1
  30. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts.map +1 -1
  31. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js +6 -6
  32. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js.map +1 -1
  33. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts +1 -1
  34. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts.map +1 -1
  35. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js +6 -6
  36. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js.map +1 -1
  37. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts +3 -1
  38. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts.map +1 -1
  39. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts +1 -1
  40. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts.map +1 -1
  41. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js +4 -5
  42. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js.map +1 -1
  43. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js +32 -37
  44. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js.map +1 -1
  45. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts +1 -1
  46. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts.map +1 -1
  47. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.js +1 -1
  48. package/dist/blocks/babylon/demo/effects/exposureBlock.block.d.ts.map +1 -1
  49. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js +7 -7
  50. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js.map +1 -1
  51. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.d.ts.map +1 -1
  52. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js +11 -11
  53. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js.map +1 -1
  54. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts +6 -1
  55. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts.map +1 -1
  56. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js +71 -71
  57. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js.map +1 -1
  58. package/dist/blocks/babylon/demo/effects/maskBlock.block.d.ts.map +1 -1
  59. package/dist/blocks/babylon/demo/effects/maskBlock.block.js +7 -7
  60. package/dist/blocks/babylon/demo/effects/maskBlock.block.js.map +1 -1
  61. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts +2 -2
  62. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts.map +1 -1
  63. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js +8 -8
  64. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js.map +1 -1
  65. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts +1 -1
  66. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts.map +1 -1
  67. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js +6 -6
  68. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js.map +1 -1
  69. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts +5 -5
  70. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts.map +1 -1
  71. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts +4 -2
  72. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts.map +1 -1
  73. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js +5 -2
  74. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js.map +1 -1
  75. package/dist/blocks/babylon/demo/effects/spritesheetBlock.js.map +1 -1
  76. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts +1 -1
  77. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts.map +1 -1
  78. package/dist/blocks/babylon/demo/effects/tintBlock.js +10 -10
  79. package/dist/blocks/babylon/demo/effects/tintBlock.js.map +1 -1
  80. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.d.ts.map +1 -1
  81. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js +9 -9
  82. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js.map +1 -1
  83. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.d.ts.map +1 -1
  84. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js +5 -5
  85. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js.map +1 -1
  86. package/dist/blocks/blockNamespaces.d.ts.map +1 -1
  87. package/dist/blocks/blockNamespaces.js +2 -0
  88. package/dist/blocks/blockNamespaces.js.map +1 -1
  89. package/dist/blocks/blockTypes.d.ts.map +1 -1
  90. package/dist/blocks/blockTypes.js +2 -0
  91. package/dist/blocks/blockTypes.js.map +1 -1
  92. package/dist/blocks/index.d.ts.map +1 -1
  93. package/dist/blocks/index.js +1 -0
  94. package/dist/blocks/index.js.map +1 -1
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +1 -0
  97. package/dist/index.js.map +1 -1
  98. package/dist/registration/IBlockRegistration.d.ts +1 -1
  99. package/dist/registration/IBlockRegistration.d.ts.map +1 -1
  100. package/dist/registration/blockSerializers.d.ts.map +1 -1
  101. package/dist/registration/blockSerializers.js +6 -8
  102. package/dist/registration/blockSerializers.js.map +1 -1
  103. package/dist/registration/builtInBlockRegistrations.d.ts +1 -1
  104. package/dist/registration/builtInBlockRegistrations.d.ts.map +1 -1
  105. package/dist/registration/builtInBlockRegistrations.js +50 -52
  106. package/dist/registration/builtInBlockRegistrations.js.map +1 -1
  107. package/dist/registration/index.d.ts +1 -0
  108. package/dist/registration/index.d.ts.map +1 -1
  109. package/dist/registration/index.js +2 -0
  110. package/dist/registration/index.js.map +1 -1
  111. package/license.md +21 -21
  112. package/package.json +15 -13
  113. package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.ts +8 -7
  114. package/src/blocks/babylon/demo/effects/blurBlock.deserializer.ts +37 -37
  115. package/src/blocks/babylon/demo/effects/blurBlock.serializer.ts +31 -31
  116. package/src/blocks/babylon/demo/effects/blurBlock.ts +115 -122
  117. package/src/blocks/babylon/demo/effects/compositionBlock.deserializer.ts +31 -31
  118. package/src/blocks/babylon/demo/effects/compositionBlock.fragment.ts +7 -3
  119. package/src/blocks/babylon/demo/effects/compositionBlock.serializer.ts +28 -28
  120. package/src/blocks/babylon/demo/effects/compositionBlock.ts +211 -243
  121. package/src/blocks/babylon/demo/effects/contrastBlock.block.ts +9 -8
  122. package/src/blocks/babylon/demo/effects/desaturateBlock.block.ts +9 -8
  123. package/src/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.ts +43 -46
  124. package/src/blocks/babylon/demo/effects/directionalBlurBlock.serializer.ts +30 -30
  125. package/src/blocks/babylon/demo/effects/directionalBlurBlock.ts +192 -196
  126. package/src/blocks/babylon/demo/effects/exposureBlock.block.ts +10 -9
  127. package/src/blocks/babylon/demo/effects/greenScreenBlock.block.ts +14 -13
  128. package/src/blocks/babylon/demo/effects/index.ts +14 -14
  129. package/src/blocks/babylon/demo/effects/kaleidoscopeBlock.ts +188 -192
  130. package/src/blocks/babylon/demo/effects/maskBlock.block.ts +10 -9
  131. package/src/blocks/babylon/demo/effects/pixelateBlock.block.ts +11 -10
  132. package/src/blocks/babylon/demo/effects/posterizeBlock.block.ts +9 -8
  133. package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.ts +7 -3
  134. package/src/blocks/babylon/demo/effects/spritesheetBlock.ts +135 -138
  135. package/src/blocks/babylon/demo/effects/tintBlock.ts +51 -51
  136. package/src/blocks/babylon/demo/transitions/index.ts +1 -1
  137. package/src/blocks/babylon/demo/transitions/wipeBlock.block.ts +12 -11
  138. package/src/blocks/babylon/demo/utilities/index.ts +1 -1
  139. package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.ts +8 -7
  140. package/src/blocks/blockNamespaces.ts +6 -4
  141. package/src/blocks/blockTypes.ts +23 -21
  142. package/src/blocks/index.ts +6 -5
  143. package/src/index.ts +3 -2
  144. package/src/registration/IBlockRegistration.ts +43 -48
  145. package/src/registration/blockSerializers.ts +50 -52
  146. package/src/registration/builtInBlockRegistrations.ts +293 -403
  147. package/src/registration/index.ts +4 -2
@@ -1,46 +1,43 @@
1
- import type { ISerializedBlockV1, SmartFilter } from "@babylonjs/smart-filters";
2
- import { DirectionalBlurBlock } from "./directionalBlurBlock.js";
3
-
4
- /**
5
- * The definition of the extra data serialized for directional blur blocks.
6
- */
7
- export interface ISerializedDirectionalBlurBlockV1 extends ISerializedBlockV1 {
8
- /**
9
- * The extra data of the block.
10
- */
11
- data: {
12
- /**
13
- * The horizontal width of the blur.
14
- */
15
- blurHorizontalWidth: number;
16
-
17
- /**
18
- * The vertical width of the blur.
19
- */
20
- blurVerticalWidth: number;
21
-
22
- /**
23
- * The blur texture ratio.
24
- */
25
- blurTextureRatio: number;
26
- };
27
- }
28
-
29
- /**
30
- * V1 Directional Blur Deserializer.
31
- * @param smartFilter - The SmartFilter to deserialize the block into
32
- * @param serializedBlock - The serialized block data
33
- * @returns A deserialized DirectionalBlurBlock
34
- */
35
- export function directionalBlurDeserializer(
36
- smartFilter: SmartFilter,
37
- serializedBlock: ISerializedDirectionalBlurBlockV1
38
- ) {
39
- const block = new DirectionalBlurBlock(smartFilter, serializedBlock.name);
40
-
41
- // If data is missing, use the default value set by the block
42
- block.blurHorizontalWidth = serializedBlock.data.blurHorizontalWidth ?? block.blurHorizontalWidth;
43
- block.blurVerticalWidth = serializedBlock.data.blurVerticalWidth ?? block.blurVerticalWidth;
44
- block.blurTextureRatio = serializedBlock.data.blurTextureRatio ?? block.blurTextureRatio;
45
- return block;
46
- }
1
+ import type { ISerializedBlockV1, SmartFilter } from "smart-filters";
2
+ import { DirectionalBlurBlock } from "./directionalBlurBlock.js";
3
+
4
+ /**
5
+ * The definition of the extra data serialized for directional blur blocks.
6
+ */
7
+ export interface ISerializedDirectionalBlurBlockV1 extends ISerializedBlockV1 {
8
+ /**
9
+ * The extra data of the block.
10
+ */
11
+ data: {
12
+ /**
13
+ * The horizontal width of the blur.
14
+ */
15
+ blurHorizontalWidth: number;
16
+
17
+ /**
18
+ * The vertical width of the blur.
19
+ */
20
+ blurVerticalWidth: number;
21
+
22
+ /**
23
+ * The blur texture ratio.
24
+ */
25
+ blurTextureRatio: number;
26
+ };
27
+ }
28
+
29
+ /**
30
+ * V1 Directional Blur Deserializer.
31
+ * @param smartFilter - The SmartFilter to deserialize the block into
32
+ * @param serializedBlock - The serialized block data
33
+ * @returns A deserialized DirectionalBlurBlock
34
+ */
35
+ export function DirectionalBlurDeserializer(smartFilter: SmartFilter, serializedBlock: ISerializedDirectionalBlurBlockV1) {
36
+ const block = new DirectionalBlurBlock(smartFilter, serializedBlock.name);
37
+
38
+ // If data is missing, use the default value set by the block
39
+ block.blurHorizontalWidth = serializedBlock.data.blurHorizontalWidth ?? block.blurHorizontalWidth;
40
+ block.blurVerticalWidth = serializedBlock.data.blurVerticalWidth ?? block.blurVerticalWidth;
41
+ block.blurTextureRatio = serializedBlock.data.blurTextureRatio ?? block.blurTextureRatio;
42
+ return block;
43
+ }
@@ -1,30 +1,30 @@
1
- import type { IBlockSerializerV1, BaseBlock } from "@babylonjs/smart-filters";
2
- import type { DirectionalBlurBlock } from "./directionalBlurBlock";
3
- import { directionalBlurBlockType } from "../../../blockTypes.js";
4
- import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
5
-
6
- /**
7
- * The V1 serializer for a Directional Blur Block
8
- */
9
- export const directionalBlurBlockSerializer: IBlockSerializerV1 = {
10
- blockType: directionalBlurBlockType,
11
- serialize: (block: BaseBlock) => {
12
- if (block.getClassName() !== directionalBlurBlockType) {
13
- throw new Error("Was asked to serialize an unrecognized block type");
14
- }
15
-
16
- const directionalBlurBlock = block as DirectionalBlurBlock;
17
- return {
18
- name: block.name,
19
- uniqueId: block.uniqueId,
20
- blockType: directionalBlurBlockType,
21
- namespace: babylonDemoEffectsNamespace,
22
- comments: block.comments,
23
- data: {
24
- blurTextureRatio: directionalBlurBlock.blurTextureRatio,
25
- blurHorizontalWidth: directionalBlurBlock.blurHorizontalWidth,
26
- blurVerticalWidth: directionalBlurBlock.blurVerticalWidth,
27
- },
28
- };
29
- },
30
- };
1
+ import type { IBlockSerializerV1, BaseBlock } from "smart-filters";
2
+ import type { DirectionalBlurBlock } from "./directionalBlurBlock.js";
3
+ import { directionalBlurBlockType } from "../../../blockTypes.js";
4
+ import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
5
+
6
+ /**
7
+ * The V1 serializer for a Directional Blur Block
8
+ */
9
+ export const DirectionalBlurBlockSerializer: IBlockSerializerV1 = {
10
+ blockType: directionalBlurBlockType,
11
+ serialize: (block: BaseBlock) => {
12
+ if (block.getClassName() !== directionalBlurBlockType) {
13
+ throw new Error("Was asked to serialize an unrecognized block type");
14
+ }
15
+
16
+ const directionalBlurBlock = block as DirectionalBlurBlock;
17
+ return {
18
+ name: block.name,
19
+ uniqueId: block.uniqueId,
20
+ blockType: directionalBlurBlockType,
21
+ namespace: babylonDemoEffectsNamespace,
22
+ comments: block.comments,
23
+ data: {
24
+ blurTextureRatio: directionalBlurBlock.blurTextureRatio,
25
+ blurHorizontalWidth: directionalBlurBlock.blurHorizontalWidth,
26
+ blurVerticalWidth: directionalBlurBlock.blurVerticalWidth,
27
+ },
28
+ };
29
+ },
30
+ };
@@ -1,196 +1,192 @@
1
- import type { Effect } from "@babylonjs/core/Materials/effect";
2
-
3
- import {
4
- type ShaderProgram,
5
- type RuntimeData,
6
- ConnectionPointType,
7
- type SmartFilter,
8
- editableInPropertyPage,
9
- PropertyTypeForEdition,
10
- ShaderBinding,
11
- ShaderBlock,
12
- } from "@babylonjs/smart-filters";
13
-
14
- import { directionalBlurBlockType } from "../../../blockTypes.js";
15
- import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
16
-
17
- const shaderProgram: ShaderProgram = {
18
- fragment: {
19
- const: `
20
- const float _epsilon_ = 0.01;
21
- `,
22
- uniform: `
23
- uniform vec2 _texelStep_;
24
- uniform sampler2D _input_;
25
- `,
26
-
27
- uniformSingle: `
28
- uniform float[7] _weights_;
29
- `,
30
-
31
- mainFunctionName: "_directionalBlur_",
32
-
33
- mainInputTexture: "_input_",
34
-
35
- functions: [
36
- {
37
- name: "_directionalBlur_",
38
- code: `
39
- vec4 _directionalBlur_(vec2 vUV) {
40
- vec2 start = vUV - 3.0 * _texelStep_;
41
-
42
- vec4 finalWeightedColor = vec4(0., 0., 0., 0.);
43
-
44
- for (int i = 0; i < 7; i++)
45
- {
46
- vec2 fetchUV = start + _texelStep_ * float(i);
47
- fetchUV = clamp(fetchUV, 0., 1.);
48
- vec4 colorSample = texture2D(_input_, fetchUV);
49
-
50
- // Ignore samples from mostly transparent pixels
51
- if (colorSample.a < _epsilon_) continue;
52
-
53
- finalWeightedColor += colorSample * _weights_[i];
54
- }
55
-
56
- return finalWeightedColor;
57
- }
58
- `,
59
- },
60
- ],
61
- },
62
- };
63
-
64
- const wideWeights = Float32Array.from([0.05, 0.1, 0.2, 0.3, 0.2, 0.1, 0.05]);
65
-
66
- /**
67
- * The shader bindings for the DirectionalBlur block.
68
- */
69
- export class DirectionalBlurShaderBinding extends ShaderBinding {
70
- private readonly _inputTexture: RuntimeData<ConnectionPointType.Texture>;
71
- private readonly _blurHorizontalWidth: number;
72
- private readonly _blurVerticalWidth: number;
73
-
74
- /**
75
- * Creates a new shader binding instance for the DirectionalBlur block.
76
- * @param inputTexture - The input texture
77
- * @param blurHorizontalWidth - The horizontal blur width
78
- * @param blurVerticalWidth - The vertical blur width
79
- */
80
- constructor(
81
- inputTexture: RuntimeData<ConnectionPointType.Texture>,
82
- blurHorizontalWidth: number,
83
- blurVerticalWidth: number
84
- ) {
85
- super();
86
- this._inputTexture = inputTexture;
87
- this._blurHorizontalWidth = blurHorizontalWidth;
88
- this._blurVerticalWidth = blurVerticalWidth;
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
- // Global pass Setup
97
- effect.setFloatArray(this.getRemappedName("weights"), wideWeights);
98
-
99
- // V blur
100
- effect.setTexture(this.getRemappedName("input"), this._inputTexture.value);
101
-
102
- // Texel size
103
- if (this._inputTexture.value) {
104
- const inputSize = this._inputTexture.value.getSize();
105
- const texelWidth = this._blurHorizontalWidth / inputSize.width;
106
- const texelHeight = this._blurVerticalWidth / inputSize.height;
107
- effect.setFloat2(this.getRemappedName("texelStep"), texelWidth, texelHeight);
108
- }
109
- }
110
- }
111
-
112
- /**
113
- * A block performing a directional "gaussian" blur.
114
- *
115
- * It is aggregated as part of the @see BlurBlock.
116
- */
117
- export class DirectionalBlurBlock extends ShaderBlock {
118
- /**
119
- * The class name of the block.
120
- */
121
- public static override ClassName = directionalBlurBlockType;
122
-
123
- /**
124
- * The namespace of the block.
125
- */
126
- public static override Namespace = babylonDemoEffectsNamespace;
127
-
128
- /**
129
- * The input texture connection point.
130
- */
131
- public readonly input = this._registerInput("input", ConnectionPointType.Texture);
132
-
133
- /**
134
- * Defines how smaller we should make the target compared to the screen size.
135
- */
136
- @editableInPropertyPage("Texture Ratio", PropertyTypeForEdition.Float, "PROPERTIES", {
137
- min: 0,
138
- max: 1,
139
- notifiers: { rebuild: true },
140
- })
141
- public blurTextureRatio = 0.5;
142
-
143
- /**
144
- * Defines the horizontal strength of the blur.
145
- */
146
- @editableInPropertyPage("Horizontal strength", PropertyTypeForEdition.Float, "PROPERTIES", {
147
- min: 0,
148
- max: 1,
149
- notifiers: { rebuild: true },
150
- })
151
- public blurHorizontalWidth = 0;
152
-
153
- /**
154
- * Defines the vertical strength of the blur.
155
- */
156
- @editableInPropertyPage("Vertical strength", PropertyTypeForEdition.Float, "PROPERTIES", {
157
- min: 0,
158
- max: 1,
159
- notifiers: { rebuild: true },
160
- })
161
- public blurVerticalWidth = 1;
162
-
163
- /**
164
- * The shader program (vertex and fragment code) to use to render the block
165
- */
166
- public static override ShaderCode = shaderProgram;
167
-
168
- /**
169
- * Instantiates a new Block.
170
- * @param smartFilter - The smart filter this block belongs to
171
- * @param name - The friendly name of the block
172
- */
173
- constructor(smartFilter: SmartFilter, name: string) {
174
- super(smartFilter, name, true);
175
- }
176
-
177
- /**
178
- * Prepares the block for runtime.
179
- * This is called by the smart filter just before creating the smart filter runtime.
180
- */
181
- public override prepareForRuntime(): void {
182
- super.prepareForRuntime();
183
-
184
- this.outputTextureOptions.ratio = this.blurTextureRatio;
185
- }
186
-
187
- /**
188
- * Get the class instance that binds all the required data to the shader (effect) when rendering.
189
- * @returns The class instance that binds the data to the effect
190
- */
191
- public getShaderBinding(): ShaderBinding {
192
- const input = this._confirmRuntimeDataSupplied(this.input);
193
-
194
- return new DirectionalBlurShaderBinding(input, this.blurHorizontalWidth, this.blurVerticalWidth);
195
- }
196
- }
1
+ import type { Effect } from "core/Materials/effect.js";
2
+
3
+ import {
4
+ type ShaderProgram,
5
+ type RuntimeData,
6
+ ConnectionPointType,
7
+ type SmartFilter,
8
+ editableInPropertyPage,
9
+ PropertyTypeForEdition,
10
+ ShaderBinding,
11
+ ShaderBlock,
12
+ } from "smart-filters";
13
+
14
+ import { directionalBlurBlockType } from "../../../blockTypes.js";
15
+ import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
16
+
17
+ const ShaderProgram: ShaderProgram = {
18
+ fragment: {
19
+ const: `
20
+ const float _epsilon_ = 0.01;
21
+ `,
22
+ uniform: `
23
+ uniform vec2 _texelStep_;
24
+ uniform sampler2D _input_;
25
+ `,
26
+
27
+ uniformSingle: `
28
+ uniform float[7] _weights_;
29
+ `,
30
+
31
+ mainFunctionName: "_directionalBlur_",
32
+
33
+ mainInputTexture: "_input_",
34
+
35
+ functions: [
36
+ {
37
+ name: "_directionalBlur_",
38
+ code: `
39
+ vec4 _directionalBlur_(vec2 vUV) {
40
+ vec2 start = vUV - 3.0 * _texelStep_;
41
+
42
+ vec4 finalWeightedColor = vec4(0., 0., 0., 0.);
43
+
44
+ for (int i = 0; i < 7; i++)
45
+ {
46
+ vec2 fetchUV = start + _texelStep_ * float(i);
47
+ fetchUV = clamp(fetchUV, 0., 1.);
48
+ vec4 colorSample = texture2D(_input_, fetchUV);
49
+
50
+ // Ignore samples from mostly transparent pixels
51
+ if (colorSample.a < _epsilon_) continue;
52
+
53
+ finalWeightedColor += colorSample * _weights_[i];
54
+ }
55
+
56
+ return finalWeightedColor;
57
+ }
58
+ `,
59
+ },
60
+ ],
61
+ },
62
+ };
63
+
64
+ const WideWeights = Float32Array.from([0.05, 0.1, 0.2, 0.3, 0.2, 0.1, 0.05]);
65
+
66
+ /**
67
+ * The shader bindings for the DirectionalBlur block.
68
+ */
69
+ export class DirectionalBlurShaderBinding extends ShaderBinding {
70
+ private readonly _inputTexture: RuntimeData<ConnectionPointType.Texture>;
71
+ private readonly _blurHorizontalWidth: number;
72
+ private readonly _blurVerticalWidth: number;
73
+
74
+ /**
75
+ * Creates a new shader binding instance for the DirectionalBlur block.
76
+ * @param inputTexture - The input texture
77
+ * @param blurHorizontalWidth - The horizontal blur width
78
+ * @param blurVerticalWidth - The vertical blur width
79
+ */
80
+ constructor(inputTexture: RuntimeData<ConnectionPointType.Texture>, blurHorizontalWidth: number, blurVerticalWidth: number) {
81
+ super();
82
+ this._inputTexture = inputTexture;
83
+ this._blurHorizontalWidth = blurHorizontalWidth;
84
+ this._blurVerticalWidth = blurVerticalWidth;
85
+ }
86
+
87
+ /**
88
+ * Binds all the required data to the shader when rendering.
89
+ * @param effect - defines the effect to bind the data to
90
+ */
91
+ public override bind(effect: Effect): void {
92
+ // Global pass Setup
93
+ effect.setFloatArray(this.getRemappedName("weights"), WideWeights);
94
+
95
+ // V blur
96
+ effect.setTexture(this.getRemappedName("input"), this._inputTexture.value);
97
+
98
+ // Texel size
99
+ if (this._inputTexture.value) {
100
+ const inputSize = this._inputTexture.value.getSize();
101
+ const texelWidth = this._blurHorizontalWidth / inputSize.width;
102
+ const texelHeight = this._blurVerticalWidth / inputSize.height;
103
+ effect.setFloat2(this.getRemappedName("texelStep"), texelWidth, texelHeight);
104
+ }
105
+ }
106
+ }
107
+
108
+ /**
109
+ * A block performing a directional "gaussian" blur.
110
+ *
111
+ * It is aggregated as part of the @see BlurBlock.
112
+ */
113
+ export class DirectionalBlurBlock extends ShaderBlock {
114
+ /**
115
+ * The class name of the block.
116
+ */
117
+ public static override ClassName = directionalBlurBlockType;
118
+
119
+ /**
120
+ * The namespace of the block.
121
+ */
122
+ public static override Namespace = babylonDemoEffectsNamespace;
123
+
124
+ /**
125
+ * The input texture connection point.
126
+ */
127
+ public readonly input = this._registerInput("input", ConnectionPointType.Texture);
128
+
129
+ /**
130
+ * Defines how smaller we should make the target compared to the screen size.
131
+ */
132
+ @editableInPropertyPage("Texture Ratio", PropertyTypeForEdition.Float, "PROPERTIES", {
133
+ min: 0,
134
+ max: 1,
135
+ notifiers: { rebuild: true },
136
+ })
137
+ public blurTextureRatio = 0.5;
138
+
139
+ /**
140
+ * Defines the horizontal strength of the blur.
141
+ */
142
+ @editableInPropertyPage("Horizontal strength", PropertyTypeForEdition.Float, "PROPERTIES", {
143
+ min: 0,
144
+ max: 1,
145
+ notifiers: { rebuild: true },
146
+ })
147
+ public blurHorizontalWidth = 0;
148
+
149
+ /**
150
+ * Defines the vertical strength of the blur.
151
+ */
152
+ @editableInPropertyPage("Vertical strength", PropertyTypeForEdition.Float, "PROPERTIES", {
153
+ min: 0,
154
+ max: 1,
155
+ notifiers: { rebuild: true },
156
+ })
157
+ public blurVerticalWidth = 1;
158
+
159
+ /**
160
+ * The shader program (vertex and fragment code) to use to render the block
161
+ */
162
+ public static override ShaderCode = ShaderProgram;
163
+
164
+ /**
165
+ * Instantiates a new Block.
166
+ * @param smartFilter - The smart filter this block belongs to
167
+ * @param name - The friendly name of the block
168
+ */
169
+ constructor(smartFilter: SmartFilter, name: string) {
170
+ super(smartFilter, name, true);
171
+ }
172
+
173
+ /**
174
+ * Prepares the block for runtime.
175
+ * This is called by the smart filter just before creating the smart filter runtime.
176
+ */
177
+ public override prepareForRuntime(): void {
178
+ super.prepareForRuntime();
179
+
180
+ this.outputTextureOptions.ratio = this.blurTextureRatio;
181
+ }
182
+
183
+ /**
184
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
185
+ * @returns The class instance that binds the data to the effect
186
+ */
187
+ public getShaderBinding(): ShaderBinding {
188
+ const input = this._confirmRuntimeDataSupplied(this.input);
189
+
190
+ return new DirectionalBlurShaderBinding(input, this.blurHorizontalWidth, this.blurVerticalWidth);
191
+ }
192
+ }
@@ -8,7 +8,7 @@
8
8
  // to the block. This file will get overwritten when the build
9
9
  // is run or during a watch when the .glsl file is updated.
10
10
 
11
- import type { Effect } from "@babylonjs/core/Materials/effect";
11
+ import type { Effect } from "core/Materials/effect.js";
12
12
 
13
13
  import {
14
14
  DisableableShaderBinding,
@@ -18,12 +18,12 @@ import {
18
18
  DisableableShaderBlock,
19
19
  type ShaderProgram,
20
20
  type IDisableableBlock,
21
- BlockDisableStrategy} from "@babylonjs/smart-filters";
21
+ BlockDisableStrategy} from "smart-filters";
22
22
 
23
23
  /**
24
24
  * The shader program for the block.
25
25
  */
26
- const shaderProgram: ShaderProgram = {
26
+ const BlockShaderProgram: ShaderProgram = {
27
27
  vertex: undefined,
28
28
  fragment: {
29
29
  uniform: `
@@ -50,11 +50,12 @@ const shaderProgram: ShaderProgram = {
50
50
  * The uniform names for this shader, to be used in the shader binding so
51
51
  * that the names are always in sync.
52
52
  */
53
- const uniforms = {
53
+ const Uniforms = {
54
54
  input: "input",
55
55
  amount: "amount",
56
56
  };
57
57
 
58
+
58
59
  /**
59
60
  * The shader binding for the ExposureBlock, used by the runtime
60
61
  */
@@ -84,8 +85,8 @@ class ExposureBlockShaderBinding extends DisableableShaderBinding {
84
85
  */
85
86
  public override bind(effect: Effect): void {
86
87
  super.bind(effect);
87
- effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
88
- effect.setFloat(this.getRemappedName(uniforms.amount), this._amount.value);
88
+ effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
89
+ effect.setFloat(this.getRemappedName(Uniforms.amount), this._amount.value);
89
90
  }
90
91
  }
91
92
 
@@ -106,17 +107,17 @@ export class ExposureBlock extends DisableableShaderBlock {
106
107
  /**
107
108
  * The input connection point.
108
109
  */
109
- public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
110
+ public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
110
111
 
111
112
  /**
112
113
  * The amount connection point.
113
114
  */
114
- public readonly amount = this._registerInput(uniforms.amount, ConnectionPointType.Float);
115
+ public readonly amount = this._registerInput(Uniforms.amount, ConnectionPointType.Float);
115
116
 
116
117
  /**
117
118
  * The shader program (vertex and fragment code) to use to render the block
118
119
  */
119
- public static override ShaderCode = shaderProgram;
120
+ public static override ShaderCode = BlockShaderProgram;
120
121
 
121
122
  /**
122
123
  * Instantiates a new ExposureBlock.