@react-three/postprocessing 2.11.1 → 2.11.3
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/effects/Autofocus.d.ts +9 -30
- package/dist/index.cjs +102 -102
- package/dist/index.js +106 -106
- package/package.json +17 -3
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import React, { RefObject } from 'react';
|
|
3
|
+
import { Vector3 } from '@react-three/fiber';
|
|
3
4
|
import { DepthOfFieldEffect } from 'postprocessing';
|
|
4
|
-
import { DepthOfField } from '
|
|
5
|
-
export type AutofocusProps = typeof DepthOfField & {
|
|
6
|
-
target?:
|
|
5
|
+
import { DepthOfField } from './DepthOfField';
|
|
6
|
+
export type AutofocusProps = React.ComponentProps<typeof DepthOfField> & {
|
|
7
|
+
target?: Vector3;
|
|
8
|
+
/** should the target follow the pointer */
|
|
7
9
|
mouse?: boolean;
|
|
10
|
+
/** size of the debug green point */
|
|
8
11
|
debug?: number;
|
|
12
|
+
/** manual update */
|
|
9
13
|
manual?: boolean;
|
|
14
|
+
/** approximate time to reach the target */
|
|
10
15
|
smoothTime?: number;
|
|
11
16
|
};
|
|
12
17
|
export type AutofocusApi = {
|
|
@@ -14,30 +19,4 @@ export type AutofocusApi = {
|
|
|
14
19
|
hitpoint: THREE.Vector3;
|
|
15
20
|
update: (delta: number, updateTarget: boolean) => void;
|
|
16
21
|
};
|
|
17
|
-
export declare const Autofocus: React.ForwardRefExoticComponent<React.
|
|
18
|
-
blendFunction?: import("postprocessing").BlendFunction | undefined;
|
|
19
|
-
worldFocusDistance?: number | undefined;
|
|
20
|
-
worldFocusRange?: number | undefined;
|
|
21
|
-
focusDistance?: number | undefined;
|
|
22
|
-
focalLength?: number | undefined;
|
|
23
|
-
focusRange?: number | undefined;
|
|
24
|
-
bokehScale?: number | undefined;
|
|
25
|
-
resolutionScale?: number | undefined;
|
|
26
|
-
resolutionX?: number | undefined;
|
|
27
|
-
resolutionY?: number | undefined;
|
|
28
|
-
width?: number | undefined;
|
|
29
|
-
height?: number | undefined;
|
|
30
|
-
} & Partial<{
|
|
31
|
-
target: import("@react-three/fiber").Vector3;
|
|
32
|
-
depthTexture: {
|
|
33
|
-
texture: THREE.Texture;
|
|
34
|
-
packing: number;
|
|
35
|
-
};
|
|
36
|
-
blur: number;
|
|
37
|
-
}> & React.RefAttributes<DepthOfFieldEffect>> & {
|
|
38
|
-
target?: [number, number, number] | undefined;
|
|
39
|
-
mouse?: boolean | undefined;
|
|
40
|
-
debug?: number | undefined;
|
|
41
|
-
manual?: boolean | undefined;
|
|
42
|
-
smoothTime?: number | undefined;
|
|
43
|
-
} & React.RefAttributes<AutofocusApi>>;
|
|
22
|
+
export declare const Autofocus: React.ForwardRefExoticComponent<Omit<AutofocusProps, "ref"> & React.RefAttributes<AutofocusApi>>;
|
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,108 @@ function _interopNamespaceDefault(e) {
|
|
|
28
28
|
|
|
29
29
|
var THREE__namespace = /*#__PURE__*/_interopNamespaceDefault(THREE);
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
const EffectComposerContext = React.createContext(null);
|
|
32
|
+
const EffectComposer = React.memo(React.forwardRef(({ children, camera: _camera, scene: _scene, resolutionScale, enabled = true, renderPriority = 1, autoClear = true, depthBuffer, disableNormalPass, stencilBuffer, multisampling = 8, frameBufferType = THREE.HalfFloatType, }, ref) => {
|
|
33
|
+
const { gl, scene: defaultScene, camera: defaultCamera, size } = fiber.useThree();
|
|
34
|
+
const scene = _scene || defaultScene;
|
|
35
|
+
const camera = _camera || defaultCamera;
|
|
36
|
+
const [composer, normalPass, downSamplingPass] = React.useMemo(() => {
|
|
37
|
+
const webGL2Available = threeStdlib.isWebGL2Available();
|
|
38
|
+
// Initialize composer
|
|
39
|
+
const effectComposer = new postprocessing.EffectComposer(gl, {
|
|
40
|
+
depthBuffer,
|
|
41
|
+
stencilBuffer,
|
|
42
|
+
multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
|
|
43
|
+
frameBufferType,
|
|
44
|
+
});
|
|
45
|
+
// Add render pass
|
|
46
|
+
effectComposer.addPass(new postprocessing.RenderPass(scene, camera));
|
|
47
|
+
// Create normal pass
|
|
48
|
+
let downSamplingPass = null;
|
|
49
|
+
let normalPass = null;
|
|
50
|
+
if (!disableNormalPass) {
|
|
51
|
+
normalPass = new postprocessing.NormalPass(scene, camera);
|
|
52
|
+
normalPass.enabled = false;
|
|
53
|
+
effectComposer.addPass(normalPass);
|
|
54
|
+
if (resolutionScale !== undefined && webGL2Available) {
|
|
55
|
+
downSamplingPass = new postprocessing.DepthDownsamplingPass({ normalBuffer: normalPass.texture, resolutionScale });
|
|
56
|
+
downSamplingPass.enabled = false;
|
|
57
|
+
effectComposer.addPass(downSamplingPass);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return [effectComposer, normalPass, downSamplingPass];
|
|
61
|
+
}, [
|
|
62
|
+
camera,
|
|
63
|
+
gl,
|
|
64
|
+
depthBuffer,
|
|
65
|
+
stencilBuffer,
|
|
66
|
+
multisampling,
|
|
67
|
+
frameBufferType,
|
|
68
|
+
scene,
|
|
69
|
+
disableNormalPass,
|
|
70
|
+
resolutionScale,
|
|
71
|
+
]);
|
|
72
|
+
React.useEffect(() => composer === null || composer === void 0 ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
|
|
73
|
+
fiber.useFrame((_, delta) => {
|
|
74
|
+
if (enabled) {
|
|
75
|
+
gl.autoClear = autoClear;
|
|
76
|
+
composer.render(delta);
|
|
77
|
+
}
|
|
78
|
+
}, enabled ? renderPriority : 0);
|
|
79
|
+
const group = React.useRef(null);
|
|
80
|
+
const instance = fiber.useInstanceHandle(group);
|
|
81
|
+
React.useLayoutEffect(() => {
|
|
82
|
+
let effectPass;
|
|
83
|
+
if (group.current && instance.current && composer) {
|
|
84
|
+
effectPass = new postprocessing.EffectPass(camera, ...instance.current.objects);
|
|
85
|
+
effectPass.renderToScreen = true;
|
|
86
|
+
composer.addPass(effectPass);
|
|
87
|
+
if (normalPass)
|
|
88
|
+
normalPass.enabled = true;
|
|
89
|
+
if (downSamplingPass)
|
|
90
|
+
downSamplingPass.enabled = true;
|
|
91
|
+
}
|
|
92
|
+
return () => {
|
|
93
|
+
if (effectPass)
|
|
94
|
+
composer === null || composer === void 0 ? void 0 : composer.removePass(effectPass);
|
|
95
|
+
if (normalPass)
|
|
96
|
+
normalPass.enabled = false;
|
|
97
|
+
if (downSamplingPass)
|
|
98
|
+
downSamplingPass.enabled = false;
|
|
99
|
+
};
|
|
100
|
+
}, [composer, children, camera, normalPass, downSamplingPass, instance]);
|
|
101
|
+
// Memoize state, otherwise it would trigger all consumers on every render
|
|
102
|
+
const state = React.useMemo(() => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]);
|
|
103
|
+
// Expose the composer
|
|
104
|
+
React.useImperativeHandle(ref, () => composer, [composer]);
|
|
105
|
+
return (jsxRuntime.jsx(EffectComposerContext.Provider, { value: state, children: jsxRuntime.jsx("group", { ref: group, children: children }) }));
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
const DepthOfField = React.forwardRef(function DepthOfField({ target, depthTexture, ...props }, ref) {
|
|
109
|
+
const invalidate = fiber.useThree((state) => state.invalidate);
|
|
110
|
+
const { camera } = React.useContext(EffectComposerContext);
|
|
111
|
+
const effect = React.useMemo(() => {
|
|
112
|
+
const effect = new postprocessing.DepthOfFieldEffect(camera, props);
|
|
113
|
+
// Temporary fix that restores DOF 6.21.3 behavior, everything since then lets shapes leak through the blur
|
|
114
|
+
const maskMaterial = effect.maskPass.getFullscreenMaterial();
|
|
115
|
+
maskMaterial.maskFunction = postprocessing.MaskFunction.MULTIPLY_RGB_SET_ALPHA;
|
|
116
|
+
return effect;
|
|
117
|
+
}, [camera, props]);
|
|
118
|
+
React.useLayoutEffect(() => {
|
|
119
|
+
if (target && typeof target !== 'number') {
|
|
120
|
+
const vec = target instanceof THREE.Vector3
|
|
121
|
+
? new THREE.Vector3().set(target.x, target.y, target.z)
|
|
122
|
+
: new THREE.Vector3().set(target[0], target[1], target[2]);
|
|
123
|
+
effect.target = vec;
|
|
124
|
+
}
|
|
125
|
+
if (depthTexture)
|
|
126
|
+
effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
|
|
127
|
+
invalidate();
|
|
128
|
+
}, [target, depthTexture, effect]);
|
|
129
|
+
return jsxRuntime.jsx("primitive", { ref: ref, object: effect, dispose: null });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const Autofocus = React.forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0.25, ...props }, fref) => {
|
|
32
133
|
const dofRef = React.useRef(null);
|
|
33
134
|
const hitpointRef = React.useRef(null);
|
|
34
135
|
const targetRef = React.useRef(null);
|
|
@@ -159,107 +260,6 @@ const ColorDepth = wrapEffect(postprocessing.ColorDepthEffect);
|
|
|
159
260
|
|
|
160
261
|
const Depth = wrapEffect(postprocessing.DepthEffect);
|
|
161
262
|
|
|
162
|
-
const EffectComposerContext = React.createContext(null);
|
|
163
|
-
const EffectComposer = React.memo(React.forwardRef(({ children, camera: _camera, scene: _scene, resolutionScale, enabled = true, renderPriority = 1, autoClear = true, depthBuffer, disableNormalPass, stencilBuffer, multisampling = 8, frameBufferType = THREE.HalfFloatType, }, ref) => {
|
|
164
|
-
const { gl, scene: defaultScene, camera: defaultCamera, size } = fiber.useThree();
|
|
165
|
-
const scene = _scene || defaultScene;
|
|
166
|
-
const camera = _camera || defaultCamera;
|
|
167
|
-
const [composer, normalPass, downSamplingPass] = React.useMemo(() => {
|
|
168
|
-
const webGL2Available = threeStdlib.isWebGL2Available();
|
|
169
|
-
// Initialize composer
|
|
170
|
-
const effectComposer = new postprocessing.EffectComposer(gl, {
|
|
171
|
-
depthBuffer,
|
|
172
|
-
stencilBuffer,
|
|
173
|
-
multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
|
|
174
|
-
frameBufferType,
|
|
175
|
-
});
|
|
176
|
-
// Add render pass
|
|
177
|
-
effectComposer.addPass(new postprocessing.RenderPass(scene, camera));
|
|
178
|
-
// Create normal pass
|
|
179
|
-
let downSamplingPass = null;
|
|
180
|
-
let normalPass = null;
|
|
181
|
-
if (!disableNormalPass) {
|
|
182
|
-
normalPass = new postprocessing.NormalPass(scene, camera);
|
|
183
|
-
normalPass.enabled = false;
|
|
184
|
-
effectComposer.addPass(normalPass);
|
|
185
|
-
if (resolutionScale !== undefined && webGL2Available) {
|
|
186
|
-
downSamplingPass = new postprocessing.DepthDownsamplingPass({ normalBuffer: normalPass.texture, resolutionScale });
|
|
187
|
-
downSamplingPass.enabled = false;
|
|
188
|
-
effectComposer.addPass(downSamplingPass);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return [effectComposer, normalPass, downSamplingPass];
|
|
192
|
-
}, [
|
|
193
|
-
camera,
|
|
194
|
-
gl,
|
|
195
|
-
depthBuffer,
|
|
196
|
-
stencilBuffer,
|
|
197
|
-
multisampling,
|
|
198
|
-
frameBufferType,
|
|
199
|
-
scene,
|
|
200
|
-
disableNormalPass,
|
|
201
|
-
resolutionScale,
|
|
202
|
-
]);
|
|
203
|
-
React.useEffect(() => composer === null || composer === void 0 ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
|
|
204
|
-
fiber.useFrame((_, delta) => {
|
|
205
|
-
if (enabled) {
|
|
206
|
-
gl.autoClear = autoClear;
|
|
207
|
-
composer.render(delta);
|
|
208
|
-
}
|
|
209
|
-
}, enabled ? renderPriority : 0);
|
|
210
|
-
const group = React.useRef(null);
|
|
211
|
-
const instance = fiber.useInstanceHandle(group);
|
|
212
|
-
React.useLayoutEffect(() => {
|
|
213
|
-
let effectPass;
|
|
214
|
-
if (group.current && instance.current && composer) {
|
|
215
|
-
effectPass = new postprocessing.EffectPass(camera, ...instance.current.objects);
|
|
216
|
-
effectPass.renderToScreen = true;
|
|
217
|
-
composer.addPass(effectPass);
|
|
218
|
-
if (normalPass)
|
|
219
|
-
normalPass.enabled = true;
|
|
220
|
-
if (downSamplingPass)
|
|
221
|
-
downSamplingPass.enabled = true;
|
|
222
|
-
}
|
|
223
|
-
return () => {
|
|
224
|
-
if (effectPass)
|
|
225
|
-
composer === null || composer === void 0 ? void 0 : composer.removePass(effectPass);
|
|
226
|
-
if (normalPass)
|
|
227
|
-
normalPass.enabled = false;
|
|
228
|
-
if (downSamplingPass)
|
|
229
|
-
downSamplingPass.enabled = false;
|
|
230
|
-
};
|
|
231
|
-
}, [composer, children, camera, normalPass, downSamplingPass, instance]);
|
|
232
|
-
// Memoize state, otherwise it would trigger all consumers on every render
|
|
233
|
-
const state = React.useMemo(() => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]);
|
|
234
|
-
// Expose the composer
|
|
235
|
-
React.useImperativeHandle(ref, () => composer, [composer]);
|
|
236
|
-
return (jsxRuntime.jsx(EffectComposerContext.Provider, { value: state, children: jsxRuntime.jsx("group", { ref: group, children: children }) }));
|
|
237
|
-
}));
|
|
238
|
-
|
|
239
|
-
const DepthOfField = React.forwardRef(function DepthOfField({ target, depthTexture, ...props }, ref) {
|
|
240
|
-
const invalidate = fiber.useThree((state) => state.invalidate);
|
|
241
|
-
const { camera } = React.useContext(EffectComposerContext);
|
|
242
|
-
const effect = React.useMemo(() => {
|
|
243
|
-
const effect = new postprocessing.DepthOfFieldEffect(camera, props);
|
|
244
|
-
// Temporary fix that restores DOF 6.21.3 behavior, everything since then lets shapes leak through the blur
|
|
245
|
-
const maskMaterial = effect.maskPass.getFullscreenMaterial();
|
|
246
|
-
maskMaterial.maskFunction = postprocessing.MaskFunction.MULTIPLY_RGB_SET_ALPHA;
|
|
247
|
-
return effect;
|
|
248
|
-
}, [camera, props]);
|
|
249
|
-
React.useLayoutEffect(() => {
|
|
250
|
-
if (target && typeof target !== 'number') {
|
|
251
|
-
const vec = target instanceof THREE.Vector3
|
|
252
|
-
? new THREE.Vector3().set(target.x, target.y, target.z)
|
|
253
|
-
: new THREE.Vector3().set(target[0], target[1], target[2]);
|
|
254
|
-
effect.target = vec;
|
|
255
|
-
}
|
|
256
|
-
if (depthTexture)
|
|
257
|
-
effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
|
|
258
|
-
invalidate();
|
|
259
|
-
}, [target, depthTexture, effect]);
|
|
260
|
-
return jsxRuntime.jsx("primitive", { ref: ref, object: effect, dispose: null });
|
|
261
|
-
});
|
|
262
|
-
|
|
263
263
|
const DotScreen = wrapEffect(postprocessing.DotScreenEffect);
|
|
264
264
|
|
|
265
265
|
const Glitch = React.forwardRef(function Glitch({ active = true, ...props }, ref) {
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,115 @@
|
|
|
1
|
-
import { jsxs, Fragment
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import * as THREE from 'three';
|
|
3
3
|
import { HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
|
|
4
|
-
import React, {
|
|
5
|
-
import { useThree, useFrame, createPortal, extend,
|
|
6
|
-
import {
|
|
4
|
+
import React, { createContext, forwardRef, useMemo, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState, useCallback } from 'react';
|
|
5
|
+
import { useThree, useFrame, useInstanceHandle, createPortal, extend, useLoader } from '@react-three/fiber';
|
|
6
|
+
import { EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, MaskFunction, DepthPickingPass, CopyPass, BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, 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
7
|
import { easing } from 'maath';
|
|
8
8
|
import { isWebGL2Available } from 'three-stdlib';
|
|
9
9
|
import { SSREffect } from 'screen-space-reflections';
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const EffectComposerContext = createContext(null);
|
|
12
|
+
const EffectComposer = React.memo(forwardRef(({ children, camera: _camera, scene: _scene, resolutionScale, enabled = true, renderPriority = 1, autoClear = true, depthBuffer, disableNormalPass, stencilBuffer, multisampling = 8, frameBufferType = HalfFloatType, }, ref) => {
|
|
13
|
+
const { gl, scene: defaultScene, camera: defaultCamera, size } = useThree();
|
|
14
|
+
const scene = _scene || defaultScene;
|
|
15
|
+
const camera = _camera || defaultCamera;
|
|
16
|
+
const [composer, normalPass, downSamplingPass] = useMemo(() => {
|
|
17
|
+
const webGL2Available = isWebGL2Available();
|
|
18
|
+
// Initialize composer
|
|
19
|
+
const effectComposer = new EffectComposer$1(gl, {
|
|
20
|
+
depthBuffer,
|
|
21
|
+
stencilBuffer,
|
|
22
|
+
multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
|
|
23
|
+
frameBufferType,
|
|
24
|
+
});
|
|
25
|
+
// Add render pass
|
|
26
|
+
effectComposer.addPass(new RenderPass(scene, camera));
|
|
27
|
+
// Create normal pass
|
|
28
|
+
let downSamplingPass = null;
|
|
29
|
+
let normalPass = null;
|
|
30
|
+
if (!disableNormalPass) {
|
|
31
|
+
normalPass = new NormalPass(scene, camera);
|
|
32
|
+
normalPass.enabled = false;
|
|
33
|
+
effectComposer.addPass(normalPass);
|
|
34
|
+
if (resolutionScale !== undefined && webGL2Available) {
|
|
35
|
+
downSamplingPass = new DepthDownsamplingPass({ normalBuffer: normalPass.texture, resolutionScale });
|
|
36
|
+
downSamplingPass.enabled = false;
|
|
37
|
+
effectComposer.addPass(downSamplingPass);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return [effectComposer, normalPass, downSamplingPass];
|
|
41
|
+
}, [
|
|
42
|
+
camera,
|
|
43
|
+
gl,
|
|
44
|
+
depthBuffer,
|
|
45
|
+
stencilBuffer,
|
|
46
|
+
multisampling,
|
|
47
|
+
frameBufferType,
|
|
48
|
+
scene,
|
|
49
|
+
disableNormalPass,
|
|
50
|
+
resolutionScale,
|
|
51
|
+
]);
|
|
52
|
+
useEffect(() => composer === null || composer === void 0 ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
|
|
53
|
+
useFrame((_, delta) => {
|
|
54
|
+
if (enabled) {
|
|
55
|
+
gl.autoClear = autoClear;
|
|
56
|
+
composer.render(delta);
|
|
57
|
+
}
|
|
58
|
+
}, enabled ? renderPriority : 0);
|
|
59
|
+
const group = useRef(null);
|
|
60
|
+
const instance = useInstanceHandle(group);
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
let effectPass;
|
|
63
|
+
if (group.current && instance.current && composer) {
|
|
64
|
+
effectPass = new EffectPass(camera, ...instance.current.objects);
|
|
65
|
+
effectPass.renderToScreen = true;
|
|
66
|
+
composer.addPass(effectPass);
|
|
67
|
+
if (normalPass)
|
|
68
|
+
normalPass.enabled = true;
|
|
69
|
+
if (downSamplingPass)
|
|
70
|
+
downSamplingPass.enabled = true;
|
|
71
|
+
}
|
|
72
|
+
return () => {
|
|
73
|
+
if (effectPass)
|
|
74
|
+
composer === null || composer === void 0 ? void 0 : composer.removePass(effectPass);
|
|
75
|
+
if (normalPass)
|
|
76
|
+
normalPass.enabled = false;
|
|
77
|
+
if (downSamplingPass)
|
|
78
|
+
downSamplingPass.enabled = false;
|
|
79
|
+
};
|
|
80
|
+
}, [composer, children, camera, normalPass, downSamplingPass, instance]);
|
|
81
|
+
// Memoize state, otherwise it would trigger all consumers on every render
|
|
82
|
+
const state = useMemo(() => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]);
|
|
83
|
+
// Expose the composer
|
|
84
|
+
useImperativeHandle(ref, () => composer, [composer]);
|
|
85
|
+
return (jsx(EffectComposerContext.Provider, { value: state, children: jsx("group", { ref: group, children: children }) }));
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
const DepthOfField = forwardRef(function DepthOfField({ target, depthTexture, ...props }, ref) {
|
|
89
|
+
const invalidate = useThree((state) => state.invalidate);
|
|
90
|
+
const { camera } = useContext(EffectComposerContext);
|
|
91
|
+
const effect = useMemo(() => {
|
|
92
|
+
const effect = new DepthOfFieldEffect(camera, props);
|
|
93
|
+
// Temporary fix that restores DOF 6.21.3 behavior, everything since then lets shapes leak through the blur
|
|
94
|
+
const maskMaterial = effect.maskPass.getFullscreenMaterial();
|
|
95
|
+
maskMaterial.maskFunction = MaskFunction.MULTIPLY_RGB_SET_ALPHA;
|
|
96
|
+
return effect;
|
|
97
|
+
}, [camera, props]);
|
|
98
|
+
useLayoutEffect(() => {
|
|
99
|
+
if (target && typeof target !== 'number') {
|
|
100
|
+
const vec = target instanceof Vector3
|
|
101
|
+
? new Vector3().set(target.x, target.y, target.z)
|
|
102
|
+
: new Vector3().set(target[0], target[1], target[2]);
|
|
103
|
+
effect.target = vec;
|
|
104
|
+
}
|
|
105
|
+
if (depthTexture)
|
|
106
|
+
effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
|
|
107
|
+
invalidate();
|
|
108
|
+
}, [target, depthTexture, effect]);
|
|
109
|
+
return jsx("primitive", { ref: ref, object: effect, dispose: null });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const Autofocus = forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0.25, ...props }, fref) => {
|
|
12
113
|
const dofRef = useRef(null);
|
|
13
114
|
const hitpointRef = useRef(null);
|
|
14
115
|
const targetRef = useRef(null);
|
|
@@ -139,107 +240,6 @@ const ColorDepth = wrapEffect(ColorDepthEffect);
|
|
|
139
240
|
|
|
140
241
|
const Depth = wrapEffect(DepthEffect);
|
|
141
242
|
|
|
142
|
-
const EffectComposerContext = createContext(null);
|
|
143
|
-
const EffectComposer = React.memo(forwardRef(({ children, camera: _camera, scene: _scene, resolutionScale, enabled = true, renderPriority = 1, autoClear = true, depthBuffer, disableNormalPass, stencilBuffer, multisampling = 8, frameBufferType = HalfFloatType, }, ref) => {
|
|
144
|
-
const { gl, scene: defaultScene, camera: defaultCamera, size } = useThree();
|
|
145
|
-
const scene = _scene || defaultScene;
|
|
146
|
-
const camera = _camera || defaultCamera;
|
|
147
|
-
const [composer, normalPass, downSamplingPass] = useMemo(() => {
|
|
148
|
-
const webGL2Available = isWebGL2Available();
|
|
149
|
-
// Initialize composer
|
|
150
|
-
const effectComposer = new EffectComposer$1(gl, {
|
|
151
|
-
depthBuffer,
|
|
152
|
-
stencilBuffer,
|
|
153
|
-
multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
|
|
154
|
-
frameBufferType,
|
|
155
|
-
});
|
|
156
|
-
// Add render pass
|
|
157
|
-
effectComposer.addPass(new RenderPass(scene, camera));
|
|
158
|
-
// Create normal pass
|
|
159
|
-
let downSamplingPass = null;
|
|
160
|
-
let normalPass = null;
|
|
161
|
-
if (!disableNormalPass) {
|
|
162
|
-
normalPass = new NormalPass(scene, camera);
|
|
163
|
-
normalPass.enabled = false;
|
|
164
|
-
effectComposer.addPass(normalPass);
|
|
165
|
-
if (resolutionScale !== undefined && webGL2Available) {
|
|
166
|
-
downSamplingPass = new DepthDownsamplingPass({ normalBuffer: normalPass.texture, resolutionScale });
|
|
167
|
-
downSamplingPass.enabled = false;
|
|
168
|
-
effectComposer.addPass(downSamplingPass);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return [effectComposer, normalPass, downSamplingPass];
|
|
172
|
-
}, [
|
|
173
|
-
camera,
|
|
174
|
-
gl,
|
|
175
|
-
depthBuffer,
|
|
176
|
-
stencilBuffer,
|
|
177
|
-
multisampling,
|
|
178
|
-
frameBufferType,
|
|
179
|
-
scene,
|
|
180
|
-
disableNormalPass,
|
|
181
|
-
resolutionScale,
|
|
182
|
-
]);
|
|
183
|
-
useEffect(() => composer === null || composer === void 0 ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
|
|
184
|
-
useFrame((_, delta) => {
|
|
185
|
-
if (enabled) {
|
|
186
|
-
gl.autoClear = autoClear;
|
|
187
|
-
composer.render(delta);
|
|
188
|
-
}
|
|
189
|
-
}, enabled ? renderPriority : 0);
|
|
190
|
-
const group = useRef(null);
|
|
191
|
-
const instance = useInstanceHandle(group);
|
|
192
|
-
useLayoutEffect(() => {
|
|
193
|
-
let effectPass;
|
|
194
|
-
if (group.current && instance.current && composer) {
|
|
195
|
-
effectPass = new EffectPass(camera, ...instance.current.objects);
|
|
196
|
-
effectPass.renderToScreen = true;
|
|
197
|
-
composer.addPass(effectPass);
|
|
198
|
-
if (normalPass)
|
|
199
|
-
normalPass.enabled = true;
|
|
200
|
-
if (downSamplingPass)
|
|
201
|
-
downSamplingPass.enabled = true;
|
|
202
|
-
}
|
|
203
|
-
return () => {
|
|
204
|
-
if (effectPass)
|
|
205
|
-
composer === null || composer === void 0 ? void 0 : composer.removePass(effectPass);
|
|
206
|
-
if (normalPass)
|
|
207
|
-
normalPass.enabled = false;
|
|
208
|
-
if (downSamplingPass)
|
|
209
|
-
downSamplingPass.enabled = false;
|
|
210
|
-
};
|
|
211
|
-
}, [composer, children, camera, normalPass, downSamplingPass, instance]);
|
|
212
|
-
// Memoize state, otherwise it would trigger all consumers on every render
|
|
213
|
-
const state = useMemo(() => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]);
|
|
214
|
-
// Expose the composer
|
|
215
|
-
useImperativeHandle(ref, () => composer, [composer]);
|
|
216
|
-
return (jsx(EffectComposerContext.Provider, { value: state, children: jsx("group", { ref: group, children: children }) }));
|
|
217
|
-
}));
|
|
218
|
-
|
|
219
|
-
const DepthOfField = forwardRef(function DepthOfField({ target, depthTexture, ...props }, ref) {
|
|
220
|
-
const invalidate = useThree((state) => state.invalidate);
|
|
221
|
-
const { camera } = useContext(EffectComposerContext);
|
|
222
|
-
const effect = useMemo(() => {
|
|
223
|
-
const effect = new DepthOfFieldEffect(camera, props);
|
|
224
|
-
// Temporary fix that restores DOF 6.21.3 behavior, everything since then lets shapes leak through the blur
|
|
225
|
-
const maskMaterial = effect.maskPass.getFullscreenMaterial();
|
|
226
|
-
maskMaterial.maskFunction = MaskFunction.MULTIPLY_RGB_SET_ALPHA;
|
|
227
|
-
return effect;
|
|
228
|
-
}, [camera, props]);
|
|
229
|
-
useLayoutEffect(() => {
|
|
230
|
-
if (target && typeof target !== 'number') {
|
|
231
|
-
const vec = target instanceof Vector3
|
|
232
|
-
? new Vector3().set(target.x, target.y, target.z)
|
|
233
|
-
: new Vector3().set(target[0], target[1], target[2]);
|
|
234
|
-
effect.target = vec;
|
|
235
|
-
}
|
|
236
|
-
if (depthTexture)
|
|
237
|
-
effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
|
|
238
|
-
invalidate();
|
|
239
|
-
}, [target, depthTexture, effect]);
|
|
240
|
-
return jsx("primitive", { ref: ref, object: effect, dispose: null });
|
|
241
|
-
});
|
|
242
|
-
|
|
243
243
|
const DotScreen = wrapEffect(DotScreenEffect);
|
|
244
244
|
|
|
245
245
|
const Glitch = forwardRef(function Glitch({ active = true, ...props }, ref) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/postprocessing",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.3",
|
|
4
4
|
"description": "postprocessing wrapper for React and @react-three/fiber",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postprocessing",
|
|
@@ -42,7 +42,9 @@
|
|
|
42
42
|
"test": "echo no tests yet",
|
|
43
43
|
"typecheck": "tsc --noEmit --emitDeclarationOnly false --strict --jsx react",
|
|
44
44
|
"typegen": "tsc --emitDeclarationOnly || true",
|
|
45
|
-
"release": "semantic-release"
|
|
45
|
+
"release": "semantic-release",
|
|
46
|
+
"storybook": "storybook dev -p 6006",
|
|
47
|
+
"build-storybook": "storybook build"
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
50
|
"maath": "^0.5.3",
|
|
@@ -51,10 +53,19 @@
|
|
|
51
53
|
"three-stdlib": "^2.21.10"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
56
|
+
"@react-three/drei": "^9.68.2",
|
|
54
57
|
"@react-three/fiber": "^8.13.0",
|
|
58
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
55
59
|
"@rollup/plugin-commonjs": "^24.1.0",
|
|
56
60
|
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
57
61
|
"@rollup/plugin-typescript": "^11.1.0",
|
|
62
|
+
"@storybook/addon-essentials": "^7.0.10",
|
|
63
|
+
"@storybook/addon-interactions": "^7.0.10",
|
|
64
|
+
"@storybook/addon-links": "^7.0.10",
|
|
65
|
+
"@storybook/blocks": "^7.0.10",
|
|
66
|
+
"@storybook/react": "^7.0.10",
|
|
67
|
+
"@storybook/react-vite": "^7.0.11",
|
|
68
|
+
"@storybook/testing-library": "^0.0.14-next.2",
|
|
58
69
|
"@types/react": "^18.2.0",
|
|
59
70
|
"@types/react-dom": "^18.2.1",
|
|
60
71
|
"@types/three": "^0.150.2",
|
|
@@ -67,6 +78,7 @@
|
|
|
67
78
|
"eslint-plugin-prettier": "^4.2.1",
|
|
68
79
|
"eslint-plugin-react": "^7.32.2",
|
|
69
80
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
81
|
+
"eslint-plugin-storybook": "^0.6.12",
|
|
70
82
|
"husky": "^8.0.3",
|
|
71
83
|
"lint-staged": "^13.2.2",
|
|
72
84
|
"prettier": "^2.8.8",
|
|
@@ -76,8 +88,10 @@
|
|
|
76
88
|
"rollup": "^3.21.0",
|
|
77
89
|
"rollup-plugin-filesize": "^10.0.0",
|
|
78
90
|
"semantic-release": "^21.0.2",
|
|
91
|
+
"storybook": "^7.0.10",
|
|
79
92
|
"three": "^0.151.3",
|
|
80
|
-
"typescript": "^5.0.4"
|
|
93
|
+
"typescript": "^5.0.4",
|
|
94
|
+
"vite": "^4.3.5"
|
|
81
95
|
},
|
|
82
96
|
"peerDependencies": {
|
|
83
97
|
"@react-three/fiber": ">=8.0",
|