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