gl-react-blur 2.0.1 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 - 2017 <renaudeau.gaetan@gmail.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,65 +1,22 @@
1
- # gl-react-blur ![](https://img.shields.io/npm/v/gl-react-blur.svg) ![](https://img.shields.io/badge/gl--react-3-05F561.svg) ![](https://img.shields.io/badge/gl--react-dom%20%7C%20native-f90.svg)
1
+ # gl-react-blur
2
2
 
3
- [Universal](https://projectseptemberinc.gitbooks.io/gl-react/content/docs/universal.html) gl-react **multi-pass gaussian Blur effect** with configurable intensity.
3
+ Universal [gl-react](https://github.com/gre/gl-react) multi-pass gaussian Blur effect with configurable intensity, also supporting variable blur with a map.
4
4
 
5
- ## `{Blur}` Props
6
-
7
- * `children` **(required)**: the content to blur.
8
- * `factor` **(required)**: positive number that control the blur intensity (independently from the viewport size).
9
- * `passes`: integer that controls the number of linear Blur passes. Default to 2. You better you an even number.
10
-
11
- More advanced...
12
-
13
- * `directionForPass`: function that gives the linear blur direction for a given pass. `(p, factor, total) => [ dx, dy ]`. Default to a function that do a _{ horizontal, vertical, diagonal 1, diagonal 2 }_ rotation with varying intensity.
14
-
15
- ## `{BlurV}` Props
16
-
17
- **BlurV** is a variant of **Blur** that allows to make **Variable** blur effect.
18
-
19
- It accepts one more prop:
20
-
21
- * `map` **(required)**: a texture that localize the blur intensity.
22
-
23
- ## Usage Examples
24
-
25
- ```js
26
- var Blur = require("gl-react-blur").Blur;
27
- // or
5
+ ```jsx
6
+ import { Surface } from "gl-react-dom"; // or gl-react-expo / gl-react-native / gl-react-headless
28
7
  import { Blur } from "gl-react-blur";
29
- ```
30
-
31
- ### Small blur on an image
32
-
33
- ```html
34
- <Blur factor={0.5} passes={2}>
35
- http://i.imgur.com/zJIxPEo.jpg
36
- </Blur>
37
- ```
38
8
 
39
- ### Medium blur on a video
40
-
41
- ```html
42
- <Blur factor={2} passes={4}>
43
- <video ... />
44
- </Blur>
9
+ <Surface width={400} height={300}>
10
+ <Blur factor={4} passes={4}>
11
+ {"https://i.imgur.com/iPKTONG.jpg"}
12
+ </Blur>
13
+ </Surface>;
45
14
  ```
46
15
 
47
- ### Powerful blur on another stack of effects
48
-
49
- ```html
50
- <Blur factor={20} passes={6}>
51
- <EffectA>
52
- <EffectB>
53
- ...
54
- </EffectB>
55
- </EffectA>
56
- </Blur>
57
- ```
16
+ ## Components
58
17
 
59
- ### Variable Blur
18
+ - **`<Blur factor passes? directionForPass?>`** — multi-pass gaussian blur. `factor` is the blur intensity in pixels; `passes` (default 2) trades performance for quality; `directionForPass(pass, factor, total)` can customize the direction vector of each pass (defaults to cycling horizontal, vertical and the two diagonals with increasing radius).
19
+ - **`<BlurV map ...>`** — same as `Blur` but the blur intensity varies per-pixel, scaled by the red/green channels of the `map` texture (e.g. for tilt-shift or depth-of-field effects).
20
+ - **`<Blur1D direction>`** / **`<BlurV1D direction map>`** — a single blur pass in one direction, the building blocks of the above.
60
21
 
61
- ```html
62
- <BlurV factor={3} passes={6} map="http://i.imgur.com/SzbbUvX.png">
63
- ...
64
- </BlurV>
65
- ```
22
+ The content to blur is given as `children` and can be any gl-react texture input (image URL, video, canvas, another Node, ...). All components accept optional `width`/`height` and otherwise inherit the size from their parent (via `connectSize`).
package/lib/Blur.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { DirectionForPass } from "./directionForPassDefault";
3
+ export type BlurProps = {
4
+ /** the content to blur: any gl-react texture input */
5
+ children: any;
6
+ /** blur intensity, in pixels */
7
+ factor: number;
8
+ /** number of Blur1D passes to run (default 2: horizontal + vertical) */
9
+ passes?: number;
10
+ /** direction vector of a given pass; defaults to cycling H, V and diagonals */
11
+ directionForPass?: DirectionForPass;
12
+ width?: number;
13
+ height?: number;
14
+ };
15
+ declare const Blur: React.ComponentType<BlurProps>;
16
+ export default Blur;
17
+ //# sourceMappingURL=Blur.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blur.d.ts","sourceRoot":"","sources":["../src/Blur.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAgC,EAC9B,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,SAAS,GAAG;IACtB,sDAAsD;IACtD,QAAQ,EAAE,GAAG,CAAC;IACd,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAGF,QAAA,MAAM,IAAI,EAiBM,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AAE/C,eAAe,IAAI,CAAC"}
package/lib/Blur.js CHANGED
@@ -3,63 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
- var _react = require("react");
8
-
9
- var _react2 = _interopRequireDefault(_react);
10
-
11
- var _propTypes = require("prop-types");
12
-
13
- var _propTypes2 = _interopRequireDefault(_propTypes);
14
-
15
- var _Blur1D = require("./Blur1D");
16
-
17
- var _Blur1D2 = _interopRequireDefault(_Blur1D);
18
-
19
- var _directionForPassDefault = require("./directionForPassDefault");
20
-
21
- var _directionForPassDefault2 = _interopRequireDefault(_directionForPassDefault);
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
25
- var Blur = function Blur(_ref) {
26
- var width = _ref.width,
27
- height = _ref.height,
28
- pixelRatio = _ref.pixelRatio,
29
- factor = _ref.factor,
30
- children = _ref.children,
31
- passes = _ref.passes,
32
- directionForPass = _ref.directionForPass;
33
-
34
- var rec = function rec(pass) {
35
- return pass <= 0 ? children : _react2.default.createElement(
36
- _Blur1D2.default,
37
- {
38
- width: width,
39
- height: height,
40
- pixelRatio: pixelRatio,
41
- direction: directionForPass(pass, factor, passes)
42
- },
43
- rec(pass - 1)
44
- );
45
- };
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _glReact = require("gl-react");
9
+ var _Blur1D = _interopRequireDefault(require("./Blur1D"));
10
+ var _directionForPassDefault = _interopRequireDefault(require("./directionForPassDefault"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ // Recursively nests Blur1D passes for multi-directional gaussian blur
13
+ const Blur = (0, _glReact.connectSize)(({
14
+ children,
15
+ factor,
16
+ passes = 2,
17
+ directionForPass = _directionForPassDefault.default
18
+ }) => {
19
+ const rec = pass => pass <= 0 ? children : /*#__PURE__*/_react.default.createElement(_Blur1D.default, {
20
+ direction: directionForPass(pass, factor, passes)
21
+ }, rec(pass - 1));
46
22
  return rec(passes);
47
- };
48
-
49
- Blur.defaultProps = {
50
- passes: 2,
51
- directionForPass: _directionForPassDefault2.default
52
- };
53
-
54
- Blur.propTypes = {
55
- factor: _propTypes2.default.number.isRequired,
56
- children: _propTypes2.default.any.isRequired,
57
- passes: _propTypes2.default.number,
58
- directionForPass: _propTypes2.default.func,
59
- width: _propTypes2.default.any,
60
- height: _propTypes2.default.any,
61
- pixelRatio: _propTypes2.default.number
62
- };
63
-
64
- exports.default = Blur;
23
+ });
24
+ var _default = exports.default = Blur;
65
25
  //# sourceMappingURL=Blur.js.map
package/lib/Blur.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Blur.js"],"names":["Blur","width","height","pixelRatio","factor","children","passes","directionForPass","rec","pass","defaultProps","directionForPassDefault","propTypes","PropTypes","number","isRequired","any","func"],"mappings":";;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;;;;;AAEA,IAAMA,OAAO,SAAPA,IAAO,OAQP;AAAA,MAPJC,KAOI,QAPJA,KAOI;AAAA,MANJC,MAMI,QANJA,MAMI;AAAA,MALJC,UAKI,QALJA,UAKI;AAAA,MAJJC,MAII,QAJJA,MAII;AAAA,MAHJC,QAGI,QAHJA,QAGI;AAAA,MAFJC,MAEI,QAFJA,MAEI;AAAA,MADJC,gBACI,QADJA,gBACI;;AACJ,MAAMC,MAAM,SAANA,GAAM;AAAA,WACVC,QAAQ,CAAR,GACEJ,QADF,GAGE;AAAC,sBAAD;AAAA;AACE,eAAOJ,KADT;AAEE,gBAAQC,MAFV;AAGE,oBAAYC,UAHd;AAIE,mBAAWI,iBAAiBE,IAAjB,EAAuBL,MAAvB,EAA+BE,MAA/B;AAJb;AAMGE,UAAIC,OAAO,CAAX;AANH,KAJQ;AAAA,GAAZ;AAaA,SAAOD,IAAIF,MAAJ,CAAP;AACD,CAvBD;;AAyBAN,KAAKU,YAAL,GAAoB;AAClBJ,UAAQ,CADU;AAElBC,oBAAkBI;AAFA,CAApB;;AAKAX,KAAKY,SAAL,GAAiB;AACfR,UAAQS,oBAAUC,MAAV,CAAiBC,UADV;AAEfV,YAAUQ,oBAAUG,GAAV,CAAcD,UAFT;AAGfT,UAAQO,oBAAUC,MAHH;AAIfP,oBAAkBM,oBAAUI,IAJb;AAKfhB,SAAOY,oBAAUG,GALF;AAMfd,UAAQW,oBAAUG,GANH;AAOfb,cAAYU,oBAAUC;AAPP,CAAjB;;kBAUed,I","file":"Blur.js","sourcesContent":["import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport Blur1D from \"./Blur1D\";\nimport directionForPassDefault from \"./directionForPassDefault\";\n\nconst Blur = ({\n width,\n height,\n pixelRatio,\n factor,\n children,\n passes,\n directionForPass\n}) => {\n const rec = pass =>\n pass <= 0 ? (\n children\n ) : (\n <Blur1D\n width={width}\n height={height}\n pixelRatio={pixelRatio}\n direction={directionForPass(pass, factor, passes)}\n >\n {rec(pass - 1)}\n </Blur1D>\n );\n return rec(passes);\n};\n\nBlur.defaultProps = {\n passes: 2,\n directionForPass: directionForPassDefault\n};\n\nBlur.propTypes = {\n factor: PropTypes.number.isRequired,\n children: PropTypes.any.isRequired,\n passes: PropTypes.number,\n directionForPass: PropTypes.func,\n width: PropTypes.any,\n height: PropTypes.any,\n pixelRatio: PropTypes.number\n};\n\nexport default Blur;\n"]}
1
+ {"version":3,"file":"Blur.js","names":["_react","_interopRequireDefault","require","_glReact","_Blur1D","_directionForPassDefault","e","__esModule","default","Blur","connectSize","children","factor","passes","directionForPass","directionForPassDefault","rec","pass","createElement","direction","_default","exports"],"sources":["../src/Blur.tsx"],"sourcesContent":["import React from \"react\";\nimport { connectSize } from \"gl-react\";\nimport Blur1D from \"./Blur1D\";\nimport directionForPassDefault, {\n DirectionForPass,\n} from \"./directionForPassDefault\";\n\nexport type BlurProps = {\n /** the content to blur: any gl-react texture input */\n children: any;\n /** blur intensity, in pixels */\n factor: number;\n /** number of Blur1D passes to run (default 2: horizontal + vertical) */\n passes?: number;\n /** direction vector of a given pass; defaults to cycling H, V and diagonals */\n directionForPass?: DirectionForPass;\n width?: number;\n height?: number;\n};\n\n// Recursively nests Blur1D passes for multi-directional gaussian blur\nconst Blur = connectSize(\n ({\n children,\n factor,\n passes = 2,\n directionForPass = directionForPassDefault,\n }: any) => {\n const rec = (pass: number): any =>\n pass <= 0 ? (\n children\n ) : (\n <Blur1D direction={directionForPass(pass, factor, passes)}>\n {rec(pass - 1)}\n </Blur1D>\n );\n return rec(passes);\n }\n) as unknown as React.ComponentType<BlurProps>;\n\nexport default Blur;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,wBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEmC,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAenC;AACA,MAAMG,IAAI,GAAG,IAAAC,oBAAW,EACtB,CAAC;EACCC,QAAQ;EACRC,MAAM;EACNC,MAAM,GAAG,CAAC;EACVC,gBAAgB,GAAGC;AAChB,CAAC,KAAK;EACT,MAAMC,GAAG,GAAIC,IAAY,IACvBA,IAAI,IAAI,CAAC,GACPN,QAAQ,gBAERX,MAAA,CAAAQ,OAAA,CAAAU,aAAA,CAACd,OAAA,CAAAI,OAAM;IAACW,SAAS,EAAEL,gBAAgB,CAACG,IAAI,EAAEL,MAAM,EAAEC,MAAM;EAAE,GACvDG,GAAG,CAACC,IAAI,GAAG,CAAC,CACP,CACT;EACH,OAAOD,GAAG,CAACH,MAAM,CAAC;AACpB,CACF,CAA8C;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAAb,OAAA,GAEhCC,IAAI","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ export type Blur1DProps = {
3
+ /** the content to blur: any gl-react texture input */
4
+ children: any;
5
+ /** blur direction & distance vector, in pixels */
6
+ direction: [number, number];
7
+ width?: number;
8
+ height?: number;
9
+ };
10
+ declare const Blur1D: React.ComponentType<Blur1DProps>;
11
+ export default Blur1D;
12
+ //# sourceMappingURL=Blur1D.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blur1D.d.ts","sourceRoot":"","sources":["../src/Blur1D.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA4B1B,MAAM,MAAM,WAAW,GAAG;IACxB,sDAAsD;IACtD,QAAQ,EAAE,GAAG,CAAC;IACd,kDAAkD;IAClD,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAGF,QAAA,MAAM,MAAM,EAOI,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;AAEjD,eAAe,MAAM,CAAC"}
package/lib/Blur1D.js CHANGED
@@ -3,49 +3,47 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
7
8
  var _glReact = require("gl-react");
8
-
9
- var _react = require("react");
10
-
11
- var _react2 = _interopRequireDefault(_react);
12
-
13
- var _propTypes = require("prop-types");
14
-
15
- var _propTypes2 = _interopRequireDefault(_propTypes);
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- var shaders = _glReact.Shaders.create({
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const shaders = _glReact.Shaders.create({
20
11
  blur1D: {
21
12
  // blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur
22
- frag: "precision highp float;\nvarying vec2 uv;\nuniform sampler2D t;\nuniform vec2 direction, resolution;\n\nvec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;\n color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;\n return color;\n}\n\nvoid main () {\n gl_FragColor = blur9(t, uv, resolution, direction);\n}"
13
+ frag: (0, _glReact.GLSL)`
14
+ precision highp float;
15
+ varying vec2 uv;
16
+ uniform sampler2D t;
17
+ uniform vec2 direction, resolution;
18
+ vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
19
+ vec4 color = vec4(0.0);
20
+ vec2 off1 = vec2(1.3846153846) * direction;
21
+ vec2 off2 = vec2(3.2307692308) * direction;
22
+ color += texture2D(image, uv) * 0.2270270270;
23
+ color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;
24
+ color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;
25
+ color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;
26
+ color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
27
+ return color;
28
+ }
29
+ void main() {
30
+ gl_FragColor = blur9(t, uv, resolution, direction);
31
+ }`
23
32
  }
24
33
  });
25
-
26
- var Blur1D = function Blur1D(_ref) {
27
- var width = _ref.width,
28
- height = _ref.height,
29
- pixelRatio = _ref.pixelRatio,
30
- direction = _ref.direction,
31
- t = _ref.children;
32
- return _react2.default.createElement(_glReact.Node, {
33
- shader: shaders.blur1D,
34
- width: width,
35
- height: height,
36
- pixelRatio: pixelRatio,
37
- uniforms: {
38
- direction: direction,
39
- resolution: _glReact.Uniform.Resolution,
40
- t: t
41
- }
42
- });
43
- };
44
-
45
- Blur1D.propTypes = {
46
- direction: _propTypes2.default.array.isRequired,
47
- children: _propTypes2.default.any.isRequired
48
- };
49
-
50
- exports.default = Blur1D;
34
+ // connectSize injects width/height for correct texel offset calculation
35
+ const Blur1D = (0, _glReact.connectSize)(({
36
+ children: t,
37
+ direction,
38
+ width,
39
+ height
40
+ }) => /*#__PURE__*/_react.default.createElement(_glReact.Node, {
41
+ shader: shaders.blur1D,
42
+ uniforms: {
43
+ t,
44
+ resolution: [width, height],
45
+ direction
46
+ }
47
+ }));
48
+ var _default = exports.default = Blur1D;
51
49
  //# sourceMappingURL=Blur1D.js.map
package/lib/Blur1D.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Blur1D.js"],"names":["shaders","Shaders","create","blur1D","frag","Blur1D","width","height","pixelRatio","direction","t","children","resolution","Uniform","Resolution","propTypes","PropTypes","array","isRequired","any"],"mappings":";;;;;;AAAA;;AACA;;;;AACA;;;;;;AAEA,IAAMA,UAAUC,iBAAQC,MAAR,CAAe;AAC7BC,UAAQ;AACN;AACAC;AAFM;AADqB,CAAf,CAAhB;;AA0BA,IAAMC,SAAS,SAATA,MAAS;AAAA,MAAGC,KAAH,QAAGA,KAAH;AAAA,MAAUC,MAAV,QAAUA,MAAV;AAAA,MAAkBC,UAAlB,QAAkBA,UAAlB;AAAA,MAA8BC,SAA9B,QAA8BA,SAA9B;AAAA,MAAmDC,CAAnD,QAAyCC,QAAzC;AAAA,SACb,8BAAC,aAAD;AACE,YAAQX,QAAQG,MADlB;AAEE,WAAOG,KAFT;AAGE,YAAQC,MAHV;AAIE,gBAAYC,UAJd;AAKE,cAAU;AACRC,0BADQ;AAERG,kBAAYC,iBAAQC,UAFZ;AAGRJ;AAHQ;AALZ,IADa;AAAA,CAAf;;AAcAL,OAAOU,SAAP,GAAmB;AACjBN,aAAWO,oBAAUC,KAAV,CAAgBC,UADV;AAEjBP,YAAUK,oBAAUG,GAAV,CAAcD;AAFP,CAAnB;;kBAKeb,M","file":"Blur1D.js","sourcesContent":["import { Shaders, Uniform, Node } from \"gl-react\";\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\nconst shaders = Shaders.create({\n blur1D: {\n // blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur\n frag: `precision highp float;\nvarying vec2 uv;\nuniform sampler2D t;\nuniform vec2 direction, resolution;\n\nvec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;\n color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;\n return color;\n}\n\nvoid main () {\n gl_FragColor = blur9(t, uv, resolution, direction);\n}`\n }\n});\n\nconst Blur1D = ({ width, height, pixelRatio, direction, children: t }) => (\n <Node\n shader={shaders.blur1D}\n width={width}\n height={height}\n pixelRatio={pixelRatio}\n uniforms={{\n direction,\n resolution: Uniform.Resolution,\n t\n }}\n />\n);\n\nBlur1D.propTypes = {\n direction: PropTypes.array.isRequired,\n children: PropTypes.any.isRequired\n};\n\nexport default Blur1D;\n"]}
1
+ {"version":3,"file":"Blur1D.js","names":["_react","_interopRequireDefault","require","_glReact","e","__esModule","default","shaders","Shaders","create","blur1D","frag","GLSL","Blur1D","connectSize","children","t","direction","width","height","createElement","Node","shader","uniforms","resolution","_default","exports"],"sources":["../src/Blur1D.tsx"],"sourcesContent":["import React from \"react\";\nimport { Shaders, Node, GLSL, connectSize } from \"gl-react\";\n\nconst shaders = Shaders.create({\n blur1D: {\n // blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur\n frag: GLSL`\nprecision highp float;\nvarying vec2 uv;\nuniform sampler2D t;\nuniform vec2 direction, resolution;\nvec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;\n color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;\n return color;\n}\nvoid main() {\n gl_FragColor = blur9(t, uv, resolution, direction);\n}`,\n },\n});\n\nexport type Blur1DProps = {\n /** the content to blur: any gl-react texture input */\n children: any;\n /** blur direction & distance vector, in pixels */\n direction: [number, number];\n width?: number;\n height?: number;\n};\n\n// connectSize injects width/height for correct texel offset calculation\nconst Blur1D = connectSize(\n ({ children: t, direction, width, height }: any) => (\n <Node\n shader={shaders.blur1D}\n uniforms={{ t, resolution: [width, height], direction }}\n />\n )\n) as unknown as React.ComponentType<Blur1DProps>;\n\nexport default Blur1D;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAA4D,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE5D,MAAMG,OAAO,GAAGC,gBAAO,CAACC,MAAM,CAAC;EAC7BC,MAAM,EAAE;IACN;IACAC,IAAI,EAAE,IAAAC,aAAI;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE;AACF,CAAC,CAAC;AAWF;AACA,MAAMC,MAAM,GAAG,IAAAC,oBAAW,EACxB,CAAC;EAAEC,QAAQ,EAAEC,CAAC;EAAEC,SAAS;EAAEC,KAAK;EAAEC;AAAY,CAAC,kBAC7CnB,MAAA,CAAAM,OAAA,CAAAc,aAAA,CAACjB,QAAA,CAAAkB,IAAI;EACHC,MAAM,EAAEf,OAAO,CAACG,MAAO;EACvBa,QAAQ,EAAE;IAAEP,CAAC;IAAEQ,UAAU,EAAE,CAACN,KAAK,EAAEC,MAAM,CAAC;IAAEF;EAAU;AAAE,CACzD,CAEL,CAAgD;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAApB,OAAA,GAElCO,MAAM","ignoreList":[]}
package/lib/BlurV.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { DirectionForPass } from "./directionForPassDefault";
3
+ export type BlurVProps = {
4
+ /** the content to blur: any gl-react texture input */
5
+ children: any;
6
+ /** blur intensity, in pixels */
7
+ factor: number;
8
+ /** a texture whose red/green channels scale the blur per-pixel */
9
+ map: any;
10
+ /** number of BlurV1D passes to run (default 2: horizontal + vertical) */
11
+ passes?: number;
12
+ /** direction vector of a given pass; defaults to cycling H, V and diagonals */
13
+ directionForPass?: DirectionForPass;
14
+ width?: number;
15
+ height?: number;
16
+ };
17
+ declare const BlurV: React.ComponentType<BlurVProps>;
18
+ export default BlurV;
19
+ //# sourceMappingURL=BlurV.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlurV.d.ts","sourceRoot":"","sources":["../src/BlurV.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAgC,EAC9B,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,UAAU,GAAG;IACvB,sDAAsD;IACtD,QAAQ,EAAE,GAAG,CAAC;IACd,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,GAAG,EAAE,GAAG,CAAC;IACT,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAGF,QAAA,MAAM,KAAK,EAkBK,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AAEhD,eAAe,KAAK,CAAC"}
package/lib/BlurV.js CHANGED
@@ -3,66 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
- var _react = require("react");
8
-
9
- var _react2 = _interopRequireDefault(_react);
10
-
11
- var _propTypes = require("prop-types");
12
-
13
- var _propTypes2 = _interopRequireDefault(_propTypes);
14
-
15
- var _BlurV1D = require("./BlurV1D");
16
-
17
- var _BlurV1D2 = _interopRequireDefault(_BlurV1D);
18
-
19
- var _directionForPassDefault = require("./directionForPassDefault");
20
-
21
- var _directionForPassDefault2 = _interopRequireDefault(_directionForPassDefault);
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
25
- var BlurV = function BlurV(_ref) {
26
- var width = _ref.width,
27
- height = _ref.height,
28
- map = _ref.map,
29
- pixelRatio = _ref.pixelRatio,
30
- factor = _ref.factor,
31
- children = _ref.children,
32
- passes = _ref.passes,
33
- directionForPass = _ref.directionForPass;
34
-
35
- var rec = function rec(pass) {
36
- return pass <= 0 ? children : _react2.default.createElement(
37
- _BlurV1D2.default,
38
- {
39
- width: width,
40
- height: height,
41
- map: map,
42
- pixelRatio: pixelRatio,
43
- direction: directionForPass(pass, factor, passes)
44
- },
45
- rec(pass - 1)
46
- );
47
- };
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _glReact = require("gl-react");
9
+ var _BlurV1D = _interopRequireDefault(require("./BlurV1D"));
10
+ var _directionForPassDefault = _interopRequireDefault(require("./directionForPassDefault"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ // Recursively nests BlurV1D passes for variable multi-directional blur
13
+ const BlurV = (0, _glReact.connectSize)(({
14
+ children,
15
+ factor,
16
+ map,
17
+ passes = 2,
18
+ directionForPass = _directionForPassDefault.default
19
+ }) => {
20
+ const rec = pass => pass <= 0 ? children : /*#__PURE__*/_react.default.createElement(_BlurV1D.default, {
21
+ map: map,
22
+ direction: directionForPass(pass, factor, passes)
23
+ }, rec(pass - 1));
48
24
  return rec(passes);
49
- };
50
-
51
- BlurV.defaultProps = {
52
- passes: 2,
53
- directionForPass: _directionForPassDefault2.default
54
- };
55
-
56
- BlurV.propTypes = {
57
- factor: _propTypes2.default.number.isRequired,
58
- children: _propTypes2.default.any.isRequired,
59
- passes: _propTypes2.default.number,
60
- directionForPass: _propTypes2.default.func,
61
- map: _propTypes2.default.any.isRequired,
62
- width: _propTypes2.default.any,
63
- height: _propTypes2.default.any,
64
- pixelRatio: _propTypes2.default.number
65
- };
66
-
67
- exports.default = BlurV;
25
+ });
26
+ var _default = exports.default = BlurV;
68
27
  //# sourceMappingURL=BlurV.js.map
package/lib/BlurV.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/BlurV.js"],"names":["BlurV","width","height","map","pixelRatio","factor","children","passes","directionForPass","rec","pass","defaultProps","directionForPassDefault","propTypes","PropTypes","number","isRequired","any","func"],"mappings":";;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;;;;;AAEA,IAAMA,QAAQ,SAARA,KAAQ,OASR;AAAA,MARJC,KAQI,QARJA,KAQI;AAAA,MAPJC,MAOI,QAPJA,MAOI;AAAA,MANJC,GAMI,QANJA,GAMI;AAAA,MALJC,UAKI,QALJA,UAKI;AAAA,MAJJC,MAII,QAJJA,MAII;AAAA,MAHJC,QAGI,QAHJA,QAGI;AAAA,MAFJC,MAEI,QAFJA,MAEI;AAAA,MADJC,gBACI,QADJA,gBACI;;AACJ,MAAMC,MAAM,SAANA,GAAM;AAAA,WACVC,QAAQ,CAAR,GACEJ,QADF,GAGE;AAAC,uBAAD;AAAA;AACE,eAAOL,KADT;AAEE,gBAAQC,MAFV;AAGE,aAAKC,GAHP;AAIE,oBAAYC,UAJd;AAKE,mBAAWI,iBAAiBE,IAAjB,EAAuBL,MAAvB,EAA+BE,MAA/B;AALb;AAOGE,UAAIC,OAAO,CAAX;AAPH,KAJQ;AAAA,GAAZ;AAcA,SAAOD,IAAIF,MAAJ,CAAP;AACD,CAzBD;;AA2BAP,MAAMW,YAAN,GAAqB;AACnBJ,UAAQ,CADW;AAEnBC,oBAAkBI;AAFC,CAArB;;AAKAZ,MAAMa,SAAN,GAAkB;AAChBR,UAAQS,oBAAUC,MAAV,CAAiBC,UADT;AAEhBV,YAAUQ,oBAAUG,GAAV,CAAcD,UAFR;AAGhBT,UAAQO,oBAAUC,MAHF;AAIhBP,oBAAkBM,oBAAUI,IAJZ;AAKhBf,OAAKW,oBAAUG,GAAV,CAAcD,UALH;AAMhBf,SAAOa,oBAAUG,GAND;AAOhBf,UAAQY,oBAAUG,GAPF;AAQhBb,cAAYU,oBAAUC;AARN,CAAlB;;kBAWef,K","file":"BlurV.js","sourcesContent":["import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport BlurV1D from \"./BlurV1D\";\nimport directionForPassDefault from \"./directionForPassDefault\";\n\nconst BlurV = ({\n width,\n height,\n map,\n pixelRatio,\n factor,\n children,\n passes,\n directionForPass\n}) => {\n const rec = pass =>\n pass <= 0 ? (\n children\n ) : (\n <BlurV1D\n width={width}\n height={height}\n map={map}\n pixelRatio={pixelRatio}\n direction={directionForPass(pass, factor, passes)}\n >\n {rec(pass - 1)}\n </BlurV1D>\n );\n return rec(passes);\n};\n\nBlurV.defaultProps = {\n passes: 2,\n directionForPass: directionForPassDefault\n};\n\nBlurV.propTypes = {\n factor: PropTypes.number.isRequired,\n children: PropTypes.any.isRequired,\n passes: PropTypes.number,\n directionForPass: PropTypes.func,\n map: PropTypes.any.isRequired,\n width: PropTypes.any,\n height: PropTypes.any,\n pixelRatio: PropTypes.number\n};\n\nexport default BlurV;\n"]}
1
+ {"version":3,"file":"BlurV.js","names":["_react","_interopRequireDefault","require","_glReact","_BlurV1D","_directionForPassDefault","e","__esModule","default","BlurV","connectSize","children","factor","map","passes","directionForPass","directionForPassDefault","rec","pass","createElement","direction","_default","exports"],"sources":["../src/BlurV.tsx"],"sourcesContent":["import React from \"react\";\nimport { connectSize } from \"gl-react\";\nimport BlurV1D from \"./BlurV1D\";\nimport directionForPassDefault, {\n DirectionForPass,\n} from \"./directionForPassDefault\";\n\nexport type BlurVProps = {\n /** the content to blur: any gl-react texture input */\n children: any;\n /** blur intensity, in pixels */\n factor: number;\n /** a texture whose red/green channels scale the blur per-pixel */\n map: any;\n /** number of BlurV1D passes to run (default 2: horizontal + vertical) */\n passes?: number;\n /** direction vector of a given pass; defaults to cycling H, V and diagonals */\n directionForPass?: DirectionForPass;\n width?: number;\n height?: number;\n};\n\n// Recursively nests BlurV1D passes for variable multi-directional blur\nconst BlurV = connectSize(\n ({\n children,\n factor,\n map,\n passes = 2,\n directionForPass = directionForPassDefault,\n }: any) => {\n const rec = (pass: number): any =>\n pass <= 0 ? (\n children\n ) : (\n <BlurV1D map={map} direction={directionForPass(pass, factor, passes)}>\n {rec(pass - 1)}\n </BlurV1D>\n );\n return rec(passes);\n }\n) as unknown as React.ComponentType<BlurVProps>;\n\nexport default BlurV;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,wBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEmC,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAiBnC;AACA,MAAMG,KAAK,GAAG,IAAAC,oBAAW,EACvB,CAAC;EACCC,QAAQ;EACRC,MAAM;EACNC,GAAG;EACHC,MAAM,GAAG,CAAC;EACVC,gBAAgB,GAAGC;AAChB,CAAC,KAAK;EACT,MAAMC,GAAG,GAAIC,IAAY,IACvBA,IAAI,IAAI,CAAC,GACPP,QAAQ,gBAERX,MAAA,CAAAQ,OAAA,CAAAW,aAAA,CAACf,QAAA,CAAAI,OAAO;IAACK,GAAG,EAAEA,GAAI;IAACO,SAAS,EAAEL,gBAAgB,CAACG,IAAI,EAAEN,MAAM,EAAEE,MAAM;EAAE,GAClEG,GAAG,CAACC,IAAI,GAAG,CAAC,CACN,CACV;EACH,OAAOD,GAAG,CAACH,MAAM,CAAC;AACpB,CACF,CAA+C;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAAd,OAAA,GAEjCC,KAAK","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ export type BlurV1DProps = {
3
+ /** the content to blur: any gl-react texture input */
4
+ children: any;
5
+ /** blur direction & distance vector, in pixels */
6
+ direction: [number, number];
7
+ /** a texture whose red/green channels scale the blur per-pixel */
8
+ map: any;
9
+ width?: number;
10
+ height?: number;
11
+ };
12
+ declare const BlurV1D: React.ComponentType<BlurV1DProps>;
13
+ export default BlurV1D;
14
+ //# sourceMappingURL=BlurV1D.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlurV1D.d.ts","sourceRoot":"","sources":["../src/BlurV1D.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA6B1B,MAAM,MAAM,YAAY,GAAG;IACzB,sDAAsD;IACtD,QAAQ,EAAE,GAAG,CAAC;IACd,kDAAkD;IAClD,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,kEAAkE;IAClE,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,QAAA,MAAM,OAAO,EAOG,KAAK,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;AAElD,eAAe,OAAO,CAAC"}
package/lib/BlurV1D.js CHANGED
@@ -3,52 +3,49 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
7
8
  var _glReact = require("gl-react");
8
-
9
- var _react = require("react");
10
-
11
- var _react2 = _interopRequireDefault(_react);
12
-
13
- var _propTypes = require("prop-types");
14
-
15
- var _propTypes2 = _interopRequireDefault(_propTypes);
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- var shaders = _glReact.Shaders.create({
20
- blur1D: {
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const shaders = _glReact.Shaders.create({
11
+ blurV1D: {
21
12
  // blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur
22
- frag: "precision highp float;\nvarying vec2 uv;\nuniform sampler2D t, map;\nuniform vec2 direction, resolution;\n\nvec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;\n color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;\n return color;\n}\n\nvoid main () {\n gl_FragColor = blur9(t, uv, resolution, direction * texture2D(map, uv).rg);\n}"
13
+ frag: (0, _glReact.GLSL)`
14
+ precision highp float;
15
+ varying vec2 uv;
16
+ uniform sampler2D t, map;
17
+ uniform vec2 direction, resolution;
18
+ vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
19
+ vec4 color = vec4(0.0);
20
+ vec2 off1 = vec2(1.3846153846) * direction;
21
+ vec2 off2 = vec2(3.2307692308) * direction;
22
+ color += texture2D(image, uv) * 0.2270270270;
23
+ color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;
24
+ color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;
25
+ color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;
26
+ color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
27
+ return color;
28
+ }
29
+ void main() {
30
+ // Direction scaled by map value makes blur strength vary per-pixel
31
+ gl_FragColor = blur9(t, uv, resolution, direction * texture2D(map, uv).rg);
32
+ }`
23
33
  }
24
34
  });
25
-
26
- var BlurV1D = function BlurV1D(_ref) {
27
- var width = _ref.width,
28
- height = _ref.height,
29
- map = _ref.map,
30
- pixelRatio = _ref.pixelRatio,
31
- direction = _ref.direction,
32
- t = _ref.children;
33
- return _react2.default.createElement(_glReact.Node, {
34
- shader: shaders.blur1D,
35
- width: width,
36
- height: height,
37
- pixelRatio: pixelRatio,
38
- uniforms: {
39
- direction: direction,
40
- resolution: _glReact.Uniform.Resolution,
41
- t: t,
42
- map: map
43
- }
44
- });
45
- };
46
-
47
- BlurV1D.propTypes = {
48
- direction: _propTypes2.default.array.isRequired,
49
- children: _propTypes2.default.any.isRequired,
50
- map: _propTypes2.default.any.isRequired
51
- };
52
-
53
- exports.default = BlurV1D;
35
+ const BlurV1D = (0, _glReact.connectSize)(({
36
+ children: t,
37
+ direction,
38
+ map,
39
+ width,
40
+ height
41
+ }) => /*#__PURE__*/_react.default.createElement(_glReact.Node, {
42
+ shader: shaders.blurV1D,
43
+ uniforms: {
44
+ t,
45
+ map,
46
+ resolution: [width, height],
47
+ direction
48
+ }
49
+ }));
50
+ var _default = exports.default = BlurV1D;
54
51
  //# sourceMappingURL=BlurV1D.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/BlurV1D.js"],"names":["shaders","Shaders","create","blur1D","frag","BlurV1D","width","height","map","pixelRatio","direction","t","children","resolution","Uniform","Resolution","propTypes","PropTypes","array","isRequired","any"],"mappings":";;;;;;AAAA;;AACA;;;;AACA;;;;;;AAEA,IAAMA,UAAUC,iBAAQC,MAAR,CAAe;AAC7BC,UAAQ;AACN;AACAC;AAFM;AADqB,CAAf,CAAhB;;AA0BA,IAAMC,UAAU,SAAVA,OAAU;AAAA,MACdC,KADc,QACdA,KADc;AAAA,MAEdC,MAFc,QAEdA,MAFc;AAAA,MAGdC,GAHc,QAGdA,GAHc;AAAA,MAIdC,UAJc,QAIdA,UAJc;AAAA,MAKdC,SALc,QAKdA,SALc;AAAA,MAMJC,CANI,QAMdC,QANc;AAAA,SAQd,8BAAC,aAAD;AACE,YAAQZ,QAAQG,MADlB;AAEE,WAAOG,KAFT;AAGE,YAAQC,MAHV;AAIE,gBAAYE,UAJd;AAKE,cAAU;AACRC,0BADQ;AAERG,kBAAYC,iBAAQC,UAFZ;AAGRJ,UAHQ;AAIRH;AAJQ;AALZ,IARc;AAAA,CAAhB;;AAsBAH,QAAQW,SAAR,GAAoB;AAClBN,aAAWO,oBAAUC,KAAV,CAAgBC,UADT;AAElBP,YAAUK,oBAAUG,GAAV,CAAcD,UAFN;AAGlBX,OAAKS,oBAAUG,GAAV,CAAcD;AAHD,CAApB;;kBAMed,O","file":"BlurV1D.js","sourcesContent":["import { Shaders, Uniform, Node } from \"gl-react\";\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\nconst shaders = Shaders.create({\n blur1D: {\n // blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur\n frag: `precision highp float;\nvarying vec2 uv;\nuniform sampler2D t, map;\nuniform vec2 direction, resolution;\n\nvec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;\n color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;\n return color;\n}\n\nvoid main () {\n gl_FragColor = blur9(t, uv, resolution, direction * texture2D(map, uv).rg);\n}`\n }\n});\n\nconst BlurV1D = ({\n width,\n height,\n map,\n pixelRatio,\n direction,\n children: t\n}) => (\n <Node\n shader={shaders.blur1D}\n width={width}\n height={height}\n pixelRatio={pixelRatio}\n uniforms={{\n direction,\n resolution: Uniform.Resolution,\n t,\n map\n }}\n />\n);\n\nBlurV1D.propTypes = {\n direction: PropTypes.array.isRequired,\n children: PropTypes.any.isRequired,\n map: PropTypes.any.isRequired\n};\n\nexport default BlurV1D;\n"]}
1
+ {"version":3,"file":"BlurV1D.js","names":["_react","_interopRequireDefault","require","_glReact","e","__esModule","default","shaders","Shaders","create","blurV1D","frag","GLSL","BlurV1D","connectSize","children","t","direction","map","width","height","createElement","Node","shader","uniforms","resolution","_default","exports"],"sources":["../src/BlurV1D.tsx"],"sourcesContent":["import React from \"react\";\nimport { Shaders, Node, GLSL, connectSize } from \"gl-react\";\n\nconst shaders = Shaders.create({\n blurV1D: {\n // blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur\n frag: GLSL`\nprecision highp float;\nvarying vec2 uv;\nuniform sampler2D t, map;\nuniform vec2 direction, resolution;\nvec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;\n color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;\n color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;\n return color;\n}\nvoid main() {\n // Direction scaled by map value makes blur strength vary per-pixel\n gl_FragColor = blur9(t, uv, resolution, direction * texture2D(map, uv).rg);\n}`,\n },\n});\n\nexport type BlurV1DProps = {\n /** the content to blur: any gl-react texture input */\n children: any;\n /** blur direction & distance vector, in pixels */\n direction: [number, number];\n /** a texture whose red/green channels scale the blur per-pixel */\n map: any;\n width?: number;\n height?: number;\n};\n\nconst BlurV1D = connectSize(\n ({ children: t, direction, map, width, height }: any) => (\n <Node\n shader={shaders.blurV1D}\n uniforms={{ t, map, resolution: [width, height], direction }}\n />\n )\n) as unknown as React.ComponentType<BlurV1DProps>;\n\nexport default BlurV1D;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAA4D,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE5D,MAAMG,OAAO,GAAGC,gBAAO,CAACC,MAAM,CAAC;EAC7BC,OAAO,EAAE;IACP;IACAC,IAAI,EAAE,IAAAC,aAAI;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE;AACF,CAAC,CAAC;AAaF,MAAMC,OAAO,GAAG,IAAAC,oBAAW,EACzB,CAAC;EAAEC,QAAQ,EAAEC,CAAC;EAAEC,SAAS;EAAEC,GAAG;EAAEC,KAAK;EAAEC;AAAY,CAAC,kBAClDpB,MAAA,CAAAM,OAAA,CAAAe,aAAA,CAAClB,QAAA,CAAAmB,IAAI;EACHC,MAAM,EAAEhB,OAAO,CAACG,OAAQ;EACxBc,QAAQ,EAAE;IAAER,CAAC;IAAEE,GAAG;IAAEO,UAAU,EAAE,CAACN,KAAK,EAAEC,MAAM,CAAC;IAAEH;EAAU;AAAE,CAC9D,CAEL,CAAiD;AAAC,IAAAS,QAAA,GAAAC,OAAA,CAAArB,OAAA,GAEnCO,OAAO","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export type DirectionForPass = (pass: number, factor: number, total: number) => [number, number];
2
+ declare const directionForPassDefault: DirectionForPass;
3
+ export default directionForPassDefault;
4
+ //# sourceMappingURL=directionForPassDefault.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directionForPassDefault.d.ts","sourceRoot":"","sources":["../src/directionForPassDefault.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,KACV,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAGtB,QAAA,MAAM,uBAAuB,EAAE,gBAY9B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
@@ -3,19 +3,21 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var NORM = Math.sqrt(2) / 2;
7
-
8
- exports.default = function (p, factor, total) {
9
- var f = factor * 2 * Math.ceil(p / 2) / total;
10
- switch ((p - 1) % 4) {// alternate horizontal, vertical and 2 diagonals
6
+ exports.default = void 0;
7
+ const NORM = Math.sqrt(2) / 2;
8
+ // Cycles through horizontal, vertical and the 2 diagonals with increasing radius
9
+ const directionForPassDefault = (p, factor, total) => {
10
+ const f = factor * 2 * Math.ceil(p / 2) / total;
11
+ switch ((p - 1) % 4) {
11
12
  case 0:
12
13
  return [f, 0];
13
14
  case 1:
14
15
  return [0, f];
15
16
  case 2:
16
17
  return [f * NORM, f * NORM];
17
- case 3:
18
+ default:
18
19
  return [f * NORM, -f * NORM];
19
20
  }
20
21
  };
22
+ var _default = exports.default = directionForPassDefault;
21
23
  //# sourceMappingURL=directionForPassDefault.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/directionForPassDefault.js"],"names":["NORM","Math","sqrt","p","factor","total","f","ceil"],"mappings":";;;;;AAAA,IAAMA,OAAOC,KAAKC,IAAL,CAAU,CAAV,IAAe,CAA5B;;kBAEe,UAACC,CAAD,EAAIC,MAAJ,EAAYC,KAAZ,EAAsB;AACnC,MAAMC,IAAIF,SAAS,CAAT,GAAaH,KAAKM,IAAL,CAAUJ,IAAI,CAAd,CAAb,GAAgCE,KAA1C;AACA,UAAQ,CAACF,IAAI,CAAL,IAAU,CAAlB,GAAuB;AACrB,SAAK,CAAL;AACE,aAAO,CAACG,CAAD,EAAI,CAAJ,CAAP;AACF,SAAK,CAAL;AACE,aAAO,CAAC,CAAD,EAAIA,CAAJ,CAAP;AACF,SAAK,CAAL;AACE,aAAO,CAACA,IAAIN,IAAL,EAAWM,IAAIN,IAAf,CAAP;AACF,SAAK,CAAL;AACE,aAAO,CAACM,IAAIN,IAAL,EAAW,CAACM,CAAD,GAAKN,IAAhB,CAAP;AARJ;AAUD,C","file":"directionForPassDefault.js","sourcesContent":["const NORM = Math.sqrt(2) / 2;\n\nexport default (p, factor, total) => {\n const f = factor * 2 * Math.ceil(p / 2) / total;\n switch ((p - 1) % 4) { // alternate horizontal, vertical and 2 diagonals\n case 0:\n return [f, 0];\n case 1:\n return [0, f];\n case 2:\n return [f * NORM, f * NORM];\n case 3:\n return [f * NORM, -f * NORM];\n }\n};\n"]}
1
+ {"version":3,"file":"directionForPassDefault.js","names":["NORM","Math","sqrt","directionForPassDefault","p","factor","total","f","ceil","_default","exports","default"],"sources":["../src/directionForPassDefault.ts"],"sourcesContent":["const NORM = Math.sqrt(2) / 2;\n\nexport type DirectionForPass = (\n pass: number,\n factor: number,\n total: number\n) => [number, number];\n\n// Cycles through horizontal, vertical and the 2 diagonals with increasing radius\nconst directionForPassDefault: DirectionForPass = (p, factor, total) => {\n const f = (factor * 2 * Math.ceil(p / 2)) / total;\n switch ((p - 1) % 4) {\n case 0:\n return [f, 0];\n case 1:\n return [0, f];\n case 2:\n return [f * NORM, f * NORM];\n default:\n return [f * NORM, -f * NORM];\n }\n};\n\nexport default directionForPassDefault;\n"],"mappings":";;;;;;AAAA,MAAMA,IAAI,GAAGC,IAAI,CAACC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AAQ7B;AACA,MAAMC,uBAAyC,GAAGA,CAACC,CAAC,EAAEC,MAAM,EAAEC,KAAK,KAAK;EACtE,MAAMC,CAAC,GAAIF,MAAM,GAAG,CAAC,GAAGJ,IAAI,CAACO,IAAI,CAACJ,CAAC,GAAG,CAAC,CAAC,GAAIE,KAAK;EACjD,QAAQ,CAACF,CAAC,GAAG,CAAC,IAAI,CAAC;IACjB,KAAK,CAAC;MACJ,OAAO,CAACG,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC;MACJ,OAAO,CAAC,CAAC,EAAEA,CAAC,CAAC;IACf,KAAK,CAAC;MACJ,OAAO,CAACA,CAAC,GAAGP,IAAI,EAAEO,CAAC,GAAGP,IAAI,CAAC;IAC7B;MACE,OAAO,CAACO,CAAC,GAAGP,IAAI,EAAE,CAACO,CAAC,GAAGP,IAAI,CAAC;EAChC;AACF,CAAC;AAAC,IAAAS,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaR,uBAAuB","ignoreList":[]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import Blur from "./Blur";
2
+ import Blur1D from "./Blur1D";
3
+ import BlurV from "./BlurV";
4
+ import BlurV1D from "./BlurV1D";
5
+ import directionForPassDefault from "./directionForPassDefault";
6
+ export { Blur, Blur1D, BlurV, BlurV1D, directionForPassDefault };
7
+ export type { BlurProps } from "./Blur";
8
+ export type { Blur1DProps } from "./Blur1D";
9
+ export type { BlurVProps } from "./BlurV";
10
+ export type { BlurV1DProps } from "./BlurV1D";
11
+ export type { DirectionForPass } from "./directionForPassDefault";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;AACjE,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC"}
package/lib/index.js CHANGED
@@ -3,28 +3,40 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.BlurV1D = exports.BlurV = exports.Blur1D = exports.Blur = undefined;
7
-
8
- var _Blur = require("./Blur");
9
-
10
- var _Blur2 = _interopRequireDefault(_Blur);
11
-
12
- var _Blur1D = require("./Blur1D");
13
-
14
- var _Blur1D2 = _interopRequireDefault(_Blur1D);
15
-
16
- var _BlurV = require("./BlurV");
17
-
18
- var _BlurV2 = _interopRequireDefault(_BlurV);
19
-
20
- var _BlurV1D = require("./BlurV1D");
21
-
22
- var _BlurV1D2 = _interopRequireDefault(_BlurV1D);
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- exports.Blur = _Blur2.default;
27
- exports.Blur1D = _Blur1D2.default;
28
- exports.BlurV = _BlurV2.default;
29
- exports.BlurV1D = _BlurV1D2.default;
6
+ Object.defineProperty(exports, "Blur", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Blur.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Blur1D", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Blur1D.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "BlurV", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _BlurV.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "BlurV1D", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _BlurV1D.default;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "directionForPassDefault", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _directionForPassDefault.default;
34
+ }
35
+ });
36
+ var _Blur = _interopRequireDefault(require("./Blur"));
37
+ var _Blur1D = _interopRequireDefault(require("./Blur1D"));
38
+ var _BlurV = _interopRequireDefault(require("./BlurV"));
39
+ var _BlurV1D = _interopRequireDefault(require("./BlurV1D"));
40
+ var _directionForPassDefault = _interopRequireDefault(require("./directionForPassDefault"));
41
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
30
42
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["Blur","Blur1D","BlurV","BlurV1D"],"mappings":";;;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;;;;;QACSA,I,GAAAA,c;QAAMC,M,GAAAA,gB;QAAQC,K,GAAAA,e;QAAOC,O,GAAAA,iB","file":"index.js","sourcesContent":["import Blur from \"./Blur\";\nimport Blur1D from \"./Blur1D\";\nimport BlurV from \"./BlurV\";\nimport BlurV1D from \"./BlurV1D\";\nexport { Blur, Blur1D, BlurV, BlurV1D };\n"]}
1
+ {"version":3,"file":"index.js","names":["_Blur","_interopRequireDefault","require","_Blur1D","_BlurV","_BlurV1D","_directionForPassDefault","e","__esModule","default"],"sources":["../src/index.ts"],"sourcesContent":["import Blur from \"./Blur\";\nimport Blur1D from \"./Blur1D\";\nimport BlurV from \"./BlurV\";\nimport BlurV1D from \"./BlurV1D\";\nimport directionForPassDefault from \"./directionForPassDefault\";\n\nexport { Blur, Blur1D, BlurV, BlurV1D, directionForPassDefault };\nexport type { BlurProps } from \"./Blur\";\nexport type { Blur1DProps } from \"./Blur1D\";\nexport type { BlurVProps } from \"./BlurV\";\nexport type { BlurV1DProps } from \"./BlurV1D\";\nexport type { DirectionForPass } from \"./directionForPassDefault\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,wBAAA,GAAAL,sBAAA,CAAAC,OAAA;AAAgE,SAAAD,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,40 +1,37 @@
1
1
  {
2
2
  "name": "gl-react-blur",
3
- "version": "2.0.1",
4
- "description": "Universal gl-react multi-pass gaussian Blur effect with configurable intensity",
5
- "main": "lib/index.js",
6
- "scripts": {
7
- "compile": "rm -rf lib/ && babel --presets es2015,stage-1,react --source-maps -d lib src",
8
- "prepublish": "npm run compile"
9
- },
10
- "dependencies": {
11
- "prop-types": "^15.6.0"
12
- },
13
- "peerDependencies": {
14
- "gl-react": "~2.2.0"
15
- },
16
- "devDependencies": {
17
- "babel-cli": "^6.4.5",
18
- "babel-preset-es2015": "^6.3.13",
19
- "babel-preset-react": "^6.3.13",
20
- "babel-preset-stage-1": "^6.3.13"
21
- },
22
- "repository": {
23
- "type": "git",
24
- "url": "git+ssh://git@github.com/gre/gl-react-blur.git"
25
- },
3
+ "version": "6.0.0",
4
+ "license": "MIT",
5
+ "author": "Gaëtan Renaudeau <renaudeau.gaetan@gmail.com>",
6
+ "description": "Universal gl-react multi-pass gaussian Blur effect with configurable intensity, also supporting variable blur with a map",
26
7
  "keywords": [
27
8
  "gl-react",
28
9
  "blur",
10
+ "gaussian",
11
+ "effect",
29
12
  "gl",
13
+ "opengl",
30
14
  "react",
31
- "gauss",
32
- "gaussian"
15
+ "react-component"
33
16
  ],
34
- "author": "Gaëtan Renaudeau",
35
- "license": "MIT",
36
- "bugs": {
37
- "url": "https://github.com/gre/gl-react-blur/issues"
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/gre/gl-react",
20
+ "directory": "packages/gl-react-blur"
38
21
  },
39
- "homepage": "https://github.com/gre/gl-react-blur#readme"
40
- }
22
+ "main": "lib/index.js",
23
+ "types": "lib/index.d.ts",
24
+ "files": [
25
+ "src",
26
+ "lib",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "peerDependencies": {
31
+ "gl-react": "*",
32
+ "react": ">=18"
33
+ },
34
+ "devDependencies": {
35
+ "gl-react": "^6.0.0"
36
+ }
37
+ }
package/src/Blur.tsx ADDED
@@ -0,0 +1,41 @@
1
+ import React from "react";
2
+ import { connectSize } from "gl-react";
3
+ import Blur1D from "./Blur1D";
4
+ import directionForPassDefault, {
5
+ DirectionForPass,
6
+ } from "./directionForPassDefault";
7
+
8
+ export type BlurProps = {
9
+ /** the content to blur: any gl-react texture input */
10
+ children: any;
11
+ /** blur intensity, in pixels */
12
+ factor: number;
13
+ /** number of Blur1D passes to run (default 2: horizontal + vertical) */
14
+ passes?: number;
15
+ /** direction vector of a given pass; defaults to cycling H, V and diagonals */
16
+ directionForPass?: DirectionForPass;
17
+ width?: number;
18
+ height?: number;
19
+ };
20
+
21
+ // Recursively nests Blur1D passes for multi-directional gaussian blur
22
+ const Blur = connectSize(
23
+ ({
24
+ children,
25
+ factor,
26
+ passes = 2,
27
+ directionForPass = directionForPassDefault,
28
+ }: any) => {
29
+ const rec = (pass: number): any =>
30
+ pass <= 0 ? (
31
+ children
32
+ ) : (
33
+ <Blur1D direction={directionForPass(pass, factor, passes)}>
34
+ {rec(pass - 1)}
35
+ </Blur1D>
36
+ );
37
+ return rec(passes);
38
+ }
39
+ ) as unknown as React.ComponentType<BlurProps>;
40
+
41
+ export default Blur;
@@ -1,15 +1,14 @@
1
- import { Shaders, Uniform, Node } from "gl-react";
2
1
  import React from "react";
3
- import PropTypes from "prop-types";
2
+ import { Shaders, Node, GLSL, connectSize } from "gl-react";
4
3
 
5
4
  const shaders = Shaders.create({
6
5
  blur1D: {
7
6
  // blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur
8
- frag: `precision highp float;
7
+ frag: GLSL`
8
+ precision highp float;
9
9
  varying vec2 uv;
10
10
  uniform sampler2D t;
11
11
  uniform vec2 direction, resolution;
12
-
13
12
  vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
14
13
  vec4 color = vec4(0.0);
15
14
  vec2 off1 = vec2(1.3846153846) * direction;
@@ -21,30 +20,29 @@ vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
21
20
  color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
22
21
  return color;
23
22
  }
24
-
25
- void main () {
23
+ void main() {
26
24
  gl_FragColor = blur9(t, uv, resolution, direction);
27
- }`
28
- }
25
+ }`,
26
+ },
29
27
  });
30
28
 
31
- const Blur1D = ({ width, height, pixelRatio, direction, children: t }) => (
32
- <Node
33
- shader={shaders.blur1D}
34
- width={width}
35
- height={height}
36
- pixelRatio={pixelRatio}
37
- uniforms={{
38
- direction,
39
- resolution: Uniform.Resolution,
40
- t
41
- }}
42
- />
43
- );
44
-
45
- Blur1D.propTypes = {
46
- direction: PropTypes.array.isRequired,
47
- children: PropTypes.any.isRequired
29
+ export type Blur1DProps = {
30
+ /** the content to blur: any gl-react texture input */
31
+ children: any;
32
+ /** blur direction & distance vector, in pixels */
33
+ direction: [number, number];
34
+ width?: number;
35
+ height?: number;
48
36
  };
49
37
 
38
+ // connectSize injects width/height for correct texel offset calculation
39
+ const Blur1D = connectSize(
40
+ ({ children: t, direction, width, height }: any) => (
41
+ <Node
42
+ shader={shaders.blur1D}
43
+ uniforms={{ t, resolution: [width, height], direction }}
44
+ />
45
+ )
46
+ ) as unknown as React.ComponentType<Blur1DProps>;
47
+
50
48
  export default Blur1D;
package/src/BlurV.tsx ADDED
@@ -0,0 +1,44 @@
1
+ import React from "react";
2
+ import { connectSize } from "gl-react";
3
+ import BlurV1D from "./BlurV1D";
4
+ import directionForPassDefault, {
5
+ DirectionForPass,
6
+ } from "./directionForPassDefault";
7
+
8
+ export type BlurVProps = {
9
+ /** the content to blur: any gl-react texture input */
10
+ children: any;
11
+ /** blur intensity, in pixels */
12
+ factor: number;
13
+ /** a texture whose red/green channels scale the blur per-pixel */
14
+ map: any;
15
+ /** number of BlurV1D passes to run (default 2: horizontal + vertical) */
16
+ passes?: number;
17
+ /** direction vector of a given pass; defaults to cycling H, V and diagonals */
18
+ directionForPass?: DirectionForPass;
19
+ width?: number;
20
+ height?: number;
21
+ };
22
+
23
+ // Recursively nests BlurV1D passes for variable multi-directional blur
24
+ const BlurV = connectSize(
25
+ ({
26
+ children,
27
+ factor,
28
+ map,
29
+ passes = 2,
30
+ directionForPass = directionForPassDefault,
31
+ }: any) => {
32
+ const rec = (pass: number): any =>
33
+ pass <= 0 ? (
34
+ children
35
+ ) : (
36
+ <BlurV1D map={map} direction={directionForPass(pass, factor, passes)}>
37
+ {rec(pass - 1)}
38
+ </BlurV1D>
39
+ );
40
+ return rec(passes);
41
+ }
42
+ ) as unknown as React.ComponentType<BlurVProps>;
43
+
44
+ export default BlurV;
@@ -1,15 +1,14 @@
1
- import { Shaders, Uniform, Node } from "gl-react";
2
1
  import React from "react";
3
- import PropTypes from "prop-types";
2
+ import { Shaders, Node, GLSL, connectSize } from "gl-react";
4
3
 
5
4
  const shaders = Shaders.create({
6
- blur1D: {
5
+ blurV1D: {
7
6
  // blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur
8
- frag: `precision highp float;
7
+ frag: GLSL`
8
+ precision highp float;
9
9
  varying vec2 uv;
10
10
  uniform sampler2D t, map;
11
11
  uniform vec2 direction, resolution;
12
-
13
12
  vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
14
13
  vec4 color = vec4(0.0);
15
14
  vec2 off1 = vec2(1.3846153846) * direction;
@@ -21,39 +20,31 @@ vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
21
20
  color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
22
21
  return color;
23
22
  }
24
-
25
- void main () {
23
+ void main() {
24
+ // Direction scaled by map value makes blur strength vary per-pixel
26
25
  gl_FragColor = blur9(t, uv, resolution, direction * texture2D(map, uv).rg);
27
- }`
28
- }
26
+ }`,
27
+ },
29
28
  });
30
29
 
31
- const BlurV1D = ({
32
- width,
33
- height,
34
- map,
35
- pixelRatio,
36
- direction,
37
- children: t
38
- }) => (
39
- <Node
40
- shader={shaders.blur1D}
41
- width={width}
42
- height={height}
43
- pixelRatio={pixelRatio}
44
- uniforms={{
45
- direction,
46
- resolution: Uniform.Resolution,
47
- t,
48
- map
49
- }}
50
- />
51
- );
52
-
53
- BlurV1D.propTypes = {
54
- direction: PropTypes.array.isRequired,
55
- children: PropTypes.any.isRequired,
56
- map: PropTypes.any.isRequired
30
+ export type BlurV1DProps = {
31
+ /** the content to blur: any gl-react texture input */
32
+ children: any;
33
+ /** blur direction & distance vector, in pixels */
34
+ direction: [number, number];
35
+ /** a texture whose red/green channels scale the blur per-pixel */
36
+ map: any;
37
+ width?: number;
38
+ height?: number;
57
39
  };
58
40
 
41
+ const BlurV1D = connectSize(
42
+ ({ children: t, direction, map, width, height }: any) => (
43
+ <Node
44
+ shader={shaders.blurV1D}
45
+ uniforms={{ t, map, resolution: [width, height], direction }}
46
+ />
47
+ )
48
+ ) as unknown as React.ComponentType<BlurV1DProps>;
49
+
59
50
  export default BlurV1D;
@@ -0,0 +1,24 @@
1
+ const NORM = Math.sqrt(2) / 2;
2
+
3
+ export type DirectionForPass = (
4
+ pass: number,
5
+ factor: number,
6
+ total: number
7
+ ) => [number, number];
8
+
9
+ // Cycles through horizontal, vertical and the 2 diagonals with increasing radius
10
+ const directionForPassDefault: DirectionForPass = (p, factor, total) => {
11
+ const f = (factor * 2 * Math.ceil(p / 2)) / total;
12
+ switch ((p - 1) % 4) {
13
+ case 0:
14
+ return [f, 0];
15
+ case 1:
16
+ return [0, f];
17
+ case 2:
18
+ return [f * NORM, f * NORM];
19
+ default:
20
+ return [f * NORM, -f * NORM];
21
+ }
22
+ };
23
+
24
+ export default directionForPassDefault;
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ import Blur from "./Blur";
2
+ import Blur1D from "./Blur1D";
3
+ import BlurV from "./BlurV";
4
+ import BlurV1D from "./BlurV1D";
5
+ import directionForPassDefault from "./directionForPassDefault";
6
+
7
+ export { Blur, Blur1D, BlurV, BlurV1D, directionForPassDefault };
8
+ export type { BlurProps } from "./Blur";
9
+ export type { Blur1DProps } from "./Blur1D";
10
+ export type { BlurVProps } from "./BlurV";
11
+ export type { BlurV1DProps } from "./BlurV1D";
12
+ export type { DirectionForPass } from "./directionForPassDefault";
package/src/Blur.js DELETED
@@ -1,46 +0,0 @@
1
- import React from "react";
2
- import PropTypes from "prop-types";
3
- import Blur1D from "./Blur1D";
4
- import directionForPassDefault from "./directionForPassDefault";
5
-
6
- const Blur = ({
7
- width,
8
- height,
9
- pixelRatio,
10
- factor,
11
- children,
12
- passes,
13
- directionForPass
14
- }) => {
15
- const rec = pass =>
16
- pass <= 0 ? (
17
- children
18
- ) : (
19
- <Blur1D
20
- width={width}
21
- height={height}
22
- pixelRatio={pixelRatio}
23
- direction={directionForPass(pass, factor, passes)}
24
- >
25
- {rec(pass - 1)}
26
- </Blur1D>
27
- );
28
- return rec(passes);
29
- };
30
-
31
- Blur.defaultProps = {
32
- passes: 2,
33
- directionForPass: directionForPassDefault
34
- };
35
-
36
- Blur.propTypes = {
37
- factor: PropTypes.number.isRequired,
38
- children: PropTypes.any.isRequired,
39
- passes: PropTypes.number,
40
- directionForPass: PropTypes.func,
41
- width: PropTypes.any,
42
- height: PropTypes.any,
43
- pixelRatio: PropTypes.number
44
- };
45
-
46
- export default Blur;
package/src/BlurV.js DELETED
@@ -1,49 +0,0 @@
1
- import React from "react";
2
- import PropTypes from "prop-types";
3
- import BlurV1D from "./BlurV1D";
4
- import directionForPassDefault from "./directionForPassDefault";
5
-
6
- const BlurV = ({
7
- width,
8
- height,
9
- map,
10
- pixelRatio,
11
- factor,
12
- children,
13
- passes,
14
- directionForPass
15
- }) => {
16
- const rec = pass =>
17
- pass <= 0 ? (
18
- children
19
- ) : (
20
- <BlurV1D
21
- width={width}
22
- height={height}
23
- map={map}
24
- pixelRatio={pixelRatio}
25
- direction={directionForPass(pass, factor, passes)}
26
- >
27
- {rec(pass - 1)}
28
- </BlurV1D>
29
- );
30
- return rec(passes);
31
- };
32
-
33
- BlurV.defaultProps = {
34
- passes: 2,
35
- directionForPass: directionForPassDefault
36
- };
37
-
38
- BlurV.propTypes = {
39
- factor: PropTypes.number.isRequired,
40
- children: PropTypes.any.isRequired,
41
- passes: PropTypes.number,
42
- directionForPass: PropTypes.func,
43
- map: PropTypes.any.isRequired,
44
- width: PropTypes.any,
45
- height: PropTypes.any,
46
- pixelRatio: PropTypes.number
47
- };
48
-
49
- export default BlurV;
@@ -1,15 +0,0 @@
1
- const NORM = Math.sqrt(2) / 2;
2
-
3
- export default (p, factor, total) => {
4
- const f = factor * 2 * Math.ceil(p / 2) / total;
5
- switch ((p - 1) % 4) { // alternate horizontal, vertical and 2 diagonals
6
- case 0:
7
- return [f, 0];
8
- case 1:
9
- return [0, f];
10
- case 2:
11
- return [f * NORM, f * NORM];
12
- case 3:
13
- return [f * NORM, -f * NORM];
14
- }
15
- };
package/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- import Blur from "./Blur";
2
- import Blur1D from "./Blur1D";
3
- import BlurV from "./BlurV";
4
- import BlurV1D from "./BlurV1D";
5
- export { Blur, Blur1D, BlurV, BlurV1D };