@babylonjs/smart-filters-blocks 0.8.1

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 (190) hide show
  1. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.d.ts +34 -0
  2. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.d.ts.map +1 -0
  3. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js +101 -0
  4. package/dist/blocks/babylon/demo/effects/blackAndWhiteBlock.block.js.map +1 -0
  5. package/dist/blocks/babylon/demo/effects/blurBlock.d.ts +53 -0
  6. package/dist/blocks/babylon/demo/effects/blurBlock.d.ts.map +1 -0
  7. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts +28 -0
  8. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.d.ts.map +1 -0
  9. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js +17 -0
  10. package/dist/blocks/babylon/demo/effects/blurBlock.deserializer.js.map +1 -0
  11. package/dist/blocks/babylon/demo/effects/blurBlock.js +98 -0
  12. package/dist/blocks/babylon/demo/effects/blurBlock.js.map +1 -0
  13. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts +8 -0
  14. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.d.ts.map +1 -0
  15. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.js +28 -0
  16. package/dist/blocks/babylon/demo/effects/blurBlock.serializer.js.map +1 -0
  17. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts +116 -0
  18. package/dist/blocks/babylon/demo/effects/compositionBlock.d.ts.map +1 -0
  19. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts +24 -0
  20. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.d.ts.map +1 -0
  21. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js +15 -0
  22. package/dist/blocks/babylon/demo/effects/compositionBlock.deserializer.js.map +1 -0
  23. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts +18 -0
  24. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.d.ts.map +1 -0
  25. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js +69 -0
  26. package/dist/blocks/babylon/demo/effects/compositionBlock.fragment.js.map +1 -0
  27. package/dist/blocks/babylon/demo/effects/compositionBlock.js +167 -0
  28. package/dist/blocks/babylon/demo/effects/compositionBlock.js.map +1 -0
  29. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts +6 -0
  30. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.d.ts.map +1 -0
  31. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.js +25 -0
  32. package/dist/blocks/babylon/demo/effects/compositionBlock.serializer.js.map +1 -0
  33. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts +39 -0
  34. package/dist/blocks/babylon/demo/effects/contrastBlock.block.d.ts.map +1 -0
  35. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js +140 -0
  36. package/dist/blocks/babylon/demo/effects/contrastBlock.block.js.map +1 -0
  37. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts +39 -0
  38. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.d.ts.map +1 -0
  39. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js +115 -0
  40. package/dist/blocks/babylon/demo/effects/desaturateBlock.block.js.map +1 -0
  41. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts +74 -0
  42. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.d.ts.map +1 -0
  43. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts +32 -0
  44. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.d.ts.map +1 -0
  45. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js +17 -0
  46. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.js.map +1 -0
  47. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js +167 -0
  48. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.js.map +1 -0
  49. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts +6 -0
  50. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.d.ts.map +1 -0
  51. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.js +27 -0
  52. package/dist/blocks/babylon/demo/effects/directionalBlurBlock.serializer.js.map +1 -0
  53. package/dist/blocks/babylon/demo/effects/exposureBlock.block.d.ts +38 -0
  54. package/dist/blocks/babylon/demo/effects/exposureBlock.block.d.ts.map +1 -0
  55. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js +107 -0
  56. package/dist/blocks/babylon/demo/effects/exposureBlock.block.js.map +1 -0
  57. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.d.ts +46 -0
  58. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.d.ts.map +1 -0
  59. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js +133 -0
  60. package/dist/blocks/babylon/demo/effects/greenScreenBlock.block.js.map +1 -0
  61. package/dist/blocks/babylon/demo/effects/index.d.ts +15 -0
  62. package/dist/blocks/babylon/demo/effects/index.d.ts.map +1 -0
  63. package/dist/blocks/babylon/demo/effects/index.js +15 -0
  64. package/dist/blocks/babylon/demo/effects/index.js.map +1 -0
  65. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts +58 -0
  66. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.d.ts.map +1 -0
  67. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js +158 -0
  68. package/dist/blocks/babylon/demo/effects/kaleidoscopeBlock.js.map +1 -0
  69. package/dist/blocks/babylon/demo/effects/maskBlock.block.d.ts +38 -0
  70. package/dist/blocks/babylon/demo/effects/maskBlock.block.d.ts.map +1 -0
  71. package/dist/blocks/babylon/demo/effects/maskBlock.block.js +110 -0
  72. package/dist/blocks/babylon/demo/effects/maskBlock.block.js.map +1 -0
  73. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts +44 -0
  74. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.d.ts.map +1 -0
  75. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js +125 -0
  76. package/dist/blocks/babylon/demo/effects/pixelateBlock.block.js.map +1 -0
  77. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts +39 -0
  78. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.d.ts.map +1 -0
  79. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js +116 -0
  80. package/dist/blocks/babylon/demo/effects/posterizeBlock.block.js.map +1 -0
  81. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts +77 -0
  82. package/dist/blocks/babylon/demo/effects/spritesheetBlock.d.ts.map +1 -0
  83. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts +18 -0
  84. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.d.ts.map +1 -0
  85. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js +58 -0
  86. package/dist/blocks/babylon/demo/effects/spritesheetBlock.fragment.js.map +1 -0
  87. package/dist/blocks/babylon/demo/effects/spritesheetBlock.js +98 -0
  88. package/dist/blocks/babylon/demo/effects/spritesheetBlock.js.map +1 -0
  89. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts +7 -0
  90. package/dist/blocks/babylon/demo/effects/tintBlock.d.ts.map +1 -0
  91. package/dist/blocks/babylon/demo/effects/tintBlock.js +51 -0
  92. package/dist/blocks/babylon/demo/effects/tintBlock.js.map +1 -0
  93. package/dist/blocks/babylon/demo/transitions/index.d.ts +2 -0
  94. package/dist/blocks/babylon/demo/transitions/index.d.ts.map +1 -0
  95. package/dist/blocks/babylon/demo/transitions/index.js +2 -0
  96. package/dist/blocks/babylon/demo/transitions/index.js.map +1 -0
  97. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.d.ts +42 -0
  98. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.d.ts.map +1 -0
  99. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js +116 -0
  100. package/dist/blocks/babylon/demo/transitions/wipeBlock.block.js.map +1 -0
  101. package/dist/blocks/babylon/demo/utilities/index.d.ts +2 -0
  102. package/dist/blocks/babylon/demo/utilities/index.d.ts.map +1 -0
  103. package/dist/blocks/babylon/demo/utilities/index.js +2 -0
  104. package/dist/blocks/babylon/demo/utilities/index.js.map +1 -0
  105. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.d.ts +34 -0
  106. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.d.ts.map +1 -0
  107. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js +97 -0
  108. package/dist/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.js.map +1 -0
  109. package/dist/blocks/blockNamespaces.d.ts +5 -0
  110. package/dist/blocks/blockNamespaces.d.ts.map +1 -0
  111. package/dist/blocks/blockNamespaces.js +5 -0
  112. package/dist/blocks/blockNamespaces.js.map +1 -0
  113. package/dist/blocks/blockTypes.d.ts +22 -0
  114. package/dist/blocks/blockTypes.d.ts.map +1 -0
  115. package/dist/blocks/blockTypes.js +22 -0
  116. package/dist/blocks/blockTypes.js.map +1 -0
  117. package/dist/blocks/index.d.ts +6 -0
  118. package/dist/blocks/index.d.ts.map +1 -0
  119. package/dist/blocks/index.js +6 -0
  120. package/dist/blocks/index.js.map +1 -0
  121. package/dist/index.d.ts +3 -0
  122. package/dist/index.d.ts.map +1 -0
  123. package/dist/index.js +3 -0
  124. package/dist/index.js.map +1 -0
  125. package/dist/registration/IBlockRegistration.d.ts +34 -0
  126. package/dist/registration/IBlockRegistration.d.ts.map +1 -0
  127. package/dist/registration/IBlockRegistration.js +2 -0
  128. package/dist/registration/IBlockRegistration.js.map +1 -0
  129. package/dist/registration/blockSerializers.d.ts +13 -0
  130. package/dist/registration/blockSerializers.d.ts.map +1 -0
  131. package/dist/registration/blockSerializers.js +35 -0
  132. package/dist/registration/blockSerializers.js.map +1 -0
  133. package/dist/registration/builtInBlockRegistrations.d.ts +13 -0
  134. package/dist/registration/builtInBlockRegistrations.d.ts.map +1 -0
  135. package/dist/registration/builtInBlockRegistrations.js +269 -0
  136. package/dist/registration/builtInBlockRegistrations.js.map +1 -0
  137. package/dist/registration/index.d.ts +3 -0
  138. package/dist/registration/index.d.ts.map +1 -0
  139. package/dist/registration/index.js +3 -0
  140. package/dist/registration/index.js.map +1 -0
  141. package/license.md +21 -0
  142. package/package.json +52 -0
  143. package/readme.md +7 -0
  144. package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.glsl +18 -0
  145. package/src/blocks/babylon/demo/effects/blackAndWhiteBlock.block.ts +133 -0
  146. package/src/blocks/babylon/demo/effects/blurBlock.deserializer.ts +37 -0
  147. package/src/blocks/babylon/demo/effects/blurBlock.serializer.ts +31 -0
  148. package/src/blocks/babylon/demo/effects/blurBlock.ts +122 -0
  149. package/src/blocks/babylon/demo/effects/compositionBlock.deserializer.ts +31 -0
  150. package/src/blocks/babylon/demo/effects/compositionBlock.fragment.glsl +38 -0
  151. package/src/blocks/babylon/demo/effects/compositionBlock.fragment.ts +71 -0
  152. package/src/blocks/babylon/demo/effects/compositionBlock.serializer.ts +28 -0
  153. package/src/blocks/babylon/demo/effects/compositionBlock.ts +243 -0
  154. package/src/blocks/babylon/demo/effects/contrastBlock.block.glsl +36 -0
  155. package/src/blocks/babylon/demo/effects/contrastBlock.block.ts +180 -0
  156. package/src/blocks/babylon/demo/effects/desaturateBlock.block.glsl +24 -0
  157. package/src/blocks/babylon/demo/effects/desaturateBlock.block.ts +155 -0
  158. package/src/blocks/babylon/demo/effects/directionalBlurBlock.deserializer.ts +46 -0
  159. package/src/blocks/babylon/demo/effects/directionalBlurBlock.serializer.ts +30 -0
  160. package/src/blocks/babylon/demo/effects/directionalBlurBlock.ts +196 -0
  161. package/src/blocks/babylon/demo/effects/exposureBlock.block.glsl +15 -0
  162. package/src/blocks/babylon/demo/effects/exposureBlock.block.ts +142 -0
  163. package/src/blocks/babylon/demo/effects/greenScreenBlock.block.glsl +23 -0
  164. package/src/blocks/babylon/demo/effects/greenScreenBlock.block.ts +174 -0
  165. package/src/blocks/babylon/demo/effects/index.ts +14 -0
  166. package/src/blocks/babylon/demo/effects/kaleidoscopeBlock.ts +192 -0
  167. package/src/blocks/babylon/demo/effects/maskBlock.block.glsl +18 -0
  168. package/src/blocks/babylon/demo/effects/maskBlock.block.ts +145 -0
  169. package/src/blocks/babylon/demo/effects/pixelateBlock.block.glsl +28 -0
  170. package/src/blocks/babylon/demo/effects/pixelateBlock.block.ts +169 -0
  171. package/src/blocks/babylon/demo/effects/posterizeBlock.block.glsl +25 -0
  172. package/src/blocks/babylon/demo/effects/posterizeBlock.block.ts +156 -0
  173. package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.glsl +26 -0
  174. package/src/blocks/babylon/demo/effects/spritesheetBlock.fragment.ts +60 -0
  175. package/src/blocks/babylon/demo/effects/spritesheetBlock.ts +138 -0
  176. package/src/blocks/babylon/demo/effects/tintBlock.ts +51 -0
  177. package/src/blocks/babylon/demo/transitions/index.ts +1 -0
  178. package/src/blocks/babylon/demo/transitions/wipeBlock.block.glsl +11 -0
  179. package/src/blocks/babylon/demo/transitions/wipeBlock.block.ts +152 -0
  180. package/src/blocks/babylon/demo/utilities/index.ts +1 -0
  181. package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.glsl +14 -0
  182. package/src/blocks/babylon/demo/utilities/premultiplyAlphaBlock.block.ts +129 -0
  183. package/src/blocks/blockNamespaces.ts +4 -0
  184. package/src/blocks/blockTypes.ts +21 -0
  185. package/src/blocks/index.ts +5 -0
  186. package/src/index.ts +2 -0
  187. package/src/registration/IBlockRegistration.ts +43 -0
  188. package/src/registration/blockSerializers.ts +52 -0
  189. package/src/registration/builtInBlockRegistrations.ts +397 -0
  190. package/src/registration/index.ts +2 -0
