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