@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.
Files changed (147) hide show
  1. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.d.ts.map +1 -1
  2. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js +5 -5
  3. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js.map +1 -1
  4. package/dist/blocks/babylon/demo/effects/blurBlock.d.ts.map +1 -1
  5. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts +1 -1
  6. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts.map +1 -1
  7. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js +3 -5
  8. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js.map +1 -1
  9. package/dist/blocks/babylon/demo/effects/blurBlock.js +8 -13
  10. package/dist/blocks/babylon/demo/effects/blurBlock.js.map +1 -1
  11. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts +1 -1
  12. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts.map +1 -1
  13. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.js +1 -1
  14. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts +7 -7
  15. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts.map +1 -1
  16. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts +1 -1
  17. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts.map +1 -1
  18. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js +2 -3
  19. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js.map +1 -1
  20. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts +4 -2
  21. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts.map +1 -1
  22. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js +5 -2
  23. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js.map +1 -1
  24. package/dist/blocks/babylon/demo/effects/compositionBlock.js +2 -6
  25. package/dist/blocks/babylon/demo/effects/compositionBlock.js.map +1 -1
  26. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts +1 -1
  27. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts.map +1 -1
  28. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.js +1 -1
  29. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts +1 -1
  30. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts.map +1 -1
  31. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js +6 -6
  32. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js.map +1 -1
  33. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts +1 -1
  34. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts.map +1 -1
  35. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js +6 -6
  36. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js.map +1 -1
  37. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts +3 -1
  38. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts.map +1 -1
  39. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts +1 -1
  40. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts.map +1 -1
  41. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js +4 -5
  42. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js.map +1 -1
  43. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js +32 -37
  44. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js.map +1 -1
  45. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts +1 -1
  46. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts.map +1 -1
  47. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.js +1 -1
  48. package/dist/blocks/babylon/demo/effects/exposureBlock.block.d.ts.map +1 -1
  49. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js +7 -7
  50. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js.map +1 -1
  51. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.d.ts.map +1 -1
  52. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js +11 -11
  53. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js.map +1 -1
  54. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts +6 -1
  55. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts.map +1 -1
  56. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js +71 -71
  57. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js.map +1 -1
  58. package/dist/blocks/babylon/demo/effects/maskBlock.block.d.ts.map +1 -1
  59. package/dist/blocks/babylon/demo/effects/maskBlock.block.js +7 -7
  60. package/dist/blocks/babylon/demo/effects/maskBlock.block.js.map +1 -1
  61. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts +2 -2
  62. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts.map +1 -1
  63. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js +8 -8
  64. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js.map +1 -1
  65. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts +1 -1
  66. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts.map +1 -1
  67. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js +6 -6
  68. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js.map +1 -1
  69. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts +5 -5
  70. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts.map +1 -1
  71. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts +4 -2
  72. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts.map +1 -1
  73. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js +5 -2
  74. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js.map +1 -1
  75. package/dist/blocks/babylon/demo/effects/spritesheetBlock.js.map +1 -1
  76. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts +1 -1
  77. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts.map +1 -1
  78. package/dist/blocks/babylon/demo/effects/tintBlock.js +10 -10
  79. package/dist/blocks/babylon/demo/effects/tintBlock.js.map +1 -1
  80. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.d.ts.map +1 -1
  81. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js +9 -9
  82. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js.map +1 -1
  83. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.d.ts.map +1 -1
  84. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js +5 -5
  85. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js.map +1 -1
  86. package/dist/blocks/blockNamespaces.d.ts.map +1 -1
  87. package/dist/blocks/blockNamespaces.js +2 -0
  88. package/dist/blocks/blockNamespaces.js.map +1 -1
  89. package/dist/blocks/blockTypes.d.ts.map +1 -1
  90. package/dist/blocks/blockTypes.js +2 -0
  91. package/dist/blocks/blockTypes.js.map +1 -1
  92. package/dist/blocks/index.d.ts.map +1 -1
  93. package/dist/blocks/index.js +1 -0
  94. package/dist/blocks/index.js.map +1 -1
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +1 -0
  97. package/dist/index.js.map +1 -1
  98. package/dist/registration/IBlockRegistration.d.ts +1 -1
  99. package/dist/registration/IBlockRegistration.d.ts.map +1 -1
  100. package/dist/registration/blockSerializers.d.ts.map +1 -1
  101. package/dist/registration/blockSerializers.js +6 -8
  102. package/dist/registration/blockSerializers.js.map +1 -1
  103. package/dist/registration/builtInBlockRegistrations.d.ts +1 -1
  104. package/dist/registration/builtInBlockRegistrations.d.ts.map +1 -1
  105. package/dist/registration/builtInBlockRegistrations.js +50 -52
  106. package/dist/registration/builtInBlockRegistrations.js.map +1 -1
  107. package/dist/registration/index.d.ts +1 -0
  108. package/dist/registration/index.d.ts.map +1 -1
  109. package/dist/registration/index.js +2 -0
  110. package/dist/registration/index.js.map +1 -1
  111. package/license.md +21 -21
  112. package/package.json +15 -13
  113. package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.ts +8 -7
  114. package/src/blocks/babylon/demo/effects/blurBlock.deserializer.ts +37 -37
  115. package/src/blocks/babylon/demo/effects/blurBlock.serializer.ts +31 -31
  116. package/src/blocks/babylon/demo/effects/blurBlock.ts +115 -122
  117. package/src/blocks/babylon/demo/effects/compositionBlock.deserializer.ts +31 -31
  118. package/src/blocks/babylon/demo/effects/compositionBlock.fragment.ts +7 -3
  119. package/src/blocks/babylon/demo/effects/compositionBlock.serializer.ts +28 -28
  120. package/src/blocks/babylon/demo/effects/compositionBlock.ts +211 -243
  121. package/src/blocks/babylon/demo/effects/contrastBlock.block.ts +9 -8
  122. package/src/blocks/babylon/demo/effects/desaturateBlock.block.ts +9 -8
  123. package/src/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.ts +43 -46
  124. package/src/blocks/babylon/demo/effects/directionalBlurBlock.serializer.ts +30 -30
  125. package/src/blocks/babylon/demo/effects/directionalBlurBlock.ts +192 -196
  126. package/src/blocks/babylon/demo/effects/exposureBlock.block.ts +10 -9
  127. package/src/blocks/babylon/demo/effects/greenScreenBlock.block.ts +14 -13
  128. package/src/blocks/babylon/demo/effects/index.ts +14 -14
  129. package/src/blocks/babylon/demo/effects/kaleidoscopeBlock.ts +188 -192
  130. package/src/blocks/babylon/demo/effects/maskBlock.block.ts +10 -9
  131. package/src/blocks/babylon/demo/effects/pixelateBlock.block.ts +11 -10
  132. package/src/blocks/babylon/demo/effects/posterizeBlock.block.ts +9 -8
  133. package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.ts +7 -3
  134. package/src/blocks/babylon/demo/effects/spritesheetBlock.ts +135 -138
  135. package/src/blocks/babylon/demo/effects/tintBlock.ts +51 -51
  136. package/src/blocks/babylon/demo/transitions/index.ts +1 -1
  137. package/src/blocks/babylon/demo/transitions/wipeBlock.block.ts +12 -11
  138. package/src/blocks/babylon/demo/utilities/index.ts +1 -1
  139. package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.ts +8 -7
  140. package/src/blocks/blockNamespaces.ts +6 -4
  141. package/src/blocks/blockTypes.ts +23 -21
  142. package/src/blocks/index.ts +6 -5
  143. package/src/index.ts +3 -2
  144. package/src/registration/IBlockRegistration.ts +43 -48
  145. package/src/registration/blockSerializers.ts +50 -52
  146. package/src/registration/builtInBlockRegistrations.ts +293 -403
  147. 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 "@babylonjs/core/Materials/effect";
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 "@babylonjs/smart-filters";
21
+ BlockDisableStrategy} from "smart-filters";
22
22
 
