gl-react-blur 2.0.0 → 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 +19 -0
- package/README.md +14 -57
- package/lib/Blur.d.ts +17 -0
- package/lib/Blur.d.ts.map +1 -0
- package/lib/Blur.js +18 -58
- package/lib/Blur.js.map +1 -1
- package/lib/Blur1D.d.ts +12 -0
- package/lib/Blur1D.d.ts.map +1 -0
- package/lib/Blur1D.js +38 -40
- package/lib/Blur1D.js.map +1 -1
- package/lib/BlurV.d.ts +19 -0
- package/lib/BlurV.d.ts.map +1 -0
- package/lib/BlurV.js +20 -61
- package/lib/BlurV.js.map +1 -1
- package/lib/BlurV1D.d.ts +14 -0
- package/lib/BlurV1D.d.ts.map +1 -0
- package/lib/BlurV1D.js +41 -44
- package/lib/BlurV1D.js.map +1 -1
- package/lib/directionForPassDefault.d.ts +4 -0
- package/lib/directionForPassDefault.d.ts.map +1 -0
- package/lib/directionForPassDefault.js +8 -6
- package/lib/directionForPassDefault.js.map +1 -1
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +36 -24
- package/lib/index.js.map +1 -1
- package/package.json +28 -31
- package/src/Blur.tsx +41 -0
- package/src/{Blur1D.js → Blur1D.tsx} +23 -25
- package/src/BlurV.tsx +44 -0
- package/src/{BlurV1D.js → BlurV1D.tsx} +26 -35
- package/src/directionForPassDefault.ts +24 -0
- package/src/index.ts +12 -0
- package/src/Blur.js +0 -46
- package/src/BlurV.js +0 -49
- package/src/directionForPassDefault.js +0 -15
- package/src/index.js +0 -5
- package/yarn-error.log +0 -1918
- package/yarn.lock +0 -1842
|
@@ -3,19 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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,"
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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,"
|
|
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": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
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
|
-
"
|
|
32
|
-
"gaussian"
|
|
15
|
+
"react-component"
|
|
33
16
|
],
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/gre/gl-react",
|
|
20
|
+
"directory": "packages/gl-react-blur"
|
|
38
21
|
},
|
|
39
|
-
"
|
|
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 } from "gl-react";
|
|
2
1
|
import React from "react";
|
|
3
|
-
import
|
|
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: `
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 } from "gl-react";
|
|
2
1
|
import React from "react";
|
|
3
|
-
import
|
|
2
|
+
import { Shaders, Node, GLSL, connectSize } from "gl-react";
|
|
4
3
|
|
|
5
4
|
const shaders = Shaders.create({
|
|
6
|
-
|
|
5
|
+
blurV1D: {
|
|
7
6
|
// blur9: from https://github.com/Jam3/glsl-fast-gaussian-blur
|
|
8
|
-
frag: `
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
};
|