@@ -0,0 +1,180 @@
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 "@babylonjs/core/Materials/effect";
12
+
13
+ import {
14
+ DisableableShaderBinding,
15
+ type RuntimeData,
16
+ ConnectionPointType,
17
+ type SmartFilter,
18
+ DisableableShaderBlock,
19
+ type ShaderProgram,
20
+ createStrongRef,
21
+ type IDisableableBlock,
22
+ BlockDisableStrategy} from "@babylonjs/smart-filters";
23
+
24
+ /**
25
+ * The shader program for the block.
26
+ */
27
+ const shaderProgram: ShaderProgram = {
28
+ vertex: undefined,
29
+ fragment: {
30
+ uniform: `
31
+ uniform sampler2D _input_; // main
32
+ uniform float _intensity_;`,
33
+ mainInputTexture: "_input_",
34
+ mainFunctionName: "_contrast_",
35
+ functions: [
36
+ {
37
+ name: "_contrast_",
38
+ code: `
39
+ vec4 _contrast_(vec2 vUV) {
40
+ vec4 color = texture2D(_input_, vUV);
41
+
42
+ float contrastLMin = mix(-2., 0., _intensity_ * 2.0);
43
+ float contrastLMax = mix(3., 1., _intensity_ * 2.0);
44
+
45
+ vec3 contrastMin = _remap_(color.rgb, contrastLMin, contrastLMax, 0., 1.);
46
+
47
+ float intensityMapped = _remap_(_intensity_, 0.5, 1., 0., 1.0);
48
+ float contrastHMin = mix(0., 0.45, intensityMapped);
49
+ float contrastHMax = mix(1., 0.5, intensityMapped);
50
+
51
+ vec3 contrastMax = _remap_(color.rgb, contrastHMin, contrastHMax, 0., 1.);
52
+
53
+ return vec4(mix(contrastMin, contrastMax, step(_intensity_, 0.5)), color.a);
54
+ }
55
+
56
+ `,
57
+ params: "vec2 vUV",
58
+ },
59
+ {
60
+ name: "_remap_",
61
+ code: `
62
+ float _remap_(float i, float smin, float smax, float dmin, float dmax) {
63
+ return dmin + (i - smin) * (dmax - dmin) / (smax - smin);
64
+ }
65
+
66
+ `,
67
+ params: "float i, float smin, float smax, float dmin, float dmax",
68
+ },
69
+ {
70
+ name: "_remap_",
71
+ code: `
72
+ vec3 _remap_(vec3 i, float smin, float smax, float dmin, float dmax) {
73
+ return dmin + (i - smin) * (dmax - dmin) / (smax - smin);
74
+ }
75
+
76
+ `,
77
+ params: "vec3 i, float smin, float smax, float dmin, float dmax",
78
+ },
79
+ ],
80
+ },
81
+ };
82
+
83
+ /**
84
+ * The uniform names for this shader, to be used in the shader binding so
85
+ * that the names are always in sync.
86
+ */
87
+ const uniforms = {
88
+ input: "input",
89
+ intensity: "intensity",
90
+ };
91
+
92
+ /**
93
+ * The shader binding for the ContrastBlock, used by the runtime
94
+ */
95
+ class ContrastBlockShaderBinding extends DisableableShaderBinding {
96
+ private readonly _input: RuntimeData<ConnectionPointType.Texture>;
97
+ private readonly _intensity: RuntimeData<ConnectionPointType.Float>;
98
+
99
+ /**
100
+ * Creates a new shader binding instance for the block.
101
+ * @param parentBlock - IDisableableBlock
102
+ * @param input - The input runtime value
103
+ * @param intensity - The intensity runtime value
104
+ */
105
+ constructor(
106
+ parentBlock: IDisableableBlock,
107
+ input: RuntimeData<ConnectionPointType.Texture>,
108
+ intensity: RuntimeData<ConnectionPointType.Float>
109
+ ) {
110
+ super(parentBlock);
111
+ this._input = input;
112
+ this._intensity = intensity;
113
+ }
114
+
115
+ /**
116
+ * Binds all the required data to the shader when rendering.
117
+ * @param effect - defines the effect to bind the data to
118
+ */
119
+ public override bind(effect: Effect): void {
120
+ super.bind(effect);
121
+ effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
122
+ effect.setFloat(this.getRemappedName(uniforms.intensity), this._intensity.value);
123
+ }
124
+ }
125
+
126
+ /**
127
+ * The implementation of the ContrastBlock
128
+ */
129
+ export class ContrastBlock extends DisableableShaderBlock {
130
+ /**
131
+ * The class name of the block.
132
+ */
133
+ public static override ClassName = "ContrastBlock";
134
+
135
+ /**
136
+ * The namespace of the block.
137
+ */
138
+ public static override Namespace = "Babylon.Demo.Effects";
139
+
140
+ /**
141
+ * The input connection point.
142
+ */
143
+ public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
144
+
145
+ /**
146
+ /**
147
+ * The intensity connection point.
148
+ */
149
+ public readonly intensity = this._registerOptionalInput(
150
+ "intensity",
151
+ ConnectionPointType.Float,
152
+ createStrongRef(0.5)
153
+ );
154
+
155
+ /**
156
+ * The shader program (vertex and fragment code) to use to render the block
157
+ */
158
+ public static override ShaderCode = shaderProgram;
159
+
160
+ /**
161
+ * Instantiates a new ContrastBlock.
162
+ * @param smartFilter - The smart filter this block belongs to
163
+ * @param name - The friendly name of the block
164
+ */
165
+ constructor(smartFilter: SmartFilter, name: string) {
166
+ super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
167
+ }
168
+
169
+ /**
170
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
171
+ * @returns The class instance that binds the data to the effect
172
+ */
173
+ public getShaderBinding(): DisableableShaderBinding {
174
+ const input = this._confirmRuntimeDataSupplied(this.input);
175
+ const intensity = this._confirmRuntimeDataSupplied(this.intensity);
176
+
177
+ return new ContrastBlockShaderBinding(this,input,intensity);
178
+ }
179
+ }
180
+
@@ -0,0 +1,24 @@
1
+ /*
2
+ {
3
+ "smartFilterBlockType": "DesaturateBlock",
4
+ "namespace": "Babylon.Demo.Effects",
5
+ "blockDisableStrategy": "AutoSample"
6
+ }
7
+ */
8
+
9
+ uniform sampler2D input; // main
10
+ // { "default": 0.3 }
11
+ uniform float intensity;
12
+
13
+ vec4 desaturate(vec2 vUV) { // main
14
+ float saturationStrength = 1. - intensity;
15
+
16
+ vec4 color = texture2D(input, vUV);
17
+
18
+ float tempMin = min(min(color.x, color.y), color.z);
19
+ float tempMax = max(max(color.x, color.y), color.z);
20
+ float tempMerge = 0.5 * (tempMin + tempMax);
21
+
22
+ return vec4(mix(color.rgb, vec3(tempMerge, tempMerge, tempMerge), saturationStrength), color.a);
23
+ }
24
+
@@ -0,0 +1,155 @@
1
+ /* eslint-disable prettier/prettier */
2
+ // ************************************************************
3
+ // Note: this file is auto-generated, do not modify it directly
4
+ // ************************************************************
5
+
6
+ // It was generated by convertGlslIntoBlock() from
7
+ // an annotated .glsl file. Modify the .glsl file to make changes
8
+ // to the block. This file will get overwritten when the build
9
+ // is run or during a watch when the .glsl file is updated.
10
+
11
+ import type { Effect } from "@babylonjs/core/Materials/effect";
12
+
13
+ import {
14
+ DisableableShaderBinding,
15
+ type RuntimeData,
16
+ ConnectionPointType,
17
+ type SmartFilter,
18
+ DisableableShaderBlock,
19
+ type ShaderProgram,
20
+ createStrongRef,
21
+ type IDisableableBlock,
22
+ BlockDisableStrategy} from "@babylonjs/smart-filters";
23
+
24
+ /**
25
+ * The shader program for the block.
26
+ */
27
+ const shaderProgram: ShaderProgram = {
28
+ vertex: undefined,
29
+ fragment: {
30
+ uniform: `
31
+ uniform sampler2D _input_; // main
32
+ uniform float _intensity_;`,
33
+ mainInputTexture: "_input_",
34
+ mainFunctionName: "_desaturate_",
35
+ functions: [
36
+ {
37
+ name: "_desaturate_",
38
+ code: `
39
+ vec4 _desaturate_(vec2 vUV) {
40
+ float saturationStrength = 1. - _intensity_;
41
+
42
+ vec4 color = texture2D(_input_, vUV);
43
+
44
+ float tempMin = min(min(color.x, color.y), color.z);
45
+ float tempMax = max(max(color.x, color.y), color.z);
46
+ float tempMerge = 0.5 * (tempMin + tempMax);
47
+
48
+ return vec4(mix(color.rgb, vec3(tempMerge, tempMerge, tempMerge), saturationStrength), color.a);
49
+ }
50
+
51
+ `,
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
+ };
66
+
67
+ /**
68
+ * The shader binding for the DesaturateBlock, used by the runtime
69
+ */
70
+ class DesaturateBlockShaderBinding extends DisableableShaderBinding {
71
+ private readonly _input: RuntimeData<ConnectionPointType.Texture>;
72
+ private readonly _intensity: RuntimeData<ConnectionPointType.Float>;
73
+
74
+ /**
75
+ * Creates a new shader binding instance for the block.
76
+ * @param parentBlock - IDisableableBlock
77
+ * @param input - The input runtime value
78
+ * @param intensity - The intensity runtime value
79
+ */
80
+ constructor(
81
+ parentBlock: IDisableableBlock,
82
+ input: RuntimeData<ConnectionPointType.Texture>,
83
+ intensity: RuntimeData<ConnectionPointType.Float>
84
+ ) {
85
+ super(parentBlock);
86
+ this._input = input;
87
+ this._intensity = intensity;
88
+ }
89
+
90
+ /**
91
+ * Binds all the required data to the shader when rendering.
92
+ * @param effect - defines the effect to bind the data to
93
+ */
94
+ public override bind(effect: Effect): void {
95
+ super.bind(effect);
96
+ effect.setTexture(this.getRemappedName(uniforms.input), this._input.value);
97
+ effect.setFloat(this.getRemappedName(uniforms.intensity), this._intensity.value);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * The implementation of the DesaturateBlock
103
+ */
104
+ export class DesaturateBlock extends DisableableShaderBlock {
105
+ /**
106
+ * The class name of the block.
107
+ */
108
+ public static override ClassName = "DesaturateBlock";
109
+
110
+ /**
111
+ * The namespace of the block.
112
+ */
113
+ public static override Namespace = "Babylon.Demo.Effects";
114
+
115
+ /**
116
+ * The input connection point.
117
+ */
118
+ public readonly input = this._registerInput(uniforms.input, ConnectionPointType.Texture);
119
+
120
+ /**
121
+ /**
122
+ * The intensity connection point.
123
+ */
124
+ public readonly intensity = this._registerOptionalInput(
125
+ "intensity",
126
+ ConnectionPointType.Float,
127
+ createStrongRef(0.3)
128
+ );
129
+
130
+ /**
131
+ * The shader program (vertex and fragment code) to use to render the block
132
+ */
133
+ public static override ShaderCode = shaderProgram;
134
+
135
+ /**
136
+ * Instantiates a new DesaturateBlock.
137
+ * @param smartFilter - The smart filter this block belongs to
138
+ * @param name - The friendly name of the block
139
+ */
140
+ constructor(smartFilter: SmartFilter, name: string) {
141
+ super(smartFilter, name, false, BlockDisableStrategy.AutoSample);
142
+ }
143
+
144
+ /**
145
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
146
+ * @returns The class instance that binds the data to the effect
147
+ */
148
+ public getShaderBinding(): DisableableShaderBinding {
149
+ const input = this._confirmRuntimeDataSupplied(this.input);
150
+ const intensity = this._confirmRuntimeDataSupplied(this.intensity);
151
+
152
+ return new DesaturateBlockShaderBinding(this,input,intensity);
153
+ }
154
+ }
155
+
@@ -0,0 +1,46 @@
1
+ import type { ISerializedBlockV1, SmartFilter } from "@babylonjs/smart-filters";
2
+ import { DirectionalBlurBlock } from "./directionalBlurBlock.js";
3
+
4
+ /**
5
+ * The definition of the extra data serialized for directional blur blocks.
6
+ */
7
+ export interface ISerializedDirectionalBlurBlockV1 extends ISerializedBlockV1 {
8
+ /**
9
+ * The extra data of the block.
10
+ */
11
+ data: {
12
+ /**
13
+ * The horizontal width of the blur.
14
+ */
15
+ blurHorizontalWidth: number;
16
+
17
+ /**
18
+ * The vertical width of the blur.
19
+ */
20
+ blurVerticalWidth: number;
21
+
22
+ /**
23
+ * The blur texture ratio.
24
+ */
25
+ blurTextureRatio: number;
26
+ };
27
+ }
28
+
29
+ /**
30
+ * V1 Directional Blur Deserializer.
31
+ * @param smartFilter - The SmartFilter to deserialize the block into
32
+ * @param serializedBlock - The serialized block data
33
+ * @returns A deserialized DirectionalBlurBlock
34
+ */
35
+ export function directionalBlurDeserializer(
36
+ smartFilter: SmartFilter,
37
+ serializedBlock: ISerializedDirectionalBlurBlockV1
38
+ ) {
39
+ const block = new DirectionalBlurBlock(smartFilter, serializedBlock.name);
40
+
41
+ // If data is missing, use the default value set by the block
42
+ block.blurHorizontalWidth = serializedBlock.data.blurHorizontalWidth ?? block.blurHorizontalWidth;
43
+ block.blurVerticalWidth = serializedBlock.data.blurVerticalWidth ?? block.blurVerticalWidth;
44
+ block.blurTextureRatio = serializedBlock.data.blurTextureRatio ?? block.blurTextureRatio;
45
+ return block;
46
+ }
@@ -0,0 +1,30 @@
1
+ import type { IBlockSerializerV1, BaseBlock } from "@babylonjs/smart-filters";
2
+ import type { DirectionalBlurBlock } from "./directionalBlurBlock";
3
+ import { directionalBlurBlockType } from "../../../blockTypes.js";
4
+ import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
5
+
6
+ /**
7
+ * The V1 serializer for a Directional Blur Block
8
+ */
9
+ export const directionalBlurBlockSerializer: IBlockSerializerV1 = {
10
+ blockType: directionalBlurBlockType,
11
+ serialize: (block: BaseBlock) => {
12
+ if (block.getClassName() !== directionalBlurBlockType) {
13
+ throw new Error("Was asked to serialize an unrecognized block type");
14
+ }
15
+
16
+ const directionalBlurBlock = block as DirectionalBlurBlock;
17
+ return {
18
+ name: block.name,
19
+ uniqueId: block.uniqueId,
20
+ blockType: directionalBlurBlockType,
21
+ namespace: babylonDemoEffectsNamespace,
22
+ comments: block.comments,
23
+ data: {
24
+ blurTextureRatio: directionalBlurBlock.blurTextureRatio,
25
+ blurHorizontalWidth: directionalBlurBlock.blurHorizontalWidth,
26
+ blurVerticalWidth: directionalBlurBlock.blurVerticalWidth,
27
+ },
28
+ };
29
+ },
30
+ };
@@ -0,0 +1,196 @@
1
+ import type { Effect } from "@babylonjs/core/Materials/effect";
2
+
3
+ import {
4
+ type ShaderProgram,
5
+ type RuntimeData,
6
+ ConnectionPointType,
7
+ type SmartFilter,
8
+ editableInPropertyPage,
9
+ PropertyTypeForEdition,
10
+ ShaderBinding,
11
+ ShaderBlock,
12
+ } from "@babylonjs/smart-filters";
13
+
14
+ import { directionalBlurBlockType } from "../../../blockTypes.js";
15
+ import { babylonDemoEffectsNamespace } from "../../../blockNamespaces.js";
16
+
17
+ const shaderProgram: ShaderProgram = {
18
+ fragment: {
19
+ const: `
20
+ const float _epsilon_ = 0.01;
21
+ `,
22
+ uniform: `
23
+ uniform vec2 _texelStep_;
24
+ uniform sampler2D _input_;
25
+ `,
26
+
27
+ uniformSingle: `
28
+ uniform float[7] _weights_;
29
+ `,
30
+
31
+ mainFunctionName: "_directionalBlur_",
32
+
33
+ mainInputTexture: "_input_",
34
+
35
+ functions: [
36
+ {
37
+ name: "_directionalBlur_",
38
+ code: `
39
+ vec4 _directionalBlur_(vec2 vUV) {
40
+ vec2 start = vUV - 3.0 * _texelStep_;
41
+
42
+ vec4 finalWeightedColor = vec4(0., 0., 0., 0.);
43
+
44
+ for (int i = 0; i < 7; i++)
45
+ {
46
+ vec2 fetchUV = start + _texelStep_ * float(i);
47
+ fetchUV = clamp(fetchUV, 0., 1.);
48
+ vec4 colorSample = texture2D(_input_, fetchUV);
49
+
50
+ // Ignore samples from mostly transparent pixels
51
+ if (colorSample.a < _epsilon_) continue;
52
+
53
+ finalWeightedColor += colorSample * _weights_[i];
54
+ }
55
+
56
+ return finalWeightedColor;
57
+ }
58
+ `,
59
+ },
60
+ ],
61
+ },
62
+ };
63
+
64
+ const wideWeights = Float32Array.from([0.05, 0.1, 0.2, 0.3, 0.2, 0.1, 0.05]);
65
+
66
+ /**
67
+ * The shader bindings for the DirectionalBlur block.
68
+ */
69
+ export class DirectionalBlurShaderBinding extends ShaderBinding {
70
+ private readonly _inputTexture: RuntimeData<ConnectionPointType.Texture>;
71
+ private readonly _blurHorizontalWidth: number;
72
+ private readonly _blurVerticalWidth: number;
73
+
74
+ /**
75
+ * Creates a new shader binding instance for the DirectionalBlur block.
76
+ * @param inputTexture - The input texture
77
+ * @param blurHorizontalWidth - The horizontal blur width
78
+ * @param blurVerticalWidth - The vertical blur width
79
+ */
80
+ constructor(
81
+ inputTexture: RuntimeData<ConnectionPointType.Texture>,
82
+ blurHorizontalWidth: number,
83
+ blurVerticalWidth: number
84
+ ) {
85
+ super();
86
+ this._inputTexture = inputTexture;
87
+ this._blurHorizontalWidth = blurHorizontalWidth;
88
+ this._blurVerticalWidth = blurVerticalWidth;
89
+ }
90
+
91
+ /**
92
+ * Binds all the required data to the shader when rendering.
93
+ * @param effect - defines the effect to bind the data to
94
+ */
95
+ public override bind(effect: Effect): void {
96
+ // Global pass Setup
97
+ effect.setFloatArray(this.getRemappedName("weights"), wideWeights);
98
+
99
+ // V blur
100
+ effect.setTexture(this.getRemappedName("input"), this._inputTexture.value);
101
+
102
+ // Texel size
103
+ if (this._inputTexture.value) {
104
+ const inputSize = this._inputTexture.value.getSize();
105
+ const texelWidth = this._blurHorizontalWidth / inputSize.width;
106
+ const texelHeight = this._blurVerticalWidth / inputSize.height;
107
+ effect.setFloat2(this.getRemappedName("texelStep"), texelWidth, texelHeight);
108
+ }
109
+ }
110
+ }
111
+
112
+ /**
113
+ * A block performing a directional "gaussian" blur.
114
+ *
115
+ * It is aggregated as part of the @see BlurBlock.
116
+ */
117
+ export class DirectionalBlurBlock extends ShaderBlock {
118
+ /**
119
+ * The class name of the block.
120
+ */
121
+ public static override ClassName = directionalBlurBlockType;
122
+
123
+ /**
124
+ * The namespace of the block.
125
+ */
126
+ public static override Namespace = babylonDemoEffectsNamespace;
127
+
128
+ /**
129
+ * The input texture connection point.
130
+ */
131
+ public readonly input = this._registerInput("input", ConnectionPointType.Texture);
132
+
133
+ /**
134
+ * Defines how smaller we should make the target compared to the screen size.
135
+ */
136
+ @editableInPropertyPage("Texture Ratio", PropertyTypeForEdition.Float, "PROPERTIES", {
137
+ min: 0,
138
+ max: 1,
139
+ notifiers: { rebuild: true },
140
+ })
141
+ public blurTextureRatio = 0.5;
142
+
143
+ /**
144
+ * Defines the horizontal strength of the blur.
145
+ */
146
+ @editableInPropertyPage("Horizontal strength", PropertyTypeForEdition.Float, "PROPERTIES", {
147
+ min: 0,
148
+ max: 1,
149
+ notifiers: { rebuild: true },
150
+ })
151
+ public blurHorizontalWidth = 0;
152
+
153
+ /**
154
+ * Defines the vertical strength of the blur.
155
+ */
156
+ @editableInPropertyPage("Vertical strength", PropertyTypeForEdition.Float, "PROPERTIES", {
157
+ min: 0,
158
+ max: 1,
159
+ notifiers: { rebuild: true },
160
+ })
161
+ public blurVerticalWidth = 1;
162
+
163
+ /**
164
+ * The shader program (vertex and fragment code) to use to render the block
165
+ */
166
+ public static override ShaderCode = shaderProgram;
167
+
168
+ /**
169
+ * Instantiates a new Block.
170
+ * @param smartFilter - The smart filter this block belongs to
171
+ * @param name - The friendly name of the block
172
+ */
173
+ constructor(smartFilter: SmartFilter, name: string) {
174
+ super(smartFilter, name, true);
175
+ }
176
+
177
+ /**
178
+ * Prepares the block for runtime.
179
+ * This is called by the smart filter just before creating the smart filter runtime.
180
+ */
181
+ public override prepareForRuntime(): void {
182
+ super.prepareForRuntime();
183
+
184
+ this.outputTextureOptions.ratio = this.blurTextureRatio;
185
+ }
186
+
187
+ /**
188
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
189
+ * @returns The class instance that binds the data to the effect
190
+ */
191
+ public getShaderBinding(): ShaderBinding {
192
+ const input = this._confirmRuntimeDataSupplied(this.input);
193
+
194
+ return new DirectionalBlurShaderBinding(input, this.blurHorizontalWidth, this.blurVerticalWidth);
195
+ }
196
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ {
3
+ "smartFilterBlockType": "ExposureBlock",
4
+ "namespace": "Babylon.Demo.Effects",
5
+ "blockDisableStrategy": "AutoSample"
6
+ }
7
+ */
8
+
9
+ uniform sampler2D input; // main
10
+ uniform float amount;
11
+
12
+ vec4 exposure(vec2 vUV) { // main
13
+ vec4 color = texture2D(input, vUV);
14
+ return vec4(color.rgb * amount, color.a);
15
+ }