@react-three/postprocessing 2.8.3 → 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/EffectComposer.d.ts +3 -3
- package/dist/Selection.d.ts +3 -3
- package/dist/effects/BrightnessContrast.d.ts +8 -1
- package/dist/effects/ChromaticAberration.d.ts +5 -3
- package/dist/effects/ColorAverage.d.ts +1 -1
- package/dist/effects/ColorDepth.d.ts +7 -1
- package/dist/effects/Depth.d.ts +7 -1
- package/dist/effects/DepthOfField.d.ts +16 -11
- package/dist/effects/DotScreen.d.ts +8 -1
- package/dist/effects/Glitch.d.ts +15 -15
- package/dist/effects/GodRays.d.ts +14 -11
- package/dist/effects/Grid.d.ts +5 -5
- package/dist/effects/HueSaturation.d.ts +8 -1
- package/dist/effects/LUT.d.ts +7 -7
- package/dist/effects/Outline.d.ts +22 -17
- package/dist/effects/Pixelation.d.ts +3 -3
- package/dist/effects/SMAA.d.ts +9 -5
- package/dist/effects/SSAO.d.ts +29 -16
- package/dist/effects/SSR.d.ts +1 -1
- package/dist/effects/SelectiveBloom.d.ts +8 -3
- package/dist/effects/Sepia.d.ts +7 -1
- package/dist/effects/ShockWave.d.ts +4 -1
- package/dist/effects/Texture.d.ts +7 -6
- package/dist/effects/TiltShift2.d.ts +11 -9
- package/dist/effects/ToneMapping.d.ts +15 -1
- package/dist/effects/Vignette.d.ts +10 -1
- package/dist/index.cjs +479 -752
- package/dist/index.js +394 -616
- package/dist/util.d.ts +7 -6
- package/package.json +48 -56
package/dist/index.js
CHANGED
|
@@ -1,588 +1,400 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import React__default, { forwardRef, useMemo, createContext, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState } from 'react';
|
|
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 { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React, { forwardRef, useMemo, createContext, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState } from 'react';
|
|
5
4
|
import * as THREE from 'three';
|
|
6
5
|
import { HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
|
|
7
|
-
import { extend, useThree, useFrame, useLoader } from '@react-three/fiber';
|
|
6
|
+
import { extend, useThree, useFrame, useInstanceHandle, useLoader } from '@react-three/fiber';
|
|
8
7
|
import { isWebGL2Available } from 'three-stdlib';
|
|
9
8
|
import { SSREffect } from 'screen-space-reflections';
|
|
10
9
|
|
|
11
|
-
const resolveRef = ref => typeof ref === 'object' && 'current' in ref ? ref.current : ref;
|
|
10
|
+
const resolveRef = (ref) => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref;
|
|
12
11
|
let i = 0;
|
|
13
12
|
const components = new WeakMap();
|
|
14
|
-
const wrapEffect = (effect, defaults) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
components.set(effect, Component = key);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const camera = useThree(state => state.camera);
|
|
31
|
-
const args = React.useMemo(() => {
|
|
32
|
-
var _defaults$args, _props$args;
|
|
33
|
-
|
|
34
|
-
return [...((_defaults$args = defaults == null ? void 0 : defaults.args) != null ? _defaults$args : []), ...((_props$args = props.args) != null ? _props$args : [{ ...defaults,
|
|
35
|
-
...props
|
|
36
|
-
}])];
|
|
37
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
-
[JSON.stringify(props)]);
|
|
39
|
-
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
40
|
-
camera: camera,
|
|
41
|
-
"blendMode-blendFunction": blendFunction,
|
|
42
|
-
"blendMode-opacity": opacity
|
|
43
|
-
}, props, {
|
|
44
|
-
ref: ref,
|
|
45
|
-
args: args
|
|
46
|
-
}));
|
|
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 }));
|
|
47
26
|
});
|
|
48
27
|
const useVector2 = (props, key) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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]);
|
|
53
37
|
};
|
|
54
38
|
|
|
55
|
-
const Bloom = wrapEffect(BloomEffect, {
|
|
56
|
-
blendFunction: BlendFunction.ADD
|
|
57
|
-
});
|
|
39
|
+
const Bloom = wrapEffect(BloomEffect, { blendFunction: BlendFunction.ADD });
|
|
58
40
|
|
|
59
41
|
const BrightnessContrast = wrapEffect(BrightnessContrastEffect);
|
|
60
42
|
|
|
61
|
-
const ChromaticAberration =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}), [offset, props]);
|
|
66
|
-
return /*#__PURE__*/React__default.createElement("primitive", {
|
|
67
|
-
ref: ref,
|
|
68
|
-
object: effect,
|
|
69
|
-
dispose: null
|
|
70
|
-
});
|
|
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 });
|
|
71
47
|
});
|
|
72
48
|
|
|
73
|
-
const ColorAverage =
|
|
74
|
-
|
|
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__default.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 =
|
|
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
|
-
scene = scene || defaultScene;
|
|
114
|
-
camera = camera || defaultCamera;
|
|
115
|
-
const [composer, normalPass, downSamplingPass] = useMemo(() => {
|
|
116
|
-
const webGL2Available = isWebGL2Available(); // Initialize composer
|
|
117
|
-
|
|
118
|
-
const effectComposer = new EffectComposer$1(gl, {
|
|
119
|
-
depthBuffer,
|
|
120
|
-
stencilBuffer,
|
|
121
|
-
multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,
|
|
122
|
-
frameBufferType
|
|
123
|
-
}); // Add render pass
|
|
124
|
-
|
|
125
|
-
effectComposer.addPass(new RenderPass(scene, camera)); // Create normal pass
|
|
126
|
-
|
|
127
|
-
let downSamplingPass = null;
|
|
128
|
-
let normalPass = null;
|
|
129
|
-
|
|
130
|
-
if (!disableNormalPass) {
|
|
131
|
-
normalPass = new NormalPass(scene, camera);
|
|
132
|
-
normalPass.enabled = false;
|
|
133
|
-
effectComposer.addPass(normalPass);
|
|
134
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
|
|
208
|
-
invalidate();
|
|
209
|
-
}, [target, depthTexture, effect]);
|
|
210
|
-
return /*#__PURE__*/React__default.createElement("primitive", {
|
|
211
|
-
ref: ref,
|
|
212
|
-
object: effect,
|
|
213
|
-
dispose: null
|
|
214
|
-
});
|
|
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 });
|
|
215
152
|
});
|
|
216
153
|
|
|
217
154
|
const DotScreen = wrapEffect(DotScreenEffect);
|
|
218
155
|
|
|
219
|
-
const Glitch =
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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, props.mode]);
|
|
237
|
-
return /*#__PURE__*/React__default.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 =
|
|
245
|
-
|
|
246
|
-
camera
|
|
247
|
-
|
|
248
|
-
const effect = useMemo(() => new GodRaysEffect(camera, props.sun, props), [camera, props]);
|
|
249
|
-
return /*#__PURE__*/React__default.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 =
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
invalidate();
|
|
266
|
-
}, [effect, size]);
|
|
267
|
-
return /*#__PURE__*/React__default.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 =
|
|
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__default.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(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}, [enabled, children]);
|
|
321
|
-
return /*#__PURE__*/React__default.createElement("group", _extends({
|
|
322
|
-
ref: group
|
|
323
|
-
}, 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 }));
|
|
324
217
|
}
|
|
325
218
|
|
|
326
|
-
const Outline =
|
|
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
|
-
}
|
|
374
|
-
}, [effect, selection, api]);
|
|
375
|
-
useEffect(() => {
|
|
376
|
-
effect.selectionLayer = selectionLayer;
|
|
377
|
-
invalidate();
|
|
378
|
-
}, [effect, selectionLayer]);
|
|
379
|
-
useRef();
|
|
380
|
-
useEffect(() => {
|
|
381
|
-
if (api && api.enabled) {
|
|
382
|
-
var _api$selected;
|
|
383
|
-
|
|
384
|
-
if ((_api$selected = api.selected) != null && _api$selected.length) {
|
|
385
|
-
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;
|
|
386
266
|
invalidate();
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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 });
|
|
398
283
|
});
|
|
399
284
|
|
|
400
|
-
const Pixelation =
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
/** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
|
|
406
|
-
const effect = useMemo(() => new PixelationEffect(granularity), [granularity]);
|
|
407
|
-
return /*#__PURE__*/React__default.createElement("primitive", {
|
|
408
|
-
ref: ref,
|
|
409
|
-
object: effect,
|
|
410
|
-
dispose: null
|
|
411
|
-
});
|
|
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 });
|
|
412
289
|
});
|
|
413
290
|
|
|
414
|
-
const Scanline = wrapEffect(ScanlineEffect, {
|
|
415
|
-
blendFunction: BlendFunction.OVERLAY
|
|
416
|
-
});
|
|
291
|
+
const Scanline = wrapEffect(ScanlineEffect, { blendFunction: BlendFunction.OVERLAY });
|
|
417
292
|
|
|
418
293
|
const addLight = (light, effect) => light.layers.enable(effect.selection.layer);
|
|
419
|
-
|
|
420
294
|
const removeLight = (light, effect) => light.layers.disable(effect.selection.layer);
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
selection = [],
|
|
425
|
-
selectionLayer = 10,
|
|
426
|
-
lights = [],
|
|
427
|
-
luminanceThreshold,
|
|
428
|
-
luminanceSmoothing,
|
|
429
|
-
intensity,
|
|
430
|
-
width,
|
|
431
|
-
height,
|
|
432
|
-
kernelSize,
|
|
433
|
-
mipmapBlur,
|
|
434
|
-
radius,
|
|
435
|
-
levels,
|
|
436
|
-
...props
|
|
437
|
-
} = _ref;
|
|
438
|
-
|
|
439
|
-
if (lights.length === 0) {
|
|
440
|
-
console.warn('SelectiveBloom requires lights to work.');
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
const invalidate = useThree(state => state.invalidate);
|
|
444
|
-
const {
|
|
445
|
-
scene,
|
|
446
|
-
camera
|
|
447
|
-
} = useContext(EffectComposerContext);
|
|
448
|
-
const effect = useMemo(() => new SelectiveBloomEffect(scene, camera, {
|
|
449
|
-
blendFunction: BlendFunction.ADD,
|
|
450
|
-
luminanceThreshold,
|
|
451
|
-
luminanceSmoothing,
|
|
452
|
-
intensity,
|
|
453
|
-
width,
|
|
454
|
-
height,
|
|
455
|
-
kernelSize,
|
|
456
|
-
mipmapBlur,
|
|
457
|
-
radius,
|
|
458
|
-
levels,
|
|
459
|
-
...props
|
|
460
|
-
}), [camera, height, intensity, kernelSize, luminanceSmoothing, luminanceThreshold, scene, width, height, mipmapBlur, radius, levels]);
|
|
461
|
-
const api = useContext(selectionContext);
|
|
462
|
-
useEffect(() => {
|
|
463
|
-
// Do not allow array selection if declarative selection is active
|
|
464
|
-
// TODO: array selection should probably be deprecated altogether
|
|
465
|
-
if (!api && selection) {
|
|
466
|
-
effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
|
|
467
|
-
invalidate();
|
|
468
|
-
return () => {
|
|
469
|
-
effect.selection.clear();
|
|
470
|
-
invalidate();
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
}, [effect, selection, api]);
|
|
474
|
-
useEffect(() => {
|
|
475
|
-
effect.selection.layer = selectionLayer;
|
|
476
|
-
invalidate();
|
|
477
|
-
}, [effect, selectionLayer]);
|
|
478
|
-
useEffect(() => {
|
|
479
|
-
if (lights && lights.length > 0) {
|
|
480
|
-
lights.forEach(light => addLight(resolveRef(light), effect));
|
|
481
|
-
invalidate();
|
|
482
|
-
return () => {
|
|
483
|
-
lights.forEach(light => removeLight(resolveRef(light), effect));
|
|
484
|
-
invalidate();
|
|
485
|
-
};
|
|
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.');
|
|
486
298
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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;
|
|
495
327
|
invalidate();
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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 });
|
|
508
354
|
});
|
|
509
355
|
|
|
510
356
|
const Sepia = wrapEffect(SepiaEffect);
|
|
511
357
|
|
|
512
|
-
const SSAO =
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
|
|
541
|
-
resolutionScale: resolutionScale != null ? resolutionScale : 1,
|
|
542
|
-
depthAwareUpsampling: true,
|
|
543
|
-
...props
|
|
544
|
-
});
|
|
545
|
-
}, [camera, normalPass, props]);
|
|
546
|
-
return /*#__PURE__*/React__default.createElement("primitive", {
|
|
547
|
-
ref: ref,
|
|
548
|
-
object: effect,
|
|
549
|
-
dispose: null
|
|
550
|
-
});
|
|
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 });
|
|
551
386
|
});
|
|
552
387
|
|
|
553
|
-
const SMAA =
|
|
554
|
-
let {
|
|
555
|
-
preset = SMAAPreset.HIGH,
|
|
556
|
-
edgeDetectionMode = EdgeDetectionMode.COLOR
|
|
557
|
-
} = _ref;
|
|
558
|
-
const smaaProps = useLoader(SMAAImageLoader, '');
|
|
559
|
-
const effect = useMemo(() => new SMAAEffect(...smaaProps, preset, edgeDetectionMode), [smaaProps, preset, edgeDetectionMode]);
|
|
560
|
-
return /*#__PURE__*/React__default.createElement("primitive", {
|
|
561
|
-
ref: ref,
|
|
562
|
-
object: effect,
|
|
563
|
-
dispose: null
|
|
564
|
-
});
|
|
565
|
-
});
|
|
388
|
+
const SMAA = wrapEffect(SMAAEffect);
|
|
566
389
|
|
|
567
|
-
const Texture =
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
t.encoding = sRGBEncoding;
|
|
576
|
-
t.wrapS = t.wrapT = RepeatWrapping;
|
|
577
|
-
}, [t]);
|
|
578
|
-
const effect = useMemo(() => new TextureEffect({ ...props,
|
|
579
|
-
texture: t || texture
|
|
580
|
-
}), [props, t, texture]);
|
|
581
|
-
return /*#__PURE__*/React__default.createElement("primitive", {
|
|
582
|
-
ref: ref,
|
|
583
|
-
object: effect,
|
|
584
|
-
dispose: null
|
|
585
|
-
});
|
|
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 });
|
|
586
398
|
});
|
|
587
399
|
|
|
588
400
|
const ToneMapping = wrapEffect(ToneMappingEffect);
|
|
@@ -591,32 +403,23 @@ const Vignette = wrapEffect(VignetteEffect);
|
|
|
591
403
|
|
|
592
404
|
const ShockWave = wrapEffect(ShockWaveEffect);
|
|
593
405
|
|
|
594
|
-
const LUT =
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
invalidate();
|
|
606
|
-
}, [effect, lut, tetrahedralInterpolation]);
|
|
607
|
-
return /*#__PURE__*/React__default.createElement("primitive", {
|
|
608
|
-
ref: ref,
|
|
609
|
-
object: effect,
|
|
610
|
-
dispose: null
|
|
611
|
-
});
|
|
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 });
|
|
612
417
|
});
|
|
613
418
|
|
|
614
|
-
const TiltShift = wrapEffect(TiltShiftEffect$1, {
|
|
615
|
-
blendFunction: BlendFunction.ADD
|
|
616
|
-
});
|
|
419
|
+
const TiltShift = wrapEffect(TiltShiftEffect$1, { blendFunction: BlendFunction.ADD });
|
|
617
420
|
|
|
618
421
|
const TiltShiftShader = {
|
|
619
|
-
|
|
422
|
+
fragmentShader: `
|
|
620
423
|
|
|
621
424
|
// original shader by Evan Wallace
|
|
622
425
|
|
|
@@ -672,76 +475,51 @@ const TiltShiftShader = {
|
|
|
672
475
|
/* switch back from pre-multiplied alpha */
|
|
673
476
|
outputColor.rgb /= outputColor.a + 0.00001;
|
|
674
477
|
}
|
|
675
|
-
|
|
478
|
+
`,
|
|
676
479
|
};
|
|
677
480
|
class TiltShiftEffect extends Effect {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
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)]])
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
}
|
|
702
|
-
const TiltShift2 = wrapEffect(TiltShiftEffect);
|
|
703
|
-
|
|
704
|
-
const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
|
|
705
|
-
let {
|
|
706
|
-
ENABLE_BLUR = true,
|
|
707
|
-
USE_MRT = true,
|
|
708
|
-
...props
|
|
709
|
-
} = _ref;
|
|
710
|
-
const {
|
|
711
|
-
invalidate
|
|
712
|
-
} = useThree();
|
|
713
|
-
const {
|
|
714
|
-
scene,
|
|
715
|
-
camera
|
|
716
|
-
} = useContext(EffectComposerContext);
|
|
717
|
-
const effect = useMemo(() => new SSREffect(scene, camera, {
|
|
718
|
-
ENABLE_BLUR,
|
|
719
|
-
USE_MRT,
|
|
720
|
-
...props
|
|
721
|
-
}), [SSREffect, scene, camera, ENABLE_BLUR, USE_MRT]);
|
|
722
|
-
useLayoutEffect(() => {
|
|
723
|
-
Object.keys(props).forEach(key => effect[key] = props[key]);
|
|
724
|
-
invalidate();
|
|
725
|
-
}, [props]);
|
|
726
|
-
const api = useContext(selectionContext);
|
|
727
|
-
useEffect(() => {
|
|
728
|
-
if (api && api.enabled) {
|
|
729
|
-
var _api$selected;
|
|
730
|
-
|
|
731
|
-
if ((_api$selected = api.selected) != null && _api$selected.length) {
|
|
732
|
-
effect.selection.set(api.selected);
|
|
733
|
-
invalidate();
|
|
734
|
-
return () => {
|
|
735
|
-
effect.selection.clear();
|
|
736
|
-
invalidate();
|
|
737
|
-
};
|
|
738
|
-
}
|
|
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
|
+
});
|
|
739
500
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
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 });
|
|
745
523
|
});
|
|
746
524
|
|
|
747
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 };
|