@react-three/postprocessing 2.7.1 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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>>;
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import { BlendFunction, Effect } from 'postprocessing';
3
+ export declare class TiltShiftEffect extends Effect {
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
+ sampleCount, // number of blur samples
9
+ direction }?: {
10
+ blendFunction?: BlendFunction;
11
+ blur?: number;
12
+ taper?: number;
13
+ start?: number[];
14
+ end?: number[];
15
+ sampleCount?: number;
16
+ direction?: number[];
17
+ });
18
+ }
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" | "taper" | "start" | "end" | "sampleCount" | "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,73 +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
+ var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
13
14
  var screenSpaceReflections = require('screen-space-reflections');
14
15
 
15
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
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);
17
38
  var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
39
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
18
40
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
19
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
20
- var _construct__default = /*#__PURE__*/_interopDefaultLegacy(_construct);
41
+ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
42
+ var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
21
43
 
22
44
  var _excluded$9 = ["blendFunction", "opacity"];
23
-
24
- var isRef = function isRef(ref) {
25
- return !!ref.current;
26
- };
27
-
28
45
  var resolveRef = function resolveRef(ref) {
29
- return isRef(ref) ? ref.current : ref;
46
+ return typeof ref === 'object' && 'current' in ref ? ref.current : ref;
30
47
  };
31
- var wrapEffect = function wrapEffect(effectImpl, defaultBlendMode) {
32
- if (defaultBlendMode === void 0) {
33
- defaultBlendMode = postprocessing.BlendFunction.NORMAL;
34
- }
35
-
36
- return /*#__PURE__*/React.forwardRef(function Wrap(_ref, ref) {
37
- var blendFunction = _ref.blendFunction,
38
- 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,
39
56
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$9);
40
57
 
41
- var invalidate = fiber.useThree(function (state) {
42
- 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;
43
70
  });
44
- var effect = React.useMemo(function () {
45
- return new effectImpl(props);
46
- }, [props]);
47
- React.useLayoutEffect(function () {
48
- effect.blendMode.blendFunction = !blendFunction && blendFunction !== 0 ? defaultBlendMode : blendFunction;
49
- if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
50
- invalidate();
51
- }, [blendFunction, effect.blendMode, opacity]);
52
- 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, {
53
82
  ref: ref,
54
- object: effect,
55
- dispose: null
56
- });
83
+ args: args
84
+ }));
57
85
  });
58
86
  };
59
87
  var useVector2 = function useVector2(props, key) {
60
- var vec = props[key];
61
- return React.useMemo(function () {
62
- if (vec instanceof three.Vector2) {
63
- return new three.Vector2().set(vec.x, vec.y);
64
- } else if (Array.isArray(vec)) {
65
- var x = vec[0],
66
- y = vec[1];
67
- return new three.Vector2().set(x, y);
68
- }
69
- }, [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]);
70
92
  };
71
93
 
72
- var Bloom = wrapEffect(postprocessing.BloomEffect, postprocessing.BlendFunction.ADD);
94
+ var Bloom = wrapEffect(postprocessing.BloomEffect, {
95
+ blendFunction: postprocessing.BlendFunction.ADD
96
+ });
73
97
 
74
98
  var BrightnessContrast = wrapEffect(postprocessing.BrightnessContrastEffect);
75
99
 
@@ -124,7 +148,7 @@ var EffectComposer = /*#__PURE__*/React__default["default"].memo( /*#__PURE__*/R
124
148
  _ref$multisampling = _ref.multisampling,
125
149
  multisampling = _ref$multisampling === void 0 ? 8 : _ref$multisampling,
126
150
  _ref$frameBufferType = _ref.frameBufferType,
127
- frameBufferType = _ref$frameBufferType === void 0 ? three.HalfFloatType : _ref$frameBufferType;
151
+ frameBufferType = _ref$frameBufferType === void 0 ? THREE.HalfFloatType : _ref$frameBufferType;
128
152
 
129
153
  var _useThree = fiber.useThree(),
130
154
  gl = _useThree.gl,
@@ -241,7 +265,7 @@ var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref
241
265
  }, [camera, props]);
242
266
  React.useLayoutEffect(function () {
243
267
  if (target) {
244
- 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]);
245
269
  effect.target = vec;
246
270
  }
247
271
 
@@ -325,7 +349,9 @@ var Grid = /*#__PURE__*/React.forwardRef(function Grid(_ref, ref) {
325
349
 
326
350
  var HueSaturation = wrapEffect(postprocessing.HueSaturationEffect);
327
351
 
328
- var Noise = wrapEffect(postprocessing.NoiseEffect, postprocessing.BlendFunction.COLOR_DODGE);
352
+ var Noise = wrapEffect(postprocessing.NoiseEffect, {
353
+ blendFunction: postprocessing.BlendFunction.COLOR_DODGE
354
+ });
329
355
 
330
356
  var _excluded$5 = ["enabled", "children"];
331
357
  var selectionContext = /*#__PURE__*/React.createContext(null);
@@ -480,7 +506,9 @@ var Pixelation = /*#__PURE__*/React.forwardRef(function Pixelation(_ref, ref) {
480
506
  });
481
507
  });
