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