@react-three/postprocessing 2.10.0 → 2.11.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,7 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import React, { RefObject } from 'react';
3
3
  import { DepthOfFieldEffect } from 'postprocessing';
4
- import { DepthOfField } from './index';
4
+ import { DepthOfField } from '..';
5
5
  export type AutofocusProps = typeof DepthOfField & {
6
6
  target?: [number, number, number];
7
7
  mouse?: boolean;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { BloomEffect, BlendFunction } from 'postprocessing';
3
- export declare const Bloom: import("react").ForwardRefExoticComponent<{
4
- blendFunction: BlendFunction;
5
- } & import("react").RefAttributes<typeof BloomEffect>>;
3
+ export declare const Bloom: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<BloomEffect>, import("@react-three/fiber").NodeProps<BloomEffect, typeof BloomEffect>>> & import("postprocessing").BloomEffectOptions & {
4
+ blendFunction?: BlendFunction | undefined;
5
+ opacity?: number | undefined;
6
+ }, "ref"> & import("react").RefAttributes<typeof BloomEffect>>;
@@ -17,5 +17,5 @@ export declare const GodRays: React.ForwardRefExoticComponent<{
17
17
  kernelSize?: import("postprocessing").KernelSize | undefined;
18
18
  blur?: boolean | undefined;
19
19
  } & {
20
- sun: Mesh | Points;
20
+ sun: Mesh | Points | React.MutableRefObject<Mesh | Points>;
21
21
  } & React.RefAttributes<GodRaysEffect>>;
@@ -1,5 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { NoiseEffect, BlendFunction } from 'postprocessing';
3
- export declare const Noise: import("react").ForwardRefExoticComponent<{
4
- blendFunction: BlendFunction;
5
- } & import("react").RefAttributes<typeof NoiseEffect>>;
3
+ export declare const Noise: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<NoiseEffect>, import("@react-three/fiber").NodeProps<NoiseEffect, typeof NoiseEffect>>> & {
4
+ blendFunction?: BlendFunction | undefined;
5
+ premultiply?: boolean | undefined;
6
+ } & {
7
+ blendFunction?: BlendFunction | undefined;
8
+ opacity?: number | undefined;
9
+ }, "ref"> & import("react").RefAttributes<typeof NoiseEffect>>;
@@ -1,6 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { ScanlineEffect, BlendFunction } from 'postprocessing';
3
- export declare const Scanline: import("react").ForwardRefExoticComponent<{
4
- blendFunction: BlendFunction;
5
- density: number;
6
- } & import("react").RefAttributes<typeof ScanlineEffect>>;
3
+ export declare const Scanline: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<ScanlineEffect>, import("@react-three/fiber").NodeProps<ScanlineEffect, typeof ScanlineEffect>>> & {
4
+ blendFunction?: BlendFunction | undefined;
5
+ density?: number | undefined;
6
+ } & {
7
+ blendFunction?: BlendFunction | undefined;
8
+ opacity?: number | undefined;
9
+ }, "ref"> & import("react").RefAttributes<typeof ScanlineEffect>>;
@@ -1,5 +1,17 @@
1
1
  /// <reference types="react" />
2
2
  import { TiltShiftEffect, BlendFunction } from 'postprocessing';
3
- export declare const TiltShift: import("react").ForwardRefExoticComponent<{
4
- blendFunction: BlendFunction;
5
- } & import("react").RefAttributes<typeof TiltShiftEffect>>;
3
+ export declare const TiltShift: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<TiltShiftEffect>, import("@react-three/fiber").NodeProps<TiltShiftEffect, typeof TiltShiftEffect>>> & {
4
+ blendFunction?: BlendFunction | undefined;
5
+ offset?: number | undefined;
6
+ rotation?: number | undefined;
7
+ focusArea?: number | undefined;
8
+ feather?: number | undefined;
9
+ bias?: number | undefined;
10
+ kernelSize?: import("postprocessing").KernelSize | undefined;
11
+ resolutionScale?: number | undefined;
12
+ resolutionX?: number | undefined;
13
+ resolutionY?: number | undefined;
14
+ } & {
15
+ blendFunction?: BlendFunction | undefined;
16
+ opacity?: number | undefined;
17
+ }, "ref"> & import("react").RefAttributes<typeof TiltShiftEffect>>;
@@ -16,6 +16,15 @@ export declare class TiltShiftEffect extends Effect {
16
16
  direction?: number[] | undefined;
17
17
  });
