rayzee 4.8.11 → 4.8.12

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/rayzee.es.js CHANGED
@@ -11891,21 +11891,45 @@ var Wc = new Float32Array(3), Gc = {
11891
11891
  let r = this.gpuDevice;
11892
11892
  if (!r) return console.warn("OIDNDenoiser: gpuDevice not available"), !1;
11893
11893
  this._ensureGPUInputBuffers(e, t);
11894
- let i = r.createCommandEncoder({ label: "oidn-tex-to-buf" }), a = e * 16, o = (n, r) => i.copyTextureToBuffer({
11895
- texture: n,
11896
- mipLevel: 0
11897
- }, {
11898
- buffer: r,
11899
- offset: 0,
11900
- bytesPerRow: a,
11901
- rowsPerImage: t
11902
- }, {
11903
- width: e,
11904
- height: t,
11905
- depthOrArrayLayers: 1
11906
- });
11907
- o(n.color, this._gpuInputBuffers.color), o(n.albedo, this._gpuInputBuffers.albedo), o(n.normal, this._gpuInputBuffers.normal), r.queue.submit([i.finish()]), this.getTransparentBackground() ? await this._cacheInputAlpha(r, e, t) : this._cachedAlpha = null, this.ctx.drawImage(this.input, 0, 0, e, t);
11908
- let s = {
11894
+ let i = r.createCommandEncoder({ label: "oidn-tex-to-buf" }), a = e * 16, o = Math.ceil(a / 256) * 256, s = o !== a, c = [], l = (n, l) => {
11895
+ if (!s) i.copyTextureToBuffer({
11896
+ texture: n,
11897
+ mipLevel: 0
11898
+ }, {
11899
+ buffer: l,
11900
+ offset: 0,
11901
+ bytesPerRow: a,
11902
+ rowsPerImage: t
11903
+ }, {
11904
+ width: e,
11905
+ height: t,
11906
+ depthOrArrayLayers: 1
11907
+ });
11908
+ else {
11909
+ let s = r.createBuffer({
11910
+ size: o * t,
11911
+ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
11912
+ });
11913
+ c.push(s), i.copyTextureToBuffer({
11914
+ texture: n,
11915
+ mipLevel: 0
11916
+ }, {
11917
+ buffer: s,
11918
+ offset: 0,
11919
+ bytesPerRow: o,
11920
+ rowsPerImage: t
11921
+ }, {
11922
+ width: e,
11923
+ height: t,
11924
+ depthOrArrayLayers: 1
11925
+ });
11926
+ for (let e = 0; e < t; e++) i.copyBufferToBuffer(s, e * o, l, e * a, a);
11927
+ }
11928
+ };
11929
+ l(n.color, this._gpuInputBuffers.color), l(n.albedo, this._gpuInputBuffers.albedo), l(n.normal, this._gpuInputBuffers.normal), r.queue.submit([i.finish()]);
11930
+ for (let e of c) e.destroy();
11931
+ this.getTransparentBackground() ? await this._cacheInputAlpha(r, e, t) : this._cachedAlpha = null, this.ctx.drawImage(this.input, 0, 0, e, t);
11932
+ let u = {
11909
11933
  color: {
11910
11934
  data: this._gpuInputBuffers.color,
11911
11935
  width: e,
@@ -11922,13 +11946,13 @@ var Wc = new Float32Array(3), Gc = {
11922
11946
  height: t
11923
11947
  }
11924
11948
  };
11925
- return this._executeWithAbortGPU(s);
11949
+ return this._executeWithAbortGPU(u);
11926
11950
  }
11927
11951
  _ensureGPUInputBuffers(e, t) {
11928
11952
  let { width: n, height: r } = this._gpuInputBufferSize;
11929
11953
  if (n === e && r === t && this._gpuInputBuffers.color) return;
11930
11954
  this._destroyGPUInputBuffers();
11931
- let i = this.gpuDevice, a = e * t * 4 * 4, o = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC;
11955
+ let i = this.gpuDevice, a = e * t * 16, o = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC;
11932
11956
  this._gpuInputBuffers.color = i.createBuffer({
11933
11957
  label: "oidn-in-color",
11934
11958
  size: a,
@@ -11957,7 +11981,7 @@ var Wc = new Float32Array(3), Gc = {
11957
11981
  };
11958
11982
  }
11959
11983
  async _cacheInputAlpha(e, t, n) {
11960
- let r = t * n * 4 * 4, i = e.createBuffer({
11984
+ let r = t * n * 16, i = e.createBuffer({
11961
11985
  label: "oidn-alpha-staging",
11962
11986
  size: r,
11963
11987
  usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
@@ -11994,24 +12018,26 @@ var Wc = new Float32Array(3), Gc = {
11994
12018
  imageWidth: e.width,
11995
12019
  imageHeight: e.height
11996
12020
  });
11997
- let r = this.gpuDevice, i = e.width, a = n.width * 16, o = n.width * n.height * 16, s = r.createBuffer({
11998
- size: o,
12021
+ let r = this.gpuDevice, i = e.width, a = e.height, o = Math.min(n.width, i - n.x), s = Math.min(n.height, a - n.y);
12022
+ if (o <= 0 || s <= 0) return;
12023
+ let l = o * 16, u = o * s * 16, d = r.createBuffer({
12024
+ size: u,
11999
12025
  usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
12000
- }), l = r.createCommandEncoder();
12001
- for (let t = 0; t < n.height; t++) {
12002
- let r = ((n.y + t) * i + n.x) * 16, o = t * a;
12003
- l.copyBufferToBuffer(e.data, r, s, o, a);
12026
+ }), f = r.createCommandEncoder();
12027
+ for (let t = 0; t < s; t++) {
12028
+ let r = ((n.y + t) * i + n.x) * 16, a = t * l;
12029
+ f.copyBufferToBuffer(e.data, r, d, a, l);
12004
12030
  }
12005
- r.queue.submit([l.finish()]), s.mapAsync(GPUMapMode.READ).then(() => {
12006
- let e = new Float32Array(s.getMappedRange()), t = new ImageData(n.width, n.height), r = this.getExposure(), i = this.getSaturation(), a = Ic.get(this.getToneMapping()) || Ic.get(c), o = this._cachedAlpha, l = this._cachedAlphaWidth;
12031
+ r.queue.submit([f.finish()]), d.mapAsync(GPUMapMode.READ).then(() => {
12032
+ let e = new Float32Array(d.getMappedRange()), t = new ImageData(o, s), r = this.getExposure(), i = this.getSaturation(), a = Ic.get(this.getToneMapping()) || Ic.get(c), l = this._cachedAlpha, u = this._cachedAlphaWidth;
12007
12033
  for (let s = 0, c = e.length; s < c; s += 4) {
12008
- let c = e[s] * r, u = e[s + 1] * r, d = e[s + 2] * r;
12009
- if (i !== 1 && (Wc[0] = c, Wc[1] = u, Wc[2] = d, Vc(Wc, i), c = Wc[0], u = Wc[1], d = Wc[2]), a(c, u, d, 1, Wc), t.data[s] = Wc[0] ** Lc * 255 | 0, t.data[s + 1] = Wc[1] ** Lc * 255 | 0, t.data[s + 2] = Wc[2] ** Lc * 255 | 0, o) {
12010
- let e = (s >> 2) % n.width, r = (s >> 2) / n.width | 0;
12011
- t.data[s + 3] = o[(n.y + r) * l + n.x + e];
12034
+ let c = e[s] * r, d = e[s + 1] * r, f = e[s + 2] * r;
12035
+ if (i !== 1 && (Wc[0] = c, Wc[1] = d, Wc[2] = f, Vc(Wc, i), c = Wc[0], d = Wc[1], f = Wc[2]), a(c, d, f, 1, Wc), t.data[s] = Wc[0] ** Lc * 255 | 0, t.data[s + 1] = Wc[1] ** Lc * 255 | 0, t.data[s + 2] = Wc[2] ** Lc * 255 | 0, l) {
12036
+ let e = (s >> 2) % o, r = (s >> 2) / o | 0;
12037
+ t.data[s + 3] = l[(n.y + r) * u + n.x + e];
12012
12038
  } else t.data[s + 3] = 255;
12013
12039
  }
12014
- s.unmap(), s.destroy(), this.ctx.putImageData(t, n.x, n.y);
12040
+ d.unmap(), d.destroy(), this.ctx.putImageData(t, n.x, n.y);
12015
12041
  });
12016
12042
  }
12017
12043
  });