@react-three/postprocessing 2.9.0 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,565 +1,400 @@
1
1
  import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUT3DEffect, TiltShiftEffect as TiltShiftEffect$1, Effect, EffectAttribute } from 'postprocessing';
2
- import _extends from '@babel/runtime/helpers/esm/extends';
3
- import React$1, { forwardRef, useMemo, createContext, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState } from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import React, { forwardRef, useMemo, createContext, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState } from 'react';
4
4
  import * as THREE from 'three';
5
5
  import { HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
6
6
  import { extend, useThree, useFrame, useInstanceHandle, useLoader } from '@react-three/fiber';
7
7
  import { isWebGL2Available } from 'three-stdlib';
8
8
  import { SSREffect } from 'screen-space-reflections';
9
9
 
10
- const resolveRef = ref => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref;
10
+ const resolveRef = (ref) => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref;
11
11
  let i = 0;
12
12
  const components = new WeakMap();
13
- const wrapEffect = (effect, defaults) => /* @__PURE__ */React$1.forwardRef(function Effect(_ref, ref) {
14
- let {
15
- blendFunction = defaults == null ? void 0 : defaults.blendFunction,
16
- opacity = defaults == null ? void 0 : defaults.opacity,
17
- ...props
18
- } = _ref;
19
- let Component = components.get(effect);
20
- if (!Component) {
21
- const key = `@react-three/postprocessing/${effect.name}-${i++}`;
22
- extend({
23
- [key]: effect
24
- });
25
- components.set(effect, Component = key);
26
- }
27
- const camera = useThree(state => state.camera);
28
- const args = React$1.useMemo(() => {
29
- var _defaults$args, _props$args;
30
- return [...((_defaults$args = defaults == null ? void 0 : defaults.args) != null ? _defaults$args : []), ...((_props$args = props.args) != null ? _props$args : [{
31
- ...defaults,
32
- ...props
33
- }])];
34
- },
35
- // eslint-disable-next-line react-hooks/exhaustive-deps
36
- [JSON.stringify(props)]);
37
- return /*#__PURE__*/React$1.createElement(Component, _extends({
38
- camera: camera,
39
- "blendMode-blendFunction": blendFunction,
40
- "blendMode-opacity": opacity
41
- }, props, {
42
- ref: ref,
43
- args: args
44
- }));
13
+ const wrapEffect = (effect, defaults) =>
14
+ /* @__PURE__ */ React.forwardRef(function Effect({ blendFunction = defaults === null || defaults === void 0 ? void 0 : defaults.blendFunction, opacity = defaults === null || defaults === void 0 ? void 0 : defaults.opacity, ...props }, ref) {
15
+ let Component = components.get(effect);
16
+ if (!Component) {
17
+ const key = `@react-three/postprocessing/${effect.name}-${i++}`;
18
+ extend({ [key]: effect });
19
+ components.set(effect, (Component = key));
20
+ }
21
+ const camera = useThree((state) => state.camera);
22
+ const args = React.useMemo(() => { var _a, _b; return [...((_a = defaults === null || defaults === void 0 ? void 0 : defaults.args) !== null && _a !== void 0 ? _a : []), ...((_b = props.args) !== null && _b !== void 0 ? _b : [{ ...defaults, ...props }])]; },
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ [JSON.stringify(props)]);
25
+ return (jsx(Component, { camera: camera, "blendMode-blendFunction": blendFunction, "blendMode-opacity": opacity, ...props, ref: ref, args: args }));
45
26
  });
46
27
  const useVector2 = (props, key) => {
47
- const value = props[key];
48
- return React$1.useMemo(() => {
49
- if (typeof value === 'number') return new THREE.Vector2(value, value);else if (value) return new THREE.Vector2(...value);else return new THREE.Vector2();
50
- }, [value]);
28
+ const value = props[key];
29
+ return React.useMemo(() => {
30
+ if (typeof value === 'number')
31
+ return new THREE.Vector2(value, value);
32
+ else if (value)
33
+ return new THREE.Vector2(...value);
34
+ else
35
+ return new THREE.Vector2();
36
+ }, [value]);
51
37
  };
52
38
 
53
- const Bloom = wrapEffect(BloomEffect, {
54
- blendFunction: BlendFunction.ADD
55
- });
39
+ const Bloom = wrapEffect(BloomEffect, { blendFunction: BlendFunction.ADD });
56
40
 
57
41
  const BrightnessContrast = wrapEffect(BrightnessContrastEffect);
58
42
 
59
- // type for function args should use constructor args
60
-
61
- const ChromaticAberration = /*#__PURE__*/forwardRef(function ChromaticAberration(props, ref) {
62
- const offset = useVector2(props, 'offset');
63
- const effect = useMemo(() => new ChromaticAberrationEffect({
64
- ...props,
65
- offset
66
- }), [offset, props]);
67
- return /*#__PURE__*/React$1.createElement("primitive", {
68
- ref: ref,
69
- object: effect,
70
- dispose: null
71
- });
43
+ const ChromaticAberration = forwardRef(function ChromaticAberration(props, ref) {
44
+ const offset = useVector2(props, 'offset');
45
+ const effect = useMemo(() => new ChromaticAberrationEffect({ ...props, offset }), [offset, props]);
46
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
72
47
  });
73
48
 
74
- const ColorAverage = /*#__PURE__*/forwardRef(function ColorAverage(_ref, ref) {
75
- let {
76
- blendFunction = BlendFunction.NORMAL
77
- } = _ref;
78
- /** Because ColorAverage blendFunction is not an object but a number, we have to define a custom prop "blendFunction" */
79
- const effect = useMemo(() => new ColorAverageEffect(blendFunction), [blendFunction]);
80
- return /*#__PURE__*/React$1.createElement("primitive", {
81
- ref: ref,
82
- object: effect,
83
- dispose: null
84
- });
49
+ const ColorAverage = forwardRef(function ColorAverage({ blendFunction = BlendFunction.NORMAL }, ref) {
50
+ /** Because ColorAverage blendFunction is not an object but a number, we have to define a custom prop "blendFunction" */
51
+ const effect = useMemo(() => new ColorAverageEffect(blendFunction), [blendFunction]);
52
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
85
53
  });
86
54
 
87
55
  const ColorDepth = wrapEffect(ColorDepthEffect);
88
56
 
89
57
  const Depth = wrapEffect(DepthEffect);
90
58
 
91
- const EffectComposerContext = /*#__PURE__*/createContext(null);
92
- const EffectComposer = /*#__PURE__*/React$1.memo( /*#__PURE__*/forwardRef((_ref, ref) => {
93
- let {
94
- children,
95
- camera: _camera,
96
- scene: _scene,
97
- resolutionScale,
98
- enabled = true,
99
- renderPriority = 1,
100
- autoClear = true,
101
- depthBuffer,
102
- disableNormalPass,
103
- stencilBuffer,
104
- multisampling = 8,
105
- frameBufferType = HalfFloatType
106
- } = _ref;
107
- const {
108
- gl,
109
- scene: defaultScene,
110
- camera: defaultCamera,
111
- size
112
- } = useThree();
113
- const scene = _scene || defaultScene;
114
- const camera = _camera || defaultCamera;
115
- const [composer, normalPass, downSamplingPass] = useMemo(() => {
116
- const webGL2Available = isWebGL2Available();
117
- // Initialize composer
118
- const effectComposer = new EffectComposer$1(gl, {
119
- depthBuffer,
120
- stencilBuffer,
121
- multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
122
- frameBufferType
123
- });
124
-
125
- // Add render pass
126
- effectComposer.addPass(new RenderPass(scene, camera));
127
-
128
- // Create normal pass
129
- let downSamplingPass = null;
130
- let normalPass = null;
131
- if (!disableNormalPass) {
132
- normalPass = new NormalPass(scene, camera);
133
- normalPass.enabled = false;
134
- effectComposer.addPass(normalPass);
135
- if (resolutionScale !== undefined && webGL2Available) {
136
- downSamplingPass = new DepthDownsamplingPass({
137
- normalBuffer: normalPass.texture,
138
- resolutionScale
59
+ const EffectComposerContext = createContext(null);
60
+ const EffectComposer = React.memo(forwardRef(({ children, camera: _camera, scene: _scene, resolutionScale, enabled = true, renderPriority = 1, autoClear = true, depthBuffer, disableNormalPass, stencilBuffer, multisampling = 8, frameBufferType = HalfFloatType, }, ref) => {
61
+ const { gl, scene: defaultScene, camera: defaultCamera, size } = useThree();
62
+ const scene = _scene || defaultScene;
63
+ const camera = _camera || defaultCamera;
64
+ const [composer, normalPass, downSamplingPass] = useMemo(() => {
65
+ const webGL2Available = isWebGL2Available();
66
+ // Initialize composer
67
+ const effectComposer = new EffectComposer$1(gl, {
68
+ depthBuffer,
69
+ stencilBuffer,
70
+ multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
71
+ frameBufferType,
139
72
  });
140
- downSamplingPass.enabled = false;
141
- effectComposer.addPass(downSamplingPass);
142
- }
143
- }
144
- return [effectComposer, normalPass, downSamplingPass];
145
- }, [camera, gl, depthBuffer, stencilBuffer, multisampling, frameBufferType, scene, disableNormalPass, resolutionScale]);
146
- useEffect(() => composer == null ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
147
- useFrame((_, delta) => {
148
- if (enabled) {
149
- gl.autoClear = autoClear;
150
- composer.render(delta);
151
- }
152
- }, enabled ? renderPriority : 0);
153
- const group = useRef(null);
154
- const instance = useInstanceHandle(group);
155
- useLayoutEffect(() => {
156
- let effectPass;
157
- if (group.current && instance.current && composer) {
158
- effectPass = new EffectPass(camera, ...instance.current.objects);
159
- effectPass.renderToScreen = true;
160
- composer.addPass(effectPass);
161
- if (normalPass) normalPass.enabled = true;
162
- if (downSamplingPass) downSamplingPass.enabled = true;
163
- }
164
- return () => {
165
- if (effectPass) composer == null ? void 0 : composer.removePass(effectPass);
166
- if (normalPass) normalPass.enabled = false;
167
- if (downSamplingPass) downSamplingPass.enabled = false;
168
- };
169
- }, [composer, children, camera, normalPass, downSamplingPass, instance]);
170
-
171
- // Memoize state, otherwise it would trigger all consumers on every render
172
- const state = useMemo(() => ({
173
- composer,
174
- normalPass,
175
- downSamplingPass,
176
- resolutionScale,
177
- camera,
178
- scene
179
- }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]);
180
-
181
- // Expose the composer
182
- useImperativeHandle(ref, () => composer, [composer]);
183
- return /*#__PURE__*/React$1.createElement(EffectComposerContext.Provider, {
184
- value: state
185
- }, /*#__PURE__*/React$1.createElement("group", {
186
- ref: group
187
- }, children));
73
+ // Add render pass
74
+ effectComposer.addPass(new RenderPass(scene, camera));
75
+ // Create normal pass
76
+ let downSamplingPass = null;
77
+ let normalPass = null;
78
+ if (!disableNormalPass) {
79
+ normalPass = new NormalPass(scene, camera);
80
+ normalPass.enabled = false;
81
+ effectComposer.addPass(normalPass);
82
+ if (resolutionScale !== undefined && webGL2Available) {
83
+ downSamplingPass = new DepthDownsamplingPass({ normalBuffer: normalPass.texture, resolutionScale });
84
+ downSamplingPass.enabled = false;
85
+ effectComposer.addPass(downSamplingPass);
86
+ }
87
+ }
88
+ return [effectComposer, normalPass, downSamplingPass];
89
+ }, [
90
+ camera,
91
+ gl,
92
+ depthBuffer,
93
+ stencilBuffer,
94
+ multisampling,
95
+ frameBufferType,
96
+ scene,
97
+ disableNormalPass,
98
+ resolutionScale,
99
+ ]);
100
+ useEffect(() => composer === null || composer === void 0 ? void 0 : composer.setSize(size.width, size.height), [composer, size]);
101
+ useFrame((_, delta) => {
102
+ if (enabled) {
103
+ gl.autoClear = autoClear;
104
+ composer.render(delta);
105
+ }
106
+ }, enabled ? renderPriority : 0);
107
+ const group = useRef(null);
108
+ const instance = useInstanceHandle(group);
109
+ useLayoutEffect(() => {
110
+ let effectPass;
111
+ if (group.current && instance.current && composer) {
112
+ effectPass = new EffectPass(camera, ...instance.current.objects);
113
+ effectPass.renderToScreen = true;
114
+ composer.addPass(effectPass);
115
+ if (normalPass)
116
+ normalPass.enabled = true;
117
+ if (downSamplingPass)
118
+ downSamplingPass.enabled = true;
119
+ }
120
+ return () => {
121
+ if (effectPass)
122
+ composer === null || composer === void 0 ? void 0 : composer.removePass(effectPass);
123
+ if (normalPass)
124
+ normalPass.enabled = false;
125
+ if (downSamplingPass)
126
+ downSamplingPass.enabled = false;
127
+ };
128
+ }, [composer, children, camera, normalPass, downSamplingPass, instance]);
129
+ // Memoize state, otherwise it would trigger all consumers on every render
130
+ const state = useMemo(() => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }), [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]);
131
+ // Expose the composer
132
+ useImperativeHandle(ref, () => composer, [composer]);
133
+ return (jsx(EffectComposerContext.Provider, { value: state, children: jsx("group", { ref: group, children: children }) }));
188
134
  }));
189
135
 
190
- const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
191
- let {
192
- target,
193
- depthTexture,
194
- ...props
195
- } = _ref;
196
- const invalidate = useThree(state => state.invalidate);
197
- const {
198
- camera
199
- } = useContext(EffectComposerContext);
200
- const effect = useMemo(() => new DepthOfFieldEffect(camera, props), [camera, props]);
201
- useLayoutEffect(() => {
202
- if (target && typeof target !== 'number') {
203
- const vec = target instanceof Vector3 ? new Vector3().set(target.x, target.y, target.z) : new Vector3().set(target[0], target[1], target[2]);
204
- effect.target = vec;
205
- }
206
- if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
207
- invalidate();
208
- }, [target, depthTexture, effect]);
209
- return /*#__PURE__*/React.createElement("primitive", {
210
- ref: ref,
211
- object: effect,
212
- dispose: null
213
- });
136
+ const DepthOfField = forwardRef(function DepthOfField({ target, depthTexture, ...props }, ref) {
137
+ const invalidate = useThree((state) => state.invalidate);
138
+ const { camera } = useContext(EffectComposerContext);
139
+ const effect = useMemo(() => new DepthOfFieldEffect(camera, props), [camera, props]);
140
+ useLayoutEffect(() => {
141
+ if (target && typeof target !== 'number') {
142
+ const vec = target instanceof Vector3
143
+ ? new Vector3().set(target.x, target.y, target.z)
144
+ : new Vector3().set(target[0], target[1], target[2]);
145
+ effect.target = vec;
146
+ }
147
+ if (depthTexture)
148
+ effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
149
+ invalidate();
150
+ }, [target, depthTexture, effect]);
151
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
214
152
  });
215
153
 
216
154
  const DotScreen = wrapEffect(DotScreenEffect);
217
155
 
218
- const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
219
- let {
220
- active = true,
221
- ...props
222
- } = _ref;
223
- const invalidate = useThree(state => state.invalidate);
224
- const delay = useVector2(props, 'delay');
225
- const duration = useVector2(props, 'duration');
226
- const strength = useVector2(props, 'strength');
227
- const effect = useMemo(() => new GlitchEffect({
228
- ...props,
229
- delay,
230
- duration,
231
- strength
232
- }), [delay, duration, props, strength]);
233
- useLayoutEffect(() => {
234
- effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED;
235
- invalidate();
236
- }, [active, effect, invalidate, props.mode]);
237
- return /*#__PURE__*/React.createElement("primitive", {
238
- ref: ref,
239
- object: effect,
240
- dispose: null
241
- });
156
+ const Glitch = forwardRef(function Glitch({ active = true, ...props }, ref) {
157
+ const invalidate = useThree((state) => state.invalidate);
158
+ const delay = useVector2(props, 'delay');
159
+ const duration = useVector2(props, 'duration');
160
+ const strength = useVector2(props, 'strength');
161
+ const effect = useMemo(() => new GlitchEffect({ ...props, delay, duration, strength }), [delay, duration, props, strength]);
162
+ useLayoutEffect(() => {
163
+ effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED;
164
+ invalidate();
165
+ }, [active, effect, invalidate, props.mode]);
166
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
242
167
  });
243
168
 
244
- const GodRays = /*#__PURE__*/forwardRef(function GodRays(props, ref) {
245
- const {
246
- camera
247
- } = useContext(EffectComposerContext);
248
- const effect = useMemo(() => new GodRaysEffect(camera, props.sun, props), [camera, props]);
249
- return /*#__PURE__*/React$1.createElement("primitive", {
250
- ref: ref,
251
- object: effect,
252
- dispose: null
253
- });
169
+ const GodRays = forwardRef(function GodRays(props, ref) {
170
+ const { camera } = useContext(EffectComposerContext);
171
+ const effect = useMemo(() => new GodRaysEffect(camera, props.sun, props), [camera, props]);
172
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
254
173
  });
255
174
 
256
- const Grid = /*#__PURE__*/forwardRef(function Grid(_ref, ref) {
257
- let {
258
- size,
259
- ...props
260
- } = _ref;
261
- const invalidate = useThree(state => state.invalidate);
262
- const effect = useMemo(() => new GridEffect(props), [props]);
263
- useLayoutEffect(() => {
264
- if (size) effect.setSize(size.width, size.height);
265
- invalidate();
266
- }, [effect, size]);
267
- return /*#__PURE__*/React$1.createElement("primitive", {
268
- ref: ref,
269
- object: effect,
270
- dispose: null
271
- });
175
+ const Grid = forwardRef(function Grid({ size, ...props }, ref) {
176
+ const invalidate = useThree((state) => state.invalidate);
177
+ const effect = useMemo(() => new GridEffect(props), [props]);
178
+ useLayoutEffect(() => {
179
+ if (size)
180
+ effect.setSize(size.width, size.height);
181
+ invalidate();
182
+ }, [effect, size]);
183
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
272
184
  });
273
185
 
274
186
  const HueSaturation = wrapEffect(HueSaturationEffect);
275
187
 
276
- const Noise = wrapEffect(NoiseEffect, {
277
- blendFunction: BlendFunction.COLOR_DODGE
278
- });
188
+ const Noise = wrapEffect(NoiseEffect, { blendFunction: BlendFunction.COLOR_DODGE });
279
189
 
280
- const selectionContext = /*#__PURE__*/createContext(null);
281
- function Selection(_ref) {
282
- let {
283
- children,
284
- enabled = true
285
- } = _ref;
286
- const [selected, select] = useState([]);
287
- const value = useMemo(() => ({
288
- selected,
289
- select,
290
- enabled
291
- }), [selected, select, enabled]);
292
- return /*#__PURE__*/React$1.createElement(selectionContext.Provider, {
293
- value: value
294
- }, children);
190
+ const selectionContext = createContext(null);
191
+ function Selection({ children, enabled = true }) {
192
+ const [selected, select] = useState([]);
193
+ const value = useMemo(() => ({ selected, select, enabled }), [selected, select, enabled]);
194
+ return jsx(selectionContext.Provider, { value: value, children: children });
295
195
  }
296
- function Select(_ref2) {
297
- let {
298
- enabled = false,
299
- children,
300
- ...props
301
- } = _ref2;
302
- const group = useRef(null);
303
- const api = useContext(selectionContext);
304
- useEffect(() => {
305
- if (api && enabled) {
306
- let changed = false;
307
- const current = [];
308
- group.current.traverse(o => {
309
- o.type === 'Mesh' && current.push(o);
310
- if (api.selected.indexOf(o) === -1) changed = true;
311
- });
312
- if (changed) {
313
- api.select(state => [...state, ...current]);
314
- return () => {
315
- api.select(state => state.filter(selected => !current.includes(selected)));
316
- };
317
- }
318
- }
319
- }, [enabled, children]);
320
- return /*#__PURE__*/React$1.createElement("group", _extends({
321
- ref: group
322
- }, props), children);
196
+ function Select({ enabled = false, children, ...props }) {
197
+ const group = useRef(null);
198
+ const api = useContext(selectionContext);
199
+ useEffect(() => {
200
+ if (api && enabled) {
201
+ let changed = false;
202
+ const current = [];
203
+ group.current.traverse((o) => {
204
+ o.type === 'Mesh' && current.push(o);
205
+ if (api.selected.indexOf(o) === -1)
206
+ changed = true;
207
+ });
208
+ if (changed) {
209
+ api.select((state) => [...state, ...current]);
210
+ return () => {
211
+ api.select((state) => state.filter((selected) => !current.includes(selected)));
212
+ };
213
+ }
214
+ }
215
+ }, [enabled, children, api]);
216
+ return (jsx("group", { ref: group, ...props, children: children }));
323
217
  }
324
218
 
325
- const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
326
- let {
327
- selection = [],
328
- selectionLayer = 10,
329
- blendFunction,
330
- patternTexture,
331
- edgeStrength,
332
- pulseSpeed,
333
- visibleEdgeColor,
334
- hiddenEdgeColor,
335
- width,
336
- height,
337
- kernelSize,
338
- blur,
339
- xRay,
340
- ...props
341
- } = _ref;
342
- const invalidate = useThree(state => state.invalidate);
343
- const {
344
- scene,
345
- camera
346
- } = useContext(EffectComposerContext);
347
- const effect = useMemo(() => new OutlineEffect(scene, camera, {
348
- blendFunction,
349
- patternTexture,
350
- edgeStrength,
351
- pulseSpeed,
352
- visibleEdgeColor,
353
- hiddenEdgeColor,
354
- width,
355
- height,
356
- kernelSize,
357
- blur,
358
- xRay,
359
- ...props
360
- }), [blendFunction, blur, camera, edgeStrength, height, hiddenEdgeColor, kernelSize, patternTexture, props, pulseSpeed, scene, visibleEdgeColor, width, xRay]);
361
- const api = useContext(selectionContext);
362
- useEffect(() => {
363
- // Do not allow array selection if declarative selection is active
364
- // TODO: array selection should probably be deprecated altogether
365
- if (!api && selection) {
366
- effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
367
- invalidate();
368
- return () => {
369
- effect.selection.clear();
370
- invalidate();
371
- };
372
- }
373
- }, [effect, selection, api, invalidate]);
374
- useEffect(() => {
375
- effect.selectionLayer = selectionLayer;
376
- invalidate();
377
- }, [effect, invalidate, selectionLayer]);
378
- useRef();
379
- useEffect(() => {
380
- if (api && api.enabled) {
381
- var _api$selected;
382
- if ((_api$selected = api.selected) != null && _api$selected.length) {
383
- effect.selection.set(api.selected);
219
+ const Outline = forwardRef(function Outline({ selection = [], selectionLayer = 10, blendFunction, patternTexture, edgeStrength, pulseSpeed, visibleEdgeColor, hiddenEdgeColor, width, height, kernelSize, blur, xRay, ...props }, forwardRef) {
220
+ const invalidate = useThree((state) => state.invalidate);
221
+ const { scene, camera } = useContext(EffectComposerContext);
222
+ const effect = useMemo(() => new OutlineEffect(scene, camera, {
223
+ blendFunction,
224
+ patternTexture,
225
+ edgeStrength,
226
+ pulseSpeed,
227
+ visibleEdgeColor,
228
+ hiddenEdgeColor,
229
+ width,
230
+ height,
231
+ kernelSize,
232
+ blur,
233
+ xRay,
234
+ ...props,
235
+ }), [
236
+ blendFunction,
237
+ blur,
238
+ camera,
239
+ edgeStrength,
240
+ height,
241
+ hiddenEdgeColor,
242
+ kernelSize,
243
+ patternTexture,
244
+ props,
245
+ pulseSpeed,
246
+ scene,
247
+ visibleEdgeColor,
248
+ width,
249
+ xRay,
250
+ ]);
251
+ const api = useContext(selectionContext);
252
+ useEffect(() => {
253
+ // Do not allow array selection if declarative selection is active
254
+ // TODO: array selection should probably be deprecated altogether
255
+ if (!api && selection) {
256
+ effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
257
+ invalidate();
258
+ return () => {
259
+ effect.selection.clear();
260
+ invalidate();
261
+ };
262
+ }
263
+ }, [effect, selection, api, invalidate]);
264
+ useEffect(() => {
265
+ effect.selectionLayer = selectionLayer;
384
266
  invalidate();
385
- return () => {
386
- effect.selection.clear();
387
- invalidate();
388
- };
389
- }
390
- }
391
- }, [api, effect.selection, invalidate]);
392
- return /*#__PURE__*/React.createElement("primitive", {
393
- ref: forwardRef,
394
- object: effect
395
- });
267
+ }, [effect, invalidate, selectionLayer]);
268
+ useRef();
269
+ useEffect(() => {
270
+ var _a;
271
+ if (api && api.enabled) {
272
+ if ((_a = api.selected) === null || _a === void 0 ? void 0 : _a.length) {
273
+ effect.selection.set(api.selected);
274
+ invalidate();
275
+ return () => {
276
+ effect.selection.clear();
277
+ invalidate();
278
+ };
279
+ }
280
+ }
281
+ }, [api, effect.selection, invalidate]);
282
+ return jsx("primitive", { ref: forwardRef, object: effect });
396
283
  });
397
284
 
398
- const Pixelation = /*#__PURE__*/forwardRef(function Pixelation(_ref, ref) {
399
- let {
400
- granularity = 5
401
- } = _ref;
402
- /** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
403
- const effect = useMemo(() => new PixelationEffect(granularity), [granularity]);
404
- return /*#__PURE__*/React$1.createElement("primitive", {
405
- ref: ref,
406
- object: effect,
407
- dispose: null
408
- });
285
+ const Pixelation = forwardRef(function Pixelation({ granularity = 5 }, ref) {
286
+ /** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
287
+ const effect = useMemo(() => new PixelationEffect(granularity), [granularity]);
288
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
409
289
  });
410
290
 
411
- const Scanline = wrapEffect(ScanlineEffect, {
412
- blendFunction: BlendFunction.OVERLAY
413
- });
291
+ const Scanline = wrapEffect(ScanlineEffect, { blendFunction: BlendFunction.OVERLAY });
414
292
 
415
293
  const addLight = (light, effect) => light.layers.enable(effect.selection.layer);
416
294
  const removeLight = (light, effect) => light.layers.disable(effect.selection.layer);
417
- const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, forwardRef) {
418
- let {
419
- selection = [],
420
- selectionLayer = 10,
421
- lights = [],
422
- luminanceThreshold,
423
- luminanceSmoothing,
424
- intensity,
425
- width,
426
- height,
427
- kernelSize,
428
- mipmapBlur,
429
- ...props
430
- } = _ref;
431
- if (lights.length === 0) {
432
- console.warn('SelectiveBloom requires lights to work.');
433
- }
434
- const invalidate = useThree(state => state.invalidate);
435
- const {
436
- scene,
437
- camera
438
- } = useContext(EffectComposerContext);
439
- const effect = useMemo(() => new SelectiveBloomEffect(scene, camera, {
440
- blendFunction: BlendFunction.ADD,
441
- luminanceThreshold,
442
- luminanceSmoothing,
443
- intensity,
444
- width,
445
- height,
446
- kernelSize,
447
- mipmapBlur,
448
- ...props
449
- }), [scene, camera, luminanceThreshold, luminanceSmoothing, intensity, width, height, kernelSize, mipmapBlur, props]);
450
- const api = useContext(selectionContext);
451
- useEffect(() => {
452
- // Do not allow array selection if declarative selection is active
453
- // TODO: array selection should probably be deprecated altogether
454
- if (!api && selection) {
455
- effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
456
- invalidate();
457
- return () => {
458
- effect.selection.clear();
459
- invalidate();
460
- };
295
+ const SelectiveBloom = forwardRef(function SelectiveBloom({ selection = [], selectionLayer = 10, lights = [], luminanceThreshold, luminanceSmoothing, intensity, width, height, kernelSize, mipmapBlur, ...props }, forwardRef) {
296
+ if (lights.length === 0) {
297
+ console.warn('SelectiveBloom requires lights to work.');
461
298
  }
462
- }, [effect, selection, api, invalidate]);
463
- useEffect(() => {
464
- effect.selection.layer = selectionLayer;
465
- invalidate();
466
- }, [effect, invalidate, selectionLayer]);
467
- useEffect(() => {
468
- if (lights && lights.length > 0) {
469
- lights.forEach(light => addLight(resolveRef(light), effect));
470
- invalidate();
471
- return () => {
472
- lights.forEach(light => removeLight(resolveRef(light), effect));
473
- invalidate();
474
- };
475
- }
476
- }, [effect, invalidate, lights, selectionLayer]);
477
- useRef();
478
- useEffect(() => {
479
- if (api && api.enabled) {
480
- var _api$selected;
481
- if ((_api$selected = api.selected) != null && _api$selected.length) {
482
- effect.selection.set(api.selected);
299
+ const invalidate = useThree((state) => state.invalidate);
300
+ const { scene, camera } = useContext(EffectComposerContext);
301
+ const effect = useMemo(() => new SelectiveBloomEffect(scene, camera, {
302
+ blendFunction: BlendFunction.ADD,
303
+ luminanceThreshold,
304
+ luminanceSmoothing,
305
+ intensity,
306
+ width,
307
+ height,
308
+ kernelSize,
309
+ mipmapBlur,
310
+ ...props,
311
+ }), [scene, camera, luminanceThreshold, luminanceSmoothing, intensity, width, height, kernelSize, mipmapBlur, props]);
312
+ const api = useContext(selectionContext);
313
+ useEffect(() => {
314
+ // Do not allow array selection if declarative selection is active
315
+ // TODO: array selection should probably be deprecated altogether
316
+ if (!api && selection) {
317
+ effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
318
+ invalidate();
319
+ return () => {
320
+ effect.selection.clear();
321
+ invalidate();
322
+ };
323
+ }
324
+ }, [effect, selection, api, invalidate]);
325
+ useEffect(() => {
326
+ effect.selection.layer = selectionLayer;
483
327
  invalidate();
484
- return () => {
485
- effect.selection.clear();
486
- invalidate();
487
- };
488
- }
489
- }
490
- }, [api, effect.selection, invalidate]);
491
- return /*#__PURE__*/React$1.createElement("primitive", {
492
- ref: forwardRef,
493
- object: effect,
494
- dispose: null
495
- });
328
+ }, [effect, invalidate, selectionLayer]);
329
+ useEffect(() => {
330
+ if (lights && lights.length > 0) {
331
+ lights.forEach((light) => addLight(resolveRef(light), effect));
332
+ invalidate();
333
+ return () => {
334
+ lights.forEach((light) => removeLight(resolveRef(light), effect));
335
+ invalidate();
336
+ };
337
+ }
338
+ }, [effect, invalidate, lights, selectionLayer]);
339
+ useRef();
340
+ useEffect(() => {
341
+ var _a;
342
+ if (api && api.enabled) {
343
+ if ((_a = api.selected) === null || _a === void 0 ? void 0 : _a.length) {
344
+ effect.selection.set(api.selected);
345
+ invalidate();
346
+ return () => {
347
+ effect.selection.clear();
348
+ invalidate();
349
+ };
350
+ }
351
+ }
352
+ }, [api, effect.selection, invalidate]);
353
+ return jsx("primitive", { ref: forwardRef, object: effect, dispose: null });
496
354
  });
497
355
 
498
356
  const Sepia = wrapEffect(SepiaEffect);
499
357
 
500
- // first two args are camera and texture
501
-
502
- const SSAO = /*#__PURE__*/forwardRef(function SSAO(props, ref) {
503
- const {
504
- camera,
505
- normalPass,
506
- downSamplingPass,
507
- resolutionScale
508
- } = useContext(EffectComposerContext);
509
- const effect = useMemo(() => {
510
- if (normalPass === null && downSamplingPass === null) {
511
- console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.');
512
- return {};
513
- }
514
- return new SSAOEffect(camera, normalPass && !downSamplingPass ? normalPass.texture : null, {
515
- blendFunction: BlendFunction.MULTIPLY,
516
- samples: 30,
517
- rings: 4,
518
- distanceThreshold: 1.0,
519
- distanceFalloff: 0.0,
520
- rangeThreshold: 0.5,
521
- rangeFalloff: 0.1,
522
- luminanceInfluence: 0.9,
523
- radius: 20,
524
- bias: 0.5,
525
- intensity: 1.0,
526
- color: undefined,
527
- // @ts-ignore
528
- normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
529
- resolutionScale: resolutionScale != null ? resolutionScale : 1,
530
- depthAwareUpsampling: true,
531
- ...props
532
- });
533
- }, [camera, normalPass, props]);
534
- return /*#__PURE__*/React.createElement("primitive", {
535
- ref: ref,
536
- object: effect,
537
- dispose: null
538
- });
358
+ const SSAO = forwardRef(function SSAO(props, ref) {
359
+ const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext);
360
+ const effect = useMemo(() => {
361
+ if (normalPass === null && downSamplingPass === null) {
362
+ console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.');
363
+ return {};
364
+ }
365
+ return new SSAOEffect(camera, normalPass && !downSamplingPass ? normalPass.texture : null, {
366
+ blendFunction: BlendFunction.MULTIPLY,
367
+ samples: 30,
368
+ rings: 4,
369
+ distanceThreshold: 1.0,
370
+ distanceFalloff: 0.0,
371
+ rangeThreshold: 0.5,
372
+ rangeFalloff: 0.1,
373
+ luminanceInfluence: 0.9,
374
+ radius: 20,
375
+ bias: 0.5,
376
+ intensity: 1.0,
377
+ color: undefined,
378
+ // @ts-ignore
379
+ normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
380
+ resolutionScale: resolutionScale !== null && resolutionScale !== void 0 ? resolutionScale : 1,
381
+ depthAwareUpsampling: true,
382
+ ...props,
383
+ });
384
+ }, [camera, normalPass, props]);
385
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
539
386
  });
540
387
 
541
388
  const SMAA = wrapEffect(SMAAEffect);
542
389
 
543
- const Texture = /*#__PURE__*/forwardRef(function Texture(_ref, ref) {
544
- let {
545
- textureSrc,
546
- texture,
547
- ...props
548
- } = _ref;
549
- const t = useLoader(TextureLoader, textureSrc);
550
- useLayoutEffect(() => {
551
- t.encoding = sRGBEncoding;
552
- t.wrapS = t.wrapT = RepeatWrapping;
553
- }, [t]);
554
- const effect = useMemo(() => new TextureEffect({
555
- ...props,
556
- texture: t || texture
557
- }), [props, t, texture]);
558
- return /*#__PURE__*/React.createElement("primitive", {
559
- ref: ref,
560
- object: effect,
561
- dispose: null
562
- });
390
+ const Texture = forwardRef(function Texture({ textureSrc, texture, ...props }, ref) {
391
+ const t = useLoader(TextureLoader, textureSrc);
392
+ useLayoutEffect(() => {
393
+ t.encoding = sRGBEncoding;
394
+ t.wrapS = t.wrapT = RepeatWrapping;
395
+ }, [t]);
396
+ const effect = useMemo(() => new TextureEffect({ ...props, texture: t || texture }), [props, t, texture]);
397
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
563
398
  });
564
399
 
565
400
  const ToneMapping = wrapEffect(ToneMappingEffect);
@@ -568,32 +403,23 @@ const Vignette = wrapEffect(VignetteEffect);
568
403
 
569
404
  const ShockWave = wrapEffect(ShockWaveEffect);
570
405
 
571
- const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
572
- let {
573
- lut,
574
- tetrahedralInterpolation,
575
- ...props
576
- } = _ref;
577
- const effect = useMemo(() => new LUT3DEffect(lut, props), [lut, props]);
578
- const invalidate = useThree(state => state.invalidate);
579
- useLayoutEffect(() => {
580
- if (tetrahedralInterpolation) effect.tetrahedralInterpolation = tetrahedralInterpolation;
581
- if (lut) effect.lut = lut;
582
- invalidate();
583
- }, [effect, invalidate, lut, tetrahedralInterpolation]);
584
- return /*#__PURE__*/React$1.createElement("primitive", {
585
- ref: ref,
586
- object: effect,
587
- dispose: null
588
- });
406
+ const LUT = forwardRef(function LUT({ lut, tetrahedralInterpolation, ...props }, ref) {
407
+ const effect = useMemo(() => new LUT3DEffect(lut, props), [lut, props]);
408
+ const invalidate = useThree((state) => state.invalidate);
409
+ useLayoutEffect(() => {
410
+ if (tetrahedralInterpolation)
411
+ effect.tetrahedralInterpolation = tetrahedralInterpolation;
412
+ if (lut)
413
+ effect.lut = lut;
414
+ invalidate();
415
+ }, [effect, invalidate, lut, tetrahedralInterpolation]);
416
+ return jsx("primitive", { ref: ref, object: effect, dispose: null });
589
417
  });
590
418
 
591
- const TiltShift = wrapEffect(TiltShiftEffect$1, {
592
- blendFunction: BlendFunction.ADD
593
- });
419
+ const TiltShift = wrapEffect(TiltShiftEffect$1, { blendFunction: BlendFunction.ADD });
594
420
 
595
421
  const TiltShiftShader = {
596
- fragmentShader: `
422
+ fragmentShader: `
597
423
 
598
424
  // original shader by Evan Wallace
599
425
 
@@ -649,73 +475,51 @@ const TiltShiftShader = {
649
475
  /* switch back from pre-multiplied alpha */
650
476
  outputColor.rgb /= outputColor.a + 0.00001;
651
477
  }
652
- `
478
+ `,
653
479
  };
654
480
  class TiltShiftEffect extends Effect {
655
- constructor(_temp) {
656
- let {
657
- blendFunction = BlendFunction.NORMAL,
658
- blur = 0.15,
659
- // [0, 1], can go beyond 1 for extra
660
- taper = 0.5,
661
- // [0, 1], can go beyond 1 for extra
662
- start = [0.5, 0.0],
663
- // [0,1] percentage x,y of screenspace
664
- end = [0.5, 1.0],
665
- // [0,1] percentage x,y of screenspace
666
- samples = 10.0,
667
- // number of blur samples
668
- direction = [1, 1] // direction of blur
669
- } = _temp === void 0 ? {} : _temp;
670
- super('TiltShiftEffect', TiltShiftShader.fragmentShader, {
671
- blendFunction,
672
- attributes: EffectAttribute.CONVOLUTION,
673
- uniforms: new Map([['blur', new Uniform(blur)], ['taper', new Uniform(taper)], ['start', new Uniform(start)], ['end', new Uniform(end)], ['samples', new Uniform(samples)], ['direction', new Uniform(direction)]])
674
- });
675
- }
676
- }
677
- const TiltShift2 = wrapEffect(TiltShiftEffect, {
678
- blendFunction: BlendFunction.NORMAL
679
- });
680
-
681
- // first two args are camera and texture
682
-
683
- const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
684
- let {
685
- ENABLE_BLUR = true,
686
- USE_MRT = true,
687
- ...props
688
- } = _ref;
689
- const {
690
- invalidate
691
- } = useThree();
692
- const {
693
- scene,
694
- camera
695
- } = useContext(EffectComposerContext);
696
- const effect = useMemo(() => new SSREffect(scene, camera, {
697
- ENABLE_BLUR,
698
- USE_MRT,
699
- ...props
700
- }), [scene, camera, ENABLE_BLUR, USE_MRT, props]);
701
- const api = useContext(selectionContext);
702
- useEffect(() => {
703
- if (api && api.enabled) {
704
- var _api$selected;
705
- if ((_api$selected = api.selected) != null && _api$selected.length) {
706
- effect.selection.set(api.selected);
707
- invalidate();
708
- return () => {
709
- effect.selection.clear();
710
- invalidate();
711
- };
712
- }
481
+ constructor({ blendFunction = BlendFunction.NORMAL, blur = 0.15, // [0, 1], can go beyond 1 for extra
482
+ taper = 0.5, // [0, 1], can go beyond 1 for extra
483
+ start = [0.5, 0.0], // [0,1] percentage x,y of screenspace
484
+ end = [0.5, 1.0], // [0,1] percentage x,y of screenspace
485
+ samples = 10.0, // number of blur samples
486
+ direction = [1, 1], // direction of blur
487
+ } = {}) {
488
+ super('TiltShiftEffect', TiltShiftShader.fragmentShader, {
489
+ blendFunction,
490
+ attributes: EffectAttribute.CONVOLUTION,
491
+ uniforms: new Map([
492
+ ['blur', new Uniform(blur)],
493
+ ['taper', new Uniform(taper)],
494
+ ['start', new Uniform(start)],
495
+ ['end', new Uniform(end)],
496
+ ['samples', new Uniform(samples)],
497
+ ['direction', new Uniform(direction)],
498
+ ]),
499
+ });
713
500
  }
714
- }, [api]);
715
- return /*#__PURE__*/React$1.createElement("primitive", _extends({
716
- ref: ref,
717
- object: effect
718
- }, props));
501
+ }
502
+ const TiltShift2 = wrapEffect(TiltShiftEffect, { blendFunction: BlendFunction.NORMAL });
503
+
504
+ const SSR = forwardRef(function SSR({ ENABLE_BLUR = true, USE_MRT = true, ...props }, ref) {
505
+ const { invalidate } = useThree();
506
+ const { scene, camera } = useContext(EffectComposerContext);
507
+ const effect = useMemo(() => new SSREffect(scene, camera, { ENABLE_BLUR, USE_MRT, ...props }), [scene, camera, ENABLE_BLUR, USE_MRT, props]);
508
+ const api = useContext(selectionContext);
509
+ useEffect(() => {
510
+ var _a;
511
+ if (api && api.enabled) {
512
+ if ((_a = api.selected) === null || _a === void 0 ? void 0 : _a.length) {
513
+ effect.selection.set(api.selected);
514
+ invalidate();
515
+ return () => {
516
+ effect.selection.clear();
517
+ invalidate();
518
+ };
519
+ }
520
+ }
521
+ }, [api]);
522
+ return jsx("primitive", { ref: ref, object: effect, ...props });
719
523
  });
720
524
 
721
525
  export { Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DotScreen, EffectComposer, EffectComposerContext, Glitch, GodRays, Grid, HueSaturation, LUT, Noise, Outline, Pixelation, SMAA, SSAO, SSR, Scanline, Select, Selection, SelectiveBloom, Sepia, ShockWave, Texture, TiltShift, TiltShift2, TiltShiftEffect, ToneMapping, Vignette, resolveRef, selectionContext, useVector2, wrapEffect };