18
18
  }
19
- export declare const TiltShift2: import("react").ForwardRefExoticComponent<{
20
- blendFunction: BlendFunction;
21
- } & import("react").RefAttributes<typeof TiltShiftEffect>>;
19
+ export declare const TiltShift2: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<TiltShiftEffect>, import("@react-three/fiber").NodeProps<TiltShiftEffect, typeof TiltShiftEffect>>> & {
20
+ blendFunction?: BlendFunction | undefined;
21
+ blur?: number | undefined;
22
+ taper?: number | undefined;
23
+ start?: number[] | undefined;
24
+ end?: number[] | undefined;
25
+ samples?: number | undefined;
26
+ direction?: number[] | undefined;
27
+ } & {
28
+ blendFunction?: BlendFunction | undefined;
29
+ opacity?: number | undefined;
30
+ }, "ref"> & import("react").RefAttributes<typeof TiltShiftEffect>>;
package/dist/index.cjs CHANGED
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var postprocessing = require('postprocessing');
4
3
  var jsxRuntime = require('react/jsx-runtime');
5
- var React = require('react');
6
4
  var THREE = require('three');
5
+ var React = require('react');
7
6
  var fiber = require('@react-three/fiber');
7
+ var postprocessing = require('postprocessing');
8
+ var maath = require('maath');
8
9
  var threeStdlib = require('three-stdlib');
9
10
  var screenSpaceReflections = require('screen-space-reflections');
10
- var maath = require('maath');
11
11
 
