@tresjs/post-processing 0.6.0 → 0.7.0

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.
@@ -0,0 +1,47 @@
1
+ import { BlendFunction, VignetteEffect, VignetteTechnique } from 'postprocessing';
2
+ export interface VignetteProps {
3
+ /**
4
+ * Whether the noise should be multiplied with the input color.
5
+ */
6
+ technique?: VignetteTechnique;
7
+ blendFunction?: BlendFunction;
8
+ offset: number;
9
+ darkness: number;
10
+ }
11
+ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<VignetteProps>, {
12
+ technique: VignetteTechnique;
13
+ blendFunction: BlendFunction;
14
+ offset: number;
15
+ darkness: number;
16
+ }>, {
17
+ pass: import("vue").ShallowRef<import("postprocessing").EffectPass | null>;
18
+ effect: import("vue").ShallowRef<VignetteEffect | null>;
19
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<VignetteProps>, {
20
+ technique: VignetteTechnique;
21
+ blendFunction: BlendFunction;
22
+ offset: number;
23
+ darkness: number;
24
+ }>>>, {
25
+ blendFunction: BlendFunction;
26
+ technique: VignetteTechnique;
27
+ offset: number;
28
+ darkness: number;
29
+ }, {}>;
30
+ export default _default;
31
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
32
+ type __VLS_TypePropsToRuntimeProps<T> = {
33
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
34
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
35
+ } : {
36
+ type: import('vue').PropType<T[K]>;
37
+ required: true;
38
+ };
39
+ };
40
+ type __VLS_WithDefaults<P, D> = {
41
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
42
+ default: D[K];
43
+ }> : P[K];
44
+ };
45
+ type __VLS_Prettify<T> = {
46
+ [K in keyof T]: T[K];
47
+ } & {};
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import Bloom from './core/effects/Bloom.vue';
2
+ import DepthOfField from './core/effects/DepthOfField.vue';
3
+ import EffectComposer from './core/EffectComposer.vue';
2
4
  import Glitch from './core/effects/Glitch.vue';
3
5
  import Outline from './core/effects/Outline.vue';
4
6
  import Pixelation from './core/effects/Pixelation.vue';
5
- import DepthOfField from './core/effects/DepthOfField.vue';
7
+ import Vignette from './core/effects/Vignette.vue';
6
8
  import Noise from './core/effects/Noise.vue';
7
- import EffectComposer from './core/EffectComposer.vue';
8
- export { Bloom, Glitch, Outline, Pixelation, DepthOfField, EffectComposer, Noise, };
9
+ export { Bloom, DepthOfField, EffectComposer, Glitch, Noise, Outline, Pixelation, Vignette, };
@@ -1,64 +1,64 @@
1
1
  /**
2
2
  * name: @tresjs/post-processing
3
- * version: v0.6.0
3
+ * version: v0.7.0
4
4
  * (c) 2023
5
5
  * description: Post-processing library for TresJS
6
6
  * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
7
  */