23
23
  /**
24
24
  * The shader program for the block.
25
25
  */
26
- const shaderProgram: ShaderProgram = {
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 uniforms = {
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(uniforms.input), this._input.value);
106
- effect.setTexture(this.getRemappedName(uniforms.background), this._background.value);
107
- effect.setColor3(this.getRemappedName(uniforms.reference), this._reference.value);
108
- effect.setFloat(this.getRemappedName(uniforms.distance), this._distance.value);
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(uniforms.input, ConnectionPointType.Texture);
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(uniforms.background, ConnectionPointType.Texture);
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(uniforms.reference, ConnectionPointType.Color3);
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(uniforms.distance, ConnectionPointType.Float);
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 = shaderProgram;
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 "@babylonjs/core/Materials/effect";
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 "@babylonjs/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(
124
- parentBlock: IDisableableBlock,
125
- inputTexture: RuntimeData<ConnectionPointType.Texture>,
126
- time: RuntimeData<ConnectionPointType.Float>
127
- ) {
128
- super(parentBlock);
129
- this._inputTexture = inputTexture;
130
- this._time = time;
131
- }
132
-
133
- /**
134
- * Binds all the required data to the shader when rendering.
135
- * @param effect - defines the effect to bind the data to
136
- */
137
- public override bind(effect: Effect): void {
138
- super.bind(effect);
139
- effect.setTexture(this.getRemappedName("input"), this._inputTexture.value);
140
- effect.setFloat(this.getRemappedName("time"), this._time.value);
141
- }
142
- }
143
-
144
- /**
145
- * A block performing a Kaleidoscope looking like effect.
146
- */
147
- export class KaleidoscopeBlock extends DisableableShaderBlock {
148
- /**
149
- * The class name of the block.
150
- */
151
- public static override ClassName = kaleidoscopeBlockType;
152
-
153
- /**
154
- * The namespace of the block.
155
- */
156
- public static override Namespace = babylonDemoEffectsNamespace;
157
-
158
- /**
159
- * The input texture connection point.
160
- */
161
- public readonly input = this._registerInput("input", ConnectionPointType.Texture);
162
-
163
- /**
164
- * The time connection point.
165
- */
166
- public readonly time = this._registerInput("time", ConnectionPointType.Float);
167
-
168
- /**
169
- * The shader program (vertex and fragment code) to use to render the block
170
- */
171
- public static override ShaderCode = shaderProgram;
172
-
173
- /**
174
- * Instantiates a new Block.
175
- * @param smartFilter - The smart filter this block belongs to
176
- * @param name - The friendly name of the block
177
- */
178
- constructor(smartFilter: SmartFilter, name: string) {
179
- super(smartFilter, name, false, BlockDisableStrategy.Manual);
180
- }
181
-
182
- /**
183
- * Get the class instance that binds all the required data to the shader (effect) when rendering.
184
- * @returns The class instance that binds the data to the effect
185
- */
186
- public getShaderBinding(): DisableableShaderBinding {
187
- const input = this._confirmRuntimeDataSupplied(this.input);
188
- const time = this._confirmRuntimeDataSupplied(this.time);
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 "@babylonjs/core/Materials/effect";
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 "@babylonjs/smart-filters";
21
+ BlockDisableStrategy} from "smart-filters";
22
22
 
23
23
  /**
24
24
  * The shader program for the block.
25
25
  */
26
- const shaderProgram: ShaderProgram = {
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 uniforms = {
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(uniforms.input), this._input.value);
91
- effect.setTexture(this.getRemappedName(uniforms.mask), this._mask.value);
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(uniforms.input, ConnectionPointType.Texture);
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(uniforms.mask, ConnectionPointType.Texture);
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 = shaderProgram;
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 "@babylonjs/core/Materials/effect";
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 "@babylonjs/smart-filters";
20
+ createStrongRef} from "smart-filters";
21
21
 
22
22
  /**
23
23
  * The shader program for the block.
24
24
  */
25
- const shaderProgram: ShaderProgram = {
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 uniforms = {
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(uniforms.input), this._input.value);
102
- effect.setFloat(this.getRemappedName(uniforms.intensity), this._intensity.value);
103
- effect.setBool(this.getRemappedName(uniforms.disabled), this._disabled.value);
104
- effect.setFloat2(this.getRemappedName(uniforms.aspect), width / height, height / width);
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(uniforms.input, ConnectionPointType.Texture);
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 = shaderProgram;
151
+ public static override ShaderCode = BlockShaderProgram;
151
152
 
152
153
  /**
153
154
  * Instantiates a new PixelateBlock.