12
12
  function _interopNamespaceDefault(e) {
13
13
  var n = Object.create(null);
@@ -28,6 +28,86 @@ function _interopNamespaceDefault(e) {
28
28
 
29
29
  var THREE__namespace = /*#__PURE__*/_interopNamespaceDefault(THREE);
30
30
 
31
+ const Autofocus = React.forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0, ...props }, fref) => {
32
+ const dofRef = React.useRef(null);
33
+ const hitpointRef = React.useRef(null);
34
+ const targetRef = React.useRef(null);
35
+ const scene = fiber.useThree(({ scene }) => scene);
36
+ const pointer = fiber.useThree(({ pointer }) => pointer);
37
+ const { composer, camera } = React.useContext(EffectComposerContext);
38
+ // see: https://codesandbox.io/s/depthpickingpass-x130hg
39
+ const [depthPickingPass] = React.useState(() => new postprocessing.DepthPickingPass());
40
+ const [copyPass] = React.useState(() => new postprocessing.CopyPass());
41
+ React.useEffect(() => {
42
+ composer.addPass(depthPickingPass);
43
+ composer.addPass(copyPass);
44
+ return () => {
45
+ composer.removePass(depthPickingPass);
46
+ composer.removePass(copyPass);
47
+ };
48
+ }, [composer, depthPickingPass, copyPass]);
49
+ React.useEffect(() => {
50
+ return () => {
51
+ depthPickingPass.dispose();
52
+ copyPass.dispose();
53
+ };
54
+ }, [depthPickingPass, copyPass]);
55
+ const [hitpoint] = React.useState(() => new THREE__namespace.Vector3(0, 0, 0));
56
+ const [ndc] = React.useState(() => new THREE__namespace.Vector3(0, 0, 0));
57
+ const getHit = React.useCallback(async (x, y) => {
58
+ ndc.x = x;
59
+ ndc.y = y;
60
+ ndc.z = await depthPickingPass.readDepth(ndc);
61
+ ndc.z = ndc.z * 2.0 - 1.0;
62
+ const hit = 1 - ndc.z > 0.0000001; // it is missed if ndc.z is close to 1
63
+ return hit ? ndc.unproject(camera) : false;
64
+ }, [ndc, depthPickingPass, camera]);
65
+ const update = React.useCallback(async (delta, updateTarget = true) => {
66
+ var _a;
67
+ // Update hitpoint
68
+ if (target) {
69
+ hitpoint.set(...target);
70
+ }
71
+ else {
72
+ const { x, y } = followMouse ? pointer : { x: 0, y: 0 };
73
+ const hit = await getHit(x, y);
74
+ if (hit)
75
+ hitpoint.copy(hit);
76
+ }
77
+ // Update target
78
+ if (updateTarget && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
79
+ if (smoothTime > 0 && delta > 0) {
80
+ maath.easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
81
+ }
82
+ else {
83
+ dofRef.current.target.copy(hitpoint);
84
+ }
85
+ }
86
+ }, [target, hitpoint, followMouse, getHit, smoothTime, pointer]);
87
+ fiber.useFrame(async (_, delta) => {
88
+ var _a;
89
+ if (!manual) {
90
+ update(delta);
91
+ }
92
+ if (hitpointRef.current) {
93
+ hitpointRef.current.position.copy(hitpoint);
94
+ }
95
+ if (targetRef.current && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
96
+ targetRef.current.position.copy(dofRef.current.target);
97
+ }
98
+ });
99
+ // Ref API
100
+ const api = React.useMemo(() => ({
101
+ dofRef,
102
+ hitpoint,
103
+ update,
104
+ }), [hitpoint, update]);
105
+ React.useImperativeHandle(fref, () => api, [api]);
106
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [debug
107
+ ? fiber.createPortal(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("mesh", { ref: hitpointRef, children: [jsxRuntime.jsx("sphereGeometry", { args: [debug, 16, 16] }), jsxRuntime.jsx("meshBasicMaterial", { color: "#00ff00", opacity: 1, transparent: true, depthWrite: false })] }), jsxRuntime.jsxs("mesh", { ref: targetRef, children: [jsxRuntime.jsx("sphereGeometry", { args: [debug / 2, 16, 16] }), jsxRuntime.jsx("meshBasicMaterial", { color: "#00ff00", opacity: 0.5, transparent: true, depthWrite: false })] })] }), scene)
108
+ : null, jsxRuntime.jsx(DepthOfField, { ref: dofRef, ...props, target: hitpoint })] }));
109
+ });
110
+
31
111
  const resolveRef = (ref) => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref;
32
112
  let i = 0;
33
113
  const components = new WeakMap();