8
- import { inject as j, shallowRef as _, watchEffect as v, onUnmounted as A, watch as w, defineComponent as f, computed as M, provide as X, renderSlot as Y } from "vue";
9
- import { EffectPass as H, BloomEffect as y, GlitchEffect as S, GlitchMode as I, OutlineEffect as P, PixelationEffect as F, DepthOfFieldEffect as R, BlendFunction as U, NoiseEffect as O, EffectComposer as z, RenderPass as K, NormalPass as q, DepthDownsamplingPass as J } from "postprocessing";
10
- import { useTresContext as b, normalizeColor as C, useRenderLoop as Q } from "@tresjs/core";
11
- import { HalfFloatType as D } from "three";
12
- const N = Symbol(), p = (a) => {
13
- const t = j(N), e = _(null), n = _(null), { scene: o, camera: l } = b();
14
- v(() => {
15
- !l.value || !(n != null && n.value) || (n.value.mainCamera = l.value);
8
+ import { inject as X, shallowRef as w, watchEffect as E, onUnmounted as M, watch as g, defineComponent as f, provide as Y, computed as N, renderSlot as V } from "vue";
9
+ import { EffectPass as U, BloomEffect as y, DepthOfFieldEffect as F, EffectComposer as P, RenderPass as q, NormalPass as H, DepthDownsamplingPass as I, GlitchEffect as S, GlitchMode as K, OutlineEffect as R, PixelationEffect as O, VignetteTechnique as J, BlendFunction as L, VignetteEffect as D, NoiseEffect as T } from "postprocessing";
10
+ import { useTresContext as h, useRenderLoop as Q, normalizeColor as C } from "@tresjs/core";
11
+ import { HalfFloatType as z } from "three";
12
+ const $ = Symbol(), m = (l) => {
13
+ const t = X($), e = w(null), n = w(null), { scene: o, camera: a } = h();
14
+ E(() => {
15
+ !a.value || !(n != null && n.value) || (n.value.mainCamera = a.value);
16
16
  });
17
17
  let s = () => {
18
18
  };
19
- return s = v(() => {
20
- !l.value || !(t != null && t.value) || !o.value || (s(), !n.value && (n.value = a(), e.value = new H(l.value, n.value), t.value.addPass(e.value)));
21
- }), A(() => {
19
+ return s = E(() => {
20
+ !a.value || !(t != null && t.value) || !o.value || (s(), !n.value && (n.value = l(), e.value = new U(a.value, n.value), t.value.addPass(e.value)));
21
+ }), M(() => {
22
22
  var r, i, d;
23
23
  e.value && ((r = t == null ? void 0 : t.value) == null || r.removePass(e.value)), (i = n.value) == null || i.dispose(), (d = e.value) == null || d.dispose();
24
24
  }), {
25
25
  pass: e,
26
26
  effect: n
27
27
  };
28
- }, G = /([^[.\]])+/g, V = (a, t) => {
28
+ }, G = /([^[.\]])+/g, Z = (l, t) => {
29
29
  if (!t)
30
30
  return;
31
31
  const e = Array.isArray(t) ? t : t.match(G);
32
- return e == null ? void 0 : e.reduce((n, o) => n && n[o], a);
33
- }, T = (a, t, e) => {
32
+ return e == null ? void 0 : e.reduce((n, o) => n && n[o], l);
33
+ }, k = (l, t, e) => {
34
34
  const n = Array.isArray(t) ? t : t.match(G);
35
- n && n.reduce((o, l, s) => (o[l] === void 0 && (o[l] = {}), s === n.length - 1 && (o[l] = e), o[l]), a);
36
- }, L = (a, t) => {
37
- const e = { ...a };
35
+ n && n.reduce((o, a, s) => (o[a] === void 0 && (o[a] = {}), s === n.length - 1 && (o[a] = e), o[a]), l);
36
+ }, x = (l, t) => {
37
+ const e = { ...l };
38
38
  return t.forEach((n) => delete e[n]), e;
39
- }, $ = (a, t, e, n, o = {}) => w(
40
- a,
41
- (l) => {
39
+ }, W = (l, t, e, n, o = {}) => g(
40
+ l,
41
+ (a) => {
42
42
  var s;
43
43
  if (t.value)
44
- if (l === void 0) {
44
+ if (a === void 0) {
45
45
  const r = n();
46
- T(t.value, e, V(r, e)), (s = r.dispose) == null || s.call(r);
46
+ k(t.value, e, Z(r, e)), (s = r.dispose) == null || s.call(r);
47
47
  } else
48
- T(t.value, e, a());
48
+ k(t.value, e, l());
49
49
  },
50
50
  o
51
- ), E = (a, t, e) => a.map(([n, o]) => $(
51
+ ), B = (l, t, e) => l.map(([n, o]) => W(
52
52
  n,
53
53
  t,
54
54
  o,
55
55
  e
56
- )), B = (a, t, e) => Object.keys(a).map((n) => $(
57
- () => a[n],
56
+ )), _ = (l, t, e) => Object.keys(l).map((n) => W(
57
+ () => l[n],
58
58
  t,
59
59
  n,
60
60
  e
61
- )), oe = /* @__PURE__ */ f({
61
+ )), le = /* @__PURE__ */ f({
62
62
  __name: "Bloom",
63
63
  props: {
64
64
  blendFunction: {},
@@ -68,9 +68,9 @@ const N = Symbol(), p = (a) => {
68
68
  luminanceSmoothing: {},
69
69
  mipmapBlur: { type: Boolean, default: void 0 }
70
70
  },
71
- setup(a, { expose: t }) {
72
- const e = a, { pass: n, effect: o } = p(() => new y(e));
73
- return t({ pass: n, effect: o }), E(
71
+ setup(l, { expose: t }) {
72
+ const e = l, { pass: n, effect: o } = m(() => new y(e));
73
+ return t({ pass: n, effect: o }), B(
74
74
  [
75
75
  // blendFunction is not updated, because it has no setter in BloomEffect
76
76
  [() => e.intensity, "intensity"],
@@ -80,9 +80,105 @@ const N = Symbol(), p = (a) => {
80
80
  ],
81
81
  o,
82
82
  () => new y()
83
- ), (l, s) => null;
83
+ ), (a, s) => null;
84
+ }
85
+ }), ae = /* @__PURE__ */ f({
86
+ __name: "DepthOfField",
87
+ props: {
88
+ blendFunction: {},
89
+ worldFocusDistance: {},
90
+ worldFocusRange: {},
91
+ focusDistance: {},
92
+ focusRange: {},
93
+ bokehScale: {},
94
+ resolutionScale: {},
95
+ resolutionX: {},
96
+ resolutionY: {}
97
+ },
98
+ setup(l, { expose: t }) {
99
+ const e = l, { camera: n } = h(), { pass: o, effect: a } = m(() => new F(n.value, e));
100
+ return t({ pass: o, effect: a }), B(
101
+ [
102
+ // blendFunction is not updated, because it has no setter in BloomEffect
103
+ [() => e.worldFocusDistance, "circleOfConfusionMaterial.worldFocusDistance"],
104
+ [() => e.focusDistance, "circleOfConfusionMaterial.focusDistance"],
105
+ [() => e.worldFocusRange, "circleOfConfusionMaterial.worldFocusRange"],
106
+ [() => e.focusRange, "circleOfConfusionMaterial.focusRange"],
107
+ [() => e.bokehScale, "bokehScale"],
108
+ [() => e.resolutionScale, "blurPass.resolution.scale"],
109
+ [() => e.resolutionX, "resolution.width"],
110
+ [() => e.resolutionY, "resolution.height"]
111
+ ],
112
+ a,
113
+ () => new F()
114
+ ), (s, r) => null;
115
+ }
116
+ });
117
+ let v;
118
+ function A() {
119
+ var l;
120
+ if (v !== void 0)
121
+ return v;
122
+ try {
123
+ let t;
124
+ const e = document.createElement("canvas");
125
+ return v = !!(window.WebGL2RenderingContext && (t = e.getContext("webgl2"))), t && ((l = t.getExtension("WEBGL_lose_context")) == null || l.loseContext()), v;
126
+ } catch {
127
+ return v = !1;
84
128
  }
85
- }), le = /* @__PURE__ */ f({
129
+ }
130
+ const se = /* @__PURE__ */ f({
131
+ __name: "EffectComposer",
132
+ props: {
133
+ enabled: { type: Boolean, default: !0 },
134
+ children: {},
135
+ depthBuffer: { type: Boolean, default: void 0 },
136
+ disableNormalPass: { type: Boolean, default: !1 },
137
+ stencilBuffer: { type: Boolean, default: void 0 },
138
+ resolutionScale: {},
139
+ autoClear: { type: Boolean, default: !0 },
140
+ multisampling: { default: 0 },
141
+ frameBufferType: { default: z }
142
+ },
143
+ setup(l) {
144
+ const t = l, { scene: e, camera: n, renderer: o, sizes: a } = h(), s = w(null);
145
+ let r = null, i = null;
146
+ Y($, s);
147
+ const d = () => {
148
+ s.value && (i = new H(e.value, n.value), i.enabled = !1, s.value.addPass(i), t.resolutionScale !== void 0 && A() && (r = new I({
149
+ normalBuffer: i.texture,
150
+ resolutionScale: t.resolutionScale
151
+ }), r.enabled = !1, s.value.addPass(r)));
152
+ }, c = N(() => {
153
+ const u = new P(), p = {
154
+ depthBuffer: t.depthBuffer !== void 0 ? t.depthBuffer : u.inputBuffer.depthBuffer,
155
+ stencilBuffer: t.stencilBuffer !== void 0 ? t.stencilBuffer : u.inputBuffer.stencilBuffer,
156
+ multisampling: A() ? 0 : t.multisampling !== void 0 ? t.multisampling : u.multisampling,
157
+ frameBufferType: t.frameBufferType !== void 0 ? t.frameBufferType : z
158
+ };
159
+ return u.dispose(), p;
160
+ }), b = () => {
161
+ !o.value && !e.value && !n.value || (s.value = new P(o.value, c.value), s.value.addPass(new q(e.value, n.value)), t.disableNormalPass || d());
162
+ };
163
+ g([o, e, n, () => t.disableNormalPass], () => {
164
+ !a.width.value || !a.height.value || b();
165
+ }), g(() => [a.width.value, a.height.value], ([u, p]) => {
166
+ !u && !p || (s.value ? s.value.setSize(u, p) : b());
167
+ }, {
168
+ immediate: !0
169
+ });
170
+ const { onLoop: j } = Q();
171
+ return j(({ delta: u }) => {
172
+ if (t.enabled && o.value && s.value && a.width.value && a.height.value) {
173
+ const p = o.value.autoClear;
174
+ o.value.autoClear = t.autoClear, t.stencilBuffer && !t.autoClear && o.value.clearStencil(), s.value.render(u), o.value.autoClear = p;
175
+ }
176
+ }), M(() => {
177
+ var u;
178
+ (u = s.value) == null || u.dispose();
179
+ }), (u, p) => V(u.$slots, "default");
180
+ }
181
+ }), re = /* @__PURE__ */ f({
86
182
  __name: "Glitch",
87
183
  props: {
88
184
  blendFunction: {},
@@ -97,23 +193,23 @@ const N = Symbol(), p = (a) => {
97
193
  perturbationMap: {},
98
194
  dtSize: {}
99
195
  },
100
- setup(a, { expose: t }) {
101
- const e = a, { pass: n, effect: o } = p(() => new S(e));
102
- return t({ pass: n, effect: o }), v(() => {
103
- const l = () => {
196
+ setup(l, { expose: t }) {
197
+ const e = l, { pass: n, effect: o } = m(() => new S(e));
198
+ return t({ pass: n, effect: o }), E(() => {
199
+ const a = () => {
104
200
  if (e.mode !== void 0)
105
- return e.active === !1 ? I.DISABLED : e.mode;
201
+ return e.active === !1 ? K.DISABLED : e.mode;
106
202
  const s = new S(), r = s.mode;
107
203
  return s.dispose(), r;
108
204
  };
109
- o.value && (o.value.mode = l());
110
- }), B(
111
- L(e, ["active", "mode", "blendFunction"]),
205
+ o.value && (o.value.mode = a());
206
+ }), _(
207
+ x(e, ["active", "mode", "blendFunction"]),
112
208
  o,
113
209
  () => new S()
114
- ), (l, s) => null;
210
+ ), (a, s) => null;
115
211
  }
116
- }), ae = /* @__PURE__ */ f({
212
+ }), ue = /* @__PURE__ */ f({
117
213
  __name: "Outline",
118
214
  props: {
119
215
  outlinedObjects: {},
@@ -132,8 +228,8 @@ const N = Symbol(), p = (a) => {
132
228
  hiddenEdgeColor: {},
133
229
  visibleEdgeColor: {}
134
230
  },
135
- setup(a, { expose: t }) {
136
- const e = a, n = (c) => c !== void 0 ? C(c).getHex() : void 0, { camera: o, scene: l } = b(), s = {
231
+ setup(l, { expose: t }) {
232
+ const e = l, n = (c) => c !== void 0 ? C(c).getHex() : void 0, { camera: o, scene: a } = h(), s = {
137
233
  blur: e.blur,
138
234
  xRay: e.xRay,
139
235
  kernelSize: e.kernelSize,
@@ -148,8 +244,8 @@ const N = Symbol(), p = (a) => {
148
244
  resolutionScale: e.resolutionScale,
149
245
  hiddenEdgeColor: n(e.hiddenEdgeColor),
150
246
  visibleEdgeColor: n(e.visibleEdgeColor)
151
- }, { pass: r, effect: i } = p(() => new P(l.value, o.value, s));
152
- t({ pass: r, effect: i }), w(
247
+ }, { pass: r, effect: i } = m(() => new R(a.value, o.value, s));
248
+ t({ pass: r, effect: i }), g(
153
249
  [() => e.outlinedObjects, i],
154
250
  // watchEffect is intentionally not used here as it would result in an endless loop
155
251
  () => {
@@ -160,11 +256,11 @@ const N = Symbol(), p = (a) => {
160
256
  immediate: !0
161
257
  }
162
258
  );
163
- const d = M(() => ({
259
+ const d = N(() => ({
164
260
  hiddenEdgeColor: e.hiddenEdgeColor ? C(e.hiddenEdgeColor) : void 0,
165
261
  visibleEdgeColor: e.visibleEdgeColor ? C(e.visibleEdgeColor) : void 0
166
262
  }));
167
- return E(
263
+ return B(
168
264
  [
169
265
  /* some properties are not updated because of different reasons:
170
266
  resolutionX - has no setter in OutlineEffect
@@ -184,143 +280,60 @@ const N = Symbol(), p = (a) => {
184
280
  [() => d.value.visibleEdgeColor, "visibleEdgeColor"]
185
281
  ],
186
282
  i,
187
- () => new P()
188
- ), (c, x) => null;
283
+ () => new R()
284
+ ), (c, b) => null;
189
285
  }
190
- }), se = /* @__PURE__ */ f({
286
+ }), ie = /* @__PURE__ */ f({
191
287
  __name: "Pixelation",
192
288
  props: {
193
289
  granularity: {}
194
290
  },
195
- setup(a, { expose: t }) {
196
- const e = a, { pass: n, effect: o } = p(() => new F(e.granularity));
197
- return t({ pass: n, effect: o }), B(
291
+ setup(l, { expose: t }) {
292
+ const e = l, { pass: n, effect: o } = m(() => new O(e.granularity));
293
+ return t({ pass: n, effect: o }), _(
198
294
  e,
199
295
  o,
200
- () => new F()
201
- ), (l, s) => null;
296
+ () => new O()
297
+ ), (a, s) => null;
202
298
  }
203
- }), re = /* @__PURE__ */ f({
204
- __name: "DepthOfField",
299
+ }), ce = /* @__PURE__ */ f({
300
+ __name: "Vignette",
205
301
  props: {
206
- blendFunction: {},
207
- worldFocusDistance: {},
208
- worldFocusRange: {},
209
- focusDistance: {},
210
- focusRange: {},
211
- bokehScale: {},
212
- resolutionScale: {},
213
- resolutionX: {},
214
- resolutionY: {}
302
+ technique: { default: J.DEFAULT },
303
+ blendFunction: { default: L.NORMAL },
304
+ offset: { default: 0.5 },
305
+ darkness: { default: 0.5 }
215
306
  },
216
- setup(a, { expose: t }) {
217
- const e = a, { camera: n } = b(), { pass: o, effect: l } = p(() => new R(n.value, e));
218
- return t({ pass: o, effect: l }), E(
219
- [
220
- // blendFunction is not updated, because it has no setter in BloomEffect
221
- [() => e.worldFocusDistance, "circleOfConfusionMaterial.worldFocusDistance"],
222
- [() => e.focusDistance, "circleOfConfusionMaterial.focusDistance"],
223
- [() => e.worldFocusRange, "circleOfConfusionMaterial.worldFocusRange"],
224
- [() => e.focusRange, "circleOfConfusionMaterial.focusRange"],
225
- [() => e.bokehScale, "bokehScale"],
226
- [() => e.resolutionScale, "blurPass.resolution.scale"],
227
- [() => e.resolutionX, "resolution.width"],
228
- [() => e.resolutionY, "resolution.height"]
229
- ],
230
- l,
231
- () => new R()
232
- ), (s, r) => null;
307
+ setup(l, { expose: t }) {
308
+ const e = l, { pass: n, effect: o } = m(() => new D(e));
309
+ return t({ pass: n, effect: o }), _(
310
+ x(e, ["blendFunction"]),
311
+ o,
312
+ () => new D()
313
+ ), (a, s) => null;
233
314
  }
234
- }), ie = /* @__PURE__ */ f({
315
+ }), fe = /* @__PURE__ */ f({
235
316
  __name: "Noise",
236
317
  props: {
237
318
  premultiply: { type: Boolean, default: !1 },
238
- blendFunction: { default: U.SCREEN }
319
+ blendFunction: { default: L.SCREEN }
239
320
  },
240
- setup(a, { expose: t }) {
241
- const e = a, { pass: n, effect: o } = p(() => new O(e));
242
- return t({ pass: n, effect: o }), B(
243
- L(e, ["blendFunction"]),
321
+ setup(l, { expose: t }) {
322
+ const e = l, { pass: n, effect: o } = m(() => new T(e));
323
+ return t({ pass: n, effect: o }), _(
324
+ x(e, ["blendFunction"]),
244
325
  o,
245
- () => new O()
246
- ), (l, s) => null;
247
- }
248
- });
249
- let m;
250
- function k() {
251
- var a;
252
- if (m !== void 0)
253
- return m;
254
- try {
255
- let t;
256
- const e = document.createElement("canvas");
257
- return m = !!(window.WebGL2RenderingContext && (t = e.getContext("webgl2"))), t && ((a = t.getExtension("WEBGL_lose_context")) == null || a.loseContext()), m;
258
- } catch {
259
- return m = !1;
260
- }
261
- }
262
- const ue = /* @__PURE__ */ f({
263
- __name: "EffectComposer",
264
- props: {
265
- enabled: { type: Boolean, default: !0 },
266
- children: {},
267
- depthBuffer: { type: Boolean, default: void 0 },
268
- disableNormalPass: { type: Boolean, default: !1 },
269
- stencilBuffer: { type: Boolean, default: void 0 },
270
- resolutionScale: {},
271
- autoClear: { type: Boolean, default: !0 },
272
- multisampling: { default: 0 },
273
- frameBufferType: { default: D }
274
- },
275
- setup(a) {
276
- const t = a, { scene: e, camera: n, renderer: o, sizes: l } = b(), s = _(null);
277
- let r = null, i = null;
278
- X(N, s);
279
- const d = () => {
280
- s.value && (i = new q(e.value, n.value), i.enabled = !1, s.value.addPass(i), t.resolutionScale !== void 0 && k() && (r = new J({
281
- normalBuffer: i.texture,
282
- resolutionScale: t.resolutionScale
283
- }), r.enabled = !1, s.value.addPass(r)));
284
- };
285
- v(() => {
286
- s.value && l.width.value && l.height.value && s.value.setSize(l.width.value, l.height.value);
287
- });
288
- const c = M(() => {
289
- const u = new z(), g = {
290
- depthBuffer: t.depthBuffer !== void 0 ? t.depthBuffer : u.inputBuffer.depthBuffer,
291
- stencilBuffer: t.stencilBuffer !== void 0 ? t.stencilBuffer : u.inputBuffer.stencilBuffer,
292
- multisampling: k() ? 0 : t.multisampling !== void 0 ? t.multisampling : u.multisampling,
293
- frameBufferType: t.frameBufferType !== void 0 ? t.frameBufferType : D
294
- };
295
- return u.dispose(), g;
296
- }), x = () => {
297
- !o.value && !e.value && !n.value || (s.value = new z(o.value, c.value), s.value.addPass(new K(e.value, n.value)), t.disableNormalPass || d());
298
- };
299
- let h = () => {
300
- };
301
- h = w([l.height, l.width], () => {
302
- !l.height.value && !l.width.value || (v(x), h == null || h());
303
- }, {
304
- immediate: !0
305
- });
306
- const { onLoop: W } = Q();
307
- return W(({ delta: u }) => {
308
- if (t.enabled && o.value && s.value && l.width.value && l.height.value) {
309
- const g = o.value.autoClear;
310
- o.value.autoClear = t.autoClear, t.stencilBuffer && !t.autoClear && o.value.clearStencil(), s.value.render(u), o.value.autoClear = g;
311
- }
312
- }), A(() => {
313
- var u;
314
- (u = s.value) == null || u.dispose();
315
- }), (u, g) => Y(u.$slots, "default");
326
+ () => new T()
327
+ ), (a, s) => null;
316
328
  }
317
329
  });
318
330
  export {
319
- oe as Bloom,
320
- re as DepthOfField,
321
- ue as EffectComposer,
322
- le as Glitch,
323
- ie as Noise,
324
- ae as Outline,
325
- se as Pixelation
331
+ le as Bloom,
332
+ ae as DepthOfField,
333
+ se as EffectComposer,
334
+ re as Glitch,
335
+ fe as Noise,
336
+ ue as Outline,
337
+ ie as Pixelation,
338
+ ce as Vignette
326
339
  };
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * name: @tresjs/post-processing
3
- * version: v0.6.0
3
+ * version: v0.7.0
4
4
  * (c) 2023
5
5
  * description: Post-processing library for TresJS
6
6
  * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
7
  */
8
- (function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("postprocessing"),require("@tresjs/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","postprocessing","@tresjs/core","three"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["tres-postprocessing"]={},s.Vue,s.Postprocessing,s.TresjsCore,s.Three))})(this,function(s,i,u,m,b){"use strict";const _=Symbol(),v=a=>{const t=i.inject(_),e=i.shallowRef(null),n=i.shallowRef(null),{scene:l,camera:o}=m.useTresContext();i.watchEffect(()=>{!o.value||!(n!=null&&n.value)||(n.value.mainCamera=o.value)});let r=()=>{};return r=i.watchEffect(()=>{!o.value||!(t!=null&&t.value)||!l.value||(r(),!n.value&&(n.value=a(),e.value=new u.EffectPass(o.value,n.value),t.value.addPass(e.value)))}),i.onUnmounted(()=>{var c,f,h;e.value&&((c=t==null?void 0:t.value)==null||c.removePass(e.value)),(f=n.value)==null||f.dispose(),(h=e.value)==null||h.dispose()}),{pass:e,effect:n}},B=/([^[.\]])+/g,R=(a,t)=>{if(!t)return;const e=Array.isArray(t)?t:t.match(B);return e==null?void 0:e.reduce((n,l)=>n&&n[l],a)},y=(a,t,e)=>{const n=Array.isArray(t)?t:t.match(B);n&&n.reduce((l,o,r)=>(l[o]===void 0&&(l[o]={}),r===n.length-1&&(l[o]=e),l[o]),a)},x=(a,t)=>{const e={...a};return t.forEach(n=>delete e[n]),e},P=(a,t,e,n,l={})=>i.watch(a,o=>{var r;if(t.value)if(o===void 0){const c=n();y(t.value,e,R(c,e)),(r=c.dispose)==null||r.call(c)}else y(t.value,e,a())},l),E=(a,t,e)=>a.map(([n,l])=>P(n,t,l,e)),S=(a,t,e)=>Object.keys(a).map(n=>P(()=>a[n],t,n,e)),O=i.defineComponent({__name:"Bloom",props:{blendFunction:{},intensity:{},kernelSize:{},luminanceThreshold:{},luminanceSmoothing:{},mipmapBlur:{type:Boolean,default:void 0}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.BloomEffect(e));return t({pass:n,effect:l}),E([[()=>e.intensity,"intensity"],[()=>e.kernelSize,"kernelSize"],[()=>e.luminanceSmoothing,"luminanceMaterial.smoothing"],[()=>e.luminanceThreshold,"luminanceMaterial.threshold"]],l,()=>new u.BloomEffect),(o,r)=>null}}),z=i.defineComponent({__name:"Glitch",props:{blendFunction:{},delay:{},duration:{},strength:{},mode:{},active:{type:Boolean},ratio:{},columns:{},chromaticAberrationOffset:{},perturbationMap:{},dtSize:{}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.GlitchEffect(e));return t({pass:n,effect:l}),i.watchEffect(()=>{const o=()=>{if(e.mode!==void 0)return e.active===!1?u.GlitchMode.DISABLED:e.mode;const r=new u.GlitchEffect,c=r.mode;return r.dispose(),c};l.value&&(l.value.mode=o())}),S(x(e,["active","mode","blendFunction"]),l,()=>new u.GlitchEffect),(o,r)=>null}}),D=i.defineComponent({__name:"Outline",props:{outlinedObjects:{},blur:{type:Boolean,default:void 0},xRay:{type:Boolean,default:void 0},kernelSize:{},pulseSpeed:{},resolutionX:{},resolutionY:{},edgeStrength:{},patternScale:{},multisampling:{},blendFunction:{},patternTexture:{},resolutionScale:{},hiddenEdgeColor:{},visibleEdgeColor:{}},setup(a,{expose:t}){const e=a,n=p=>p!==void 0?m.normalizeColor(p).getHex():void 0,{camera:l,scene:o}=m.useTresContext(),r={blur:e.blur,xRay:e.xRay,kernelSize:e.kernelSize,pulseSpeed:e.pulseSpeed,resolutionX:e.resolutionX,resolutionY:e.resolutionY,patternScale:e.patternScale,edgeStrength:e.edgeStrength,blendFunction:e.blendFunction,multisampling:e.multisampling,patternTexture:e.patternTexture,resolutionScale:e.resolutionScale,hiddenEdgeColor:n(e.hiddenEdgeColor),visibleEdgeColor:n(e.visibleEdgeColor)},{pass:c,effect:f}=v(()=>new u.OutlineEffect(o.value,l.value,r));t({pass:c,effect:f}),i.watch([()=>e.outlinedObjects,f],()=>{var p;(p=f.value)==null||p.selection.set(e.outlinedObjects||[])},{immediate:!0});const h=i.computed(()=>({hiddenEdgeColor:e.hiddenEdgeColor?m.normalizeColor(e.hiddenEdgeColor):void 0,visibleEdgeColor:e.visibleEdgeColor?m.normalizeColor(e.visibleEdgeColor):void 0}));return E([[()=>e.blur,"blur"],[()=>e.xRay,"xRay"],[()=>e.pulseSpeed,"pulseSpeed"],[()=>e.kernelSize,"kernelSize"],[()=>e.edgeStrength,"edgeStrength"],[()=>e.patternScale,"patternScale"],[()=>e.multisampling,"multisampling"],[()=>h.value.hiddenEdgeColor,"hiddenEdgeColor"],[()=>h.value.visibleEdgeColor,"visibleEdgeColor"]],f,()=>new u.OutlineEffect),(p,T)=>null}}),k=i.defineComponent({__name:"Pixelation",props:{granularity:{}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.PixelationEffect(e.granularity));return t({pass:n,effect:l}),S(e,l,()=>new u.PixelationEffect),(o,r)=>null}}),M=i.defineComponent({__name:"DepthOfField",props:{blendFunction:{},worldFocusDistance:{},worldFocusRange:{},focusDistance:{},focusRange:{},bokehScale:{},resolutionScale:{},resolutionX:{},resolutionY:{}},setup(a,{expose:t}){const e=a,{camera:n}=m.useTresContext(),{pass:l,effect:o}=v(()=>new u.DepthOfFieldEffect(n.value,e));return t({pass:l,effect:o}),E([[()=>e.worldFocusDistance,"circleOfConfusionMaterial.worldFocusDistance"],[()=>e.focusDistance,"circleOfConfusionMaterial.focusDistance"],[()=>e.worldFocusRange,"circleOfConfusionMaterial.worldFocusRange"],[()=>e.focusRange,"circleOfConfusionMaterial.focusRange"],[()=>e.bokehScale,"bokehScale"],[()=>e.resolutionScale,"blurPass.resolution.scale"],[()=>e.resolutionX,"resolution.width"],[()=>e.resolutionY,"resolution.height"]],o,()=>new u.DepthOfFieldEffect),(r,c)=>null}}),j=i.defineComponent({__name:"Noise",props:{premultiply:{type:Boolean,default:!1},blendFunction:{default:u.BlendFunction.SCREEN}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.NoiseEffect(e));return t({pass:n,effect:l}),S(x(e,["blendFunction"]),l,()=>new u.NoiseEffect),(o,r)=>null}});let C;function F(){var a;if(C!==void 0)return C;try{let t;const e=document.createElement("canvas");return C=!!(window.WebGL2RenderingContext&&(t=e.getContext("webgl2"))),t&&((a=t.getExtension("WEBGL_lose_context"))==null||a.loseContext()),C}catch{return C=!1}}const A=i.defineComponent({__name:"EffectComposer",props:{enabled:{type:Boolean,default:!0},children:{},depthBuffer:{type:Boolean,default:void 0},disableNormalPass:{type:Boolean,default:!1},stencilBuffer:{type:Boolean,default:void 0},resolutionScale:{},autoClear:{type:Boolean,default:!0},multisampling:{default:0},frameBufferType:{default:b.HalfFloatType}},setup(a){const t=a,{scene:e,camera:n,renderer:l,sizes:o}=m.useTresContext(),r=i.shallowRef(null);let c=null,f=null;i.provide(_,r);const h=()=>{r.value&&(f=new u.NormalPass(e.value,n.value),f.enabled=!1,r.value.addPass(f),t.resolutionScale!==void 0&&F()&&(c=new u.DepthDownsamplingPass({normalBuffer:f.texture,resolutionScale:t.resolutionScale}),c.enabled=!1,r.value.addPass(c)))};i.watchEffect(()=>{r.value&&o.width.value&&o.height.value&&r.value.setSize(o.width.value,o.height.value)});const p=i.computed(()=>{const d=new u.EffectComposer,g={depthBuffer:t.depthBuffer!==void 0?t.depthBuffer:d.inputBuffer.depthBuffer,stencilBuffer:t.stencilBuffer!==void 0?t.stencilBuffer:d.inputBuffer.stencilBuffer,multisampling:F()?0:t.multisampling!==void 0?t.multisampling:d.multisampling,frameBufferType:t.frameBufferType!==void 0?t.frameBufferType:b.HalfFloatType};return d.dispose(),g}),T=()=>{!l.value&&!e.value&&!n.value||(r.value=new u.EffectComposer(l.value,p.value),r.value.addPass(new u.RenderPass(e.value,n.value)),t.disableNormalPass||h())};let w=()=>{};w=i.watch([o.height,o.width],()=>{!o.height.value&&!o.width.value||(i.watchEffect(T),w==null||w())},{immediate:!0});const{onLoop:N}=m.useRenderLoop();return N(({delta:d})=>{if(t.enabled&&l.value&&r.value&&o.width.value&&o.height.value){const g=l.value.autoClear;l.value.autoClear=t.autoClear,t.stencilBuffer&&!t.autoClear&&l.value.clearStencil(),r.value.render(d),l.value.autoClear=g}}),i.onUnmounted(()=>{var d;(d=r.value)==null||d.dispose()}),(d,g)=>i.renderSlot(d.$slots,"default")}});s.Bloom=O,s.DepthOfField=M,s.EffectComposer=A,s.Glitch=z,s.Noise=j,s.Outline=D,s.Pixelation=k,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
8
+ (function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue"),require("postprocessing"),require("@tresjs/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","postprocessing","@tresjs/core","three"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s["tres-postprocessing"]={},s.Vue,s.Postprocessing,s.TresjsCore,s.Three))})(this,function(s,u,r,m,g){"use strict";const B=Symbol(),h=o=>{const n=u.inject(B),e=u.shallowRef(null),t=u.shallowRef(null),{scene:l,camera:a}=m.useTresContext();u.watchEffect(()=>{!a.value||!(t!=null&&t.value)||(t.value.mainCamera=a.value)});let i=()=>{};return i=u.watchEffect(()=>{!a.value||!(n!=null&&n.value)||!l.value||(i(),!t.value&&(t.value=o(),e.value=new r.EffectPass(a.value,t.value),n.value.addPass(e.value)))}),u.onUnmounted(()=>{var c,d,v;e.value&&((c=n==null?void 0:n.value)==null||c.removePass(e.value)),(d=t.value)==null||d.dispose(),(v=e.value)==null||v.dispose()}),{pass:e,effect:t}},y=/([^[.\]])+/g,T=(o,n)=>{if(!n)return;const e=Array.isArray(n)?n:n.match(y);return e==null?void 0:e.reduce((t,l)=>t&&t[l],o)},x=(o,n,e)=>{const t=Array.isArray(n)?n:n.match(y);t&&t.reduce((l,a,i)=>(l[a]===void 0&&(l[a]={}),i===t.length-1&&(l[a]=e),l[a]),o)},w=(o,n)=>{const e={...o};return n.forEach(t=>delete e[t]),e},F=(o,n,e,t,l={})=>u.watch(o,a=>{var i;if(n.value)if(a===void 0){const c=t();x(n.value,e,T(c,e)),(i=c.dispose)==null||i.call(c)}else x(n.value,e,o())},l),b=(o,n,e)=>o.map(([t,l])=>F(t,n,l,e)),E=(o,n,e)=>Object.keys(o).map(t=>F(()=>o[t],n,t,e)),R=u.defineComponent({__name:"Bloom",props:{blendFunction:{},intensity:{},kernelSize:{},luminanceThreshold:{},luminanceSmoothing:{},mipmapBlur:{type:Boolean,default:void 0}},setup(o,{expose:n}){const e=o,{pass:t,effect:l}=h(()=>new r.BloomEffect(e));return n({pass:t,effect:l}),b([[()=>e.intensity,"intensity"],[()=>e.kernelSize,"kernelSize"],[()=>e.luminanceSmoothing,"luminanceMaterial.smoothing"],[()=>e.luminanceThreshold,"luminanceMaterial.threshold"]],l,()=>new r.BloomEffect),(a,i)=>null}}),O=u.defineComponent({__name:"DepthOfField",props:{blendFunction:{},worldFocusDistance:{},worldFocusRange:{},focusDistance:{},focusRange:{},bokehScale:{},resolutionScale:{},resolutionX:{},resolutionY:{}},setup(o,{expose:n}){const e=o,{camera:t}=m.useTresContext(),{pass:l,effect:a}=h(()=>new r.DepthOfFieldEffect(t.value,e));return n({pass:l,effect:a}),b([[()=>e.worldFocusDistance,"circleOfConfusionMaterial.worldFocusDistance"],[()=>e.focusDistance,"circleOfConfusionMaterial.focusDistance"],[()=>e.worldFocusRange,"circleOfConfusionMaterial.worldFocusRange"],[()=>e.focusRange,"circleOfConfusionMaterial.focusRange"],[()=>e.bokehScale,"bokehScale"],[()=>e.resolutionScale,"blurPass.resolution.scale"],[()=>e.resolutionX,"resolution.width"],[()=>e.resolutionY,"resolution.height"]],a,()=>new r.DepthOfFieldEffect),(i,c)=>null}});let _;function P(){var o;if(_!==void 0)return _;try{let n;const e=document.createElement("canvas");return _=!!(window.WebGL2RenderingContext&&(n=e.getContext("webgl2"))),n&&((o=n.getExtension("WEBGL_lose_context"))==null||o.loseContext()),_}catch{return _=!1}}const z=u.defineComponent({__name:"EffectComposer",props:{enabled:{type:Boolean,default:!0},children:{},depthBuffer:{type:Boolean,default:void 0},disableNormalPass:{type:Boolean,default:!1},stencilBuffer:{type:Boolean,default:void 0},resolutionScale:{},autoClear:{type:Boolean,default:!0},multisampling:{default:0},frameBufferType:{default:g.HalfFloatType}},setup(o){const n=o,{scene:e,camera:t,renderer:l,sizes:a}=m.useTresContext(),i=u.shallowRef(null);let c=null,d=null;u.provide(B,i);const v=()=>{i.value&&(d=new r.NormalPass(e.value,t.value),d.enabled=!1,i.value.addPass(d),n.resolutionScale!==void 0&&P()&&(c=new r.DepthDownsamplingPass({normalBuffer:d.texture,resolutionScale:n.resolutionScale}),c.enabled=!1,i.value.addPass(c)))},p=u.computed(()=>{const f=new r.EffectComposer,C={depthBuffer:n.depthBuffer!==void 0?n.depthBuffer:f.inputBuffer.depthBuffer,stencilBuffer:n.stencilBuffer!==void 0?n.stencilBuffer:f.inputBuffer.stencilBuffer,multisampling:P()?0:n.multisampling!==void 0?n.multisampling:f.multisampling,frameBufferType:n.frameBufferType!==void 0?n.frameBufferType:g.HalfFloatType};return f.dispose(),C}),S=()=>{!l.value&&!e.value&&!t.value||(i.value=new r.EffectComposer(l.value,p.value),i.value.addPass(new r.RenderPass(e.value,t.value)),n.disableNormalPass||v())};u.watch([l,e,t,()=>n.disableNormalPass],()=>{!a.width.value||!a.height.value||S()}),u.watch(()=>[a.width.value,a.height.value],([f,C])=>{!f&&!C||(i.value?i.value.setSize(f,C):S())},{immediate:!0});const{onLoop:j}=m.useRenderLoop();return j(({delta:f})=>{if(n.enabled&&l.value&&i.value&&a.width.value&&a.height.value){const C=l.value.autoClear;l.value.autoClear=n.autoClear,n.stencilBuffer&&!n.autoClear&&l.value.clearStencil(),i.value.render(f),l.value.autoClear=C}}),u.onUnmounted(()=>{var f;(f=i.value)==null||f.dispose()}),(f,C)=>u.renderSlot(f.$slots,"default")}}),D=u.defineComponent({__name:"Glitch",props:{blendFunction:{},delay:{},duration:{},strength:{},mode:{},active:{type:Boolean},ratio:{},columns:{},chromaticAberrationOffset:{},perturbationMap:{},dtSize:{}},setup(o,{expose:n}){const e=o,{pass:t,effect:l}=h(()=>new r.GlitchEffect(e));return n({pass:t,effect:l}),u.watchEffect(()=>{const a=()=>{if(e.mode!==void 0)return e.active===!1?r.GlitchMode.DISABLED:e.mode;const i=new r.GlitchEffect,c=i.mode;return i.dispose(),c};l.value&&(l.value.mode=a())}),E(w(e,["active","mode","blendFunction"]),l,()=>new r.GlitchEffect),(a,i)=>null}}),k=u.defineComponent({__name:"Outline",props:{outlinedObjects:{},blur:{type:Boolean,default:void 0},xRay:{type:Boolean,default:void 0},kernelSize:{},pulseSpeed:{},resolutionX:{},resolutionY:{},edgeStrength:{},patternScale:{},multisampling:{},blendFunction:{},patternTexture:{},resolutionScale:{},hiddenEdgeColor:{},visibleEdgeColor:{}},setup(o,{expose:n}){const e=o,t=p=>p!==void 0?m.normalizeColor(p).getHex():void 0,{camera:l,scene:a}=m.useTresContext(),i={blur:e.blur,xRay:e.xRay,kernelSize:e.kernelSize,pulseSpeed:e.pulseSpeed,resolutionX:e.resolutionX,resolutionY:e.resolutionY,patternScale:e.patternScale,edgeStrength:e.edgeStrength,blendFunction:e.blendFunction,multisampling:e.multisampling,patternTexture:e.patternTexture,resolutionScale:e.resolutionScale,hiddenEdgeColor:t(e.hiddenEdgeColor),visibleEdgeColor:t(e.visibleEdgeColor)},{pass:c,effect:d}=h(()=>new r.OutlineEffect(a.value,l.value,i));n({pass:c,effect:d}),u.watch([()=>e.outlinedObjects,d],()=>{var p;(p=d.value)==null||p.selection.set(e.outlinedObjects||[])},{immediate:!0});const v=u.computed(()=>({hiddenEdgeColor:e.hiddenEdgeColor?m.normalizeColor(e.hiddenEdgeColor):void 0,visibleEdgeColor:e.visibleEdgeColor?m.normalizeColor(e.visibleEdgeColor):void 0}));return b([[()=>e.blur,"blur"],[()=>e.xRay,"xRay"],[()=>e.pulseSpeed,"pulseSpeed"],[()=>e.kernelSize,"kernelSize"],[()=>e.edgeStrength,"edgeStrength"],[()=>e.patternScale,"patternScale"],[()=>e.multisampling,"multisampling"],[()=>v.value.hiddenEdgeColor,"hiddenEdgeColor"],[()=>v.value.visibleEdgeColor,"visibleEdgeColor"]],d,()=>new r.OutlineEffect),(p,S)=>null}}),A=u.defineComponent({__name:"Pixelation",props:{granularity:{}},setup(o,{expose:n}){const e=o,{pass:t,effect:l}=h(()=>new r.PixelationEffect(e.granularity));return n({pass:t,effect:l}),E(e,l,()=>new r.PixelationEffect),(a,i)=>null}}),M=u.defineComponent({__name:"Vignette",props:{technique:{default:r.VignetteTechnique.DEFAULT},blendFunction:{default:r.BlendFunction.NORMAL},offset:{default:.5},darkness:{default:.5}},setup(o,{expose:n}){const e=o,{pass:t,effect:l}=h(()=>new r.VignetteEffect(e));return n({pass:t,effect:l}),E(w(e,["blendFunction"]),l,()=>new r.VignetteEffect),(a,i)=>null}}),N=u.defineComponent({__name:"Noise",props:{premultiply:{type:Boolean,default:!1},blendFunction:{default:r.BlendFunction.SCREEN}},setup(o,{expose:n}){const e=o,{pass:t,effect:l}=h(()=>new r.NoiseEffect(e));return n({pass:t,effect:l}),E(w(e,["blendFunction"]),l,()=>new r.NoiseEffect),(a,i)=>null}});s.Bloom=R,s.DepthOfField=O,s.EffectComposer=z,s.Glitch=D,s.Noise=N,s.Outline=k,s.Pixelation=A,s.Vignette=M,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tresjs/post-processing",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
5
  "packageManager": "pnpm@8.10.2",
6
6
  "description": "Post-processing library for TresJS",
7
7
  "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",