@react-three/postprocessing 2.8.0 → 2.8.2

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.
@@ -1,17 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { BloomEffect, BlendFunction } from 'postprocessing';
3
3
  export declare const Bloom: import("react").ForwardRefExoticComponent<{
4
- mipmapBlur?: boolean;
5
- radius?: number;
6
- levels?: number;
7
- blendFunction?: BlendFunction;
8
- luminanceThreshold?: number;
9
- luminanceSmoothing?: number;
10
- intensity?: number;
11
- width?: number;
12
- height?: number;
13
- kernelSize?: KernelSize;
14
- } & Partial<{
15
4
  blendFunction: BlendFunction;
16
- opacity: number;
17
- }> & import("react").RefAttributes<typeof BloomEffect>>;
5
+ } & import("react").RefAttributes<typeof BloomEffect>>;
@@ -1,10 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { BrightnessContrastEffect } from 'postprocessing';
3
- export declare const BrightnessContrast: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: import("postprocessing").BlendFunction;
5
- brightness?: number;
6
- contrast?: number;
7
- } & Partial<{
8
- blendFunction: import("postprocessing").BlendFunction;
9
- opacity: number;
10
- }> & import("react").RefAttributes<typeof BrightnessContrastEffect>>;
3
+ export declare const BrightnessContrast: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof BrightnessContrastEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "blendFunction" | "opacity" | keyof BrightnessContrastEffect | "brightness" | "contrast"> & import("react").RefAttributes<typeof BrightnessContrastEffect>>;
@@ -1,9 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { ColorDepthEffect } from 'postprocessing';
3
- export declare const ColorDepth: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: import("postprocessing").BlendFunction;
5
- bits?: number;
6
- } & Partial<{
7
- blendFunction: import("postprocessing").BlendFunction;
8
- opacity: number;
9
- }> & import("react").RefAttributes<typeof ColorDepthEffect>>;
3
+ export declare const ColorDepth: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof ColorDepthEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "blendFunction" | "opacity" | keyof ColorDepthEffect | "bits"> & import("react").RefAttributes<typeof ColorDepthEffect>>;
@@ -1,9 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { DepthEffect } from 'postprocessing';
3
- export declare const Depth: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: import("postprocessing").BlendFunction;
5
- inverted?: boolean;
6
- } & Partial<{
7
- blendFunction: import("postprocessing").BlendFunction;
8
- opacity: number;
9
- }> & import("react").RefAttributes<typeof DepthEffect>>;
3
+ export declare const Depth: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof DepthEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "blendFunction" | "opacity" | keyof DepthEffect> & import("react").RefAttributes<typeof DepthEffect>>;
@@ -6,6 +6,7 @@ export declare const DepthOfField: React.ForwardRefExoticComponent<{
6
6
  blendFunction?: import("postprocessing").BlendFunction;
7
7
  focusDistance?: number;
8
8
  focalLength?: number;
9
+ focusRange?: number;
9
10
  bokehScale?: number;
10
11
  width?: number;
11
12
  height?: number;
@@ -1,10 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { DotScreenEffect } from 'postprocessing';
3
- export declare const DotScreen: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: import("postprocessing").BlendFunction;
5
- angle?: number;
6
- scale?: number;
7
- } & Partial<{
8
- blendFunction: import("postprocessing").BlendFunction;
9
- opacity: number;
10
- }> & import("react").RefAttributes<typeof DotScreenEffect>>;
3
+ export declare const DotScreen: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof DotScreenEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "scale" | "blendFunction" | "opacity" | "angle" | keyof DotScreenEffect> & import("react").RefAttributes<typeof DotScreenEffect>>;
@@ -1,10 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { HueSaturationEffect } from 'postprocessing';
3
- export declare const HueSaturation: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: import("postprocessing").BlendFunction;
5
- hue?: number;
6
- saturation?: number;
7
- } & Partial<{
8
- blendFunction: import("postprocessing").BlendFunction;
9
- opacity: number;
10
- }> & import("react").RefAttributes<typeof HueSaturationEffect>>;
3
+ export declare const HueSaturation: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof HueSaturationEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "blendFunction" | "opacity" | keyof HueSaturationEffect | "hue" | "saturation"> & import("react").RefAttributes<typeof HueSaturationEffect>>;
@@ -1,9 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { NoiseEffect, BlendFunction } from 'postprocessing';
3
3
  export declare const Noise: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: BlendFunction;
5
- premultiply?: boolean;
6
- } & Partial<{
7
4
  blendFunction: BlendFunction;
8
- opacity: number;
9
- }> & import("react").RefAttributes<typeof NoiseEffect>>;
5
+ } & import("react").RefAttributes<typeof NoiseEffect>>;
@@ -1,9 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { ScanlineEffect, BlendFunction } from 'postprocessing';
3
3
  export declare const Scanline: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: BlendFunction;