@@ -197,7 +277,9 @@ const Glitch = React.forwardRef(function Glitch({ active = true, ...props }, ref
197
277
 
198
278
  const GodRays = React.forwardRef(function GodRays(props, ref) {
199
279
  const { camera } = React.useContext(EffectComposerContext);
200
- const effect = React.useMemo(() => new postprocessing.GodRaysEffect(camera, props.sun, props), [camera, props]);
280
+ const effect = React.useMemo(() => new postprocessing.GodRaysEffect(camera, resolveRef(props.sun), props), [camera, props]);
281
+ // @ts-ignore v6.30.2 https://github.com/pmndrs/postprocessing/pull/470/commits/091ef6f9516ca02efa7576305afbecf1ce8323ae
282
+ React.useLayoutEffect(() => void (effect.lightSource = resolveRef(props.sun)), [effect, props.sun]);
201
283
  return jsxRuntime.jsx("primitive", { ref: ref, object: effect, dispose: null });
202
284
  });
203
285
 
@@ -550,79 +632,6 @@ const SSR = React.forwardRef(function SSR({ ENABLE_BLUR = true, USE_MRT = true,
550
632
  return jsxRuntime.jsx("primitive", { ref: ref, object: effect, ...props });
551
633
  });
552
634
 
553
- const Autofocus = React.forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0, ...props }, fref) => {
554
- const dofRef = React.useRef(null);
555
- const hitpointRef = React.useRef(null);
556
- const targetRef = React.useRef(null);
557
- const scene = fiber.useThree(({ scene }) => scene);
558
- const pointer = fiber.useThree(({ pointer }) => pointer);
559
- const { composer, camera } = React.useContext(EffectComposerContext);
560
- // see: https://codesandbox.io/s/depthpickingpass-x130hg
561
- const [depthPickingPass] = React.useState(new postprocessing.DepthPickingPass());
562
- const [copyPass] = React.useState(new postprocessing.CopyPass());
563
- React.useEffect(() => {
564
- composer.addPass(depthPickingPass);
565
- composer.addPass(copyPass);
566
- return () => {
567
- composer.removePass(depthPickingPass);
568
- composer.removePass(copyPass);
569
- };
570
- }, [composer, depthPickingPass, copyPass]);
571
- const [hitpoint] = React.useState(new THREE__namespace.Vector3(0, 0, 0));
572
- const [ndc] = React.useState(new THREE__namespace.Vector3(0, 0, 0));
573
- const getHit = React.useCallback(async (x, y) => {
574
- ndc.x = x;
575
- ndc.y = y;
576
- ndc.z = await depthPickingPass.readDepth(ndc);
577
- ndc.z = ndc.z * 2.0 - 1.0;
578
- const hit = 1 - ndc.z > 0.0000001; // it is missed if ndc.z is close to 1
579
- return hit ? ndc.unproject(camera) : false;
580
- }, [ndc, depthPickingPass, camera]);
581
- const update = React.useCallback(async (delta, updateTarget = true) => {
582
- var _a;
583
- // Update hitpoint
584
- if (target) {
585
- hitpoint.set(...target);
586
- }
587
- else {
588
- const { x, y } = followMouse ? pointer : { x: 0, y: 0 };
589
- const hit = await getHit(x, y);
590
- if (hit)
591
- hitpoint.copy(hit);
592
- }
593
- // Update target
594
- if (updateTarget && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
595
- if (smoothTime > 0 && delta > 0) {
596
- maath.easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
597
- }
598
- else {
599
- dofRef.current.target.copy(hitpoint);
600
- }
601
- }
602
- }, [target, hitpoint, followMouse, getHit, smoothTime, pointer]);
603
- fiber.useFrame(async (_, delta) => {
604
- var _a;
605
- if (!manual) {
606
- update(delta);
607
- }
608
- if (hitpointRef.current) {
609
- hitpointRef.current.position.copy(hitpoint);
610
- }
611
- if (targetRef.current && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
612
- targetRef.current.position.copy(dofRef.current.target);
613
- }
614
- });
615
- // Ref API
616
- React.useImperativeHandle(fref, () => ({
617
- dofRef,
618
- hitpoint,
619
- update,
620
- }), [hitpoint, update]);
621
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [debug
622
- ? fiber.createPortal(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("mesh", { ref: hitpointRef, children: [jsxRuntime.jsx("sphereGeometry", { args: [debug, 16, 16] }), jsxRuntime.jsx("meshBasicMaterial", { color: "#00ff00", opacity: 1, transparent: true, depthWrite: false })] }), jsxRuntime.jsxs("mesh", { ref: targetRef, children: [jsxRuntime.jsx("sphereGeometry", { args: [debug / 2, 16, 16] }), jsxRuntime.jsx("meshBasicMaterial", { color: "#00ff00", opacity: 0.5, transparent: true, depthWrite: false })] })] }), scene)
623
- : null, jsxRuntime.jsx(DepthOfField, { ref: dofRef, ...props, target: hitpoint })] }));
624
- });
625
-
626
635
  exports.Autofocus = Autofocus;
