@babylonjs/smart-filters-blocks 1.0.13 → 8.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -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: `
|
|
@@ -58,13 +58,14 @@ const shaderProgram: ShaderProgram = {
|
|
|
58
58
|
* The uniform names for this shader, to be used in the shader binding so
|
|
59
59
|
* that the names are always in sync.
|
|
60
60
|
*/
|
|
61
|
-
const
|
|
61
|
+
const Uniforms = {
|
|
62
62
|
input: "input",
|
|
63
63
|
background: "background",
|
|
64
64
|
reference: "reference",
|
|
65
65
|
distance: "distance",
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
|
|
68
69
|
/**
|
|
69
70
|
* The shader binding for the GreenScreenBlock, used by the runtime
|
|
70
71
|
*/
|
|
@@ -102,10 +103,10 @@ class GreenScreenBlockShaderBinding extends DisableableShaderBinding {
|
|
|
102
103
|
*/
|
|
103
104
|
public override bind(effect: Effect): void {
|
|
104
105
|
super.bind(effect);
|
|
105
|
-
effect.setTexture(this.getRemappedName(
|
|
106
|
-
effect.setTexture(this.getRemappedName(
|
|
107
|
-
effect.setColor3(this.getRemappedName(
|
|
108
|
-
effect.setFloat(this.getRemappedName(
|
|
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);
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
|
|
@@ -126,27 +127,27 @@ export class GreenScreenBlock extends DisableableShaderBlock {
|
|
|
126
127
|
/**
|
|
127
128
|
* The input connection point.
|
|
128
129
|
*/
|
|
129
|
-
public readonly input = this._registerInput(
|
|
130
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
130
131
|
|
|
131
132
|
/**
|
|
132
133
|
* The background connection point.
|
|
133
134
|
*/
|
|
134
|
-
public readonly background = this._registerInput(
|
|
135
|
+
public readonly background = this._registerInput(Uniforms.background, ConnectionPointType.Texture);
|
|
135
136
|
|
|
136
137
|
/**
|
|
137
138
|
* The reference connection point.
|
|
138
139
|
*/
|
|
139
|
-
public readonly reference = this._registerInput(
|
|
140
|
+
public readonly reference = this._registerInput(Uniforms.reference, ConnectionPointType.Color3);
|
|
140
141
|
|
|
141
142
|
/**
|
|
142
143
|
* The distance connection point.
|
|
143
144
|
*/
|
|
144
|
-
public readonly distance = this._registerInput(
|
|
145
|
+
public readonly distance = this._registerInput(Uniforms.distance, ConnectionPointType.Float);
|
|
145
146
|
|
|
146
147
|
/**
|
|
147
148
|
* The shader program (vertex and fragment code) to use to render the block
|
|
148
149
|
*/
|
|
149
|
-
public static override ShaderCode =
|
|
150
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
150
151
|
|
|
151
152
|
/**
|
|
152
153
|
* Instantiates a new GreenScreenBlock.
|
|
@@ -1,14 +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";
|
|
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";
|
|
@@ -1,192 +1,188 @@
|
|
|
1
|
-
import type { Effect } from "
|
|
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 "
|
|
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
|
|
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(
|
|
124
|
-
parentBlock
|
|
125
|
-
inputTexture
|
|
126
|
-
time
|
|
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
|
-
return new KaleidoscopeShaderBinding(this, input, time);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
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
|
+
}
|
|
@@ -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: `
|
|
@@ -53,11 +53,12 @@ const shaderProgram: ShaderProgram = {
|
|
|
53
53
|
* The uniform names for this shader, to be used in the shader binding so
|
|
54
54
|
* that the names are always in sync.
|
|
55
55
|
*/
|
|
56
|
-
const
|
|
56
|
+
const Uniforms = {
|
|
57
57
|
input: "input",
|
|
58
58
|
mask: "mask",
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
|
|
61
62
|
/**
|
|
62
63
|
* The shader binding for the MaskBlock, used by the runtime
|
|
63
64
|
*/
|
|
@@ -87,8 +88,8 @@ class MaskBlockShaderBinding extends DisableableShaderBinding {
|
|
|
87
88
|
*/
|
|
88
89
|
public override bind(effect: Effect): void {
|
|
89
90
|
super.bind(effect);
|
|
90
|
-
effect.setTexture(this.getRemappedName(
|
|
91
|
-
effect.setTexture(this.getRemappedName(
|
|
91
|
+
effect.setTexture(this.getRemappedName(Uniforms.input), this._input.value);
|
|
92
|
+
effect.setTexture(this.getRemappedName(Uniforms.mask), this._mask.value);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -109,17 +110,17 @@ export class MaskBlock extends DisableableShaderBlock {
|
|
|
109
110
|
/**
|
|
110
111
|
* The input connection point.
|
|
111
112
|
*/
|
|
112
|
-
public readonly input = this._registerInput(
|
|
113
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
113
114
|
|
|
114
115
|
/**
|
|
115
116
|
* The mask connection point.
|
|
116
117
|
*/
|
|
117
|
-
public readonly mask = this._registerInput(
|
|
118
|
+
public readonly mask = this._registerInput(Uniforms.mask, ConnectionPointType.Texture);
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
121
|
* The shader program (vertex and fragment code) to use to render the block
|
|
121
122
|
*/
|
|
122
|
-
public static override ShaderCode =
|
|
123
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
123
124
|
|
|
124
125
|
/**
|
|
125
126
|
* Instantiates a new MaskBlock.
|
|
@@ -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
|
ShaderBinding,
|
|
@@ -17,12 +17,12 @@ import {
|
|
|
17
17
|
type SmartFilter,
|
|
18
18
|
ShaderBlock,
|
|
19
19
|
type ShaderProgram,
|
|
20
|
-
createStrongRef} from "
|
|
20
|
+
createStrongRef} from "smart-filters";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* The shader program for the block.
|
|
24
24
|
*/
|
|
25
|
-
const
|
|
25
|
+
const BlockShaderProgram: ShaderProgram = {
|
|
26
26
|
vertex: undefined,
|
|
27
27
|
fragment: {
|
|
28
28
|
uniform: `
|
|
@@ -59,13 +59,14 @@ const shaderProgram: ShaderProgram = {
|
|
|
59
59
|
* The uniform names for this shader, to be used in the shader binding so
|
|
60
60
|
* that the names are always in sync.
|
|
61
61
|
*/
|
|
62
|
-
const
|
|
62
|
+
const Uniforms = {
|
|
63
63
|
input: "input",
|
|
64
64
|
intensity: "intensity",
|
|
65
65
|
disabled: "disabled",
|
|
66
66
|
aspect: "aspect",
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
|
|
69
70
|
/**
|
|
70
71
|
* The shader binding for the PixelateBlock, used by the runtime
|
|
71
72
|
*/
|
|
@@ -98,10 +99,10 @@ class PixelateBlockShaderBinding extends ShaderBinding {
|
|
|
98
99
|
* @param height - defines the height of the output
|
|
99
100
|
*/
|
|
100
101
|
public override bind(effect: Effect, width: number, height: number): void {
|
|
101
|
-
effect.setTexture(this.getRemappedName(
|
|
102
|
-
effect.setFloat(this.getRemappedName(
|
|
103
|
-
effect.setBool(this.getRemappedName(
|
|
104
|
-
effect.setFloat2(this.getRemappedName(
|
|
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);
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -122,7 +123,7 @@ export class PixelateBlock extends ShaderBlock {
|
|
|
122
123
|
/**
|
|
123
124
|
* The input connection point.
|
|
124
125
|
*/
|
|
125
|
-
public readonly input = this._registerInput(
|
|
126
|
+
public readonly input = this._registerInput(Uniforms.input, ConnectionPointType.Texture);
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
129
|
/**
|
|
@@ -147,7 +148,7 @@ export class PixelateBlock extends ShaderBlock {
|
|
|
147
148
|
/**
|
|
148
149
|
* The shader program (vertex and fragment code) to use to render the block
|
|
149
150
|
*/
|
|
150
|
-
public static override ShaderCode =
|
|
151
|
+
public static override ShaderCode = BlockShaderProgram;
|
|
151
152
|
|
|
152
153
|
/**
|
|
153
154
|
* Instantiates a new PixelateBlock.
|