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