@react-three/postprocessing 2.8.3 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,24 +1,22 @@
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';
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, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUT3DEffect, TiltShiftEffect as TiltShiftEffect$1, Effect, EffectAttribute } from 'postprocessing';
2
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';
3
+ import React$1, { forwardRef, useMemo, createContext, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState } from 'react';
5
4
  import * as THREE from 'three';
6
5
  import { HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
7
- import { extend, useThree, useFrame, useLoader } from '@react-three/fiber';
6
+ import { extend, useThree, useFrame, useInstanceHandle, useLoader } from '@react-three/fiber';
8
7
  import { isWebGL2Available } from 'three-stdlib';
9
8
  import { SSREffect } from 'screen-space-reflections';
10
9
 
11
- const resolveRef = ref => typeof ref === 'object' && 'current' in ref ? ref.current : ref;
10
+ const resolveRef = ref => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref;
12
11
  let i = 0;
13
12
  const components = new WeakMap();
14
- const wrapEffect = (effect, defaults) => /* @__PURE__ */React.forwardRef(function Effect(_ref, ref) {
13
+ const wrapEffect = (effect, defaults) => /* @__PURE__ */React$1.forwardRef(function Effect(_ref, ref) {
15
14
  let {
16
15
  blendFunction = defaults == null ? void 0 : defaults.blendFunction,
17
16
  opacity = defaults == null ? void 0 : defaults.opacity,
18
17
  ...props
19
18
  } = _ref;
20
19
  let Component = components.get(effect);
21
-
22
20
  if (!Component) {
23
21
  const key = `@react-three/postprocessing/${effect.name}-${i++}`;
24
22
  extend({
@@ -26,17 +24,17 @@ const wrapEffect = (effect, defaults) => /* @__PURE__ */React.forwardRef(functio
26
24
  });
27
25
  components.set(effect, Component = key);
28
26
  }
29
-
30
27
  const camera = useThree(state => state.camera);
31
- const args = React.useMemo(() => {
28
+ const args = React$1.useMemo(() => {
32
29
  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,
30
+ return [...((_defaults$args = defaults == null ? void 0 : defaults.args) != null ? _defaults$args : []), ...((_props$args = props.args) != null ? _props$args : [{
31
+ ...defaults,
35
32
  ...props
36
33
  }])];
37
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ },
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
36
  [JSON.stringify(props)]);
39
- return /*#__PURE__*/React.createElement(Component, _extends({
37
+ return /*#__PURE__*/React$1.createElement(Component, _extends({
40
38
  camera: camera,
41
39
  "blendMode-blendFunction": blendFunction,
42
40
  "blendMode-opacity": opacity
@@ -47,7 +45,7 @@ const wrapEffect = (effect, defaults) => /* @__PURE__ */React.forwardRef(functio
47
45
  });
48
46
  const useVector2 = (props, key) => {
49
47
  const value = props[key];
50
- return React.useMemo(() => {
48
+ return React$1.useMemo(() => {
51
49
  if (typeof value === 'number') return new THREE.Vector2(value, value);else if (value) return new THREE.Vector2(...value);else return new THREE.Vector2();
52
50
  }, [value]);
53
51
  };
@@ -58,12 +56,15 @@ const Bloom = wrapEffect(BloomEffect, {
58
56
 
59
57
  const BrightnessContrast = wrapEffect(BrightnessContrastEffect);
60
58
 
59
+ // type for function args should use constructor args
60
+
61
61
  const ChromaticAberration = /*#__PURE__*/forwardRef(function ChromaticAberration(props, ref) {
62
62
  const offset = useVector2(props, 'offset');
63
- const effect = useMemo(() => new ChromaticAberrationEffect({ ...props,
63
+ const effect = useMemo(() => new ChromaticAberrationEffect({
64
+ ...props,
64
65
  offset
65
66
  }), [offset, props]);
66
- return /*#__PURE__*/React__default.createElement("primitive", {
67
+ return /*#__PURE__*/React$1.createElement("primitive", {
67
68
  ref: ref,
68
69
  object: effect,
69
70
  dispose: null
@@ -74,10 +75,9 @@ const ColorAverage = /*#__PURE__*/forwardRef(function ColorAverage(_ref, ref) {
74
75
  let {
75
76
  blendFunction = BlendFunction.NORMAL
76
77
  } = _ref;
77
-
78
78
  /** Because ColorAverage blendFunction is not an object but a number, we have to define a custom prop "blendFunction" */
79
79
  const effect = useMemo(() => new ColorAverageEffect(blendFunction), [blendFunction]);
80
- return /*#__PURE__*/React__default.createElement("primitive", {
80
+ return /*#__PURE__*/React$1.createElement("primitive", {
81
81
  ref: ref,
82
82
  object: effect,
83
83
  dispose: null
@@ -89,11 +89,11 @@ const ColorDepth = wrapEffect(ColorDepthEffect);
89
89
  const Depth = wrapEffect(DepthEffect);
90
90
 
91
91
  const EffectComposerContext = /*#__PURE__*/createContext(null);
92
- const EffectComposer = /*#__PURE__*/React__default.memo( /*#__PURE__*/forwardRef((_ref, ref) => {
92
+ const EffectComposer = /*#__PURE__*/React$1.memo( /*#__PURE__*/forwardRef((_ref, ref) => {
93
93
  let {
94
94
  children,
95
- camera,
96
- scene,
95
+ camera: _camera,
96
+ scene: _scene,
97
97
  resolutionScale,
98
98
  enabled = true,
99
99
  renderPriority = 1,
@@ -110,28 +110,28 @@ const EffectComposer = /*#__PURE__*/React__default.memo( /*#__PURE__*/forwardRef
110
110
  camera: defaultCamera,
111
111
  size
112
112
  } = useThree();
113
- scene = scene || defaultScene;
114
- camera = camera || defaultCamera;
113
+ const scene = _scene || defaultScene;
114
+ const camera = _camera || defaultCamera;
115
115
  const [composer, normalPass, downSamplingPass] = useMemo(() => {
116
- const webGL2Available = isWebGL2Available(); // Initialize composer
117
-
116
+ const webGL2Available = isWebGL2Available();
117
+ // Initialize composer
118
118
  const effectComposer = new EffectComposer$1(gl, {
119
119
  depthBuffer,
120
120
  stencilBuffer,
121
121
  multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
122
122
  frameBufferType
123
- }); // Add render pass
123
+ });
124
124
 
125
- effectComposer.addPass(new RenderPass(scene, camera)); // Create normal pass
125
+ // Add render pass
126
+ effectComposer.addPass(new RenderPass(scene, camera));
126
127
 
128
+ // Create normal pass
127
129
  let downSamplingPass = null;
128
130
  let normalPass = null;
129
-
130
131
  if (!disableNormalPass) {
131
132
  normalPass = new NormalPass(scene, camera);
132
133
  normalPass.enabled = false;
133
134
  effectComposer.addPass(normalPass);
134
-
135
135
  if (resolutionScale !== undefined && webGL2Available) {
136
136
  downSamplingPass = new DepthDownsamplingPass({
137
137
  normalBuffer: normalPass.texture,
@@ -141,7 +141,6 @@ const EffectComposer = /*#__PURE__*/React__default.memo( /*#__PURE__*/forwardRef
141
141
  effectComposer.addPass(downSamplingPass);
142
142
  }
143
143
  }
144
-
145
144
  return [effectComposer, normalPass, downSamplingPass];
146
145
  }, [camera, gl, depthBuffer, stencilBuffer, multisampling, frameBufferType, scene, disableNormalPass, resolutionScale]);
147
146
  useEffect(() => composer == null ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
@@ -152,24 +151,24 @@ const EffectComposer = /*#__PURE__*/React__default.memo( /*#__PURE__*/forwardRef
152
151
  }
153
152
  }, enabled ? renderPriority : 0);
154
153
  const group = useRef(null);
154
+ const instance = useInstanceHandle(group);
155
155
  useLayoutEffect(() => {
156
156
  let effectPass;
157
-
158
- if (group.current && group.current.__r3f && composer) {
159
- effectPass = new EffectPass(camera, ...group.current.__r3f.objects);
157
+ if (group.current && instance.current && composer) {
158
+ effectPass = new EffectPass(camera, ...instance.current.objects);
160
159
  effectPass.renderToScreen = true;
161
160
  composer.addPass(effectPass);
162
161
  if (normalPass) normalPass.enabled = true;
163
162
  if (downSamplingPass) downSamplingPass.enabled = true;
164
163
  }
165
-
166
164
  return () => {
167
165
  if (effectPass) composer == null ? void 0 : composer.removePass(effectPass);
168
166
  if (normalPass) normalPass.enabled = false;
169
167
  if (downSamplingPass) downSamplingPass.enabled = false;
170
168
  };
171
- }, [composer, children, camera, normalPass, downSamplingPass]); // Memoize state, otherwise it would trigger all consumers on every render
169
+ }, [composer, children, camera, normalPass, downSamplingPass, instance]);
172
170
 
171
+ // Memoize state, otherwise it would trigger all consumers on every render
173
172
  const state = useMemo(() => ({
174
173
  composer,
175
174
  normalPass,
@@ -177,12 +176,13 @@ const EffectComposer = /*#__PURE__*/React__default.memo( /*#__PURE__*/forwardRef
177
176
  resolutionScale,
178
177
  camera,
179
178
  scene
180
- }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]); // Expose the composer
179
+ }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]);
181
180
 
181
+ // Expose the composer
182
182
  useImperativeHandle(ref, () => composer, [composer]);
183
- return /*#__PURE__*/React__default.createElement(EffectComposerContext.Provider, {
183
+ return /*#__PURE__*/React$1.createElement(EffectComposerContext.Provider, {
184
184
  value: state
185
- }, /*#__PURE__*/React__default.createElement("group", {
185
+ }, /*#__PURE__*/React$1.createElement("group", {
186
186
  ref: group
187
187
  }, children));
188
188
  }));
@@ -199,15 +199,14 @@ const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
199
199
  } = useContext(EffectComposerContext);
200
200
  const effect = useMemo(() => new DepthOfFieldEffect(camera, props), [camera, props]);
201
201
  useLayoutEffect(() => {
202
- if (target) {
202
+ if (target && typeof target !== 'number') {
203
203
  const vec = target instanceof Vector3 ? new Vector3().set(target.x, target.y, target.z) : new Vector3().set(target[0], target[1], target[2]);
204
204
  effect.target = vec;
205
205
  }
206
-
207
206
  if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
208
207
  invalidate();
209
208
  }, [target, depthTexture, effect]);
210
- return /*#__PURE__*/React__default.createElement("primitive", {
209
+ return /*#__PURE__*/React.createElement("primitive", {
211
210
  ref: ref,
212
211
  object: effect,
213
212
  dispose: null
@@ -225,7 +224,8 @@ const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
225
224
  const delay = useVector2(props, 'delay');
226
225
  const duration = useVector2(props, 'duration');
227
226
  const strength = useVector2(props, 'strength');
228
- const effect = useMemo(() => new GlitchEffect({ ...props,
227
+ const effect = useMemo(() => new GlitchEffect({
228
+ ...props,
229
229
  delay,
230
230
  duration,
231
231
  strength
@@ -233,8 +233,8 @@ const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
233
233
  useLayoutEffect(() => {
234
234
  effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED;
235
235
  invalidate();
236
- }, [active, effect, props.mode]);
237
- return /*#__PURE__*/React__default.createElement("primitive", {
236
+ }, [active, effect, invalidate, props.mode]);
237
+ return /*#__PURE__*/React.createElement("primitive", {
238
238
  ref: ref,
239
239
  object: effect,
240
240
  dispose: null
@@ -246,7 +246,7 @@ const GodRays = /*#__PURE__*/forwardRef(function GodRays(props, ref) {
246
246
  camera
247
247
  } = useContext(EffectComposerContext);
248
248
  const effect = useMemo(() => new GodRaysEffect(camera, props.sun, props), [camera, props]);
249
- return /*#__PURE__*/React__default.createElement("primitive", {
249
+ return /*#__PURE__*/React$1.createElement("primitive", {
250
250
  ref: ref,
251
251
  object: effect,
252
252
  dispose: null
@@ -264,7 +264,7 @@ const Grid = /*#__PURE__*/forwardRef(function Grid(_ref, ref) {
264
264
  if (size) effect.setSize(size.width, size.height);
265
265
  invalidate();
266
266
  }, [effect, size]);
267
- return /*#__PURE__*/React__default.createElement("primitive", {
267
+ return /*#__PURE__*/React$1.createElement("primitive", {
268
268
  ref: ref,
269
269
  object: effect,
270
270
  dispose: null
@@ -289,7 +289,7 @@ function Selection(_ref) {
289
289
  select,
290
290
  enabled
291
291
  }), [selected, select, enabled]);
292
- return /*#__PURE__*/React__default.createElement(selectionContext.Provider, {
292
+ return /*#__PURE__*/React$1.createElement(selectionContext.Provider, {
293
293
  value: value
294
294
  }, children);
295
295
  }
@@ -309,7 +309,6 @@ function Select(_ref2) {
309
309
  o.type === 'Mesh' && current.push(o);
310
310
  if (api.selected.indexOf(o) === -1) changed = true;
311
311
  });
312
-
313
312
  if (changed) {
314
313
  api.select(state => [...state, ...current]);
315
314
  return () => {
@@ -318,7 +317,7 @@ function Select(_ref2) {
318
317
  }
319
318
  }
320
319
  }, [enabled, children]);
321
- return /*#__PURE__*/React__default.createElement("group", _extends({
320
+ return /*#__PURE__*/React$1.createElement("group", _extends({
322
321
  ref: group
323
322
  }, props), children);
324
323
  }
@@ -358,7 +357,7 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
358
357
  blur,
359
358
  xRay,
360
359
  ...props
361
- }), [blendFunction, blur, camera, edgeStrength, height, hiddenEdgeColor, kernelSize, patternTexture, pulseSpeed, scene, visibleEdgeColor, width, xRay]);
360
+ }), [blendFunction, blur, camera, edgeStrength, height, hiddenEdgeColor, kernelSize, patternTexture, props, pulseSpeed, scene, visibleEdgeColor, width, xRay]);
362
361
  const api = useContext(selectionContext);
363
362
  useEffect(() => {
364
363
  // Do not allow array selection if declarative selection is active
@@ -371,16 +370,15 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
371
370
  invalidate();
372
371
  };
373
372
  }
374
- }, [effect, selection, api]);
373
+ }, [effect, selection, api, invalidate]);
375
374
  useEffect(() => {
376
375
  effect.selectionLayer = selectionLayer;
377
376
  invalidate();
378
- }, [effect, selectionLayer]);
377
+ }, [effect, invalidate, selectionLayer]);
379
378
  useRef();
380
379
  useEffect(() => {
381
380
  if (api && api.enabled) {
382
381
  var _api$selected;
383
-
384
382
  if ((_api$selected = api.selected) != null && _api$selected.length) {
385
383
  effect.selection.set(api.selected);
386
384
  invalidate();
@@ -390,8 +388,8 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
390
388
  };
391
389
  }
392
390
  }
393
- }, [api]);
394
- return /*#__PURE__*/React__default.createElement("primitive", {
391
+ }, [api, effect.selection, invalidate]);
392
+ return /*#__PURE__*/React.createElement("primitive", {
395
393
  ref: forwardRef,
396
394
  object: effect
397
395
  });
@@ -401,10 +399,9 @@ const Pixelation = /*#__PURE__*/forwardRef(function Pixelation(_ref, ref) {
401
399
  let {
402
400
  granularity = 5
403
401
  } = _ref;
404
-
405
402
  /** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
406
403
  const effect = useMemo(() => new PixelationEffect(granularity), [granularity]);
407
- return /*#__PURE__*/React__default.createElement("primitive", {
404
+ return /*#__PURE__*/React$1.createElement("primitive", {
408
405
  ref: ref,
409
406
  object: effect,
410
407
  dispose: null
@@ -416,9 +413,7 @@ const Scanline = wrapEffect(ScanlineEffect, {
416
413
  });
417
414
 
418
415
  const addLight = (light, effect) => light.layers.enable(effect.selection.layer);
419
-
420
416
  const removeLight = (light, effect) => light.layers.disable(effect.selection.layer);
421
-
422
417
  const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, forwardRef) {
423
418
  let {
424
419
  selection = [],
@@ -431,15 +426,11 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
431
426
  height,
432
427
  kernelSize,
433
428
  mipmapBlur,
434
- radius,
435
- levels,
436
429
  ...props
437
430
  } = _ref;
438
-
439
431
  if (lights.length === 0) {
440
432
  console.warn('SelectiveBloom requires lights to work.');
441
433
  }
442
-
443
434
  const invalidate = useThree(state => state.invalidate);
444
435
  const {
445
436
  scene,
@@ -454,10 +445,8 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
454
445
  height,
455
446
  kernelSize,
456
447
  mipmapBlur,
457
- radius,
458
- levels,
459
448
  ...props
460
- }), [camera, height, intensity, kernelSize, luminanceSmoothing, luminanceThreshold, scene, width, height, mipmapBlur, radius, levels]);
449
+ }), [scene, camera, luminanceThreshold, luminanceSmoothing, intensity, width, height, kernelSize, mipmapBlur, props]);
461
450
  const api = useContext(selectionContext);
462
451
  useEffect(() => {
463
452
  // Do not allow array selection if declarative selection is active
@@ -470,11 +459,11 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
470
459
  invalidate();
471
460
  };
472
461
  }
473
- }, [effect, selection, api]);
462
+ }, [effect, selection, api, invalidate]);
474
463
  useEffect(() => {
475
464
  effect.selection.layer = selectionLayer;
476
465
  invalidate();
477
- }, [effect, selectionLayer]);
466
+ }, [effect, invalidate, selectionLayer]);
478
467
  useEffect(() => {
479
468
  if (lights && lights.length > 0) {
480
469
  lights.forEach(light => addLight(resolveRef(light), effect));
@@ -484,12 +473,11 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
484
473
  invalidate();
485
474
  };
486
475
  }
487
- }, [effect, lights, selectionLayer]);
476
+ }, [effect, invalidate, lights, selectionLayer]);
488
477
  useRef();
489
478
  useEffect(() => {
490
479
  if (api && api.enabled) {
491
480
  var _api$selected;
492
-
493
481
  if ((_api$selected = api.selected) != null && _api$selected.length) {
494
482
  effect.selection.set(api.selected);
495
483
  invalidate();
@@ -499,8 +487,8 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
499
487
  };
500
488
  }
501
489
  }
502
- }, [api]);
503
- return /*#__PURE__*/React__default.createElement("primitive", {
490
+ }, [api, effect.selection, invalidate]);
491
+ return /*#__PURE__*/React$1.createElement("primitive", {
504
492
  ref: forwardRef,
505
493
  object: effect,
506
494
  dispose: null
@@ -509,6 +497,8 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
509
497
 
510
498
  const Sepia = wrapEffect(SepiaEffect);
511
499
 
500
+ // first two args are camera and texture
501
+
512
502
  const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
513
503
  const {
514
504
  camera,
@@ -519,9 +509,8 @@ const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
519
509
  const effect = useMemo(() => {
520
510
  if (normalPass === null && downSamplingPass === null) {
521
511
  console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.');
522
- return null;
512
+ return {};
523
513
  }
524
-
525
514
  return new SSAOEffect(camera, normalPass && !downSamplingPass ? normalPass.texture : null, {
526
515
  blendFunction: BlendFunction.MULTIPLY,
527
516
  samples: 30,
@@ -532,10 +521,9 @@ const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
532
521
  rangeFalloff: 0.1,
533
522
  luminanceInfluence: 0.9,
534
523
  radius: 20,
535
- scale: 0.5,
536
524
  bias: 0.5,
537
525
  intensity: 1.0,
538
- color: null,
526
+ color: undefined,
539
527
  // @ts-ignore
540
528
  normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
541
529
  resolutionScale: resolutionScale != null ? resolutionScale : 1,
@@ -543,26 +531,14 @@ const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
543
531
  ...props
544
532
  });
545
533
  }, [camera, normalPass, props]);
546
- return /*#__PURE__*/React__default.createElement("primitive", {
534
+ return /*#__PURE__*/React.createElement("primitive", {
547
535
  ref: ref,
548
536
  object: effect,
549
537
  dispose: null
550
538
  });
551
539
  });
552
540
 
553
- const SMAA = /*#__PURE__*/forwardRef(function SMAA(_ref, ref) {
554
- let {
555
- preset = SMAAPreset.HIGH,
556
- edgeDetectionMode = EdgeDetectionMode.COLOR
557
- } = _ref;
558
- const smaaProps = useLoader(SMAAImageLoader, '');
559
- const effect = useMemo(() => new SMAAEffect(...smaaProps, preset, edgeDetectionMode), [smaaProps, preset, edgeDetectionMode]);
560
- return /*#__PURE__*/React__default.createElement("primitive", {
561
- ref: ref,
562
- object: effect,
563
- dispose: null
564
- });
565
- });
541
+ const SMAA = wrapEffect(SMAAEffect);
566
542
 
567
543
  const Texture = /*#__PURE__*/forwardRef(function Texture(_ref, ref) {
568
544
  let {
@@ -575,10 +551,11 @@ const Texture = /*#__PURE__*/forwardRef(function Texture(_ref, ref) {
575
551
  t.encoding = sRGBEncoding;
576
552
  t.wrapS = t.wrapT = RepeatWrapping;
577
553
  }, [t]);
578
- const effect = useMemo(() => new TextureEffect({ ...props,
554
+ const effect = useMemo(() => new TextureEffect({
555
+ ...props,
579
556
  texture: t || texture
580
557
  }), [props, t, texture]);
581
- return /*#__PURE__*/React__default.createElement("primitive", {
558
+ return /*#__PURE__*/React.createElement("primitive", {
582
559
  ref: ref,
583
560
  object: effect,
584
561
  dispose: null
@@ -597,14 +574,14 @@ const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
597
574
  tetrahedralInterpolation,
598
575
  ...props
599
576
  } = _ref;
577
+ const effect = useMemo(() => new LUT3DEffect(lut, props), [lut, props]);
600
578
  const invalidate = useThree(state => state.invalidate);
601
- const effect = useMemo(() => new LUTEffect(lut, props), [lut, props]);
602
579
  useLayoutEffect(() => {
603
- if (lut) effect.setLUT(lut);
604
- if (tetrahedralInterpolation) effect.setTetrahedralInterpolationEnabled(tetrahedralInterpolation);
580
+ if (tetrahedralInterpolation) effect.tetrahedralInterpolation = tetrahedralInterpolation;
581
+ if (lut) effect.lut = lut;
605
582
  invalidate();
606
- }, [effect, lut, tetrahedralInterpolation]);
607
- return /*#__PURE__*/React__default.createElement("primitive", {
583
+ }, [effect, invalidate, lut, tetrahedralInterpolation]);
584
+ return /*#__PURE__*/React$1.createElement("primitive", {
608
585
  ref: ref,
609
586
  object: effect,
610
587
  dispose: null
@@ -689,7 +666,6 @@ class TiltShiftEffect extends Effect {
689
666
  samples = 10.0,
690
667
  // number of blur samples
691
668
  direction = [1, 1] // direction of blur
692
-
693
669
  } = _temp === void 0 ? {} : _temp;
694
670
  super('TiltShiftEffect', TiltShiftShader.fragmentShader, {
695
671
  blendFunction,
@@ -697,9 +673,12 @@ class TiltShiftEffect extends Effect {
697
673
  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)]])
698
674
  });
699
675
  }
700
-
701
676
  }
702
- const TiltShift2 = wrapEffect(TiltShiftEffect);
677
+ const TiltShift2 = wrapEffect(TiltShiftEffect, {
678
+ blendFunction: BlendFunction.NORMAL
679
+ });
680
+
681
+ // first two args are camera and texture
703
682
 
704
683
  const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
705
684
  let {
@@ -718,16 +697,11 @@ const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
718
697
  ENABLE_BLUR,
719
698
  USE_MRT,
720
699
  ...props
721
- }), [SSREffect, scene, camera, ENABLE_BLUR, USE_MRT]);
722
- useLayoutEffect(() => {
723
- Object.keys(props).forEach(key => effect[key] = props[key]);
724
- invalidate();
725
- }, [props]);
700
+ }), [scene, camera, ENABLE_BLUR, USE_MRT, props]);
726
701
  const api = useContext(selectionContext);
727
702
  useEffect(() => {
728
703
  if (api && api.enabled) {
729
704
  var _api$selected;
730
-
731
705
  if ((_api$selected = api.selected) != null && _api$selected.length) {
732
706
  effect.selection.set(api.selected);
733
707
  invalidate();
@@ -738,10 +712,10 @@ const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
738
712
  }
739
713
  }
740
714
  }, [api]);
741
- return /*#__PURE__*/React__default.createElement("primitive", {
715
+ return /*#__PURE__*/React$1.createElement("primitive", _extends({
742
716
  ref: ref,
743
717
  object: effect
744
- });
718
+ }, props));
745
719
  });
746
720
 
747
721
  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,12 +1,13 @@
1
- import * as React from 'react';
1
+ import React, { MutableRefObject } from 'react';
2
+ import { Vector2 } from 'three';
2
3
  import * as THREE from 'three';
3
4
  import { type ReactThreeFiber } from '@react-three/fiber';
4
- import { type Effect, type BlendFunction } from 'postprocessing';
5
+ import type { Effect, BlendFunction } from 'postprocessing';
5
6
  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] & {
7
+ export type EffectConstructor = new (...args: any[]) => Effect;
8
+ export type EffectProps<T extends EffectConstructor> = ReactThreeFiber.Node<T extends Function ? T['prototype'] : InstanceType<T>, T> & ConstructorParameters<T>[0] & {
8
9
  blendFunction?: BlendFunction;
9
10
  opacity?: number;
10
11
  };
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;
12
+ export declare const wrapEffect: <T extends EffectConstructor, P extends EffectProps<T>>(effect: T, defaults?: P | undefined) => React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
13
+ export declare const useVector2: (props: Record<string, unknown>, key: string) => THREE.Vector2;