@babylonjs/smart-filters-blocks 1.0.13 → 8.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js +5 -5
- package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/blurBlock.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js +3 -5
- package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/blurBlock.js +8 -13
- package/dist/blocks/babylon/demo/effects/blurBlock.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/blurBlock.serializer.js +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts +7 -7
- package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js +2 -3
- package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts +4 -2
- package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js +5 -2
- package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.js +2 -6
- package/dist/blocks/babylon/demo/effects/compositionBlock.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.js +1 -1
- package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/contrastBlock.block.js +6 -6
- package/dist/blocks/babylon/demo/effects/contrastBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js +6 -6
- package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts +3 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js +4 -5
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js +32 -37
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.js +1 -1
- package/dist/blocks/babylon/demo/effects/exposureBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/exposureBlock.block.js +7 -7
- package/dist/blocks/babylon/demo/effects/exposureBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js +11 -11
- package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts +6 -1
- package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js +71 -71
- package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/maskBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/maskBlock.block.js +7 -7
- package/dist/blocks/babylon/demo/effects/maskBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts +2 -2
- package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js +8 -8
- package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js +6 -6
- package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts +5 -5
- package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts +4 -2
- package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js +5 -2
- package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/spritesheetBlock.js.map +1 -1
- package/dist/blocks/babylon/demo/effects/tintBlock.d.ts +1 -1
- package/dist/blocks/babylon/demo/effects/tintBlock.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/effects/tintBlock.js +10 -10
- package/dist/blocks/babylon/demo/effects/tintBlock.js.map +1 -1
- package/dist/blocks/babylon/demo/transitions/wipeBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js +9 -9
- package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js.map +1 -1
- package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.d.ts.map +1 -1
- package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js +5 -5
- package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js.map +1 -1
- package/dist/blocks/blockNamespaces.d.ts.map +1 -1
- package/dist/blocks/blockNamespaces.js +2 -0
- package/dist/blocks/blockNamespaces.js.map +1 -1
- package/dist/blocks/blockTypes.d.ts.map +1 -1
- package/dist/blocks/blockTypes.js +2 -0
- package/dist/blocks/blockTypes.js.map +1 -1
- package/dist/blocks/index.d.ts.map +1 -1
- package/dist/blocks/index.js +1 -0
- package/dist/blocks/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/registration/IBlockRegistration.d.ts +1 -1
- package/dist/registration/IBlockRegistration.d.ts.map +1 -1
- package/dist/registration/blockSerializers.d.ts.map +1 -1
- package/dist/registration/blockSerializers.js +6 -8
- package/dist/registration/blockSerializers.js.map +1 -1
- package/dist/registration/builtInBlockRegistrations.d.ts +1 -1
- package/dist/registration/builtInBlockRegistrations.d.ts.map +1 -1
- package/dist/registration/builtInBlockRegistrations.js +50 -52
- package/dist/registration/builtInBlockRegistrations.js.map +1 -1
- package/dist/registration/index.d.ts +1 -0
- package/dist/registration/index.d.ts.map +1 -1
- package/dist/registration/index.js +2 -0
- package/dist/registration/index.js.map +1 -1
- package/license.md +21 -21
- package/package.json +15 -13
- package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.ts +8 -7
- package/src/blocks/babylon/demo/effects/blurBlock.deserializer.ts +37 -37
- package/src/blocks/babylon/demo/effects/blurBlock.serializer.ts +31 -31
- package/src/blocks/babylon/demo/effects/blurBlock.ts +115 -122
- package/src/blocks/babylon/demo/effects/compositionBlock.deserializer.ts +31 -31
- package/src/blocks/babylon/demo/effects/compositionBlock.fragment.ts +7 -3
- package/src/blocks/babylon/demo/effects/compositionBlock.serializer.ts +28 -28
- package/src/blocks/babylon/demo/effects/compositionBlock.ts +211 -243
- package/src/blocks/babylon/demo/effects/contrastBlock.block.ts +9 -8
- package/src/blocks/babylon/demo/effects/desaturateBlock.block.ts +9 -8
- package/src/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.ts +43 -46
- package/src/blocks/babylon/demo/effects/directionalBlurBlock.serializer.ts +30 -30
- package/src/blocks/babylon/demo/effects/directionalBlurBlock.ts +192 -196
- package/src/blocks/babylon/demo/effects/exposureBlock.block.ts +10 -9
- package/src/blocks/babylon/demo/effects/greenScreenBlock.block.ts +14 -13
- package/src/blocks/babylon/demo/effects/index.ts +14 -14
- package/src/blocks/babylon/demo/effects/kaleidoscopeBlock.ts +188 -192
- package/src/blocks/babylon/demo/effects/maskBlock.block.ts +10 -9
- package/src/blocks/babylon/demo/effects/pixelateBlock.block.ts +11 -10
- package/src/blocks/babylon/demo/effects/posterizeBlock.block.ts +9 -8
- package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.ts +7 -3
- package/src/blocks/babylon/demo/effects/spritesheetBlock.ts +135 -138
- package/src/blocks/babylon/demo/effects/tintBlock.ts +51 -51
- package/src/blocks/babylon/demo/transitions/index.ts +1 -1
- package/src/blocks/babylon/demo/transitions/wipeBlock.block.ts +12 -11
- package/src/blocks/babylon/demo/utilities/index.ts +1 -1
- package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.ts +8 -7
- package/src/blocks/blockNamespaces.ts +6 -4
- package/src/blocks/blockTypes.ts +23 -21
- package/src/blocks/index.ts +6 -5
- package/src/index.ts +3 -2
- package/src/registration/IBlockRegistration.ts +43 -48
- package/src/registration/blockSerializers.ts +50 -52
- package/src/registration/builtInBlockRegistrations.ts +293 -403
- package/src/registration/index.ts +4 -2
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
import type { ISerializedBlockV1, SmartFilter } from "
|
|
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
|
|
36
|
-
smartFilter
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 "
|
|
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
|
|
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 "
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type ShaderProgram,
|
|
5
|
-
type RuntimeData,
|
|
6
|
-
ConnectionPointType,
|
|
7
|
-
type SmartFilter,
|
|
8
|
-
editableInPropertyPage,
|
|
9
|
-
PropertyTypeForEdition,
|
|
10
|
-
ShaderBinding,
|
|
11
|
-
ShaderBlock,
|
|
12
|
-
} from "
|
|
13
|
-
|
|
14
|
-
import { directionalBlurBlockType } from "../../../blockTypes.js";
|
|
15
|
-
import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
|
|
16
|
-
|
|
17
|
-
const
|
|
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
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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 "
|
|
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 "
|
|
21
|
+
BlockDisableStrategy} from "smart-filters";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* The shader program for the block.
|
|
25
25
|
*/
|
|
26
|
-
const
|
|
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
|
|
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(
|
|
88
|
-
effect.setFloat(this.getRemappedName(
|
|
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(
|
|
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(
|
|
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 =
|
|
120
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
120
121
|
|
|
121
122
|
/**
|
|
122
123
|
* Instantiates a new ExposureBlock.
|