5
- density?: number;
6
- } & Partial<{
7
4
  blendFunction: BlendFunction;
8
- opacity: number;
9
- }> & import("react").RefAttributes<typeof ScanlineEffect>>;
5
+ } & import("react").RefAttributes<typeof ScanlineEffect>>;
@@ -1,9 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { SepiaEffect } from 'postprocessing';
3
- export declare const Sepia: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: import("postprocessing").BlendFunction;
5
- intensity?: number;
6
- } & Partial<{
7
- blendFunction: import("postprocessing").BlendFunction;
8
- opacity: number;
9
- }> & import("react").RefAttributes<typeof SepiaEffect>>;
3
+ export declare const Sepia: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof SepiaEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "blendFunction" | "opacity" | "intensity" | keyof SepiaEffect> & import("react").RefAttributes<typeof SepiaEffect>>;
@@ -1,6 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { ShockWaveEffect } from 'postprocessing';
3
- export declare const ShockWave: import("react").ForwardRefExoticComponent<import("three").Camera & Partial<{
4
- blendFunction: import("postprocessing").BlendFunction;
5
- opacity: number;
6
- }> & import("react").RefAttributes<typeof ShockWaveEffect>>;
3
+ export declare const ShockWave: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof ShockWaveEffect>, "children" | "camera" | "quaternion" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "position" | "up" | "scale" | "rotation" | "matrix" | "layers" | "dispose" | "type" | "id" | "uuid" | "name" | "parent" | "modelViewMatrix" | "normalMatrix" | "matrixWorld" | "matrixAutoUpdate" | "matrixWorldNeedsUpdate" | "visible" | "castShadow" | "receiveShadow" | "frustumCulled" | "renderOrder" | "animations" | "userData" | "customDepthMaterial" | "customDistanceMaterial" | "isObject3D" | "onBeforeRender" | "onAfterRender" | "applyMatrix4" | "applyQuaternion" | "setRotationFromAxisAngle" | "setRotationFromEuler" | "setRotationFromMatrix" | "setRotationFromQuaternion" | "rotateOnAxis" | "rotateOnWorldAxis" | "rotateX" | "rotateY" | "rotateZ" | "translateOnAxis" | "translateX" | "translateY" | "translateZ" | "localToWorld" | "worldToLocal" | "lookAt" | "add" | "remove" | "removeFromParent" | "clear" | "getObjectById" | "getObjectByName" | "getObjectByProperty" | "getWorldPosition" | "getWorldQuaternion" | "getWorldScale" | "getWorldDirection" | "raycast" | "traverse" | "traverseVisible" | "traverseAncestors" | "updateMatrix" | "updateMatrixWorld" | "updateWorldMatrix" | "toJSON" | "clone" | "copy" | "addEventListener" | "hasEventListener" | "removeEventListener" | "dispatchEvent" | "blendFunction" | "opacity" | "update" | "setSize" | "initialize" | "attributes" | "fragmentShader" | "vertexShader" | "defines" | "uniforms" | "extensions" | "blendMode" | "setDepthTexture" | "matrixWorldInverse" | "projectionMatrix" | "projectionMatrixInverse" | "isCamera" | "epicenter" | "speed" | "explode"> & import("react").RefAttributes<typeof ShockWaveEffect>>;
@@ -1,17 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { TiltShiftEffect, BlendFunction } from 'postprocessing';
3
3
  export declare const TiltShift: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: BlendFunction;
5
- offset?: number;
6
- rotation?: number;
7
- focusArea?: number;
8
- feather?: number;
9
- bias?: number;
10
- kernelSize?: KernelSize;
11
- resolutionScale?: number;
12
- resolutionX?: Resolution;
13
- resolutionY?: Resolutio;
14
- } & Partial<{
15
4
  blendFunction: BlendFunction;
16
- opacity: number;
17
- }> & import("react").RefAttributes<typeof TiltShiftEffect>>;
5
+ } & import("react").RefAttributes<typeof TiltShiftEffect>>;
@@ -1,23 +1,19 @@
1
1
  /// <reference types="react" />
2
2
  import { BlendFunction, Effect } from 'postprocessing';