627
636
  exports.Bloom = Bloom;
628
637
  exports.BrightnessContrast = BrightnessContrast;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './effects/Autofocus';
1
2
  export * from './effects/Bloom';
2
3
  export * from './effects/BrightnessContrast';
3
4
  export * from './effects/ChromaticAberration';
@@ -27,6 +28,5 @@ export * from './effects/TiltShift';
27
28
  export * from './effects/TiltShift2';
28
29
  export * from './effects/SSR';
29
30
  export * from './Selection';
30
- export * from './Autofocus';
31
31
  export * from './EffectComposer';
32
32
  export * from './util';
package/dist/index.js CHANGED
@@ -1,12 +1,92 @@
1
- import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, MaskFunction, 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, DepthPickingPass, CopyPass } from 'postprocessing';
2
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import React, { forwardRef, useMemo, createContext, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState, useCallback } from 'react';
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
4
2
  import * as THREE from 'three';
5
3
  import { HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
6
- import { extend, useThree, useFrame, useInstanceHandle, useLoader, createPortal } from '@react-three/fiber';
4
+ import React, { forwardRef, useRef, useContext, useState, useEffect, useCallback, useMemo, useImperativeHandle, createContext, useLayoutEffect } from 'react';
5
+ import { useThree, useFrame, createPortal, extend, useInstanceHandle, useLoader } from '@react-three/fiber';
6
+ import { DepthPickingPass, CopyPass, BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, MaskFunction, 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';
7
+ import { easing } from 'maath';
7
8
  import { isWebGL2Available } from 'three-stdlib';
8
9
  import { SSREffect } from 'screen-space-reflections';
9
- import { easing } from 'maath';
10
+
11
+ const Autofocus = forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0, ...props }, fref) => {
12
+ const dofRef = useRef(null);
13
+ const hitpointRef = useRef(null);
14
+ const targetRef = useRef(null);
15
+ const scene = useThree(({ scene }) => scene);
16
+ const pointer = useThree(({ pointer }) => pointer);
17
+ const { composer, camera } = useContext(EffectComposerContext);
18
+ // see: https://codesandbox.io/s/depthpickingpass-x130hg
19
+ const [depthPickingPass] = useState(() => new DepthPickingPass());
20
+ const [copyPass] = useState(() => new CopyPass());
21
+ useEffect(() => {
22
+ composer.addPass(depthPickingPass);
23
+ composer.addPass(copyPass);
24
+ return () => {
25
+ composer.removePass(depthPickingPass);
26
+ composer.removePass(copyPass);
27
+ };
28
+ }, [composer, depthPickingPass, copyPass]);
29
+ useEffect(() => {
30
+ return () => {
31
+ depthPickingPass.dispose();
32
+ copyPass.dispose();
33
+ };
34
+ }, [depthPickingPass, copyPass]);
35
+ const [hitpoint] = useState(() => new THREE.Vector3(0, 0, 0));
36
+ const [ndc] = useState(() => new THREE.Vector3(0, 0, 0));
37
+ const getHit = useCallback(async (x, y) => {
38
+ ndc.x = x;
39
+ ndc.y = y;
40
+ ndc.z = await depthPickingPass.readDepth(ndc);
41
+ ndc.z = ndc.z * 2.0 - 1.0;
42
+ const hit = 1 - ndc.z > 0.0000001; // it is missed if ndc.z is close to 1
43
+ return hit ? ndc.unproject(camera) : false;
44
+ }, [ndc, depthPickingPass, camera]);
45
+ const update = useCallback(async (delta, updateTarget = true) => {
46
+ var _a;
47
+ // Update hitpoint
48
+ if (target) {
49
+ hitpoint.set(...target);
50
+ }
51
+ else {
52
+ const { x, y } = followMouse ? pointer : { x: 0, y: 0 };
53
+ const hit = await getHit(x, y);
54
+ if (hit)
55
+ hitpoint.copy(hit);
56
+ }
57
+ // Update target
58
+ if (updateTarget && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
59
+ if (smoothTime > 0 && delta > 0) {
60
+ easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
61
+ }
62
+ else {
63
+ dofRef.current.target.copy(hitpoint);
64
+ }
65
+ }
66
+ }, [target, hitpoint, followMouse, getHit, smoothTime, pointer]);
67
+ useFrame(async (_, delta) => {
68
+ var _a;
69
+ if (!manual) {
70
+ update(delta);
71
+ }
72
+ if (hitpointRef.current) {
73
+ hitpointRef.current.position.copy(hitpoint);
74
+ }
75
+ if (targetRef.current && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
76
+ targetRef.current.position.copy(dofRef.current.target);
77
+ }
78
+ });
79
+ // Ref API
80
+ const api = useMemo(() => ({
81
+ dofRef,
82
+ hitpoint,
83
+ update,
84
+ }), [hitpoint, update]);
85
+ useImperativeHandle(fref, () => api, [api]);
86
+ return (jsxs(Fragment, { children: [debug
87
+ ? createPortal(jsxs(Fragment, { children: [jsxs("mesh", { ref: hitpointRef, children: [jsx("sphereGeometry", { args: [debug, 16, 16] }), jsx("meshBasicMaterial", { color: "#00ff00", opacity: 1, transparent: true, depthWrite: false })] }), jsxs("mesh", { ref: targetRef, children: [jsx("sphereGeometry", { args: [debug / 2, 16, 16] }), jsx("meshBasicMaterial", { color: "#00ff00", opacity: 0.5, transparent: true, depthWrite: false })] })] }), scene)
88
+ : null, jsx(DepthOfField, { ref: dofRef, ...props, target: hitpoint })] }));
89
+ });
10
90
 
