@tresjs/post-processing 0.1.0 → 0.2.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/README.md +3 -3
- package/dist/core/EffectComposer.vue.d.ts +108 -0
- package/dist/core/effects/Bloom.vue.d.ts +146 -0
- package/dist/core/effects/Glitch.vue.d.ts +183 -0
- package/dist/core/effects/Outline.d.ts +134 -0
- package/dist/index.d.ts +5 -4
- package/dist/tres-postprocessing.js +366 -174
- package/dist/tres-postprocessing.umd.cjs +3 -3
- package/package.json +39 -28
- package/dist/core/effects/Bloom.d.ts +0 -69
- package/dist/core/effects/Glitch.d.ts +0 -90
- package/dist/core/useEffectComposer/component.d.ts +0 -119
|
@@ -1,215 +1,407 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/post-processing
|
|
3
|
-
* version: v0.1
|
|
3
|
+
* version: v0.2.1
|
|
4
4
|
* (c) 2023
|
|
5
|
-
* description: Post-processing library for
|
|
5
|
+
* description: Post-processing library for TresJS
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
import { getCurrentInstance as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { EffectComposer as
|
|
12
|
-
function x(
|
|
13
|
-
|
|
8
|
+
import { inject as b, getCurrentInstance as D, onMounted as F, nextTick as Y, getCurrentScope as q, onScopeDispose as U, unref as N, toRef as V, readonly as J, customRef as K, ref as h, watch as y, watchEffect as S, computed as G, defineComponent as B, shallowRef as L, provide as Z, renderSlot as _, toRaw as v, onUnmounted as R } from "vue";
|
|
9
|
+
import { HalfFloatType as ee, Color as A } from "three";
|
|
10
|
+
import { useTres as te, useRenderLoop as ne } from "@tresjs/core";
|
|
11
|
+
import { EffectComposer as ae, RenderPass as le, NormalPass as ie, DepthDownsamplingPass as ue, BlendFunction as W, BloomEffect as re, EffectPass as z, GlitchMode as O, GlitchEffect as oe, OutlineEffect as T } from "postprocessing";
|
|
12
|
+
function x() {
|
|
13
|
+
const { state: e, setState: n } = b("useTres", te()), l = b("extend") || (() => {
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
state: e,
|
|
17
|
+
setState: n,
|
|
18
|
+
extend: l
|
|
19
|
+
};
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
let g;
|
|
22
|
+
function se() {
|
|
23
|
+
var e;
|
|
24
|
+
if (g !== void 0)
|
|
25
|
+
return g;
|
|
26
|
+
try {
|
|
27
|
+
let n;
|
|
28
|
+
const l = document.createElement("canvas");
|
|
29
|
+
return g = !!(window.WebGL2RenderingContext && (n = l.getContext("webgl2"))), n && ((e = n.getExtension("WEBGL_lose_context")) == null || e.loseContext()), g;
|
|
30
|
+
} catch {
|
|
31
|
+
return g = !1;
|
|
32
|
+
}
|
|
17
33
|
}
|
|
18
|
-
|
|
34
|
+
function k(e) {
|
|
35
|
+
return q() ? (U(e), !0) : !1;
|
|
36
|
+
}
|
|
37
|
+
function H(e) {
|
|
38
|
+
return typeof e == "function" ? e() : N(e);
|
|
39
|
+
}
|
|
40
|
+
const ce = typeof window < "u", I = () => {
|
|
19
41
|
};
|
|
20
|
-
function
|
|
42
|
+
function de(...e) {
|
|
21
43
|
if (e.length !== 1)
|
|
22
|
-
return
|
|
23
|
-
const
|
|
24
|
-
return typeof
|
|
44
|
+
return V(...e);
|
|
45
|
+
const n = e[0];
|
|
46
|
+
return typeof n == "function" ? J(K(() => ({ get: n, set: I }))) : h(n);
|
|
25
47
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
48
|
+
function fe(e, n = !0) {
|
|
49
|
+
D() ? F(e) : n ? e() : Y(e);
|
|
28
50
|
}
|
|
29
|
-
function
|
|
30
|
-
var
|
|
31
|
-
const
|
|
32
|
-
return (
|
|
51
|
+
function me(e) {
|
|
52
|
+
var n;
|
|
53
|
+
const l = H(e);
|
|
54
|
+
return (n = l == null ? void 0 : l.$el) != null ? n : l;
|
|
33
55
|
}
|
|
34
|
-
const
|
|
35
|
-
function
|
|
36
|
-
let
|
|
37
|
-
if (typeof e[0] == "string" || Array.isArray(e[0]) ? ([
|
|
38
|
-
return
|
|
39
|
-
Array.isArray(
|
|
40
|
-
const o = [],
|
|
41
|
-
o.forEach((
|
|
42
|
-
},
|
|
43
|
-
() => [
|
|
44
|
-
([
|
|
45
|
-
|
|
46
|
-
...
|
|
56
|
+
const M = ce ? window : void 0;
|
|
57
|
+
function ve(...e) {
|
|
58
|
+
let n, l, a, t;
|
|
59
|
+
if (typeof e[0] == "string" || Array.isArray(e[0]) ? ([l, a, t] = e, n = M) : [n, l, a, t] = e, !n)
|
|
60
|
+
return I;
|
|
61
|
+
Array.isArray(l) || (l = [l]), Array.isArray(a) || (a = [a]);
|
|
62
|
+
const o = [], s = () => {
|
|
63
|
+
o.forEach((r) => r()), o.length = 0;
|
|
64
|
+
}, c = (r, u, d, m) => (r.addEventListener(u, d, m), () => r.removeEventListener(u, d, m)), f = y(
|
|
65
|
+
() => [me(n), H(t)],
|
|
66
|
+
([r, u]) => {
|
|
67
|
+
s(), r && o.push(
|
|
68
|
+
...l.flatMap((d) => a.map((m) => c(r, d, m, u)))
|
|
47
69
|
);
|
|
48
70
|
},
|
|
49
71
|
{ immediate: !0, flush: "post" }
|
|
50
72
|
), i = () => {
|
|
51
|
-
|
|
73
|
+
f(), s();
|
|
52
74
|
};
|
|
53
|
-
return
|
|
75
|
+
return k(i), i;
|
|
54
76
|
}
|
|
55
|
-
function
|
|
56
|
-
const e =
|
|
57
|
-
return
|
|
77
|
+
function he() {
|
|
78
|
+
const e = h(!1);
|
|
79
|
+
return D() && F(() => {
|
|
58
80
|
e.value = !0;
|
|
59
81
|
}), e;
|
|
60
82
|
}
|
|
61
|
-
function
|
|
62
|
-
const
|
|
63
|
-
return
|
|
83
|
+
function ye(e) {
|
|
84
|
+
const n = he();
|
|
85
|
+
return G(() => (n.value, !!e()));
|
|
64
86
|
}
|
|
65
|
-
function
|
|
66
|
-
const { window:
|
|
67
|
-
let
|
|
68
|
-
const o =
|
|
69
|
-
|
|
70
|
-
},
|
|
71
|
-
|
|
87
|
+
function ge(e, n = {}) {
|
|
88
|
+
const { window: l = M } = n, a = ye(() => l && "matchMedia" in l && typeof l.matchMedia == "function");
|
|
89
|
+
let t;
|
|
90
|
+
const o = h(!1), s = () => {
|
|
91
|
+
t && ("removeEventListener" in t ? t.removeEventListener("change", c) : t.removeListener(c));
|
|
92
|
+
}, c = () => {
|
|
93
|
+
a.value && (s(), t = l.matchMedia(de(e).value), o.value = !!(t != null && t.matches), t && ("addEventListener" in t ? t.addEventListener("change", c) : t.addListener(c)));
|
|
72
94
|
};
|
|
73
|
-
return
|
|
95
|
+
return S(c), k(() => s()), o;
|
|
74
96
|
}
|
|
75
|
-
function
|
|
97
|
+
function be(e = {}) {
|
|
76
98
|
const {
|
|
77
|
-
window:
|
|
78
|
-
initialWidth:
|
|
79
|
-
initialHeight:
|
|
80
|
-
listenOrientation:
|
|
99
|
+
window: n = M,
|
|
100
|
+
initialWidth: l = 1 / 0,
|
|
101
|
+
initialHeight: a = 1 / 0,
|
|
102
|
+
listenOrientation: t = !0,
|
|
81
103
|
includeScrollbar: o = !0
|
|
82
|
-
} = e,
|
|
83
|
-
|
|
104
|
+
} = e, s = h(l), c = h(a), f = () => {
|
|
105
|
+
n && (o ? (s.value = n.innerWidth, c.value = n.innerHeight) : (s.value = n.document.documentElement.clientWidth, c.value = n.document.documentElement.clientHeight));
|
|
84
106
|
};
|
|
85
|
-
if (
|
|
86
|
-
const i =
|
|
87
|
-
y(i, () =>
|
|
107
|
+
if (f(), fe(f), ve("resize", f, { passive: !0 }), t) {
|
|
108
|
+
const i = ge("(orientation: portrait)");
|
|
109
|
+
y(i, () => f());
|
|
88
110
|
}
|
|
89
|
-
return { width:
|
|
111
|
+
return { width: s, height: c };
|
|
90
112
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
113
|
+
const Ee = /* @__PURE__ */ B({
|
|
114
|
+
__name: "EffectComposer",
|
|
115
|
+
props: {
|
|
116
|
+
enabled: { type: Boolean, default: !0 },
|
|
117
|
+
children: {},
|
|
118
|
+
depthBuffer: { type: Boolean },
|
|
119
|
+
dissableNormalPass: { type: Boolean, default: !1 },
|
|
120
|
+
stencilBuffer: { type: Boolean },
|
|
121
|
+
resolutionScale: {},
|
|
122
|
+
autoClear: { type: Boolean, default: !0 },
|
|
123
|
+
multisampling: { default: 8 },
|
|
124
|
+
frameBufferType: { default: () => ee },
|
|
125
|
+
scene: {},
|
|
126
|
+
camera: {}
|
|
127
|
+
},
|
|
128
|
+
setup(e) {
|
|
129
|
+
const { state: n } = x(), l = L(null), a = e.scene || n.scene, t = e.camera || n.camera;
|
|
130
|
+
let o = null, s = null;
|
|
131
|
+
const c = se();
|
|
132
|
+
Z("effectComposer", l);
|
|
133
|
+
const { width: f, height: i } = be();
|
|
134
|
+
function r() {
|
|
135
|
+
l.value && (s = new ie(e.scene, e.camera), s.enabled = !1, l.value.addPass(s), e.resolutionScale !== void 0 && c && (o = new ue({
|
|
136
|
+
normalBuffer: s.texture,
|
|
137
|
+
resolutionScale: e.resolutionScale
|
|
138
|
+
}), o.enabled = !1, l.value.addPass(o)));
|
|
139
|
+
}
|
|
140
|
+
S(() => {
|
|
141
|
+
n.renderer && (n.renderer.setSize(f.value, i.value), n.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)), l.value = new ae(n.renderer, {
|
|
142
|
+
depthBuffer: e.depthBuffer,
|
|
143
|
+
stencilBuffer: e.stencilBuffer,
|
|
144
|
+
multisampling: e.multisampling > 0 && c ? e.multisampling : 0,
|
|
145
|
+
frameBufferType: e.frameBufferType
|
|
146
|
+
}), l.value.addPass(new le(a, t)), e.dissableNormalPass || r());
|
|
147
|
+
});
|
|
148
|
+
const { onLoop: u } = ne();
|
|
149
|
+
return u(() => {
|
|
150
|
+
l.value && l.value.render();
|
|
151
|
+
}), u(({ delta: d }) => {
|
|
152
|
+
if (e.enabled && n.renderer && l.value) {
|
|
153
|
+
const m = n.renderer.autoClear;
|
|
154
|
+
n.renderer.autoClear = e.autoClear, e.stencilBuffer && !e.autoClear && n.renderer.clearStencil(), l.value.render(d), n.renderer.autoClear = m;
|
|
155
|
+
}
|
|
156
|
+
}), (d, m) => _(d.$slots, "default");
|
|
102
157
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
"scene"
|
|
128
|
-
],
|
|
129
|
-
setup(e, { slots: t }) {
|
|
130
|
-
const { state: n } = C(), {
|
|
131
|
-
enabled: r = !0,
|
|
132
|
-
renderPriority: a = 1,
|
|
133
|
-
autoClear: o = !0,
|
|
134
|
-
multisampling: l = 8,
|
|
135
|
-
frameBufferType: s = J,
|
|
136
|
-
resolutionScale: u
|
|
137
|
-
} = F(e), i = V(null), c = e.scene || n.scene, m = e.camera || n.camera;
|
|
138
|
-
let d = null, f = null;
|
|
139
|
-
const W = ce();
|
|
140
|
-
_("effectComposer", i);
|
|
141
|
-
const { width: G, height: T } = le();
|
|
142
|
-
function z() {
|
|
143
|
-
i.value && (f = new X(c, m), f.enabled = !1, i.value.addPass(f), u.value !== void 0 && W && (d = new Y({
|
|
144
|
-
normalBuffer: f.texture,
|
|
145
|
-
resolutionScale: u == null ? void 0 : u.value
|
|
146
|
-
}), d.enabled = !1, i.value.addPass(d)));
|
|
158
|
+
}), Pe = /* @__PURE__ */ B({
|
|
159
|
+
__name: "Bloom",
|
|
160
|
+
props: {
|
|
161
|
+
blendFunction: { default: () => W.ADD },
|
|
162
|
+
intensity: { default: 1 },
|
|
163
|
+
blurPass: {},
|
|
164
|
+
width: {},
|
|
165
|
+
height: {},
|
|
166
|
+
kernelSize: {},
|
|
167
|
+
luminanceThreshold: { default: 0.9 },
|
|
168
|
+
luminanceSmoothing: { default: 0.025 },
|
|
169
|
+
mipmapBlur: { type: Boolean, default: !1 }
|
|
170
|
+
},
|
|
171
|
+
setup(e, { expose: n }) {
|
|
172
|
+
const { state: l } = x(), a = b("effectComposer"), t = h(null), o = h(null);
|
|
173
|
+
n({ pass: t, effect: o });
|
|
174
|
+
function s() {
|
|
175
|
+
o.value = new re({
|
|
176
|
+
blendFunction: e.blendFunction,
|
|
177
|
+
mipmapBlur: e.mipmapBlur,
|
|
178
|
+
intensity: e.intensity,
|
|
179
|
+
luminanceThreshold: e.luminanceThreshold,
|
|
180
|
+
luminanceSmoothing: e.luminanceSmoothing
|
|
181
|
+
}), t.value = new z(N(l.camera), v(o.value));
|
|
147
182
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
183
|
+
function c() {
|
|
184
|
+
var r, u;
|
|
185
|
+
(r = o.value) == null || r.dispose(), (u = t.value) == null || u.dispose(), a == null || a.value.removePass(v(t.value));
|
|
186
|
+
}
|
|
187
|
+
const f = y(
|
|
188
|
+
() => [l.camera, a == null ? void 0 : a.value],
|
|
189
|
+
() => {
|
|
190
|
+
var r;
|
|
191
|
+
l.camera && a && a.value && (s(), (r = a == null ? void 0 : a.value) == null || r.addPass(v(t.value)));
|
|
192
|
+
}
|
|
193
|
+
), i = y(
|
|
194
|
+
() => [e.blendFunction, e.mipmapBlur, e.intensity, e.luminanceThreshold, e.luminanceSmoothing],
|
|
195
|
+
() => {
|
|
196
|
+
var r;
|
|
197
|
+
t.value && (c(), s(), (r = a == null ? void 0 : a.value) == null || r.addPass(v(t.value)));
|
|
154
198
|
}
|
|
155
199
|
);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}), () => {
|
|
160
|
-
var h;
|
|
161
|
-
return (h = t.default) == null ? void 0 : h.call(t);
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}), he = g({
|
|
165
|
-
name: "Bloom",
|
|
166
|
-
props: [
|
|
167
|
-
"intensity",
|
|
168
|
-
"blurPass",
|
|
169
|
-
"width",
|
|
170
|
-
"height",
|
|
171
|
-
"kernelSize",
|
|
172
|
-
"luminanceThreshold",
|
|
173
|
-
"luminanceSmoothing"
|
|
174
|
-
],
|
|
175
|
-
async setup(e, { expose: t }) {
|
|
176
|
-
const { state: n } = C(), r = w("effectComposer"), a = v(null);
|
|
177
|
-
return t({ getPass: () => a.value }), b(() => {
|
|
178
|
-
var o;
|
|
179
|
-
n.camera && r && r.value && (a.value = new R(P(n.camera), new Z(e)), (o = r == null ? void 0 : r.value) == null || o.addPass(M(a.value)));
|
|
180
|
-
}), () => {
|
|
181
|
-
};
|
|
200
|
+
return R(() => {
|
|
201
|
+
c(), f(), i();
|
|
202
|
+
}), (r, u) => null;
|
|
182
203
|
}
|
|
183
|
-
}),
|
|
184
|
-
|
|
185
|
-
props:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
204
|
+
}), Be = /* @__PURE__ */ B({
|
|
205
|
+
__name: "Glitch",
|
|
206
|
+
props: {
|
|
207
|
+
blendFunction: { default: () => W.ADD },
|
|
208
|
+
delay: {},
|
|
209
|
+
duration: {},
|
|
210
|
+
strength: {},
|
|
211
|
+
mode: {},
|
|
212
|
+
active: { type: Boolean },
|
|
213
|
+
ratio: { default: 0.85 },
|
|
214
|
+
columns: { default: 0.05 },
|
|
215
|
+
chromaticAberrationOffset: {},
|
|
216
|
+
peturbationMap: {},
|
|
217
|
+
dtSize: { default: 64 }
|
|
218
|
+
},
|
|
219
|
+
setup(e, { expose: n }) {
|
|
220
|
+
const { state: l } = x(), a = b("effectComposer"), t = h(null), o = h(null);
|
|
221
|
+
n({ pass: t });
|
|
222
|
+
function s() {
|
|
223
|
+
o.value = new oe({
|
|
224
|
+
blendFunction: e.blendFunction,
|
|
225
|
+
delay: e.delay,
|
|
226
|
+
duration: e.duration,
|
|
227
|
+
strength: e.strength,
|
|
228
|
+
ratio: e.ratio,
|
|
229
|
+
columns: e.columns,
|
|
230
|
+
chromaticAberrationOffset: e.chromaticAberrationOffset,
|
|
231
|
+
dtSize: e.dtSize
|
|
232
|
+
}), t.value = new z(N(l.camera), v(o.value));
|
|
233
|
+
}
|
|
234
|
+
function c() {
|
|
235
|
+
var u, d;
|
|
236
|
+
(u = o.value) == null || u.dispose(), (d = t.value) == null || d.dispose(), a == null || a.value.removePass(v(t.value));
|
|
237
|
+
}
|
|
238
|
+
const f = y(
|
|
239
|
+
() => [l.camera, a == null ? void 0 : a.value],
|
|
240
|
+
() => {
|
|
241
|
+
var u;
|
|
242
|
+
l.camera && a && a.value && (s(), (u = a == null ? void 0 : a.value) == null || u.addPass(v(t.value)));
|
|
243
|
+
}
|
|
244
|
+
), i = y(
|
|
245
|
+
() => [e.delay, e.duration, e.strength, e.ratio, e.columns, e.chromaticAberrationOffset, e.peturbationMap, e.dtSize],
|
|
246
|
+
() => {
|
|
247
|
+
var u;
|
|
248
|
+
t.value && (a == null || a.value.removePass(v(t.value)), s(), (u = a == null ? void 0 : a.value) == null || u.addPass(v(t.value)));
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
S(() => {
|
|
252
|
+
t.value && (t.value.mode = e.active ? e.mode || O.SPORADIC : O.DISABLED);
|
|
253
|
+
});
|
|
254
|
+
const r = y(
|
|
203
255
|
() => e.active,
|
|
204
|
-
(
|
|
205
|
-
|
|
256
|
+
(u) => {
|
|
257
|
+
t.value && (t.value.enabled = u);
|
|
206
258
|
}
|
|
207
|
-
)
|
|
259
|
+
);
|
|
260
|
+
return R(() => {
|
|
261
|
+
c(), f(), i(), r();
|
|
262
|
+
}), (u, d) => null;
|
|
263
|
+
}
|
|
264
|
+
}), xe = B({
|
|
265
|
+
name: "Outline",
|
|
266
|
+
props: {
|
|
267
|
+
/**
|
|
268
|
+
* The objects in the scene which should have an outline.
|
|
269
|
+
*/
|
|
270
|
+
outlinedObjects: {
|
|
271
|
+
type: Array,
|
|
272
|
+
requred: !0
|
|
273
|
+
},
|
|
274
|
+
/**
|
|
275
|
+
* The blend function. Use `BlendFunction.ALPHA` for dark outlines.
|
|
276
|
+
*/
|
|
277
|
+
blendFunction: {
|
|
278
|
+
type: Number
|
|
279
|
+
},
|
|
280
|
+
patternTexture: {
|
|
281
|
+
type: Number
|
|
282
|
+
},
|
|
283
|
+
patternScale: {
|
|
284
|
+
type: Number
|
|
285
|
+
},
|
|
286
|
+
edgeStrength: {
|
|
287
|
+
type: Number
|
|
288
|
+
},
|
|
289
|
+
/**
|
|
290
|
+
* The pulse speed. A value of zero disables the pulse effect.
|
|
291
|
+
*/
|
|
292
|
+
pulseSpeed: {
|
|
293
|
+
type: Number
|
|
294
|
+
},
|
|
295
|
+
visibleEdgeColor: {
|
|
296
|
+
type: [String, Number, Array]
|
|
297
|
+
},
|
|
298
|
+
hiddenEdgeColor: {
|
|
299
|
+
type: [String, Number, Array]
|
|
300
|
+
},
|
|
301
|
+
/**
|
|
302
|
+
* The number of samples used for multisample antialiasing. Requires WebGL 2.
|
|
303
|
+
*/
|
|
304
|
+
multisampling: {
|
|
305
|
+
type: Number
|
|
306
|
+
},
|
|
307
|
+
resolutionScale: {
|
|
308
|
+
type: Number
|
|
309
|
+
},
|
|
310
|
+
resolutionX: {
|
|
311
|
+
type: Number
|
|
312
|
+
},
|
|
313
|
+
resolutionY: {
|
|
314
|
+
type: Number
|
|
315
|
+
},
|
|
316
|
+
/**
|
|
317
|
+
* The blur kernel size.
|
|
318
|
+
*/
|
|
319
|
+
kernelSize: {
|
|
320
|
+
type: Number
|
|
321
|
+
},
|
|
322
|
+
blur: {
|
|
323
|
+
type: Boolean
|
|
324
|
+
},
|
|
325
|
+
/**
|
|
326
|
+
* Whether occluded parts of selected objects should be visible
|
|
327
|
+
*/
|
|
328
|
+
xRay: {
|
|
329
|
+
type: Boolean
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
setup(e) {
|
|
333
|
+
const { state: n } = x(), l = b("effectComposer"), a = L(null), t = L(null), o = (i) => i instanceof A ? i : Array.isArray(i) ? new A(...i) : new A(i), s = (i) => i !== void 0 ? o(i).getHex() : void 0, c = G(() => {
|
|
334
|
+
const {
|
|
335
|
+
blur: i,
|
|
336
|
+
xRay: r,
|
|
337
|
+
kernelSize: u,
|
|
338
|
+
pulseSpeed: d,
|
|
339
|
+
resolutionX: m,
|
|
340
|
+
resolutionY: p,
|
|
341
|
+
patternScale: w,
|
|
342
|
+
edgeStrength: C,
|
|
343
|
+
blendFunction: E,
|
|
344
|
+
multisampling: P,
|
|
345
|
+
patternTexture: $,
|
|
346
|
+
resolutionScale: j,
|
|
347
|
+
hiddenEdgeColor: Q,
|
|
348
|
+
visibleEdgeColor: X
|
|
349
|
+
} = e;
|
|
350
|
+
return {
|
|
351
|
+
blur: i,
|
|
352
|
+
xRay: r,
|
|
353
|
+
kernelSize: u,
|
|
354
|
+
pulseSpeed: d,
|
|
355
|
+
resolutionX: m,
|
|
356
|
+
resolutionY: p,
|
|
357
|
+
patternScale: w,
|
|
358
|
+
edgeStrength: C,
|
|
359
|
+
blendFunction: E,
|
|
360
|
+
multisampling: P,
|
|
361
|
+
patternTexture: $,
|
|
362
|
+
resolutionScale: j,
|
|
363
|
+
hiddenEdgeColor: s(Q),
|
|
364
|
+
visibleEdgeColor: s(X)
|
|
365
|
+
};
|
|
366
|
+
}), f = S(() => {
|
|
367
|
+
var i;
|
|
368
|
+
n.camera && l && l.value && n.scene && (t.value = new T(n.scene, n.camera, c.value), a.value = new z(n.camera, t.value), (i = l.value) == null || i.addPass(a.value), f());
|
|
369
|
+
});
|
|
370
|
+
return y(
|
|
371
|
+
[() => e.outlinedObjects, t],
|
|
372
|
+
// whatchEffect is intentionally not used here as it would result in an endless loop
|
|
373
|
+
() => {
|
|
374
|
+
var i;
|
|
375
|
+
(i = t.value) == null || i.selection.set(e.outlinedObjects || []);
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
immediate: !0
|
|
379
|
+
}
|
|
380
|
+
), S(() => {
|
|
381
|
+
if (!t.value)
|
|
382
|
+
return;
|
|
383
|
+
const i = new T(), {
|
|
384
|
+
blur: r,
|
|
385
|
+
xRay: u,
|
|
386
|
+
kernelSize: d,
|
|
387
|
+
pulseSpeed: m,
|
|
388
|
+
patternScale: p,
|
|
389
|
+
edgeStrength: w,
|
|
390
|
+
multisampling: C,
|
|
391
|
+
hiddenEdgeColor: E,
|
|
392
|
+
visibleEdgeColor: P
|
|
393
|
+
} = c.value;
|
|
394
|
+
t.value.blur = r !== void 0 ? r : i.blur, t.value.xRay = u !== void 0 ? u : i.xRay, t.value.pulseSpeed = m !== void 0 ? m : i.pulseSpeed, t.value.kernelSize = d !== void 0 ? d : i.kernelSize, t.value.edgeStrength = w !== void 0 ? w : i.edgeStrength, t.value.patternScale = p !== void 0 ? p : i.patternScale, t.value.multisampling = C !== void 0 ? C : i.multisampling, t.value.hiddenEdgeColor = E !== void 0 ? o(E) : i.hiddenEdgeColor, t.value.visibleEdgeColor = P !== void 0 ? o(P) : i.visibleEdgeColor, i.dispose();
|
|
395
|
+
}), R(() => {
|
|
396
|
+
var i, r, u, d;
|
|
397
|
+
(i = t.value) == null || i.selection.clear(), (r = l.value) == null || r.removePass(a.value), (u = t.value) == null || u.dispose(), (d = a.value) == null || d.dispose();
|
|
398
|
+
}), () => {
|
|
208
399
|
};
|
|
209
400
|
}
|
|
210
401
|
});
|
|
211
402
|
export {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
403
|
+
Pe as Bloom,
|
|
404
|
+
Ee as EffectComposer,
|
|
405
|
+
Be as Glitch,
|
|
406
|
+
xe as Outline
|
|
215
407
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/post-processing
|
|
3
|
-
* version: v0.1
|
|
3
|
+
* version: v0.2.1
|
|
4
4
|
* (c) 2023
|
|
5
|
-
* description: Post-processing library for
|
|
5
|
+
* description: Post-processing library for TresJS
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
(function(
|
|
8
|
+
(function(v,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("three"),require("@tresjs/core"),require("postprocessing")):typeof define=="function"&&define.amd?define(["exports","vue","three","@tresjs/core","postprocessing"],t):(v=typeof globalThis<"u"?globalThis:v||self,t(v["tres-postprocessing"]={},v.Vue,v.Three,v.TresjsCore,v.Postprocessing))})(this,function(v,t,b,A,m){"use strict";function S(){const{state:e,setState:a}=t.inject("useTres",A.useTres()),i=t.inject("extend")||(()=>{});return{state:e,setState:a,extend:i}}let w;function M(){var e;if(w!==void 0)return w;try{let a;const i=document.createElement("canvas");return w=!!(window.WebGL2RenderingContext&&(a=i.getContext("webgl2"))),a&&((e=a.getExtension("WEBGL_lose_context"))==null||e.loseContext()),w}catch{return w=!1}}function R(e){return t.getCurrentScope()?(t.onScopeDispose(e),!0):!1}function x(e){return typeof e=="function"?e():t.unref(e)}const N=typeof window<"u",L=()=>{};function O(...e){if(e.length!==1)return t.toRef(...e);const a=e[0];return typeof a=="function"?t.readonly(t.customRef(()=>({get:a,set:L}))):t.ref(a)}function T(e,a=!0){t.getCurrentInstance()?t.onMounted(e):a?e():t.nextTick(e)}function z(e){var a;const i=x(e);return(a=i==null?void 0:i.$el)!=null?a:i}const p=N?window:void 0;function j(...e){let a,i,l,n;if(typeof e[0]=="string"||Array.isArray(e[0])?([i,l,n]=e,a=p):[a,i,l,n]=e,!a)return L;Array.isArray(i)||(i=[i]),Array.isArray(l)||(l=[l]);const c=[],s=()=>{c.forEach(u=>u()),c.length=0},d=(u,o,f,y)=>(u.addEventListener(o,f,y),()=>u.removeEventListener(o,f,y)),h=t.watch(()=>[z(a),x(n)],([u,o])=>{s(),u&&c.push(...i.flatMap(f=>l.map(y=>d(u,f,y,o))))},{immediate:!0,flush:"post"}),r=()=>{h(),s()};return R(r),r}function F(){const e=t.ref(!1);return t.getCurrentInstance()&&t.onMounted(()=>{e.value=!0}),e}function D(e){const a=F();return t.computed(()=>(a.value,!!e()))}function G(e,a={}){const{window:i=p}=a,l=D(()=>i&&"matchMedia"in i&&typeof i.matchMedia=="function");let n;const c=t.ref(!1),s=()=>{n&&("removeEventListener"in n?n.removeEventListener("change",d):n.removeListener(d))},d=()=>{l.value&&(s(),n=i.matchMedia(O(e).value),c.value=!!(n!=null&&n.matches),n&&("addEventListener"in n?n.addEventListener("change",d):n.addListener(d)))};return t.watchEffect(d),R(()=>s()),c}function W(e={}){const{window:a=p,initialWidth:i=1/0,initialHeight:l=1/0,listenOrientation:n=!0,includeScrollbar:c=!0}=e,s=t.ref(i),d=t.ref(l),h=()=>{a&&(c?(s.value=a.innerWidth,d.value=a.innerHeight):(s.value=a.document.documentElement.clientWidth,d.value=a.document.documentElement.clientHeight))};if(h(),T(h),j("resize",h,{passive:!0}),n){const r=G("(orientation: portrait)");t.watch(r,()=>h())}return{width:s,height:d}}const k=t.defineComponent({__name:"EffectComposer",props:{enabled:{type:Boolean,default:!0},children:{},depthBuffer:{type:Boolean},dissableNormalPass:{type:Boolean,default:!1},stencilBuffer:{type:Boolean},resolutionScale:{},autoClear:{type:Boolean,default:!0},multisampling:{default:8},frameBufferType:{default:()=>b.HalfFloatType},scene:{},camera:{}},setup(e){const{state:a}=S(),i=t.shallowRef(null),l=e.scene||a.scene,n=e.camera||a.camera;let c=null,s=null;const d=M();t.provide("effectComposer",i);const{width:h,height:r}=W();function u(){i.value&&(s=new m.NormalPass(e.scene,e.camera),s.enabled=!1,i.value.addPass(s),e.resolutionScale!==void 0&&d&&(c=new m.DepthDownsamplingPass({normalBuffer:s.texture,resolutionScale:e.resolutionScale}),c.enabled=!1,i.value.addPass(c)))}t.watchEffect(()=>{a.renderer&&(a.renderer.setSize(h.value,r.value),a.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),i.value=new m.EffectComposer(a.renderer,{depthBuffer:e.depthBuffer,stencilBuffer:e.stencilBuffer,multisampling:e.multisampling>0&&d?e.multisampling:0,frameBufferType:e.frameBufferType}),i.value.addPass(new m.RenderPass(l,n)),e.dissableNormalPass||u())});const{onLoop:o}=A.useRenderLoop();return o(()=>{i.value&&i.value.render()}),o(({delta:f})=>{if(e.enabled&&a.renderer&&i.value){const y=a.renderer.autoClear;a.renderer.autoClear=e.autoClear,e.stencilBuffer&&!e.autoClear&&a.renderer.clearStencil(),i.value.render(f),a.renderer.autoClear=y}}),(f,y)=>t.renderSlot(f.$slots,"default")}}),I=t.defineComponent({__name:"Bloom",props:{blendFunction:{default:()=>m.BlendFunction.ADD},intensity:{default:1},blurPass:{},width:{},height:{},kernelSize:{},luminanceThreshold:{default:.9},luminanceSmoothing:{default:.025},mipmapBlur:{type:Boolean,default:!1}},setup(e,{expose:a}){const{state:i}=S(),l=t.inject("effectComposer"),n=t.ref(null),c=t.ref(null);a({pass:n,effect:c});function s(){c.value=new m.BloomEffect({blendFunction:e.blendFunction,mipmapBlur:e.mipmapBlur,intensity:e.intensity,luminanceThreshold:e.luminanceThreshold,luminanceSmoothing:e.luminanceSmoothing}),n.value=new m.EffectPass(t.unref(i.camera),t.toRaw(c.value))}function d(){var u,o;(u=c.value)==null||u.dispose(),(o=n.value)==null||o.dispose(),l==null||l.value.removePass(t.toRaw(n.value))}const h=t.watch(()=>[i.camera,l==null?void 0:l.value],()=>{var u;i.camera&&l&&l.value&&(s(),(u=l==null?void 0:l.value)==null||u.addPass(t.toRaw(n.value)))}),r=t.watch(()=>[e.blendFunction,e.mipmapBlur,e.intensity,e.luminanceThreshold,e.luminanceSmoothing],()=>{var u;n.value&&(d(),s(),(u=l==null?void 0:l.value)==null||u.addPass(t.toRaw(n.value)))});return t.onUnmounted(()=>{d(),h(),r()}),(u,o)=>null}}),q=t.defineComponent({__name:"Glitch",props:{blendFunction:{default:()=>m.BlendFunction.ADD},delay:{},duration:{},strength:{},mode:{},active:{type:Boolean},ratio:{default:.85},columns:{default:.05},chromaticAberrationOffset:{},peturbationMap:{},dtSize:{default:64}},setup(e,{expose:a}){const{state:i}=S(),l=t.inject("effectComposer"),n=t.ref(null),c=t.ref(null);a({pass:n});function s(){c.value=new m.GlitchEffect({blendFunction:e.blendFunction,delay:e.delay,duration:e.duration,strength:e.strength,ratio:e.ratio,columns:e.columns,chromaticAberrationOffset:e.chromaticAberrationOffset,dtSize:e.dtSize}),n.value=new m.EffectPass(t.unref(i.camera),t.toRaw(c.value))}function d(){var o,f;(o=c.value)==null||o.dispose(),(f=n.value)==null||f.dispose(),l==null||l.value.removePass(t.toRaw(n.value))}const h=t.watch(()=>[i.camera,l==null?void 0:l.value],()=>{var o;i.camera&&l&&l.value&&(s(),(o=l==null?void 0:l.value)==null||o.addPass(t.toRaw(n.value)))}),r=t.watch(()=>[e.delay,e.duration,e.strength,e.ratio,e.columns,e.chromaticAberrationOffset,e.peturbationMap,e.dtSize],()=>{var o;n.value&&(l==null||l.value.removePass(t.toRaw(n.value)),s(),(o=l==null?void 0:l.value)==null||o.addPass(t.toRaw(n.value)))});t.watchEffect(()=>{n.value&&(n.value.mode=e.active?e.mode||m.GlitchMode.SPORADIC:m.GlitchMode.DISABLED)});const u=t.watch(()=>e.active,o=>{n.value&&(n.value.enabled=o)});return t.onUnmounted(()=>{d(),h(),r(),u()}),(o,f)=>null}}),$=t.defineComponent({name:"Outline",props:{outlinedObjects:{type:Array,requred:!0},blendFunction:{type:Number},patternTexture:{type:Number},patternScale:{type:Number},edgeStrength:{type:Number},pulseSpeed:{type:Number},visibleEdgeColor:{type:[String,Number,Array]},hiddenEdgeColor:{type:[String,Number,Array]},multisampling:{type:Number},resolutionScale:{type:Number},resolutionX:{type:Number},resolutionY:{type:Number},kernelSize:{type:Number},blur:{type:Boolean},xRay:{type:Boolean}},setup(e){const{state:a}=S(),i=t.inject("effectComposer"),l=t.shallowRef(null),n=t.shallowRef(null),c=r=>r instanceof b.Color?r:Array.isArray(r)?new b.Color(...r):new b.Color(r),s=r=>r!==void 0?c(r).getHex():void 0,d=t.computed(()=>{const{blur:r,xRay:u,kernelSize:o,pulseSpeed:f,resolutionX:y,resolutionY:g,patternScale:C,edgeStrength:E,blendFunction:P,multisampling:B,patternTexture:U,resolutionScale:H,hiddenEdgeColor:Q,visibleEdgeColor:V}=e;return{blur:r,xRay:u,kernelSize:o,pulseSpeed:f,resolutionX:y,resolutionY:g,patternScale:C,edgeStrength:E,blendFunction:P,multisampling:B,patternTexture:U,resolutionScale:H,hiddenEdgeColor:s(Q),visibleEdgeColor:s(V)}}),h=t.watchEffect(()=>{var r;a.camera&&i&&i.value&&a.scene&&(n.value=new m.OutlineEffect(a.scene,a.camera,d.value),l.value=new m.EffectPass(a.camera,n.value),(r=i.value)==null||r.addPass(l.value),h())});return t.watch([()=>e.outlinedObjects,n],()=>{var r;(r=n.value)==null||r.selection.set(e.outlinedObjects||[])},{immediate:!0}),t.watchEffect(()=>{if(!n.value)return;const r=new m.OutlineEffect,{blur:u,xRay:o,kernelSize:f,pulseSpeed:y,patternScale:g,edgeStrength:C,multisampling:E,hiddenEdgeColor:P,visibleEdgeColor:B}=d.value;n.value.blur=u!==void 0?u:r.blur,n.value.xRay=o!==void 0?o:r.xRay,n.value.pulseSpeed=y!==void 0?y:r.pulseSpeed,n.value.kernelSize=f!==void 0?f:r.kernelSize,n.value.edgeStrength=C!==void 0?C:r.edgeStrength,n.value.patternScale=g!==void 0?g:r.patternScale,n.value.multisampling=E!==void 0?E:r.multisampling,n.value.hiddenEdgeColor=P!==void 0?c(P):r.hiddenEdgeColor,n.value.visibleEdgeColor=B!==void 0?c(B):r.visibleEdgeColor,r.dispose()}),t.onUnmounted(()=>{var r,u,o,f;(r=n.value)==null||r.selection.clear(),(u=i.value)==null||u.removePass(l.value),(o=n.value)==null||o.dispose(),(f=l.value)==null||f.dispose()}),()=>{}}});v.Bloom=I,v.EffectComposer=k,v.Glitch=q,v.Outline=$,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|