@react-three/postprocessing 2.2.4 → 2.3.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/README.md +2 -0
- package/dist/EffectComposer.d.ts +4 -1
- package/dist/effects/Glitch.d.ts +2 -2
- package/dist/index.cjs.js +54 -26
- package/dist/index.js +52 -27
- package/package.json +29 -30
package/README.md
CHANGED
|
@@ -72,6 +72,8 @@ The EffectComposer must wrap all your effects. It will manage them for you.
|
|
|
72
72
|
autoClear?: boolean
|
|
73
73
|
multisampling?: number
|
|
74
74
|
frameBufferType?: TextureDataType
|
|
75
|
+
/** For effects that support DepthDownsamplingPass */
|
|
76
|
+
resolutionScale?: number
|
|
75
77
|
renderPriority?: number
|
|
76
78
|
camera?: THREE.Camera
|
|
77
79
|
scene?: THREE.Scene
|
package/dist/EffectComposer.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { EffectComposer as EffectComposerImpl, NormalPass } from 'postprocessing';
|
|
3
|
+
import { EffectComposer as EffectComposerImpl, NormalPass, DepthDownsamplingPass } from 'postprocessing';
|
|
4
4
|
import { TextureDataType } from 'three';
|
|
5
5
|
export declare const EffectComposerContext: React.Context<{
|
|
6
6
|
composer: EffectComposerImpl;
|
|
7
7
|
normalPass: NormalPass | null;
|
|
8
|
+
downSamplingPass: DepthDownsamplingPass | null;
|
|
8
9
|
camera: THREE.Camera;
|
|
9
10
|
scene: THREE.Scene;
|
|
11
|
+
resolutionScale?: number;
|
|
10
12
|
}>;
|
|
11
13
|
export declare type EffectComposerProps = {
|
|
12
14
|
enabled?: boolean;
|
|
@@ -15,6 +17,7 @@ export declare type EffectComposerProps = {
|
|
|
15
17
|
disableNormalPass?: boolean;
|
|
16
18
|
stencilBuffer?: boolean;
|
|
17
19
|
autoClear?: boolean;
|
|
20
|
+
resolutionScale?: number;
|
|
18
21
|
multisampling?: number;
|
|
19
22
|
frameBufferType?: TextureDataType;
|
|
20
23
|
renderPriority?: number;
|
package/dist/effects/Glitch.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { GlitchEffect, GlitchMode } from 'postprocessing';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { ReactThreeFiber } from '@react-three/fiber';
|
|
4
4
|
export declare type GlitchProps = ConstructorParameters<typeof GlitchEffect>[0] & Partial<{
|
|
5
|
-
mode: typeof GlitchMode;
|
|
5
|
+
mode: typeof GlitchMode[keyof typeof GlitchMode];
|
|
6
6
|
active: boolean;
|
|
7
7
|
delay: ReactThreeFiber.Vector2;
|
|
8
8
|
duration: ReactThreeFiber.Vector2;
|
|
@@ -20,7 +20,7 @@ export declare const Glitch: React.ForwardRefExoticComponent<{
|
|
|
20
20
|
columns?: number;
|
|
21
21
|
ratio?: number;
|
|
22
22
|
} & Partial<{
|
|
23
|
-
mode: typeof GlitchMode;
|
|
23
|
+
mode: typeof GlitchMode[keyof typeof GlitchMode];
|
|
24
24
|
active: boolean;
|
|
25
25
|
delay: ReactThreeFiber.Vector2;
|
|
26
26
|
duration: ReactThreeFiber.Vector2;
|
package/dist/index.cjs.js
CHANGED
|
@@ -11,7 +11,6 @@ var _extends = require('@babel/runtime/helpers/extends');
|
|
|
11
11
|
var _construct = require('@babel/runtime/helpers/construct');
|
|
12
12
|
var threeStdlib = require('three-stdlib');
|
|
13
13
|
var mergeRefs = require('react-merge-refs');
|
|
14
|
-
var without = require('lodash-es/without');
|
|
15
14
|
|
|
16
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
16
|
|
|
@@ -39,7 +38,6 @@ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
|
39
38
|
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
40
39
|
var _construct__default = /*#__PURE__*/_interopDefaultLegacy(_construct);
|
|
41
40
|
var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
|
|
42
|
-
var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
|
|
43
41
|
|
|
44
42
|
var _excluded$7 = ["blendFunction", "opacity"];
|
|
45
43
|
|
|
@@ -133,6 +131,7 @@ var EffectComposer = /*#__PURE__*/React__default["default"].memo( /*#__PURE__*/R
|
|
|
133
131
|
var children = _ref.children,
|
|
134
132
|
camera = _ref.camera,
|
|
135
133
|
scene = _ref.scene,
|
|
134
|
+
resolutionScale = _ref.resolutionScale,
|
|
136
135
|
_ref$enabled = _ref.enabled,
|
|
137
136
|
enabled = _ref$enabled === void 0 ? true : _ref$enabled,
|
|
138
137
|
_ref$renderPriority = _ref.renderPriority,
|
|
@@ -157,11 +156,13 @@ var EffectComposer = /*#__PURE__*/React__default["default"].memo( /*#__PURE__*/R
|
|
|
157
156
|
camera = camera || defaultCamera;
|
|
158
157
|
|
|
159
158
|
var _useMemo = React.useMemo(function () {
|
|
159
|
+
var webGL2Available = threeStdlib.isWebGL2Available(); // Initialize composer
|
|
160
|
+
|
|
160
161
|
// Initialize composer
|
|
161
162
|
var effectComposer = new postprocessing.EffectComposer(gl, {
|
|
162
163
|
depthBuffer: depthBuffer,
|
|
163
164
|
stencilBuffer: stencilBuffer,
|
|
164
|
-
multisampling: multisampling > 0 &&
|
|
165
|
+
multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
|
|
165
166
|
frameBufferType: frameBufferType
|
|
166
167
|
}); // Add render pass
|
|
167
168
|
|
|
@@ -169,19 +170,31 @@ var EffectComposer = /*#__PURE__*/React__default["default"].memo( /*#__PURE__*/R
|
|
|
169
170
|
effectComposer.addPass(new postprocessing.RenderPass(scene, camera)); // Create normal pass
|
|
170
171
|
|
|
171
172
|
// Create normal pass
|
|
172
|
-
var
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
173
|
+
var downSamplingPass = null;
|
|
174
|
+
var normalPass = null;
|
|
175
|
+
|
|
176
|
+
if (!disableNormalPass) {
|
|
177
|
+
normalPass = new postprocessing.NormalPass(scene, camera);
|
|
178
|
+
normalPass.enabled = false;
|
|
179
|
+
effectComposer.addPass(normalPass);
|
|
180
|
+
|
|
181
|
+
if (resolutionScale !== undefined && webGL2Available) {
|
|
182
|
+
downSamplingPass = new postprocessing.DepthDownsamplingPass({
|
|
183
|
+
normalBuffer: normalPass.texture,
|
|
184
|
+
resolutionScale: resolutionScale
|
|
185
|
+
});
|
|
186
|
+
downSamplingPass.enabled = false;
|
|
187
|
+
effectComposer.addPass(downSamplingPass);
|
|
188
|
+
}
|
|
177
189
|
}
|
|
178
190
|
|
|
179
|
-
return [effectComposer,
|
|
180
|
-
}, [camera, gl, depthBuffer, stencilBuffer, multisampling, frameBufferType, scene, disableNormalPass]),
|
|
191
|
+
return [effectComposer, normalPass, downSamplingPass];
|
|
192
|
+
}, [camera, gl, depthBuffer, stencilBuffer, multisampling, frameBufferType, scene, disableNormalPass, resolutionScale]),
|
|
181
193
|
composer = _useMemo[0],
|
|
182
|
-
normalPass = _useMemo[1]
|
|
194
|
+
normalPass = _useMemo[1],
|
|
195
|
+
downSamplingPass = _useMemo[2];
|
|
183
196
|
|
|
184
|
-
React.
|
|
197
|
+
React.useEffect(function () {
|
|
185
198
|
return composer == null ? void 0 : composer.setSize(size.width, size.height);
|
|
186
199
|
}, [composer, size]);
|
|
187
200
|
fiber.useFrame(function (_, delta) {
|
|
@@ -196,25 +209,29 @@ var EffectComposer = /*#__PURE__*/React__default["default"].memo( /*#__PURE__*/R
|
|
|
196
209
|
|
|
197
210
|
if (group.current && group.current.__r3f && composer) {
|
|
198
211
|
effectPass = _construct__default["default"](postprocessing.EffectPass, [camera].concat(group.current.__r3f.objects));
|
|
199
|
-
composer.addPass(effectPass);
|
|
200
212
|
effectPass.renderToScreen = true;
|
|
213
|
+
composer.addPass(effectPass);
|
|
201
214
|
if (normalPass) normalPass.enabled = true;
|
|
215
|
+
if (downSamplingPass) downSamplingPass.enabled = true;
|
|
202
216
|
}
|
|
203
217
|
|
|
204
218
|
return function () {
|
|
205
219
|
if (effectPass) composer == null ? void 0 : composer.removePass(effectPass);
|
|
206
220
|
if (normalPass) normalPass.enabled = false;
|
|
221
|
+
if (downSamplingPass) downSamplingPass.enabled = false;
|
|
207
222
|
};
|
|
208
|
-
}, [composer, children, camera]); // Memoize state, otherwise it would trigger all consumers on every render
|
|
223
|
+
}, [composer, children, camera, normalPass, downSamplingPass]); // Memoize state, otherwise it would trigger all consumers on every render
|
|
209
224
|
|
|
210
225
|
var state = React.useMemo(function () {
|
|
211
226
|
return {
|
|
212
227
|
composer: composer,
|
|
213
228
|
normalPass: normalPass,
|
|
229
|
+
downSamplingPass: downSamplingPass,
|
|
230
|
+
resolutionScale: resolutionScale,
|
|
214
231
|
camera: camera,
|
|
215
232
|
scene: scene
|
|
216
233
|
};
|
|
217
|
-
}, [composer, normalPass, camera, scene]); // Expose the composer
|
|
234
|
+
}, [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]); // Expose the composer
|
|
218
235
|
|
|
219
236
|
React.useImperativeHandle(ref, function () {
|
|
220
237
|
return composer;
|
|
@@ -375,7 +392,9 @@ function Select(_ref2) {
|
|
|
375
392
|
});
|
|
376
393
|
return function () {
|
|
377
394
|
api.select(function (state) {
|
|
378
|
-
return
|
|
395
|
+
return state.filter(function (selected) {
|
|
396
|
+
return !current.includes(selected);
|
|
397
|
+
});
|
|
379
398
|
});
|
|
380
399
|
};
|
|
381
400
|
}
|
|
@@ -428,8 +447,11 @@ var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, forwardRef) {
|
|
|
428
447
|
xRay: xRay
|
|
429
448
|
});
|
|
430
449
|
}, [blendFunction, blur, camera, edgeStrength, height, hiddenEdgeColor, kernelSize, patternTexture, pulseSpeed, scene, visibleEdgeColor, width, xRay]);
|
|
450
|
+
var api = React.useContext(selectionContext);
|
|
431
451
|
React.useEffect(function () {
|
|
432
|
-
if
|
|
452
|
+
// Do not allow array selection if declarative selection is active
|
|
453
|
+
// TODO: array selection should probably be deprecated altogether
|
|
454
|
+
if (!api && selection) {
|
|
433
455
|
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
434
456
|
invalidate();
|
|
435
457
|
return function () {
|
|
@@ -437,12 +459,11 @@ var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, forwardRef) {
|
|
|
437
459
|
invalidate();
|
|
438
460
|
};
|
|
439
461
|
}
|
|
440
|
-
}, [effect, selection]);
|
|
462
|
+
}, [effect, selection, api]);
|
|
441
463
|
React.useEffect(function () {
|
|
442
464
|
effect.selectionLayer = selectionLayer;
|
|
443
465
|
invalidate();
|
|
444
466
|
}, [effect, selectionLayer]);
|
|
445
|
-
var api = React.useContext(selectionContext);
|
|
446
467
|
var ref = React.useRef();
|
|
447
468
|
React.useEffect(function () {
|
|
448
469
|
if (api && api.enabled) {
|
|
@@ -530,8 +551,11 @@ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
|
|
|
530
551
|
kernelSize: kernelSize
|
|
531
552
|
});
|
|
532
553
|
}, [camera, height, intensity, kernelSize, luminanceSmoothing, luminanceThreshold, scene, width]);
|
|
554
|
+
var api = React.useContext(selectionContext);
|
|
533
555
|
React.useEffect(function () {
|
|
534
|
-
if
|
|
556
|
+
// Do not allow array selection if declarative selection is active
|
|
557
|
+
// TODO: array selection should probably be deprecated altogether
|
|
558
|
+
if (!api && selection) {
|
|
535
559
|
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
536
560
|
invalidate();
|
|
537
561
|
return function () {
|
|
@@ -539,7 +563,7 @@ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
|
|
|
539
563
|
invalidate();
|
|
540
564
|
};
|
|
541
565
|
}
|
|
542
|
-
}, [effect, selection]);
|
|
566
|
+
}, [effect, selection, api]);
|
|
543
567
|
React.useEffect(function () {
|
|
544
568
|
effect.selection.layer = selectionLayer;
|
|
545
569
|
invalidate();
|
|
@@ -558,7 +582,6 @@ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
|
|
|
558
582
|
};
|
|
559
583
|
}
|
|
560
584
|
}, [effect, lights, selectionLayer]);
|
|
561
|
-
var api = React.useContext(selectionContext);
|
|
562
585
|
var ref = React.useRef();
|
|
563
586
|
React.useEffect(function () {
|
|
564
587
|
if (api && api.enabled) {
|
|
@@ -590,15 +613,17 @@ var Sepia = wrapEffect(postprocessing.SepiaEffect);
|
|
|
590
613
|
var SSAO = /*#__PURE__*/React.forwardRef(function SSAO(props, ref) {
|
|
591
614
|
var _useContext = React.useContext(EffectComposerContext),
|
|
592
615
|
camera = _useContext.camera,
|
|
593
|
-
normalPass = _useContext.normalPass
|
|
616
|
+
normalPass = _useContext.normalPass,
|
|
617
|
+
downSamplingPass = _useContext.downSamplingPass,
|
|
618
|
+
resolutionScale = _useContext.resolutionScale;
|
|
594
619
|
|
|
595
620
|
var effect = React.useMemo(function () {
|
|
596
|
-
if (normalPass === null) {
|
|
621
|
+
if (normalPass === null && downSamplingPass === null) {
|
|
597
622
|
console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.');
|
|
598
623
|
return null;
|
|
599
624
|
}
|
|
600
625
|
|
|
601
|
-
return new postprocessing.SSAOEffect(camera, normalPass.
|
|
626
|
+
return new postprocessing.SSAOEffect(camera, normalPass ? normalPass.texture : null, _extends__default["default"]({
|
|
602
627
|
blendFunction: postprocessing.BlendFunction.MULTIPLY,
|
|
603
628
|
samples: 30,
|
|
604
629
|
rings: 4,
|
|
@@ -611,7 +636,10 @@ var SSAO = /*#__PURE__*/React.forwardRef(function SSAO(props, ref) {
|
|
|
611
636
|
scale: 0.5,
|
|
612
637
|
bias: 0.5,
|
|
613
638
|
intensity: 1.0,
|
|
614
|
-
color: null
|
|
639
|
+
color: null,
|
|
640
|
+
// @ts-ignore
|
|
641
|
+
normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
|
|
642
|
+
resolutionScale: resolutionScale != null ? resolutionScale : 1
|
|
615
643
|
}, props));
|
|
616
644
|
}, [camera, normalPass, props]);
|
|
617
645
|
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, EffectPass, DepthOfFieldEffect, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAPreset, EdgeDetectionMode, SMAAImageLoader, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUTEffect } from 'postprocessing';
|
|
2
|
-
import React, { forwardRef, useMemo, useLayoutEffect, createContext, useRef, useImperativeHandle, useContext, useState
|
|
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 } from 'postprocessing';
|
|
2
|
+
import React, { forwardRef, useMemo, useLayoutEffect, createContext, useEffect, useRef, useImperativeHandle, useContext, useState } from 'react';
|
|
3
3
|
import * as THREE from 'three';
|
|
4
4
|
import { Vector2, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping } from 'three';
|
|
5
5
|
import { useThree, useFrame, useLoader } from '@react-three/fiber';
|
|
6
6
|
import { isWebGL2Available } from 'three-stdlib';
|
|
7
7
|
import mergeRefs from 'react-merge-refs';
|
|
8
8
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
9
|
-
import without from 'lodash-es/without';
|
|
10
9
|
|
|
11
10
|
const isRef = ref => !!ref.current;
|
|
12
11
|
|
|
@@ -88,6 +87,7 @@ const EffectComposer = /*#__PURE__*/React.memo( /*#__PURE__*/forwardRef((_ref, r
|
|
|
88
87
|
children,
|
|
89
88
|
camera,
|
|
90
89
|
scene,
|
|
90
|
+
resolutionScale,
|
|
91
91
|
enabled = true,
|
|
92
92
|
renderPriority = 1,
|
|
93
93
|
autoClear = true,
|
|
@@ -105,27 +105,39 @@ const EffectComposer = /*#__PURE__*/React.memo( /*#__PURE__*/forwardRef((_ref, r
|
|
|
105
105
|
} = useThree();
|
|
106
106
|
scene = scene || defaultScene;
|
|
107
107
|
camera = camera || defaultCamera;
|
|
108
|
-
const [composer, normalPass] = useMemo(() => {
|
|
109
|
-
// Initialize composer
|
|
108
|
+
const [composer, normalPass, downSamplingPass] = useMemo(() => {
|
|
109
|
+
const webGL2Available = isWebGL2Available(); // Initialize composer
|
|
110
|
+
|
|
110
111
|
const effectComposer = new EffectComposer$1(gl, {
|
|
111
112
|
depthBuffer,
|
|
112
113
|
stencilBuffer,
|
|
113
|
-
multisampling: multisampling > 0 &&
|
|
114
|
+
multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
|
|
114
115
|
frameBufferType
|
|
115
116
|
}); // Add render pass
|
|
116
117
|
|
|
117
118
|
effectComposer.addPass(new RenderPass(scene, camera)); // Create normal pass
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
120
|
+
let downSamplingPass = null;
|
|
121
|
+
let normalPass = null;
|
|
122
|
+
|
|
123
|
+
if (!disableNormalPass) {
|
|
124
|
+
normalPass = new NormalPass(scene, camera);
|
|
125
|
+
normalPass.enabled = false;
|
|
126
|
+
effectComposer.addPass(normalPass);
|
|
127
|
+
|
|
128
|
+
if (resolutionScale !== undefined && webGL2Available) {
|
|
129
|
+
downSamplingPass = new DepthDownsamplingPass({
|
|
130
|
+
normalBuffer: normalPass.texture,
|
|
131
|
+
resolutionScale
|
|
132
|
+
});
|
|
133
|
+
downSamplingPass.enabled = false;
|
|
134
|
+
effectComposer.addPass(downSamplingPass);
|
|
135
|
+
}
|
|
124
136
|
}
|
|
125
137
|
|
|
126
|
-
return [effectComposer,
|
|
127
|
-
}, [camera, gl, depthBuffer, stencilBuffer, multisampling, frameBufferType, scene, disableNormalPass]);
|
|
128
|
-
|
|
138
|
+
return [effectComposer, normalPass, downSamplingPass];
|
|
139
|
+
}, [camera, gl, depthBuffer, stencilBuffer, multisampling, frameBufferType, scene, disableNormalPass, resolutionScale]);
|
|
140
|
+
useEffect(() => composer == null ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
|
|
129
141
|
useFrame((_, delta) => {
|
|
130
142
|
if (enabled) {
|
|
131
143
|
gl.autoClear = autoClear;
|
|
@@ -138,23 +150,27 @@ const EffectComposer = /*#__PURE__*/React.memo( /*#__PURE__*/forwardRef((_ref, r
|
|
|
138
150
|
|
|
139
151
|
if (group.current && group.current.__r3f && composer) {
|
|
140
152
|
effectPass = new EffectPass(camera, ...group.current.__r3f.objects);
|
|
141
|
-
composer.addPass(effectPass);
|
|
142
153
|
effectPass.renderToScreen = true;
|
|
154
|
+
composer.addPass(effectPass);
|
|
143
155
|
if (normalPass) normalPass.enabled = true;
|
|
156
|
+
if (downSamplingPass) downSamplingPass.enabled = true;
|
|
144
157
|
}
|
|
145
158
|
|
|
146
159
|
return () => {
|
|
147
160
|
if (effectPass) composer == null ? void 0 : composer.removePass(effectPass);
|
|
148
161
|
if (normalPass) normalPass.enabled = false;
|
|
162
|
+
if (downSamplingPass) downSamplingPass.enabled = false;
|
|
149
163
|
};
|
|
150
|
-
}, [composer, children, camera]); // Memoize state, otherwise it would trigger all consumers on every render
|
|
164
|
+
}, [composer, children, camera, normalPass, downSamplingPass]); // Memoize state, otherwise it would trigger all consumers on every render
|
|
151
165
|
|
|
152
166
|
const state = useMemo(() => ({
|
|
153
167
|
composer,
|
|
154
168
|
normalPass,
|
|
169
|
+
downSamplingPass,
|
|
170
|
+
resolutionScale,
|
|
155
171
|
camera,
|
|
156
172
|
scene
|
|
157
|
-
}), [composer, normalPass, camera, scene]); // Expose the composer
|
|
173
|
+
}), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]); // Expose the composer
|
|
158
174
|
|
|
159
175
|
useImperativeHandle(ref, () => composer, [composer]);
|
|
160
176
|
return /*#__PURE__*/React.createElement(EffectComposerContext.Provider, {
|
|
@@ -288,7 +304,7 @@ function Select(_ref2) {
|
|
|
288
304
|
if (changed) {
|
|
289
305
|
api.select(state => [...state, ...current]);
|
|
290
306
|
return () => {
|
|
291
|
-
api.select(state =>
|
|
307
|
+
api.select(state => state.filter(selected => !current.includes(selected)));
|
|
292
308
|
};
|
|
293
309
|
}
|
|
294
310
|
}
|
|
@@ -333,8 +349,11 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
|
|
|
333
349
|
blur,
|
|
334
350
|
xRay
|
|
335
351
|
}), [blendFunction, blur, camera, edgeStrength, height, hiddenEdgeColor, kernelSize, patternTexture, pulseSpeed, scene, visibleEdgeColor, width, xRay]);
|
|
352
|
+
const api = useContext(selectionContext);
|
|
336
353
|
useEffect(() => {
|
|
337
|
-
if
|
|
354
|
+
// Do not allow array selection if declarative selection is active
|
|
355
|
+
// TODO: array selection should probably be deprecated altogether
|
|
356
|
+
if (!api && selection) {
|
|
338
357
|
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
339
358
|
invalidate();
|
|
340
359
|
return () => {
|
|
@@ -342,12 +361,11 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
|
|
|
342
361
|
invalidate();
|
|
343
362
|
};
|
|
344
363
|
}
|
|
345
|
-
}, [effect, selection]);
|
|
364
|
+
}, [effect, selection, api]);
|
|
346
365
|
useEffect(() => {
|
|
347
366
|
effect.selectionLayer = selectionLayer;
|
|
348
367
|
invalidate();
|
|
349
368
|
}, [effect, selectionLayer]);
|
|
350
|
-
const api = useContext(selectionContext);
|
|
351
369
|
const ref = useRef();
|
|
352
370
|
useEffect(() => {
|
|
353
371
|
if (api && api.enabled) {
|
|
@@ -422,8 +440,11 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
|
|
|
422
440
|
height,
|
|
423
441
|
kernelSize
|
|
424
442
|
}), [camera, height, intensity, kernelSize, luminanceSmoothing, luminanceThreshold, scene, width]);
|
|
443
|
+
const api = useContext(selectionContext);
|
|
425
444
|
useEffect(() => {
|
|
426
|
-
if
|
|
445
|
+
// Do not allow array selection if declarative selection is active
|
|
446
|
+
// TODO: array selection should probably be deprecated altogether
|
|
447
|
+
if (!api && selection) {
|
|
427
448
|
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
428
449
|
invalidate();
|
|
429
450
|
return () => {
|
|
@@ -431,7 +452,7 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
|
|
|
431
452
|
invalidate();
|
|
432
453
|
};
|
|
433
454
|
}
|
|
434
|
-
}, [effect, selection]);
|
|
455
|
+
}, [effect, selection, api]);
|
|
435
456
|
useEffect(() => {
|
|
436
457
|
effect.selection.layer = selectionLayer;
|
|
437
458
|
invalidate();
|
|
@@ -446,7 +467,6 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
|
|
|
446
467
|
};
|
|
447
468
|
}
|
|
448
469
|
}, [effect, lights, selectionLayer]);
|
|
449
|
-
const api = useContext(selectionContext);
|
|
450
470
|
const ref = useRef();
|
|
451
471
|
useEffect(() => {
|
|
452
472
|
if (api && api.enabled) {
|
|
@@ -476,15 +496,17 @@ const Sepia = wrapEffect(SepiaEffect);
|
|
|
476
496
|
const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
|
|
477
497
|
const {
|
|
478
498
|
camera,
|
|
479
|
-
normalPass
|
|
499
|
+
normalPass,
|
|
500
|
+
downSamplingPass,
|
|
501
|
+
resolutionScale
|
|
480
502
|
} = useContext(EffectComposerContext);
|
|
481
503
|
const effect = useMemo(() => {
|
|
482
|
-
if (normalPass === null) {
|
|
504
|
+
if (normalPass === null && downSamplingPass === null) {
|
|
483
505
|
console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.');
|
|
484
506
|
return null;
|
|
485
507
|
}
|
|
486
508
|
|
|
487
|
-
return new SSAOEffect(camera, normalPass.
|
|
509
|
+
return new SSAOEffect(camera, normalPass ? normalPass.texture : null, {
|
|
488
510
|
blendFunction: BlendFunction.MULTIPLY,
|
|
489
511
|
samples: 30,
|
|
490
512
|
rings: 4,
|
|
@@ -498,6 +520,9 @@ const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
|
|
|
498
520
|
bias: 0.5,
|
|
499
521
|
intensity: 1.0,
|
|
500
522
|
color: null,
|
|
523
|
+
// @ts-ignore
|
|
524
|
+
normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
|
|
525
|
+
resolutionScale: resolutionScale != null ? resolutionScale : 1,
|
|
501
526
|
...props
|
|
502
527
|
});
|
|
503
528
|
}, [camera, normalPass, props]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/postprocessing",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "postprocessing wrapper for React and @react-three/fiber",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postprocessing",
|
|
@@ -38,49 +38,48 @@
|
|
|
38
38
|
"typegen": "tsc --emitDeclarationOnly || true"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
-
"postprocessing": "6.24.1",
|
|
41
|
+
"postprocessing": "6.26.3",
|
|
43
42
|
"react-merge-refs": "^1.1.0",
|
|
44
|
-
"three-stdlib": "^2.8.
|
|
43
|
+
"three-stdlib": "^2.8.11"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
|
-
"@babel/core": "^7.
|
|
48
|
-
"@babel/plugin-transform-modules-commonjs": "7.
|
|
49
|
-
"@babel/plugin-transform-parameters": "7.16.
|
|
50
|
-
"@babel/plugin-transform-runtime": "7.
|
|
51
|
-
"@babel/plugin-transform-template-literals": "7.16.
|
|
52
|
-
"@babel/preset-env": "^7.16.
|
|
53
|
-
"@babel/preset-react": "7.16.
|
|
54
|
-
"@babel/preset-typescript": "^7.16.
|
|
55
|
-
"@react-three/fiber": "^7.0.
|
|
56
|
-
"@rollup/plugin-babel": "^5.3.
|
|
57
|
-
"@rollup/plugin-commonjs": "^21.0.
|
|
46
|
+
"@babel/core": "^7.17.8",
|
|
47
|
+
"@babel/plugin-transform-modules-commonjs": "7.17.7",
|
|
48
|
+
"@babel/plugin-transform-parameters": "7.16.7",
|
|
49
|
+
"@babel/plugin-transform-runtime": "7.17.0",
|
|
50
|
+
"@babel/plugin-transform-template-literals": "7.16.7",
|
|
51
|
+
"@babel/preset-env": "^7.16.11",
|
|
52
|
+
"@babel/preset-react": "7.16.7",
|
|
53
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
54
|
+
"@react-three/fiber": "^7.0.26",
|
|
55
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
56
|
+
"@rollup/plugin-commonjs": "^21.0.3",
|
|
58
57
|
"@rollup/plugin-json": "^4.1.0",
|
|
59
|
-
"@rollup/plugin-node-resolve": "^13.1.
|
|
60
|
-
"@types/react": "^17.0.
|
|
61
|
-
"@types/react-dom": "^17.0.
|
|
58
|
+
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
59
|
+
"@types/react": "^17.0.43",
|
|
60
|
+
"@types/react-dom": "^17.0.14",
|
|
62
61
|
"@types/react-test-renderer": "^17.0.1",
|
|
63
|
-
"@types/three": "^0.
|
|
64
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
65
|
-
"@typescript-eslint/parser": "^5.
|
|
66
|
-
"eslint": "^8.
|
|
67
|
-
"eslint-config-prettier": "^8.
|
|
62
|
+
"@types/three": "^0.139.0",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
|
64
|
+
"@typescript-eslint/parser": "^5.17.0",
|
|
65
|
+
"eslint": "^8.12.0",
|
|
66
|
+
"eslint-config-prettier": "^8.5.0",
|
|
68
67
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
69
|
-
"eslint-plugin-import": "^2.25.
|
|
68
|
+
"eslint-plugin-import": "^2.25.4",
|
|
70
69
|
"eslint-plugin-prettier": "^4.0.0",
|
|
71
|
-
"eslint-plugin-react": "^7.
|
|
70
|
+
"eslint-plugin-react": "^7.29.4",
|
|
72
71
|
"eslint-plugin-react-hooks": "^4.3.0",
|
|
73
72
|
"husky": "^7.0.4",
|
|
74
73
|
"husky-run": "^0.0.0",
|
|
75
|
-
"lint-staged": "^12.
|
|
76
|
-
"prettier": "^2.
|
|
74
|
+
"lint-staged": "^12.3.7",
|
|
75
|
+
"prettier": "^2.6.1",
|
|
77
76
|
"react": "^17.0.2",
|
|
78
77
|
"react-dom": "^17.0.2",
|
|
79
78
|
"rimraf": "^3.0.2",
|
|
80
|
-
"rollup": "^2.
|
|
81
|
-
"rollup-plugin-filesize": "^9.1.
|
|
79
|
+
"rollup": "^2.70.1",
|
|
80
|
+
"rollup-plugin-filesize": "^9.1.2",
|
|
82
81
|
"rollup-plugin-terser": "^7.0.2",
|
|
83
|
-
"typescript": "^4.
|
|
82
|
+
"typescript": "^4.6.3"
|
|
84
83
|
},
|
|
85
84
|
"peerDependencies": {
|
|
86
85
|
"@react-three/fiber": ">=7.0",
|