@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,188 @@
|
|
|
1
|
+
import type { Effect } from "core/Materials/effect.js";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ShaderProgram,
|
|
5
|
+
DisableableShaderBinding,
|
|
6
|
+
type RuntimeData,
|
|
7
|
+
ConnectionPointType,
|
|
8
|
+
type IDisableableBlock,
|
|
9
|
+
DisableableShaderBlock,
|
|
10
|
+
type SmartFilter,
|
|
11
|
+
BlockDisableStrategy,
|
|
12
|
+
} from "smart-filters";
|
|
13
|
+
|
|
14
|
+
import { kaleidoscopeBlockType } from "../../../blockTypes.js";
|
|
15
|
+
import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This block uses a custom vertex shader, so it defines the ShaderProgram inline
|
|
19
|
+
*/
|
|
20
|
+
const ShaderProgram: ShaderProgram = {
|
|
21
|
+
vertex: `
|
|
22
|
+
// Attributes
|
|
23
|
+
attribute vec2 position;
|
|
24
|
+
|
|
25
|
+
// Output
|
|
26
|
+
varying vec2 vUV;
|
|
27
|
+
|
|
28
|
+
void main(void) {
|
|
29
|
+
vUV = position;
|
|
30
|
+
gl_Position = vec4(position, 0.0, 1.0);
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
|
|
34
|
+
fragment: {
|
|
35
|
+
uniform: `
|
|
36
|
+
uniform sampler2D _input_;
|
|
37
|
+
uniform float _time_;
|
|
38
|
+
uniform bool _disabled_;
|
|
39
|
+
`,
|
|
40
|
+
|
|
41
|
+
const: `
|
|
42
|
+
const float _width_ = 200.;
|
|
43
|
+
const float _height_ = 300.;
|
|
44
|
+
const vec2 _imageRatio_ = vec2(700. / _width_, 1024. / _height_);
|
|
45
|
+
const vec2 _imageRelativeSize_ = 1. / _imageRatio_;
|
|
46
|
+
const float _halfDiag_ = sqrt(_imageRelativeSize_.x * _imageRelativeSize_.x + _imageRelativeSize_.y * _imageRelativeSize_.y) * 0.5;
|
|
47
|
+
|
|
48
|
+
const float _radius_ = 0.9;
|
|
49
|
+
const float _radius2_ = 0.4;
|
|
50
|
+
|
|
51
|
+
const float _segments_ = 6.;
|
|
52
|
+
const float _segmentArc_ = (2. * 3.1415926535897932384626433832795 / _segments_);
|
|
53
|
+
`,
|
|
54
|
+
|
|
55
|
+
mainFunctionName: "_kaleidoscope_",
|
|
56
|
+
|
|
57
|
+
mainInputTexture: "_input_",
|
|
58
|
+
|
|
59
|
+
functions: [
|
|
60
|
+
{
|
|
61
|
+
name: "_kaleidoscope_",
|
|
62
|
+
code: `
|
|
63
|
+
vec4 _kaleidoscope_(vec2 vUV) {
|
|
64
|
+
if (_disabled_) return texture2D(_input_, vUV);
|
|
65
|
+
|
|
66
|
+
float distanceToCircle = abs(length(vUV) - _radius_);
|
|
67
|
+
vec4 result = vec4(0., 0., 0., 0.);
|
|
68
|
+
|
|
69
|
+
if (distanceToCircle < _halfDiag_ * 10000.) {
|
|
70
|
+
float pointTheta = atan(vUV.y, vUV.x);
|
|
71
|
+
pointTheta += _time_;
|
|
72
|
+
for (float i = -1.; i < 2.; i += 1.) {
|
|
73
|
+
float chunk = floor(pointTheta / _segmentArc_) + i;
|
|
74
|
+
float chunkStart = -_time_ + chunk * _segmentArc_ + _segmentArc_ * 0.5;
|
|
75
|
+
vec2 chunkStartCenter = vec2(cos(chunkStart), sin(chunkStart)) * _radius_;
|
|
76
|
+
vec2 chunkStartPoint = vUV - chunkStartCenter;
|
|
77
|
+
chunkStartPoint *= _imageRatio_;
|
|
78
|
+
chunkStartPoint *= vec2(0.5, 0.5);
|
|
79
|
+
chunkStartPoint += vec2(0.5, 0.5);
|
|
80
|
+
|
|
81
|
+
if (chunkStartPoint.x > 0. && chunkStartPoint.x < 1. && chunkStartPoint.y > 0. && chunkStartPoint.y < 1.) {
|
|
82
|
+
result = texture2D(_input_, chunkStartPoint);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (float i = -1.; i < 2.; i += 1.) {
|
|
87
|
+
float chunk = floor(pointTheta / _segmentArc_) + i;
|
|
88
|
+
float chunkStart = -_time_ + chunk * _segmentArc_ + _segmentArc_ * 0.5;
|
|
89
|
+
vec2 chunkStartCenter = vec2(cos(chunkStart), sin(chunkStart)) * _radius2_;
|
|
90
|
+
vec2 chunkStartPoint = vUV - chunkStartCenter;
|
|
91
|
+
chunkStartPoint *= _imageRatio_;
|
|
92
|
+
chunkStartPoint *= vec2(0.5, 0.5);
|
|
93
|
+
chunkStartPoint += vec2(0.5, 0.5);
|
|
94
|
+
|
|
95
|
+
if (chunkStartPoint.x > 0. && chunkStartPoint.x < 1. && chunkStartPoint.y > 0. && chunkStartPoint.y < 1.) {
|
|
96
|
+
vec4 top = texture2D(_input_, chunkStartPoint);
|
|
97
|
+
result = mix(result, top, (result.a <= 0.) ? 1. : top.a);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
`,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The shader bindings for the Kaleidoscope block.
|
|
112
|
+
*/
|
|
113
|
+
export class KaleidoscopeShaderBinding extends DisableableShaderBinding {
|
|
114
|
+
private readonly _inputTexture: RuntimeData<ConnectionPointType.Texture>;
|
|
115
|
+
private readonly _time: RuntimeData<ConnectionPointType.Float>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new shader binding instance for the Kaleidoscope block.
|
|
119
|
+
* @param parentBlock - The parent block
|
|
120
|
+
* @param inputTexture - the input texture
|
|
121
|
+
* @param time - the time
|
|
122
|
+
*/
|
|
123
|
+
constructor(parentBlock: IDisableableBlock, inputTexture: RuntimeData<ConnectionPointType.Texture>, time: RuntimeData<ConnectionPointType.Float>) {
|
|
124
|
+
super(parentBlock);
|
|
125
|
+
this._inputTexture = inputTexture;
|
|
126
|
+
this._time = time;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Binds all the required data to the shader when rendering.
|
|
131
|
+
* @param effect - defines the effect to bind the data to
|
|
132
|
+
*/
|
|
133
|
+
public override bind(effect: Effect): void {
|
|
134
|
+
super.bind(effect);
|
|
135
|
+
effect.setTexture(this.getRemappedName("input"), this._inputTexture.value);
|
|
136
|
+
effect.setFloat(this.getRemappedName("time"), this._time.value);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A block performing a Kaleidoscope looking like effect.
|
|
142
|
+
*/
|
|
143
|
+
export class KaleidoscopeBlock extends DisableableShaderBlock {
|
|
144
|
+
/**
|
|
145
|
+
* The class name of the block.
|
|
146
|
+
*/
|
|
147
|
+
public static override ClassName = kaleidoscopeBlockType;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The namespace of the block.
|
|
151
|
+
*/
|
|
152
|
+
public static override Namespace = babylonDemoEffectsNamespace;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The input texture connection point.
|
|
156
|
+
*/
|
|
157
|
+
public readonly input = this._registerInput("input", ConnectionPointType.Texture);
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The time connection point.
|
|
161
|
+
*/
|
|
162
|
+
public readonly time = this._registerInput("time", ConnectionPointType.Float);
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
166
|
+
*/
|
|
167
|
+
public static override ShaderCode = ShaderProgram;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Instantiates a new Block.
|
|
171
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
172
|
+
* @param name - The friendly name of the block
|
|
173
|
+
*/
|
|
174
|
+
constructor(smartFilter: SmartFilter, name: string) {
|
|
175
|
+
super(smartFilter, name, false, BlockDisableStrategy.Manual);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
180
|
+
* @returns The class instance that binds the data to the effect
|
|
181
|
+
*/
|
|
182
|
+
public getShaderBinding(): DisableableShaderBinding {
|
|
183
|
+
const input = this._confirmRuntimeDataSupplied(this.input);
|
|
184
|
+
const time = this._confirmRuntimeDataSupplied(this.time);
|
|
185
|
+
|
|
186
|
+
return new KaleidoscopeShaderBinding(this, input, time);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
{
|
|
3
|
+
"smartFilterBlockType": "MaskBlock",
|
|
4
|
+
"namespace": "Babylon.Demo.Effects",
|
|
5
|
+
"blockDisableStrategy": "AutoSample"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
uniform sampler2D input; // main
|
|
10
|
+
uniform sampler2D mask;
|
|
11
|
+
|
|
12
|
+
vec4 maskBlock(vec2 vUV) { // main
|
|
13
|
+
vec4 color = texture2D(input, vUV);
|
|
14
|
+
vec3 maskColor = texture2D(mask, vUV).rgb;
|
|
15
|
+
float luminance = dot(maskColor, vec3(0.3, 0.59, 0.11));
|
|
16
|
+
|
|
17
|
+
return vec4(color.rgb * luminance, luminance * color.a);
|
|
18
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
|
+
// ************************************************************
|
|
3
|
+
// Note: this file is auto-generated, do not modify it directly
|
|
4
|
+
// ************************************************************
|
|
5
|
+
|
|
6
|
+
// It was generated by convertGlslIntoBlock() from
|
|
7
|
+
// an annotated .glsl file. Modify the .glsl file to make changes
|
|
8
|
+
// to the block. This file will get overwritten when the build
|
|
9
|
+
// is run or during a watch when the .glsl file is updated.
|
|
10
|
+
|
|
11
|
+
import type { Effect } from "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 _mask_;`,
|
|
32
|
+
mainInputTexture: "_input_",
|
|
33
|
+
mainFunctionName: "_maskBlock_",
|
|
34
|
+
functions: [
|
|
35
|
+
{
|
|
36
|
+
name: "_maskBlock_",
|
|
37
|
+
code: `
|
|
38
|
+
vec4 _maskBlock_(vec2 vUV) {
|
|
39
|
+
vec4 color = texture2D(_input_, vUV);
|
|
40
|
+
vec3 maskColor = texture2D(_mask_, vUV).rgb;
|
|
41
|
+
float luminance = dot(maskColor, vec3(0.3, 0.59, 0.11));
|
|
42
|
+
|
|
43
|
+
return vec4(color.rgb * luminance, luminance * color.a);
|
|
44
|
+
}
|
|
45
|
+
`,
|
|
46
|
+
params: "vec2 vUV",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The uniform names for this shader, to be used in the shader binding so
|
|
54
|
+
* that the names are always in sync.
|
|
55
|
+
*/
|
|
56
|
+
const Uniforms = {
|
|
57
|
+
input: "input",
|
|
58
|
+
mask: "mask",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The shader binding for the MaskBlock, used by the runtime
|
|
64
|
+
*/
|
|
65
|
+
class MaskBlockShaderBinding extends DisableableShaderBinding {
|
|
66
|
+
private readonly _input: RuntimeData<ConnectionPointType.Texture>;
|
|
67
|
+
private readonly _mask: RuntimeData<ConnectionPointType.Texture>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new shader binding instance for the block.
|
|
71
|
+
* @param parentBlock - IDisableableBlock
|
|
72
|
+
* @param input - The input runtime value
|
|
73
|
+
* @param mask - The mask runtime value
|
|
74
|
+
*/
|
|
75
|
+
constructor(
|
|
76
|
+
parentBlock: IDisableableBlock,
|
|
77
|
+
input: RuntimeData<ConnectionPointType.Texture>,
|
|
78
|
+
mask: RuntimeData<ConnectionPointType.Texture>
|
|
79
|
+
) {
|
|
80
|
+
super(parentBlock);
|
|
81
|
+
this._input = input;
|
|
82
|
+
this._mask = mask;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Binds all the required data to the shader when rendering.
|
|
87
|
+
* @param effect - defines the effect to bind the data to
|
|
88
|
+
*/
|
|
89
|
+
public override bind(effect: Effect): void {
|
|
90
|
+
super.bind(effect);
|
|
91
|
+
effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
|
|
92
|
+
effect.setTexture(this.getRemappedName(Uniforms.mask), this._mask.value);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The implementation of the MaskBlock
|
|
98
|
+
*/
|
|
99
|
+
export class MaskBlock extends DisableableShaderBlock {
|
|
100
|
+
/**
|
|
101
|
+
* The class name of the block.
|
|
102
|
+
*/
|
|
103
|
+
public static override ClassName = "MaskBlock";
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The namespace of the block.
|
|
107
|
+
*/
|
|
108
|
+
public static override Namespace = "Babylon.Demo.Effects";
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The input connection point.
|
|
112
|
+
*/
|
|
113
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The mask connection point.
|
|
117
|
+
*/
|
|
118
|
+
public readonly mask = this._registerInput(Uniforms.mask, ConnectionPointType.Texture);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
122
|
+
*/
|
|
123
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Instantiates a new MaskBlock.
|
|
127
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
128
|
+
* @param name - The friendly name of the block
|
|
129
|
+
*/
|
|
130
|
+
constructor(smartFilter: SmartFilter, name: string) {
|
|
131
|
+
super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
136
|
+
* @returns The class instance that binds the data to the effect
|
|
137
|
+
*/
|
|
138
|
+
public getShaderBinding(): DisableableShaderBinding {
|
|
139
|
+
const input = this._confirmRuntimeDataSupplied(this.input);
|
|
140
|
+
const mask = this._confirmRuntimeDataSupplied(this.mask);
|
|
141
|
+
|
|
142
|
+
return new MaskBlockShaderBinding(this,input,mask);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
{
|
|
3
|
+
"smartFilterBlockType": "PixelateBlock",
|
|
4
|
+
"namespace": "Babylon.Demo.Effects",
|
|
5
|
+
"blockDisableStrategy": "Manual"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
uniform sampler2D input; // main
|
|
10
|
+
// { "default": "0.3" }
|
|
11
|
+
uniform float intensity;
|
|
12
|
+
// { "default": false }
|
|
13
|
+
uniform bool disabled;
|
|
14
|
+
// { "autoBind": "outputAspectRatio" }
|
|
15
|
+
uniform vec2 aspect;
|
|
16
|
+
|
|
17
|
+
const float videoPixelatePower = 6.0;
|
|
18
|
+
const float videoPixelateMin = 10.0;
|
|
19
|
+
const float videoPixelateMax = 1920.0;
|
|
20
|
+
|
|
21
|
+
vec4 pixelate(vec2 vUV) { // main
|
|
22
|
+
if (!disabled) {
|
|
23
|
+
float pixelateStrength = mix(videoPixelateMin, videoPixelateMax, pow(1. - intensity, videoPixelatePower));
|
|
24
|
+
vec2 pixelate = vec2(pixelateStrength * aspect.x, pixelateStrength);
|
|
25
|
+
vec2 pixelSize = vec2(1. / pixelate);
|
|
26
|
+
vUV = pixelSize * (floor(pixelate * vUV) + 0.5);
|
|
27
|
+
}
|
|
28
|
+
return texture2D(input, vUV);
|
|
29
|
+
}
|
|
@@ -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
|
+
ShaderBinding,
|
|
15
|
+
type RuntimeData,
|
|
16
|
+
ConnectionPointType,
|
|
17
|
+
type SmartFilter,
|
|
18
|
+
ShaderBlock,
|
|
19
|
+
type ShaderProgram,
|
|
20
|
+
createStrongRef} from "smart-filters";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The shader program for the block.
|
|
24
|
+
*/
|
|
25
|
+
const BlockShaderProgram: ShaderProgram = {
|
|
26
|
+
vertex: undefined,
|
|
27
|
+
fragment: {
|
|
28
|
+
uniform: `
|
|
29
|
+
uniform sampler2D _input_; // main
|
|
30
|
+
uniform float _intensity_;
|
|
31
|
+
uniform bool _disabled_;
|
|
32
|
+
uniform vec2 _aspect_;`,
|
|
33
|
+
const: ` const float _videoPixelatePower_ = 6.0;
|
|
34
|
+
const float _videoPixelateMin_ = 10.0;
|
|
35
|
+
const float _videoPixelateMax_ = 1920.0;`,
|
|
36
|
+
mainInputTexture: "_input_",
|
|
37
|
+
mainFunctionName: "_pixelate_",
|
|
38
|
+
functions: [
|
|
39
|
+
{
|
|
40
|
+
name: "_pixelate_",
|
|
41
|
+
code: `
|
|
42
|
+
vec4 _pixelate_(vec2 vUV) {
|
|
43
|
+
if (!_disabled_) {
|
|
44
|
+
float pixelateStrength = mix(_videoPixelateMin_, _videoPixelateMax_, pow(1. - _intensity_, _videoPixelatePower_));
|
|
45
|
+
vec2 _pixelate_ = vec2(pixelateStrength * _aspect_.x, pixelateStrength);
|
|
46
|
+
vec2 pixelSize = vec2(1. / _pixelate_);
|
|
47
|
+
vUV = pixelSize * (floor(_pixelate_ * vUV) + 0.5);
|
|
48
|
+
}
|
|
49
|
+
return texture2D(_input_, vUV);
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
params: "vec2 vUV",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The uniform names for this shader, to be used in the shader binding so
|
|
60
|
+
* that the names are always in sync.
|
|
61
|
+
*/
|
|
62
|
+
const Uniforms = {
|
|
63
|
+
input: "input",
|
|
64
|
+
intensity: "intensity",
|
|
65
|
+
disabled: "disabled",
|
|
66
|
+
aspect: "aspect",
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The shader binding for the PixelateBlock, used by the runtime
|
|
72
|
+
*/
|
|
73
|
+
class PixelateBlockShaderBinding extends ShaderBinding {
|
|
74
|
+
private readonly _input: RuntimeData<ConnectionPointType.Texture>;
|
|
75
|
+
private readonly _intensity: RuntimeData<ConnectionPointType.Float>;
|
|
76
|
+
private readonly _disabled: RuntimeData<ConnectionPointType.Boolean>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new shader binding instance for the block.
|
|
80
|
+
* @param input - The input runtime value
|
|
81
|
+
* @param intensity - The intensity runtime value
|
|
82
|
+
* @param disabled - The disabled runtime value
|
|
83
|
+
*/
|
|
84
|
+
constructor(
|
|
85
|
+
input: RuntimeData<ConnectionPointType.Texture>,
|
|
86
|
+
intensity: RuntimeData<ConnectionPointType.Float>,
|
|
87
|
+
disabled: RuntimeData<ConnectionPointType.Boolean>
|
|
88
|
+
) {
|
|
89
|
+
super();
|
|
90
|
+
this._input = input;
|
|
91
|
+
this._intensity = intensity;
|
|
92
|
+
this._disabled = disabled;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Binds all the required data to the shader when rendering.
|
|
97
|
+
* @param effect - defines the effect to bind the data to
|
|
98
|
+
* @param width - defines the width of the output
|
|
99
|
+
* @param height - defines the height of the output
|
|
100
|
+
*/
|
|
101
|
+
public override bind(effect: Effect, width: number, height: number): void {
|
|
102
|
+
effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
|
|
103
|
+
effect.setFloat(this.getRemappedName(Uniforms.intensity), this._intensity.value);
|
|
104
|
+
effect.setBool(this.getRemappedName(Uniforms.disabled), this._disabled.value);
|
|
105
|
+
effect.setFloat2(this.getRemappedName(Uniforms.aspect), width / height, height / width);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The implementation of the PixelateBlock
|
|
111
|
+
*/
|
|
112
|
+
export class PixelateBlock extends ShaderBlock {
|
|
113
|
+
/**
|
|
114
|
+
* The class name of the block.
|
|
115
|
+
*/
|
|
116
|
+
public static override ClassName = "PixelateBlock";
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The namespace of the block.
|
|
120
|
+
*/
|
|
121
|
+
public static override Namespace = "Babylon.Demo.Effects";
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The input connection point.
|
|
125
|
+
*/
|
|
126
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
/**
|
|
130
|
+
* The intensity connection point.
|
|
131
|
+
*/
|
|
132
|
+
public readonly intensity = this._registerOptionalInput(
|
|
133
|
+
"intensity",
|
|
134
|
+
ConnectionPointType.Float,
|
|
135
|
+
createStrongRef(0.3)
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
/**
|
|
140
|
+
* The disabled connection point.
|
|
141
|
+
*/
|
|
142
|
+
public readonly disabled = this._registerOptionalInput(
|
|
143
|
+
"disabled",
|
|
144
|
+
ConnectionPointType.Boolean,
|
|
145
|
+
createStrongRef(false)
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The shader program (vertex and fragment code) to use to render the block
|
|
150
|
+
*/
|
|
151
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Instantiates a new PixelateBlock.
|
|
155
|
+
* @param smartFilter - The smart filter this block belongs to
|
|
156
|
+
* @param name - The friendly name of the block
|
|
157
|
+
*/
|
|
158
|
+
constructor(smartFilter: SmartFilter, name: string) {
|
|
159
|
+
super(smartFilter, name, false);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Get the class instance that binds all the required data to the shader (effect) when rendering.
|
|
164
|
+
* @returns The class instance that binds the data to the effect
|
|
165
|
+
*/
|
|
166
|
+
public getShaderBinding(): ShaderBinding {
|
|
167
|
+
const input = this._confirmRuntimeDataSupplied(this.input);
|
|
168
|
+
const intensity = this._confirmRuntimeDataSupplied(this.intensity);
|
|
169
|
+
const disabled = this._confirmRuntimeDataSupplied(this.disabled);
|
|
170
|
+
|
|
171
|
+
return new PixelateBlockShaderBinding(input,intensity,disabled);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
{
|
|
3
|
+
"smartFilterBlockType": "PosterizeBlock",
|
|
4
|
+
"namespace": "Babylon.Demo.Effects",
|
|
5
|
+
"blockDisableStrategy": "AutoSample"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
uniform sampler2D input; // main
|
|
10
|
+
// { "default": 0.3 }
|
|
11
|
+
uniform float intensity;
|
|
12
|
+
|
|
13
|
+
const float posterizePower = 6.0;
|
|
14
|
+
const float minLevel = 2.0;
|
|
15
|
+
const float maxLevel = 256.0;
|
|
16
|
+
|
|
17
|
+
vec4 posterize(vec2 vUV) { // main
|
|
18
|
+
vec4 color = texture2D(input, vUV);
|
|
19
|
+
|
|
20
|
+
float posterizeStrength = mix(minLevel, maxLevel, pow(1. - intensity, posterizePower));
|
|
21
|
+
vec3 posterize = vec3(posterizeStrength);
|
|
22
|
+
color.rgb = floor(color.rgb / (1.0 / posterize)) * (1.0 / posterize);
|
|
23
|
+
|
|
24
|
+
return color;
|
|
25
|
+
}
|