3
3
  export declare class TiltShiftEffect extends Effect {
4
- constructor({ blendFunction, blur, gradient, start, end, delta, }?: {
4
+ constructor({ blendFunction, blur, // [0, 1], can go beyond 1 for extra
5
+ taper, // [0, 1], can go beyond 1 for extra
6
+ start, // [0,1] percentage x,y of screenspace
7
+ end, // [0,1] percentage x,y of screenspace
8
+ samples, // number of blur samples
9
+ direction }?: {
5
10
  blendFunction?: BlendFunction;
6
11
  blur?: number;
7
- gradient?: number;
12
+ taper?: number;
8
13
  start?: number[];
9
14
  end?: number[];
10
- delta?: number[];
15
+ samples?: number;
16
+ direction?: number[];
11
17
  });
12
18
  }
13
- export declare const TiltShift2: import("react").ForwardRefExoticComponent<{
14
- blendFunction?: BlendFunction;
15
- blur?: number;
16
- gradient?: number;
17
- start?: number[];
18
- end?: number[];
19
- delta?: number[];
20
- } & Partial<{
21
- blendFunction: BlendFunction;
22
- opacity: number;
23
- }> & import("react").RefAttributes<typeof TiltShiftEffect>>;
19
+ export declare const TiltShift2: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof TiltShiftEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "blendFunction" | "opacity" | "blur" | "samples" | "taper" | "start" | "end" | "direction" | keyof TiltShiftEffect> & import("react").RefAttributes<typeof TiltShiftEffect>>;
@@ -1,14 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { ToneMappingEffect } from 'postprocessing';
3
- export declare const ToneMapping: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: import("postprocessing").BlendFunction;
5
- adaptive?: boolean;
6
- resolution?: number;
7
- middleGrey?: number;
8
- maxLuminance?: number;
9
- averageLuminance?: number;
10
- adaptationRate?: number;
11
- } & Partial<{
12
- blendFunction: import("postprocessing").BlendFunction;
13
- opacity: number;
14
- }> & import("react").RefAttributes<typeof ToneMappingEffect>>;
3
+ export declare const ToneMapping: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof ToneMappingEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "blendFunction" | "opacity" | keyof ToneMappingEffect | "middleGrey" | "maxLuminance" | "averageLuminance"> & import("react").RefAttributes<typeof ToneMappingEffect>>;
@@ -1,11 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { VignetteEffect } from 'postprocessing';
3
- export declare const Vignette: import("react").ForwardRefExoticComponent<{
4
- blendFunction?: import("postprocessing").BlendFunction;
5
- eskil?: boolean;
6
- offset?: number;
7
- darkness?: number;
8
- } & Partial<{
9
- blendFunction: import("postprocessing").BlendFunction;
10
- opacity: number;
11
- }> & import("react").RefAttributes<typeof VignetteEffect>>;
3
+ export declare const Vignette: import("react").ForwardRefExoticComponent<Pick<import("../util").EffectProps<typeof VignetteEffect>, "children" | "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "key" | "onUpdate" | "blendFunction" | "opacity" | "offset" | keyof VignetteEffect | "darkness"> & import("react").RefAttributes<typeof VignetteEffect>>;
package/dist/index.cjs CHANGED
@@ -3,75 +3,97 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var postprocessing = require('postprocessing');
6
+ var _construct = require('@babel/runtime/helpers/construct');
7
+ var _extends = require('@babel/runtime/helpers/extends');
6
8
  var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
7
9
  var React = require('react');
8
- var three = require('three');
10
+ var THREE = require('three');
9
11
  var fiber = require('@react-three/fiber');
10
- var _extends = require('@babel/runtime/helpers/extends');
11
- var _construct = require('@babel/runtime/helpers/construct');
12
12
  var threeStdlib = require('three-stdlib');
13
13
  var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
14
14
  var screenSpaceReflections = require('screen-space-reflections');
15
15
 
16
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
17
 
18
+ function _interopNamespace(e) {
19
+ if (e && e.__esModule) return e;
20
+ var n = Object.create(null);
21
+ if (e) {
22
+ Object.keys(e).forEach(function (k) {
23
+ if (k !== 'default') {
24
+ var d = Object.getOwnPropertyDescriptor(e, k);
25
+ Object.defineProperty(n, k, d.get ? d : {
26
+ enumerable: true,
27
+ get: function () { return e[k]; }
28
+ });
29
+ }
30
+ });
31
+ }
32
+ n["default"] = e;
33
+ return Object.freeze(n);
34
+ }
35
+
36
+ var _construct__default = /*#__PURE__*/_interopDefaultLegacy(_construct);
37
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
18
38
  var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
39
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
19
40
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
21
- var _construct__default = /*#__PURE__*/_interopDefaultLegacy(_construct);
41
+ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
22
42
  var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
23
43
 
24
44
  var _excluded$9 = ["blendFunction", "opacity"];
25
-
26
- var isRef = function isRef(ref) {
27
- return !!ref.current;
28
- };
29
-
30
45
  var resolveRef = function resolveRef(ref) {
31
- return isRef(ref) ? ref.current : ref;
46
+ return typeof ref === 'object' && 'current' in ref ? ref.current : ref;
32
47
  };
33
- var wrapEffect = function wrapEffect(effectImpl, defaultBlendMode) {
34
- if (defaultBlendMode === void 0) {
35
- defaultBlendMode = postprocessing.BlendFunction.NORMAL;
36
- }
37
-
38
- return /*#__PURE__*/React.forwardRef(function Wrap(_ref, ref) {
39
- var blendFunction = _ref.blendFunction,
40
- opacity = _ref.opacity,
48
+ var i = 0;
49
+ var components = new WeakMap();
50
+ var wrapEffect = function wrapEffect(effect, defaults) {
51
+ return /* @__PURE__ */React__namespace.forwardRef(function Effect(_ref, ref) {
52
+ var _ref$blendFunction = _ref.blendFunction,
53
+ blendFunction = _ref$blendFunction === void 0 ? defaults == null ? void 0 : defaults.blendFunction : _ref$blendFunction,
54
+ _ref$opacity = _ref.opacity,
55
+ opacity = _ref$opacity === void 0 ? defaults == null ? void 0 : defaults.opacity : _ref$opacity,
41
56
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$9);
42
57
 
43
- var invalidate = fiber.useThree(function (state) {
44
- return state.invalidate;
58
+ var Component = components.get(effect);
59
+
60
+ if (!Component) {
61
+ var _extend;
62
+
63
+ var key = "@react-three/postprocessing/" + effect.name + "-" + i++;
64
+ fiber.extend((_extend = {}, _extend[key] = effect, _extend));
65
+ components.set(effect, Component = key);
66
+ }
67
+
68
+ var camera = fiber.useThree(function (state) {
69
+ return state.camera;
45
70
  });
46
- var effect = React.useMemo(function () {
47
- return new effectImpl(props);
48
- }, [props]);
49
- React.useLayoutEffect(function () {
50
- effect.blendMode.blendFunction = !blendFunction && blendFunction !== 0 ? defaultBlendMode : blendFunction;
51
- if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
52
- invalidate();
53
- }, [blendFunction, effect.blendMode, opacity]);
54
- return /*#__PURE__*/React__default["default"].createElement("primitive", {
71
+ var args = React__namespace.useMemo(function () {
72
+ var _defaults$args, _props$args;
73
+
74
+ return [].concat((_defaults$args = defaults == null ? void 0 : defaults.args) != null ? _defaults$args : [], (_props$args = props.args) != null ? _props$args : [_extends__default["default"]({}, defaults, props)]);
75
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
76
+ [JSON.stringify(props)]);
77
+ return /*#__PURE__*/React__namespace.createElement(Component, _extends__default["default"]({
78
+ camera: camera,
79
+ "blendMode-blendFunction": blendFunction,
80
+ "blendMode-opacity": opacity
81
+ }, props, {
55
82
  ref: ref,
56
- object: effect,
57
- dispose: null
58
- });
83
+ args: args
84
+ }));
59
85
  });
60
86
  };
61
87
  var useVector2 = function useVector2(props, key) {
62
- var vec = props[key];
63
- return React.useMemo(function () {
64
- if (vec instanceof three.Vector2) {
65
- return new three.Vector2().set(vec.x, vec.y);
66
- } else if (Array.isArray(vec)) {
67
- var x = vec[0],
68
- y = vec[1];
69
- return new three.Vector2().set(x, y);
70
- }
71
- }, [vec]);
88
+ var value = props[key];
89
+ return React__namespace.useMemo(function () {
90
+ if (typeof value === 'number') return new THREE__namespace.Vector2(value, value);else if (value) return _construct__default["default"](THREE__namespace.Vector2, value);else return new THREE__namespace.Vector2();
91
+ }, [value]);
72
92
  };
73
93
 
74
- var Bloom = wrapEffect(postprocessing.BloomEffect, postprocessing.BlendFunction.ADD);
94
+ var Bloom = wrapEffect(postprocessing.BloomEffect, {
95
+ blendFunction: postprocessing.BlendFunction.ADD
96
+ });
75
97
 
76
98
  var BrightnessContrast = wrapEffect(postprocessing.BrightnessContrastEffect);
77
99
 
@@ -126,7 +148,7 @@ var EffectComposer = /*#__PURE__*/React__default["default"].memo( /*#__PURE__*/R
126
148
  _ref$multisampling = _ref.multisampling,
127
149
  multisampling = _ref$multisampling === void 0 ? 8 : _ref$multisampling,
128
150
  _ref$frameBufferType = _ref.frameBufferType,
129
- frameBufferType = _ref$frameBufferType === void 0 ? three.HalfFloatType : _ref$frameBufferType;
151
+ frameBufferType = _ref$frameBufferType === void 0 ? THREE.HalfFloatType : _ref$frameBufferType;
130
152
 
131
153
  var _useThree = fiber.useThree(),
132
154
  gl = _useThree.gl,
@@ -243,7 +265,7 @@ var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref
243
265
  }, [camera, props]);
244
266
  React.useLayoutEffect(function () {
245
267
  if (target) {
246
- var vec = target instanceof three.Vector3 ? new three.Vector3().set(target.x, target.y, target.z) : new three.Vector3().set(target[0], target[1], target[2]);
268
+ var vec = target instanceof THREE.Vector3 ? new THREE.Vector3().set(target.x, target.y, target.z) : new THREE.Vector3().set(target[0], target[1], target[2]);
247
269
  effect.target = vec;
248
270
  }
249
271
 
@@ -327,7 +349,9 @@ var Grid = /*#__PURE__*/React.forwardRef(function Grid(_ref, ref) {
327
349
 
328
350
  var HueSaturation = wrapEffect(postprocessing.HueSaturationEffect);
329
351
 
330
- var Noise = wrapEffect(postprocessing.NoiseEffect, postprocessing.BlendFunction.COLOR_DODGE);
352
+ var Noise = wrapEffect(postprocessing.NoiseEffect, {
353
+ blendFunction: postprocessing.BlendFunction.COLOR_DODGE
354
+ });
331
355
 
332
356
  var _excluded$5 = ["enabled", "children"];
333
357
  var selectionContext = /*#__PURE__*/React.createContext(null);
@@ -482,7 +506,9 @@ var Pixelation = /*#__PURE__*/React.forwardRef(function Pixelation(_ref, ref) {
482
506
  });
483
507
  });
484
508
 
485
- var Scanline = wrapEffect(postprocessing.ScanlineEffect, postprocessing.BlendFunction.OVERLAY);
509
+ var Scanline = wrapEffect(postprocessing.ScanlineEffect, {
510
+ blendFunction: postprocessing.BlendFunction.OVERLAY
511
+ });
486
512
 
487
513
  var _excluded$3 = ["selection", "selectionLayer", "lights", "luminanceThreshold", "luminanceSmoothing", "intensity", "width", "height", "kernelSize", "mipmapBlur", "radius", "levels"];
488
514
 
@@ -655,10 +681,10 @@ var Texture = /*#__PURE__*/React.forwardRef(function Texture(_ref, ref) {
655
681
  texture = _ref.texture,
656
682
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$2);
657
683
 
658
- var t = fiber.useLoader(three.TextureLoader, textureSrc);
684
+ var t = fiber.useLoader(THREE.TextureLoader, textureSrc);
659
685
  React.useLayoutEffect(function () {
660
- t.encoding = three.sRGBEncoding;
661
- t.wrapS = t.wrapT = three.RepeatWrapping;
686
+ t.encoding = THREE.sRGBEncoding;
687
+ t.wrapS = t.wrapT = THREE.RepeatWrapping;
662
688
  }, [t]);
663
689
  var effect = React.useMemo(function () {
664
690
  return new postprocessing.TextureEffect(_extends__default["default"]({}, props, {
@@ -702,10 +728,12 @@ var LUT = /*#__PURE__*/React.forwardRef(function LUT(_ref, ref) {
702
728
  });
703
729
  });
704
730
 
705
- var TiltShift = wrapEffect(postprocessing.TiltShiftEffect, postprocessing.BlendFunction.ADD);
731
+ var TiltShift = wrapEffect(postprocessing.TiltShiftEffect, {
732
+ blendFunction: postprocessing.BlendFunction.ADD
733
+ });
706
734
 
707
735
  var TiltShiftShader = {
708
- fragmentShader: "\n // original shader by Evan Wallace\n uniform float blur;\n uniform float gradient;\n uniform vec2 start;\n uniform vec2 end;\n uniform vec2 delta;\n\n float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n }\n\n void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {\n\n vec4 color = vec4(0.0);\n float total = 0.0;\n vec2 startPixel = vec2(start.x * resolution.x, start.y * resolution.y);\n vec2 endPixel = vec2(end.x * resolution.x, end.y * resolution.y);\n\n /* randomize the lookup values to hide the fixed number of samples */\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n vec2 normal = normalize(vec2(startPixel.y - endPixel.y, endPixel.x - startPixel.x));\n float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradient) * blur;\n\n #pragma unroll_loop_start\n for (float i = -3.0; i <= 3.0; i++) {\n float percent = (i + offset - 0.5) / 3.0;\n float weight = 1.0 - abs(percent);\n vec4 sample_t = texture2D(inputBuffer, uv + delta / resolution * percent * radius);\n /* switch to pre-multiplied alpha to correctly blur transparent images */\n sample_t.rgb *= sample_t.a;\n color += sample_t * weight;\n total += weight;\n }\n #pragma unroll_loop_end\n\n outputColor = color / total;\n /* switch back from pre-multiplied alpha */\n outputColor.rgb /= outputColor.a + 0.00001;\n }\n "
736
+ fragmentShader: "\n\n // original shader by Evan Wallace\n\n #define MAX_ITERATIONS 100\n\n uniform float blur;\n uniform float taper;\n uniform vec2 start;\n uniform vec2 end;\n uniform vec2 direction;\n uniform int samples;\n\n float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n }\n\n void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {\n vec4 color = vec4(0.0);\n float total = 0.0;\n vec2 startPixel = vec2(start.x * resolution.x, start.y * resolution.y);\n vec2 endPixel = vec2(end.x * resolution.x, end.y * resolution.y);\n float f_samples = float(samples);\n float half_samples = f_samples / 2.0;\n\n // use screen diagonal to normalize blur radii\n float maxScreenDistance = distance(vec2(0.0), resolution); // diagonal distance\n float gradientRadius = taper * (maxScreenDistance);\n float blurRadius = blur * (maxScreenDistance / 16.0);\n\n /* randomize the lookup values to hide the fixed number of samples */\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n vec2 normal = normalize(vec2(startPixel.y - endPixel.y, endPixel.x - startPixel.x));\n float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradientRadius) * blurRadius;\n\n #pragma unroll_loop_start\n for (int i = 0; i <= MAX_ITERATIONS; i++) {\n if (i >= samples) { break; } // return early if over sample count\n float f_i = float(i);\n float s_i = -half_samples + f_i;\n float percent = (s_i + offset - 0.5) / half_samples;\n float weight = 1.0 - abs(percent);\n vec4 sample_i = texture2D(inputBuffer, uv + normalize(direction) / resolution * percent * radius);\n /* switch to pre-multiplied alpha to correctly blur transparent images */\n sample_i.rgb *= sample_i.a;\n color += sample_i * weight;\n total += weight;\n }\n #pragma unroll_loop_end\n\n outputColor = color / total;\n\n /* switch back from pre-multiplied alpha */\n outputColor.rgb /= outputColor.a + 0.00001;\n }\n "
709
737
  };
710
738
  var TiltShiftEffect = /*#__PURE__*/function (_Effect) {
711
739
  _inheritsLoose__default["default"](TiltShiftEffect, _Effect);
@@ -713,28 +741,30 @@ var TiltShiftEffect = /*#__PURE__*/function (_Effect) {
713
741
  function TiltShiftEffect(_temp) {
714
742
  var _ref = _temp === void 0 ? {} : _temp,
715
743
  _ref$blendFunction = _ref.blendFunction,
716
- blendFunction = _ref$blendFunction === void 0 ? postprocessing.BlendFunction.ADD : _ref$blendFunction,
744
+ blendFunction = _ref$blendFunction === void 0 ? postprocessing.BlendFunction.NORMAL : _ref$blendFunction,
717
745
  _ref$blur = _ref.blur,
718
- blur = _ref$blur === void 0 ? 20.0 : _ref$blur,
719
- _ref$gradient = _ref.gradient,
720
- gradient = _ref$gradient === void 0 ? 1100.0 : _ref$gradient,
746
+ blur = _ref$blur === void 0 ? 1.0 : _ref$blur,
747
+ _ref$taper = _ref.taper,
748
+ taper = _ref$taper === void 0 ? 0.5 : _ref$taper,
721
749
  _ref$start = _ref.start,
722
750
  start = _ref$start === void 0 ? [0.5, 0.0] : _ref$start,
723
751
  _ref$end = _ref.end,
724
752
  end = _ref$end === void 0 ? [0.5, 1.0] : _ref$end,
725
- _ref$delta = _ref.delta,
726
- delta = _ref$delta === void 0 ? [1, 1] : _ref$delta;
753
+ _ref$samples = _ref.samples,
754
+ samples = _ref$samples === void 0 ? 10.0 : _ref$samples,
755
+ _ref$direction = _ref.direction,
756
+ direction = _ref$direction === void 0 ? [1, 1] : _ref$direction;
727
757
 
728
758
  return _Effect.call(this, 'TiltShiftEffect', TiltShiftShader.fragmentShader, {
729
759
  blendFunction: blendFunction,
730
760
  attributes: postprocessing.EffectAttribute.CONVOLUTION,
731
- uniforms: new Map([['blur', new three.Uniform(blur)], ['gradient', new three.Uniform(gradient)], ['start', new three.Uniform(start)], ['end', new three.Uniform(end)], ['delta', new three.Uniform(delta)]])
761
+ uniforms: new Map([['blur', new THREE.Uniform(blur)], ['taper', new THREE.Uniform(taper)], ['start', new THREE.Uniform(start)], ['end', new THREE.Uniform(end)], ['samples', new THREE.Uniform(samples)], ['direction', new THREE.Uniform(direction)]])
732
762
  }) || this;
733
763
  }
734
764
 
735
765
  return TiltShiftEffect;
736
766
  }(postprocessing.Effect);
737
- var TiltShift2 = wrapEffect(TiltShiftEffect, postprocessing.BlendFunction.NORMAL);
767
+ var TiltShift2 = wrapEffect(TiltShiftEffect);
738
768
 
739
769
  var _excluded = ["ENABLE_BLUR", "USE_MRT"];
740
770
 
@@ -818,4 +848,7 @@ exports.TiltShift2 = TiltShift2;
818
848
  exports.TiltShiftEffect = TiltShiftEffect;
819
849
  exports.ToneMapping = ToneMapping;
820
850
  exports.Vignette = Vignette;
851
+ exports.resolveRef = resolveRef;
821
852
  exports.selectionContext = selectionContext;
853
+ exports.useVector2 = useVector2;
854
+ exports.wrapEffect = wrapEffect;
package/dist/index.d.ts CHANGED
@@ -28,3 +28,4 @@ export * from './effects/TiltShift2';
28
28
  export * from './effects/SSR';
29
29
  export * from './Selection';
30
30
  export * from './EffectComposer';
31
+ export * from './util';
package/dist/index.js CHANGED
@@ -1,52 +1,60 @@
1
- import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAPreset, EdgeDetectionMode, SMAAImageLoader, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUTEffect, TiltShiftEffect as TiltShiftEffect$1, Effect, EffectAttribute } from 'postprocessing';
2
- import React, { forwardRef, useMemo, useLayoutEffect, createContext, useEffect, useRef, useImperativeHandle, useContext, useState } from 'react';
3
- import { Vector2, HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
4
- import { useThree, useFrame, useLoader } from '@react-three/fiber';
5
- import { isWebGL2Available } from 'three-stdlib';
1
+ import { BloomEffect, BlendFunction, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAPreset, EdgeDetectionMode, SMAAImageLoader, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUTEffect, TiltShiftEffect as TiltShiftEffect$1, Effect, EffectAttribute } from 'postprocessing';
6
2
  import _extends from '@babel/runtime/helpers/esm/extends';
3
+ import * as React from 'react';
4
+ import React__default, { forwardRef, useMemo, createContext, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState } from 'react';
5
+ import * as THREE from 'three';
6
+ import { HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
7
+ import { extend, useThree, useFrame, useLoader } from '@react-three/fiber';
8
+ import { isWebGL2Available } from 'three-stdlib';
7
9
  import { SSREffect } from 'screen-space-reflections';
8
10
 
9
- const isRef = ref => !!ref.current;
11
+ const resolveRef = ref => typeof ref === 'object' && 'current' in ref ? ref.current : ref;
12
+ let i = 0;
13
+ const components = new WeakMap();
14
+ const wrapEffect = (effect, defaults) => /* @__PURE__ */React.forwardRef(function Effect(_ref, ref) {
15
+ let {
16
+ blendFunction = defaults == null ? void 0 : defaults.blendFunction,
17
+ opacity = defaults == null ? void 0 : defaults.opacity,
18
+ ...props
19
+ } = _ref;
20
+ let Component = components.get(effect);
10
21
 
11
- const resolveRef = ref => isRef(ref) ? ref.current : ref;
12
- const wrapEffect = function (effectImpl, defaultBlendMode) {
13
- if (defaultBlendMode === void 0) {
14
- defaultBlendMode = BlendFunction.NORMAL;
22
+ if (!Component) {
23
+ const key = `@react-three/postprocessing/${effect.name}-${i++}`;
24
+ extend({
25
+ [key]: effect
26
+ });
27
+ components.set(effect, Component = key);
15
28
  }
16
29
 
17
- return /*#__PURE__*/forwardRef(function Wrap(_ref, ref) {
18
- let {
19
- blendFunction,
20
- opacity,
30
+ const camera = useThree(state => state.camera);
31
+ const args = React.useMemo(() => {
32
+ var _defaults$args, _props$args;
33
+
34
+ return [...((_defaults$args = defaults == null ? void 0 : defaults.args) != null ? _defaults$args : []), ...((_props$args = props.args) != null ? _props$args : [{ ...defaults,
21
35
  ...props
22
- } = _ref;
23
- const invalidate = useThree(state => state.invalidate);
24
- const effect = useMemo(() => new effectImpl(props), [props]);
25
- useLayoutEffect(() => {
26
- effect.blendMode.blendFunction = !blendFunction && blendFunction !== 0 ? defaultBlendMode : blendFunction;
27
- if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
28
- invalidate();
29
- }, [blendFunction, effect.blendMode, opacity]);
30
- return /*#__PURE__*/React.createElement("primitive", {
31
- ref: ref,
32
- object: effect,
33
- dispose: null
34
- });
35
- });
36
- };
36
+ }])];
37
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ [JSON.stringify(props)]);
39
+ return /*#__PURE__*/React.createElement(Component, _extends({
40
+ camera: camera,
41
+ "blendMode-blendFunction": blendFunction,
42
+ "blendMode-opacity": opacity
43
+ }, props, {
44
+ ref: ref,
45
+ args: args
46
+ }));
47
+ });
37
48
  const useVector2 = (props, key) => {
38
- const vec = props[key];
39
- return useMemo(() => {
40
- if (vec instanceof Vector2) {
41
- return new Vector2().set(vec.x, vec.y);
42
- } else if (Array.isArray(vec)) {
43
- const [x, y] = vec;
44
- return new Vector2().set(x, y);
45
- }
46
- }, [vec]);
49
+ const value = props[key];
50
+ return React.useMemo(() => {
51
+ if (typeof value === 'number') return new THREE.Vector2(value, value);else if (value) return new THREE.Vector2(...value);else return new THREE.Vector2();
52
+ }, [value]);
47
53
  };
48
54
 
49
- const Bloom = wrapEffect(BloomEffect, BlendFunction.ADD);
55
+ const Bloom = wrapEffect(BloomEffect, {
56
+ blendFunction: BlendFunction.ADD
57
+ });
50
58
 
51
59
  const BrightnessContrast = wrapEffect(BrightnessContrastEffect);
52
60
 
@@ -55,7 +63,7 @@ const ChromaticAberration = /*#__PURE__*/forwardRef(function ChromaticAberration
55
63
  const effect = useMemo(() => new ChromaticAberrationEffect({ ...props,
56
64
  offset
57
65
  }), [offset, props]);
58
- return /*#__PURE__*/React.createElement("primitive", {
66
+ return /*#__PURE__*/React__default.createElement("primitive", {
59
67
  ref: ref,
60
68
  object: effect,
61
69
  dispose: null
@@ -69,7 +77,7 @@ const ColorAverage = /*#__PURE__*/forwardRef(function ColorAverage(_ref, ref) {
69
77
 
70
78
  /** Because ColorAverage blendFunction is not an object but a number, we have to define a custom prop "blendFunction" */
71
79
  const effect = useMemo(() => new ColorAverageEffect(blendFunction), [blendFunction]);
72
- return /*#__PURE__*/React.createElement("primitive", {
80
+ return /*#__PURE__*/React__default.createElement("primitive", {
73
81
  ref: ref,
74
82
  object: effect,
75
83
  dispose: null
@@ -81,7 +89,7 @@ const ColorDepth = wrapEffect(ColorDepthEffect);
81
89
  const Depth = wrapEffect(DepthEffect);
82
90
 
83
91
  const EffectComposerContext = /*#__PURE__*/createContext(null);
84
- const EffectComposer = /*#__PURE__*/React.memo( /*#__PURE__*/forwardRef((_ref, ref) => {
92
+ const EffectComposer = /*#__PURE__*/React__default.memo( /*#__PURE__*/forwardRef((_ref, ref) => {
85
93
  let {
86
94
  children,
87
95
  camera,
@@ -172,9 +180,9 @@ const EffectComposer = /*#__PURE__*/React.memo( /*#__PURE__*/forwardRef((_ref, r
172
180
  }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]); // Expose the composer
173
181
 
174
182
  useImperativeHandle(ref, () => composer, [composer]);
175
- return /*#__PURE__*/React.createElement(EffectComposerContext.Provider, {
183
+ return /*#__PURE__*/React__default.createElement(EffectComposerContext.Provider, {
176
184
  value: state
177
- }, /*#__PURE__*/React.createElement("group", {
185
+ }, /*#__PURE__*/React__default.createElement("group", {
178
186
  ref: group
179
187
  }, children));
180
188
  }));
@@ -199,7 +207,7 @@ const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
199
207
  if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
200
208
  invalidate();
201
209
  }, [target, depthTexture, effect]);
202
- return /*#__PURE__*/React.createElement("primitive", {
210
+ return /*#__PURE__*/React__default.createElement("primitive", {
203
211
  ref: ref,
204
212
  object: effect,
205
213
  dispose: null
@@ -226,7 +234,7 @@ const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
226
234
  effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED;
227
235
  invalidate();
228
236
  }, [active, effect, props.mode]);
229
- return /*#__PURE__*/React.createElement("primitive", {
237
+ return /*#__PURE__*/React__default.createElement("primitive", {
230
238
  ref: ref,
231
239
  object: effect,
232
240
  dispose: null
@@ -238,7 +246,7 @@ const GodRays = /*#__PURE__*/forwardRef(function GodRays(props, ref) {
238
246
  camera
239
247
  } = useContext(EffectComposerContext);
240
248
  const effect = useMemo(() => new GodRaysEffect(camera, props.sun, props), [camera, props]);
241
- return /*#__PURE__*/React.createElement("primitive", {
249
+ return /*#__PURE__*/React__default.createElement("primitive", {
242
250
  ref: ref,
243
251
  object: effect,
244
252
  dispose: null
@@ -256,7 +264,7 @@ const Grid = /*#__PURE__*/forwardRef(function Grid(_ref, ref) {
256
264
  if (size) effect.setSize(size.width, size.height);
257
265
  invalidate();
258
266
  }, [effect, size]);
259
- return /*#__PURE__*/React.createElement("primitive", {
267
+ return /*#__PURE__*/React__default.createElement("primitive", {
260
268
  ref: ref,
261
269
  object: effect,
262
270
  dispose: null
@@ -265,7 +273,9 @@ const Grid = /*#__PURE__*/forwardRef(function Grid(_ref, ref) {
265
273
 
266
274
  const HueSaturation = wrapEffect(HueSaturationEffect);
267
275
 
268
- const Noise = wrapEffect(NoiseEffect, BlendFunction.COLOR_DODGE);
276
+ const Noise = wrapEffect(NoiseEffect, {
277
+ blendFunction: BlendFunction.COLOR_DODGE
278
+ });
269
279
 
270
280
  const selectionContext = /*#__PURE__*/createContext(null);
271
281
  function Selection(_ref) {
@@ -279,7 +289,7 @@ function Selection(_ref) {
279
289
  select,
280
290
  enabled
281
291
  }), [selected, select, enabled]);
282
- return /*#__PURE__*/React.createElement(selectionContext.Provider, {
292
+ return /*#__PURE__*/React__default.createElement(selectionContext.Provider, {
283
293
  value: value
284
294
  }, children);
285
295
  }
@@ -308,7 +318,7 @@ function Select(_ref2) {
308
318
  }
309
319
  }
310
320
  }, [enabled, children]);
311
- return /*#__PURE__*/React.createElement("group", _extends({
321
+ return /*#__PURE__*/React__default.createElement("group", _extends({
312
322
  ref: group
313
323
  }, props), children);
314
324
  }
@@ -381,7 +391,7 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
381
391
  }
382
392
  }
383
393
  }, [api]);
384
- return /*#__PURE__*/React.createElement("primitive", {
394
+ return /*#__PURE__*/React__default.createElement("primitive", {
385
395
  ref: forwardRef,
386
396
  object: effect
387
397
  });
@@ -394,14 +404,16 @@ const Pixelation = /*#__PURE__*/forwardRef(function Pixelation(_ref, ref) {
394
404
 
395
405
  /** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
396
406
  const effect = useMemo(() => new PixelationEffect(granularity), [granularity]);
397
- return /*#__PURE__*/React.createElement("primitive", {
407
+ return /*#__PURE__*/React__default.createElement("primitive", {
398
408
  ref: ref,
399
409
  object: effect,
400
410
  dispose: null
401
411
  });
402
412
  });
403
413
 
404
- const Scanline = wrapEffect(ScanlineEffect, BlendFunction.OVERLAY);
414
+ const Scanline = wrapEffect(ScanlineEffect, {
415
+ blendFunction: BlendFunction.OVERLAY
416
+ });
405
417
 
406
418
  const addLight = (light, effect) => light.layers.enable(effect.selection.layer);
407
419
 
@@ -488,7 +500,7 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
488
500
  }
489
501
  }
490
502
  }, [api]);
491
- return /*#__PURE__*/React.createElement("primitive", {
503
+ return /*#__PURE__*/React__default.createElement("primitive", {
492
504
  ref: forwardRef,
493
505
  object: effect,
494
506
  dispose: null
@@ -531,7 +543,7 @@ const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
531
543
  ...props
532
544
  });
533
545
  }, [camera, normalPass, props]);
534
- return /*#__PURE__*/React.createElement("primitive", {
546
+ return /*#__PURE__*/React__default.createElement("primitive", {
535
547
  ref: ref,
536
548
  object: effect,
537
549
  dispose: null
@@ -545,7 +557,7 @@ const SMAA = /*#__PURE__*/forwardRef(function SMAA(_ref, ref) {
545
557
  } = _ref;
546
558
  const smaaProps = useLoader(SMAAImageLoader, '');
547
559
  const effect = useMemo(() => new SMAAEffect(...smaaProps, preset, edgeDetectionMode), [smaaProps, preset, edgeDetectionMode]);
548
- return /*#__PURE__*/React.createElement("primitive", {
560
+ return /*#__PURE__*/React__default.createElement("primitive", {
549
561
  ref: ref,
550
562
  object: effect,
551
563
  dispose: null
@@ -566,7 +578,7 @@ const Texture = /*#__PURE__*/forwardRef(function Texture(_ref, ref) {
566
578
  const effect = useMemo(() => new TextureEffect({ ...props,
567
579
  texture: t || texture
568
580
  }), [props, t, texture]);
569
- return /*#__PURE__*/React.createElement("primitive", {
581
+ return /*#__PURE__*/React__default.createElement("primitive", {
570
582
  ref: ref,
571
583
  object: effect,
572
584
  dispose: null
@@ -592,54 +604,71 @@ const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
592
604
  if (tetrahedralInterpolation) effect.setTetrahedralInterpolationEnabled(tetrahedralInterpolation);
593
605
  invalidate();
594
606
  }, [effect, lut, tetrahedralInterpolation]);
595
- return /*#__PURE__*/React.createElement("primitive", {
607
+ return /*#__PURE__*/React__default.createElement("primitive", {
596
608
  ref: ref,
597
609
  object: effect,
598
610
  dispose: null
599
611
  });
600
612
  });
601
613
 
602
- const TiltShift = wrapEffect(TiltShiftEffect$1, BlendFunction.ADD);
614
+ const TiltShift = wrapEffect(TiltShiftEffect$1, {
615
+ blendFunction: BlendFunction.ADD
616
+ });
603
617
 
604
618
  const TiltShiftShader = {
605
619
  fragmentShader: `
620
+
606
621
  // original shader by Evan Wallace
622
+
623
+ #define MAX_ITERATIONS 100
624
+
607
625
  uniform float blur;
608
- uniform float gradient;
626
+ uniform float taper;
609
627
  uniform vec2 start;
610
628
  uniform vec2 end;
611
- uniform vec2 delta;
629
+ uniform vec2 direction;
630
+ uniform int samples;
612
631
 
613
632
  float random(vec3 scale, float seed) {
614
- /* use the fragment position for a different seed per-pixel */
615
- return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
633
+ /* use the fragment position for a different seed per-pixel */
634
+ return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
616
635
  }
617
636
 
618
637
  void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
619
-
620
638
  vec4 color = vec4(0.0);
621
639
  float total = 0.0;
622
640
  vec2 startPixel = vec2(start.x * resolution.x, start.y * resolution.y);
623
641
  vec2 endPixel = vec2(end.x * resolution.x, end.y * resolution.y);
642
+ float f_samples = float(samples);
643
+ float half_samples = f_samples / 2.0;
644
+
645
+ // use screen diagonal to normalize blur radii
646
+ float maxScreenDistance = distance(vec2(0.0), resolution); // diagonal distance
647
+ float gradientRadius = taper * (maxScreenDistance);
648
+ float blurRadius = blur * (maxScreenDistance / 16.0);
624
649
 
625
650
  /* randomize the lookup values to hide the fixed number of samples */
626
651
  float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
627
652
  vec2 normal = normalize(vec2(startPixel.y - endPixel.y, endPixel.x - startPixel.x));
628
- float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradient) * blur;
653
+ float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradientRadius) * blurRadius;
629
654
 
630
655
  #pragma unroll_loop_start
631
- for (float i = -3.0; i <= 3.0; i++) {
632
- float percent = (i + offset - 0.5) / 3.0;
656
+ for (int i = 0; i <= MAX_ITERATIONS; i++) {
657
+ if (i >= samples) { break; } // return early if over sample count
658
+ float f_i = float(i);
659
+ float s_i = -half_samples + f_i;
660
+ float percent = (s_i + offset - 0.5) / half_samples;
633
661
  float weight = 1.0 - abs(percent);
634
- vec4 sample_t = texture2D(inputBuffer, uv + delta / resolution * percent * radius);
662
+ vec4 sample_i = texture2D(inputBuffer, uv + normalize(direction) / resolution * percent * radius);
635
663
  /* switch to pre-multiplied alpha to correctly blur transparent images */
636
- sample_t.rgb *= sample_t.a;
637
- color += sample_t * weight;
664
+ sample_i.rgb *= sample_i.a;
665
+ color += sample_i * weight;
638
666
  total += weight;
639
667
  }
640
668
  #pragma unroll_loop_end
641
669
 
642
670
  outputColor = color / total;
671
+
643
672
  /* switch back from pre-multiplied alpha */
644
673
  outputColor.rgb /= outputColor.a + 0.00001;
645
674
  }
@@ -648,22 +677,29 @@ const TiltShiftShader = {
648
677
  class TiltShiftEffect extends Effect {
649
678
  constructor(_temp) {
650
679
  let {
651
- blendFunction = BlendFunction.ADD,
652
- blur = 20.0,
653
- gradient = 1100.0,
680
+ blendFunction = BlendFunction.NORMAL,
681
+ blur = 1.0,
682
+ // [0, 1], can go beyond 1 for extra
683
+ taper = 0.5,
684
+ // [0, 1], can go beyond 1 for extra
654
685
  start = [0.5, 0.0],
686
+ // [0,1] percentage x,y of screenspace
655
687
  end = [0.5, 1.0],
656
- delta = [1, 1]
688
+ // [0,1] percentage x,y of screenspace
689
+ samples = 10.0,
690
+ // number of blur samples
691
+ direction = [1, 1] // direction of blur
692
+
657
693
  } = _temp === void 0 ? {} : _temp;
658
694
  super('TiltShiftEffect', TiltShiftShader.fragmentShader, {
659
695
  blendFunction,
660
696
  attributes: EffectAttribute.CONVOLUTION,
661
- uniforms: new Map([['blur', new Uniform(blur)], ['gradient', new Uniform(gradient)], ['start', new Uniform(start)], ['end', new Uniform(end)], ['delta', new Uniform(delta)]])
697
+ uniforms: new Map([['blur', new Uniform(blur)], ['taper', new Uniform(taper)], ['start', new Uniform(start)], ['end', new Uniform(end)], ['samples', new Uniform(samples)], ['direction', new Uniform(direction)]])
662
698
  });
663
699
  }
664
700
 
665
701
  }
666
- const TiltShift2 = wrapEffect(TiltShiftEffect, BlendFunction.NORMAL);
702
+ const TiltShift2 = wrapEffect(TiltShiftEffect);
667
703
 
668
704
  const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
669
705
  let {
@@ -702,10 +738,10 @@ const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
702
738
  }
703
739
  }
704
740
  }, [api]);
705
- return /*#__PURE__*/React.createElement("primitive", {
741
+ return /*#__PURE__*/React__default.createElement("primitive", {
706
742
  ref: ref,
707
743
  object: effect
708
744
  });
709
745
  });
710
746
 
711
- export { Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DotScreen, EffectComposer, EffectComposerContext, Glitch, GodRays, Grid, HueSaturation, LUT, Noise, Outline, Pixelation, SMAA, SSAO, SSR, Scanline, Select, Selection, SelectiveBloom, Sepia, ShockWave, Texture, TiltShift, TiltShift2, TiltShiftEffect, ToneMapping, Vignette, selectionContext };
747
+ export { Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DotScreen, EffectComposer, EffectComposerContext, Glitch, GodRays, Grid, HueSaturation, LUT, Noise, Outline, Pixelation, SMAA, SSAO, SSR, Scanline, Select, Selection, SelectiveBloom, Sepia, ShockWave, Texture, TiltShift, TiltShift2, TiltShiftEffect, ToneMapping, Vignette, resolveRef, selectionContext, useVector2, wrapEffect };
package/dist/util.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import React, { MutableRefObject } from 'react';
2
- import { Vector2, Object3D } from 'three';
3
- import { Effect, BlendFunction } from 'postprocessing';
4
- declare type ObjectRef = MutableRefObject<Object3D>;
5
- export declare const resolveRef: (ref: Object3D | ObjectRef) => Object3D<import("three").Event>;
6
- export declare const wrapEffect: <T extends new (...args: any[]) => Effect>(effectImpl: T, defaultBlendMode?: BlendFunction) => React.ForwardRefExoticComponent<React.PropsWithoutRef<ConstructorParameters<T>[0] & Partial<{
7
- blendFunction: BlendFunction;
8
- opacity: number;
9
- }>> & React.RefAttributes<T>>;
10
- export declare const useVector2: (props: any, key: string) => Vector2;
11
- export {};
1
+ import * as React from 'react';
2
+ import * as THREE from 'three';
3
+ import { type ReactThreeFiber } from '@react-three/fiber';
4
+ import { type Effect, type BlendFunction } from 'postprocessing';
5
+ export declare const resolveRef: <T>(ref: T | React.MutableRefObject<T>) => T;
6
+ export declare type EffectConstructor = new (...args: any[]) => Effect;
7
+ export declare type EffectProps<T extends EffectConstructor> = ReactThreeFiber.Node<T extends Function ? T['prototype'] : InstanceType<T>, T> & ConstructorParameters<T>[0] & {
8
+ blendFunction?: BlendFunction;
9
+ opacity?: number;
10
+ };
11
+ export declare const wrapEffect: <T extends EffectConstructor, P extends EffectProps<T>>(effect: T, defaults?: P) => React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
12
+ export declare const useVector2: (props: object, key: string) => THREE.Vector2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/postprocessing",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",