@react-three/postprocessing 2.0.5 → 2.1.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/Bloom.d.ts +1 -1
- package/dist/effects/GodRays.d.ts +1 -1
- package/dist/effects/Outline.d.ts +3 -3
- package/dist/effects/SSAO.d.ts +2 -0
- package/dist/effects/SelectiveBloom.d.ts +2 -2
- package/dist/index.cjs.js +579 -1
- package/dist/index.js +457 -1
- package/dist/util.d.ts +5 -3
- package/package.json +31 -30
package/dist/effects/Bloom.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import React, { MutableRefObject } from 'react';
|
|
|
3
3
|
import { Object3D } from 'three';
|
|
4
4
|
declare type ObjectRef = MutableRefObject<Object3D>;
|
|
5
5
|
export declare type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] & Partial<{
|
|
6
|
-
selection: ObjectRef | ObjectRef[];
|
|
6
|
+
selection: Object3D | Object3D[] | ObjectRef | ObjectRef[];
|
|
7
7
|
selectionLayer: number;
|
|
8
8
|
}>;
|
|
9
9
|
export declare const Outline: React.ForwardRefExoticComponent<Partial<{
|
|
@@ -15,11 +15,11 @@ export declare const Outline: React.ForwardRefExoticComponent<Partial<{
|
|
|
15
15
|
hiddenEdgeColor: number;
|
|
16
16
|
width: number;
|
|
17
17
|
height: number;
|
|
18
|
-
kernelSize:
|
|
18
|
+
kernelSize: KernelSize;
|
|
19
19
|
blur: boolean;
|
|
20
20
|
xRay: boolean;
|
|
21
21
|
}> & Partial<{
|
|
22
|
-
selection: ObjectRef | ObjectRef[];
|
|
22
|
+
selection: Object3D | Object3D[] | ObjectRef | ObjectRef[];
|
|
23
23
|
selectionLayer: number;
|
|
24
24
|
}> & React.RefAttributes<OutlineEffect>>;
|
|
25
25
|
export {};
|
package/dist/effects/SSAO.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import React, { MutableRefObject } from 'react';
|
|
|
3
3
|
import { Object3D } from 'three';
|
|
4
4
|
declare type ObjectRef = MutableRefObject<Object3D>;
|
|
5
5
|
export declare type SelectiveBloomProps = ConstructorParameters<typeof SelectiveBloomEffect>[2] & Partial<{
|
|
6
|
-
lights: ObjectRef[];
|
|
7
|
-
selection: ObjectRef | ObjectRef[];
|
|
6
|
+
lights: Object3D[] | ObjectRef[];
|
|
7
|
+
selection: Object3D | Object3D[] | ObjectRef | ObjectRef[];
|
|
8
8
|
selectionLayer: number;
|
|
9
9
|
}>;
|
|
10
10
|
export declare const SelectiveBloom: React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<SelectiveBloomEffect>>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1,579 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var postprocessing = require('postprocessing');
|
|
6
|
+
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var THREE = require('three');
|
|
9
|
+
var _extends = require('@babel/runtime/helpers/extends');
|
|
10
|
+
var _construct = require('@babel/runtime/helpers/construct');
|
|
11
|
+
var fiber = require('@react-three/fiber');
|
|
12
|
+
var threeStdlib = require('three-stdlib');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
+
|
|
16
|
+
function _interopNamespace(e) {
|
|
17
|
+
if (e && e.__esModule) return e;
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n["default"] = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
35
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
36
|
+
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
37
|
+
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
38
|
+
var _construct__default = /*#__PURE__*/_interopDefaultLegacy(_construct);
|
|
39
|
+
|
|
40
|
+
var _excluded$6 = ["blendFunction", "opacity"];
|
|
41
|
+
|
|
42
|
+
var isRef = function isRef(ref) {
|
|
43
|
+
return !!ref.current;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var resolveRef = function resolveRef(ref) {
|
|
47
|
+
return isRef(ref) ? ref.current : ref;
|
|
48
|
+
};
|
|
49
|
+
var wrapEffect = function wrapEffect(effectImpl, defaultBlendMode) {
|
|
50
|
+
if (defaultBlendMode === void 0) {
|
|
51
|
+
defaultBlendMode = postprocessing.BlendFunction.NORMAL;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return /*#__PURE__*/React.forwardRef(function Wrap(_ref, ref) {
|
|
55
|
+
var blendFunction = _ref.blendFunction,
|
|
56
|
+
opacity = _ref.opacity,
|
|
57
|
+
props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$6);
|
|
58
|
+
|
|
59
|
+
var effect = React.useMemo(function () {
|
|
60
|
+
return new effectImpl(props);
|
|
61
|
+
}, [props]);
|
|
62
|
+
React.useLayoutEffect(function () {
|
|
63
|
+
effect.blendMode.blendFunction = blendFunction || defaultBlendMode;
|
|
64
|
+
if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
|
|
65
|
+
}, [blendFunction, effect.blendMode, opacity]);
|
|
66
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
67
|
+
ref: ref,
|
|
68
|
+
object: effect,
|
|
69
|
+
dispose: null
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
var useVector2 = function useVector2(props, key) {
|
|
74
|
+
var vec = props[key];
|
|
75
|
+
return React.useMemo(function () {
|
|
76
|
+
if (vec instanceof THREE.Vector2) {
|
|
77
|
+
return new THREE.Vector2().set(vec.x, vec.y);
|
|
78
|
+
} else if (Array.isArray(vec)) {
|
|
79
|
+
var x = vec[0],
|
|
80
|
+
y = vec[1];
|
|
81
|
+
return new THREE.Vector2().set(x, y);
|
|
82
|
+
}
|
|
83
|
+
}, [vec]);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
var Bloom = wrapEffect(postprocessing.BloomEffect, postprocessing.BlendFunction.SCREEN);
|
|
87
|
+
|
|
88
|
+
var BrightnessContrast = wrapEffect(postprocessing.BrightnessContrastEffect);
|
|
89
|
+
|
|
90
|
+
var ChromaticAberration = /*#__PURE__*/React.forwardRef(function ChromaticAberration(props, ref) {
|
|
91
|
+
var offset = useVector2(props, 'offset');
|
|
92
|
+
var effect = React.useMemo(function () {
|
|
93
|
+
return new postprocessing.ChromaticAberrationEffect(_extends__default["default"]({}, props, {
|
|
94
|
+
offset: offset
|
|
95
|
+
}));
|
|
96
|
+
}, [offset, props]);
|
|
97
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
98
|
+
ref: ref,
|
|
99
|
+
object: effect,
|
|
100
|
+
dispose: null
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
var ColorAverage = /*#__PURE__*/React.forwardRef(function ColorAverage(_ref, ref) {
|
|
105
|
+
var _ref$blendFunction = _ref.blendFunction,
|
|
106
|
+
blendFunction = _ref$blendFunction === void 0 ? postprocessing.BlendFunction.NORMAL : _ref$blendFunction;
|
|
107
|
+
|
|
108
|
+
/** Because ColorAverage blendFunction is not an object but a number, we have to define a custom prop "blendFunction" */
|
|
109
|
+
var effect = React.useMemo(function () {
|
|
110
|
+
return new postprocessing.ColorAverageEffect(blendFunction);
|
|
111
|
+
}, [blendFunction]);
|
|
112
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
113
|
+
ref: ref,
|
|
114
|
+
object: effect,
|
|
115
|
+
dispose: null
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
var ColorDepth = wrapEffect(postprocessing.ColorDepthEffect);
|
|
120
|
+
|
|
121
|
+
var Depth = wrapEffect(postprocessing.DepthEffect);
|
|
122
|
+
|
|
123
|
+
var EffectComposerContext = /*#__PURE__*/React.createContext(null);
|
|
124
|
+
var EffectComposer = /*#__PURE__*/React__default["default"].memo( /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
125
|
+
var children = _ref.children,
|
|
126
|
+
camera = _ref.camera,
|
|
127
|
+
scene = _ref.scene,
|
|
128
|
+
_ref$renderPriority = _ref.renderPriority,
|
|
129
|
+
renderPriority = _ref$renderPriority === void 0 ? 1 : _ref$renderPriority,
|
|
130
|
+
_ref$autoClear = _ref.autoClear,
|
|
131
|
+
autoClear = _ref$autoClear === void 0 ? true : _ref$autoClear,
|
|
132
|
+
depthBuffer = _ref.depthBuffer,
|
|
133
|
+
disableNormalPass = _ref.disableNormalPass,
|
|
134
|
+
stencilBuffer = _ref.stencilBuffer,
|
|
135
|
+
_ref$multisampling = _ref.multisampling,
|
|
136
|
+
multisampling = _ref$multisampling === void 0 ? 8 : _ref$multisampling,
|
|
137
|
+
_ref$frameBufferType = _ref.frameBufferType,
|
|
138
|
+
frameBufferType = _ref$frameBufferType === void 0 ? THREE__namespace.HalfFloatType : _ref$frameBufferType;
|
|
139
|
+
|
|
140
|
+
var _useThree = fiber.useThree(),
|
|
141
|
+
gl = _useThree.gl,
|
|
142
|
+
defaultScene = _useThree.scene,
|
|
143
|
+
defaultCamera = _useThree.camera,
|
|
144
|
+
size = _useThree.size;
|
|
145
|
+
|
|
146
|
+
scene = scene || defaultScene;
|
|
147
|
+
camera = camera || defaultCamera;
|
|
148
|
+
|
|
149
|
+
var _useMemo = React.useMemo(function () {
|
|
150
|
+
// Initialize composer
|
|
151
|
+
var effectComposer = new postprocessing.EffectComposer(gl, {
|
|
152
|
+
depthBuffer: depthBuffer,
|
|
153
|
+
stencilBuffer: stencilBuffer,
|
|
154
|
+
multisampling: threeStdlib.isWebGL2Available() ? multisampling : 0,
|
|
155
|
+
frameBufferType: frameBufferType
|
|
156
|
+
}); // Add render pass
|
|
157
|
+
|
|
158
|
+
// Add render pass
|
|
159
|
+
effectComposer.addPass(new postprocessing.RenderPass(scene, camera)); // Create normal pass
|
|
160
|
+
|
|
161
|
+
// Create normal pass
|
|
162
|
+
var pass = disableNormalPass ? null : new postprocessing.NormalPass(scene, camera);
|
|
163
|
+
if (pass) pass.enabled = false;
|
|
164
|
+
|
|
165
|
+
if (pass) {
|
|
166
|
+
effectComposer.addPass(pass);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return [effectComposer, pass];
|
|
170
|
+
}, [camera, gl, depthBuffer, stencilBuffer, multisampling, frameBufferType, scene, disableNormalPass]),
|
|
171
|
+
composer = _useMemo[0],
|
|
172
|
+
normalPass = _useMemo[1];
|
|
173
|
+
|
|
174
|
+
React.useLayoutEffect(function () {
|
|
175
|
+
return composer == null ? void 0 : composer.setSize(size.width, size.height);
|
|
176
|
+
}, [composer, size]);
|
|
177
|
+
fiber.useFrame(function (_, delta) {
|
|
178
|
+
return void (gl.autoClear = autoClear, composer.render(delta));
|
|
179
|
+
}, renderPriority);
|
|
180
|
+
var group = React.useRef(null);
|
|
181
|
+
React.useLayoutEffect(function () {
|
|
182
|
+
var effectPass;
|
|
183
|
+
|
|
184
|
+
if (group.current && group.current.__r3f && composer) {
|
|
185
|
+
effectPass = _construct__default["default"](postprocessing.EffectPass, [camera].concat(group.current.__r3f.objects));
|
|
186
|
+
composer.addPass(effectPass);
|
|
187
|
+
effectPass.renderToScreen = true;
|
|
188
|
+
if (normalPass) normalPass.enabled = false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return function () {
|
|
192
|
+
if (effectPass) composer == null ? void 0 : composer.removePass(effectPass);
|
|
193
|
+
if (normalPass) normalPass.enabled = false;
|
|
194
|
+
};
|
|
195
|
+
}, [composer, children, camera]); // Memoize state, otherwise it would trigger all consumers on every render
|
|
196
|
+
|
|
197
|
+
var state = React.useMemo(function () {
|
|
198
|
+
return {
|
|
199
|
+
composer: composer,
|
|
200
|
+
normalPass: normalPass,
|
|
201
|
+
camera: camera,
|
|
202
|
+
scene: scene
|
|
203
|
+
};
|
|
204
|
+
}, [composer, normalPass, camera, scene]); // Expose the composer
|
|
205
|
+
|
|
206
|
+
React.useImperativeHandle(ref, function () {
|
|
207
|
+
return composer;
|
|
208
|
+
}, [composer]);
|
|
209
|
+
return /*#__PURE__*/React__default["default"].createElement(EffectComposerContext.Provider, {
|
|
210
|
+
value: state
|
|
211
|
+
}, /*#__PURE__*/React__default["default"].createElement("group", {
|
|
212
|
+
ref: group
|
|
213
|
+
}, children));
|
|
214
|
+
}));
|
|
215
|
+
var EffectComposer$1 = EffectComposer;
|
|
216
|
+
|
|
217
|
+
var _excluded$5 = ["target", "depthTexture"];
|
|
218
|
+
var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref) {
|
|
219
|
+
var target = _ref.target,
|
|
220
|
+
depthTexture = _ref.depthTexture,
|
|
221
|
+
props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$5);
|
|
222
|
+
|
|
223
|
+
var _useContext = React.useContext(EffectComposerContext),
|
|
224
|
+
camera = _useContext.camera;
|
|
225
|
+
|
|
226
|
+
var effect = React.useMemo(function () {
|
|
227
|
+
return new postprocessing.DepthOfFieldEffect(camera, props);
|
|
228
|
+
}, [camera, props]);
|
|
229
|
+
React.useLayoutEffect(function () {
|
|
230
|
+
if (target) {
|
|
231
|
+
var vec = target instanceof THREE.Vector3 ? new THREE.Vector3().set(target.x, target.y, target.z) : new THREE.Vector3().set(target[0], target[1], target[2]);
|
|
232
|
+
effect.target = vec;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
|
|
236
|
+
}, [target, depthTexture, effect]);
|
|
237
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
238
|
+
ref: ref,
|
|
239
|
+
object: effect,
|
|
240
|
+
dispose: null
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
var DotScreen = wrapEffect(postprocessing.DotScreenEffect);
|
|
245
|
+
|
|
246
|
+
var _excluded$4 = ["active"];
|
|
247
|
+
var Glitch = /*#__PURE__*/React.forwardRef(function Glitch(_ref, ref) {
|
|
248
|
+
var _ref$active = _ref.active,
|
|
249
|
+
active = _ref$active === void 0 ? true : _ref$active,
|
|
250
|
+
props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$4);
|
|
251
|
+
|
|
252
|
+
var delay = useVector2(props, 'delay');
|
|
253
|
+
var duration = useVector2(props, 'duration');
|
|
254
|
+
var strength = useVector2(props, 'strength');
|
|
255
|
+
var effect = React.useMemo(function () {
|
|
256
|
+
return new postprocessing.GlitchEffect(_extends__default["default"]({}, props, {
|
|
257
|
+
delay: delay,
|
|
258
|
+
duration: duration,
|
|
259
|
+
strength: strength
|
|
260
|
+
}));
|
|
261
|
+
}, [delay, duration, props, strength]);
|
|
262
|
+
React.useLayoutEffect(function () {
|
|
263
|
+
effect.mode = active ? props.mode || postprocessing.GlitchMode.SPORADIC : postprocessing.GlitchMode.DISABLED;
|
|
264
|
+
}, [active, effect, props.mode]);
|
|
265
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
266
|
+
ref: ref,
|
|
267
|
+
object: effect,
|
|
268
|
+
dispose: null
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
var GodRays = /*#__PURE__*/React.forwardRef(function GodRays(props, ref) {
|
|
273
|
+
var _useContext = React.useContext(EffectComposerContext),
|
|
274
|
+
camera = _useContext.camera;
|
|
275
|
+
|
|
276
|
+
var effect = React.useMemo(function () {
|
|
277
|
+
return new postprocessing.GodRaysEffect(camera, props.sun, props);
|
|
278
|
+
}, [camera, props]);
|
|
279
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
280
|
+
ref: ref,
|
|
281
|
+
object: effect,
|
|
282
|
+
dispose: null
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
var _excluded$3 = ["size"];
|
|
287
|
+
var Grid = /*#__PURE__*/React.forwardRef(function Grid(_ref, ref) {
|
|
288
|
+
var size = _ref.size,
|
|
289
|
+
props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$3);
|
|
290
|
+
|
|
291
|
+
var effect = React.useMemo(function () {
|
|
292
|
+
return new postprocessing.GridEffect(props);
|
|
293
|
+
}, [props]);
|
|
294
|
+
React.useLayoutEffect(function () {
|
|
295
|
+
if (size) effect.setSize(size.width, size.height);
|
|
296
|
+
}, [effect, size]);
|
|
297
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
298
|
+
ref: ref,
|
|
299
|
+
object: effect,
|
|
300
|
+
dispose: null
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
var HueSaturation = wrapEffect(postprocessing.HueSaturationEffect);
|
|
305
|
+
|
|
306
|
+
var Noise = wrapEffect(postprocessing.NoiseEffect, postprocessing.BlendFunction.COLOR_DODGE);
|
|
307
|
+
|
|
308
|
+
var _excluded$2 = ["selection", "selectionLayer", "blendFunction", "patternTexture", "edgeStrength", "pulseSpeed", "visibleEdgeColor", "hiddenEdgeColor", "width", "height", "kernelSize", "blur", "xRay"];
|
|
309
|
+
var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, ref) {
|
|
310
|
+
var _ref$selection = _ref.selection,
|
|
311
|
+
selection = _ref$selection === void 0 ? [] : _ref$selection,
|
|
312
|
+
_ref$selectionLayer = _ref.selectionLayer,
|
|
313
|
+
selectionLayer = _ref$selectionLayer === void 0 ? 10 : _ref$selectionLayer,
|
|
314
|
+
blendFunction = _ref.blendFunction,
|
|
315
|
+
patternTexture = _ref.patternTexture,
|
|
316
|
+
edgeStrength = _ref.edgeStrength,
|
|
317
|
+
pulseSpeed = _ref.pulseSpeed,
|
|
318
|
+
visibleEdgeColor = _ref.visibleEdgeColor,
|
|
319
|
+
hiddenEdgeColor = _ref.hiddenEdgeColor,
|
|
320
|
+
width = _ref.width,
|
|
321
|
+
height = _ref.height,
|
|
322
|
+
kernelSize = _ref.kernelSize,
|
|
323
|
+
blur = _ref.blur,
|
|
324
|
+
xRay = _ref.xRay;
|
|
325
|
+
_objectWithoutPropertiesLoose__default["default"](_ref, _excluded$2);
|
|
326
|
+
|
|
327
|
+
var _useContext = React.useContext(EffectComposerContext),
|
|
328
|
+
scene = _useContext.scene,
|
|
329
|
+
camera = _useContext.camera;
|
|
330
|
+
|
|
331
|
+
var effect = React.useMemo(function () {
|
|
332
|
+
return new postprocessing.OutlineEffect(scene, camera, {
|
|
333
|
+
blendFunction: blendFunction,
|
|
334
|
+
patternTexture: patternTexture,
|
|
335
|
+
edgeStrength: edgeStrength,
|
|
336
|
+
pulseSpeed: pulseSpeed,
|
|
337
|
+
visibleEdgeColor: visibleEdgeColor,
|
|
338
|
+
hiddenEdgeColor: hiddenEdgeColor,
|
|
339
|
+
width: width,
|
|
340
|
+
height: height,
|
|
341
|
+
kernelSize: kernelSize,
|
|
342
|
+
blur: blur,
|
|
343
|
+
xRay: xRay
|
|
344
|
+
});
|
|
345
|
+
}, [blendFunction, blur, camera, edgeStrength, height, hiddenEdgeColor, kernelSize, patternTexture, pulseSpeed, scene, visibleEdgeColor, width, xRay]);
|
|
346
|
+
React.useEffect(function () {
|
|
347
|
+
if (selection) {
|
|
348
|
+
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
349
|
+
return function () {
|
|
350
|
+
return void effect.selection.clear();
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}, [effect, selection]);
|
|
354
|
+
React.useEffect(function () {
|
|
355
|
+
effect.selectionLayer = selectionLayer;
|
|
356
|
+
}, [effect, selectionLayer]);
|
|
357
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
358
|
+
ref: ref,
|
|
359
|
+
object: effect,
|
|
360
|
+
dispose: null
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
var Pixelation = /*#__PURE__*/React.forwardRef(function Pixelation(_ref, ref) {
|
|
365
|
+
var _ref$granularity = _ref.granularity,
|
|
366
|
+
granularity = _ref$granularity === void 0 ? 5 : _ref$granularity;
|
|
367
|
+
|
|
368
|
+
/** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
|
|
369
|
+
var effect = React.useMemo(function () {
|
|
370
|
+
return new postprocessing.PixelationEffect(granularity);
|
|
371
|
+
}, [granularity]);
|
|
372
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
373
|
+
ref: ref,
|
|
374
|
+
object: effect,
|
|
375
|
+
dispose: null
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
var Scanline = wrapEffect(postprocessing.ScanlineEffect, postprocessing.BlendFunction.OVERLAY);
|
|
380
|
+
|
|
381
|
+
var addLight = function addLight(light, effect) {
|
|
382
|
+
return light.layers.enable(effect.selection.layer);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
var removeLight = function removeLight(light, effect) {
|
|
386
|
+
return light.layers.disable(effect.selection.layer);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref, ref) {
|
|
390
|
+
var _ref$selection = _ref.selection,
|
|
391
|
+
selection = _ref$selection === void 0 ? [] : _ref$selection,
|
|
392
|
+
_ref$selectionLayer = _ref.selectionLayer,
|
|
393
|
+
selectionLayer = _ref$selectionLayer === void 0 ? 10 : _ref$selectionLayer,
|
|
394
|
+
_ref$lights = _ref.lights,
|
|
395
|
+
lights = _ref$lights === void 0 ? [] : _ref$lights,
|
|
396
|
+
luminanceThreshold = _ref.luminanceThreshold,
|
|
397
|
+
luminanceSmoothing = _ref.luminanceSmoothing,
|
|
398
|
+
intensity = _ref.intensity,
|
|
399
|
+
width = _ref.width,
|
|
400
|
+
height = _ref.height,
|
|
401
|
+
kernelSize = _ref.kernelSize;
|
|
402
|
+
|
|
403
|
+
if (lights.length === 0) {
|
|
404
|
+
console.warn('SelectiveBloom requires lights to work.');
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
var _useContext = React.useContext(EffectComposerContext),
|
|
408
|
+
scene = _useContext.scene,
|
|
409
|
+
camera = _useContext.camera;
|
|
410
|
+
|
|
411
|
+
var effect = React.useMemo(function () {
|
|
412
|
+
return new postprocessing.SelectiveBloomEffect(scene, camera, {
|
|
413
|
+
blendFunction: postprocessing.BlendFunction.SCREEN,
|
|
414
|
+
luminanceThreshold: luminanceThreshold,
|
|
415
|
+
luminanceSmoothing: luminanceSmoothing,
|
|
416
|
+
intensity: intensity,
|
|
417
|
+
width: width,
|
|
418
|
+
height: height,
|
|
419
|
+
kernelSize: kernelSize
|
|
420
|
+
});
|
|
421
|
+
}, [camera, height, intensity, kernelSize, luminanceSmoothing, luminanceThreshold, scene, width]);
|
|
422
|
+
React.useEffect(function () {
|
|
423
|
+
if (selection) {
|
|
424
|
+
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
425
|
+
return function () {
|
|
426
|
+
return void effect.selection.clear();
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}, [effect, selection]);
|
|
430
|
+
React.useEffect(function () {
|
|
431
|
+
effect.selection.layer = selectionLayer;
|
|
432
|
+
}, [effect, selectionLayer]);
|
|
433
|
+
React.useEffect(function () {
|
|
434
|
+
if (lights && lights.length > 0) {
|
|
435
|
+
lights.forEach(function (light) {
|
|
436
|
+
return addLight(resolveRef(light), effect);
|
|
437
|
+
});
|
|
438
|
+
return function () {
|
|
439
|
+
return lights.forEach(function (light) {
|
|
440
|
+
return removeLight(resolveRef(light), effect);
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
}, [effect, lights, selectionLayer]);
|
|
445
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
446
|
+
ref: ref,
|
|
447
|
+
object: effect,
|
|
448
|
+
dispose: null
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
var Sepia = wrapEffect(postprocessing.SepiaEffect);
|
|
453
|
+
|
|
454
|
+
var SSAO = /*#__PURE__*/React.forwardRef(function SSAO(props, ref) {
|
|
455
|
+
var _useContext = React.useContext(EffectComposerContext),
|
|
456
|
+
camera = _useContext.camera,
|
|
457
|
+
normalPass = _useContext.normalPass;
|
|
458
|
+
|
|
459
|
+
var effect = React.useMemo(function () {
|
|
460
|
+
if (normalPass === null) {
|
|
461
|
+
console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.');
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return new postprocessing.SSAOEffect(camera, normalPass.renderTarget.texture, _extends__default["default"]({
|
|
466
|
+
blendFunction: postprocessing.BlendFunction.MULTIPLY,
|
|
467
|
+
samples: 30,
|
|
468
|
+
rings: 4,
|
|
469
|
+
distanceThreshold: 1.0,
|
|
470
|
+
distanceFalloff: 0.0,
|
|
471
|
+
rangeThreshold: 0.5,
|
|
472
|
+
rangeFalloff: 0.1,
|
|
473
|
+
luminanceInfluence: 0.9,
|
|
474
|
+
radius: 20,
|
|
475
|
+
scale: 0.5,
|
|
476
|
+
bias: 0.5,
|
|
477
|
+
intensity: 1.0,
|
|
478
|
+
color: null
|
|
479
|
+
}, props));
|
|
480
|
+
}, [camera, normalPass, props]);
|
|
481
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
482
|
+
ref: ref,
|
|
483
|
+
object: effect,
|
|
484
|
+
dispose: null
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
var SMAA = /*#__PURE__*/React.forwardRef(function SMAA(_ref, ref) {
|
|
489
|
+
var _ref$preset = _ref.preset,
|
|
490
|
+
preset = _ref$preset === void 0 ? postprocessing.SMAAPreset.HIGH : _ref$preset,
|
|
491
|
+
_ref$edgeDetectionMod = _ref.edgeDetectionMode,
|
|
492
|
+
edgeDetectionMode = _ref$edgeDetectionMod === void 0 ? postprocessing.EdgeDetectionMode.COLOR : _ref$edgeDetectionMod;
|
|
493
|
+
var smaaProps = fiber.useLoader(postprocessing.SMAAImageLoader, '');
|
|
494
|
+
var effect = React.useMemo(function () {
|
|
495
|
+
return _construct__default["default"](postprocessing.SMAAEffect, smaaProps.concat([preset, edgeDetectionMode]));
|
|
496
|
+
}, [smaaProps, preset, edgeDetectionMode]);
|
|
497
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
498
|
+
ref: ref,
|
|
499
|
+
object: effect,
|
|
500
|
+
dispose: null
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
var _excluded$1 = ["textureSrc", "texture"];
|
|
505
|
+
var Texture = /*#__PURE__*/React.forwardRef(function Texture(_ref, ref) {
|
|
506
|
+
var textureSrc = _ref.textureSrc,
|
|
507
|
+
texture = _ref.texture,
|
|
508
|
+
props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$1);
|
|
509
|
+
|
|
510
|
+
var t = fiber.useLoader(THREE.TextureLoader, textureSrc);
|
|
511
|
+
React.useLayoutEffect(function () {
|
|
512
|
+
t.encoding = THREE.sRGBEncoding;
|
|
513
|
+
t.wrapS = t.wrapT = THREE.RepeatWrapping;
|
|
514
|
+
}, [t]);
|
|
515
|
+
var effect = React.useMemo(function () {
|
|
516
|
+
return new postprocessing.TextureEffect(_extends__default["default"]({}, props, {
|
|
517
|
+
texture: t || texture
|
|
518
|
+
}));
|
|
519
|
+
}, [props, t, texture]);
|
|
520
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
521
|
+
ref: ref,
|
|
522
|
+
object: effect,
|
|
523
|
+
dispose: null
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
var ToneMapping = wrapEffect(postprocessing.ToneMappingEffect);
|
|
528
|
+
|
|
529
|
+
var Vignette = wrapEffect(postprocessing.VignetteEffect);
|
|
530
|
+
|
|
531
|
+
var ShockWave = wrapEffect(postprocessing.ShockWaveEffect);
|
|
532
|
+
|
|
533
|
+
var _excluded = ["lut", "tetrahedralInterpolation"];
|
|
534
|
+
var LUT = /*#__PURE__*/React.forwardRef(function LUT(_ref, ref) {
|
|
535
|
+
var lut = _ref.lut,
|
|
536
|
+
tetrahedralInterpolation = _ref.tetrahedralInterpolation,
|
|
537
|
+
props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded);
|
|
538
|
+
|
|
539
|
+
var effect = React.useMemo(function () {
|
|
540
|
+
return new postprocessing.LUTEffect(lut, props);
|
|
541
|
+
}, [lut, props]);
|
|
542
|
+
React.useLayoutEffect(function () {
|
|
543
|
+
if (lut) effect.setLUT(lut);
|
|
544
|
+
if (tetrahedralInterpolation) effect.setTetrahedralInterpolationEnabled(tetrahedralInterpolation);
|
|
545
|
+
}, [effect, lut, tetrahedralInterpolation]);
|
|
546
|
+
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
547
|
+
ref: ref,
|
|
548
|
+
object: effect,
|
|
549
|
+
dispose: null
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
exports.Bloom = Bloom;
|
|
554
|
+
exports.BrightnessContrast = BrightnessContrast;
|
|
555
|
+
exports.ChromaticAberration = ChromaticAberration;
|
|
556
|
+
exports.ColorAverage = ColorAverage;
|
|
557
|
+
exports.ColorDepth = ColorDepth;
|
|
558
|
+
exports.Depth = Depth;
|
|
559
|
+
exports.DepthOfField = DepthOfField;
|
|
560
|
+
exports.DotScreen = DotScreen;
|
|
561
|
+
exports.EffectComposer = EffectComposer$1;
|
|
562
|
+
exports.EffectComposerContext = EffectComposerContext;
|
|
563
|
+
exports.Glitch = Glitch;
|
|
564
|
+
exports.GodRays = GodRays;
|
|
565
|
+
exports.Grid = Grid;
|
|
566
|
+
exports.HueSaturation = HueSaturation;
|
|
567
|
+
exports.LUT = LUT;
|
|
568
|
+
exports.Noise = Noise;
|
|
569
|
+
exports.Outline = Outline;
|
|
570
|
+
exports.Pixelation = Pixelation;
|
|
571
|
+
exports.SMAA = SMAA;
|
|
572
|
+
exports.SSAO = SSAO;
|
|
573
|
+
exports.Scanline = Scanline;
|
|
574
|
+
exports.SelectiveBloom = SelectiveBloom;
|
|
575
|
+
exports.Sepia = Sepia;
|
|
576
|
+
exports.ShockWave = ShockWave;
|
|
577
|
+
exports.Texture = Texture;
|
|
578
|
+
exports.ToneMapping = ToneMapping;
|
|
579
|
+
exports.Vignette = Vignette;
|
package/dist/index.js
CHANGED
|
@@ -1 +1,457 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$2, 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, useEffect } from 'react';
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { Vector2, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping } from 'three';
|
|
5
|
+
import { useThree, useFrame, useLoader } from '@react-three/fiber';
|
|
6
|
+
import { isWebGL2Available } from 'three-stdlib';
|
|
7
|
+
|
|
8
|
+
const isRef = ref => !!ref.current;
|
|
9
|
+
|
|
10
|
+
const resolveRef = ref => isRef(ref) ? ref.current : ref;
|
|
11
|
+
const wrapEffect = function (effectImpl, defaultBlendMode) {
|
|
12
|
+
if (defaultBlendMode === void 0) {
|
|
13
|
+
defaultBlendMode = BlendFunction.NORMAL;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return /*#__PURE__*/forwardRef(function Wrap(_ref, ref) {
|
|
17
|
+
let {
|
|
18
|
+
blendFunction,
|
|
19
|
+
opacity,
|
|
20
|
+
...props
|
|
21
|
+
} = _ref;
|
|
22
|
+
const effect = useMemo(() => new effectImpl(props), [props]);
|
|
23
|
+
useLayoutEffect(() => {
|
|
24
|
+
effect.blendMode.blendFunction = blendFunction || defaultBlendMode;
|
|
25
|
+
if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
|
|
26
|
+
}, [blendFunction, effect.blendMode, opacity]);
|
|
27
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
28
|
+
ref: ref,
|
|
29
|
+
object: effect,
|
|
30
|
+
dispose: null
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const useVector2 = (props, key) => {
|
|
35
|
+
const vec = props[key];
|
|
36
|
+
return useMemo(() => {
|
|
37
|
+
if (vec instanceof Vector2) {
|
|
38
|
+
return new Vector2().set(vec.x, vec.y);
|
|
39
|
+
} else if (Array.isArray(vec)) {
|
|
40
|
+
const [x, y] = vec;
|
|
41
|
+
return new Vector2().set(x, y);
|
|
42
|
+
}
|
|
43
|
+
}, [vec]);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const Bloom = wrapEffect(BloomEffect, BlendFunction.SCREEN);
|
|
47
|
+
|
|
48
|
+
const BrightnessContrast = wrapEffect(BrightnessContrastEffect);
|
|
49
|
+
|
|
50
|
+
const ChromaticAberration = /*#__PURE__*/forwardRef(function ChromaticAberration(props, ref) {
|
|
51
|
+
const offset = useVector2(props, 'offset');
|
|
52
|
+
const effect = useMemo(() => new ChromaticAberrationEffect({ ...props,
|
|
53
|
+
offset
|
|
54
|
+
}), [offset, props]);
|
|
55
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
56
|
+
ref: ref,
|
|
57
|
+
object: effect,
|
|
58
|
+
dispose: null
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const ColorAverage = /*#__PURE__*/forwardRef(function ColorAverage(_ref, ref) {
|
|
63
|
+
let {
|
|
64
|
+
blendFunction = BlendFunction.NORMAL
|
|
65
|
+
} = _ref;
|
|
66
|
+
|
|
67
|
+
/** Because ColorAverage blendFunction is not an object but a number, we have to define a custom prop "blendFunction" */
|
|
68
|
+
const effect = useMemo(() => new ColorAverageEffect(blendFunction), [blendFunction]);
|
|
69
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
70
|
+
ref: ref,
|
|
71
|
+
object: effect,
|
|
72
|
+
dispose: null
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const ColorDepth = wrapEffect(ColorDepthEffect);
|
|
77
|
+
|
|
78
|
+
const Depth = wrapEffect(DepthEffect);
|
|
79
|
+
|
|
80
|
+
const EffectComposerContext = /*#__PURE__*/createContext(null);
|
|
81
|
+
const EffectComposer = /*#__PURE__*/React.memo( /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
82
|
+
let {
|
|
83
|
+
children,
|
|
84
|
+
camera,
|
|
85
|
+
scene,
|
|
86
|
+
renderPriority = 1,
|
|
87
|
+
autoClear = true,
|
|
88
|
+
depthBuffer,
|
|
89
|
+
disableNormalPass,
|
|
90
|
+
stencilBuffer,
|
|
91
|
+
multisampling = 8,
|
|
92
|
+
frameBufferType = THREE.HalfFloatType
|
|
93
|
+
} = _ref;
|
|
94
|
+
const {
|
|
95
|
+
gl,
|
|
96
|
+
scene: defaultScene,
|
|
97
|
+
camera: defaultCamera,
|
|
98
|
+
size
|
|
99
|
+
} = useThree();
|
|
100
|
+
scene = scene || defaultScene;
|
|
101
|
+
camera = camera || defaultCamera;
|
|
102
|
+
const [composer, normalPass] = useMemo(() => {
|
|
103
|
+
// Initialize composer
|
|
104
|
+
const effectComposer = new EffectComposer$2(gl, {
|
|
105
|
+
depthBuffer,
|
|
106
|
+
stencilBuffer,
|
|
107
|
+
multisampling: isWebGL2Available() ? multisampling : 0,
|
|
108
|
+
frameBufferType
|
|
109
|
+
}); // Add render pass
|
|
110
|
+
|
|
111
|
+
effectComposer.addPass(new RenderPass(scene, camera)); // Create normal pass
|
|
112
|
+
|
|
113
|
+
const pass = disableNormalPass ? null : new NormalPass(scene, camera);
|
|
114
|
+
if (pass) pass.enabled = false;
|
|
115
|
+
|
|
116
|
+
if (pass) {
|
|
117
|
+
effectComposer.addPass(pass);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return [effectComposer, pass];
|
|
121
|
+
}, [camera, gl, depthBuffer, stencilBuffer, multisampling, frameBufferType, scene, disableNormalPass]);
|
|
122
|
+
useLayoutEffect(() => composer == null ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
|
|
123
|
+
useFrame((_, delta) => void (gl.autoClear = autoClear, composer.render(delta)), renderPriority);
|
|
124
|
+
const group = useRef(null);
|
|
125
|
+
useLayoutEffect(() => {
|
|
126
|
+
let effectPass;
|
|
127
|
+
|
|
128
|
+
if (group.current && group.current.__r3f && composer) {
|
|
129
|
+
effectPass = new EffectPass(camera, ...group.current.__r3f.objects);
|
|
130
|
+
composer.addPass(effectPass);
|
|
131
|
+
effectPass.renderToScreen = true;
|
|
132
|
+
if (normalPass) normalPass.enabled = false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return () => {
|
|
136
|
+
if (effectPass) composer == null ? void 0 : composer.removePass(effectPass);
|
|
137
|
+
if (normalPass) normalPass.enabled = false;
|
|
138
|
+
};
|
|
139
|
+
}, [composer, children, camera]); // Memoize state, otherwise it would trigger all consumers on every render
|
|
140
|
+
|
|
141
|
+
const state = useMemo(() => ({
|
|
142
|
+
composer,
|
|
143
|
+
normalPass,
|
|
144
|
+
camera,
|
|
145
|
+
scene
|
|
146
|
+
}), [composer, normalPass, camera, scene]); // Expose the composer
|
|
147
|
+
|
|
148
|
+
useImperativeHandle(ref, () => composer, [composer]);
|
|
149
|
+
return /*#__PURE__*/React.createElement(EffectComposerContext.Provider, {
|
|
150
|
+
value: state
|
|
151
|
+
}, /*#__PURE__*/React.createElement("group", {
|
|
152
|
+
ref: group
|
|
153
|
+
}, children));
|
|
154
|
+
}));
|
|
155
|
+
var EffectComposer$1 = EffectComposer;
|
|
156
|
+
|
|
157
|
+
const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
|
|
158
|
+
let {
|
|
159
|
+
target,
|
|
160
|
+
depthTexture,
|
|
161
|
+
...props
|
|
162
|
+
} = _ref;
|
|
163
|
+
const {
|
|
164
|
+
camera
|
|
165
|
+
} = useContext(EffectComposerContext);
|
|
166
|
+
const effect = useMemo(() => new DepthOfFieldEffect(camera, props), [camera, props]);
|
|
167
|
+
useLayoutEffect(() => {
|
|
168
|
+
if (target) {
|
|
169
|
+
const vec = target instanceof Vector3 ? new Vector3().set(target.x, target.y, target.z) : new Vector3().set(target[0], target[1], target[2]);
|
|
170
|
+
effect.target = vec;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
|
|
174
|
+
}, [target, depthTexture, effect]);
|
|
175
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
176
|
+
ref: ref,
|
|
177
|
+
object: effect,
|
|
178
|
+
dispose: null
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const DotScreen = wrapEffect(DotScreenEffect);
|
|
183
|
+
|
|
184
|
+
const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
|
|
185
|
+
let {
|
|
186
|
+
active = true,
|
|
187
|
+
...props
|
|
188
|
+
} = _ref;
|
|
189
|
+
const delay = useVector2(props, 'delay');
|
|
190
|
+
const duration = useVector2(props, 'duration');
|
|
191
|
+
const strength = useVector2(props, 'strength');
|
|
192
|
+
const effect = useMemo(() => new GlitchEffect({ ...props,
|
|
193
|
+
delay,
|
|
194
|
+
duration,
|
|
195
|
+
strength
|
|
196
|
+
}), [delay, duration, props, strength]);
|
|
197
|
+
useLayoutEffect(() => {
|
|
198
|
+
effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED;
|
|
199
|
+
}, [active, effect, props.mode]);
|
|
200
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
201
|
+
ref: ref,
|
|
202
|
+
object: effect,
|
|
203
|
+
dispose: null
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const GodRays = /*#__PURE__*/forwardRef(function GodRays(props, ref) {
|
|
208
|
+
const {
|
|
209
|
+
camera
|
|
210
|
+
} = useContext(EffectComposerContext);
|
|
211
|
+
const effect = useMemo(() => new GodRaysEffect(camera, props.sun, props), [camera, props]);
|
|
212
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
213
|
+
ref: ref,
|
|
214
|
+
object: effect,
|
|
215
|
+
dispose: null
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const Grid = /*#__PURE__*/forwardRef(function Grid(_ref, ref) {
|
|
220
|
+
let {
|
|
221
|
+
size,
|
|
222
|
+
...props
|
|
223
|
+
} = _ref;
|
|
224
|
+
const effect = useMemo(() => new GridEffect(props), [props]);
|
|
225
|
+
useLayoutEffect(() => {
|
|
226
|
+
if (size) effect.setSize(size.width, size.height);
|
|
227
|
+
}, [effect, size]);
|
|
228
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
229
|
+
ref: ref,
|
|
230
|
+
object: effect,
|
|
231
|
+
dispose: null
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const HueSaturation = wrapEffect(HueSaturationEffect);
|
|
236
|
+
|
|
237
|
+
const Noise = wrapEffect(NoiseEffect, BlendFunction.COLOR_DODGE);
|
|
238
|
+
|
|
239
|
+
const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, ref) {
|
|
240
|
+
let {
|
|
241
|
+
selection = [],
|
|
242
|
+
selectionLayer = 10,
|
|
243
|
+
blendFunction,
|
|
244
|
+
patternTexture,
|
|
245
|
+
edgeStrength,
|
|
246
|
+
pulseSpeed,
|
|
247
|
+
visibleEdgeColor,
|
|
248
|
+
hiddenEdgeColor,
|
|
249
|
+
width,
|
|
250
|
+
height,
|
|
251
|
+
kernelSize,
|
|
252
|
+
blur,
|
|
253
|
+
xRay,
|
|
254
|
+
...props
|
|
255
|
+
} = _ref;
|
|
256
|
+
const {
|
|
257
|
+
scene,
|
|
258
|
+
camera
|
|
259
|
+
} = useContext(EffectComposerContext);
|
|
260
|
+
const effect = useMemo(() => new OutlineEffect(scene, camera, {
|
|
261
|
+
blendFunction,
|
|
262
|
+
patternTexture,
|
|
263
|
+
edgeStrength,
|
|
264
|
+
pulseSpeed,
|
|
265
|
+
visibleEdgeColor,
|
|
266
|
+
hiddenEdgeColor,
|
|
267
|
+
width,
|
|
268
|
+
height,
|
|
269
|
+
kernelSize,
|
|
270
|
+
blur,
|
|
271
|
+
xRay
|
|
272
|
+
}), [blendFunction, blur, camera, edgeStrength, height, hiddenEdgeColor, kernelSize, patternTexture, pulseSpeed, scene, visibleEdgeColor, width, xRay]);
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
if (selection) {
|
|
275
|
+
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
276
|
+
return () => void effect.selection.clear();
|
|
277
|
+
}
|
|
278
|
+
}, [effect, selection]);
|
|
279
|
+
useEffect(() => {
|
|
280
|
+
effect.selectionLayer = selectionLayer;
|
|
281
|
+
}, [effect, selectionLayer]);
|
|
282
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
283
|
+
ref: ref,
|
|
284
|
+
object: effect,
|
|
285
|
+
dispose: null
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
const Pixelation = /*#__PURE__*/forwardRef(function Pixelation(_ref, ref) {
|
|
290
|
+
let {
|
|
291
|
+
granularity = 5
|
|
292
|
+
} = _ref;
|
|
293
|
+
|
|
294
|
+
/** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
|
|
295
|
+
const effect = useMemo(() => new PixelationEffect(granularity), [granularity]);
|
|
296
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
297
|
+
ref: ref,
|
|
298
|
+
object: effect,
|
|
299
|
+
dispose: null
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const Scanline = wrapEffect(ScanlineEffect, BlendFunction.OVERLAY);
|
|
304
|
+
|
|
305
|
+
const addLight = (light, effect) => light.layers.enable(effect.selection.layer);
|
|
306
|
+
|
|
307
|
+
const removeLight = (light, effect) => light.layers.disable(effect.selection.layer);
|
|
308
|
+
|
|
309
|
+
const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, ref) {
|
|
310
|
+
let {
|
|
311
|
+
selection = [],
|
|
312
|
+
selectionLayer = 10,
|
|
313
|
+
lights = [],
|
|
314
|
+
luminanceThreshold,
|
|
315
|
+
luminanceSmoothing,
|
|
316
|
+
intensity,
|
|
317
|
+
width,
|
|
318
|
+
height,
|
|
319
|
+
kernelSize
|
|
320
|
+
} = _ref;
|
|
321
|
+
|
|
322
|
+
if (lights.length === 0) {
|
|
323
|
+
console.warn('SelectiveBloom requires lights to work.');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const {
|
|
327
|
+
scene,
|
|
328
|
+
camera
|
|
329
|
+
} = useContext(EffectComposerContext);
|
|
330
|
+
const effect = useMemo(() => new SelectiveBloomEffect(scene, camera, {
|
|
331
|
+
blendFunction: BlendFunction.SCREEN,
|
|
332
|
+
luminanceThreshold,
|
|
333
|
+
luminanceSmoothing,
|
|
334
|
+
intensity,
|
|
335
|
+
width,
|
|
336
|
+
height,
|
|
337
|
+
kernelSize
|
|
338
|
+
}), [camera, height, intensity, kernelSize, luminanceSmoothing, luminanceThreshold, scene, width]);
|
|
339
|
+
useEffect(() => {
|
|
340
|
+
if (selection) {
|
|
341
|
+
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
342
|
+
return () => void effect.selection.clear();
|
|
343
|
+
}
|
|
344
|
+
}, [effect, selection]);
|
|
345
|
+
useEffect(() => {
|
|
346
|
+
effect.selection.layer = selectionLayer;
|
|
347
|
+
}, [effect, selectionLayer]);
|
|
348
|
+
useEffect(() => {
|
|
349
|
+
if (lights && lights.length > 0) {
|
|
350
|
+
lights.forEach(light => addLight(resolveRef(light), effect));
|
|
351
|
+
return () => lights.forEach(light => removeLight(resolveRef(light), effect));
|
|
352
|
+
}
|
|
353
|
+
}, [effect, lights, selectionLayer]);
|
|
354
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
355
|
+
ref: ref,
|
|
356
|
+
object: effect,
|
|
357
|
+
dispose: null
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
const Sepia = wrapEffect(SepiaEffect);
|
|
362
|
+
|
|
363
|
+
const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
|
|
364
|
+
const {
|
|
365
|
+
camera,
|
|
366
|
+
normalPass
|
|
367
|
+
} = useContext(EffectComposerContext);
|
|
368
|
+
const effect = useMemo(() => {
|
|
369
|
+
if (normalPass === null) {
|
|
370
|
+
console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.');
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return new SSAOEffect(camera, normalPass.renderTarget.texture, {
|
|
375
|
+
blendFunction: BlendFunction.MULTIPLY,
|
|
376
|
+
samples: 30,
|
|
377
|
+
rings: 4,
|
|
378
|
+
distanceThreshold: 1.0,
|
|
379
|
+
distanceFalloff: 0.0,
|
|
380
|
+
rangeThreshold: 0.5,
|
|
381
|
+
rangeFalloff: 0.1,
|
|
382
|
+
luminanceInfluence: 0.9,
|
|
383
|
+
radius: 20,
|
|
384
|
+
scale: 0.5,
|
|
385
|
+
bias: 0.5,
|
|
386
|
+
intensity: 1.0,
|
|
387
|
+
color: null,
|
|
388
|
+
...props
|
|
389
|
+
});
|
|
390
|
+
}, [camera, normalPass, props]);
|
|
391
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
392
|
+
ref: ref,
|
|
393
|
+
object: effect,
|
|
394
|
+
dispose: null
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
const SMAA = /*#__PURE__*/forwardRef(function SMAA(_ref, ref) {
|
|
399
|
+
let {
|
|
400
|
+
preset = SMAAPreset.HIGH,
|
|
401
|
+
edgeDetectionMode = EdgeDetectionMode.COLOR
|
|
402
|
+
} = _ref;
|
|
403
|
+
const smaaProps = useLoader(SMAAImageLoader, '');
|
|
404
|
+
const effect = useMemo(() => new SMAAEffect(...smaaProps, preset, edgeDetectionMode), [smaaProps, preset, edgeDetectionMode]);
|
|
405
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
406
|
+
ref: ref,
|
|
407
|
+
object: effect,
|
|
408
|
+
dispose: null
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const Texture = /*#__PURE__*/forwardRef(function Texture(_ref, ref) {
|
|
413
|
+
let {
|
|
414
|
+
textureSrc,
|
|
415
|
+
texture,
|
|
416
|
+
...props
|
|
417
|
+
} = _ref;
|
|
418
|
+
const t = useLoader(TextureLoader, textureSrc);
|
|
419
|
+
useLayoutEffect(() => {
|
|
420
|
+
t.encoding = sRGBEncoding;
|
|
421
|
+
t.wrapS = t.wrapT = RepeatWrapping;
|
|
422
|
+
}, [t]);
|
|
423
|
+
const effect = useMemo(() => new TextureEffect({ ...props,
|
|
424
|
+
texture: t || texture
|
|
425
|
+
}), [props, t, texture]);
|
|
426
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
427
|
+
ref: ref,
|
|
428
|
+
object: effect,
|
|
429
|
+
dispose: null
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
const ToneMapping = wrapEffect(ToneMappingEffect);
|
|
434
|
+
|
|
435
|
+
const Vignette = wrapEffect(VignetteEffect);
|
|
436
|
+
|
|
437
|
+
const ShockWave = wrapEffect(ShockWaveEffect);
|
|
438
|
+
|
|
439
|
+
const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
|
|
440
|
+
let {
|
|
441
|
+
lut,
|
|
442
|
+
tetrahedralInterpolation,
|
|
443
|
+
...props
|
|
444
|
+
} = _ref;
|
|
445
|
+
const effect = useMemo(() => new LUTEffect(lut, props), [lut, props]);
|
|
446
|
+
useLayoutEffect(() => {
|
|
447
|
+
if (lut) effect.setLUT(lut);
|
|
448
|
+
if (tetrahedralInterpolation) effect.setTetrahedralInterpolationEnabled(tetrahedralInterpolation);
|
|
449
|
+
}, [effect, lut, tetrahedralInterpolation]);
|
|
450
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
451
|
+
ref: ref,
|
|
452
|
+
object: effect,
|
|
453
|
+
dispose: null
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
export { Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DotScreen, EffectComposer$1 as EffectComposer, EffectComposerContext, Glitch, GodRays, Grid, HueSaturation, LUT, Noise, Outline, Pixelation, SMAA, SSAO, Scanline, SelectiveBloom, Sepia, ShockWave, Texture, ToneMapping, Vignette };
|
package/dist/util.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Vector2 } from 'three';
|
|
1
|
+
import React, { MutableRefObject } from 'react';
|
|
2
|
+
import { Vector2, Object3D } from 'three';
|
|
3
3
|
import { Effect, BlendFunction } from 'postprocessing';
|
|
4
|
+
declare type ObjectRef = MutableRefObject<Object3D>;
|
|
5
|
+
export declare const resolveRef: (ref: Object3D | ObjectRef) => Object3D<import("three").Event>;
|
|
4
6
|
export declare const wrapEffect: <T extends new (...args: any[]) => Effect>(effectImpl: T, defaultBlendMode?: BlendFunction) => React.ForwardRefExoticComponent<React.PropsWithoutRef<ConstructorParameters<T>[0] & Partial<{
|
|
5
7
|
blendFunction: BlendFunction;
|
|
6
8
|
opacity: number;
|
|
7
9
|
}>> & React.RefAttributes<T>>;
|
|
8
10
|
export declare const useVector2: (props: any, key: string) => Vector2;
|
|
9
|
-
export
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/postprocessing",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "postprocessing wrapper for React and @react-three/fiber",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postprocessing",
|
|
@@ -38,53 +38,54 @@
|
|
|
38
38
|
"typegen": "tsc --emitDeclarationOnly || true"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"postprocessing": "^6.
|
|
42
|
-
"react-merge-refs": "^1.1.0"
|
|
41
|
+
"postprocessing": "^6.24.0",
|
|
42
|
+
"react-merge-refs": "^1.1.0",
|
|
43
|
+
"three-stdlib": "^2.8.6"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@babel/core": "^7.
|
|
46
|
-
"@babel/plugin-transform-modules-commonjs": "7.
|
|
47
|
-
"@babel/plugin-transform-parameters": "7.
|
|
48
|
-
"@babel/plugin-transform-runtime": "7.
|
|
49
|
-
"@babel/plugin-transform-template-literals": "7.
|
|
50
|
-
"@babel/preset-env": "^7.
|
|
51
|
-
"@babel/preset-react": "7.
|
|
52
|
-
"@babel/preset-typescript": "^7.
|
|
53
|
-
"@react-three/fiber": "^
|
|
46
|
+
"@babel/core": "^7.16.5",
|
|
47
|
+
"@babel/plugin-transform-modules-commonjs": "7.16.5",
|
|
48
|
+
"@babel/plugin-transform-parameters": "7.16.5",
|
|
49
|
+
"@babel/plugin-transform-runtime": "7.16.5",
|
|
50
|
+
"@babel/plugin-transform-template-literals": "7.16.5",
|
|
51
|
+
"@babel/preset-env": "^7.16.5",
|
|
52
|
+
"@babel/preset-react": "7.16.5",
|
|
53
|
+
"@babel/preset-typescript": "^7.16.5",
|
|
54
|
+
"@react-three/fiber": "^7.0.24",
|
|
54
55
|
"@rollup/plugin-babel": "^5.3.0",
|
|
55
|
-
"@rollup/plugin-commonjs": "^
|
|
56
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
56
57
|
"@rollup/plugin-json": "^4.1.0",
|
|
57
|
-
"@rollup/plugin-node-resolve": "^13.
|
|
58
|
-
"@types/react": "^17.0.
|
|
59
|
-
"@types/react-dom": "^17.0.
|
|
58
|
+
"@rollup/plugin-node-resolve": "^13.1.1",
|
|
59
|
+
"@types/react": "^17.0.37",
|
|
60
|
+
"@types/react-dom": "^17.0.11",
|
|
60
61
|
"@types/react-test-renderer": "^17.0.1",
|
|
61
|
-
"@types/three": "^0.
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
63
|
-
"@typescript-eslint/parser": "^
|
|
64
|
-
"eslint": "^
|
|
62
|
+
"@types/three": "^0.135.0",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
64
|
+
"@typescript-eslint/parser": "^5.8.0",
|
|
65
|
+
"eslint": "^8.5.0",
|
|
65
66
|
"eslint-config-prettier": "^8.3.0",
|
|
66
67
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
67
|
-
"eslint-plugin-import": "^2.
|
|
68
|
-
"eslint-plugin-prettier": "^
|
|
69
|
-
"eslint-plugin-react": "^7.
|
|
70
|
-
"eslint-plugin-react-hooks": "^4.
|
|
71
|
-
"husky": "^7.0.
|
|
68
|
+
"eslint-plugin-import": "^2.25.3",
|
|
69
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
70
|
+
"eslint-plugin-react": "^7.27.1",
|
|
71
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
72
|
+
"husky": "^7.0.4",
|
|
72
73
|
"husky-run": "^0.0.0",
|
|
73
|
-
"lint-staged": "^
|
|
74
|
-
"prettier": "^2.
|
|
74
|
+
"lint-staged": "^12.1.3",
|
|
75
|
+
"prettier": "^2.5.1",
|
|
75
76
|
"react": "^17.0.2",
|
|
76
77
|
"react-dom": "^17.0.2",
|
|
77
78
|
"rimraf": "^3.0.2",
|
|
78
|
-
"rollup": "^2.
|
|
79
|
+
"rollup": "^2.61.1",
|
|
79
80
|
"rollup-plugin-filesize": "^9.1.1",
|
|
80
81
|
"rollup-plugin-terser": "^7.0.2",
|
|
81
|
-
"typescript": "^4.
|
|
82
|
+
"typescript": "^4.5.4"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
85
|
"@react-three/fiber": ">=7.0",
|
|
85
86
|
"react": ">=17.0",
|
|
86
87
|
"react-dom": ">=17.0",
|
|
87
|
-
"three": ">=0.
|
|
88
|
+
"three": ">=0.136.0"
|
|
88
89
|
},
|
|
89
90
|
"peerDependenciesMeta": {
|
|
90
91
|
"react-dom": {
|