@onerjs/smart-filters-blocks 8.25.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/license.md +21 -0
- package/package.json +54 -0
- package/readme.md +7 -0
- package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.glsl +18 -0
- package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.ts +133 -0
- package/src/blocks/babylon/demo/effects/blurBlock.deserializer.ts +37 -0
- package/src/blocks/babylon/demo/effects/blurBlock.serializer.ts +31 -0
- package/src/blocks/babylon/demo/effects/blurBlock.ts +115 -0
- package/src/blocks/babylon/demo/effects/compositionBlock.deserializer.ts +31 -0
- package/src/blocks/babylon/demo/effects/compositionBlock.fragment.glsl +38 -0
- package/src/blocks/babylon/demo/effects/compositionBlock.fragment.ts +74 -0
- package/src/blocks/babylon/demo/effects/compositionBlock.serializer.ts +28 -0
- package/src/blocks/babylon/demo/effects/compositionBlock.ts +211 -0
- package/src/blocks/babylon/demo/effects/contrastBlock.block.glsl +36 -0
- package/src/blocks/babylon/demo/effects/contrastBlock.block.ts +178 -0
- package/src/blocks/babylon/demo/effects/desaturateBlock.block.glsl +24 -0
- package/src/blocks/babylon/demo/effects/desaturateBlock.block.ts +155 -0
- package/src/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.ts +43 -0
- package/src/blocks/babylon/demo/effects/directionalBlurBlock.serializer.ts +30 -0
- package/src/blocks/babylon/demo/effects/directionalBlurBlock.ts +192 -0
- package/src/blocks/babylon/demo/effects/exposureBlock.block.glsl +15 -0
- package/src/blocks/babylon/demo/effects/exposureBlock.block.ts +142 -0
- package/src/blocks/babylon/demo/effects/greenScreenBlock.block.glsl +23 -0
- package/src/blocks/babylon/demo/effects/greenScreenBlock.block.ts +174 -0
- package/src/blocks/babylon/demo/effects/index.ts +14 -0
- package/src/blocks/babylon/demo/effects/kaleidoscopeBlock.ts +188 -0
- package/src/blocks/babylon/demo/effects/maskBlock.block.glsl +18 -0
- package/src/blocks/babylon/demo/effects/maskBlock.block.ts +145 -0
- package/src/blocks/babylon/demo/effects/pixelateBlock.block.glsl +29 -0
- package/src/blocks/babylon/demo/effects/pixelateBlock.block.ts +174 -0
- package/src/blocks/babylon/demo/effects/posterizeBlock.block.glsl +25 -0
- package/src/blocks/babylon/demo/effects/posterizeBlock.block.ts +156 -0
- package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.glsl +26 -0
- package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.ts +63 -0
- package/src/blocks/babylon/demo/effects/spritesheetBlock.ts +135 -0
- package/src/blocks/babylon/demo/effects/tintBlock.ts +51 -0
- package/src/blocks/babylon/demo/transitions/index.ts +1 -0
- package/src/blocks/babylon/demo/transitions/wipeBlock.block.glsl +11 -0
- package/src/blocks/babylon/demo/transitions/wipeBlock.block.ts +152 -0
- package/src/blocks/babylon/demo/utilities/index.ts +1 -0
- package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.glsl +14 -0
- package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.ts +129 -0
- package/src/blocks/blockNamespaces.ts +6 -0
- package/src/blocks/blockTypes.ts +23 -0
- package/src/blocks/index.ts +6 -0
- package/src/index.ts +3 -0
- package/src/registration/IBlockRegistration.ts +43 -0
- package/src/registration/blockSerializers.ts +50 -0
- package/src/registration/builtInBlockRegistrations.ts +293 -0
- package/src/registration/index.ts +4 -0
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
{
|
|
3
|
+
"smartFilterBlockType": "ExposureBlock",
|
|
4
|
+
"namespace": "Babylon.Demo.Effects",
|
|
5
|
+
"blockDisableStrategy": "AutoSample"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
uniform sampler2D input; // main
|
|
10
|
+
uniform float amount;
|
|
11
|
+
|
|
12
|
+
vec4 exposure(vec2 vUV) { // main
|
|
13
|
+
vec4 color = texture2D(input, vUV);
|
|
14
|
+
return vec4(color.rgb * amount, color.a);
|
|
15
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
|
+
// ************************************************************
|
|
3
|
+
// Note: this file is auto-generated, do not modify it directly
|
|
4
|
+
// ************************************************************
|
|
5
|
+
|
|
6
|
+
// It was generated by convertGlslIntoBlock() from
|
|
7
|
+
// an annotated .glsl file. Modify the .glsl file to make changes
|
|
8
|
+
// to the block. This file will get overwritten when the build
|
|
9
|
+
// is run or during a watch when the .glsl file is updated.
|
|
10
|
+
|
|
11
|
+
import type { Effect } from "core/Materials/effect.js";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
DisableableShaderBinding,
|
|
15
|
+
type RuntimeData,
|
|
16
|
+
ConnectionPointType,
|
|
17
|
+
type SmartFilter,
|
|
18
|
+
DisableableShaderBlock,
|
|
19
|
+
type ShaderProgram,
|
|
20
|
+
type IDisableableBlock,
|
|
21
|
+
BlockDisableStrategy} from "smart-filters";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The shader program for the block.
|
|
25
|
+
*/
|
|
26
|
+
const BlockShaderProgram: ShaderProgram = {
|
|
27
|
+
vertex: undefined,
|
|
28
|
+
fragment: {
|
|
29
|
+
uniform: `
|
|
30
|
+
uniform sampler2D _input_; // main
|
|
31
|
+
uniform float _amount_;`,
|
|
32
|
+
mainInputTexture: "_input_",
|
|
33
|
+
mainFunctionName: "_exposure_",
|
|
34
|
+
functions: [
|
|
35
|
+
{
|
|
36
|
+
name: "_exposure_",
|
|
37
|
+
code: `
|
|
38
|
+
vec4 _exposure_(vec2 vUV) {
|
|
39
|
+
vec4 color = texture2D(_input_, vUV);
|
|
40
|
+
return vec4(color.rgb * _amount_, color.a);
|
|
41
|
+
}
|
|
42
|
+
`,
|
|
43
|
+
params: "vec2 vUV",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The uniform names for this shader, to be used in the shader binding so
|
|
51
|
+
* that the names are always in sync.
|
|
52
|
+
*/
|
|
53
|
+
const Uniforms = {
|
|
54
|
+
input: "input",
|
|
55
|
+
amount: "amount",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The shader binding for the ExposureBlock, used by the runtime
|
|
61
|
+
*/
|
|
62
|
+
class ExposureBlockShaderBinding extends DisableableShaderBinding {
|
|
63
|
+
private readonly _input: RuntimeData<ConnectionPointType.Texture>;
|
|
64
|
+
private readonly _amount: RuntimeData<ConnectionPointType.Float>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new shader binding instance for the block.
|
|
68
|
+
* @param parentBlock - IDisableableBlock
|
|
69
|
+
* @param input - The input runtime value
|
|
70
|
+
* @param amount - The amount runtime value
|
|
71
|
+
*/
|
|
72
|
+
constructor(
|
|
73
|
+
parentBlock: IDisableableBlock,
|
|
74
|
+
input: RuntimeData<ConnectionPointType.Texture>,
|
|
75
|
+
amount: RuntimeData<ConnectionPointType.Float>
|
|
76
|
+
) {
|
|
77
|
+
super(parentBlock);
|
|
78
|
+
this._input = input;
|
|
79
|
+
this._amount = amount;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Binds all the required data to the shader when rendering.
|
|
84
|
+
* @param effect - defines the effect to bind the data to
|
|
85
|
+
*/
|
|
86
|
+
public override bind(effect: Effect): void {
|
|
87
|
+
super.bind(effect);
|
|
88
|
+
effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
|
|
89
|
+
effect.setFloat(this.getRemappedName(Uniforms.amount), this._amount.value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The implementation of the ExposureBlock
|
|
95
|
+
*/
|
|
96
|
+
export class ExposureBlock extends DisableableShaderBlock {
|
|
97
|
+
/**
|
|
98
|
+
* The class name of the block.
|
|
99
|
+
*/
|
|
100
|
+
public static override ClassName = "ExposureBlock";
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The namespace of the block.
|
|
104
|
+
*/
|
|
105
|
+
public static override Namespace = "Babylon.Demo.Effects";
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The input connection point.
|
|
109
|
+
*/
|
|
110
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The amount connection point.
|
|
114
|
+
*/
|
|
115
|
+
public readonly amount = this._registerInput(Uniforms.amount, ConnectionPointType.Float);
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
119
|
+
*/
|
|
120
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Instantiates a new ExposureBlock.
|
|
124
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
125
|
+
* @param name - The friendly name of the block
|
|
126
|
+
*/
|
|
127
|
+
constructor(smartFilter: SmartFilter, name: string) {
|
|
128
|
+
super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
133
|
+
* @returns The class instance that binds the data to the effect
|
|
134
|
+
*/
|
|
135
|
+
public getShaderBinding(): DisableableShaderBinding {
|
|
136
|
+
const input = this._confirmRuntimeDataSupplied(this.input);
|
|
137
|
+
const amount = this._confirmRuntimeDataSupplied(this.amount);
|
|
138
|
+
|
|
139
|
+
return new ExposureBlockShaderBinding(this,input,amount);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
{
|
|
3
|
+
"smartFilterBlockType": "GreenScreenBlock",
|
|
4
|
+
"namespace": "Babylon.Demo.Effects",
|
|
5
|
+
"blockDisableStrategy": "AutoSample"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
uniform sampler2D input; // main
|
|
10
|
+
uniform sampler2D background;
|
|
11
|
+
uniform vec3 reference;
|
|
12
|
+
uniform float distance;
|
|
13
|
+
|
|
14
|
+
vec4 greenScreen(vec2 vUV) { // main
|
|
15
|
+
vec4 color = texture2D(input, vUV);
|
|
16
|
+
vec4 background = texture2D(background, vUV);
|
|
17
|
+
|
|
18
|
+
if (length(color.rgb - reference) < distance) {
|
|
19
|
+
return background;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return color;
|
|
23
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
|
+
// ************************************************************
|
|
3
|
+
// Note: this file is auto-generated, do not modify it directly
|
|
4
|
+
// ************************************************************
|
|
5
|
+
|
|
6
|
+
// It was generated by convertGlslIntoBlock() from
|
|
7
|
+
// an annotated .glsl file. Modify the .glsl file to make changes
|
|
8
|
+
// to the block. This file will get overwritten when the build
|
|
9
|
+
// is run or during a watch when the .glsl file is updated.
|
|
10
|
+
|
|
11
|
+
import type { Effect } from "core/Materials/effect.js";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
DisableableShaderBinding,
|
|
15
|
+
type RuntimeData,
|
|
16
|
+
ConnectionPointType,
|
|
17
|
+
type SmartFilter,
|
|
18
|
+
DisableableShaderBlock,
|
|
19
|
+
type ShaderProgram,
|
|
20
|
+
type IDisableableBlock,
|
|
21
|
+
BlockDisableStrategy} from "smart-filters";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The shader program for the block.
|
|
25
|
+
*/
|
|
26
|
+
const BlockShaderProgram: ShaderProgram = {
|
|
27
|
+
vertex: undefined,
|
|
28
|
+
fragment: {
|
|
29
|
+
uniform: `
|
|
30
|
+
uniform sampler2D _input_; // main
|
|
31
|
+
uniform sampler2D _background_;
|
|
32
|
+
uniform vec3 _reference_;
|
|
33
|
+
uniform float _distance_;`,
|
|
34
|
+
mainInputTexture: "_input_",
|
|
35
|
+
mainFunctionName: "_greenScreen_",
|
|
36
|
+
functions: [
|
|
37
|
+
{
|
|
38
|
+
name: "_greenScreen_",
|
|
39
|
+
code: `
|
|
40
|
+
vec4 _greenScreen_(vec2 vUV) {
|
|
41
|
+
vec4 color = texture2D(_input_, vUV);
|
|
42
|
+
vec4 _background_ = texture2D(_background_, vUV);
|
|
43
|
+
|
|
44
|
+
if (length(color.rgb - _reference_) < _distance_) {
|
|
45
|
+
return _background_;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return color;
|
|
49
|
+
}
|
|
50
|
+
`,
|
|
51
|
+
params: "vec2 vUV",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The uniform names for this shader, to be used in the shader binding so
|
|
59
|
+
* that the names are always in sync.
|
|
60
|
+
*/
|
|
61
|
+
const Uniforms = {
|
|
62
|
+
input: "input",
|
|
63
|
+
background: "background",
|
|
64
|
+
reference: "reference",
|
|
65
|
+
distance: "distance",
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The shader binding for the GreenScreenBlock, used by the runtime
|
|
71
|
+
*/
|
|
72
|
+
class GreenScreenBlockShaderBinding extends DisableableShaderBinding {
|
|
73
|
+
private readonly _input: RuntimeData<ConnectionPointType.Texture>;
|
|
74
|
+
private readonly _background: RuntimeData<ConnectionPointType.Texture>;
|
|
75
|
+
private readonly _reference: RuntimeData<ConnectionPointType.Color3>;
|
|
76
|
+
private readonly _distance: RuntimeData<ConnectionPointType.Float>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new shader binding instance for the block.
|
|
80
|
+
* @param parentBlock - IDisableableBlock
|
|
81
|
+
* @param input - The input runtime value
|
|
82
|
+
* @param background - The background runtime value
|
|
83
|
+
* @param reference - The reference runtime value
|
|
84
|
+
* @param distance - The distance runtime value
|
|
85
|
+
*/
|
|
86
|
+
constructor(
|
|
87
|
+
parentBlock: IDisableableBlock,
|
|
88
|
+
input: RuntimeData<ConnectionPointType.Texture>,
|
|
89
|
+
background: RuntimeData<ConnectionPointType.Texture>,
|
|
90
|
+
reference: RuntimeData<ConnectionPointType.Color3>,
|
|
91
|
+
distance: RuntimeData<ConnectionPointType.Float>
|
|
92
|
+
) {
|
|
93
|
+
super(parentBlock);
|
|
94
|
+
this._input = input;
|
|
95
|
+
this._background = background;
|
|
96
|
+
this._reference = reference;
|
|
97
|
+
this._distance = distance;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Binds all the required data to the shader when rendering.
|
|
102
|
+
* @param effect - defines the effect to bind the data to
|
|
103
|
+
*/
|
|
104
|
+
public override bind(effect: Effect): void {
|
|
105
|
+
super.bind(effect);
|
|
106
|
+
effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
|
|
107
|
+
effect.setTexture(this.getRemappedName(Uniforms.background), this._background.value);
|
|
108
|
+
effect.setColor3(this.getRemappedName(Uniforms.reference), this._reference.value);
|
|
109
|
+
effect.setFloat(this.getRemappedName(Uniforms.distance), this._distance.value);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The implementation of the GreenScreenBlock
|
|
115
|
+
*/
|
|
116
|
+
export class GreenScreenBlock extends DisableableShaderBlock {
|
|
117
|
+
/**
|
|
118
|
+
* The class name of the block.
|
|
119
|
+
*/
|
|
120
|
+
public static override ClassName = "GreenScreenBlock";
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The namespace of the block.
|
|
124
|
+
*/
|
|
125
|
+
public static override Namespace = "Babylon.Demo.Effects";
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The input connection point.
|
|
129
|
+
*/
|
|
130
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The background connection point.
|
|
134
|
+
*/
|
|
135
|
+
public readonly background = this._registerInput(Uniforms.background, ConnectionPointType.Texture);
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The reference connection point.
|
|
139
|
+
*/
|
|
140
|
+
public readonly reference = this._registerInput(Uniforms.reference, ConnectionPointType.Color3);
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The distance connection point.
|
|
144
|
+
*/
|
|
145
|
+
public readonly distance = this._registerInput(Uniforms.distance, ConnectionPointType.Float);
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
149
|
+
*/
|
|
150
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Instantiates a new GreenScreenBlock.
|
|
154
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
155
|
+
* @param name - The friendly name of the block
|
|
156
|
+
*/
|
|
157
|
+
constructor(smartFilter: SmartFilter, name: string) {
|
|
158
|
+
super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
163
|
+
* @returns The class instance that binds the data to the effect
|
|
164
|
+
*/
|
|
165
|
+
public getShaderBinding(): DisableableShaderBinding {
|
|
166
|
+
const input = this._confirmRuntimeDataSupplied(this.input);
|
|
167
|
+
const background = this._confirmRuntimeDataSupplied(this.background);
|
|
168
|
+
const reference = this._confirmRuntimeDataSupplied(this.reference);
|
|
169
|
+
const distance = this._confirmRuntimeDataSupplied(this.distance);
|
|
170
|
+
|
|
171
|
+
return new GreenScreenBlockShaderBinding(this,input,background,reference,distance);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./blackAndWhiteBlock.block.js";
|
|
2
|
+
export * from "./blurBlock.js";
|
|
3
|
+
export * from "./compositionBlock.js";
|
|
4
|
+
export * from "./contrastBlock.block.js";
|
|
5
|
+
export * from "./desaturateBlock.block.js";
|
|
6
|
+
export * from "./directionalBlurBlock.js";
|
|
7
|
+
export * from "./exposureBlock.block.js";
|
|
8
|
+
export * from "./greenScreenBlock.block.js";
|
|
9
|
+
export * from "./kaleidoscopeBlock.js";
|
|
10
|
+
export * from "./maskBlock.block.js";
|
|
11
|
+
export * from "./pixelateBlock.block.js";
|
|
12
|
+
export * from "./posterizeBlock.block.js";
|
|
13
|
+
export * from "./spritesheetBlock.js";
|
|
14
|
+
export * from "./tintBlock.js";
|