softbox 4.17.0 → 4.19.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.
- package/README.md +7 -6
- package/dist/{BrightnessContrastShader-BN6FBcLV.cjs → BrightnessContrastShader-C1jbh-NA.cjs} +2 -2
- package/dist/BrightnessContrastShader-CoM5EjqG.js +13 -0
- package/dist/CopyShader-C2Oc7n1P.js +12 -0
- package/dist/{CopyShader-DPSZNOxL.cjs → CopyShader-CM1OGKAp.cjs} +2 -2
- package/dist/EffectComposer-CMs4vldH.js +88 -0
- package/dist/EffectComposer-CdAQB6p0.cjs +1 -0
- package/dist/HueSaturationShader-BeHSjNY8.js +13 -0
- package/dist/{HueSaturationShader-BEp7jjxf.cjs → HueSaturationShader-bN5IWhh8.cjs} +2 -2
- package/dist/OutputPass-DicIJHut.cjs +72 -0
- package/dist/OutputPass-oQu4Xmeb.js +29 -0
- package/dist/Pass-CSHIrJrV.js +51 -0
- package/dist/Pass-D0vYi-gB.cjs +1 -0
- package/dist/RenderPass-DS8SYAhJ.js +16 -0
- package/dist/RenderPass-DlRq51Kq.cjs +1 -0
- package/dist/ShaderPass-DghZ7TAj.cjs +1 -0
- package/dist/ShaderPass-h4P0lBmc.js +22 -0
- package/dist/{ThreePathTracingService-DvBQToys.cjs → ThreePathTracingService-CMw8SvGp.cjs} +97 -97
- package/dist/ThreePathTracingService-Dze7maGx.js +2546 -0
- package/dist/UnrealBloomPass-BTHiW_Y8.js +123 -0
- package/dist/UnrealBloomPass-CQHHa-s_.cjs +115 -0
- package/dist/VignetteShader-CPF_iEkO.js +13 -0
- package/dist/{VignetteShader-Drpo9YxI.cjs → VignetteShader-CQmGrpns.cjs} +2 -2
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/simple-viewer.cjs +23 -1
- package/dist/simple-viewer.es.js +8492 -11
- package/dist/unwrap-CuSMMFPQ.cjs +2 -0
- package/dist/unwrap-DdgS2iXe.js +2087 -0
- package/package.json +30 -18
- package/dist/BrightnessContrastShader-B9tNAd_c.js +0 -49
- package/dist/CopyShader-DVL8Bcar.js +0 -41
- package/dist/EffectComposer-BdHnHszK.js +0 -188
- package/dist/EffectComposer-D2IQ0sek.cjs +0 -1
- package/dist/HueSaturationShader-B6tnz2ga.js +0 -60
- package/dist/OutputPass-Dy4KNHYF.cjs +0 -72
- package/dist/OutputPass-Tt8WbC_B.js +0 -125
- package/dist/Pass-C1mreNp8.cjs +0 -1
- package/dist/Pass-DOcH4lwV.js +0 -88
- package/dist/RenderPass-B57TYmjs.js +0 -37
- package/dist/RenderPass-BVzyKWsC.cjs +0 -1
- package/dist/ShaderPass-BQRqK8zp.cjs +0 -1
- package/dist/ShaderPass-C2HX8lsT.js +0 -45
- package/dist/ThreePathTracingService-Cf8e9Msc.js +0 -6383
- package/dist/UnrealBloomPass-Kx7djcld.cjs +0 -115
- package/dist/UnrealBloomPass-rjyQu37v.js +0 -281
- package/dist/VignetteShader-BG_QwoTp.js +0 -45
- package/dist/index-1jWUObtn.js +0 -13084
- package/dist/index-BlwMVqol.cjs +0 -29
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("./unwrap-CuSMMFPQ.cjs"),t=require("./Pass-D0vYi-gB.cjs");let n=require("three");n=e.j(n,1);function r(e){switch(e){case 1:return`R`;case 2:return`RG`;case 3:return`RGBA`;case 4:return`RGBA`}throw Error()}function i(e){switch(e){case 1:return n.RedFormat;case 2:return n.RGFormat;case 3:return n.RGBAFormat;case 4:return n.RGBAFormat}}function a(e){switch(e){case 1:return n.RedIntegerFormat;case 2:return n.RGIntegerFormat;case 3:return n.RGBAIntegerFormat;case 4:return n.RGBAIntegerFormat}}var o=class extends n.DataTexture{constructor(){super(),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){let t=this.overrideItemSize,o=e.itemSize,s=e.count;if(t!==null){if(o*s%t!==0)throw Error(`VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.`);e.itemSize=t,e.count=s*o/t}let c=e.itemSize,l=e.count,u=e.normalized,d=e.array.constructor,f=d.BYTES_PER_ELEMENT,p=this._forcedType,m=c;if(p===null)switch(d){case Float32Array:p=n.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:p=n.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:p=n.IntType;break}let h,g,_,v,y=r(c);switch(p){case n.FloatType:_=1,g=i(c),u&&f===1?(v=d,y+=`8`,d===Uint8Array?h=n.UnsignedByteType:(h=n.ByteType,y+=`_SNORM`)):(v=Float32Array,y+=`32F`,h=n.FloatType);break;case n.IntType:y+=f*8+`I`,_=u?2**(d.BYTES_PER_ELEMENT*8-1):1,g=a(c),f===1?(v=Int8Array,h=n.ByteType):f===2?(v=Int16Array,h=n.ShortType):(v=Int32Array,h=n.IntType);break;case n.UnsignedIntType:y+=f*8+`UI`,_=u?2**(d.BYTES_PER_ELEMENT*8-1):1,g=a(c),f===1?(v=Uint8Array,h=n.UnsignedByteType):f===2?(v=Uint16Array,h=n.UnsignedShortType):(v=Uint32Array,h=n.UnsignedIntType);break}m===3&&(g===n.RGBAFormat||g===n.RGBAIntegerFormat)&&(m=4);let b=Math.ceil(Math.sqrt(l))||1,x=m*b*b,S=new v(x),C=e.normalized;e.normalized=!1;for(let t=0;t<l;t++){let n=m*t;S[n]=e.getX(t)/_,c>=2&&(S[n+1]=e.getY(t)/_),c>=3&&(S[n+2]=e.getZ(t)/_,m===4&&(S[n+3]=1)),c>=4&&(S[n+3]=e.getW(t)/_)}e.normalized=C,this.internalFormat=y,this.format=g,this.type=h,this.image.width=b,this.image.height=b,this.image.data=S,this.needsUpdate=!0,this.dispose(),e.itemSize=o,e.count=s}},s=class extends o{constructor(){super(),this._forcedType=n.UnsignedIntType}},c=class extends o{constructor(){super(),this._forcedType=n.FloatType}},l=class{constructor(){this.index=new s,this.position=new c,this.bvhBounds=new n.DataTexture,this.bvhContents=new n.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(t){let{geometry:r}=t;if(d(t,this.bvhBounds,this.bvhContents),this.position.updateFrom(r.attributes.position),t.indirect){let i=t._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(r.index)this._cachedIndexAttr=r.index.clone();else{let t=e._(e.v(r));this._cachedIndexAttr=new n.BufferAttribute(t,1,!1)}u(r,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(r.index)}dispose(){let{index:e,position:t,bvhBounds:n,bvhContents:r}=this;e&&e.dispose(),t&&t.dispose(),n&&n.dispose(),r&&r.dispose()}};function u(e,t,n){let r=n.array,i=e.index?e.index.array:null;for(let e=0,n=t.length;e<n;e++){let n=3*e,a=3*t[e];for(let e=0;e<3;e++)r[n+e]=i?i[a+e]:a+e}}function d(t,r,i){let a=t._roots;if(a.length!==1)throw Error(`MeshBVHUniformStruct: Multi-root BVHs not supported.`);let o=a[0],s=new Uint16Array(o),c=new Uint32Array(o),l=new Float32Array(o),u=o.byteLength/32,d=2*Math.ceil(Math.sqrt(u/2)),f=new Float32Array(4*d*d),p=Math.ceil(Math.sqrt(u)),m=new Uint32Array(2*p*p);for(let t=0;t<u;t++){let n=t*32/4,r=n*2,i=e.y(n);for(let e=0;e<3;e++)f[8*t+0+e]=l[i+0+e],f[8*t+4+e]=l[i+3+e];if(e.x(r,s)){let i=e.b(r,s),a=e.S(n,c),o=e.w|i;m[t*2+0]=o,m[t*2+1]=a}else{let r=c[n+6],i=e.C(n,c);m[t*2+0]=i,m[t*2+1]=r}}r.image.data=f,r.image.width=d,r.image.height=d,r.format=n.RGBAFormat,r.type=n.FloatType,r.internalFormat=`RGBA32F`,r.minFilter=n.NearestFilter,r.magFilter=n.NearestFilter,r.generateMipmaps=!1,r.needsUpdate=!0,r.dispose(),i.image.data=m,i.image.width=p,i.image.height=p,i.format=n.RGIntegerFormat,i.type=n.UnsignedIntType,i.internalFormat=`RG32UI`,i.minFilter=n.NearestFilter,i.magFilter=n.NearestFilter,i.generateMipmaps=!1,i.needsUpdate=!0,i.dispose()}var f=`
|
|
2
2
|
|
|
3
3
|
// A stack of uint32 indices can can store the indices for
|
|
4
4
|
// a perfectly balanced tree with a depth up to 31. Lower stack
|
|
@@ -80,7 +80,7 @@ void ndcToCameraRay(
|
|
|
80
80
|
rayDirection = direction.xyz;
|
|
81
81
|
|
|
82
82
|
}
|
|
83
|
-
`,
|
|
83
|
+
`,p=`
|
|
84
84
|
|
|
85
85
|
#ifndef TRI_INTERSECT_EPSILON
|
|
86
86
|
#define TRI_INTERSECT_EPSILON 1e-5
|
|
@@ -284,7 +284,7 @@ bool _bvhIntersectFirstHit(
|
|
|
284
284
|
return found;
|
|
285
285
|
|
|
286
286
|
}
|
|
287
|
-
`,
|
|
287
|
+
`,m=`
|
|
288
288
|
struct BVH {
|
|
289
289
|
|
|
290
290
|
usampler2D index;
|
|
@@ -294,7 +294,7 @@ struct BVH {
|
|
|
294
294
|
usampler2D bvhContents;
|
|
295
295
|
|
|
296
296
|
};
|
|
297
|
-
`;function Le(s,e,t=0){if(s.isInterleavedBufferAttribute){const r=s.itemSize;for(let i=0,o=s.count;i<o;i++){const a=i+t;e.setX(a,s.getX(i)),r>=2&&e.setY(a,s.getY(i)),r>=3&&e.setZ(a,s.getZ(i)),r>=4&&e.setW(a,s.getW(i))}}else{const r=e.array,i=r.constructor,o=r.BYTES_PER_ELEMENT*s.itemSize*t;new i(r.buffer,o,s.array.length).set(s.array)}}function W(s,e=null){const t=s.array.constructor,r=s.normalized,i=s.itemSize,o=e===null?s.count:e;return new n.BufferAttribute(new t(i*o),i,r)}function H(s,e){if(!s&&!e)return!0;if(!!s!=!!e)return!1;const t=s.count===e.count,r=s.normalized===e.normalized,i=s.array.constructor===e.array.constructor,o=s.itemSize===e.itemSize;return!(!t||!r||!i||!o)}function it(s){const e=s[0].index!==null,t=new Set(Object.keys(s[0].attributes));if(!s[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let r=0;r<s.length;++r){const i=s[r];let o=0;if(e!==(i.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const a in i.attributes){if(!t.has(a))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+a+'" attribute exists among all geometries, or in none of them.');o++}if(o!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function st(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getIndex().count;return e}function ot(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getAttribute("position").count;return e}function nt(s,e,t){s.index&&s.index.count!==e&&s.setIndex(null);const r=s.attributes;for(const i in r)r[i].count!==t&&s.deleteAttribute(i)}function lt(s,e={},t=new n.BufferGeometry){const{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:o=[],overwriteIndex:a=!0}=e;it(s);const c=s[0].index!==null,f=c?st(s):-1,m=ot(s);if(nt(t,f,m),r){let h=0;for(let l=0,y=s.length;l<y;l++){const p=s[l];let v;c?v=p.getIndex().count:v=p.getAttribute("position").count,t.addGroup(h,v,l),h+=v}}if(c){let h=!1;if(t.index||(t.setIndex(new n.BufferAttribute(new Uint32Array(f),1,!1)),h=!0),h||a){let l=0,y=0;const p=t.getIndex();for(let v=0,u=s.length;v<u;v++){const g=s[v],x=g.getIndex();if(!(!i&&!h&&o[v]))for(let w=0;w<x.count;++w)p.setX(l+w,x.getX(w)+y);l+=x.count,y+=g.getAttribute("position").count}}}const d=Object.keys(s[0].attributes);for(let h=0,l=d.length;h<l;h++){let y=!1;const p=d[h];if(!t.getAttribute(p)){const g=s[0].getAttribute(p);t.setAttribute(p,W(g,m)),y=!0}let v=0;const u=t.getAttribute(p);for(let g=0,x=s.length;g<x;g++){const b=s[g],w=!i&&!y&&o[g],R=b.getAttribute(p);w||Le(R,u,v),v+=R.count}}}function ct(s,e,t){const r=s.index,o=s.attributes.position.count,a=r?r.count:o;let c=s.groups;c.length===0&&(c=[{count:a,start:0,materialIndex:0}]);let f=s.getAttribute("materialIndex");if(!f||f.count!==o){let d;t.length<=255?d=new Uint8Array(o):d=new Uint16Array(o),f=new n.BufferAttribute(d,1,!1),s.deleteAttribute("materialIndex"),s.setAttribute("materialIndex",f)}const m=f.array;for(let d=0;d<c.length;d++){const h=c[d],l=h.start,y=h.count,p=Math.min(y,a-l),v=Array.isArray(e)?e[h.materialIndex]:e,u=t.indexOf(v);for(let g=0;g<p;g++){let x=l+g;r&&(x=r.getX(x)),m[x]=u}}}function ut(s,e){if(!s.index){const t=s.attributes.position.count,r=new Array(t);for(let i=0;i<t;i++)r[i]=i;s.setIndex(r)}if(!s.attributes.normal&&e&&e.includes("normal")&&s.computeVertexNormals(),!s.attributes.uv&&e&&e.includes("uv")){const t=s.attributes.position.count;s.setAttribute("uv",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.uv2&&e&&e.includes("uv2")){const t=s.attributes.position.count;s.setAttribute("uv2",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.tangent&&e&&e.includes("tangent"))if(s.attributes.uv&&s.attributes.normal)s.computeTangents();else{const t=s.attributes.position.count;s.setAttribute("tangent",new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!s.attributes.color&&e&&e.includes("color")){const t=s.attributes.position.count,r=new Float32Array(t*4);r.fill(1),s.setAttribute("color",new n.BufferAttribute(r,4))}}function ne(s){let e=0;if(s.byteLength!==0){const t=new Uint8Array(s);for(let r=0;r<s.byteLength;r++){const i=t[r];e=(e<<5)-e+i,e|=0}}return e}function ge(s){let e=s.uuid;const t=Object.values(s.attributes);s.index&&(t.push(s.index),e+=`index|${s.index.version}`);const r=Object.keys(t).sort();for(const i of r){const o=t[i];e+=`${i}_${o.version}|`}return e}function ve(s){const e=s.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${ne(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class ft{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=ge(t),this.primitiveCount=r,this.skeletonHash=ve(e)}didChange(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===ge(t)&&this.skeletonHash===ve(e)&&this.primitiveCount===r)}}const C=new n.Vector3,D=new n.Vector3,E=new n.Vector3,xe=new n.Vector4,G=new n.Vector3,ee=new n.Vector3,ye=new n.Vector4,be=new n.Vector4,V=new n.Matrix4,Te=new n.Matrix4;function we(s,e,t){const r=s.skeleton,i=s.geometry,o=r.bones,a=r.boneInverses;ye.fromBufferAttribute(i.attributes.skinIndex,e),be.fromBufferAttribute(i.attributes.skinWeight,e),V.elements.fill(0);for(let c=0;c<4;c++){const f=be.getComponent(c);if(f!==0){const m=ye.getComponent(c);Te.multiplyMatrices(o[m].matrixWorld,a[m]),ht(V,Te,f)}}return V.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),t.transformDirection(V),t}function te(s,e,t,r,i){G.set(0,0,0);for(let o=0,a=s.length;o<a;o++){const c=e[o],f=s[o];c!==0&&(ee.fromBufferAttribute(f,r),t?G.addScaledVector(ee,c):G.addScaledVector(ee.sub(i),c))}i.add(G)}function ht(s,e,t){const r=s.elements,i=e.elements;for(let o=0,a=i.length;o<a;o++)r[o]+=i[o]*t}function dt(s){const{index:e,attributes:t}=s;if(e)for(let r=0,i=e.count;r<i;r+=3){const o=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,o)}else for(const r in t){const i=t[r],o=i.itemSize;for(let a=0,c=i.count;a<c;a+=3)for(let f=0;f<o;f++){const m=i.getComponent(a,f),d=i.getComponent(a+2,f);i.setComponent(a,f,d),i.setComponent(a+2,f,m)}}return s}function mt(s,e={},t=new n.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const r=s.geometry,i=e.applyWorldTransforms,o=e.attributes.includes("normal"),a=e.attributes.includes("tangent"),c=r.attributes,f=t.attributes;for(const x in t.attributes)(!e.attributes.includes(x)||!(x in r.attributes))&&t.deleteAttribute(x);!t.index&&r.index&&(t.index=r.index.clone()),f.position||t.setAttribute("position",W(c.position)),o&&!f.normal&&c.normal&&t.setAttribute("normal",W(c.normal)),a&&!f.tangent&&c.tangent&&t.setAttribute("tangent",W(c.tangent)),H(r.index,t.index),H(c.position,f.position),o&&H(c.normal,f.normal),a&&H(c.tangent,f.tangent);const m=c.position,d=o?c.normal:null,h=a?c.tangent:null,l=r.morphAttributes.position,y=r.morphAttributes.normal,p=r.morphAttributes.tangent,v=r.morphTargetsRelative,u=s.morphTargetInfluences,g=new n.Matrix3;g.getNormalMatrix(s.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let x=0,b=c.position.count;x<b;x++)C.fromBufferAttribute(m,x),d&&D.fromBufferAttribute(d,x),h&&(xe.fromBufferAttribute(h,x),E.fromBufferAttribute(h,x)),u&&(l&&te(l,u,v,x,C),y&&te(y,u,v,x,D),p&&te(p,u,v,x,E)),s.isSkinnedMesh&&(s.applyBoneTransform(x,C),d&&we(s,x,D),h&&we(s,x,E)),i&&C.applyMatrix4(s.matrixWorld),f.position.setXYZ(x,C.x,C.y,C.z),d&&(i&&D.applyNormalMatrix(g),f.normal.setXYZ(x,D.x,D.y,D.z)),h&&(i&&E.transformDirection(s.matrixWorld),f.tangent.setXYZW(x,E.x,E.y,E.z,xe.w));for(const x in e.attributes){const b=e.attributes[x];b==="position"||b==="tangent"||b==="normal"||!(b in c)||(f[b]||t.setAttribute(b,W(c[b])),H(c[b],f[b]),Le(c[b],f[b]))}return s.matrixWorld.determinant()<0&&dt(t),t}class pt extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new ft}isCompatible(e,t){const r=e.geometry;for(let i=0;i<t.length;i++){const o=t[i],a=r.attributes[o],c=this.attributes[o];if(a&&!H(a,c))return!1}return!0}updateFrom(e,t){const r=this._diff;return r.didChange(e)?(mt(e,t,this),r.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const ie=0,Ue=1,Ge=2;function gt(s,e){for(let t=0,r=s.length;t<r;t++)s[t].traverseVisible(o=>{o.isMesh&&e(o)})}function vt(s){const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];Array.isArray(i.material)?e.push(...i.material):e.push(i.material)}return e}function xt(s,e,t){if(s.length===0){e.setIndex(null);const r=e.attributes;for(const i in r)e.deleteAttribute(i);for(const i in t.attributes)e.setAttribute(t.attributes[i],new n.BufferAttribute(new Float32Array(0),4,!1))}else lt(s,t,e);for(const r in e.attributes)e.attributes[r].needsUpdate=!0}class yt{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new n.MeshBasicMaterial,t=new n.BufferGeometry;t.setAttribute("position",new n.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new n.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return gt(this.objects,t=>{e.push(t)}),e.sort((t,r)=>t.uuid>r.uuid?1:t.uuid<r.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),r=new Set(e.keys()),i={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let o=0,a=t.length;o<a;o++){const c=t[o],f=c.uuid;r.delete(f);let m=e.get(f);(!m||!m.isCompatible(c,this.attributes))&&(m&&m.dispose(),m=new pt,e.set(f,m)),m.updateFrom(c,i)&&this.generateMissingAttributes&&ut(m,this.attributes)}r.forEach(o=>{e.delete(o)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){const{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:o}=this,a=this._getMeshes(),c=[],f=[],m=o.get(e)||[];this._updateIntermediateGeometries();let d=!1;a.length!==m.length&&(d=!0);for(let l=0,y=a.length;l<y;l++){const p=a[l],v=i.get(p.uuid);f.push(v);const u=m[l];!u||u.uuid!==v.uuid?(c.push(!1),d=!0):u.version!==v.version?c.push(!1):c.push(!0)}xt(f,e,{useGroups:t,forceUpdate:d,skipAssigningAttributes:c,overwriteIndex:r}),d&&e.dispose(),o.set(e,f.map(l=>({version:l.version,uuid:l.uuid})));let h=ie;return d?h=Ge:c.includes(!1)&&(h=Ue),{changeType:h,materials:vt(a),geometry:e}}}function bt(s){const e=new Set;for(let t=0,r=s.length;t<r;t++){const i=s[t];for(const o in i){const a=i[o];a&&a.isTexture&&e.add(a)}}return Array.from(e)}function Tt(s){const e=[],t=new Set;for(let i=0,o=s.length;i<o;i++)s[i].traverse(a=>{a.visible&&(a.isRectAreaLight||a.isSpotLight||a.isPointLight||a.isDirectionalLight)&&(e.push(a),a.iesMap&&t.add(a.iesMap))});const r=Array.from(t).sort((i,o)=>i.uuid<o.uuid?1:i.uuid>o.uuid?-1:0);return{lights:e,iesTextures:r}}class wt{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new n.BufferGeometry,this.staticGeometryGenerator=new yt(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:r,attributes:i}=this,o=t.objects;t.attributes=i,o.forEach(h=>{h.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const a=t.generate(r),c=a.materials,f=bt(c),{lights:m,iesTextures:d}=Tt(o);if(a.changeType!==ie&&ct(r,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(a.changeType===Ge){const h={strategy:T.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,h):this.bvh=new T.MeshBVH(r,h)}else a.changeType===Ue&&this.bvh.refit()}return{bvhChanged:a.changeType!==ie,bvh:this.bvh,lights:m,iesTextures:d,geometry:r,materials:c,textures:f,objects:o}}}class le extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(r){this.uniforms[t].value=r}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class Rt extends le{constructor(e){super({blending:n.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
|
|
297
|
+
`;function h(e,t,n=0){if(e.isInterleavedBufferAttribute){let r=e.itemSize;for(let i=0,a=e.count;i<a;i++){let a=i+n;t.setX(a,e.getX(i)),r>=2&&t.setY(a,e.getY(i)),r>=3&&t.setZ(a,e.getZ(i)),r>=4&&t.setW(a,e.getW(i))}}else{let r=t.array,i=r.constructor,a=r.BYTES_PER_ELEMENT*e.itemSize*n;new i(r.buffer,a,e.array.length).set(e.array)}}function g(e,t=null){let r=e.array.constructor,i=e.normalized,a=e.itemSize;return new n.BufferAttribute(new r(a*(t===null?e.count:t)),a,i)}function _(e,t){if(!e&&!t)return!0;if(!!e!=!!t)return!1;let n=e.count===t.count,r=e.normalized===t.normalized,i=e.array.constructor===t.array.constructor,a=e.itemSize===t.itemSize;return!(!n||!r||!i||!a)}function v(e){let t=e[0].index!==null,n=new Set(Object.keys(e[0].attributes));if(!e[0].getAttribute(`position`))throw Error(`StaticGeometryGenerator: position attribute is required.`);for(let r=0;r<e.length;++r){let i=e[r],a=0;if(t!==(i.index!==null))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`);for(let e in i.attributes){if(!n.has(e))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`);a++}if(a!==n.size)throw Error(`StaticGeometryGenerator: All geometries must have the same number of attributes.`)}}function y(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getIndex().count;return t}function b(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getAttribute(`position`).count;return t}function x(e,t,n){e.index&&e.index.count!==t&&e.setIndex(null);let r=e.attributes;for(let t in r)r[t].count!==n&&e.deleteAttribute(t)}function S(e,t={},r=new n.BufferGeometry){let{useGroups:i=!1,forceUpdate:a=!1,skipAssigningAttributes:o=[],overwriteIndex:s=!0}=t;v(e);let c=e[0].index!==null,l=c?y(e):-1,u=b(e);if(x(r,l,u),i){let t=0;for(let n=0,i=e.length;n<i;n++){let i=e[n],a;a=c?i.getIndex().count:i.getAttribute(`position`).count,r.addGroup(t,a,n),t+=a}}if(c){let t=!1;if(r.index||(r.setIndex(new n.BufferAttribute(new Uint32Array(l),1,!1)),t=!0),t||s){let n=0,i=0,s=r.getIndex();for(let r=0,c=e.length;r<c;r++){let c=e[r],l=c.getIndex();if(!(!a&&!t&&o[r]))for(let e=0;e<l.count;++e)s.setX(n+e,l.getX(e)+i);n+=l.count,i+=c.getAttribute(`position`).count}}}let d=Object.keys(e[0].attributes);for(let t=0,n=d.length;t<n;t++){let n=!1,i=d[t];if(!r.getAttribute(i)){let t=e[0].getAttribute(i);r.setAttribute(i,g(t,u)),n=!0}let s=0,c=r.getAttribute(i);for(let t=0,r=e.length;t<r;t++){let r=e[t],l=!a&&!n&&o[t],u=r.getAttribute(i);l||h(u,c,s),s+=u.count}}}function C(e,t,r){let i=e.index,a=e.attributes.position.count,o=i?i.count:a,s=e.groups;s.length===0&&(s=[{count:o,start:0,materialIndex:0}]);let c=e.getAttribute(`materialIndex`);if(!c||c.count!==a){let t;t=r.length<=255?new Uint8Array(a):new Uint16Array(a),c=new n.BufferAttribute(t,1,!1),e.deleteAttribute(`materialIndex`),e.setAttribute(`materialIndex`,c)}let l=c.array;for(let e=0;e<s.length;e++){let n=s[e],a=n.start,c=n.count,u=Math.min(c,o-a),d=Array.isArray(t)?t[n.materialIndex]:t,f=r.indexOf(d);for(let e=0;e<u;e++){let t=a+e;i&&(t=i.getX(t)),l[t]=f}}}function w(e,t){if(!e.index){let t=e.attributes.position.count,n=Array(t);for(let e=0;e<t;e++)n[e]=e;e.setIndex(n)}if(!e.attributes.normal&&t&&t.includes(`normal`)&&e.computeVertexNormals(),!e.attributes.uv&&t&&t.includes(`uv`)){let t=e.attributes.position.count;e.setAttribute(`uv`,new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!e.attributes.uv2&&t&&t.includes(`uv2`)){let t=e.attributes.position.count;e.setAttribute(`uv2`,new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!e.attributes.tangent&&t&&t.includes(`tangent`))if(e.attributes.uv&&e.attributes.normal)e.computeTangents();else{let t=e.attributes.position.count;e.setAttribute(`tangent`,new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!e.attributes.color&&t&&t.includes(`color`)){let t=e.attributes.position.count,r=new Float32Array(t*4);r.fill(1),e.setAttribute(`color`,new n.BufferAttribute(r,4))}}function T(e){let t=0;if(e.byteLength!==0){let n=new Uint8Array(e);for(let r=0;r<e.byteLength;r++){let e=n[r];t=(t<<5)-t+e,t|=0}}return t}function E(e){let t=e.uuid,n=Object.values(e.attributes);e.index&&(n.push(e.index),t+=`index|${e.index.version}`);let r=Object.keys(n).sort();for(let e of r){let r=n[e];t+=`${e}_${r.version}|`}return t}function D(e){let t=e.skeleton;return t?(t.boneTexture||t.computeBoneTexture(),`${T(t.boneTexture.image.data.buffer)}_${t.boneTexture.uuid}`):null}var O=class{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=E(t),this.primitiveCount=n,this.skeletonHash=D(e)}didChange(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===E(t)&&this.skeletonHash===D(e)&&this.primitiveCount===n)}},k=new n.Vector3,A=new n.Vector3,j=new n.Vector3,M=new n.Vector4,N=new n.Vector3,P=new n.Vector3,ee=new n.Vector4,te=new n.Vector4,F=new n.Matrix4,I=new n.Matrix4;function ne(e,t,n){let r=e.skeleton,i=e.geometry,a=r.bones,o=r.boneInverses;ee.fromBufferAttribute(i.attributes.skinIndex,t),te.fromBufferAttribute(i.attributes.skinWeight,t),F.elements.fill(0);for(let e=0;e<4;e++){let t=te.getComponent(e);if(t!==0){let n=ee.getComponent(e);I.multiplyMatrices(a[n].matrixWorld,o[n]),re(F,I,t)}}return F.multiply(e.bindMatrix).premultiply(e.bindMatrixInverse),n.transformDirection(F),n}function L(e,t,n,r,i){N.set(0,0,0);for(let a=0,o=e.length;a<o;a++){let o=t[a],s=e[a];o!==0&&(P.fromBufferAttribute(s,r),n?N.addScaledVector(P,o):N.addScaledVector(P.sub(i),o))}i.add(N)}function re(e,t,n){let r=e.elements,i=t.elements;for(let e=0,t=i.length;e<t;e++)r[e]+=i[e]*n}function ie(e){let{index:t,attributes:n}=e;if(t)for(let e=0,n=t.count;e<n;e+=3){let n=t.getX(e),r=t.getX(e+2);t.setX(e,r),t.setX(e+2,n)}else for(let e in n){let t=n[e],r=t.itemSize;for(let e=0,n=t.count;e<n;e+=3)for(let n=0;n<r;n++){let r=t.getComponent(e,n),i=t.getComponent(e+2,n);t.setComponent(e,n,i),t.setComponent(e+2,n,r)}}return e}function ae(e,t={},r=new n.BufferGeometry){t={applyWorldTransforms:!0,attributes:[],...t};let i=e.geometry,a=t.applyWorldTransforms,o=t.attributes.includes(`normal`),s=t.attributes.includes(`tangent`),c=i.attributes,l=r.attributes;for(let e in r.attributes)(!t.attributes.includes(e)||!(e in i.attributes))&&r.deleteAttribute(e);!r.index&&i.index&&(r.index=i.index.clone()),l.position||r.setAttribute(`position`,g(c.position)),o&&!l.normal&&c.normal&&r.setAttribute(`normal`,g(c.normal)),s&&!l.tangent&&c.tangent&&r.setAttribute(`tangent`,g(c.tangent)),_(i.index,r.index),_(c.position,l.position),o&&_(c.normal,l.normal),s&&_(c.tangent,l.tangent);let u=c.position,d=o?c.normal:null,f=s?c.tangent:null,p=i.morphAttributes.position,m=i.morphAttributes.normal,v=i.morphAttributes.tangent,y=i.morphTargetsRelative,b=e.morphTargetInfluences,x=new n.Matrix3;x.getNormalMatrix(e.matrixWorld),i.index&&r.index.array.set(i.index.array);for(let t=0,n=c.position.count;t<n;t++)k.fromBufferAttribute(u,t),d&&A.fromBufferAttribute(d,t),f&&(M.fromBufferAttribute(f,t),j.fromBufferAttribute(f,t)),b&&(p&&L(p,b,y,t,k),m&&L(m,b,y,t,A),v&&L(v,b,y,t,j)),e.isSkinnedMesh&&(e.applyBoneTransform(t,k),d&&ne(e,t,A),f&&ne(e,t,j)),a&&k.applyMatrix4(e.matrixWorld),l.position.setXYZ(t,k.x,k.y,k.z),d&&(a&&A.applyNormalMatrix(x),l.normal.setXYZ(t,A.x,A.y,A.z)),f&&(a&&j.transformDirection(e.matrixWorld),l.tangent.setXYZW(t,j.x,j.y,j.z,M.w));for(let e in t.attributes){let n=t.attributes[e];n===`position`||n===`tangent`||n===`normal`||!(n in c)||(l[n]||r.setAttribute(n,g(c[n])),_(c[n],l[n]),h(c[n],l[n]))}return e.matrixWorld.determinant()<0&&ie(r),r}var oe=class extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new O}isCompatible(e,t){let n=e.geometry;for(let e=0;e<t.length;e++){let r=t[e],i=n.attributes[r],a=this.attributes[r];if(i&&!_(i,a))return!1}return!0}updateFrom(e,t){let n=this._diff;return n.didChange(e)?(ae(e,t,this),n.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}};function se(e,t){for(let n=0,r=e.length;n<r;n++)e[n].traverseVisible(e=>{e.isMesh&&t(e)})}function ce(e){let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];Array.isArray(r.material)?t.push(...r.material):t.push(r.material)}return t}function le(e,t,r){if(e.length===0){t.setIndex(null);let e=t.attributes;for(let n in e)t.deleteAttribute(n);for(let e in r.attributes)t.setAttribute(r.attributes[e],new n.BufferAttribute(new Float32Array,4,!1))}else S(e,r,t);for(let e in t.attributes)t.attributes[e].needsUpdate=!0}var ue=class{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=[`position`,`normal`,`color`,`tangent`,`uv`,`uv2`],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){let e=new n.MeshBasicMaterial,t=new n.BufferGeometry;t.setAttribute(`position`,new n.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new n.Mesh(t,e)}return this._dummyMesh}_getMeshes(){let e=[];return se(this.objects,t=>{e.push(t)}),e.sort((e,t)=>e.uuid>t.uuid?1:e.uuid<t.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){let{_intermediateGeometry:e}=this,t=this._getMeshes(),n=new Set(e.keys()),r={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let i=0,a=t.length;i<a;i++){let a=t[i],o=a.uuid;n.delete(o);let s=e.get(o);(!s||!s.isCompatible(a,this.attributes))&&(s&&s.dispose(),s=new oe,e.set(o,s)),s.updateFrom(a,r)&&this.generateMissingAttributes&&w(s,this.attributes)}n.forEach(t=>{e.delete(t)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){let{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:a}=this,o=this._getMeshes(),s=[],c=[],l=a.get(e)||[];this._updateIntermediateGeometries();let u=!1;o.length!==l.length&&(u=!0);for(let e=0,t=o.length;e<t;e++){let t=o[e],n=i.get(t.uuid);c.push(n);let r=l[e];!r||r.uuid!==n.uuid?(s.push(!1),u=!0):r.version===n.version?s.push(!0):s.push(!1)}le(c,e,{useGroups:t,forceUpdate:u,skipAssigningAttributes:s,overwriteIndex:r}),u&&e.dispose(),a.set(e,c.map(e=>({version:e.version,uuid:e.uuid})));let d=0;return u?d=2:s.includes(!1)&&(d=1),{changeType:d,materials:ce(o),geometry:e}}};function de(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return Array.from(t)}function fe(e){let t=[],n=new Set;for(let r=0,i=e.length;r<i;r++)e[r].traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&(t.push(e),e.iesMap&&n.add(e.iesMap))});return{lights:t,iesTextures:Array.from(n).sort((e,t)=>e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0)}}var pe=class{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=[`position`,`normal`,`tangent`,`color`,`uv`,`uv2`],this.generateBVH=!0,this.bvh=null,this.geometry=new n.BufferGeometry,this.staticGeometryGenerator=new ue(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw Error(`PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.`);if(this.bvh instanceof Promise)return this._pendingGenerate||=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e))),this._pendingGenerate;{this._buildAsync=!0;let t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(t=null){let{staticGeometryGenerator:n,geometry:r,attributes:i}=this,a=n.objects;n.attributes=i,a.forEach(e=>{e.traverse(e=>{e.isSkinnedMesh&&e.skeleton&&e.skeleton.update()})});let o=n.generate(r),s=o.materials,c=de(s),{lights:l,iesTextures:u}=fe(a);if(o.changeType!==0&&C(r,s,s),this.generateBVH){if(this.bvh instanceof Promise)throw Error(`PathTracingSceneGenerator: BVH is already building asynchronously.`);if(o.changeType===2){let n={strategy:2,maxLeafTris:1,indirect:!0,onProgress:t,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,n):this.bvh=new e.g(r,n)}else o.changeType===1&&this.bvh.refit()}return{bvhChanged:o.changeType!==0,bvh:this.bvh,lights:l,iesTextures:u,geometry:r,materials:s,textures:c,objects:a}}},R=class extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:`recompilation`})}constructor(e){super(e);for(let e in this.uniforms)Object.defineProperty(this,e,{get(){return this.uniforms[e].value},set(t){this.uniforms[e].value=t}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}},me=class extends R{constructor(e){super({blending:n.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
|
|
298
298
|
|
|
299
299
|
varying vec2 vUv;
|
|
300
300
|
|
|
@@ -331,8 +331,8 @@ struct BVH {
|
|
|
331
331
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
}`}),this.setValues(e)}}function
|
|
335
|
-
${
|
|
334
|
+
}`}),this.setValues(e)}};function z(e=1){let t=`uint`;return e>1&&(t=`uvec`+e),`
|
|
335
|
+
${t} sobolReverseBits( ${t} x ) {
|
|
336
336
|
|
|
337
337
|
x = ( ( ( x & 0xaaaaaaaau ) >> 1 ) | ( ( x & 0x55555555u ) << 1 ) );
|
|
338
338
|
x = ( ( ( x & 0xccccccccu ) >> 2 ) | ( ( x & 0x33333333u ) << 2 ) );
|
|
@@ -342,13 +342,13 @@ struct BVH {
|
|
|
342
342
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
${
|
|
345
|
+
${t} sobolHashCombine( uint seed, ${t} v ) {
|
|
346
346
|
|
|
347
|
-
return seed ^ ( v + ${
|
|
347
|
+
return seed ^ ( v + ${t}( ( seed << 6 ) + ( seed >> 2 ) ) );
|
|
348
348
|
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
${
|
|
351
|
+
${t} sobolLaineKarrasPermutation( ${t} x, ${t} seed ) {
|
|
352
352
|
|
|
353
353
|
x += seed;
|
|
354
354
|
x ^= x * 0x6c50b47cu;
|
|
@@ -359,41 +359,41 @@ struct BVH {
|
|
|
359
359
|
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
-
${
|
|
362
|
+
${t} nestedUniformScrambleBase2( ${t} x, ${t} seed ) {
|
|
363
363
|
|
|
364
364
|
x = sobolLaineKarrasPermutation( x, seed );
|
|
365
365
|
x = sobolReverseBits( x );
|
|
366
366
|
return x;
|
|
367
367
|
|
|
368
368
|
}
|
|
369
|
-
`}function
|
|
369
|
+
`}function B(e=1){let t=`uint`,n=`float`,r=``,i=`.r`,a=`1u`;return e>1&&(t=`uvec`+e,n=`vec`+e,r=e+``,e===2?(i=`.rg`,a=`uvec2( 1u, 2u )`):e===3?(i=`.rgb`,a=`uvec3( 1u, 2u, 3u )`):(i=``,a=`uvec4( 1u, 2u, 3u, 4u )`)),`
|
|
370
370
|
|
|
371
|
-
${
|
|
371
|
+
${n} sobol${r}( int effect ) {
|
|
372
372
|
|
|
373
373
|
uint seed = sobolGetSeed( sobolBounceIndex, uint( effect ) );
|
|
374
374
|
uint index = sobolPathIndex;
|
|
375
375
|
|
|
376
376
|
uint shuffle_seed = sobolHashCombine( seed, 0u );
|
|
377
377
|
uint shuffled_index = nestedUniformScrambleBase2( sobolReverseBits( index ), shuffle_seed );
|
|
378
|
-
${
|
|
379
|
-
${
|
|
378
|
+
${n} sobol_pt = sobolGetTexturePoint( shuffled_index )${i};
|
|
379
|
+
${t} result = ${t}( sobol_pt * 16777216.0 );
|
|
380
380
|
|
|
381
|
-
${
|
|
381
|
+
${t} seed2 = sobolHashCombine( seed, ${a} );
|
|
382
382
|
result = nestedUniformScrambleBase2( result, seed2 );
|
|
383
383
|
|
|
384
|
-
return SOBOL_FACTOR * ${
|
|
384
|
+
return SOBOL_FACTOR * ${n}( result >> 8 );
|
|
385
385
|
|
|
386
386
|
}
|
|
387
|
-
`}
|
|
387
|
+
`}var he=`
|
|
388
388
|
|
|
389
389
|
// Utils
|
|
390
390
|
const float SOBOL_FACTOR = 1.0 / 16777216.0;
|
|
391
391
|
const uint SOBOL_MAX_POINTS = 256u * 256u;
|
|
392
392
|
|
|
393
|
-
${
|
|
394
|
-
${
|
|
395
|
-
${
|
|
396
|
-
${
|
|
393
|
+
${z(1)}
|
|
394
|
+
${z(2)}
|
|
395
|
+
${z(3)}
|
|
396
|
+
${z(4)}
|
|
397
397
|
|
|
398
398
|
uint sobolHash( uint x ) {
|
|
399
399
|
|
|
@@ -407,7 +407,7 @@ struct BVH {
|
|
|
407
407
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
`,
|
|
410
|
+
`,ge=`
|
|
411
411
|
|
|
412
412
|
const uint SOBOL_DIRECTIONS_1[ 32 ] = uint[ 32 ](
|
|
413
413
|
0x80000000u, 0xc0000000u, 0xa0000000u, 0xf0000000u,
|
|
@@ -485,7 +485,7 @@ struct BVH {
|
|
|
485
485
|
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
`,
|
|
488
|
+
`,_e=`
|
|
489
489
|
|
|
490
490
|
// Seeds
|
|
491
491
|
uniform sampler2D sobolTexture;
|
|
@@ -523,12 +523,12 @@ struct BVH {
|
|
|
523
523
|
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
-
${
|
|
527
|
-
${
|
|
528
|
-
${
|
|
529
|
-
${
|
|
526
|
+
${B(1)}
|
|
527
|
+
${B(2)}
|
|
528
|
+
${B(3)}
|
|
529
|
+
${B(4)}
|
|
530
530
|
|
|
531
|
-
|
|
531
|
+
`,ve=class extends R{constructor(){super({blending:n.NoBlending,uniforms:{resolution:{value:new n.Vector2}},vertexShader:`
|
|
532
532
|
|
|
533
533
|
varying vec2 vUv;
|
|
534
534
|
void main() {
|
|
@@ -539,8 +539,8 @@ struct BVH {
|
|
|
539
539
|
}
|
|
540
540
|
`,fragmentShader:`
|
|
541
541
|
|
|
542
|
-
${
|
|
543
|
-
${
|
|
542
|
+
${he}
|
|
543
|
+
${ge}
|
|
544
544
|
|
|
545
545
|
varying vec2 vUv;
|
|
546
546
|
uniform vec2 resolution;
|
|
@@ -550,7 +550,7 @@ struct BVH {
|
|
|
550
550
|
gl_FragColor = generateSobolPoint( index );
|
|
551
551
|
|
|
552
552
|
}
|
|
553
|
-
`})}}class Ft{generate(e,t=256){const r=new n.WebGLRenderTarget(t,t,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),i=e.getRenderTarget();e.setRenderTarget(r);const o=new N.FullScreenQuad(new _t);return o.material.resolution.set(t,t),o.render(e),e.setRenderTarget(i),o.dispose(),r}}class At extends n.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}}class Mt{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof At?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function re(s){const e=new Uint16Array(s.length);for(let t=0,r=s.length;t<r;++t)e[t]=n.DataUtils.toHalfFloat(s[t]);return e}function Re(s,e,t=0,r=s.length){let i=t,o=t+r-1;for(;i<o;){const a=i+o>>1;s[a]<e?i=a+1:o=a}return i-t}function Ct(s,e,t){return .2126*s+.7152*e+.0722*t}function Dt(s,e=n.HalfFloatType){const t=s.clone();t.source=new n.Source({...t.image});const{width:r,height:i,data:o}=t.image;let a=o;if(t.type!==e){e===n.HalfFloatType?a=new Uint16Array(o.length):a=new Float32Array(o.length);let c;o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?c=2**(8*o.BYTES_PER_ELEMENT-1)-1:c=2**(8*o.BYTES_PER_ELEMENT)-1;for(let f=0,m=o.length;f<m;f++){let d=o[f];t.type===n.HalfFloatType&&(d=n.DataUtils.fromHalfFloat(o[f])),t.type!==n.FloatType&&t.type!==n.HalfFloatType&&(d/=c),e===n.HalfFloatType&&(a[f]=n.DataUtils.toHalfFloat(d))}t.image.data=a,t.type=e}if(t.flipY){const c=a;a=a.slice();for(let f=0;f<i;f++)for(let m=0;m<r;m++){const d=i-f-1,h=4*(f*r+m),l=4*(d*r+m);a[l+0]=c[h+0],a[l+1]=c[h+1],a[l+2]=c[h+2],a[l+3]=c[h+3]}t.flipY=!1,t.image.data=a}return t}class Et{constructor(){const e=new n.DataTexture(re(new Float32Array([0,0,0,0])),1,1);e.type=n.HalfFloatType,e.format=n.RGBAFormat,e.minFilter=n.LinearFilter,e.magFilter=n.LinearFilter,e.wrapS=n.RepeatWrapping,e.wrapT=n.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new n.DataTexture(re(new Float32Array([0,1])),1,2);t.type=n.HalfFloatType,t.format=n.RedFormat,t.minFilter=n.LinearFilter,t.magFilter=n.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const r=new n.DataTexture(re(new Float32Array([0,0,1,1])),2,2);r.type=n.HalfFloatType,r.format=n.RedFormat,r.minFilter=n.LinearFilter,r.magFilter=n.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Dt(e);t.wrapS=n.RepeatWrapping,t.wrapT=n.ClampToEdgeWrapping;const{width:r,height:i,data:o}=t.image,a=new Float32Array(r*i),c=new Float32Array(r*i),f=new Float32Array(i),m=new Float32Array(i);let d=0,h=0;for(let u=0;u<i;u++){let g=0;for(let x=0;x<r;x++){const b=u*r+x,w=n.DataUtils.fromHalfFloat(o[4*b+0]),R=n.DataUtils.fromHalfFloat(o[4*b+1]),A=n.DataUtils.fromHalfFloat(o[4*b+2]),M=Ct(w,R,A);g+=M,d+=M,a[b]=M,c[b]=g}if(g!==0)for(let x=u*r,b=u*r+r;x<b;x++)a[x]/=g,c[x]/=g;h+=g,f[u]=g,m[u]=h}if(h!==0)for(let u=0,g=f.length;u<g;u++)f[u]/=h,m[u]/=h;const l=new Uint16Array(i),y=new Uint16Array(r*i);for(let u=0;u<i;u++){const g=(u+1)/i,x=Re(m,g);l[u]=n.DataUtils.toHalfFloat((x+.5)/i)}for(let u=0;u<i;u++)for(let g=0;g<r;g++){const x=u*r+g,b=(g+1)/r,w=Re(c,b,u*r,r);y[x]=n.DataUtils.toHalfFloat((w+.5)/r)}this.dispose();const{marginalWeights:p,conditionalWeights:v}=this;p.image={width:i,height:1,data:l},p.needsUpdate=!0,v.image={width:r,height:i,data:y},v.needsUpdate=!0,this.totalSum=d,this.map=t}}const ae=6,Pt=0,Ot=1,Nt=2,kt=3,Bt=4,F=new n.Vector3,_=new n.Vector3,Ie=new n.Matrix4,k=new n.Quaternion,Se=new n.Vector3,B=new n.Vector3,zt=new n.Vector3(0,1,0);class Ht{constructor(){const e=new n.DataTexture(new Float32Array(4),1,1);e.format=n.RGBAFormat,e.type=n.FloatType,e.wrapS=n.ClampToEdgeWrapping,e.wrapT=n.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const r=this.tex,i=Math.max(e.length*ae,1),o=Math.ceil(Math.sqrt(i));r.image.width!==o&&(r.dispose(),r.image.data=new Float32Array(o*o*4),r.image.width=o,r.image.height=o);const a=r.image.data;for(let f=0,m=e.length;f<m;f++){const d=e[f],h=f*ae*4;let l=0;for(let p=0;p<ae*4;p++)a[h+p]=0;d.getWorldPosition(_),a[h+l++]=_.x,a[h+l++]=_.y,a[h+l++]=_.z;let y=Pt;if(d.isRectAreaLight&&d.isCircular?y=Ot:d.isSpotLight?y=Nt:d.isDirectionalLight?y=kt:d.isPointLight&&(y=Bt),a[h+l++]=y,a[h+l++]=d.color.r,a[h+l++]=d.color.g,a[h+l++]=d.color.b,a[h+l++]=d.intensity,d.getWorldQuaternion(k),d.isRectAreaLight)F.set(d.width,0,0).applyQuaternion(k),a[h+l++]=F.x,a[h+l++]=F.y,a[h+l++]=F.z,l++,_.set(0,d.height,0).applyQuaternion(k),a[h+l++]=_.x,a[h+l++]=_.y,a[h+l++]=_.z,a[h+l++]=F.cross(_).length()*(d.isCircular?Math.PI/4:1);else if(d.isSpotLight){const p=d.radius||0;Se.setFromMatrixPosition(d.matrixWorld),B.setFromMatrixPosition(d.target.matrixWorld),Ie.lookAt(Se,B,zt),k.setFromRotationMatrix(Ie),F.set(1,0,0).applyQuaternion(k),a[h+l++]=F.x,a[h+l++]=F.y,a[h+l++]=F.z,l++,_.set(0,1,0).applyQuaternion(k),a[h+l++]=_.x,a[h+l++]=_.y,a[h+l++]=_.z,a[h+l++]=Math.PI*p*p,a[h+l++]=p,a[h+l++]=d.decay,a[h+l++]=d.distance,a[h+l++]=Math.cos(d.angle),a[h+l++]=Math.cos(d.angle*(1-d.penumbra)),a[h+l++]=d.iesMap?t.indexOf(d.iesMap):-1}else if(d.isPointLight){const p=F.setFromMatrixPosition(d.matrixWorld);a[h+l++]=p.x,a[h+l++]=p.y,a[h+l++]=p.z,l++,l+=4,l+=1,a[h+l++]=d.decay,a[h+l++]=d.distance}else if(d.isDirectionalLight){const p=F.setFromMatrixPosition(d.matrixWorld),v=_.setFromMatrixPosition(d.target.matrixWorld);B.subVectors(p,v).normalize(),a[h+l++]=B.x,a[h+l++]=B.y,a[h+l++]=B.z}}this.count=e.length;const c=ne(a.buffer);return this.hash!==c?(this.hash=c,r.needsUpdate=!0,!0):!1}}function _e(s,e,t,r,i){if(e>r)throw new Error;const o=s.length/e,a=s.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(s.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**a-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(a-1)-1;break}for(let f=0;f<o;f++){const m=4*f,d=e*f;for(let h=0;h<r;h++)t[i+m+h]=e>=h+1?s[d+h]/c:0}}class Wt extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const r=this._textures[e];r.updateFrom(t);const i=r.image,o=this.image;if(i.width!==o.width||i.height!==o.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:a,height:c,data:f}=o,d=a*c*4*e;let h=t.itemSize;h===3&&(h=4),_e(r.image.data,h,f,4,d),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,r=e.length;for(let h=0,l=r;h<l;h++)if(e[h].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const i=this._textures;for(;i.length<r;){const h=new We;i.push(h)}for(;i.length>r;)i.pop();for(let h=0,l=r;h<l;h++)i[h].updateFrom(e[h]);const a=i[0].image,c=this.image;(a.width!==c.width||a.height!==c.height||a.depth!==r)&&(c.width=a.width,c.height=a.height,c.depth=r,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:f,width:m,height:d}=c;for(let h=0,l=r;h<l;h++){const y=i[h],v=m*d*4*h;let u=e[h].itemSize;u===3&&(u=4),_e(y.image.data,u,f,4,v)}this.dispose(),this.needsUpdate=!0}}class Lt extends Wt{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,r,i){this.setAttributes([e,t,r,i])}}function ce(s,e){return s.uuid<e.uuid?1:s.uuid>e.uuid?-1:0}function se(s){return`${s.source.uuid}:${s.colorSpace}`}function Ut(s){const e=new Set,t=[];for(let r=0,i=s.length;r<i;r++){const o=s[r],a=se(o);e.has(a)||(e.add(a),t.push(o))}return t}function Gt(s){const e=s.map(r=>r.iesMap||null).filter(r=>r),t=new Set(e);return Array.from(t).sort(ce)}function Vt(s){const e=new Set;for(let r=0,i=s.length;r<i;r++){const o=s[r];for(const a in o){const c=o[a];c&&c.isTexture&&e.add(c)}}const t=Array.from(e);return Ut(t).sort(ce)}function qt(s){const e=[];return s.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(ce)}const qe=45,Fe=qe*4;class $t{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}}class jt extends n.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=n.RGBAFormat,this.type=n.FloatType,this.wrapS=n.ClampToEdgeWrapping,this.wrapT=n.ClampToEdgeWrapping,this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.features=new $t}updateFrom(e,t){function r(p,v,u=-1){if(v in p&&p[v]){const g=se(p[v]);return h[g]}else return u}function i(p,v,u){return v in p?p[v]:u}function o(p,v,u,g){const x=p[v]&&p[v].isTexture?p[v]:null;if(x){x.matrixAutoUpdate&&x.updateMatrix();const b=x.matrix.elements;let w=0;u[g+w++]=b[0],u[g+w++]=b[3],u[g+w++]=b[6],w++,u[g+w++]=b[1],u[g+w++]=b[4],u[g+w++]=b[7],w++}return 8}let a=0;const c=e.length*qe,f=Math.ceil(Math.sqrt(c))||1,{image:m,features:d}=this,h={};for(let p=0,v=t.length;p<v;p++)h[se(t[p])]=p;m.width!==f&&(this.dispose(),m.data=new Float32Array(f*f*4),m.width=f,m.height=f);const l=m.data;d.reset();for(let p=0,v=e.length;p<v;p++){const u=e[p];if(u.isFogVolumeMaterial){d.setUsed("FOG");for(let b=0;b<Fe;b++)l[a+b]=0;l[a+0+0]=u.color.r,l[a+0+1]=u.color.g,l[a+0+2]=u.color.b,l[a+8+3]=i(u,"emissiveIntensity",0),l[a+12+0]=u.emissive.r,l[a+12+1]=u.emissive.g,l[a+12+2]=u.emissive.b,l[a+52+1]=u.density,l[a+52+3]=0,l[a+56+2]=4,a+=Fe;continue}l[a++]=u.color.r,l[a++]=u.color.g,l[a++]=u.color.b,l[a++]=r(u,"map"),l[a++]=i(u,"metalness",0),l[a++]=r(u,"metalnessMap"),l[a++]=i(u,"roughness",0),l[a++]=r(u,"roughnessMap"),l[a++]=i(u,"ior",1.5),l[a++]=i(u,"transmission",0),l[a++]=r(u,"transmissionMap"),l[a++]=i(u,"emissiveIntensity",0),"emissive"in u?(l[a++]=u.emissive.r,l[a++]=u.emissive.g,l[a++]=u.emissive.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"emissiveMap"),l[a++]=r(u,"normalMap"),"normalScale"in u?(l[a++]=u.normalScale.x,l[a++]=u.normalScale.y):(l[a++]=1,l[a++]=1),l[a++]=i(u,"clearcoat",0),l[a++]=r(u,"clearcoatMap"),l[a++]=i(u,"clearcoatRoughness",0),l[a++]=r(u,"clearcoatRoughnessMap"),l[a++]=r(u,"clearcoatNormalMap"),"clearcoatNormalScale"in u?(l[a++]=u.clearcoatNormalScale.x,l[a++]=u.clearcoatNormalScale.y):(l[a++]=1,l[a++]=1),a++,l[a++]=i(u,"sheen",0),"sheenColor"in u?(l[a++]=u.sheenColor.r,l[a++]=u.sheenColor.g,l[a++]=u.sheenColor.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"sheenColorMap"),l[a++]=i(u,"sheenRoughness",0),l[a++]=r(u,"sheenRoughnessMap"),l[a++]=r(u,"iridescenceMap"),l[a++]=r(u,"iridescenceThicknessMap"),l[a++]=i(u,"iridescence",0),l[a++]=i(u,"iridescenceIOR",1.3);const g=i(u,"iridescenceThicknessRange",[100,400]);l[a++]=g[0],l[a++]=g[1],"specularColor"in u?(l[a++]=u.specularColor.r,l[a++]=u.specularColor.g,l[a++]=u.specularColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=r(u,"specularColorMap"),l[a++]=i(u,"specularIntensity",1),l[a++]=r(u,"specularIntensityMap");const x=i(u,"thickness",0)===0&&i(u,"attenuationDistance",1/0)===1/0;if(l[a++]=Number(x),a++,"attenuationColor"in u?(l[a++]=u.attenuationColor.r,l[a++]=u.attenuationColor.g,l[a++]=u.attenuationColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=i(u,"attenuationDistance",1/0),l[a++]=r(u,"alphaMap"),l[a++]=u.opacity,l[a++]=u.alphaTest,!x&&u.transmission>0)l[a++]=0;else switch(u.side){case n.FrontSide:l[a++]=1;break;case n.BackSide:l[a++]=-1;break;case n.DoubleSide:l[a++]=0;break}l[a++]=Number(i(u,"matte",!1)),l[a++]=Number(i(u,"castShadow",!0)),l[a++]=Number(u.vertexColors)|Number(u.flatShading)<<1,l[a++]=Number(u.transparent),a+=o(u,"map",l,a),a+=o(u,"metalnessMap",l,a),a+=o(u,"roughnessMap",l,a),a+=o(u,"transmissionMap",l,a),a+=o(u,"emissiveMap",l,a),a+=o(u,"normalMap",l,a),a+=o(u,"clearcoatMap",l,a),a+=o(u,"clearcoatNormalMap",l,a),a+=o(u,"clearcoatRoughnessMap",l,a),a+=o(u,"sheenColorMap",l,a),a+=o(u,"sheenRoughnessMap",l,a),a+=o(u,"iridescenceMap",l,a),a+=o(u,"iridescenceThicknessMap",l,a),a+=o(u,"specularColorMap",l,a),a+=o(u,"specularIntensityMap",l,a)}const y=ne(l.buffer);return this.hash!==y?(this.hash=y,this.needsUpdate=!0,!0):!1}}const Ae=new n.Color;function Yt(s){return s?`${s.uuid}:${s.version}`:null}function Qt(s,e){for(const t in e)t in s&&(s[t]=e[t])}class Me extends n.WebGLArrayRenderTarget{constructor(e,t,r){const i={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...r};super(e,t,1,i),Qt(this.texture,i),this.texture.setTextures=(...a)=>{this.setTextures(...a)},this.hashes=[null];const o=new N.FullScreenQuad(new Xt);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){const o=e.getRenderTarget(),a=e.toneMapping,c=e.getClearAlpha();e.getClearColor(Ae);const f=t.length||1;(r!==this.width||i!==this.height||this.depth!==f)&&(this.setSize(r,i,f),this.hashes=new Array(f).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;const m=this.fsQuad,d=this.hashes;let h=!1;for(let l=0,y=f;l<y;l++){const p=t[l],v=Yt(p);p&&(d[l]!==v||p.isWebGLRenderTarget)&&(p.matrixAutoUpdate=!1,p.matrix.identity(),m.material.map=p,e.setRenderTarget(this,l),m.render(e),p.updateMatrix(),p.matrixAutoUpdate=!0,d[l]=v,h=!0)}return m.material.map=null,e.setClearColor(Ae,c),e.setRenderTarget(o),e.toneMapping=a,h}dispose(){super.dispose(),this.fsQuad.dispose()}}class Xt extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
|
|
553
|
+
`})}},ye=class{generate(e,r=256){let i=new n.WebGLRenderTarget(r,r,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),a=e.getRenderTarget();e.setRenderTarget(i);let o=new t.t(new ve);return o.material.resolution.set(r,r),o.render(e),e.setRenderTarget(a),o.dispose(),i}},be=class extends n.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}},xe=class{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof be?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}};function V(e){let t=new Uint16Array(e.length);for(let r=0,i=e.length;r<i;++r)t[r]=n.DataUtils.toHalfFloat(e[r]);return t}function H(e,t,n=0,r=e.length){let i=n,a=n+r-1;for(;i<a;){let n=i+a>>1;e[n]<t?i=n+1:a=n}return i-n}function Se(e,t,n){return .2126*e+.7152*t+.0722*n}function Ce(e,t=n.HalfFloatType){let r=e.clone();r.source=new n.Source({...r.image});let{width:i,height:a,data:o}=r.image,s=o;if(r.type!==t){s=t===n.HalfFloatType?new Uint16Array(o.length):new Float32Array(o.length);let e;e=o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?2**(8*o.BYTES_PER_ELEMENT-1)-1:2**(8*o.BYTES_PER_ELEMENT)-1;for(let i=0,a=o.length;i<a;i++){let a=o[i];r.type===n.HalfFloatType&&(a=n.DataUtils.fromHalfFloat(o[i])),r.type!==n.FloatType&&r.type!==n.HalfFloatType&&(a/=e),t===n.HalfFloatType&&(s[i]=n.DataUtils.toHalfFloat(a))}r.image.data=s,r.type=t}if(r.flipY){let e=s;s=s.slice();for(let t=0;t<a;t++)for(let n=0;n<i;n++){let r=a-t-1,o=4*(t*i+n),c=4*(r*i+n);s[c+0]=e[o+0],s[c+1]=e[o+1],s[c+2]=e[o+2],s[c+3]=e[o+3]}r.flipY=!1,r.image.data=s}return r}var we=class{constructor(){let e=new n.DataTexture(V(new Float32Array([0,0,0,0])),1,1);e.type=n.HalfFloatType,e.format=n.RGBAFormat,e.minFilter=n.LinearFilter,e.magFilter=n.LinearFilter,e.wrapS=n.RepeatWrapping,e.wrapT=n.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;let t=new n.DataTexture(V(new Float32Array([0,1])),1,2);t.type=n.HalfFloatType,t.format=n.RedFormat,t.minFilter=n.LinearFilter,t.magFilter=n.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;let r=new n.DataTexture(V(new Float32Array([0,0,1,1])),2,2);r.type=n.HalfFloatType,r.format=n.RedFormat,r.minFilter=n.LinearFilter,r.magFilter=n.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){let t=Ce(e);t.wrapS=n.RepeatWrapping,t.wrapT=n.ClampToEdgeWrapping;let{width:r,height:i,data:a}=t.image,o=new Float32Array(r*i),s=new Float32Array(r*i),c=new Float32Array(i),l=new Float32Array(i),u=0,d=0;for(let e=0;e<i;e++){let t=0;for(let i=0;i<r;i++){let c=e*r+i,l=Se(n.DataUtils.fromHalfFloat(a[4*c+0]),n.DataUtils.fromHalfFloat(a[4*c+1]),n.DataUtils.fromHalfFloat(a[4*c+2]));t+=l,u+=l,o[c]=l,s[c]=t}if(t!==0)for(let n=e*r,i=e*r+r;n<i;n++)o[n]/=t,s[n]/=t;d+=t,c[e]=t,l[e]=d}if(d!==0)for(let e=0,t=c.length;e<t;e++)c[e]/=d,l[e]/=d;let f=new Uint16Array(i),p=new Uint16Array(r*i);for(let e=0;e<i;e++){let t=H(l,(e+1)/i);f[e]=n.DataUtils.toHalfFloat((t+.5)/i)}for(let e=0;e<i;e++)for(let t=0;t<r;t++){let i=e*r+t,a=H(s,(t+1)/r,e*r,r);p[i]=n.DataUtils.toHalfFloat((a+.5)/r)}this.dispose();let{marginalWeights:m,conditionalWeights:h}=this;m.image={width:i,height:1,data:f},m.needsUpdate=!0,h.image={width:r,height:i,data:p},h.needsUpdate=!0,this.totalSum=u,this.map=t}},U=6,Te=0,Ee=1,De=2,Oe=3,ke=4,W=new n.Vector3,G=new n.Vector3,Ae=new n.Matrix4,K=new n.Quaternion,je=new n.Vector3,q=new n.Vector3,Me=new n.Vector3(0,1,0),Ne=class{constructor(){let e=new n.DataTexture(new Float32Array(4),1,1);e.format=n.RGBAFormat,e.type=n.FloatType,e.wrapS=n.ClampToEdgeWrapping,e.wrapT=n.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){let n=this.tex,r=Math.max(e.length*U,1),i=Math.ceil(Math.sqrt(r));n.image.width!==i&&(n.dispose(),n.image.data=new Float32Array(i*i*4),n.image.width=i,n.image.height=i);let a=n.image.data;for(let n=0,r=e.length;n<r;n++){let r=e[n],i=n*U*4,o=0;for(let e=0;e<U*4;e++)a[i+e]=0;r.getWorldPosition(G),a[i+o++]=G.x,a[i+o++]=G.y,a[i+o++]=G.z;let s=Te;if(r.isRectAreaLight&&r.isCircular?s=Ee:r.isSpotLight?s=De:r.isDirectionalLight?s=Oe:r.isPointLight&&(s=ke),a[i+o++]=s,a[i+o++]=r.color.r,a[i+o++]=r.color.g,a[i+o++]=r.color.b,a[i+o++]=r.intensity,r.getWorldQuaternion(K),r.isRectAreaLight)W.set(r.width,0,0).applyQuaternion(K),a[i+o++]=W.x,a[i+o++]=W.y,a[i+o++]=W.z,o++,G.set(0,r.height,0).applyQuaternion(K),a[i+o++]=G.x,a[i+o++]=G.y,a[i+o++]=G.z,a[i+o++]=W.cross(G).length()*(r.isCircular?Math.PI/4:1);else if(r.isSpotLight){let e=r.radius||0;je.setFromMatrixPosition(r.matrixWorld),q.setFromMatrixPosition(r.target.matrixWorld),Ae.lookAt(je,q,Me),K.setFromRotationMatrix(Ae),W.set(1,0,0).applyQuaternion(K),a[i+o++]=W.x,a[i+o++]=W.y,a[i+o++]=W.z,o++,G.set(0,1,0).applyQuaternion(K),a[i+o++]=G.x,a[i+o++]=G.y,a[i+o++]=G.z,a[i+o++]=Math.PI*e*e,a[i+o++]=e,a[i+o++]=r.decay,a[i+o++]=r.distance,a[i+o++]=Math.cos(r.angle),a[i+o++]=Math.cos(r.angle*(1-r.penumbra)),a[i+o++]=r.iesMap?t.indexOf(r.iesMap):-1}else if(r.isPointLight){let e=W.setFromMatrixPosition(r.matrixWorld);a[i+o++]=e.x,a[i+o++]=e.y,a[i+o++]=e.z,o++,o+=4,o+=1,a[i+o++]=r.decay,a[i+o++]=r.distance}else if(r.isDirectionalLight){let e=W.setFromMatrixPosition(r.matrixWorld),t=G.setFromMatrixPosition(r.target.matrixWorld);q.subVectors(e,t).normalize(),a[i+o++]=q.x,a[i+o++]=q.y,a[i+o++]=q.z}}this.count=e.length;let o=T(a.buffer);return this.hash===o?!1:(this.hash=o,n.needsUpdate=!0,!0)}};function Pe(e,t,n,r,i){if(t>r)throw Error();let a=e.length/t,o=e.constructor.BYTES_PER_ELEMENT*8,s=1;switch(e.constructor){case Uint8Array:case Uint16Array:case Uint32Array:s=2**o-1;break;case Int8Array:case Int16Array:case Int32Array:s=2**(o-1)-1;break}for(let o=0;o<a;o++){let a=4*o,c=t*o;for(let o=0;o<r;o++)n[i+a+o]=t>=o+1?e[c+o]/s:0}}var Fe=class extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat=`RGBA32F`}updateAttribute(e,t){let n=this._textures[e];n.updateFrom(t);let r=n.image,i=this.image;if(r.width!==i.width||r.height!==i.height)throw Error(`FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.`);let{width:a,height:o,data:s}=i,c=a*o*4*e,l=t.itemSize;l===3&&(l=4),Pe(n.image.data,l,s,4,c),this.dispose(),this.needsUpdate=!0}setAttributes(e){let t=e[0].count,n=e.length;for(let r=0,i=n;r<i;r++)if(e[r].count!==t)throw Error(`FloatAttributeTextureArray: All attributes must have the same item count.`);let r=this._textures;for(;r.length<n;){let e=new c;r.push(e)}for(;r.length>n;)r.pop();for(let t=0,i=n;t<i;t++)r[t].updateFrom(e[t]);let i=r[0].image,a=this.image;(i.width!==a.width||i.height!==a.height||i.depth!==n)&&(a.width=i.width,a.height=i.height,a.depth=n,a.data=new Float32Array(a.width*a.height*a.depth*4));let{data:o,width:s,height:l}=a;for(let t=0,i=n;t<i;t++){let n=r[t],i=s*l*4*t,a=e[t].itemSize;a===3&&(a=4),Pe(n.image.data,a,o,4,i)}this.dispose(),this.needsUpdate=!0}},Ie=class extends Fe{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,n,r){this.setAttributes([e,t,n,r])}};function J(e,t){return e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0}function Y(e){return`${e.source.uuid}:${e.colorSpace}`}function Le(e){let t=new Set,n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=Y(i);t.has(a)||(t.add(a),n.push(i))}return n}function Re(e){let t=e.map(e=>e.iesMap||null).filter(e=>e),n=new Set(t);return Array.from(n).sort(J)}function ze(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return Le(Array.from(t)).sort(J)}function Be(e){let t=[];return e.traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&t.push(e)}),t.sort(J)}var Ve=45,He=Ve*4,Ue=class{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}},We=class extends n.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=n.RGBAFormat,this.type=n.FloatType,this.wrapS=n.ClampToEdgeWrapping,this.wrapT=n.ClampToEdgeWrapping,this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.features=new Ue}updateFrom(e,t){function r(e,t,n=-1){if(t in e&&e[t]){let n=Y(e[t]);return d[n]}else return n}function i(e,t,n){return t in e?e[t]:n}function a(e,t,n,r){let i=e[t]&&e[t].isTexture?e[t]:null;if(i){i.matrixAutoUpdate&&i.updateMatrix();let e=i.matrix.elements,t=0;n[r+t++]=e[0],n[r+t++]=e[3],n[r+t++]=e[6],t++,n[r+t++]=e[1],n[r+t++]=e[4],n[r+t++]=e[7],t++}return 8}let o=0,s=e.length*Ve,c=Math.ceil(Math.sqrt(s))||1,{image:l,features:u}=this,d={};for(let e=0,n=t.length;e<n;e++)d[Y(t[e])]=e;l.width!==c&&(this.dispose(),l.data=new Float32Array(c*c*4),l.width=c,l.height=c);let f=l.data;u.reset();for(let t=0,s=e.length;t<s;t++){let s=e[t];if(s.isFogVolumeMaterial){u.setUsed(`FOG`);for(let e=0;e<He;e++)f[o+e]=0;f[o+0+0]=s.color.r,f[o+0+1]=s.color.g,f[o+0+2]=s.color.b,f[o+8+3]=i(s,`emissiveIntensity`,0),f[o+12+0]=s.emissive.r,f[o+12+1]=s.emissive.g,f[o+12+2]=s.emissive.b,f[o+52+1]=s.density,f[o+52+3]=0,f[o+56+2]=4,o+=He;continue}f[o++]=s.color.r,f[o++]=s.color.g,f[o++]=s.color.b,f[o++]=r(s,`map`),f[o++]=i(s,`metalness`,0),f[o++]=r(s,`metalnessMap`),f[o++]=i(s,`roughness`,0),f[o++]=r(s,`roughnessMap`),f[o++]=i(s,`ior`,1.5),f[o++]=i(s,`transmission`,0),f[o++]=r(s,`transmissionMap`),f[o++]=i(s,`emissiveIntensity`,0),`emissive`in s?(f[o++]=s.emissive.r,f[o++]=s.emissive.g,f[o++]=s.emissive.b):(f[o++]=0,f[o++]=0,f[o++]=0),f[o++]=r(s,`emissiveMap`),f[o++]=r(s,`normalMap`),`normalScale`in s?(f[o++]=s.normalScale.x,f[o++]=s.normalScale.y):(f[o++]=1,f[o++]=1),f[o++]=i(s,`clearcoat`,0),f[o++]=r(s,`clearcoatMap`),f[o++]=i(s,`clearcoatRoughness`,0),f[o++]=r(s,`clearcoatRoughnessMap`),f[o++]=r(s,`clearcoatNormalMap`),`clearcoatNormalScale`in s?(f[o++]=s.clearcoatNormalScale.x,f[o++]=s.clearcoatNormalScale.y):(f[o++]=1,f[o++]=1),o++,f[o++]=i(s,`sheen`,0),`sheenColor`in s?(f[o++]=s.sheenColor.r,f[o++]=s.sheenColor.g,f[o++]=s.sheenColor.b):(f[o++]=0,f[o++]=0,f[o++]=0),f[o++]=r(s,`sheenColorMap`),f[o++]=i(s,`sheenRoughness`,0),f[o++]=r(s,`sheenRoughnessMap`),f[o++]=r(s,`iridescenceMap`),f[o++]=r(s,`iridescenceThicknessMap`),f[o++]=i(s,`iridescence`,0),f[o++]=i(s,`iridescenceIOR`,1.3);let c=i(s,`iridescenceThicknessRange`,[100,400]);f[o++]=c[0],f[o++]=c[1],`specularColor`in s?(f[o++]=s.specularColor.r,f[o++]=s.specularColor.g,f[o++]=s.specularColor.b):(f[o++]=1,f[o++]=1,f[o++]=1),f[o++]=r(s,`specularColorMap`),f[o++]=i(s,`specularIntensity`,1),f[o++]=r(s,`specularIntensityMap`);let l=i(s,`thickness`,0)===0&&i(s,`attenuationDistance`,1/0)===1/0;if(f[o++]=Number(l),o++,`attenuationColor`in s?(f[o++]=s.attenuationColor.r,f[o++]=s.attenuationColor.g,f[o++]=s.attenuationColor.b):(f[o++]=1,f[o++]=1,f[o++]=1),f[o++]=i(s,`attenuationDistance`,1/0),f[o++]=r(s,`alphaMap`),f[o++]=s.opacity,f[o++]=s.alphaTest,!l&&s.transmission>0)f[o++]=0;else switch(s.side){case n.FrontSide:f[o++]=1;break;case n.BackSide:f[o++]=-1;break;case n.DoubleSide:f[o++]=0;break}f[o++]=Number(i(s,`matte`,!1)),f[o++]=Number(i(s,`castShadow`,!0)),f[o++]=Number(s.vertexColors)|Number(s.flatShading)<<1,f[o++]=Number(s.transparent),o+=a(s,`map`,f,o),o+=a(s,`metalnessMap`,f,o),o+=a(s,`roughnessMap`,f,o),o+=a(s,`transmissionMap`,f,o),o+=a(s,`emissiveMap`,f,o),o+=a(s,`normalMap`,f,o),o+=a(s,`clearcoatMap`,f,o),o+=a(s,`clearcoatNormalMap`,f,o),o+=a(s,`clearcoatRoughnessMap`,f,o),o+=a(s,`sheenColorMap`,f,o),o+=a(s,`sheenRoughnessMap`,f,o),o+=a(s,`iridescenceMap`,f,o),o+=a(s,`iridescenceThicknessMap`,f,o),o+=a(s,`specularColorMap`,f,o),o+=a(s,`specularIntensityMap`,f,o)}let p=T(f.buffer);return this.hash===p?!1:(this.hash=p,this.needsUpdate=!0,!0)}},Ge=new n.Color;function Ke(e){return e?`${e.uuid}:${e.version}`:null}function qe(e,t){for(let n in t)n in e&&(e[n]=t[n])}var Je=class extends n.WebGLArrayRenderTarget{constructor(e,r,i){let a={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...i};super(e,r,1,a),qe(this.texture,a),this.texture.setTextures=(...e)=>{this.setTextures(...e)},this.hashes=[null];let o=new t.t(new Ye);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){let a=e.getRenderTarget(),o=e.toneMapping,s=e.getClearAlpha();e.getClearColor(Ge);let c=t.length||1;(r!==this.width||i!==this.height||this.depth!==c)&&(this.setSize(r,i,c),this.hashes=Array(c).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;let l=this.fsQuad,u=this.hashes,d=!1;for(let n=0,r=c;n<r;n++){let r=t[n],i=Ke(r);r&&(u[n]!==i||r.isWebGLRenderTarget)&&(r.matrixAutoUpdate=!1,r.matrix.identity(),l.material.map=r,e.setRenderTarget(this,n),l.render(e),r.updateMatrix(),r.matrixAutoUpdate=!0,u[n]=i,d=!0)}return l.material.map=null,e.setClearColor(Ge,s),e.setRenderTarget(a),e.toneMapping=o,d}dispose(){super.dispose(),this.fsQuad.dispose()}},Ye=class extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
|
|
554
554
|
varying vec2 vUv;
|
|
555
555
|
void main() {
|
|
556
556
|
|
|
@@ -566,7 +566,7 @@ struct BVH {
|
|
|
566
566
|
gl_FragColor = texture2D( map, vUv );
|
|
567
567
|
|
|
568
568
|
}
|
|
569
|
-
`})}}function
|
|
569
|
+
`})}};function Xe(e,t=Math.random()){for(let n=e.length-1;n>0;n--){let r=Math.floor(t()*(n+1)),i=e[n];e[n]=e[r],e[r]=i}return e}var Ze=class{constructor(e,t,n=Math.random){let r=e**t,i=new Uint16Array(r),a=r;for(let e=0;e<r;e++)i[e]=e;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let e=0;e<r;e++)i[e]=e;a=0},this.reshuffle=function(){a=0},this.next=function(){let{samples:r}=this;a>=i.length&&(Xe(i,n),this.reshuffle());let o=i[a++];for(let i=0;i<t;i++)r[i]=(o%e+n())/e,o=Math.floor(o/e);return r}}},Qe=class{constructor(e,t,n=Math.random){let r=0;for(let e of t)r+=e;let i=new Float32Array(r),a=[],o=0;for(let r of t){let t=new Ze(e,r,n);t.samples=new Float32Array(i.buffer,o,t.samples.length),o+=t.samples.length*4,a.push(t)}this.samples=i,this.strataCount=e,this.next=function(){for(let e of a)e.next();return i},this.reshuffle=function(){for(let e of a)e.reshuffle()},this.reset=function(){for(let e of a)e.reset()}}},$e=class{constructor(e=0){this.m=2147483648,this.a=1103515245,this.c=12345,this.seed=e}nextInt(){return this.seed=(this.a*this.seed+this.c)%this.m,this.seed}nextFloat(){return this.nextInt()/(this.m-1)}},et=class extends n.DataTexture{constructor(e=1,t=1,r=8){super(new Float32Array(1),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.strata=r,this.sampler=null,this.generator=new $e,this.stableNoise=!1,this.random=()=>this.stableNoise?this.generator.nextFloat():Math.random(),this.init(e,t,r)}init(e=this.image.height,t=this.image.width,n=this.strata){let{image:r}=this;if(r.width===t&&r.height===e&&this.sampler!==null)return;let i=new Qe(n,Array(e*t).fill(4),this.random);r.width=t,r.height=e,r.data=i.samples,this.sampler=i,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}};function tt(e,t=Math.random){for(let n=e.length-1;n>0;n--){let r=~~((t()-1e-6)*n),i=e[n];e[n]=e[r],e[r]=i}}function nt(e,t){e.fill(0);for(let n=0;n<t;n++)e[n]=1}var rt=class{constructor(e){this.count=0,this.size=-1,this.sigma=-1,this.radius=-1,this.lookupTable=null,this.score=null,this.binaryPattern=null,this.resize(e),this.setSigma(1.5)}findVoid(){let{score:e,binaryPattern:t}=this,n=1/0,r=-1;for(let i=0,a=t.length;i<a;i++){if(t[i]!==0)continue;let a=e[i];a<n&&(n=a,r=i)}return r}findCluster(){let{score:e,binaryPattern:t}=this,n=-1/0,r=-1;for(let i=0,a=t.length;i<a;i++){if(t[i]!==1)continue;let a=e[i];a>n&&(n=a,r=i)}return r}setSigma(e){if(e===this.sigma)return;let t=~~(Math.sqrt(20*e**2)+1),n=2*t+1,r=new Float32Array(n*n),i=e*e;for(let e=-t;e<=t;e++)for(let a=-t;a<=t;a++){let o=(t+a)*n+e+t,s=e*e+a*a;r[o]=Math.E**(-s/(2*i))}this.lookupTable=r,this.sigma=e,this.radius=t}resize(e){this.size!==e&&(this.size=e,this.score=new Float32Array(e*e),this.binaryPattern=new Uint8Array(e*e))}invert(){let{binaryPattern:e,score:t,size:n}=this;t.fill(0);for(let t=0,r=e.length;t<r;t++)if(e[t]===0){let r=~~(t/n),i=t-r*n;this.updateScore(i,r,1),e[t]=1}else e[t]=0}updateScore(e,t,n){let{size:r,score:i,lookupTable:a}=this,o=this.radius,s=2*o+1;for(let c=-o;c<=o;c++)for(let l=-o;l<=o;l++){let u=a[(o+l)*s+c+o],d=e+c;d=d<0?r+d:d%r;let f=t+l;f=f<0?r+f:f%r;let p=f*r+d;i[p]+=n*u}}addPointIndex(e){this.binaryPattern[e]=1;let t=this.size,n=~~(e/t),r=e-n*t;this.updateScore(r,n,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;let t=this.size,n=~~(e/t),r=e-n*t;this.updateScore(r,n,-1),this.count--}copy(e){this.resize(e.size),this.score.set(e.score),this.binaryPattern.set(e.binaryPattern),this.setSigma(e.sigma),this.count=e.count}},it=class{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new rt(1),this.savedSamples=new rt(1)}generate(){let{samples:e,savedSamples:t,sigma:n,majorityPointsRatio:r,size:i}=this;e.resize(i),e.setSigma(n);let a=Math.floor(i*i*r),o=e.binaryPattern;nt(o,a),tt(o,this.random);for(let t=0,n=o.length;t<n;t++)o[t]===1&&e.addPointIndex(t);for(;;){let t=e.findCluster();e.removePointIndex(t);let n=e.findVoid();if(t===n){e.addPointIndex(t);break}e.addPointIndex(n)}let s=new Uint32Array(i*i);t.copy(e);let c;for(c=e.count-1;c>=0;){let t=e.findCluster();e.removePointIndex(t),s[t]=c,c--}let l=i*i;for(c=t.count;c<l/2;){let e=t.findVoid();t.addPointIndex(e),s[e]=c,c++}for(t.invert();c<l;){let e=t.findCluster();t.removePointIndex(e),s[e]=c,c++}return{data:s,maxValue:l}}};function at(e){return e>=3?4:e}function ot(e){switch(e){case 1:return n.RedFormat;case 2:return n.RGFormat;default:return n.RGBAFormat}}var st=class extends n.DataTexture{constructor(e=64,t=1){super(new Float32Array(4),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.size=e,this.channels=t,this.update()}update(){let e=this.channels,t=this.size,n=new it;n.channels=e,n.size=t;let r=at(e),i=ot(r);(this.image.width!==t||i!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*r),this.format=i,this.dispose());let a=this.image.data;for(let t=0,i=e;t<i;t++){let e=n.generate(),i=e.data,o=e.maxValue;for(let e=0,n=i.length;e<n;e++){let n=i[e]/o;a[e*r+t]=n}}this.needsUpdate=!0}},ct=`
|
|
570
570
|
|
|
571
571
|
struct PhysicalCamera {
|
|
572
572
|
|
|
@@ -578,7 +578,7 @@ struct BVH {
|
|
|
578
578
|
|
|
579
579
|
};
|
|
580
580
|
|
|
581
|
-
`,
|
|
581
|
+
`,lt=`
|
|
582
582
|
|
|
583
583
|
struct EquirectHdrInfo {
|
|
584
584
|
|
|
@@ -590,7 +590,7 @@ struct BVH {
|
|
|
590
590
|
|
|
591
591
|
};
|
|
592
592
|
|
|
593
|
-
`,
|
|
593
|
+
`,ut=`
|
|
594
594
|
|
|
595
595
|
#define RECT_AREA_LIGHT_TYPE 0
|
|
596
596
|
#define CIRC_AREA_LIGHT_TYPE 1
|
|
@@ -676,7 +676,7 @@ struct BVH {
|
|
|
676
676
|
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
-
`,
|
|
679
|
+
`,dt=`
|
|
680
680
|
|
|
681
681
|
struct Material {
|
|
682
682
|
|
|
@@ -883,7 +883,7 @@ struct BVH {
|
|
|
883
883
|
|
|
884
884
|
}
|
|
885
885
|
|
|
886
|
-
`,
|
|
886
|
+
`,ft=`
|
|
887
887
|
|
|
888
888
|
struct SurfaceRecord {
|
|
889
889
|
|
|
@@ -945,7 +945,7 @@ struct BVH {
|
|
|
945
945
|
vec3 color;
|
|
946
946
|
};
|
|
947
947
|
|
|
948
|
-
`,
|
|
948
|
+
`,pt=`
|
|
949
949
|
|
|
950
950
|
// samples the the given environment map in the given direction
|
|
951
951
|
vec3 sampleEquirectColor( sampler2D envMap, vec3 direction ) {
|
|
@@ -1012,7 +1012,7 @@ struct BVH {
|
|
|
1012
1012
|
return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
|
|
1013
1013
|
|
|
1014
1014
|
}
|
|
1015
|
-
`,
|
|
1015
|
+
`,mt=`
|
|
1016
1016
|
|
|
1017
1017
|
float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
|
|
1018
1018
|
|
|
@@ -1227,7 +1227,7 @@ struct BVH {
|
|
|
1227
1227
|
|
|
1228
1228
|
}
|
|
1229
1229
|
|
|
1230
|
-
`,
|
|
1230
|
+
`,ht=`
|
|
1231
1231
|
|
|
1232
1232
|
vec3 sampleHemisphere( vec3 n, vec2 uv ) {
|
|
1233
1233
|
|
|
@@ -1312,7 +1312,7 @@ struct BVH {
|
|
|
1312
1312
|
}
|
|
1313
1313
|
|
|
1314
1314
|
|
|
1315
|
-
`,
|
|
1315
|
+
`,gt=`
|
|
1316
1316
|
|
|
1317
1317
|
bool totalInternalReflection( float cosTheta, float eta ) {
|
|
1318
1318
|
|
|
@@ -1415,7 +1415,7 @@ struct BVH {
|
|
|
1415
1415
|
|
|
1416
1416
|
}
|
|
1417
1417
|
|
|
1418
|
-
`,
|
|
1418
|
+
`,_t=`
|
|
1419
1419
|
|
|
1420
1420
|
// Fast arccos approximation used to remove banding artifacts caused by numerical errors in acos.
|
|
1421
1421
|
// This is a cubic Lagrange interpolating polynomial for x = [-1, -1/2, 0, 1/2, 1].
|
|
@@ -1495,7 +1495,7 @@ struct BVH {
|
|
|
1495
1495
|
|
|
1496
1496
|
}
|
|
1497
1497
|
|
|
1498
|
-
`,
|
|
1498
|
+
`,vt=`
|
|
1499
1499
|
|
|
1500
1500
|
// Finds the point where the ray intersects the plane defined by u and v and checks if this point
|
|
1501
1501
|
// falls in the bounds of the rectangle on that same plane.
|
|
@@ -1556,7 +1556,7 @@ struct BVH {
|
|
|
1556
1556
|
|
|
1557
1557
|
}
|
|
1558
1558
|
|
|
1559
|
-
`,
|
|
1559
|
+
`,yt=`
|
|
1560
1560
|
|
|
1561
1561
|
// add texel fetch functions for texture arrays
|
|
1562
1562
|
vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
|
|
@@ -1579,7 +1579,7 @@ struct BVH {
|
|
|
1579
1579
|
|
|
1580
1580
|
}
|
|
1581
1581
|
|
|
1582
|
-
|
|
1582
|
+
`,bt=`
|
|
1583
1583
|
|
|
1584
1584
|
// TODO: possibly this should be renamed something related to material or path tracing logic
|
|
1585
1585
|
|
|
@@ -1694,7 +1694,7 @@ struct BVH {
|
|
|
1694
1694
|
return x < 0.5 ? sqrt( 2.0 * x ) - 1.0 : 1.0 - sqrt( 2.0 - ( 2.0 * x ) );
|
|
1695
1695
|
|
|
1696
1696
|
}
|
|
1697
|
-
`,
|
|
1697
|
+
`,xt=`
|
|
1698
1698
|
|
|
1699
1699
|
// https://www.shadertoy.com/view/wltcRS
|
|
1700
1700
|
uvec4 WHITE_NOISE_SEED;
|
|
@@ -1750,7 +1750,7 @@ struct BVH {
|
|
|
1750
1750
|
return vec4( WHITE_NOISE_SEED ) / float( 0xffffffffu );
|
|
1751
1751
|
|
|
1752
1752
|
}
|
|
1753
|
-
`,
|
|
1753
|
+
`,St=`
|
|
1754
1754
|
|
|
1755
1755
|
uniform sampler2D stratifiedTexture;
|
|
1756
1756
|
uniform sampler2D stratifiedOffsetTexture;
|
|
@@ -1799,7 +1799,7 @@ struct BVH {
|
|
|
1799
1799
|
|
|
1800
1800
|
}
|
|
1801
1801
|
|
|
1802
|
-
`,
|
|
1802
|
+
`,Ct=`
|
|
1803
1803
|
|
|
1804
1804
|
// diffuse
|
|
1805
1805
|
float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) {
|
|
@@ -2237,7 +2237,7 @@ struct BVH {
|
|
|
2237
2237
|
|
|
2238
2238
|
}
|
|
2239
2239
|
|
|
2240
|
-
`,
|
|
2240
|
+
`,wt=`
|
|
2241
2241
|
|
|
2242
2242
|
// returns the hit distance given the material density
|
|
2243
2243
|
float intersectFogVolume( Material material, float u ) {
|
|
@@ -2258,7 +2258,7 @@ struct BVH {
|
|
|
2258
2258
|
|
|
2259
2259
|
}
|
|
2260
2260
|
|
|
2261
|
-
`,
|
|
2261
|
+
`,Tt=`
|
|
2262
2262
|
|
|
2263
2263
|
// The GGX functions provide sampling and distribution information for normals as output so
|
|
2264
2264
|
// in order to get probability of scatter direction the half vector must be computed and provided.
|
|
@@ -2359,7 +2359,7 @@ struct BVH {
|
|
|
2359
2359
|
|
|
2360
2360
|
}
|
|
2361
2361
|
|
|
2362
|
-
`,
|
|
2362
|
+
`,Et=`
|
|
2363
2363
|
|
|
2364
2364
|
// XYZ to sRGB color space
|
|
2365
2365
|
const mat3 XYZ_TO_REC709 = mat3(
|
|
@@ -2493,7 +2493,7 @@ struct BVH {
|
|
|
2493
2493
|
|
|
2494
2494
|
}
|
|
2495
2495
|
|
|
2496
|
-
`,
|
|
2496
|
+
`,Dt=`
|
|
2497
2497
|
|
|
2498
2498
|
// See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
2499
2499
|
float velvetD( float cosThetaH, float roughness ) {
|
|
@@ -2590,7 +2590,7 @@ struct BVH {
|
|
|
2590
2590
|
|
|
2591
2591
|
}
|
|
2592
2592
|
|
|
2593
|
-
`,
|
|
2593
|
+
`,Ot=`
|
|
2594
2594
|
|
|
2595
2595
|
#ifndef FOG_CHECK_ITERATIONS
|
|
2596
2596
|
#define FOG_CHECK_ITERATIONS 30
|
|
@@ -2651,7 +2651,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2651
2651
|
|
|
2652
2652
|
}
|
|
2653
2653
|
|
|
2654
|
-
`,
|
|
2654
|
+
`,kt=`
|
|
2655
2655
|
|
|
2656
2656
|
// step through multiple surface hits and accumulate color attenuation based on transmissive surfaces
|
|
2657
2657
|
// returns true if a solid surface was hit
|
|
@@ -2828,7 +2828,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2828
2828
|
|
|
2829
2829
|
}
|
|
2830
2830
|
|
|
2831
|
-
`,
|
|
2831
|
+
`,At=`
|
|
2832
2832
|
|
|
2833
2833
|
vec3 ndcToRayOrigin( vec2 coord ) {
|
|
2834
2834
|
|
|
@@ -2911,7 +2911,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2911
2911
|
|
|
2912
2912
|
}
|
|
2913
2913
|
|
|
2914
|
-
`,
|
|
2914
|
+
`,jt=`
|
|
2915
2915
|
|
|
2916
2916
|
vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) {
|
|
2917
2917
|
|
|
@@ -3007,7 +3007,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3007
3007
|
|
|
3008
3008
|
}
|
|
3009
3009
|
|
|
3010
|
-
`,
|
|
3010
|
+
`,Mt=`
|
|
3011
3011
|
|
|
3012
3012
|
#define SKIP_SURFACE 0
|
|
3013
3013
|
#define HIT_SURFACE 1
|
|
@@ -3329,7 +3329,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3329
3329
|
return HIT_SURFACE;
|
|
3330
3330
|
|
|
3331
3331
|
}
|
|
3332
|
-
`,
|
|
3332
|
+
`,Nt=`
|
|
3333
3333
|
|
|
3334
3334
|
struct Ray {
|
|
3335
3335
|
|
|
@@ -3378,7 +3378,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3378
3378
|
|
|
3379
3379
|
}
|
|
3380
3380
|
|
|
3381
|
-
`,
|
|
3381
|
+
`,Pt=`
|
|
3382
3382
|
|
|
3383
3383
|
#define NO_HIT 0
|
|
3384
3384
|
#define SURFACE_HIT 1
|
|
@@ -3425,7 +3425,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3425
3425
|
|
|
3426
3426
|
}
|
|
3427
3427
|
|
|
3428
|
-
|
|
3428
|
+
`,Ft=class extends R{onBeforeRender(){this.setDefine(`FEATURE_DOF`,this.physicalCamera.bokehSize===0?0:1),this.setDefine(`FEATURE_BACKGROUND_MAP`,+!!this.backgroundMap),this.setDefine(`FEATURE_FOG`,+!!this.materials.features.isUsed(`FOG`))}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new n.Vector2},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new xe},cameraWorldMatrix:{value:new n.Matrix4},invProjectionMatrix:{value:new n.Matrix4},bvh:{value:new l},attributesArray:{value:new Ie},materialIndexAttribute:{value:new s},materials:{value:new We},textures:{value:new Je().texture},lights:{value:new Ne},iesProfiles:{value:new Je(360,180,{type:n.HalfFloatType,wrapS:n.ClampToEdgeWrapping,wrapT:n.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new n.Matrix4},envMapInfo:{value:new we},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new n.Matrix4},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new et},stratifiedOffsetTexture:{value:new st(64,1)}},vertexShader:`
|
|
3429
3429
|
|
|
3430
3430
|
varying vec2 vUv;
|
|
3431
3431
|
void main() {
|
|
@@ -3449,27 +3449,27 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3449
3449
|
#include <common>
|
|
3450
3450
|
|
|
3451
3451
|
// bvh intersection
|
|
3452
|
-
${
|
|
3453
|
-
${
|
|
3454
|
-
${
|
|
3452
|
+
${f}
|
|
3453
|
+
${m}
|
|
3454
|
+
${p}
|
|
3455
3455
|
|
|
3456
3456
|
// uniform structs
|
|
3457
|
-
${
|
|
3458
|
-
${
|
|
3459
|
-
${
|
|
3460
|
-
${
|
|
3461
|
-
${
|
|
3457
|
+
${ct}
|
|
3458
|
+
${ut}
|
|
3459
|
+
${lt}
|
|
3460
|
+
${dt}
|
|
3461
|
+
${ft}
|
|
3462
3462
|
|
|
3463
3463
|
// random
|
|
3464
3464
|
#if RANDOM_TYPE == 2 // Stratified List
|
|
3465
3465
|
|
|
3466
|
-
${
|
|
3466
|
+
${St}
|
|
3467
3467
|
|
|
3468
3468
|
#elif RANDOM_TYPE == 1 // Sobol
|
|
3469
3469
|
|
|
3470
|
-
${
|
|
3471
|
-
${
|
|
3472
|
-
${
|
|
3470
|
+
${xt}
|
|
3471
|
+
${he}
|
|
3472
|
+
${_e}
|
|
3473
3473
|
|
|
3474
3474
|
#define rand(v) sobol(v)
|
|
3475
3475
|
#define rand2(v) sobol2(v)
|
|
@@ -3478,7 +3478,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3478
3478
|
|
|
3479
3479
|
#else // PCG
|
|
3480
3480
|
|
|
3481
|
-
${
|
|
3481
|
+
${xt}
|
|
3482
3482
|
|
|
3483
3483
|
// Using the sobol functions seems to break the the compiler on MacOS
|
|
3484
3484
|
// - specifically the "sobolReverseBits" function.
|
|
@@ -3494,11 +3494,11 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3494
3494
|
#endif
|
|
3495
3495
|
|
|
3496
3496
|
// common
|
|
3497
|
-
${
|
|
3498
|
-
${
|
|
3499
|
-
${
|
|
3500
|
-
${
|
|
3501
|
-
${
|
|
3497
|
+
${yt}
|
|
3498
|
+
${gt}
|
|
3499
|
+
${bt}
|
|
3500
|
+
${_t}
|
|
3501
|
+
${vt}
|
|
3502
3502
|
|
|
3503
3503
|
// environment
|
|
3504
3504
|
uniform EquirectHdrInfo envMapInfo;
|
|
@@ -3554,16 +3554,16 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3554
3554
|
float lightsDenom;
|
|
3555
3555
|
|
|
3556
3556
|
// sampling
|
|
3557
|
-
${
|
|
3558
|
-
${
|
|
3559
|
-
${
|
|
3557
|
+
${ht}
|
|
3558
|
+
${pt}
|
|
3559
|
+
${mt}
|
|
3560
3560
|
|
|
3561
|
-
${
|
|
3562
|
-
${
|
|
3563
|
-
${
|
|
3564
|
-
${
|
|
3565
|
-
${
|
|
3566
|
-
${
|
|
3561
|
+
${Ot}
|
|
3562
|
+
${Tt}
|
|
3563
|
+
${Dt}
|
|
3564
|
+
${Et}
|
|
3565
|
+
${wt}
|
|
3566
|
+
${Ct}
|
|
3567
3567
|
|
|
3568
3568
|
float applyFilteredGlossy( float roughness, float accumulatedRoughness ) {
|
|
3569
3569
|
|
|
@@ -3595,12 +3595,12 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3595
3595
|
|
|
3596
3596
|
}
|
|
3597
3597
|
|
|
3598
|
-
${
|
|
3599
|
-
${
|
|
3600
|
-
${
|
|
3601
|
-
${
|
|
3602
|
-
${
|
|
3603
|
-
${
|
|
3598
|
+
${Nt}
|
|
3599
|
+
${At}
|
|
3600
|
+
${Pt}
|
|
3601
|
+
${kt}
|
|
3602
|
+
${jt}
|
|
3603
|
+
${Mt}
|
|
3604
3604
|
|
|
3605
3605
|
void main() {
|
|
3606
3606
|
|
|
@@ -3892,7 +3892,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3892
3892
|
|
|
3893
3893
|
}
|
|
3894
3894
|
|
|
3895
|
-
`}),this.setValues(e)}}function*
|
|
3895
|
+
`}),this.setValues(e)}};function*It(){let{_renderer:e,_fsQuad:t,_blendQuad:r,_primaryTarget:i,_blendTargets:a,_sobolTarget:o,_subframe:s,alpha:c,material:l}=this,u=new n.Vector4,d=new n.Vector4,f=r.material,[p,m]=a;for(;;){c?(f.opacity=this._opacityFactor/(this.samples+1),l.blending=n.NoBlending,l.opacity=1):(l.opacity=this._opacityFactor/(this.samples+1),l.blending=n.NormalBlending);let[a,h,g,_]=s,v=i.width,y=i.height;l.resolution.set(v*g,y*_),l.sobolTexture=o.texture,l.stratifiedTexture.init(20,l.bounces+l.transmissiveBounces+5),l.stratifiedTexture.next(),l.seed++;let b=this.tiles.x||1,x=this.tiles.y||1,S=b*x,C=Math.ceil(v*g),w=Math.ceil(y*_),T=Math.floor(a*v),E=Math.floor(h*y),D=Math.ceil(C/b),O=Math.ceil(w/x);for(let n=0;n<x;n++)for(let a=0;a<b;a++){let o=e.getRenderTarget(),s=e.autoClear,l=e.getScissorTest();e.getScissor(u),e.getViewport(d);let h=a,g=n;if(!this.stableTiles){let e=this._currentTile%(b*x);h=e%b,g=~~(e/b),this._currentTile=e+1}let _=x-g-1;i.scissor.set(T+h*D,E+_*O,Math.min(D,C-h*D),Math.min(O,w-_*O)),i.viewport.set(T,E,C,w),e.setRenderTarget(i),e.setScissorTest(!0),e.autoClear=!1,t.render(e),e.setViewport(d),e.setScissor(u),e.setScissorTest(l),e.setRenderTarget(o),e.autoClear=s,c&&(f.target1=p.texture,f.target2=i.texture,e.setRenderTarget(m),r.render(e),e.setRenderTarget(o)),this.samples+=1/S,a===b-1&&n===x-1&&(this.samples=Math.round(this.samples)),yield}[p,m]=[m,p]}}var Lt=new n.Color,Rt=class{get material(){return this._fsQuad.material}set material(e){this._fsQuad.material.removeEventListener(`recompilation`,this._compileFunction),e.addEventListener(`recompilation`,this._compileFunction),this._fsQuad.material=e}get target(){return this._alpha?this._blendTargets[1]:this._primaryTarget}set alpha(e){this._alpha!==e&&(e||(this._blendTargets[0].dispose(),this._blendTargets[1].dispose()),this._alpha=e,this.reset())}get alpha(){return this._alpha}get isCompiling(){return!!this._compilePromise}constructor(e){this.camera=null,this.tiles=new n.Vector2(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new n.Vector4(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new t.t(new Ft),this._blendQuad=new t.t(new me),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new ye().generate(e),this._primaryTarget=new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),this._blendTargets=[new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter})],this._compileFunction=()=>{let e=this.compileMaterial(this._fsQuad._mesh);e.then(()=>{this._compilePromise===e&&(this._compilePromise=null)}),this._compilePromise=e},this.material.addEventListener(`recompilation`,this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){let{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let n=0;e.projectionMatrix.elements[15]>0&&(n=1),e.isEquirectCamera&&(n=2),t.setDefine(`CAMERA_TYPE`,n),this.camera=e}setSize(e,t){e=Math.ceil(e),t=Math.ceil(t),!(this._primaryTarget.width===e&&this._primaryTarget.height===t)&&(this._primaryTarget.setSize(e,t),this._blendTargets[0].setSize(e,t),this._blendTargets[1].setSize(e,t),this.reset())}getSize(e){e.x=this._primaryTarget.width,e.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){let{_renderer:e,_primaryTarget:t,_blendTargets:n}=this,r=e.getRenderTarget(),i=e.getClearAlpha();e.getClearColor(Lt),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(n[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(n[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Lt,i),e.setRenderTarget(r),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||=It.call(this),this._task.next())}},X=new n.Vector2,zt=new n.Vector2,Z=new n.Spherical,Q=new n.Color,Bt=class extends n.DataTexture{constructor(e=512,t=512){super(new Float32Array(e*t*4),e,t,n.RGBAFormat,n.FloatType,n.EquirectangularReflectionMapping,n.RepeatWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;let{data:e,width:t,height:n}=this.image;for(let r=0;r<t;r++)for(let i=0;i<n;i++){zt.set(t,n),X.set(r/t,i/n),X.x-=.5,X.y=1-X.y,Z.theta=X.x*2*Math.PI,Z.phi=X.y*Math.PI,Z.radius=1,this.generationCallback(Z,X,zt,Q);let a=4*(i*t+r);e[a+0]=Q.r,e[a+1]=Q.g,e[a+2]=Q.b,e[a+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}},Vt=new n.Vector3,Ht=class extends Bt{constructor(e=512){super(e,e),this.topColor=new n.Color().set(16777215),this.bottomColor=new n.Color().set(0),this.exponent=2,this.generationCallback=(e,t,n,r)=>{Vt.setFromSpherical(e);let i=Vt.y*.5+.5;r.lerpColors(this.bottomColor,this.topColor,i**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}},Ut=class extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}constructor(e){super({uniforms:{map:{value:null},opacity:{value:1}},vertexShader:`
|
|
3896
3896
|
varying vec2 vUv;
|
|
3897
3897
|
void main() {
|
|
3898
3898
|
|
|
@@ -3949,7 +3949,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3949
3949
|
#include <premultiplied_alpha_fragment>
|
|
3950
3950
|
|
|
3951
3951
|
}
|
|
3952
|
-
`}),this.setValues(e)}}class
|
|
3952
|
+
`}),this.setValues(e)}},Wt=class extends n.ShaderMaterial{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
|
|
3953
3953
|
varying vec2 vUv;
|
|
3954
3954
|
void main() {
|
|
3955
3955
|
|
|
@@ -3966,7 +3966,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3966
3966
|
#include <common>
|
|
3967
3967
|
#include <cube_uv_reflection_fragment>
|
|
3968
3968
|
|
|
3969
|
-
${
|
|
3969
|
+
${bt}
|
|
3970
3970
|
|
|
3971
3971
|
void main() {
|
|
3972
3972
|
|
|
@@ -3974,7 +3974,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3974
3974
|
rayDirection.x *= flipEnvMap;
|
|
3975
3975
|
gl_FragColor = textureCube( envMap, rayDirection );
|
|
3976
3976
|
|
|
3977
|
-
}`}),this.depthWrite=!1,this.depthTest=!1}}class ke{constructor(e){this._renderer=e,this._quad=new N.FullScreenQuad(new zr)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");const i=e.images[0],o=this._renderer,a=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);const c=new n.WebGLRenderTarget(t,r,{type:n.FloatType,colorSpace:i.colorSpace}),f=i.height,m=Math.log2(f)-2,d=1/f,h=1/(3*Math.max(Math.pow(2,m),112));a.material.defines.CUBEUV_MAX_MIP=`${m}.0`,a.material.defines.CUBEUV_TEXEL_WIDTH=h,a.material.defines.CUBEUV_TEXEL_HEIGHT=d,a.material.uniforms.envMap.value=e,a.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,a.material.needsUpdate=!0;const l=o.getRenderTarget(),y=o.autoClear;o.autoClear=!0,o.setRenderTarget(c),a.render(o),o.setRenderTarget(l),o.autoClear=y;const p=new Uint16Array(t*r*4),v=new Float32Array(t*r*4);o.readRenderTargetPixels(c,0,0,t,r,v),c.dispose();for(let g=0,x=v.length;g<x;g++)p[g]=n.DataUtils.toHalfFloat(v[g]);const u=new n.DataTexture(p,t,r,n.RGBAFormat,n.HalfFloatType);return u.minFilter=n.LinearMipMapLinearFilter,u.magFilter=n.LinearFilter,u.wrapS=n.RepeatWrapping,u.wrapT=n.RepeatWrapping,u.mapping=n.EquirectangularReflectionMapping,u.needsUpdate=!0,u}dispose(){this._quad.dispose()}}function Hr(s){return s.extensions.get("EXT_float_blend")}const z=new n.Vector2;class Wr{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new wt,this._pathTracer=new Pe(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new Pe(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new N.FullScreenQuad(new Br({map:null,transparent:!0,blending:n.NoBlending,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new n.Vector2(1024,1024),this.rasterizeSceneCallback=(t,r)=>{this._renderer.render(t,r)},this.renderToCanvasCallback=(t,r,i)=>{const o=r.autoClear;r.autoClear=!1,i.render(r),r.autoClear=o},this.setScene(new n.Scene,new n.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,r={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();const i=this._generator;if(i.setObjects(e),this._buildAsync)return i.generateAsync(r.onProgress).then(o=>this._updateFromResults(e,t,o));{const o=i.generate();return this._updateFromResults(e,t,o)}}setSceneAsync(...e){this._buildAsync=!0;const t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){const e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){const e=this._pathTracer.material,t=this._renderer,r=this._materials,i=this.textureSize,o=Vt(r);e.textures.setTextures(t,o,i.x,i.y),e.materials.updateFrom(r,o),this.reset()}updateLights(){const e=this.scene,t=this._renderer,r=this._pathTracer.material,i=qt(e),o=Gt(i);r.lights.updateFrom(i,o),r.iesProfiles.setTextures(t,o),this.reset()}updateEnvironment(){const e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new kr(16);const r=this._colorBackground;r.topColor.equals(e.background)||(r.topColor.set(e.background),r.bottomColor.set(e.background),r.update()),t.backgroundMap=r,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){const r=new ke(this._renderer).generate(e.background);this._internalBackground=r,t.backgroundMap=r,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){const r=new ke(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(r)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,r){const{materials:i,geometry:o,bvh:a,bvhChanged:c}=r;this._materials=i;const m=this._pathTracer.material;return c&&(m.bvh.updateFrom(a),m.attributesArray.updateFrom(o.attributes.normal,o.attributes.tangent,o.attributes.uv,o.attributes.color),m.materialIndexAttribute.updateFrom(o.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),r}renderSample(){const e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,o=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,o.material.opacity=0,i.start());const a=i.getDelta()*1e3,c=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=c&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!Hr(r),e.alpha=t.alpha,this.renderToCanvas){const f=this._renderer,m=this.minSamples;if(c>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?o.material.opacity=Math.min(o.material.opacity+a/this.fadeDuration,1):o.material.opacity=1),!this.enablePathTracing||this.samples<m||o.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());const d=o.material.opacity;o.material.opacity=1-o.material.opacity,o.material.map=e.target.texture,o.render(f),o.material.opacity=d}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&o.material.opacity>0&&(o.material.opacity<1&&(o.material.blending=this.dynamicLowRes?n.AdditiveBlending:n.NormalBlending),o.material.map=t.target.texture,this.renderToCanvasCallback(t.target,f,o),o.material.blending=n.NoBlending)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._renderQuad.dispose(),this._renderQuad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(z);const e=Math.floor(this.renderScale*z.x),t=Math.floor(this.renderScale*z.y);if(this._pathTracer.getSize(z),z.x!==e||z.y!==t){const r=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*r),Math.floor(t*r))}}}}function Be(s){return typeof s=="object"&&s!==null&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}function O(s){return s!==null&&typeof s=="object"&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}const S=class S{constructor(){this.pathTracer=null,this.enabled=!1,this.renderer=null,this.sampleCount=0,this.createAttempts=0,this.maxCreateAttempts=10,this.sceneInitialized=!1,this.environmentWaitFrames=0,this.maxEnvironmentWaitFrames=300,this.disposed=!1,this.convertedEnvTexture=null,this.resumable=!1,this.lastCameraMoveTime=-1/0,this.cameraDirty=!1,this.events=new T.TypedEventEmitter,this.rasterFadeTarget=null,this.fadeQuad=null,this.fadeToneMapping=null,this.fadeSupported=!0,this.settings={samples:T.DEFAULT_PATH_TRACING_SAMPLES,bounces:4,transmissiveBounces:2,renderScale:1,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}ingestSceneWithoutShadowHelpers(e,t){var o;const r=[],i=[];e.traverse(a=>{var c,f;(c=a.userData)!=null&&c[T.CONTACT_SHADOW_HELPER_FLAG]&&a.visible?r.push(a):(f=a.userData)!=null&&f[T.PATH_TRACING_FLOOR_FLAG]&&!a.visible&&i.push(a)}),r.forEach(a=>a.visible=!1),i.forEach(a=>a.visible=!0);try{(o=this.pathTracer)==null||o.setScene(e,t)}finally{r.forEach(a=>a.visible=!0),i.forEach(a=>a.visible=!1)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;const t=e.image,r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return null;i.drawImage(t,0,0);const o=i.getImageData(0,0,r.width,r.height),a=new Float32Array(o.data.length);for(let f=0;f<o.data.length;f++)a[f]=o.data[f]/255;const c=new I.DataTexture(a,r.width,r.height,I.RGBAFormat,I.FloatType);return c.mapping=e.mapping,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.magFilter=e.magFilter,c.minFilter=e.minFilter,c.anisotropy=e.anisotropy,c.needsUpdate=!0,c}async initialize(e){try{return this.renderer=e.renderer,this.enabled=e.enabled,this.isSupported()?T.Result.ok(void 0):T.Result.err(new T.ThreeViewerError("Path tracing is not supported in this environment",T.ErrorCode.PATH_TRACING_INIT_FAILED,{reason:"WebGL2 or required extensions not available"}))}catch(t){return T.Result.err(new T.ThreeViewerError("Failed to initialize path tracing",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return T.Result.err(new T.ThreeViewerError("Instance is disposed",T.ErrorCode.INVALID_STATE));try{const e=O(this.renderer)?this.renderer.getInternalRenderer():null;return e?(this.pathTracer=new Wr(e),this.pathTracer.tiles&&"set"in this.pathTracer.tiles&&this.pathTracer.tiles.set(1,1),this.pathTracer.bounces=this.settings.bounces,this.settings.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=this.settings.transmissiveBounces),this.pathTracer.renderScale=this.settings.renderScale,this.pathTracer.dynamicLowRes=this.settings.dynamicLowRes,this.pathTracer.lowResScale=this.settings.lowResScale,e.setRenderTarget(null),T.Result.ok(void 0)):T.Result.err(new T.ThreeViewerError("Renderer not ready, will retry",T.ErrorCode.RENDERER_NOT_INITIALIZED))}catch(e){return T.Result.err(new T.ThreeViewerError("Failed to create path tracer",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:e}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.resumable=!1,this.reset(),this.sceneInitialized=!1;const t=O(this.renderer)?this.renderer.getInternalRenderer():null;t&&(t.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.resumable=e==="completed",this.events.emit("pathtracing:paused",{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(e,t){if(this.disposed)return T.Result.ok(void 0);const r=this.renderer;if(!r)return T.Result.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(e,t);if(!this.pathTracer){const i=this.ensurePathTracerCreated(r,e,t);if(i)return i}try{const i=this.extractThreeObjects(e,t);if(!i)return T.Result.err(new T.ThreeViewerError("Could not extract Three.js scene or camera",T.ErrorCode.INVALID_PARAMETER));const{threeScene:o,threeCamera:a}=i;if(!this.sceneInitialized){const c=await this.initializeSceneForPathTracing(r,e,t,o,a);if(c)return c}return this.sceneInitialized?this.accumulateSample(r,e,t):r.render(e,t)}catch(i){return T.Result.err(new T.ThreeViewerError("Failed to render with path tracing",T.ErrorCode.RENDER_FAILED,{originalError:i}))}}ensurePathTracerCreated(e,t,r){var o;this.createAttempts++;const i=this.createPathTracer();return i.ok?(this.createAttempts=0,null):(this.createAttempts<this.maxCreateAttempts&&((o=i.error)==null?void 0:o.message)==="Renderer not ready, will retry"||(this.disableAfterSelfPause("gave-up"),this.createAttempts=0),e.render(t,r))}extractThreeObjects(e,t){let r=null,i=null;return Be(e)&&(r=e.getInternalRenderer()),Be(t)&&(i=t.getInternalRenderer()),!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,o){var a;try{const c=i.__originalEnvironmentTexture;if(!i.environment&&!c)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause("gave-up"),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,c&&c.isCubeTexture){const f=i.environment;i.environment=c;try{this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0}finally{i.environment=f}}else if(c&&c.mapping===I.EquirectangularReflectionMapping){let f=c;if(c.image instanceof HTMLImageElement)if(this.convertedEnvTexture)f=this.convertedEnvTexture;else{const d=this.convertToDataTexture(c);if(!d)throw new Error("Failed to convert environment texture to DataTexture");this.convertedEnvTexture=d,f=d}const m=i.environment;i.environment=f;try{const d=c.image;d&&!("data"in d&&d.data)&&d instanceof HTMLImageElement&&!d.complete&&await new Promise(h=>{d.onload=()=>{c.needsUpdate=!0,h()},d.onerror=()=>{h()},d.complete&&h()}),this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0,i.environment=m}catch(d){throw i.environment=m,d}}else if(((a=i.environment)==null?void 0:a.mapping)===I.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0;else return this.disableAfterSelfPause("gave-up"),e.render(t,r)}catch(c){return console.warn("Scene initialization error:",c),e.render(t,r)}return null}accumulateSample(e,t,r){var o,a;if(this.sampleCount===0)try{(o=this.pathTracer)==null||o.updateLights()}catch(c){console.warn("Failed to update lights for path tracing:",c)}const i=e.render(t,r);if(!i.ok)return i;if(performance.now()-this.lastCameraMoveTime<S.CAMERA_SETTLE_MS)return T.Result.ok(void 0);if(this.cameraDirty&&(this.cameraDirty=!1,(a=this.pathTracer)==null||a.updateCamera()),this.fadeSupported&&this.sampleCount===0&&this.runFadeStep(()=>this.captureRasterFade(e,t,r)),this.accumulateOneSample(),this.sampleCount++,this.fadeSupported&&this.sampleCount<S.FADE_SAMPLES){const c=1-this.pathTracedLayerOpacity(this.sampleCount);this.runFadeStep(()=>this.renderRasterFade(c))}return this.sampleCount===this.settings.samples?this.captureCompletedFrame():T.Result.ok(void 0)}runFadeStep(e){try{e()}catch(t){console.warn("Path-tracing startup dissolve unavailable; showing samples directly:",t),this.fadeSupported=!1}}pathTracedLayerOpacity(e){const t=S.FADE_HOLD_SAMPLES,r=S.FADE_SAMPLES,i=S.FADE_PREVIEW_OPACITY,o=t+(r-t)*S.FADE_RELEASE_FRACTION;return e<o?i*S.smoothstep(t,o,e):i+(1-i)*S.smoothstep(o,r,e)}static smoothstep(e,t,r){const i=Math.min(1,Math.max(0,(r-e)/(t-e)));return i*i*(3-2*i)}captureRasterFade(e,t,r){const i=O(this.renderer)?this.renderer.getInternalRenderer():null;if(!i)return;const o=i.getDrawingBufferSize(new I.Vector2);this.rasterFadeTarget?(this.rasterFadeTarget.width!==o.x||this.rasterFadeTarget.height!==o.y)&&this.rasterFadeTarget.setSize(o.x,o.y):(this.rasterFadeTarget=new I.WebGLRenderTarget(o.x,o.y,{type:I.HalfFloatType}),this.rasterFadeTarget.texture.colorSpace=I.LinearSRGBColorSpace);const a=i.getRenderTarget();i.setRenderTarget(this.rasterFadeTarget),e.render(t,r),i.setRenderTarget(a)}renderRasterFade(e){var a,c;const t=O(this.renderer)?this.renderer.getInternalRenderer():null;if(!t||!this.rasterFadeTarget)return;(!this.fadeQuad||this.fadeToneMapping!==t.toneMapping)&&((c=(a=this.fadeQuad)==null?void 0:a.material)==null||c.dispose(),this.fadeToneMapping=t.toneMapping,this.fadeQuad=new N.FullScreenQuad(this.createFadeMaterial(t.toneMapping)));const r=this.fadeQuad.material;r.uniforms.tRaster.value=this.rasterFadeTarget.texture,r.uniforms.uOpacity.value=e;const i=t.autoClear,o=t.getRenderTarget();t.setRenderTarget(null),t.autoClear=!1;try{this.fadeQuad.render(t)}finally{t.autoClear=i,t.setRenderTarget(o)}}createFadeMaterial(e){const t={[I.LinearToneMapping]:"LINEAR_TONE_MAPPING",[I.ReinhardToneMapping]:"REINHARD_TONE_MAPPING",[I.CineonToneMapping]:"CINEON_TONE_MAPPING",[I.ACESFilmicToneMapping]:"ACES_FILMIC_TONE_MAPPING",[I.AgXToneMapping]:"AGX_TONE_MAPPING",[I.NeutralToneMapping]:"NEUTRAL_TONE_MAPPING"},r={},i=t[e];return i&&(r[i]=""),new I.ShaderMaterial({defines:r,uniforms:{tRaster:{value:null},uOpacity:{value:1}},vertexShader:`
|
|
3977
|
+
}`}),this.depthWrite=!1,this.depthTest=!1}},Gt=class{constructor(e){this._renderer=e,this._quad=new t.t(new Wt)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw Error(`CubeToEquirectMaterial: Source can only be cube textures.`);let i=e.images[0],a=this._renderer,o=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);let s=new n.WebGLRenderTarget(t,r,{type:n.FloatType,colorSpace:i.colorSpace}),c=i.height,l=Math.log2(c)-2,u=1/c,d=1/(3*Math.max(2**l,112));o.material.defines.CUBEUV_MAX_MIP=`${l}.0`,o.material.defines.CUBEUV_TEXEL_WIDTH=d,o.material.defines.CUBEUV_TEXEL_HEIGHT=u,o.material.uniforms.envMap.value=e,o.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,o.material.needsUpdate=!0;let f=a.getRenderTarget(),p=a.autoClear;a.autoClear=!0,a.setRenderTarget(s),o.render(a),a.setRenderTarget(f),a.autoClear=p;let m=new Uint16Array(t*r*4),h=new Float32Array(t*r*4);a.readRenderTargetPixels(s,0,0,t,r,h),s.dispose();for(let e=0,t=h.length;e<t;e++)m[e]=n.DataUtils.toHalfFloat(h[e]);let g=new n.DataTexture(m,t,r,n.RGBAFormat,n.HalfFloatType);return g.minFilter=n.LinearMipMapLinearFilter,g.magFilter=n.LinearFilter,g.wrapS=n.RepeatWrapping,g.wrapT=n.RepeatWrapping,g.mapping=n.EquirectangularReflectionMapping,g.needsUpdate=!0,g}dispose(){this._quad.dispose()}};function Kt(e){return e.extensions.get(`EXT_float_blend`)}var $=new n.Vector2,qt=class{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine(`FEATURE_MIS`,+!!e)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new pe,this._pathTracer=new Rt(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new Rt(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new t.t(new Ut({map:null,transparent:!0,blending:n.NoBlending,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new n.Vector2(1024,1024),this.rasterizeSceneCallback=(e,t)=>{this._renderer.render(e,t)},this.renderToCanvasCallback=(e,t,n)=>{let r=t.autoClear;t.autoClear=!1,n.render(t),t.autoClear=r},this.setScene(new n.Scene,new n.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,n={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();let r=this._generator;if(r.setObjects(e),this._buildAsync)return r.generateAsync(n.onProgress).then(n=>this._updateFromResults(e,t,n));{let n=r.generate();return this._updateFromResults(e,t,n)}}setSceneAsync(...e){this._buildAsync=!0;let t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){let e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){let e=this._pathTracer.material,t=this._renderer,n=this._materials,r=this.textureSize,i=ze(n);e.textures.setTextures(t,i,r.x,r.y),e.materials.updateFrom(n,i),this.reset()}updateLights(){let e=this.scene,t=this._renderer,n=this._pathTracer.material,r=Be(e),i=Re(r);n.lights.updateFrom(r,i),n.iesProfiles.setTextures(t,i),this.reset()}updateEnvironment(){let e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&=(this._internalBackground.dispose(),null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new Ht(16);let n=this._colorBackground;n.topColor.equals(e.background)||(n.topColor.set(e.background),n.bottomColor.set(e.background),n.update()),t.backgroundMap=n,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){let n=new Gt(this._renderer).generate(e.background);this._internalBackground=n,t.backgroundMap=n,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){let n=new Gt(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(n)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,n){let{materials:r,geometry:i,bvh:a,bvhChanged:o}=n;this._materials=r;let s=this._pathTracer.material;return o&&(s.bvh.updateFrom(a),s.attributesArray.updateFrom(i.attributes.normal,i.attributes.tangent,i.attributes.uv,i.attributes.color),s.materialIndexAttribute.updateFrom(i.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),n}renderSample(){let e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,a=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,a.material.opacity=0,i.start());let o=i.getDelta()*1e3,s=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=s&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!Kt(r),e.alpha=t.alpha,this.renderToCanvas){let r=this._renderer,i=this.minSamples;if(s>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration===0?a.material.opacity=1:a.material.opacity=Math.min(a.material.opacity+o/this.fadeDuration,1)),!this.enablePathTracing||this.samples<i||a.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());let n=a.material.opacity;a.material.opacity=1-a.material.opacity,a.material.map=e.target.texture,a.render(r),a.material.opacity=n}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&a.material.opacity>0&&(a.material.opacity<1&&(a.material.blending=this.dynamicLowRes?n.AdditiveBlending:n.NormalBlending),a.material.map=t.target.texture,this.renderToCanvasCallback(t.target,r,a),a.material.blending=n.NoBlending)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._renderQuad.dispose(),this._renderQuad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize($);let e=Math.floor(this.renderScale*$.x),t=Math.floor(this.renderScale*$.y);if(this._pathTracer.getSize($),$.x!==e||$.y!==t){let n=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*n),Math.floor(t*n))}}}},Jt=class r{ingestSceneWithoutShadowHelpers(e,t){let n=[],r=[];e.traverse(e=>{e.userData?.softboxContactShadowHelper&&e.visible?n.push(e):e.userData?.softboxPathTracingFloor&&!e.visible&&r.push(e)}),n.forEach(e=>e.visible=!1),r.forEach(e=>e.visible=!0);try{this.pathTracer?.setScene(e,t)}finally{n.forEach(e=>e.visible=!0),r.forEach(e=>e.visible=!1)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;let t=e.image,r=document.createElement(`canvas`);r.width=t.width,r.height=t.height;let i=r.getContext(`2d`);if(!i)return null;i.drawImage(t,0,0);let a=i.getImageData(0,0,r.width,r.height),o=new Float32Array(a.data.length);for(let e=0;e<a.data.length;e++)o[e]=a.data[e]/255;let s=new n.DataTexture(o,r.width,r.height,n.RGBAFormat,n.FloatType);return s.mapping=e.mapping,s.wrapS=e.wrapS,s.wrapT=e.wrapT,s.magFilter=e.magFilter,s.minFilter=e.minFilter,s.anisotropy=e.anisotropy,s.needsUpdate=!0,s}getThreeRenderer(){return e.i(this.renderer)}static{this.CAMERA_SETTLE_MS=200}static{this.FADE_SAMPLES=256}static{this.FADE_HOLD_SAMPLES=4}static{this.FADE_PREVIEW_OPACITY=.3}static{this.FADE_RELEASE_FRACTION=.5}constructor(){this.pathTracer=null,this.enabled=!1,this.renderer=null,this.sampleCount=0,this.createAttempts=0,this.maxCreateAttempts=10,this.sceneInitialized=!1,this.environmentWaitFrames=0,this.maxEnvironmentWaitFrames=300,this.disposed=!1,this.convertedEnvTexture=null,this.convertedEnvSourceUuid=null,this.resumable=!1,this.lastCameraMoveTime=-1/0,this.cameraDirty=!1,this.events=new e.D,this.rasterFadeTarget=null,this.fadeQuad=null,this.fadeToneMapping=null,this.fadeSupported=!0,this.settings={samples:300,bounces:4,transmissiveBounces:2,renderScale:1,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}async initialize(t){try{return this.renderer=t.renderer,this.enabled=t.enabled,this.isSupported()?e.O.ok(void 0):e.O.err(new e.A(`Path tracing is not supported in this environment`,e.k.PATH_TRACING_INIT_FAILED,{reason:`WebGL2 or required extensions not available`}))}catch(t){return e.O.err(new e.A(`Failed to initialize path tracing`,e.k.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return e.O.err(new e.A(`Instance is disposed`,e.k.INVALID_STATE));try{let t=this.getThreeRenderer();return t?(this.pathTracer=new qt(t),this.pathTracer.tiles&&`set`in this.pathTracer.tiles&&this.pathTracer.tiles.set(1,1),this.pathTracer.bounces=this.settings.bounces,this.settings.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=this.settings.transmissiveBounces),this.pathTracer.renderScale=this.settings.renderScale,this.pathTracer.dynamicLowRes=this.settings.dynamicLowRes,this.pathTracer.lowResScale=this.settings.lowResScale,t.setRenderTarget(null),e.O.ok(void 0)):e.O.err(new e.A(`Renderer not ready, will retry`,e.k.RENDERER_NOT_INITIALIZED))}catch(t){return e.O.err(new e.A(`Failed to create path tracer`,e.k.PATH_TRACING_INIT_FAILED,{originalError:t}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.resumable=!1,this.reset(),this.sceneInitialized=!1;let e=this.getThreeRenderer();e&&(e.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.resumable=e===`completed`,this.events.emit(`pathtracing:paused`,{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(t,n){if(this.disposed)return e.O.ok(void 0);let r=this.renderer;if(!r)return e.O.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(t,n);if(!this.pathTracer){let e=this.ensurePathTracerCreated(r,t,n);if(e)return e}try{let i=this.extractThreeObjects(t,n);if(!i)return e.O.err(new e.A(`Could not extract Three.js scene or camera`,e.k.INVALID_PARAMETER));let{threeScene:a,threeCamera:o}=i;if(!this.sceneInitialized){let e=await this.initializeSceneForPathTracing(r,t,n,a,o);if(e)return e}return this.sceneInitialized?this.accumulateSample(r,t,n):r.render(t,n)}catch(t){return e.O.err(new e.A(`Failed to render with path tracing`,e.k.RENDER_FAILED,{originalError:t}))}}ensurePathTracerCreated(e,t,n){this.createAttempts++;let r=this.createPathTracer();return r.ok?(this.createAttempts=0,null):this.createAttempts<this.maxCreateAttempts&&r.error?.message===`Renderer not ready, will retry`?e.render(t,n):(this.disableAfterSelfPause(`gave-up`),this.createAttempts=0,e.render(t,n))}extractThreeObjects(t,n){let r=e.a(t),i=e.t(n);return!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,a){try{let o=i.__originalEnvironmentTexture;if(!i.environment&&!o)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause(`gave-up`),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,o&&o.isCubeTexture){let e=i.environment;i.environment=o;try{this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0}finally{i.environment=e}}else if(o&&o.mapping===n.EquirectangularReflectionMapping){let e=o;if(o.image instanceof HTMLImageElement)if(this.convertedEnvTexture&&this.convertedEnvSourceUuid===o.uuid)e=this.convertedEnvTexture;else{this.convertedEnvTexture?.dispose(),this.convertedEnvTexture=null,this.convertedEnvSourceUuid=null;let t=this.convertToDataTexture(o);if(!t)throw Error(`Failed to convert environment texture to DataTexture`);this.convertedEnvTexture=t,this.convertedEnvSourceUuid=o.uuid,e=t}let t=i.environment;i.environment=e;try{let e=o.image;e&&!(`data`in e&&e.data)&&e instanceof HTMLImageElement&&!e.complete&&await new Promise(t=>{e.onload=()=>{o.needsUpdate=!0,t()},e.onerror=()=>{t()},e.complete&&t()}),this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0,i.environment=t}catch(e){throw i.environment=t,e}}else if(i.environment?.mapping===n.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0;else return this.disableAfterSelfPause(`gave-up`),e.render(t,r)}catch(n){return console.warn(`Scene initialization error:`,n),e.render(t,r)}return null}accumulateSample(t,n,i){if(this.sampleCount===0)try{this.pathTracer?.updateLights()}catch(e){console.warn(`Failed to update lights for path tracing:`,e)}let a=t.render(n,i);if(!a.ok)return a;if(performance.now()-this.lastCameraMoveTime<r.CAMERA_SETTLE_MS)return e.O.ok(void 0);if(this.cameraDirty&&(this.cameraDirty=!1,this.pathTracer?.updateCamera()),this.fadeSupported&&this.sampleCount===0&&this.runFadeStep(()=>this.captureRasterFade(t,n,i)),this.accumulateOneSample(),this.sampleCount++,this.fadeSupported&&this.sampleCount<this.fadeWindowSamples()){let e=1-this.pathTracedLayerOpacity(this.sampleCount);this.runFadeStep(()=>this.renderRasterFade(e))}return this.sampleCount===this.settings.samples?this.captureCompletedFrame():e.O.ok(void 0)}runFadeStep(e){try{e()}catch(e){console.warn(`Path-tracing startup dissolve unavailable; showing samples directly:`,e),this.fadeSupported=!1}}fadeWindowSamples(){let e=r.FADE_HOLD_SAMPLES+2;return Math.max(e,Math.min(r.FADE_SAMPLES,this.settings.samples))}pathTracedLayerOpacity(e){let t=r.FADE_HOLD_SAMPLES,n=this.fadeWindowSamples(),i=r.FADE_PREVIEW_OPACITY,a=t+(n-t)*r.FADE_RELEASE_FRACTION;return e<a?i*r.smoothstep(t,a,e):i+(1-i)*r.smoothstep(a,n,e)}static smoothstep(e,t,n){let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)}captureRasterFade(e,t,r){let i=this.getThreeRenderer();if(!i)return;let a=i.getDrawingBufferSize(new n.Vector2);this.rasterFadeTarget?(this.rasterFadeTarget.width!==a.x||this.rasterFadeTarget.height!==a.y)&&this.rasterFadeTarget.setSize(a.x,a.y):(this.rasterFadeTarget=new n.WebGLRenderTarget(a.x,a.y,{type:n.HalfFloatType}),this.rasterFadeTarget.texture.colorSpace=n.LinearSRGBColorSpace);let o=i.getRenderTarget();i.setRenderTarget(this.rasterFadeTarget),e.render(t,r),i.setRenderTarget(o)}renderRasterFade(e){let n=this.getThreeRenderer();if(!n||!this.rasterFadeTarget)return;(!this.fadeQuad||this.fadeToneMapping!==n.toneMapping)&&((this.fadeQuad?.material)?.dispose(),this.fadeToneMapping=n.toneMapping,this.fadeQuad=new t.t(this.createFadeMaterial(n.toneMapping)));let r=this.fadeQuad.material;r.uniforms.tRaster.value=this.rasterFadeTarget.texture,r.uniforms.uOpacity.value=e;let i=n.autoClear,a=n.getRenderTarget();n.setRenderTarget(null),n.autoClear=!1;try{this.fadeQuad.render(n)}finally{n.autoClear=i,n.setRenderTarget(a)}}createFadeMaterial(e){let t={[n.LinearToneMapping]:`LINEAR_TONE_MAPPING`,[n.ReinhardToneMapping]:`REINHARD_TONE_MAPPING`,[n.CineonToneMapping]:`CINEON_TONE_MAPPING`,[n.ACESFilmicToneMapping]:`ACES_FILMIC_TONE_MAPPING`,[n.AgXToneMapping]:`AGX_TONE_MAPPING`,[n.NeutralToneMapping]:`NEUTRAL_TONE_MAPPING`},r={},i=t[e];return i&&(r[i]=``),new n.ShaderMaterial({defines:r,uniforms:{tRaster:{value:null},uOpacity:{value:1}},vertexShader:`
|
|
3978
3978
|
varying vec2 vUv;
|
|
3979
3979
|
void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }
|
|
3980
3980
|
`,fragmentShader:`
|
|
@@ -3998,4 +3998,4 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3998
3998
|
#endif
|
|
3999
3999
|
gl_FragColor = vec4( sRGBTransferOETF( vec4( color, 1.0 ) ).rgb, uOpacity );
|
|
4000
4000
|
}
|
|
4001
|
-
`,transparent:!0,depthTest:!1,depthWrite:!1})}renderWhileDisabled(
|
|
4001
|
+
`,transparent:!0,depthTest:!1,depthWrite:!1})}renderWhileDisabled(t,n){if(!this.renderer)return e.O.ok(void 0);if(this.sampleCount>=this.settings.samples&&this.sampleCount>0){let t=this.getThreeRenderer();return this.pathTracer&&t&&t.setRenderTarget(null),e.O.ok(void 0)}return this.renderer.render(t,n)}accumulateOneSample(){let e=this.getThreeRenderer();if(!e)throw Error(`Three.js renderer not available`);let t=e.autoClear,n=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(n)}captureCompletedFrame(){let t=this.getThreeRenderer();if(t&&this.pathTracer)try{let e=t.autoClear;t.autoClear=!0,t.setRenderTarget(null),t.clear(!0,!0,!0);let n=this.pathTracer.copyQuad;n&&typeof n.render==`function`?n.render(t):(t.autoClear=!1,this.pathTracer.renderSample()),t.autoClear=e}catch(e){console.warn(`Failed to present path traced result:`,e)}return this.disableAfterSelfPause(`completed`),e.O.ok(void 0)}getSampleCount(){return this.sampleCount}isEnabled(){return this.enabled}isPathTracerDisposed(){return this.disposed}canResume(){return this.resumable&&this.pathTracer!==null&&!this.disposed}reset(e=!1){if(this.sampleCount=0,this.pathTracer){if(e){this.pathTracer.reset(),this.sceneInitialized=!1;return}this.lastCameraMoveTime=performance.now(),this.cameraDirty=!0,this.pathTracer.reset()}}dispose(){if(this.disposed=!0,this.events.removeAllListeners(),this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn(`Failed to dispose path tracer during service disposal:`,e)}this.pathTracer=null}this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null,this.convertedEnvSourceUuid=null),this.fadeQuad&&=(this.fadeQuad.material.dispose(),null),this.fadeToneMapping=null,this.rasterFadeTarget&&=(this.rasterFadeTarget.dispose(),null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement(`canvas`).getContext(`webgl2`)!==null}};exports.ThreePathTracingService=Jt;
|