482
508
 
483
- var Scanline = wrapEffect(postprocessing.ScanlineEffect, postprocessing.BlendFunction.OVERLAY);
509
+ var Scanline = wrapEffect(postprocessing.ScanlineEffect, {
510
+ blendFunction: postprocessing.BlendFunction.OVERLAY
511
+ });
484
512
 
485
513
  var _excluded$3 = ["selection", "selectionLayer", "lights", "luminanceThreshold", "luminanceSmoothing", "intensity", "width", "height", "kernelSize", "mipmapBlur", "radius", "levels"];
486
514
 
@@ -653,10 +681,10 @@ var Texture = /*#__PURE__*/React.forwardRef(function Texture(_ref, ref) {
653
681
  texture = _ref.texture,
654
682
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$2);
655
683
 
656
- var t = fiber.useLoader(three.TextureLoader, textureSrc);
684
+ var t = fiber.useLoader(THREE.TextureLoader, textureSrc);
657
685
  React.useLayoutEffect(function () {
658
- t.encoding = three.sRGBEncoding;
659
- t.wrapS = t.wrapT = three.RepeatWrapping;
686
+ t.encoding = THREE.sRGBEncoding;
687
+ t.wrapS = t.wrapT = THREE.RepeatWrapping;
660
688
  }, [t]);
661
689
  var effect = React.useMemo(function () {
662
690
  return new postprocessing.TextureEffect(_extends__default["default"]({}, props, {
@@ -700,7 +728,43 @@ var LUT = /*#__PURE__*/React.forwardRef(function LUT(_ref, ref) {
700
728
  });
701
729
  });
702
730
 
703
- var TiltShift = wrapEffect(postprocessing.TiltShiftEffect, postprocessing.BlendFunction.ADD);
731
+ var TiltShift = wrapEffect(postprocessing.TiltShiftEffect, {
732
+ blendFunction: postprocessing.BlendFunction.ADD
733
+ });
734
+
735
+ var TiltShiftShader = {
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 sampleCount;\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(sampleCount);\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 >= sampleCount) { 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 "
737
+ };
738
+ var TiltShiftEffect = /*#__PURE__*/function (_Effect) {
739
+ _inheritsLoose__default["default"](TiltShiftEffect, _Effect);
740
+
741
+ function TiltShiftEffect(_temp) {
742
+ var _ref = _temp === void 0 ? {} : _temp,
743
+ _ref$blendFunction = _ref.blendFunction,
744
+ blendFunction = _ref$blendFunction === void 0 ? postprocessing.BlendFunction.NORMAL : _ref$blendFunction,
745
+ _ref$blur = _ref.blur,
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,
749
+ _ref$start = _ref.start,
750
+ start = _ref$start === void 0 ? [0.5, 0.0] : _ref$start,
751
+ _ref$end = _ref.end,
752
+ end = _ref$end === void 0 ? [0.5, 1.0] : _ref$end,
753
+ _ref$sampleCount = _ref.sampleCount,
754
+ sampleCount = _ref$sampleCount === void 0 ? 10.0 : _ref$sampleCount,
755
+ _ref$direction = _ref.direction,
756
+ direction = _ref$direction === void 0 ? [1, 1] : _ref$direction;
757
+
758
+ return _Effect.call(this, 'TiltShiftEffect', TiltShiftShader.fragmentShader, {
759
+ blendFunction: blendFunction,
760
+ attributes: postprocessing.EffectAttribute.CONVOLUTION,
761
+ uniforms: new Map([['blur', new THREE.Uniform(blur)], ['taper', new THREE.Uniform(taper)], ['start', new THREE.Uniform(start)], ['end', new THREE.Uniform(end)], ['sampleCount', new THREE.Uniform(sampleCount)], ['direction', new THREE.Uniform(direction)]])
762
+ }) || this;
763
+ }
764
+
765
+ return TiltShiftEffect;
766
+ }(postprocessing.Effect);
767
+ var TiltShift2 = wrapEffect(TiltShiftEffect);
704
768
 
705
769
  var _excluded = ["ENABLE_BLUR", "USE_MRT"];
706
770
 
@@ -780,6 +844,11 @@ exports.Sepia = Sepia;
780
844
  exports.ShockWave = ShockWave;
781
845
  exports.Texture = Texture;
782
846
  exports.TiltShift = TiltShift;
847
+ exports.TiltShift2 = TiltShift2;
848
+ exports.TiltShiftEffect = TiltShiftEffect;
783
849
  exports.ToneMapping = ToneMapping;
784
850
  exports.Vignette = Vignette;
851
+ exports.resolveRef = resolveRef;
785
852
  exports.selectionContext = selectionContext;
853
+ exports.useVector2 = useVector2;
854
+ exports.wrapEffect = wrapEffect;
package/dist/index.d.ts CHANGED
@@ -24,6 +24,8 @@ export * from './effects/Vignette';
24
24
  export * from './effects/ShockWave';
25
25
  export * from './effects/LUT';
26
26
  export * from './effects/TiltShift';
27
+ export * from './effects/TiltShift2';
27
28
  export * from './effects/SSR';
28
29
  export * from './Selection';
29
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 } from 'postprocessing';
2
- import React, { forwardRef, useMemo, useLayoutEffect, createContext, useEffect, useRef, useImperativeHandle, useContext, useState } from 'react';
3
- import { Vector2, HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping } 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,14 +604,102 @@ 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, BlendFunction.ADD);
614
+ const TiltShift = wrapEffect(TiltShiftEffect$1, {
615
+ blendFunction: BlendFunction.ADD
616
+ });
617
+
618
+ const TiltShiftShader = {
619
+ fragmentShader: `
620
+
621
+ // original shader by Evan Wallace
622
+
623
+ #define MAX_ITERATIONS 100
624
+
625
+ uniform float blur;
626
+ uniform float taper;
627
+ uniform vec2 start;
628
+ uniform vec2 end;
629
+ uniform vec2 direction;
630
+ uniform int sampleCount;
631
+
632
+ float random(vec3 scale, float 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);
635
+ }
636
+
637
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
638
+ vec4 color = vec4(0.0);
639
+ float total = 0.0;
640
+ vec2 startPixel = vec2(start.x * resolution.x, start.y * resolution.y);
641
+ vec2 endPixel = vec2(end.x * resolution.x, end.y * resolution.y);
642
+ float f_samples = float(sampleCount);
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);
649
+
650
+ /* randomize the lookup values to hide the fixed number of samples */
651
+ float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
652
+ vec2 normal = normalize(vec2(startPixel.y - endPixel.y, endPixel.x - startPixel.x));
653
+ float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradientRadius) * blurRadius;
654
+
655
+ #pragma unroll_loop_start
656
+ for (int i = 0; i <= MAX_ITERATIONS; i++) {
657
+ if (i >= sampleCount) { 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;
661
+ float weight = 1.0 - abs(percent);
662
+ vec4 sample_i = texture2D(inputBuffer, uv + normalize(direction) / resolution * percent * radius);
663
+ /* switch to pre-multiplied alpha to correctly blur transparent images */
664
+ sample_i.rgb *= sample_i.a;
665
+ color += sample_i * weight;
666
+ total += weight;
667
+ }
668
+ #pragma unroll_loop_end
669
+
670
+ outputColor = color / total;
671
+
672
+ /* switch back from pre-multiplied alpha */
673
+ outputColor.rgb /= outputColor.a + 0.00001;
674
+ }
675
+ `
676
+ };
677
+ class TiltShiftEffect extends Effect {
678
+ constructor(_temp) {
679
+ let {
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
685
+ start = [0.5, 0.0],
686
+ // [0,1] percentage x,y of screenspace
687
+ end = [0.5, 1.0],
688
+ // [0,1] percentage x,y of screenspace
689
+ sampleCount = 10.0,
690
+ // number of blur samples
691
+ direction = [1, 1] // direction of blur
692
+
693
+ } = _temp === void 0 ? {} : _temp;
694
+ super('TiltShiftEffect', TiltShiftShader.fragmentShader, {
695
+ blendFunction,
696
+ attributes: EffectAttribute.CONVOLUTION,
697
+ uniforms: new Map([['blur', new Uniform(blur)], ['taper', new Uniform(taper)], ['start', new Uniform(start)], ['end', new Uniform(end)], ['sampleCount', new Uniform(sampleCount)], ['direction', new Uniform(direction)]])
698
+ });
699
+ }
700
+
701
+ }
702
+ const TiltShift2 = wrapEffect(TiltShiftEffect);
603
703
 
604
704
  const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
605
705
  let {
@@ -638,10 +738,10 @@ const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
638
738
  }
639
739
  }
640
740
  }, [api]);
641
- return /*#__PURE__*/React.createElement("primitive", {
741
+ return /*#__PURE__*/React__default.createElement("primitive", {
642
742
  ref: ref,
643
743
  object: effect
644
744
  });
645
745
  });
646
746
 
647
- 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, 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.7.1",
3
+ "version": "2.8.1",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",