11
91
  const resolveRef = (ref) => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref;
12
92
  let i = 0;
@@ -177,7 +257,9 @@ const Glitch = forwardRef(function Glitch({ active = true, ...props }, ref) {
177
257
 
178
258
  const GodRays = forwardRef(function GodRays(props, ref) {
179
259
  const { camera } = useContext(EffectComposerContext);
180
- const effect = useMemo(() => new GodRaysEffect(camera, props.sun, props), [camera, props]);
260
+ const effect = useMemo(() => new GodRaysEffect(camera, resolveRef(props.sun), props), [camera, props]);
261
+ // @ts-ignore v6.30.2 https://github.com/pmndrs/postprocessing/pull/470/commits/091ef6f9516ca02efa7576305afbecf1ce8323ae
262
+ useLayoutEffect(() => void (effect.lightSource = resolveRef(props.sun)), [effect, props.sun]);
181
263
  return jsx("primitive", { ref: ref, object: effect, dispose: null });
182
264
  });
183
265
 
@@ -530,77 +612,4 @@ const SSR = forwardRef(function SSR({ ENABLE_BLUR = true, USE_MRT = true, ...pro
530
612
  return jsx("primitive", { ref: ref, object: effect, ...props });
531
613
  });
532
614
 
533
- const Autofocus = forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0, ...props }, fref) => {
534
- const dofRef = useRef(null);
535
- const hitpointRef = useRef(null);
536
- const targetRef = useRef(null);
537
- const scene = useThree(({ scene }) => scene);
538
- const pointer = useThree(({ pointer }) => pointer);
539
- const { composer, camera } = useContext(EffectComposerContext);
540
- // see: https://codesandbox.io/s/depthpickingpass-x130hg
541
- const [depthPickingPass] = useState(new DepthPickingPass());
542
- const [copyPass] = useState(new CopyPass());
543
- useEffect(() => {
544
- composer.addPass(depthPickingPass);
545
- composer.addPass(copyPass);
546
- return () => {
547
- composer.removePass(depthPickingPass);
548
- composer.removePass(copyPass);
549
- };
550
- }, [composer, depthPickingPass, copyPass]);
551
- const [hitpoint] = useState(new THREE.Vector3(0, 0, 0));
552
- const [ndc] = useState(new THREE.Vector3(0, 0, 0));
553
- const getHit = useCallback(async (x, y) => {
554
- ndc.x = x;
555
- ndc.y = y;
556
- ndc.z = await depthPickingPass.readDepth(ndc);
557
- ndc.z = ndc.z * 2.0 - 1.0;
558
- const hit = 1 - ndc.z > 0.0000001; // it is missed if ndc.z is close to 1
559
- return hit ? ndc.unproject(camera) : false;
560
- }, [ndc, depthPickingPass, camera]);
561
- const update = useCallback(async (delta, updateTarget = true) => {
562
- var _a;
563
- // Update hitpoint
564
- if (target) {
565
- hitpoint.set(...target);
566
- }
567
- else {
568
- const { x, y } = followMouse ? pointer : { x: 0, y: 0 };
569
- const hit = await getHit(x, y);
570
- if (hit)
571
- hitpoint.copy(hit);
572
- }
573
- // Update target
574
- if (updateTarget && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
575
- if (smoothTime > 0 && delta > 0) {
576
- easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
577
- }
578
- else {
579
- dofRef.current.target.copy(hitpoint);
580
- }
581
- }
582
- }, [target, hitpoint, followMouse, getHit, smoothTime, pointer]);
583
- useFrame(async (_, delta) => {
584
- var _a;
585
- if (!manual) {
586
- update(delta);
587
- }
588
- if (hitpointRef.current) {
589
- hitpointRef.current.position.copy(hitpoint);
590
- }
591
- if (targetRef.current && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
592
- targetRef.current.position.copy(dofRef.current.target);
593
- }
594
- });
595
- // Ref API
596
- useImperativeHandle(fref, () => ({
597
- dofRef,
598
- hitpoint,
599
- update,
600
- }), [hitpoint, update]);
601
- return (jsxs(Fragment, { children: [debug
602
- ? createPortal(jsxs(Fragment, { children: [jsxs("mesh", { ref: hitpointRef, children: [jsx("sphereGeometry", { args: [debug, 16, 16] }), jsx("meshBasicMaterial", { color: "#00ff00", opacity: 1, transparent: true, depthWrite: false })] }), jsxs("mesh", { ref: targetRef, children: [jsx("sphereGeometry", { args: [debug / 2, 16, 16] }), jsx("meshBasicMaterial", { color: "#00ff00", opacity: 0.5, transparent: true, depthWrite: false })] })] }), scene)
603
- : null, jsx(DepthOfField, { ref: dofRef, ...props, target: hitpoint })] }));
604
- });
605
-
606
615
  export { Autofocus, 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
@@ -9,5 +9,5 @@ export type EffectProps<T extends EffectConstructor> = ReactThreeFiber.Node<T ex
9
9
  blendFunction?: BlendFunction;
10
10
  opacity?: number;
11
11
  };
12
- export declare const wrapEffect: <T extends EffectConstructor, P extends EffectProps<T> = EffectProps<T>>(effect: T, defaults?: P | undefined) => React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
12
+ export declare const wrapEffect: <T extends EffectConstructor>(effect: T, defaults?: EffectProps<T> | undefined) => React.ForwardRefExoticComponent<React.PropsWithoutRef<EffectProps<T>> & React.RefAttributes<T>>;
13
13
  export declare const useVector2: (props: Record<string, unknown>, key: string) => THREE.Vector2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/postprocessing",
3
- "version": "2.10.0",
3
+ "version": "2.11.1",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",