@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,211 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
|
|
3
|
+
import type { Effect } from "core/Materials/effect.js";
|
|
4
|
+
import {
|
|
5
|
+
DisableableShaderBinding,
|
|
6
|
+
type RuntimeData,
|
|
7
|
+
ConnectionPointType,
|
|
8
|
+
type IDisableableBlock,
|
|
9
|
+
DisableableShaderBlock,
|
|
10
|
+
type SmartFilter,
|
|
11
|
+
createStrongRef,
|
|
12
|
+
PropertyTypeForEdition,
|
|
13
|
+
editableInPropertyPage,
|
|
14
|
+
} from "smart-filters";
|
|
15
|
+
import { compositionBlockType } from "../../../blockTypes.js";
|
|
16
|
+
import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
|
|
17
|
+
import { uniforms, shaderProgram } from "./compositionBlock.fragment.js";
|
|
18
|
+
|
|
19
|
+
/** Defines that alpha blending is disabled */
|
|
20
|
+
export const ALPHA_DISABLE = 0;
|
|
21
|
+
/** Defines that alpha blending is SRC ALPHA * SRC + DEST */
|
|
22
|
+
export const ALPHA_ADD = 1;
|
|
23
|
+
/** Defines that alpha blending is SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */
|
|
24
|
+
export const ALPHA_COMBINE = 2;
|
|
25
|
+
/** Defines that alpha blending is DEST - SRC * DEST */
|
|
26
|
+
export const ALPHA_SUBTRACT = 3;
|
|
27
|
+
/** Defines that alpha blending is SRC * DEST */
|
|
28
|
+
export const ALPHA_MULTIPLY = 4;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The shader bindings for the Composition block.
|
|
32
|
+
* This demonstrates how multiple input connection point values can be packed into a single
|
|
33
|
+
* uniform.
|
|
34
|
+
*/
|
|
35
|
+
export class CompositionShaderBinding extends DisableableShaderBinding {
|
|
36
|
+
private readonly _backgroundTexture: RuntimeData<ConnectionPointType.Texture>;
|
|
37
|
+
private readonly _foregroundTexture: RuntimeData<ConnectionPointType.Texture>;
|
|
38
|
+
private readonly _foregroundTop: RuntimeData<ConnectionPointType.Float>;
|
|
39
|
+
private readonly _foregroundLeft: RuntimeData<ConnectionPointType.Float>;
|
|
40
|
+
private readonly _foregroundWidth: RuntimeData<ConnectionPointType.Float>;
|
|
41
|
+
private readonly _foregroundHeight: RuntimeData<ConnectionPointType.Float>;
|
|
42
|
+
private readonly _foregroundAlphaScale: RuntimeData<ConnectionPointType.Float>;
|
|
43
|
+
private readonly _alphaMode: number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new shader binding instance for the Composition block.
|
|
47
|
+
* @param parentBlock - The parent block
|
|
48
|
+
* @param backgroundTexture - the background texture
|
|
49
|
+
* @param foregroundTexture - the foreground texture
|
|
50
|
+
* @param foregroundTop - the top position of the foreground texture
|
|
51
|
+
* @param foregroundLeft - the left position of the foreground texture
|
|
52
|
+
* @param foregroundWidth - the width of the foreground texture
|
|
53
|
+
* @param foregroundHeight - the height of the foreground texture
|
|
54
|
+
* @param foregroundAlphaScale - the alpha scale of the foreground texture
|
|
55
|
+
* @param alphaMode - the alpha mode to use
|
|
56
|
+
*/
|
|
57
|
+
constructor(
|
|
58
|
+
parentBlock: IDisableableBlock,
|
|
59
|
+
backgroundTexture: RuntimeData<ConnectionPointType.Texture>,
|
|
60
|
+
foregroundTexture: RuntimeData<ConnectionPointType.Texture>,
|
|
61
|
+
foregroundTop: RuntimeData<ConnectionPointType.Float>,
|
|
62
|
+
foregroundLeft: RuntimeData<ConnectionPointType.Float>,
|
|
63
|
+
foregroundWidth: RuntimeData<ConnectionPointType.Float>,
|
|
64
|
+
foregroundHeight: RuntimeData<ConnectionPointType.Float>,
|
|
65
|
+
foregroundAlphaScale: RuntimeData<ConnectionPointType.Float>,
|
|
66
|
+
alphaMode: number
|
|
67
|
+
) {
|
|
68
|
+
super(parentBlock);
|
|
69
|
+
this._backgroundTexture = backgroundTexture;
|
|
70
|
+
this._foregroundTexture = foregroundTexture;
|
|
71
|
+
this._foregroundTop = foregroundTop;
|
|
72
|
+
this._foregroundLeft = foregroundLeft;
|
|
73
|
+
this._foregroundWidth = foregroundWidth;
|
|
74
|
+
this._foregroundHeight = foregroundHeight;
|
|
75
|
+
this._foregroundAlphaScale = foregroundAlphaScale;
|
|
76
|
+
this._alphaMode = alphaMode;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Binds all the required data to the shader when rendering.
|
|
81
|
+
* @param effect - defines the effect to bind the data to
|
|
82
|
+
* @param width - defines the width of the output
|
|
83
|
+
* @param height - defines the height of the output
|
|
84
|
+
*/
|
|
85
|
+
public override bind(effect: Effect, width: number, height: number): void {
|
|
86
|
+
super.bind(effect, width, height);
|
|
87
|
+
|
|
88
|
+
const background = this._backgroundTexture.value;
|
|
89
|
+
const foreground = this._foregroundTexture.value;
|
|
90
|
+
const foregroundTop = this._foregroundTop.value;
|
|
91
|
+
const foregroundLeft = this._foregroundLeft.value;
|
|
92
|
+
const foregroundWidth = this._foregroundWidth.value;
|
|
93
|
+
const foregroundHeight = this._foregroundHeight.value;
|
|
94
|
+
const foregroundAlphaScale = this._foregroundAlphaScale.value;
|
|
95
|
+
const alphaMode = this._alphaMode;
|
|
96
|
+
|
|
97
|
+
effect.setFloat(this.getRemappedName(uniforms.alphaMode), alphaMode);
|
|
98
|
+
effect.setTexture(this.getRemappedName(uniforms.background), background);
|
|
99
|
+
effect.setTexture(this.getRemappedName(uniforms.foreground), foreground);
|
|
100
|
+
|
|
101
|
+
// NOTE: textures may always be undefined if connected to another shader block when the graph is optimized
|
|
102
|
+
|
|
103
|
+
effect.setFloat2(this.getRemappedName(uniforms.scaleUV), foregroundWidth, foregroundHeight);
|
|
104
|
+
effect.setFloat2(this.getRemappedName(uniforms.translateUV), -1 * foregroundLeft, foregroundTop);
|
|
105
|
+
effect.setFloat(this.getRemappedName(uniforms.foregroundAlphaScale), foregroundAlphaScale);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A simple compositing Block letting the filter "blend" 2 different layers.
|
|
111
|
+
* It demonstrates how a block can use properties for values which will not change at runtime (alphaMode)
|
|
112
|
+
*
|
|
113
|
+
* The alpha mode of the block can be set to one of the following:
|
|
114
|
+
* - ALPHA_DISABLE: alpha blending is disabled
|
|
115
|
+
* - ALPHA_ADD: alpha blending is SRC ALPHA * SRC + DEST
|
|
116
|
+
* - ALPHA_COMBINE: alpha blending is SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST
|
|
117
|
+
* - ALPHA_SUBTRACT: alpha blending is DEST - SRC * DEST
|
|
118
|
+
* - ALPHA_MULTIPLY: alpha blending is SRC * DEST
|
|
119
|
+
*/
|
|
120
|
+
export class CompositionBlock extends DisableableShaderBlock {
|
|
121
|
+
/**
|
|
122
|
+
* The class name of the block.
|
|
123
|
+
*/
|
|
124
|
+
public static override ClassName = compositionBlockType;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The namespace of the block.
|
|
128
|
+
*/
|
|
129
|
+
public static override Namespace = babylonDemoEffectsNamespace;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The background texture to composite on to.
|
|
133
|
+
*/
|
|
134
|
+
public readonly background = this._registerInput(uniforms.background, ConnectionPointType.Texture);
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The foreground texture to composite in.
|
|
138
|
+
*/
|
|
139
|
+
public readonly foreground = this._registerOptionalInput(uniforms.foreground, ConnectionPointType.Texture, createStrongRef(null));
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Defines where the top of the texture to composite in should be displayed. (between 0 and 1).
|
|
143
|
+
*/
|
|
144
|
+
public readonly foregroundTop = this._registerOptionalInput("foregroundTop", ConnectionPointType.Float, createStrongRef(0.0));
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Defines where the left of the texture to composite in should be displayed. (between 0 and 1).
|
|
148
|
+
*/
|
|
149
|
+
public readonly foregroundLeft = this._registerOptionalInput("foregroundLeft", ConnectionPointType.Float, createStrongRef(0.0));
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Defines the width of the texture in the composition.
|
|
153
|
+
*/
|
|
154
|
+
public readonly foregroundWidth = this._registerOptionalInput("foregroundWidth", ConnectionPointType.Float, createStrongRef(1.0));
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Defines the height of the texture in the composition.
|
|
158
|
+
*/
|
|
159
|
+
public readonly foregroundHeight = this._registerOptionalInput("foregroundHeight", ConnectionPointType.Float, createStrongRef(1.0));
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Defines a multiplier applied to the foreground's alpha channel.
|
|
163
|
+
*/
|
|
164
|
+
public readonly foregroundAlphaScale = this._registerOptionalInput(uniforms.foregroundAlphaScale, ConnectionPointType.Float, createStrongRef(1.0));
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Defines blend mode of the composition.
|
|
168
|
+
*/
|
|
169
|
+
@editableInPropertyPage("Alpha Mode", PropertyTypeForEdition.List, "PROPERTIES", {
|
|
170
|
+
notifiers: { rebuild: true },
|
|
171
|
+
options: [
|
|
172
|
+
{ label: "Disable", value: ALPHA_DISABLE },
|
|
173
|
+
{ label: "Add", value: ALPHA_ADD },
|
|
174
|
+
{ label: "Combine", value: ALPHA_COMBINE },
|
|
175
|
+
{ label: "Subtract", value: ALPHA_SUBTRACT },
|
|
176
|
+
{ label: "Multiply", value: ALPHA_MULTIPLY },
|
|
177
|
+
],
|
|
178
|
+
})
|
|
179
|
+
public alphaMode: number = ALPHA_COMBINE;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
183
|
+
*/
|
|
184
|
+
public static override ShaderCode = shaderProgram;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Instantiates a new Block.
|
|
188
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
189
|
+
* @param name - The friendly name of the block
|
|
190
|
+
*/
|
|
191
|
+
constructor(smartFilter: SmartFilter, name: string) {
|
|
192
|
+
super(smartFilter, name, true);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
197
|
+
* @returns The class instance that binds the data to the effect
|
|
198
|
+
*/
|
|
199
|
+
public getShaderBinding(): DisableableShaderBinding {
|
|
200
|
+
const background = this._confirmRuntimeDataSupplied(this.background);
|
|
201
|
+
const foreground = this._confirmRuntimeDataSupplied(this.foreground);
|
|
202
|
+
const foregroundWidth = this.foregroundWidth.runtimeData;
|
|
203
|
+
const foregroundLeft = this.foregroundLeft.runtimeData;
|
|
204
|
+
const foregroundHeight = this.foregroundHeight.runtimeData;
|
|
205
|
+
const foregroundTop = this.foregroundTop.runtimeData;
|
|
206
|
+
const foregroundAlphaScale = this.foregroundAlphaScale.runtimeData;
|
|
207
|
+
const alphaMode = this.alphaMode;
|
|
208
|
+
|
|
209
|
+
return new CompositionShaderBinding(this, background, foreground, foregroundTop, foregroundLeft, foregroundWidth, foregroundHeight, foregroundAlphaScale, alphaMode);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
{
|
|
3
|
+
"smartFilterBlockType": "ContrastBlock",
|
|
4
|
+
"namespace": "Babylon.Demo.Effects",
|
|
5
|
+
"blockDisableStrategy": "AutoSample"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
uniform sampler2D input; // main
|
|
10
|
+
// { "default": 0.5 }
|
|
11
|
+
uniform float intensity;
|
|
12
|
+
|
|
13
|
+
vec4 contrast(vec2 vUV) { // main
|
|
14
|
+
vec4 color = texture2D(input, vUV);
|
|
15
|
+
|
|
16
|
+
float contrastLMin = mix(-2., 0., intensity * 2.0);
|
|
17
|
+
float contrastLMax = mix(3., 1., intensity * 2.0);
|
|
18
|
+
|
|
19
|
+
vec3 contrastMin = remap(color.rgb, contrastLMin, contrastLMax, 0., 1.);
|
|
20
|
+
|
|
21
|
+
float intensityMapped = remap(intensity, 0.5, 1., 0., 1.0);
|
|
22
|
+
float contrastHMin = mix(0., 0.45, intensityMapped);
|
|
23
|
+
float contrastHMax = mix(1., 0.5, intensityMapped);
|
|
24
|
+
|
|
25
|
+
vec3 contrastMax = remap(color.rgb, contrastHMin, contrastHMax, 0., 1.);
|
|
26
|
+
|
|
27
|
+
return vec4(mix(contrastMin, contrastMax, step(intensity, 0.5)), color.a);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
float remap(float i, float smin, float smax, float dmin, float dmax) {
|
|
31
|
+
return dmin + (i - smin) * (dmax - dmin) / (smax - smin);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
vec3 remap(vec3 i, float smin, float smax, float dmin, float dmax) {
|
|
35
|
+
return dmin + (i - smin) * (dmax - dmin) / (smax - smin);
|
|
36
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
createStrongRef,
|
|
21
|
+
type IDisableableBlock,
|
|
22
|
+
BlockDisableStrategy} from "smart-filters";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The shader program for the block.
|
|
26
|
+
*/
|
|
27
|
+
const BlockShaderProgram: ShaderProgram = {
|
|
28
|
+
vertex: undefined,
|
|
29
|
+
fragment: {
|
|
30
|
+
uniform: `
|
|
31
|
+
uniform sampler2D _input_; // main
|
|
32
|
+
uniform float _intensity_;`,
|
|
33
|
+
mainInputTexture: "_input_",
|
|
34
|
+
mainFunctionName: "_contrast_",
|
|
35
|
+
functions: [
|
|
36
|
+
{
|
|
37
|
+
name: "_contrast_",
|
|
38
|
+
code: `
|
|
39
|
+
vec4 _contrast_(vec2 vUV) {
|
|
40
|
+
vec4 color = texture2D(_input_, vUV);
|
|
41
|
+
|
|
42
|
+
float contrastLMin = mix(-2., 0., _intensity_ * 2.0);
|
|
43
|
+
float contrastLMax = mix(3., 1., _intensity_ * 2.0);
|
|
44
|
+
|
|
45
|
+
vec3 contrastMin = _remap_(color.rgb, contrastLMin, contrastLMax, 0., 1.);
|
|
46
|
+
|
|
47
|
+
float intensityMapped = _remap_(_intensity_, 0.5, 1., 0., 1.0);
|
|
48
|
+
float contrastHMin = mix(0., 0.45, intensityMapped);
|
|
49
|
+
float contrastHMax = mix(1., 0.5, intensityMapped);
|
|
50
|
+
|
|
51
|
+
vec3 contrastMax = _remap_(color.rgb, contrastHMin, contrastHMax, 0., 1.);
|
|
52
|
+
|
|
53
|
+
return vec4(mix(contrastMin, contrastMax, step(_intensity_, 0.5)), color.a);
|
|
54
|
+
}
|
|
55
|
+
`,
|
|
56
|
+
params: "vec2 vUV",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "_remap_",
|
|
60
|
+
code: `
|
|
61
|
+
float _remap_(float i, float smin, float smax, float dmin, float dmax) {
|
|
62
|
+
return dmin + (i - smin) * (dmax - dmin) / (smax - smin);
|
|
63
|
+
}
|
|
64
|
+
`,
|
|
65
|
+
params: "float i, float smin, float smax, float dmin, float dmax",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "_remap_",
|
|
69
|
+
code: `
|
|
70
|
+
vec3 _remap_(vec3 i, float smin, float smax, float dmin, float dmax) {
|
|
71
|
+
return dmin + (i - smin) * (dmax - dmin) / (smax - smin);
|
|
72
|
+
}
|
|
73
|
+
`,
|
|
74
|
+
params: "vec3 i, float smin, float smax, float dmin, float dmax",
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The uniform names for this shader, to be used in the shader binding so
|
|
82
|
+
* that the names are always in sync.
|
|
83
|
+
*/
|
|
84
|
+
const Uniforms = {
|
|
85
|
+
input: "input",
|
|
86
|
+
intensity: "intensity",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The shader binding for the ContrastBlock, used by the runtime
|
|
92
|
+
*/
|
|
93
|
+
class ContrastBlockShaderBinding extends DisableableShaderBinding {
|
|
94
|
+
private readonly _input: RuntimeData<ConnectionPointType.Texture>;
|
|
95
|
+
private readonly _intensity: RuntimeData<ConnectionPointType.Float>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Creates a new shader binding instance for the block.
|
|
99
|
+
* @param parentBlock - IDisableableBlock
|
|
100
|
+
* @param input - The input runtime value
|
|
101
|
+
* @param intensity - The intensity runtime value
|
|
102
|
+
*/
|
|
103
|
+
constructor(
|
|
104
|
+
parentBlock: IDisableableBlock,
|
|
105
|
+
input: RuntimeData<ConnectionPointType.Texture>,
|
|
106
|
+
intensity: RuntimeData<ConnectionPointType.Float>
|
|
107
|
+
) {
|
|
108
|
+
super(parentBlock);
|
|
109
|
+
this._input = input;
|
|
110
|
+
this._intensity = intensity;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Binds all the required data to the shader when rendering.
|
|
115
|
+
* @param effect - defines the effect to bind the data to
|
|
116
|
+
*/
|
|
117
|
+
public override bind(effect: Effect): void {
|
|
118
|
+
super.bind(effect);
|
|
119
|
+
effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
|
|
120
|
+
effect.setFloat(this.getRemappedName(Uniforms.intensity), this._intensity.value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The implementation of the ContrastBlock
|
|
126
|
+
*/
|
|
127
|
+
export class ContrastBlock extends DisableableShaderBlock {
|
|
128
|
+
/**
|
|
129
|
+
* The class name of the block.
|
|
130
|
+
*/
|
|
131
|
+
public static override ClassName = "ContrastBlock";
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The namespace of the block.
|
|
135
|
+
*/
|
|
136
|
+
public static override Namespace = "Babylon.Demo.Effects";
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The input connection point.
|
|
140
|
+
*/
|
|
141
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
/**
|
|
145
|
+
* The intensity connection point.
|
|
146
|
+
*/
|
|
147
|
+
public readonly intensity = this._registerOptionalInput(
|
|
148
|
+
"intensity",
|
|
149
|
+
ConnectionPointType.Float,
|
|
150
|
+
createStrongRef(0.5)
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
155
|
+
*/
|
|
156
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Instantiates a new ContrastBlock.
|
|
160
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
161
|
+
* @param name - The friendly name of the block
|
|
162
|
+
*/
|
|
163
|
+
constructor(smartFilter: SmartFilter, name: string) {
|
|
164
|
+
super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
169
|
+
* @returns The class instance that binds the data to the effect
|
|
170
|
+
*/
|
|
171
|
+
public getShaderBinding(): DisableableShaderBinding {
|
|
172
|
+
const input = this._confirmRuntimeDataSupplied(this.input);
|
|
173
|
+
const intensity = this._confirmRuntimeDataSupplied(this.intensity);
|
|
174
|
+
|
|
175
|
+
return new ContrastBlockShaderBinding(this,input,intensity);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
{
|
|
3
|
+
"smartFilterBlockType": "DesaturateBlock",
|
|
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
|
+
vec4 desaturate(vec2 vUV) { // main
|
|
14
|
+
float saturationStrength = 1. - intensity;
|
|
15
|
+
|
|
16
|
+
vec4 color = texture2D(input, vUV);
|
|
17
|
+
|
|
18
|
+
float tempMin = min(min(color.x, color.y), color.z);
|
|
19
|
+
float tempMax = max(max(color.x, color.y), color.z);
|
|
20
|
+
float tempMerge = 0.5 * (tempMin + tempMax);
|
|
21
|
+
|
|
22
|
+
return vec4(mix(color.rgb, vec3(tempMerge, tempMerge, tempMerge), saturationStrength), color.a);
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
createStrongRef,
|
|
21
|
+
type IDisableableBlock,
|
|
22
|
+
BlockDisableStrategy} from "smart-filters";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The shader program for the block.
|
|
26
|
+
*/
|
|
27
|
+
const BlockShaderProgram: ShaderProgram = {
|
|
28
|
+
vertex: undefined,
|
|
29
|
+
fragment: {
|
|
30
|
+
uniform: `
|
|
31
|
+
uniform sampler2D _input_; // main
|
|
32
|
+
uniform float _intensity_;`,
|
|
33
|
+
mainInputTexture: "_input_",
|
|
34
|
+
mainFunctionName: "_desaturate_",
|
|
35
|
+
functions: [
|
|
36
|
+
{
|
|
37
|
+
name: "_desaturate_",
|
|
38
|
+
code: `
|
|
39
|
+
vec4 _desaturate_(vec2 vUV) {
|
|
40
|
+
float saturationStrength = 1. - _intensity_;
|
|
41
|
+
|
|
42
|
+
vec4 color = texture2D(_input_, vUV);
|
|
43
|
+
|
|
44
|
+
float tempMin = min(min(color.x, color.y), color.z);
|
|
45
|
+
float tempMax = max(max(color.x, color.y), color.z);
|
|
46
|
+
float tempMerge = 0.5 * (tempMin + tempMax);
|
|
47
|
+
|
|
48
|
+
return vec4(mix(color.rgb, vec3(tempMerge, tempMerge, tempMerge), saturationStrength), color.a);
|
|
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
|
+
intensity: "intensity",
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The shader binding for the DesaturateBlock, used by the runtime
|
|
69
|
+
*/
|
|
70
|
+
class DesaturateBlockShaderBinding extends DisableableShaderBinding {
|
|
71
|
+
private readonly _input: RuntimeData<ConnectionPointType.Texture>;
|
|
72
|
+
private readonly _intensity: RuntimeData<ConnectionPointType.Float>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new shader binding instance for the block.
|
|
76
|
+
* @param parentBlock - IDisableableBlock
|
|
77
|
+
* @param input - The input runtime value
|
|
78
|
+
* @param intensity - The intensity runtime value
|
|
79
|
+
*/
|
|
80
|
+
constructor(
|
|
81
|
+
parentBlock: IDisableableBlock,
|
|
82
|
+
input: RuntimeData<ConnectionPointType.Texture>,
|
|
83
|
+
intensity: RuntimeData<ConnectionPointType.Float>
|
|
84
|
+
) {
|
|
85
|
+
super(parentBlock);
|
|
86
|
+
this._input = input;
|
|
87
|
+
this._intensity = intensity;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Binds all the required data to the shader when rendering.
|
|
92
|
+
* @param effect - defines the effect to bind the data to
|
|
93
|
+
*/
|
|
94
|
+
public override bind(effect: Effect): void {
|
|
95
|
+
super.bind(effect);
|
|
96
|
+
effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
|
|
97
|
+
effect.setFloat(this.getRemappedName(Uniforms.intensity), this._intensity.value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The implementation of the DesaturateBlock
|
|
103
|
+
*/
|
|
104
|
+
export class DesaturateBlock extends DisableableShaderBlock {
|
|
105
|
+
/**
|
|
106
|
+
* The class name of the block.
|
|
107
|
+
*/
|
|
108
|
+
public static override ClassName = "DesaturateBlock";
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The namespace of the block.
|
|
112
|
+
*/
|
|
113
|
+
public static override Namespace = "Babylon.Demo.Effects";
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The input connection point.
|
|
117
|
+
*/
|
|
118
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
/**
|
|
122
|
+
* The intensity connection point.
|
|
123
|
+
*/
|
|
124
|
+
public readonly intensity = this._registerOptionalInput(
|
|
125
|
+
"intensity",
|
|
126
|
+
ConnectionPointType.Float,
|
|
127
|
+
createStrongRef(0.3)
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
132
|
+
*/
|
|
133
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Instantiates a new DesaturateBlock.
|
|
137
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
138
|
+
* @param name - The friendly name of the block
|
|
139
|
+
*/
|
|
140
|
+
constructor(smartFilter: SmartFilter, name: string) {
|
|
141
|
+
super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
146
|
+
* @returns The class instance that binds the data to the effect
|
|
147
|
+
*/
|
|
148
|
+
public getShaderBinding(): DisableableShaderBinding {
|
|
149
|
+
const input = this._confirmRuntimeDataSupplied(this.input);
|
|
150
|
+
const intensity = this._confirmRuntimeDataSupplied(this.intensity);
|
|
151
|
+
|
|
152
|
+
return new DesaturateBlockShaderBinding(this,input,intensity);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,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
|
+
};
|