@threepipe/webgi-plugins 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,149 +1,10 @@
1
- (function(o,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("threepipe")):typeof define=="function"&&define.amd?define(["exports","threepipe"],e):(o=typeof globalThis<"u"?globalThis:o||self,e(o["@threepipe/webgi-plugins"]={},o.threepipe))})(this,function(o,e){"use strict";/**
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("threepipe")):"function"==typeof define&&define.amd?define(["exports","threepipe"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@threepipe/webgi-plugins"]={},e.threepipe)}(this,(function(e,t){"use strict";
2
+ /**
2
3
  * @license
3
- * @threepipe/webgi-plugins v0.1.0
4
- * Copyright 2022-2024 repalash <palash@shaders.app>
4
+ * @threepipe/webgi-plugins v0.2.1
5
+ * Copyright 2022-2025 repalash <palash@shaders.app>
5
6
  * GPL-3.0-only License
6
- */var v;const A=`#if defined(HAS_VELOCITY_BUFFER)
7
- uniform sampler2D tVelocity;vec2 getVelocity(const in vec2 uv){vec2 screenSpaceVelocity=texture2D(tVelocity,uv).xy*2.0-1.0;return sign(screenSpaceVelocity)*pow(abs(screenSpaceVelocity),vec2(4.));}
8
- #endif
9
- `,O=`#ifdef USE_ALPHAMAP
10
- #define USE_UV
11
- #endif
12
- #include <uv_pars_vertex>
13
- #include <morphtarget_pars_vertex>
14
- #include <skinning_pars_vertex>
15
- #include <logdepthbuf_pars_vertex>
16
- #include <clipping_planes_pars_vertex>
17
- varying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 modelMatrixPrevious;void main(){
18
- #include <uv_vertex>
19
- #include <skinbase_vertex>
20
- #include <begin_vertex>
21
- #include <morphtarget_vertex>
22
- #include <skinning_vertex>
23
- #include <displacementmap_vertex>
24
- vec4 mvPosition=vec4(transformed,1.0);
25
- #ifdef USE_INSTANCING
26
- mvPosition=instanceMatrix*mvPosition;
27
- #endif
28
- vWorldPosition=(modelMatrix*mvPosition).xyz;vWorldPositionPrevious=(modelMatrixPrevious*mvPosition).xyz;mvPosition=modelViewMatrix*mvPosition;gl_Position=projectionMatrix*mvPosition;
29
- #include <logdepthbuf_vertex>
30
- #include <clipping_planes_vertex>
31
- }`,N="varying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 currentProjectionViewMatrix;uniform mat4 lastProjectionViewMatrix;vec2 computeScreenSpaceVelocity2(){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(vWorldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(vWorldPositionPrevious,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}void main(){vec2 velocity=clamp(computeScreenSpaceVelocity2(),-1.0,1.0);velocity=sign(velocity)*pow(abs(velocity),vec2(1./4.));velocity=velocity*0.5+0.5;gl_FragColor=vec4(velocity.x,velocity.y,1.,1.);}",V=`#include <common>
32
- #include <gbuffer_unpack>
33
- #ifdef HAS_VELOCITY_BUFFER
34
- #endif
35
- #include <cameraHelpers>
36
- varying vec2 vUv;uniform vec2 previousRTSize;uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;uniform mat4 inverseViewMatrix;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;
37
- #ifndef HAS_VELOCITY_BUFFER
38
- #define HAS_VELOCITY_BUFFER 0
39
- #endif
40
- vec3 find_closest_fragment_3x3(const in vec2 uv){const vec3 offset=vec3(-1.0,1.0,0.0);vec2 texelSize=1.0/previousRTSize;vec3 dtr=vec3(1,1,getDepth(uv+offset.yy*texelSize));vec3 dtc=vec3(0,1,getDepth(uv+offset.zy*texelSize));vec3 dtl=vec3(-1,1,getDepth(uv+offset.xy*texelSize));vec3 dml=vec3(-1,0,getDepth(uv+offset.xz*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dmr=vec3(1,0,getDepth(uv+offset.yz*texelSize));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.xx*texelSize));vec3 dbc=vec3(0,-1,getDepth(uv+offset.zx*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.yx*texelSize));vec3 dmin=dtl;if(dmin.z>dtc.z)dmin=dtc;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dml.z)dmin=dml;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dmr.z)dmin=dmr;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbc.z)dmin=dbc;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+texelSize.xy*dmin.xy,dmin.z);}vec3 find_closest_fragment_5tap(const in vec2 uv){vec2 texelSize=1.0/previousRTSize;vec2 offset=vec2(1.0,-1.0);vec3 dtl=vec3(-1,1,getDepth(uv+offset.yx*texelSize));vec3 dtr=vec3(1,1,getDepth(uv+offset.xx*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.yy*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.xy*texelSize));vec3 dmin=dtl;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+dmin.xy*texelSize,dmin.z);}vec4 clip_aabb(const in vec4 aabb_min,const in vec4 aabb_max,vec4 p){const float FLT_EPS=1e-8;vec4 p_clip=0.5*(aabb_max+aabb_min);vec4 e_clip=0.5*(aabb_max-aabb_min)+FLT_EPS;vec4 v_clip=p-p_clip;vec4 v_unit=abs(v_clip/e_clip);float ma_unit=max(v_unit.x,max(v_unit.y,v_unit.z));if(ma_unit>1.0)return p_clip+v_clip/ma_unit;else return p;}
41
- #if HAS_VELOCITY_BUFFER == 0
42
- vec2 computeScreenSpaceVelocity(const in vec3 worldPosition){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(worldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(worldPosition,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}
43
- #endif
44
- vec4 computeTAA(const in vec2 uv,const in vec2 screenSpaceVelocity){vec2 jitterOffset=jitterSample/previousRTSize;vec2 uvUnJitter=uv;vec4 currentColor=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter));vec4 previousColor=previousRTTexelToLinear(texture2D(previousRT,uv-screenSpaceVelocity));const vec3 offset=vec3(1.,-1.,0.);vec2 texelSize=1./previousRTSize;float texelSpeed=length(screenSpaceVelocity);vec4 tl=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yx*texelSize));vec4 tc=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.zx*texelSize));vec4 tr=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.xx*texelSize));vec4 ml=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yz*texelSize));vec4 mc=currentColor;vec4 mr=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.xz*texelSize));vec4 bl=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yy*texelSize));vec4 bc=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.zy*texelSize));vec4 br=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.xy*texelSize));vec4 corners=2.0*(tr+bl+br+tl)-2.0*mc;mc+=(mc-(corners*0.166667))*2.718282*0.3;mc=max(vec4(0.0),mc);vec4 min5=min(tc,min(ml,min(mc,min(mr,bc))));vec4 max5=max(tc,max(ml,max(mc,max(mr,bc))));vec4 cmin=min(min5,min(tl,min(tr,min(bl,br))));vec4 cmax=max(min5,max(tl,max(tr,max(bl,br))));;cmin=0.5*(cmin+min5);cmax=0.5*(cmax+max5);previousColor=clip_aabb(cmin,cmax,previousColor);float lum0=luminance(currentColor.rgb);float lum1=luminance(previousColor.rgb);float unbiased_diff=abs(lum0-lum1)/max(lum0,max(lum1,0.2));float unbiased_weight=1.0-unbiased_diff;float unbiased_weight_sqr=unbiased_weight*unbiased_weight;float k_feedback=mix(feedBack.x,feedBack.y,unbiased_weight_sqr);return mix(currentColor,previousColor,k_feedback);}vec3 getWorldPositionFromViewZ(const in vec2 uv,const in float viewDepth){vec2 uv_=2.*uv-1.;float xe=-(uv_.x+projection[2][0])*viewDepth/projection[0][0];float ye=-(uv_.y+projection[2][1])*viewDepth/projection[1][1];return(inverseViewMatrix*vec4(xe,ye,viewDepth,1.)).xyz;}void main(){vec2 jitterOffset=jitterSample/previousRTSize;
45
- #if HAS_VELOCITY_BUFFER == 0
46
- #if QUALITY == 1
47
- vec3 c_frag=find_closest_fragment_3x3(vUv);
48
- #else
49
- vec3 c_frag=find_closest_fragment_5tap(vUv);
50
- #endif
51
- #else
52
- vec3 c_frag=vec3(0.0);
53
- #endif
54
- if(c_frag.z>=0.999){gl_FragColor=currentRTTexelToLinear(texture2D(currentRT,vUv-jitterOffset));}else{
55
- #if HAS_VELOCITY_BUFFER == 0
56
- float sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);
57
- #else
58
- screenSpaceVelocity=getVelocity(vUv);
59
- #endif
60
- gl_FragColor=firstFrame ? currentRTTexelToLinear(texture2D(currentRT,vUv)): computeTAA(vUv,screenSpaceVelocity);
61
- #ifdef DEBUG_VELOCITY
62
- gl_FragColor=vec4(10.*length(screenSpaceVelocity));
63
- #endif
64
- }
65
- #include <encodings_fragment>
66
- }`;var k=Object.defineProperty,I=Object.getOwnPropertyDescriptor,T=(u,t,r,n)=>{for(var i=n>1?void 0:n?I(t,r):t,a=u.length-1,s;a>=0;a--)(s=u[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&k(t,r,i),i};const j="taa",C=class C extends e.PipelinePassPlugin{constructor(t=!0){super(),this.passId=j,this._stableNoise=!0,this._gbufferUnpackExtension=void 0,this._gbufferUnpackExtensionChanged=()=>{if(!this._pass||!this._viewer)throw new Error("TemporalAAPlugin: pass/viewer not created yet");const r=this._viewer.renderManager.gbufferUnpackExtension;this._gbufferUnpackExtension!==r&&(this._gbufferUnpackExtension&&this._pass.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]),this._gbufferUnpackExtension=r,this._gbufferUnpackExtension?this._pass.material.registerMaterialExtensions([this._gbufferUnpackExtension]):this._viewer.console.warn("TemporalAAPlugin: GBuffer unpack extension removed"))},this.dependencies=[e.GBufferPlugin,e.ProgressivePlugin],this.uiConfig={type:"folder",label:"TemporalAA Plugin",onChange:this.setDirty.bind(this),children:[...e.generateUiConfig(this)||[]]},this.enabled=t,this.setDirty=this.setDirty.bind(this)}get stableNoise(){var t;return((t=this._viewer)==null?void 0:t.renderManager.stableNoise)??this._stableNoise}set stableNoise(t){this._viewer&&(this._viewer.renderManager.stableNoise=t),this._stableNoise=t}_createPass(){if(!this._viewer)throw new Error("TemporalAAPlugin: viewer not set");if(!this._viewer.renderManager.gbufferTarget||!this._viewer.renderManager.gbufferUnpackExtension)throw new Error("TemporalAAPlugin: GBuffer target not created. GBufferPlugin is required.");return new b(this.passId,this._viewer.getPlugin(e.ProgressivePlugin).target)}onAdded(t){super.onAdded(t),this._gbufferUnpackExtensionChanged(),t.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),t.renderManager.addEventListener("resize",this._pass.onSizeUpdate)}onRemove(t){t.renderManager.removeEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),t.renderManager.removeEventListener("resize",this._pass.onSizeUpdate),super.onRemove(t)}_beforeRender(t,r,n){if(!super._beforeRender(t,r,n))return!1;const i=this.pass,a=this._viewer;if(!i||!a)return!1;const s=n.frameCount;if(i.taaEnabled=s<=1&&t.renderCamera===t.mainCamera,!i.taaEnabled)return!1;const l=r;return l?(l.updateMatrixWorld(!0),l.updateShaderProperties(i.material),i.updateCameraProperties(l),i.target=a.getPlugin(e.ProgressivePlugin).target,!0):!1}};C.PluginType="TAA",C.OldPluginType="TemporalAAPlugin";let x=C;T([e.uiToggle("Stable Noise (Total frame count)")],x.prototype,"stableNoise",1),T([e.uiConfig()],x.prototype,"_pass",2);class b extends e.ExtendedShaderPass{constructor(t,r){var n;super({vertexShader:e.CopyShader.vertexShader,fragmentShader:V,uniforms:{currentRT:{value:null},previousRT:{value:null},previousRTSize:{value:new e.Vector2},cameraNearFar:{value:new e.Vector2},lastProjectionViewMatrix:{value:new e.Matrix4},currentProjectionViewMatrix:{value:new e.Matrix4},projection:{value:new e.Matrix4},inverseViewMatrix:{value:new e.Matrix4},jitterSample:{value:new e.Vector2},firstFrame:{value:!0}},defines:{QUALITY:1,UNJITTER:0}},"currentRT","previousRT"),this.before=["progressive"],this.after=[],this.required=["render","progressive"],this.taaEnabled=!0,this.feedBack=new e.Vector2(.88,.97),this.debugVelocity=!1,this.uiConfig={type:"folder",label:"Temporal AA Pass",onChange:this.setDirty,children:[{type:"checkbox",label:"Enabled",property:[this,"enabled"],onChange:()=>this.onSizeUpdate()},...((n=e.generateUiConfig(this))==null?void 0:n.filter(i=>i&&i.label!=="Enabled"))||[]]},this.passId=t,this.onSizeUpdate=this.onSizeUpdate.bind(this),this.target=r,this.clear=!1,this.needsSwap=!0}render(t,r,n,i,a){if(!this.taaEnabled||!this.enabled){this.needsSwap=!1;return}this.needsSwap=!0,this.uniforms.previousRT.value=this.target.texture,super.render(t,r,n,i,a),this.uniforms.lastProjectionViewMatrix.value.copy(this.uniforms.currentProjectionViewMatrix.value),this.uniforms.firstFrame.value=!1}updateCameraProperties(t){t&&(this.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this.uniforms.inverseViewMatrix.value.copy(t.matrixWorld))}onSizeUpdate(){this.uniforms.firstFrame.value=!0,this.setDirty()}setSize(t,r){super.setSize(t,r),this.onSizeUpdate()}}T([e.serialize(),e.uniform(),e.uiVector("Feedback",void 0,1e-4)],b.prototype,"feedBack",2),T([e.uiToggle(),e.matDefineBool("DEBUG_VELOCITY",void 0,!1,void 0,!0)],b.prototype,"debugVelocity",2);var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,D=(u,t,r,n)=>{for(var i=n>1?void 0:n?H(t,r):t,a=u.length-1,s;a>=0;a--)(s=u[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&G(t,r,i),i};o.VelocityBufferPlugin=class extends e.PipelinePassPlugin{constructor(t=e.UnsignedByteType,r=!0,n=!0){super(),this.passId="velocityBuffer",this.material=new U,this.unpackExtension={shaderExtender:i=>{i.fragmentShader=e.shaderReplaceString(i.fragmentShader,"//velocity_unpack",`
67
- `+A+`
68
- `)},extraUniforms:{tVelocity:()=>{var i;return{value:(i=this.target)==null?void 0:i.texture}}},extraDefines:{HAS_VELOCITY_BUFFER:()=>{var i;return(i=this.target)!=null&&i.texture?1:void 0}},priority:100,isCompatible:()=>!0},this.enabled=r,this.bufferType=t,this._attachToTaa=n}_createTarget(t=!0){this._viewer&&(t&&this._disposeTarget(),this.target||(this.target=this._viewer.renderManager.createTarget({depthBuffer:!0,samples:0,type:this.bufferType,generateMipmaps:!1,colorSpace:e.LinearSRGBColorSpace})),this.texture=this.target.texture,this.texture.name="velocityBuffer",this._pass&&(this._pass.target=this.target))}_disposeTarget(){this._viewer&&(this.target&&(this._viewer.renderManager.disposeTarget(this.target),this.target=void 0),this.texture=void 0)}_createPass(){if(this._createTarget(!0),!this.target)throw new Error("VelocityBufferPlugin: target not created");this.material.userData.isGBufferMaterial=!0;const t=this._viewer,r=new class extends e.GBufferRenderPass{constructor(){super(...arguments),this._firstCall=!0}render(i,a,s,l,c){if(t.renderManager.frameCount>0||!this.enabled||!this.camera)return;const f=this.overrideMaterial;f.uniforms.currentProjectionViewMatrix.value.copy(this.camera.projectionMatrix).multiply(this.camera.matrixWorldInverse),this._firstCall&&(f.uniforms.lastProjectionViewMatrix.value.copy(f.uniforms.currentProjectionViewMatrix.value),this._firstCall=!1),super.render(i,a,s,l,c),f.uniforms.lastProjectionViewMatrix.value.copy(f.uniforms.currentProjectionViewMatrix.value)}}(this.passId,this.target,this.material,new e.Color(.5,.5,.5),1),n=r.preprocessMaterial;return r.preprocessMaterial=i=>{var a;return n(i,(a=i.userData[o.VelocityBufferPlugin.PluginType])==null?void 0:a.disabled)},r.before=["render"],r.after=[],r.required=["render"],r}onAdded(t){var r;if(super.onAdded(t),this._attachToTaa){const n=t.getPlugin(x);n?(r=n.pass)==null||r.material.registerMaterialExtensions([this.unpackExtension]):t.console.warn("VelocityBufferPlugin: TemporalAAPlugin not found, set attachToTaa to false if not required")}}onRemove(t){var r,n;return this._disposeTarget(),this._attachToTaa&&((n=(r=t.getPlugin(x))==null?void 0:r.pass)==null||n.material.unregisterMaterialExtensions([this.unpackExtension])),super.onRemove(t)}_beforeRender(t,r,n){if(!super._beforeRender(t,r,n))return!1;const i=this.pass;return!i||n.frameCount>0?!1:(i.scene=t,i.camera=r,r.updateShaderProperties(i.overrideMaterial),!0)}},o.VelocityBufferPlugin.PluginType="VelocityBuffer",o.VelocityBufferPlugin.OldPluginType="VelocityBufferPlugin",D([e.uiImage("Velocity Buffer")],o.VelocityBufferPlugin.prototype,"texture",2),o.VelocityBufferPlugin=D([e.uiFolderContainer("Velocity Buffer Plugin (for TAA)")],o.VelocityBufferPlugin);class U extends e.ShaderMaterial{constructor(){super({vertexShader:O,fragmentShader:N,uniforms:{cameraNearFar:{value:new e.Vector2(.1,1e3)},alphaMap:{value:null},alphaTest:{value:null},alphaMapTransform:{value:new e.Matrix3},currentProjectionViewMatrix:{value:new e.Matrix4},lastProjectionViewMatrix:{value:new e.Matrix4}},blending:e.NoBlending}),this.extraUniformsToUpload={modelMatrixPrevious:{value:new e.Matrix4().identity()}},this._previousWorldMatrices={}}onBeforeRender(t,r,n,i,a){const s=this._previousWorldMatrices[a.uuid];this.extraUniformsToUpload.modelMatrixPrevious.value.copy(s??a.matrixWorld),s?s.copy(a.matrixWorld):this._previousWorldMatrices[a.uuid]=a.matrixWorld.clone();let l=a.material;Array.isArray(l)&&(l=l[0]),this.uniforms.alphaMap.value=(l==null?void 0:l.alphaMap)??null,this.uniforms.alphaTest.value=!l||!l.alphaTest||l.alphaTest<1e-7?.001:l.alphaTest;let c=this.uniforms.alphaMap.value?1:void 0;c!==this.defines.USE_ALPHAMAP&&(c===void 0?delete this.defines.USE_ALPHAMAP:this.defines.USE_ALPHAMAP=c,this.needsUpdate=!0),c=l!=null&&l.userData.ALPHA_I_RGBA_PACKING?1:void 0,c!==this.defines.ALPHA_I_RGBA_PACKING&&(c===void 0?delete this.defines.ALPHA_I_RGBA_PACKING:this.defines.ALPHA_I_RGBA_PACKING=c,this.needsUpdate=!0),this.side=(l==null?void 0:l.side)??e.DoubleSide}}const W=`#include <packing>
69
- uniform float intensity;uniform float opacity;uniform vec2 tDiffuseSize;varying vec2 vUv;uniform float weight;
70
- #if PASS_STEP == 0
71
- uniform vec4 prefilter;vec4 Prefilter(vec4 c){
72
- #ifdef HAS_GBUFFER
73
- #if !BACKGROUND_BLOOM
74
- if(getDepth(vUv)>0.999){return vec4(0.0);}
75
- #endif
76
- #endif
77
- float brightness=max(c.r,max(c.g,c.b));float soft=brightness+prefilter.x*(prefilter.y-1.);soft=clamp(soft,0.,prefilter.z);soft=soft*soft*prefilter.w;float contribution=max(soft,brightness-prefilter.x);contribution/=max(brightness,0.001);return vec4(c.rgb*contribution,c.a);}
78
- #endif
79
- vec4 Sample(vec2 uv){return tDiffuseTexelToLinear(texture2D(tDiffuse,uv));}vec4 SampleBox(vec2 uv,float delta){vec4 o=vec2(-delta,delta).xxyy/tDiffuseSize.xyxy;vec4 s=Sample(uv+o.xy)+Sample(uv+o.zy)+Sample(uv+o.xw)+Sample(uv+o.zw);return s*0.25;}int getBloomBit(in int number){
80
- #ifdef WebGL2Context
81
- return(number/4)% 2;
82
- #else
83
- return int(mod(floor(float(number)/4.),2.));
84
- #endif
85
- }void main(){
86
- #if PASS_STEP == 0
87
- #ifdef GBUFFER_HAS_FLAGS
88
- int doBloom=getBloomBit(getGBufferFlags(vUv).a);
89
- #else
90
- int doBloom=1;
91
- #endif
92
- gl_FragColor=float(doBloom)*weight*Prefilter(SampleBox(vUv,1.));gl_FragColor.a=1.;
93
- #elif PASS_STEP == 1
94
- gl_FragColor=weight*(SampleBox(vUv,1.));gl_FragColor.a=1.;
95
- #elif PASS_STEP == 2
96
- gl_FragColor=(SampleBox(vUv,0.5));gl_FragColor.a=1.;
97
- #elif PASS_STEP == 3
98
- vec4 texel=tSourceTexelToLinear(texture2D(tSource,vUv));vec4 bloom=intensity*SampleBox(vUv,0.5).rgba;float brightness=max(bloom.r,max(bloom.g,bloom.b));texel.rgb+=bloom.rgb;texel.a=min(1.,texel.a+brightness);gl_FragColor=texel;
99
- #elif PASS_STEP == 4
100
- vec4 texel=vec4(0.);texel.rgb+=intensity*SampleBox(vUv,0.5).rgb;texel.a=1.;gl_FragColor=texel;
101
- #endif
102
- #include <encodings_fragment>
103
- }`;var Y=Object.defineProperty,$=Object.getOwnPropertyDescriptor,S=(u,t,r,n)=>{for(var i=n>1?void 0:n?$(t,r):t,a=u.length-1,s;a>=0;a--)(s=u[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&Y(t,r,i),i};const q="bloom",B=(v=class extends e.PipelinePassPlugin{constructor(){super(...arguments),this.passId=q,this.materialExtension=e.uiConfigMaterialExtension(this._getUiConfig.bind(this),v.PluginType),this.dependencies=[e.GBufferPlugin],this._onPluginAdd=t=>{var n,i,a,s;if(((i=(n=t.plugin)==null?void 0:n.constructor)==null?void 0:i.PluginType)!==e.GBufferPlugin.PluginType)return;const r=t.plugin;r.registerGBufferUpdater(this.constructor.PluginType,this.updateGBufferFlags.bind(this)),(a=this._pass)==null||a.material.registerMaterialExtensions([r.unpackExtension]),(s=this._viewer)==null||s.removeEventListener("addPlugin",this._onPluginAdd)},this.uiConfig={type:"folder",label:"Bloom Plugin",onChange:this.setDirty.bind(this),children:[...e.generateUiConfig(this)||[]]}}_createPass(){return new o.BloomPluginPass(this.passId)}onAdded(t){super.onAdded(t);const r=t.getPlugin(e.GBufferPlugin);r?(r.registerGBufferUpdater(this.constructor.PluginType,this.updateGBufferFlags.bind(this)),this._pass.material.registerMaterialExtensions([r.unpackExtension])):t.addEventListener("addPlugin",this._onPluginAdd),t.materialManager.registerMaterialExtension(this.materialExtension)}onRemove(t){var n;t.removeEventListener("addPlugin",this._onPluginAdd);const r=t.getPlugin(e.GBufferPlugin);r==null||r.unregisterGBufferUpdater(this.constructor.PluginType),r&&((n=this._pass)==null||n.material.unregisterMaterialExtensions([r.unpackExtension])),t.materialManager.unregisterMaterialExtension(this.materialExtension),super.onRemove(t)}updateGBufferFlags(t,r){var a;if(!r.material||!r.material.userData)return;const i=((a=r.material.userData[v.PluginType])==null?void 0:a.enable)===!1||r.material.userData.pluginsDisabled?0:1;t.w=e.updateBit(t.w,2,i)}static AddBloomData(t,r,n=!0){const i=t==null?void 0:t.userData;if(!i)return null;i[v.PluginType]||(i[v.PluginType]={});const a=i[v.PluginType];return a.enable=!0,r&&Object.assign(a,r),n&&t.setDirty&&t.setDirty(),a}_getUiConfig(t){const r={type:"folder",label:"Bloom",children:[{type:"checkbox",label:"Enabled",get value(){var n;return((n=t.userData[v.PluginType])==null?void 0:n.enable)??!0},set value(n){var a;let i=t.userData[v.PluginType];n!==(i==null?void 0:i.enable)&&(i||(i=v.AddBloomData(t,void 0,!1)),i.enable=n,t.setDirty(),(a=r.uiRefresh)==null||a.call(r,!0,"postFrame"))},onChange:this.setDirty}]};return r}},v.PluginType="Bloom",v.OldPluginType="BloomPlugin",v);S([e.uiConfig()],B.prototype,"_pass",2);let M=B;o.BloomPluginPass=class extends e.ExtendedShaderPass{constructor(t){super({vertexShader:e.CopyShader.vertexShader,defines:{PASS_STEP:1},uniforms:{tSource:{value:null},tDiffuse:{value:null},opacity:{value:1},tDiffuseSize:{value:new e.Vector2},weight:{value:1}},fragmentShader:W},"tDiffuse","tSource"),this.uiConfig=void 0,this.before=["screen"],this.after=["render","progressive"],this.required=["render"],this.prefilter=new e.Vector4(2,.5,0,0),this.threshold=2,this.softThreshold=.5,this.intensity=.2,this.backgroundBloom=!1,this.bloomIterations=4,this.radius=.6,this.power=1,this.bloomDebug=!1,this._weights=[],this.passId=t,this._updateWeights=this._updateWeights.bind(this),this._thresholdsUpdated=this._thresholdsUpdated.bind(this),this._updateWeights(),this._thresholdsUpdated(),this.clear=!0}_thresholdsUpdated(){this.prefilter.x=this.threshold,this.prefilter.y=this.softThreshold,this.prefilter.z=2*this.prefilter.x*this.prefilter.y,this.prefilter.w=.125/(this.uniforms.prefilter.value.z+1e-5)}render(t,r,n,i,a){const s=t.renderManager;this.material.defines.PASS_STEP=0,this.clear=!0,this.needsSwap=!1;const l=n;if(!l){console.warn("BloomPluginPass: No source to read from");return}this.needsSwap=!0;let c=.5,f=l.width*c,d=l.height*c;const E=[];let _=s.getTempTarget({sizeMultiplier:1,type:e.HalfFloatType});E.push(_);let P=l;this.material.needsUpdate=!0,this.material.uniforms.weight.value=this._weights[0],super.render(t,_,P,i,a),P=_;let h=1;for(;h<this.bloomIterations&&(f/=2,d/=2,c/=2,!(d<2||f<2));h++){_=s.getTempTarget({sizeMultiplier:c,type:e.HalfFloatType}),E.push(_),this.material.defines.PASS_STEP=1;let z=this._weights[h];z=this._weights[h-1]!==0?this._weights[h]/this._weights[h-1]:this._weights[h],this.material.uniforms.weight.value=z,this.material.needsUpdate=!0,super.render(t,_,P,i,a),P=_}this.clear=!1;const de=t.autoClear;for(t.autoClear=!1,h-=2;h>=0;h--)_=E[h],E[h]=void 0,this.material.defines.PASS_STEP=2,this.material.transparent=!0,this.material.blending=e.AdditiveBlending,this.material.needsUpdate=!0,t.autoClear=!1,super.render(t,_,P,i,a),this.material.blending=e.NoBlending,s.releaseTempTarget(P),P=_;this.clear=!0,t.autoClear=de,t.autoClear=!0,this.bloomDebug?(this.material.defines.PASS_STEP=4,this.material.needsUpdate=!0,super.render(t,r,P,i,a)):(this.uniforms.tSource.value=l.texture,this.material.defines.PASS_STEP=3,this.material.needsUpdate=!0,super.render(t,r,P,i,a),this.uniforms.tSource.value=null),s.releaseTempTarget(P)}_updateWeights(){if(!this._weights)return;const t=Math.max(Math.min(this.radius,1),0),r=1/(this.bloomIterations-1);for(let n=0;n<this.bloomIterations;n++){let i=n*r+.1,a=1.2-i;i=Math.pow(i,this.power),a=Math.pow(a,this.power),this._weights[n]=a*(1-t)+i*t}this.setDirty()}},S([e.uniform()],o.BloomPluginPass.prototype,"prefilter",2),S([e.uiSlider("Threshold",[0,2]),e.onChange(o.BloomPluginPass.prototype._thresholdsUpdated),e.serialize()],o.BloomPluginPass.prototype,"threshold",2),S([e.uiSlider("Soft Threshold",[0,1]),e.onChange(o.BloomPluginPass.prototype._thresholdsUpdated),e.serialize()],o.BloomPluginPass.prototype,"softThreshold",2),S([e.uiSlider("Intensity",[0,3]),e.serialize(),e.uniform()],o.BloomPluginPass.prototype,"intensity",2),S([e.uiToggle("Background Bloom"),e.serialize(),e.matDefine("BACKGROUND_BLOOM",void 0,!1,void 0,u=>u?"1":"0",u=>u&&u!=="0")],o.BloomPluginPass.prototype,"backgroundBloom",2),S([e.uiSlider("Iterations",[0,7],1),e.onChange(o.BloomPluginPass.prototype._updateWeights),e.serialize()],o.BloomPluginPass.prototype,"bloomIterations",2),S([e.uiSlider("Radius",[0,1],.01),e.onChange(o.BloomPluginPass.prototype._updateWeights),e.serialize()],o.BloomPluginPass.prototype,"radius",2),S([e.uiSlider("Power",[.2,10],.01),e.onChange(o.BloomPluginPass.prototype._updateWeights),e.serialize()],o.BloomPluginPass.prototype,"power",2),S([e.uiToggle("Debug")],o.BloomPluginPass.prototype,"bloomDebug",2),o.BloomPluginPass=S([e.uiFolderContainer("Bloom Pass")],o.BloomPluginPass);const K=`#include <common>
104
- #include <packing>
105
- varying vec2 vUv;uniform vec2 cocTextureSize;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;uniform vec2 crossCenter;uniform float crossRadius;uniform float crossAlpha;uniform vec3 crossColor;float smoothBoundary(float d,float smooothFactor){smooothFactor*=0.5;float value=smoothstep(-smooothFactor,smooothFactor,d);return value;}float circle(vec2 p,float r){return min((length(p)-r),-(length(p)-r-0.01));}float computeCoc(){float depth=getDepth(vUv);if(depth>1.0-0.01)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){vec4 blur=blurTextureTexelToLinear(texture2D(blurTexture,vUv));float scale=0.5;blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(1.0,1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(-1.0,1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(-1.0,-1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(1.0,-1.0)/cocTextureSize));blur/=5.0;vec2 uvNearest=(floor(vUv*cocTextureSize)+0.5)/cocTextureSize;float coc=abs(min(2.*cocTextureTexelToLinear(texture2D(cocTexture,uvNearest)).a-1.,computeCoc()));float cocLower=0.005;float cocHigher=0.3;vec4 outColor=vec4(mix(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,blur.rgb,smoothstep(cocLower,cocHigher,coc)),1.0);vec2 d=vUv-crossCenter;if(length(d)>crossRadius+0.05){float dist=circle(d,crossRadius);gl_FragColor=outColor;}else{d.x*=cocTextureSize.x/cocTextureSize.y;float dist=circle(d,crossRadius);dist=smoothBoundary(dist,2.*fwidth(dist));vec4 color=outColor;vec3 dofCircleColor=mix(crossColor,color.rgb,1.-crossAlpha);gl_FragColor=vec4(mix(color.rgb,dofCircleColor,dist),color.a);}
106
- #include <encodings_fragment>
107
- }`,Z=`#include <randomHelpers>
108
- #include <common>
109
- varying vec2 vUv;uniform vec2 colorTextureSize;uniform float blurRadius;uniform float frameCount;vec4 CircularBlur(){vec4 color=colorTextureTexelToLinear(texture2D(colorTexture,vUv));
110
- #ifdef DOF_MODE
111
- float blurDist=blurRadius*(2.*color.a-1.);
112
- #else
113
- float blurDist=blurRadius*color.a;
114
- #endif
115
- float rnd=PI2*random3(vec3(vUv,frameCount*0.1));float costheta=cos(rnd);float sintheta=sin(rnd);vec4 rotationMatrix=vec4(costheta,-sintheta,sintheta,costheta);vec3 colorSum=vec3(0.0);float weightSum=0.001;vec2 ofs;vec4 sampleColor;setPds();
116
- #pragma unroll_loop_start
117
- for(int i=0;i<16;i++){ofs=poisson_disk_samples[UNROLLED_LOOP_INDEX];ofs=vec2(dot(ofs,rotationMatrix.xy),dot(ofs,rotationMatrix.zw));sampleColor=colorTextureTexelToLinear(texture2D(colorTexture,vUv+blurDist*ofs/colorTextureSize.xy));
118
- #ifdef DOF_MODE
119
- sampleColor.a=abs(sampleColor.a*2.0-1.0);sampleColor.a*=sampleColor.a*sampleColor.a;
120
- #endif
121
- colorSum+=sampleColor.rgb*sampleColor.a;weightSum+=sampleColor.a;}
122
- #pragma unroll_loop_end
123
- colorSum/=weightSum;return vec4(min(vec3(72.),max(vec3(0.),colorSum)),1.0);}void main(){gl_FragColor=CircularBlur();
124
- #include <encodings_fragment>
125
- }`,J="vec2 poisson_disk_samples[16];void setPds(){poisson_disk_samples[0]=vec2(-0.399691779231,0.728591545584);poisson_disk_samples[1]=vec2(-0.48622557676,-0.84016533712);poisson_disk_samples[2]=vec2(0.770309468987,-0.24906070432);poisson_disk_samples[3]=vec2(0.556596796154,0.820359876432);poisson_disk_samples[4]=vec2(-0.933902004071,0.0600539051593);poisson_disk_samples[5]=vec2(0.330144964342,0.207477293384);poisson_disk_samples[6]=vec2(0.289013230975,-0.686749271417);poisson_disk_samples[7]=vec2(-0.0832470893559,-0.187351643125);poisson_disk_samples[8]=vec2(-0.296314525615,0.254474834305);poisson_disk_samples[9]=vec2(-0.850977666059,0.484642744689);poisson_disk_samples[10]=vec2(0.829287915319,0.2345063545);poisson_disk_samples[11]=vec2(-0.773042143899,-0.543741521254);poisson_disk_samples[12]=vec2(0.0561133030864,0.928419742597);poisson_disk_samples[13]=vec2(-0.205799249508,-0.562072714492);poisson_disk_samples[14]=vec2(-0.526991665882,-0.193690188118);poisson_disk_samples[15]=vec2(-0.051789270667,-0.935374050821);}",Q=`#include <common>
126
- #include <packing>
127
- varying vec2 vUv;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;float computeCoc(){float depth=getDepth(vUv);if(depth==1.0)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*computeCoc()+0.5);
128
- #include <encodings_fragment>
129
- }`,X=`#include <common>
130
- #include <gbuffer_unpack>
131
- varying vec2 vUv;uniform vec2 colorTextureSize;uniform vec2 direction;uniform vec2 nearFarBlurScale;const float MAXIMUM_BLUR_SIZE=4.0;float expandNear(const in vec2 offset,const in bool isBackground){float coc=0.0;vec2 sampleOffsets=MAXIMUM_BLUR_SIZE*offset/5.0;float coc0=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv)).a-1.;float coc1=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-5.0*sampleOffsets)).a-1.;float coc2=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-4.0*sampleOffsets)).a-1.;float coc3=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-3.0*sampleOffsets)).a-1.;float coc4=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-2.0*sampleOffsets)).a-1.;float coc5=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-1.0*sampleOffsets)).a-1.;float coc6=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+1.0*sampleOffsets)).a-1.;float coc7=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+2.0*sampleOffsets)).a-1.;float coc8=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+3.0*sampleOffsets)).a-1.;float coc9=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+4.0*sampleOffsets)).a-1.;float coc10=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+5.0*sampleOffsets)).a-1.;if(isBackground){coc=abs(coc0)*0.095474+(abs(coc1)+abs(coc10))*0.084264+(abs(coc2)+abs(coc9))*0.088139+(abs(coc3)+abs(coc8))*0.091276+(abs(coc4)+abs(coc7))*0.093585+(abs(coc5)+abs(coc6))*0.094998;}else{coc=min(coc0,0.0);coc=min(coc1*0.3,coc);coc=min(coc2*0.5,coc);coc=min(coc3*0.75,coc);coc=min(coc4*0.8,coc);coc=min(coc5*0.95,coc);coc=min(coc6*0.95,coc);coc=min(coc7*0.8,coc);coc=min(coc8*0.75,coc);coc=min(coc9*0.5,coc);coc=min(coc10*0.3,coc);if(abs(coc0)>abs(coc))coc=coc0;}return coc;}void main(){vec2 offset=2.*direction/colorTextureSize;bool isBackground=getDepth(vUv)>1.0-0.001;float coc=expandNear(offset,isBackground);gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*coc+0.5);
132
- #include <encodings_fragment>
133
- }`;var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,m=(u,t,r,n)=>{for(var i=n>1?void 0:n?te(t,r):t,a=u.length-1,s;a>=0;a--)(s=u[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&ee(t,r,i),i};const ie="depthOfField",w=class w extends e.PipelinePassPlugin{constructor(t=!0,r=!1){super(),this.passId=ie,this.enableEdit=!1,this._focalPointHit=new e.Vector3(0,0,0),this.crossFadeTime=200,this._focalPointHitTime=0,this.dependencies=[e.GBufferPlugin],this._onPluginAdd=n=>{var a,s,l,c,f;const i=n.plugin;if(i){if(((a=i.constructor)==null?void 0:a.PluginType)===e.GBufferPlugin.PluginType){const d=i;(s=this._pass)==null||s.material.registerMaterialExtensions([d.unpackExtension]),(l=this._pass)==null||l.computeCocMaterial.registerMaterialExtensions([d.unpackExtension]),(c=this._pass)==null||c.expandCocMaterial.registerMaterialExtensions([d.unpackExtension])}((f=i.constructor)==null?void 0:f.PluginType)===e.PickingPlugin.PluginType&&i.addEventListener("hitObject",this._onObjectHit)}},this._onPluginRemove=n=>{var a,s,l,c,f;const i=n.plugin;if(i){if(((a=i.constructor)==null?void 0:a.PluginType)===e.GBufferPlugin.PluginType){const d=n.plugin;(s=this._pass)==null||s.material.unregisterMaterialExtensions([d.unpackExtension]),(l=this._pass)==null||l.computeCocMaterial.unregisterMaterialExtensions([d.unpackExtension]),(c=this._pass)==null||c.expandCocMaterial.unregisterMaterialExtensions([d.unpackExtension])}((f=i.constructor)==null?void 0:f.PluginType)===e.PickingPlugin.PluginType&&n.plugin.removeEventListener("hitObject",this._onObjectHit)}},this.uiConfig={type:"folder",label:"DepthOfField",onChange:this.setDirty.bind(this),children:[...e.generateUiConfig(this)||[],()=>{var n;return(n=this._pass)==null?void 0:n.uiConfig}]},this._tempVec=new e.Vector3,this.enabled=t,this.enableEdit=r,this._onObjectHit=this._onObjectHit.bind(this),this.setDirty=this.setDirty.bind(this)}get _frameFadeTime(){return this.crossFadeTime*2.5}setFocalPoint(t,r=!0,n=!1){var i,a;this._focalPointHit.copy(t),r&&((a=(i=this._viewer)==null?void 0:i.getPlugin("FrameFadePlugin"))==null||a.startTransition(this._frameFadeTime)),n&&(this._focalPointHitTime=e.now()),this.setDirty()}getFocalPoint(){return this._focalPointHit}_onObjectHit(t){var r,n;!this._pass||!t.intersects.intersect||this.isDisabled()||!this.enableEdit||(this._focalPointHit.copy(t.intersects.intersect.point),this._focalPointHitTime=t.time,t.intersects.selectedObject=null,(n=(r=this._viewer)==null?void 0:r.getPlugin(e.FrameFadePlugin))==null||n.startTransition(this._frameFadeTime),this.setDirty())}_createPass(){return new o.DepthOfFieldPluginPass(this.passId)}onAdded(t){super.onAdded(t),t.addEventListener("addPlugin",this._onPluginAdd),t.addEventListener("removePlugin",this._onPluginRemove),this._onPluginAdd({plugin:t.getPlugin(e.GBufferPlugin)}),this._onPluginAdd({plugin:t.getPlugin(e.PickingPlugin)})}onRemove(t){t.removeEventListener("addPlugin",this._onPluginAdd),t.removeEventListener("removePlugin",this._onPluginRemove),this._onPluginRemove({plugin:t.getPlugin(e.GBufferPlugin)}),this._onPluginRemove({plugin:t.getPlugin(e.PickingPlugin)}),super.onRemove(t)}_beforeRender(t,r,n){if(!super._beforeRender(t,r,n))return!1;const i=this.pass;if(!i)return!1;i.dofBlurMaterial.uniforms.frameCount&&(n==null||n.updateShaderProperties(i.dofBlurMaterial));const a=r;if(!a)return!1;a.updateMatrixWorld(!0),a.updateShaderProperties(i.material),a.getWorldPosition(this._tempVec),this._tempVec.subVectors(this._focalPointHit,this._tempVec),i.focalDepthRange.x=this._tempVec.length(),i.focalDepthRange.x*=a.getWorldDirection(new e.Vector3).dot(this._tempVec.normalize());let s=(e.now()-this._focalPointHitTime)/this.crossFadeTime;if(s=1-Math.min(1,Math.max(0,s)),Math.abs(s-i.crossAlpha)>.01&&(i.crossAlpha=s,this.setDirty()),s>0){const l=this._tempVec.copy(this._focalPointHit).project(a).addScalar(1).divideScalar(2);i.crossCenter.set(l.x,l.y),i.computeCocMaterial.uniformsNeedUpdate=!0,i.expandCocMaterial.uniformsNeedUpdate=!0}return!0}};w.PluginType="DepthOfField",w.OldPluginType="DepthOfFieldPlugin";let p=w;m([e.serialize(),e.uiToggle()],p.prototype,"enableEdit",2),m([e.serialize("focalPoint")],p.prototype,"_focalPointHit",2),m([e.serialize()],p.prototype,"crossFadeTime",2);const re=new e.ExtendedShaderMaterial({uniforms:{colorTexture:{value:null},colorTextureSize:{value:new e.Vector2},direction:{value:new e.Vector2},frameCount:{value:0},blurRadius:{value:16}},vertexShader:e.shaderUtils.defaultVertex,fragmentShader:J+`
134
- `+Z,defines:{DOF_MODE:1}},["colorTexture"]);o.DepthOfFieldPluginPass=class extends e.ExtendedShaderPass{constructor(t){super({uniforms:{colorTexture:{value:null},blurTexture:{value:null},cocTexture:{value:null},cocTextureSize:{value:new e.Vector2},cameraNearFar:{value:new e.Vector2}},vertexShader:e.shaderUtils.defaultVertex,fragmentShader:K},"colorTexture","cocTexture","blurTexture"),this.uiConfig=void 0,this.before=["progressive","screen"],this.after=["render"],this.required=["render"],this.dofBlurMaterial=re,this.nearFarBlurScale=new e.Vector2(.25,.25),this.focalDepthRange=new e.Vector2(.5,1.5),this.crossCenter=new e.Vector2(.5,.5),this.crossRadius=.04,this.crossAlpha=1,this.crossColor=new e.Color(16750848),this.passId=t,this.computeCocMaterial=new e.ExtendedShaderMaterial({uniforms:{colorTexture:{value:null},cameraNearFar:this.uniforms.cameraNearFar,nearFarBlurScale:this.uniforms.nearFarBlurScale,focalDepthRange:this.uniforms.focalDepthRange},vertexShader:e.shaderUtils.defaultVertex,fragmentShader:Q},["colorTexture"]),this.expandCocMaterial=new e.ExtendedShaderMaterial({uniforms:{colorTexture:{value:null},colorTextureSize:{value:new e.Vector2},direction:{value:new e.Vector2},nearFarBlurScale:this.uniforms.nearFarBlurScale},vertexShader:e.shaderUtils.defaultVertex,fragmentShader:X},["colorTexture"])}render(t,r,n,i,a){if(!this.enabled)return;if(!n){console.error("DepthOfFieldPluginPass: No readBuffer");return}const s=t.renderManager,l={minFilter:e.NearestFilter,magFilter:e.NearestFilter,type:e.HalfFloatType,colorSpace:e.LinearSRGBColorSpace,sizeMultiplier:.5,format:e.RGBAFormat,depthBuffer:!1,generateMipmaps:!1},c=s.getTempTarget(l),f=s.getTempTarget(l);if(this.computeCocMaterial.uniforms.colorTexture.value=n.texture,s.blit(c,{material:this.computeCocMaterial}),this.expandCocMaterial.uniforms.colorTexture.value=c.texture,this.expandCocMaterial.uniforms.direction.value.set(1,0),s.blit(f,{material:this.expandCocMaterial}),this.expandCocMaterial.uniforms.colorTexture.value=f.texture,this.expandCocMaterial.uniforms.direction.value.set(0,1),s.blit(c,{material:this.expandCocMaterial}),this.dofBlurMaterial.uniforms.frameCount)this.dofBlurMaterial.uniforms.colorTexture.value=c.texture,s.blit(f,{material:this.dofBlurMaterial});else{const d=s.getTempTarget(l);this.dofBlurMaterial.uniforms.cocTexture.value=c.texture,this.dofBlurMaterial.uniforms.colorTexture.value=c.texture,this.dofBlurMaterial.uniforms.direction.value.set(1,0),s.blit(d,{material:this.dofBlurMaterial}),this.dofBlurMaterial.uniforms.colorTexture.value=d.texture,this.dofBlurMaterial.uniforms.direction.value.set(0,1),s.blit(f,{material:this.dofBlurMaterial}),s.releaseTempTarget(d)}this.material.uniforms.blurTexture.value=f.texture,this.material.uniforms.cocTexture.value=c.texture,super.render(t,r,n,i,a),s.releaseTempTarget(c),s.releaseTempTarget(f)}},m([e.bindToValue({obj:"focalDepthRange",key:"y"}),e.uiSlider("Depth Range",[.25,3])],o.DepthOfFieldPluginPass.prototype,"depthRange",2),m([e.bindToValue({obj:"nearFarBlurScale",key:"x"}),e.uiSlider("Near Blur Scale",[0,1])],o.DepthOfFieldPluginPass.prototype,"nearBlurScale",2),m([e.bindToValue({obj:"nearFarBlurScale",key:"y"}),e.uiSlider("Far Blur Scale",[0,1])],o.DepthOfFieldPluginPass.prototype,"farBlurScale",2),m([e.serialize(),e.uniform()],o.DepthOfFieldPluginPass.prototype,"nearFarBlurScale",2),m([e.serialize(),e.uniform()],o.DepthOfFieldPluginPass.prototype,"focalDepthRange",2),m([e.uniform()],o.DepthOfFieldPluginPass.prototype,"crossCenter",2),m([e.uniform()],o.DepthOfFieldPluginPass.prototype,"crossRadius",2),m([e.uniform()],o.DepthOfFieldPluginPass.prototype,"crossAlpha",2),m([e.uniform()],o.DepthOfFieldPluginPass.prototype,"crossColor",2),o.DepthOfFieldPluginPass=m([e.uiFolderContainer("DepthOfField Pass")],o.DepthOfFieldPluginPass);const R=`#ifndef SSRT_PARS_SNIP
135
- #define SSRT_PARS_SNIP
136
- #define pow2(a) a*a
137
- float getDepth2(const in vec2 uv,const in float lod){float viewDepth=getDepth(uv);return depthToViewZ(viewDepth);}
138
- #define LOD_DEPTH 1.0
139
- #define LOD_COLOR 5.0
140
- void _traceRay(in vec4 ray_origin,in vec4 ray_dir,in float tolerance,inout vec3 state,in int loopMax,in float iStepCount){vec4 sample_uv;float d,hit;float dLod=0.;
141
- #pragma unroll_loop_start
142
- for(int i=0;i<8;i++){if(UNROLLED_LOOP_INDEX<loopMax){sample_uv=ray_origin+ray_dir*state.y;d=getDepth2(sample_uv.xy,dLod);d=sample_uv.z/sample_uv.w-d;if(abs(d+tolerance)<tolerance){hit=clamp(state.x/(state.x-d),0.,1.)-1.;hit=(state.y+hit*iStepCount);state.z=min(state.z,hit);}state.x=d;state.y+=1.*iStepCount;}}
143
- #pragma unroll_loop_end
144
- }vec3 traceRay(in vec3 ray_origin_view,in vec3 ray_dir_view,in float tolerance,inout vec3 state,in int _STEP_COUNT){vec4 sample_uv;vec4 ray_origin=viewToScreen3(ray_origin_view);vec3 ray_end_view=ray_origin_view+ray_dir_view;vec4 ray_dir=viewToScreen3(ray_end_view);vec2 clamp_end=clamp(ray_dir.xy,vec2(0.),vec2(1.));vec2 correction=abs(ray_dir.xy-clamp_end);correction=(step(0.01,correction)*correction/(abs(clamp_end-ray_origin.xy)+0.01))+1.;correction.x=1./min(max(correction.y,correction.x),10.);ray_dir=ray_dir-ray_origin;ray_dir.xyw*=correction.x;float iStepCount=1./float(_STEP_COUNT);tolerance*=0.125;_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT,iStepCount);if(_STEP_COUNT>8&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-8,iStepCount);if(_STEP_COUNT>15&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);if(_STEP_COUNT>23&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);sample_uv=ray_origin+ray_dir*state.z;sample_uv.z/=sample_uv.w;state.z=state.z<0.999 ? state.z : 9999999.;return sample_uv.xyz;}/**for ray clippinga=ray_originb=ray_endc=clamp(b)x=c.y-a.yy=b.y-c.y(c.y-a.y)/(b.y-c.y)=m/(l-m)m/(l-m)=km=kl-kmm=kl/(1+k)((c-a)/(b-c))/(1+(c-a)/(b-c))x/(y*(1+x/y))x/(y+x)1/(y/x+1)x/(y+yx)1/(y/x+y)ray scale=k/(1+k)1/(1/k+1)=1/((b-c)/(c-a)+1)**/
145
- #endif
146
- `;var ne=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,y=(u,t,r,n)=>{for(var i=n>1?void 0:n?ae(t,r):t,a=u.length-1,s;a>=0;a--)(s=u[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&ne(t,r,i),i};o.SSContactShadowsPlugin=class extends e.AViewerPluginSync{constructor(t=!0){super(),this.enabled=!0,this._uniforms={sscsRadius:{value:.03},sscsIntensity:{value:1},sscsTolerance:{value:1.5},frameCount:{value:0},projection:{value:new e.Matrix4},cameraPositionWorld:{value:new e.Vector3},cameraNearFar:{value:new e.Vector2(.1,1e3)},sceneBoundingRadius:{value:0}},this.radius=.015,this.intensity=1,this.tolerance=1.5,this._defines={PERSPECTIVE_CAMERA:1},this.onlySSCSDebug=!1,this.stepCount=2,this.dependencies=[e.GBufferPlugin],this.materialExtension={uuid:o.SSContactShadowsPlugin.PluginType,shaderExtender:(r,n,i)=>{var c,f;if(!r.defines.SSCS_ENABLED)return;const a="float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {",s=e.glsl`
7
+ */var i;var r=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=(e,t,i,a)=>{for(var o,s=a>1?void 0:a?n(t,i):t,l=e.length-1;l>=0;l--)(o=e[l])&&(s=(a?o(t,i,s):o(s))||s);return a&&s&&r(t,i,s),s};const o=class extends t.PipelinePassPlugin{constructor(e=!0){super(),this.passId="taa",this._stableNoise=!0,this._gbufferUnpackExtension=void 0,this._gbufferUnpackExtensionChanged=()=>{if(!this._pass||!this._viewer)throw new Error("TemporalAAPlugin: pass/viewer not created yet");const e=this._viewer.renderManager.gbufferUnpackExtension;this._gbufferUnpackExtension!==e&&(this._gbufferUnpackExtension&&this._pass.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]),this._gbufferUnpackExtension=e,this._gbufferUnpackExtension?this._pass.material.registerMaterialExtensions([this._gbufferUnpackExtension]):this._viewer.console.warn("TemporalAAPlugin: GBuffer unpack extension removed"))},this.dependencies=[t.GBufferPlugin,t.ProgressivePlugin],this.uiConfig={type:"folder",label:"TemporalAA Plugin",onChange:this.setDirty.bind(this),children:[...t.generateUiConfig(this)||[]]},this.enabled=e,this.setDirty=this.setDirty.bind(this)}get stableNoise(){var e;return(null==(e=this._viewer)?void 0:e.renderManager.stableNoise)??this._stableNoise}set stableNoise(e){this._viewer&&(this._viewer.renderManager.stableNoise=e),this._stableNoise=e}_createPass(){if(!this._viewer)throw new Error("TemporalAAPlugin: viewer not set");if(!this._viewer.renderManager.gbufferTarget||!this._viewer.renderManager.gbufferUnpackExtension)throw new Error("TemporalAAPlugin: GBuffer target not created. GBufferPlugin is required.");const e=!!this._viewer.renderManager.msaa;return new l(this.passId,(()=>{var e,i;return null==(i=null==(e=this._viewer)?void 0:e.getPlugin(t.ProgressivePlugin))?void 0:i.target}),e)}onAdded(e){super.onAdded(e),this._gbufferUnpackExtensionChanged(),e.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),e.renderManager.addEventListener("resize",this._pass.onSizeUpdate)}onRemove(e){e.renderManager.removeEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),e.renderManager.removeEventListener("resize",this._pass.onSizeUpdate),super.onRemove(e)}_beforeRender(e,i,r){if(!super._beforeRender(e,i,r))return!1;const n=this.pass,a=this._viewer;if(!n||!a)return!1;const o=r.frameCount;if(n.taaEnabled=o<=1&&e.renderCamera===e.mainCamera,!n.taaEnabled)return!1;const s=i;return!!s&&(s.updateMatrixWorld(!0),s.updateShaderProperties(n.material),n.updateCameraProperties(s),n.target=a.getPlugin(t.ProgressivePlugin).target,!0)}};o.PluginType="TAA",o.OldPluginType="TemporalAAPlugin";let s=o;a([t.uiToggle("Stable Noise (Total frame count)")],s.prototype,"stableNoise",1),a([t.uiConfig()],s.prototype,"_pass",2);class l extends t.ExtendedShaderPass{constructor(e,i,r=!0){var n;super({vertexShader:t.CopyShader.vertexShader,fragmentShader:"#include <common>\n#include <gbuffer_unpack>\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#endif\n#include <cameraHelpers>\nvarying vec2 vUv;uniform vec2 previousRTSize;uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;uniform mat4 inverseViewMatrix;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;\n#ifndef HAS_VELOCITY_BUFFER\n#define HAS_VELOCITY_BUFFER 0\n#endif\nvec3 find_closest_fragment_3x3(const in vec2 uv){const vec3 offset=vec3(-1.0,1.0,0.0);vec2 texelSize=1.0/previousRTSize;vec3 dtr=vec3(1,1,getDepth(uv+offset.yy*texelSize));vec3 dtc=vec3(0,1,getDepth(uv+offset.zy*texelSize));vec3 dtl=vec3(-1,1,getDepth(uv+offset.xy*texelSize));vec3 dml=vec3(-1,0,getDepth(uv+offset.xz*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dmr=vec3(1,0,getDepth(uv+offset.yz*texelSize));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.xx*texelSize));vec3 dbc=vec3(0,-1,getDepth(uv+offset.zx*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.yx*texelSize));vec3 dmin=dtl;if(dmin.z>dtc.z)dmin=dtc;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dml.z)dmin=dml;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dmr.z)dmin=dmr;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbc.z)dmin=dbc;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+texelSize.xy*dmin.xy,dmin.z);}vec3 find_closest_fragment_5tap(const in vec2 uv){vec2 texelSize=1.0/previousRTSize;vec2 offset=vec2(1.0,-1.0);vec3 dtl=vec3(-1,1,getDepth(uv+offset.yx*texelSize));vec3 dtr=vec3(1,1,getDepth(uv+offset.xx*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.yy*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.xy*texelSize));vec3 dmin=dtl;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+dmin.xy*texelSize,dmin.z);}vec4 clip_aabb(const in vec4 aabb_min,const in vec4 aabb_max,vec4 p){const float FLT_EPS=1e-8;vec4 p_clip=0.5*(aabb_max+aabb_min);vec4 e_clip=0.5*(aabb_max-aabb_min)+FLT_EPS;vec4 v_clip=p-p_clip;vec4 v_unit=abs(v_clip/e_clip);float ma_unit=max(v_unit.x,max(v_unit.y,v_unit.z));if(ma_unit>1.0)return p_clip+v_clip/ma_unit;else return p;}\n#if HAS_VELOCITY_BUFFER == 0\nvec2 computeScreenSpaceVelocity(const in vec3 worldPosition){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(worldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(worldPosition,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}\n#endif\nvec4 currentRTTexelToLinear1(vec4 a){if(isinf(a.x)||isinf(a.y)||isinf(a.z)||isinf(a.w)){return vec4(1.);}return currentRTTexelToLinear(a);}vec4 computeTAA(const in vec2 uv,const in vec2 screenSpaceVelocity,const in float feedbackScale){vec2 uvUnJitter=uv;vec4 currentColor=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter));vec4 previousColor=previousRTTexelToLinear(texture2D(previousRT,uv-screenSpaceVelocity));const vec3 offset=vec3(1.,-1.,0.);vec2 texelSize=1./previousRTSize;float texelSpeed=length(screenSpaceVelocity);vec4 tl=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yx*texelSize));vec4 tc=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.zx*texelSize));vec4 tr=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xx*texelSize));vec4 ml=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yz*texelSize));vec4 mc=currentColor;vec4 mr=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xz*texelSize));vec4 bl=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yy*texelSize));vec4 bc=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.zy*texelSize));vec4 br=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xy*texelSize));vec4 corners=2.0*(tr+bl+br+tl)-2.0*mc;mc+=(mc-(corners*0.166667))*2.718282*0.3;mc=max(vec4(0.0),mc);vec4 min5=min(tc,min(ml,min(mc,min(mr,bc))));vec4 max5=max(tc,max(ml,max(mc,max(mr,bc))));vec4 cmin=min(min5,min(tl,min(tr,min(bl,br))));vec4 cmax=max(min5,max(tl,max(tr,max(bl,br))));;cmin=0.5*(cmin+min5);cmax=0.5*(cmax+max5);previousColor=clip_aabb(cmin,cmax,previousColor);float lum0=luminance(currentColor.rgb);float lum1=luminance(previousColor.rgb);float unbiased_diff=abs(lum0-lum1)/max(lum0,max(lum1,0.2));float unbiased_weight=1.0-unbiased_diff;float unbiased_weight_sqr=unbiased_weight*unbiased_weight;float k_feedback=mix(feedBack.x,feedBack.y,unbiased_weight_sqr);return mix(currentColor,previousColor,clamp(k_feedback*feedbackScale,0.,1.));}vec3 getWorldPositionFromViewZ(const in vec2 uv,const in float viewDepth){vec2 uv_=2.*uv-1.;float xe=-(uv_.x+projection[2][0])*viewDepth/projection[0][0];float ye=-(uv_.y+projection[2][1])*viewDepth/projection[1][1];return(inverseViewMatrix*vec4(xe,ye,viewDepth,1.)).xyz;}void main(){\n#if HAS_VELOCITY_BUFFER == 0\n#if QUALITY == 1\nvec3 c_frag=find_closest_fragment_3x3(vUv);\n#else\nvec3 c_frag=find_closest_fragment_5tap(vUv);\n#endif\n#else\nvec3 c_frag=vec3(vUv,0.);\n#endif\nbool bg=firstFrame;\n#if BACKGROUND_TAA\nfloat d=c_frag.z;float edgef=min(1.,max(0.,1.-(d*100.-99.)));\n#else\nbg=bg||c_frag.z>0.999;\n#endif\nif(firstFrame){gl_FragColor=currentRTTexelToLinear1(texture2D(currentRT,vUv));}else{\n#if HAS_VELOCITY_BUFFER == 0\nfloat sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);\n#else\nvec2 screenSpaceVelocity=getVelocity(c_frag.xy);\n#endif\n#if BACKGROUND_TAA\ngl_FragColor=computeTAA(vUv,screenSpaceVelocity*edgef,edgef);\n#else\ngl_FragColor=computeTAA(vUv,screenSpaceVelocity,1.);\n#endif\n}\n#include <encodings_fragment>\n#ifdef DEBUG_VELOCITY\nfloat sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);gl_FragColor=vec4(10.*length(screenSpaceVelocity),0.,0.,1.);\n#endif\n}",uniforms:{currentRT:{value:null},previousRT:{value:null},previousRTSize:{value:new t.Vector2},cameraNearFar:{value:new t.Vector2},lastProjectionViewMatrix:{value:new t.Matrix4},currentProjectionViewMatrix:{value:new t.Matrix4},projection:{value:new t.Matrix4},inverseViewMatrix:{value:new t.Matrix4},jitterSample:{value:new t.Vector2},firstFrame:{value:!0}},defines:{QUALITY:1,UNJITTER:0,BACKGROUND_TAA:r?1:0}},"currentRT","previousRT"),this.before=["progressive"],this.after=[],this.required=["render","progressive"],this.taaEnabled=!0,this.feedBack=new t.Vector2(.88,.97),this.debugVelocity=!1,this.uiConfig={type:"folder",label:"Temporal AA Pass",onChange:this.setDirty,children:[{type:"checkbox",label:"Enabled",property:[this,"enabled"],onChange:()=>this.onSizeUpdate()},...(null==(n=t.generateUiConfig(this))?void 0:n.filter((e=>e&&"Enabled"!==e.label)))||[]]},this.passId=e,this.onSizeUpdate=this.onSizeUpdate.bind(this),this.target=i,this.clear=!1,this.needsSwap=!0}render(e,i,r,n,a){var o;this.taaEnabled&&this.enabled?(this.needsSwap=!0,this.uniforms.previousRT.value=(null==(o=t.getOrCall(this.target))?void 0:o.texture)??null,super.render(e,i,r,n,a),this.uniforms.lastProjectionViewMatrix.value.copy(this.uniforms.currentProjectionViewMatrix.value),this.uniforms.firstFrame.value=!1):this.needsSwap=!1}updateCameraProperties(e){e&&(this.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this.uniforms.inverseViewMatrix.value.copy(e.matrixWorld))}onSizeUpdate(){this.uniforms.firstFrame.value=!0,this.setDirty()}setSize(e,t){super.setSize(e,t),this.onSizeUpdate()}}a([t.serialize(),t.uniform(),t.uiVector("Feedback",void 0,1e-4)],l.prototype,"feedBack",2),a([t.uiToggle(),t.matDefineBool("DEBUG_VELOCITY",void 0,!1,void 0,!0)],l.prototype,"debugVelocity",2);var c=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=(e,t,i,r)=>{for(var n,a=r>1?void 0:r?u(t,i):t,o=e.length-1;o>=0;o--)(n=e[o])&&(a=(r?n(t,i,a):n(a))||a);return r&&a&&c(t,i,a),a};e.VelocityBufferPlugin=class extends t.PipelinePassPlugin{constructor(e=t.UnsignedByteType,i=!0,r=!0){super(),this.passId="velocityBuffer",this.material=new f,this.unpackExtension={shaderExtender:e=>{this.isDisabled()||(e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"#pragma <velocity_unpack>","\n#if defined(HAS_VELOCITY_BUFFER)\nuniform sampler2D tVelocity;vec2 getVelocity(const in vec2 uv){vec2 screenSpaceVelocity=texture2D(tVelocity,uv).xy*2.0-1.0;return sign(screenSpaceVelocity)*pow(abs(screenSpaceVelocity),vec2(4.));}\n#endif\n\n"))},computeCacheKey:()=>this.isDisabled()?"":"vb",extraUniforms:{tVelocity:()=>{var e;return{value:this.isDisabled()?null:null==(e=this.target)?void 0:e.texture}}},extraDefines:{HAS_VELOCITY_BUFFER:()=>{var e;return!this.isDisabled()&&(null==(e=this.target)?void 0:e.texture)?1:void 0}},priority:100,isCompatible:()=>!0},this.enabled=i,this.bufferType=e,this._attachToTaa=r}_createTarget(e=!0){this._viewer&&(e&&this._disposeTarget(),this.target||(this.target=this._viewer.renderManager.createTarget({depthBuffer:!0,samples:0,type:this.bufferType,generateMipmaps:!1,colorSpace:t.LinearSRGBColorSpace})),this.texture=this.target.texture,this.texture.name="velocityBuffer",this._pass&&(this._pass.target=this.target))}_disposeTarget(){this._viewer&&(this.target&&(this._viewer.renderManager.disposeTarget(this.target),this.target=void 0),this.texture=void 0)}_createPass(){if(this._createTarget(!0),!this.target)throw new Error("VelocityBufferPlugin: target not created");this.material.userData.isGBufferMaterial=!0;const i=this._viewer,r=new class extends t.GBufferRenderPass{constructor(){super(...arguments),this._firstCall=!0}render(e,t,r,n,a){if(i.renderManager.frameCount>0)return;if(!this.enabled||!this.camera)return;const o=this.overrideMaterial;o.uniforms.currentProjectionViewMatrix.value.copy(this.camera.projectionMatrix).multiply(this.camera.matrixWorldInverse),this._firstCall&&(o.uniforms.lastProjectionViewMatrix.value.copy(o.uniforms.currentProjectionViewMatrix.value),this._firstCall=!1),super.render(e,t,r,n,a),o.uniforms.lastProjectionViewMatrix.value.copy(o.uniforms.currentProjectionViewMatrix.value)}}(this.passId,this.target,this.material,new t.Color(.5,.5,.5),1),n=r.preprocessMaterial;return r.preprocessMaterial=t=>{var i;return n(t,null==(i=t.userData[e.VelocityBufferPlugin.PluginType])?void 0:i.disabled)},r.before=["render"],r.after=[],r.required=["render"],r}onAdded(e){var t;if(super.onAdded(e),this._attachToTaa){const i=e.getPlugin(s);i?null==(t=i.pass)||t.material.registerMaterialExtensions([this.unpackExtension]):e.console.warn("VelocityBufferPlugin: TemporalAAPlugin not found, set attachToTaa to false if not required")}}onRemove(e){var t,i;return this._disposeTarget(),this._attachToTaa&&(null==(i=null==(t=e.getPlugin(s))?void 0:t.pass)||i.material.unregisterMaterialExtensions([this.unpackExtension])),super.onRemove(e)}setDirty(){var e,t;super.setDirty(),null==(t=(e=this.unpackExtension).setDirty)||t.call(e)}_beforeRender(e,t,i){if(!super._beforeRender(e,t,i))return!1;const r=this.pass;return!!r&&(!(i.frameCount>0)&&(r.scene=e,r.camera=t,t.updateShaderProperties(r.overrideMaterial),!0))}},e.VelocityBufferPlugin.PluginType="VelocityBuffer",e.VelocityBufferPlugin.OldPluginType="VelocityBufferPlugin",d([t.uiImage("Velocity Buffer")],e.VelocityBufferPlugin.prototype,"texture",2),e.VelocityBufferPlugin=d([t.uiFolderContainer("Velocity Buffer Plugin (for TAA)")],e.VelocityBufferPlugin);class f extends t.ShaderMaterial{constructor(){super({vertexShader:"#ifdef USE_ALPHAMAP\n#define USE_UV\n#endif\n#include <uv_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 modelMatrixPrevious;void main(){\n#include <uv_vertex>\n#include <skinbase_vertex>\n#include <begin_vertex>\n#include <morphtarget_vertex>\n#include <skinning_vertex>\n#include <displacementmap_vertex>\nvec4 mvPosition=vec4(transformed,1.0);\n#ifdef USE_INSTANCING\nmvPosition=instanceMatrix*mvPosition;\n#endif\nvWorldPosition=(modelMatrix*mvPosition).xyz;vWorldPositionPrevious=(modelMatrixPrevious*mvPosition).xyz;mvPosition=modelViewMatrix*mvPosition;gl_Position=projectionMatrix*mvPosition;\n#include <logdepthbuf_vertex>\n#include <clipping_planes_vertex>\n}",fragmentShader:"varying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 currentProjectionViewMatrix;uniform mat4 lastProjectionViewMatrix;vec2 computeScreenSpaceVelocity2(){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(vWorldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(vWorldPositionPrevious,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}void main(){vec2 velocity=clamp(computeScreenSpaceVelocity2(),-1.0,1.0);velocity=sign(velocity)*pow(abs(velocity),vec2(1./4.));velocity=velocity*0.5+0.5;gl_FragColor=vec4(velocity.x,velocity.y,1.,1.);}",uniforms:{cameraNearFar:{value:new t.Vector2(.1,1e3)},alphaMap:{value:null},alphaTest:{value:null},alphaMapTransform:{value:new t.Matrix3},currentProjectionViewMatrix:{value:new t.Matrix4},lastProjectionViewMatrix:{value:new t.Matrix4}},blending:t.NoBlending}),this.extraUniformsToUpload={modelMatrixPrevious:{value:(new t.Matrix4).identity()}},this._previousWorldMatrices={}}onBeforeRender(e,i,r,n,a){const o=this._previousWorldMatrices[a.uuid];this.extraUniformsToUpload.modelMatrixPrevious.value.copy(o??a.matrixWorld),o?o.copy(a.matrixWorld):this._previousWorldMatrices[a.uuid]=a.matrixWorld.clone();let s=a.material;Array.isArray(s)&&(s=s[0]),this.uniforms.alphaMap.value=(null==s?void 0:s.alphaMap)??null,this.uniforms.alphaTest.value=!s||!s.alphaTest||s.alphaTest<1e-7?.001:s.alphaTest;let l=this.uniforms.alphaMap.value?1:void 0;l!==this.defines.USE_ALPHAMAP&&(void 0===l?delete this.defines.USE_ALPHAMAP:this.defines.USE_ALPHAMAP=l,this.needsUpdate=!0),l=(null==s?void 0:s.userData.ALPHA_I_RGBA_PACKING)?1:void 0,l!==this.defines.ALPHA_I_RGBA_PACKING&&(void 0===l?delete this.defines.ALPHA_I_RGBA_PACKING:this.defines.ALPHA_I_RGBA_PACKING=l,this.needsUpdate=!0),this.side=(null==s?void 0:s.side)??t.DoubleSide}}var p=Object.defineProperty,h=Object.getOwnPropertyDescriptor,g=(e,t,i,r)=>{for(var n,a=r>1?void 0:r?h(t,i):t,o=e.length-1;o>=0;o--)(n=e[o])&&(a=(r?n(t,i,a):n(a))||a);return r&&a&&p(t,i,a),a};const v=(i=class extends t.PipelinePassPlugin{constructor(){super(...arguments),this.passId="bloom",this.materialExtension=t.uiConfigMaterialExtension(this._getUiConfig.bind(this),i.PluginType),this.dependencies=[t.GBufferPlugin],this._onPluginAdd=e=>{var i,r,n,a;if((null==(r=null==(i=e.plugin)?void 0:i.constructor)?void 0:r.PluginType)!==t.GBufferPlugin.PluginType)return;const o=e.plugin;o.registerGBufferUpdater(this.constructor.PluginType,this.updateGBufferFlags.bind(this)),null==(n=this._pass)||n.material.registerMaterialExtensions([o.unpackExtension]),null==(a=this._viewer)||a.removeEventListener("addPlugin",this._onPluginAdd)},this.uiConfig={type:"folder",label:"Bloom Plugin",onChange:this.setDirty.bind(this),children:[...t.generateUiConfig(this)||[]]}}_createPass(){var t;return new e.BloomPluginPass(this.passId,Math.min(8,(null==(t=this._viewer)?void 0:t.renderManager.maxHDRIntensity)||8))}onAdded(e){super.onAdded(e);const i=e.getPlugin(t.GBufferPlugin);i?(i.registerGBufferUpdater(this.constructor.PluginType,this.updateGBufferFlags.bind(this)),this._pass.material.registerMaterialExtensions([i.unpackExtension])):e.addEventListener("addPlugin",this._onPluginAdd),e.materialManager.registerMaterialExtension(this.materialExtension)}onRemove(e){var i;e.removeEventListener("addPlugin",this._onPluginAdd);const r=e.getPlugin(t.GBufferPlugin);null==r||r.unregisterGBufferUpdater(this.constructor.PluginType),r&&(null==(i=this._pass)||i.material.unregisterMaterialExtensions([r.unpackExtension])),e.materialManager.unregisterMaterialExtension(this.materialExtension),super.onRemove(e)}updateGBufferFlags(e,r){var n;if(!r.material||!r.material.userData)return;const a=!1===(null==(n=r.material.userData[i.PluginType])?void 0:n.enable)||r.material.userData.pluginsDisabled?0:1;e.w=t.updateBit(e.w,2,a)}static AddBloomData(e,t,r=!0){const n=null==e?void 0:e.userData;if(!n)return null;n[i.PluginType]||(n[i.PluginType]={});const a=n[i.PluginType];return a.enable=!0,t&&Object.assign(a,t),r&&e.setDirty&&e.setDirty(),a}_getUiConfig(e){const t={type:"folder",label:"Bloom",children:[{type:"checkbox",label:"Enabled",get value(){var t;return(null==(t=e.userData[i.PluginType])?void 0:t.enable)??!0},set value(r){var n;let a=e.userData[i.PluginType];r!==(null==a?void 0:a.enable)&&(a||(a=i.AddBloomData(e,void 0,!1)),a.enable=r,e.setDirty(),null==(n=t.uiRefresh)||n.call(t,!0,"postFrame"))},onChange:this.setDirty}]};return t}},i.PluginType="Bloom",i.OldPluginType="BloomPlugin",i);g([t.uiConfig()],v.prototype,"_pass",2);let m=v;e.BloomPluginPass=class extends t.ExtendedShaderPass{constructor(e,i=16){super({vertexShader:t.CopyShader.vertexShader,defines:{PASS_STEP:1,MAX_INTENSITY:Math.min(i,16)},uniforms:{tSource:{value:null},tDiffuse:{value:null},opacity:{value:1},tDiffuseSize:{value:new t.Vector2},weight:{value:1}},fragmentShader:"#include <packing>\nuniform float intensity;uniform float opacity;uniform vec2 tDiffuseSize;varying vec2 vUv;uniform float weight;\n#if PASS_STEP == 0\nuniform vec4 prefilter;vec4 Prefilter(vec4 c){\n#ifdef HAS_GBUFFER\n#if !BACKGROUND_BLOOM\nif(getDepth(vUv)>0.999){return vec4(0.0);}\n#endif\n#endif\nfloat brightness=max(c.r,max(c.g,c.b));float soft=brightness+prefilter.x*(prefilter.y-1.);soft=clamp(soft,0.,prefilter.z);soft=soft*soft*prefilter.w;float contribution=max(soft,brightness-prefilter.x);contribution/=max(brightness,0.001);return vec4(c.rgb*contribution,c.a);}\n#endif\nvec4 Sample(vec2 uv){return min(vec4(MAX_INTENSITY,MAX_INTENSITY,MAX_INTENSITY,1.),tDiffuseTexelToLinear(texture2D(tDiffuse,uv)));}vec4 SampleBox(vec2 uv,float delta){vec4 o=vec2(-delta,delta).xxyy/tDiffuseSize.xyxy;vec4 s=Sample(uv+o.xy)+Sample(uv+o.zy)+Sample(uv+o.xw)+Sample(uv+o.zw);return s*0.25;}int getBloomBit(in int number){\n#ifdef WebGL2Context\nreturn(number/4)% 2;\n#else\nreturn int(mod(floor(float(number)/4.),2.));\n#endif\n}void main(){\n#if PASS_STEP == 0\n#ifdef GBUFFER_HAS_FLAGS\nint doBloom=getBloomBit(getGBufferFlags(vUv).a);\n#else\nint doBloom=1;\n#endif\ngl_FragColor=float(doBloom)*weight*Prefilter(SampleBox(vUv,1.));gl_FragColor.a=1.;\n#elif PASS_STEP == 1\ngl_FragColor=weight*(SampleBox(vUv,1.));gl_FragColor.a=1.;\n#elif PASS_STEP == 2\ngl_FragColor=(SampleBox(vUv,0.5));gl_FragColor.a=1.;\n#elif PASS_STEP == 3\nvec4 texel=tSourceTexelToLinear(texture2D(tSource,vUv));vec4 bloom=intensity*SampleBox(vUv,0.5).rgba;float brightness=max(bloom.r,max(bloom.g,bloom.b));texel.rgb+=bloom.rgb;texel.a=min(1.,texel.a+brightness);gl_FragColor=texel;\n#elif PASS_STEP == 4\nvec4 texel=vec4(0.);texel.rgb+=intensity*SampleBox(vUv,0.5).rgb;texel.a=1.;gl_FragColor=texel;\n#endif\n#include <encodings_fragment>\n}"},"tDiffuse","tSource"),this.uiConfig=void 0,this.before=["screen"],this.after=["render","progressive"],this.required=["render"],this.prefilter=new t.Vector4(2,.5,0,0),this.threshold=2,this.softThreshold=.5,this.intensity=.2,this.backgroundBloom=!1,this.bloomIterations=4,this._currentIterations=0,this.radius=.6,this.power=1,this.bloomDebug=!1,this._weights=[],this.passId=e,this._updateWeights=this._updateWeights.bind(this),this._thresholdsUpdated=this._thresholdsUpdated.bind(this),this._updateWeights(),this._thresholdsUpdated(),this.clear=!0}_thresholdsUpdated(){var e;this.prefilter.x=this.threshold,this.prefilter.y=this.softThreshold,this.prefilter.z=2*this.prefilter.x*this.prefilter.y,this.prefilter.w=(null==(e=this.uniforms)?void 0:e.prefilter)?.125/(this.uniforms.prefilter.value.z+1e-5):0}render(e,i,r,n,a){const o=e.renderManager;this.material.defines.PASS_STEP=0,this.clear=!0,this.needsSwap=!1;const s=r;if(!s)return void console.warn("BloomPluginPass: No source to read from");this.needsSwap=!0;let l=.5,c=s.width*l,u=s.height*l;const d=[];let f=o.getTempTarget({sizeMultiplier:1,type:t.HalfFloatType});d.push(f);let p=s;this.material.needsUpdate=!0,this.material.uniforms.weight.value=this._weights[0],super.render(e,f,p,n,a),p=f;const h=this._currentIterations;let g=1;const v=Math.max(2,this.bloomIterations);for(;g<v&&(c/=2,u/=2,l/=2,!(u<2||c<2));g++){f=o.getTempTarget({sizeMultiplier:l,type:t.HalfFloatType}),d.push(f),this.material.defines.PASS_STEP=1;let i=this._weights[g];i=0!==this._weights[g-1]?this._weights[g]/this._weights[g-1]:this._weights[g],this.material.uniforms.weight.value=i,this.material.needsUpdate=!0,super.render(e,f,p,n,a),p=f,this._currentIterations=g+1}h!==this._currentIterations&&this._updateWeights(!1),this.clear=!1;const m=e.autoClear;for(e.autoClear=!1,g-=2;g>=0;g--)f=d[g],d[g]=void 0,this.material.defines.PASS_STEP=2,this.material.transparent=!0,this.material.blending=t.AdditiveBlending,this.material.needsUpdate=!0,e.autoClear=!1,super.render(e,f,p,n,a),this.material.blending=t.NoBlending,o.releaseTempTarget(p),p=f;this.clear=!0,e.autoClear=m,e.autoClear=!0,this.bloomDebug?(this.material.defines.PASS_STEP=4,this.material.needsUpdate=!0,super.render(e,i,p,n,a)):(this.uniforms.tSource.value=s.texture,this.material.defines.PASS_STEP=3,this.material.needsUpdate=!0,super.render(e,i,p,n,a),this.uniforms.tSource.value=null),o.releaseTempTarget(p)}_updateWeights(e=!0){if(!this._weights)return;const t=Math.max(Math.min(this.radius,1),0),i=Math.max(2,this._currentIterations||this.bloomIterations),r=1/(i-1);for(let n=0;n<i;n++){let e=n*r+.1,i=1.2-e;e=Math.pow(e,this.power),i=Math.pow(i,this.power),this._weights[n]=i*(1-t)+e*t}!1!==e&&this.setDirty()}},g([t.uniform()],e.BloomPluginPass.prototype,"prefilter",2),g([t.uiSlider("Threshold",[0,2]),t.onChange(e.BloomPluginPass.prototype._thresholdsUpdated),t.serialize()],e.BloomPluginPass.prototype,"threshold",2),g([t.uiSlider("Soft Threshold",[0,1]),t.onChange(e.BloomPluginPass.prototype._thresholdsUpdated),t.serialize()],e.BloomPluginPass.prototype,"softThreshold",2),g([t.uiSlider("Intensity",[0,3]),t.serialize(),t.uniform()],e.BloomPluginPass.prototype,"intensity",2),g([t.uiToggle("Background Bloom"),t.serialize(),t.matDefineBool("BACKGROUND_BLOOM")],e.BloomPluginPass.prototype,"backgroundBloom",2),g([t.uiSlider("Iterations",[2,7],1),t.onChange2(e.BloomPluginPass.prototype._updateWeights),t.serialize()],e.BloomPluginPass.prototype,"bloomIterations",2),g([t.uiSlider("Radius",[0,1],.01),t.onChange2(e.BloomPluginPass.prototype._updateWeights),t.serialize()],e.BloomPluginPass.prototype,"radius",2),g([t.uiSlider("Power",[.2,10],.01),t.onChange2(e.BloomPluginPass.prototype._updateWeights),t.serialize()],e.BloomPluginPass.prototype,"power",2),g([t.uiToggle("Debug")],e.BloomPluginPass.prototype,"bloomDebug",2),e.BloomPluginPass=g([t.uiFolderContainer("Bloom Pass")],e.BloomPluginPass);var S=Object.defineProperty,x=Object.getOwnPropertyDescriptor,_=(e,t,i,r)=>{for(var n,a=r>1?void 0:r?x(t,i):t,o=e.length-1;o>=0;o--)(n=e[o])&&(a=(r?n(t,i,a):n(a))||a);return r&&a&&S(t,i,a),a};const P=class extends t.PipelinePassPlugin{constructor(e=!0,i=!1){super(),this.passId="depthOfField",this.enableEdit=!1,this._focalPointHit=new t.Vector3(0,0,0),this.crossFadeTime=200,this._focalPointHitTime=0,this.dependencies=[t.GBufferPlugin],this._onPluginAdd=e=>{var i,r,n,a,o;const s=e.plugin;if(s){if((null==(i=s.constructor)?void 0:i.PluginType)===t.GBufferPlugin.PluginType){const e=s;null==(r=this._pass)||r.material.registerMaterialExtensions([e.unpackExtension]),null==(n=this._pass)||n.computeCocMaterial.registerMaterialExtensions([e.unpackExtension]),null==(a=this._pass)||a.expandCocMaterial.registerMaterialExtensions([e.unpackExtension])}if((null==(o=s.constructor)?void 0:o.PluginType)===t.PickingPlugin.PluginType){s.addEventListener("hitObject",this._onObjectHit)}}},this._onPluginRemove=e=>{var i,r,n,a,o;const s=e.plugin;if(s){if((null==(i=s.constructor)?void 0:i.PluginType)===t.GBufferPlugin.PluginType){const t=e.plugin;null==(r=this._pass)||r.material.unregisterMaterialExtensions([t.unpackExtension]),null==(n=this._pass)||n.computeCocMaterial.unregisterMaterialExtensions([t.unpackExtension]),null==(a=this._pass)||a.expandCocMaterial.unregisterMaterialExtensions([t.unpackExtension])}if((null==(o=s.constructor)?void 0:o.PluginType)===t.PickingPlugin.PluginType){e.plugin.removeEventListener("hitObject",this._onObjectHit)}}},this.uiConfig={type:"folder",label:"DepthOfField",onChange:this.setDirty.bind(this),children:[...t.generateUiConfig(this)||[],()=>{var e;return null==(e=this._pass)?void 0:e.uiConfig}]},this._tempVec=new t.Vector3,this.enabled=e,this.enableEdit=i,this._onObjectHit=this._onObjectHit.bind(this),this.setDirty=this.setDirty.bind(this)}get _frameFadeTime(){return 2.5*this.crossFadeTime}setFocalPoint(e,i=!0,r=!1){var n,a;this._focalPointHit.copy(e),i&&(null==(a=null==(n=this._viewer)?void 0:n.getPlugin("FrameFadePlugin"))||a.startTransition(this._frameFadeTime)),r&&(this._focalPointHitTime=t.now()),this.setDirty()}getFocalPoint(){return this._focalPointHit}_onObjectHit(e){var i,r;this._pass&&e.intersects.intersect&&!this.isDisabled()&&this.enableEdit&&(this._focalPointHit.copy(e.intersects.intersect.point),this._focalPointHitTime=e.time,e.intersects.selectedObject=null,null==(r=null==(i=this._viewer)?void 0:i.getPlugin(t.FrameFadePlugin))||r.startTransition(this._frameFadeTime),this.setDirty())}_createPass(){return new e.DepthOfFieldPluginPass(this.passId)}onAdded(e){super.onAdded(e),e.addEventListener("addPlugin",this._onPluginAdd),e.addEventListener("removePlugin",this._onPluginRemove),this._onPluginAdd({plugin:e.getPlugin(t.GBufferPlugin)}),this._onPluginAdd({plugin:e.getPlugin(t.PickingPlugin)})}onRemove(e){e.removeEventListener("addPlugin",this._onPluginAdd),e.removeEventListener("removePlugin",this._onPluginRemove),this._onPluginRemove({plugin:e.getPlugin(t.GBufferPlugin)}),this._onPluginRemove({plugin:e.getPlugin(t.PickingPlugin)}),super.onRemove(e)}_beforeRender(e,i,r){if(!super._beforeRender(e,i,r))return!1;const n=this.pass;if(!n)return!1;n.dofBlurMaterial.uniforms.frameCount&&(null==r||r.updateShaderProperties(n.dofBlurMaterial));const a=i;if(!a)return!1;a.updateMatrixWorld(!0),a.updateShaderProperties(n.material),a.getWorldPosition(this._tempVec),this._tempVec.subVectors(this._focalPointHit,this._tempVec),n.focalDepthRange.x=this._tempVec.length(),n.focalDepthRange.x*=a.getWorldDirection(new t.Vector3).dot(this._tempVec.normalize());let o=(t.now()-this._focalPointHitTime)/this.crossFadeTime;if(o=1-Math.min(1,Math.max(0,o)),Math.abs(o-n.crossAlpha)>.01&&(n.crossAlpha=o,this.setDirty()),o>0){const e=this._tempVec.copy(this._focalPointHit).project(a).addScalar(1).divideScalar(2);n.crossCenter.set(e.x,e.y),n.computeCocMaterial.uniformsNeedUpdate=!0,n.expandCocMaterial.uniformsNeedUpdate=!0}return!0}};P.PluginType="DepthOfField",P.OldPluginType="DepthOfFieldPlugin";let y=P;_([t.serialize(),t.uiToggle()],y.prototype,"enableEdit",2),_([t.serialize("focalPoint")],y.prototype,"_focalPointHit",2),_([t.serialize()],y.prototype,"crossFadeTime",2);const T=new t.ExtendedShaderMaterial({uniforms:{colorTexture:{value:null},colorTextureSize:{value:new t.Vector2},direction:{value:new t.Vector2},frameCount:{value:0},blurRadius:{value:16}},vertexShader:t.shaderUtils.defaultVertex,fragmentShader:"vec2 poisson_disk_samples[16];void setPds(){poisson_disk_samples[0]=vec2(-0.399691779231,0.728591545584);poisson_disk_samples[1]=vec2(-0.48622557676,-0.84016533712);poisson_disk_samples[2]=vec2(0.770309468987,-0.24906070432);poisson_disk_samples[3]=vec2(0.556596796154,0.820359876432);poisson_disk_samples[4]=vec2(-0.933902004071,0.0600539051593);poisson_disk_samples[5]=vec2(0.330144964342,0.207477293384);poisson_disk_samples[6]=vec2(0.289013230975,-0.686749271417);poisson_disk_samples[7]=vec2(-0.0832470893559,-0.187351643125);poisson_disk_samples[8]=vec2(-0.296314525615,0.254474834305);poisson_disk_samples[9]=vec2(-0.850977666059,0.484642744689);poisson_disk_samples[10]=vec2(0.829287915319,0.2345063545);poisson_disk_samples[11]=vec2(-0.773042143899,-0.543741521254);poisson_disk_samples[12]=vec2(0.0561133030864,0.928419742597);poisson_disk_samples[13]=vec2(-0.205799249508,-0.562072714492);poisson_disk_samples[14]=vec2(-0.526991665882,-0.193690188118);poisson_disk_samples[15]=vec2(-0.051789270667,-0.935374050821);}\n#include <randomHelpers>\n#include <common>\nvarying vec2 vUv;uniform vec2 colorTextureSize;uniform float blurRadius;uniform float frameCount;vec4 CircularBlur(){vec4 color=colorTextureTexelToLinear(texture2D(colorTexture,vUv));\n#ifdef DOF_MODE\nfloat blurDist=blurRadius*(2.*color.a-1.);\n#else\nfloat blurDist=blurRadius*color.a;\n#endif\nfloat rnd=PI2*random3(vec3(vUv,frameCount*0.1));float costheta=cos(rnd);float sintheta=sin(rnd);vec4 rotationMatrix=vec4(costheta,-sintheta,sintheta,costheta);vec3 colorSum=vec3(0.0);float weightSum=0.001;vec2 ofs;vec4 sampleColor;setPds();\n#pragma unroll_loop_start\nfor(int i=0;i<16;i++){ofs=poisson_disk_samples[UNROLLED_LOOP_INDEX];ofs=vec2(dot(ofs,rotationMatrix.xy),dot(ofs,rotationMatrix.zw));sampleColor=colorTextureTexelToLinear(texture2D(colorTexture,vUv+blurDist*ofs/colorTextureSize.xy));\n#ifdef DOF_MODE\nsampleColor.a=abs(sampleColor.a*2.0-1.0);sampleColor.a*=sampleColor.a*sampleColor.a;\n#endif\ncolorSum+=sampleColor.rgb*sampleColor.a;weightSum+=sampleColor.a;}\n#pragma unroll_loop_end\ncolorSum/=weightSum;return vec4(min(vec3(72.),max(vec3(0.),colorSum)),1.0);}void main(){gl_FragColor=CircularBlur();\n#include <encodings_fragment>\n}",defines:{DOF_MODE:1}},["colorTexture"]);e.DepthOfFieldPluginPass=class extends t.ExtendedShaderPass{constructor(e){super({uniforms:{colorTexture:{value:null},blurTexture:{value:null},cocTexture:{value:null},cocTextureSize:{value:new t.Vector2},cameraNearFar:{value:new t.Vector2}},vertexShader:t.shaderUtils.defaultVertex,fragmentShader:"#include <common>\n#include <packing>\nvarying vec2 vUv;uniform vec2 cocTextureSize;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;uniform vec2 crossCenter;uniform float crossRadius;uniform float crossAlpha;uniform vec3 crossColor;float smoothBoundary(float d,float smooothFactor){smooothFactor*=0.5;float value=smoothstep(-smooothFactor,smooothFactor,d);return value;}float circle(vec2 p,float r){return min((length(p)-r),-(length(p)-r-0.01));}float computeCoc(){float depth=getDepth(vUv);if(depth>1.0-0.01)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){vec4 blur=blurTextureTexelToLinear(texture2D(blurTexture,vUv));float scale=0.5;blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(1.0,1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(-1.0,1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(-1.0,-1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(1.0,-1.0)/cocTextureSize));blur/=5.0;vec2 uvNearest=(floor(vUv*cocTextureSize)+0.5)/cocTextureSize;float coc=abs(min(2.*cocTextureTexelToLinear(texture2D(cocTexture,uvNearest)).a-1.,computeCoc()));float cocLower=0.005;float cocHigher=0.3;vec4 outColor=vec4(mix(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,blur.rgb,smoothstep(cocLower,cocHigher,coc)),1.0);vec2 d=vUv-crossCenter;if(length(d)>crossRadius+0.05){float dist=circle(d,crossRadius);gl_FragColor=outColor;}else{d.x*=cocTextureSize.x/cocTextureSize.y;float dist=circle(d,crossRadius);dist=smoothBoundary(dist,2.*fwidth(dist));vec4 color=outColor;vec3 dofCircleColor=mix(crossColor,color.rgb,1.-crossAlpha);gl_FragColor=vec4(mix(color.rgb,dofCircleColor,dist),color.a);}\n#include <encodings_fragment>\n}"},"colorTexture","cocTexture","blurTexture"),this.uiConfig=void 0,this.before=["progressive","screen"],this.after=["render"],this.required=["render"],this.dofBlurMaterial=T,this.nearFarBlurScale=new t.Vector2(.25,.25),this.focalDepthRange=new t.Vector2(.5,1.5),this.crossCenter=new t.Vector2(.5,.5),this.crossRadius=.04,this.crossAlpha=1,this.crossColor=new t.Color(16750848),this.passId=e,this.computeCocMaterial=new t.ExtendedShaderMaterial({uniforms:{colorTexture:{value:null},cameraNearFar:this.uniforms.cameraNearFar,nearFarBlurScale:this.uniforms.nearFarBlurScale,focalDepthRange:this.uniforms.focalDepthRange},vertexShader:t.shaderUtils.defaultVertex,fragmentShader:"#include <common>\n#include <packing>\nvarying vec2 vUv;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;float computeCoc(){float depth=getDepth(vUv);if(depth==1.0)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*computeCoc()+0.5);\n#include <encodings_fragment>\n}"},["colorTexture"]),this.expandCocMaterial=new t.ExtendedShaderMaterial({uniforms:{colorTexture:{value:null},colorTextureSize:{value:new t.Vector2},direction:{value:new t.Vector2},nearFarBlurScale:this.uniforms.nearFarBlurScale},vertexShader:t.shaderUtils.defaultVertex,fragmentShader:"#include <common>\n#include <gbuffer_unpack>\nvarying vec2 vUv;uniform vec2 colorTextureSize;uniform vec2 direction;uniform vec2 nearFarBlurScale;const float MAXIMUM_BLUR_SIZE=4.0;float expandNear(const in vec2 offset,const in bool isBackground){float coc=0.0;vec2 sampleOffsets=MAXIMUM_BLUR_SIZE*offset/5.0;float coc0=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv)).a-1.;float coc1=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-5.0*sampleOffsets)).a-1.;float coc2=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-4.0*sampleOffsets)).a-1.;float coc3=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-3.0*sampleOffsets)).a-1.;float coc4=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-2.0*sampleOffsets)).a-1.;float coc5=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-1.0*sampleOffsets)).a-1.;float coc6=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+1.0*sampleOffsets)).a-1.;float coc7=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+2.0*sampleOffsets)).a-1.;float coc8=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+3.0*sampleOffsets)).a-1.;float coc9=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+4.0*sampleOffsets)).a-1.;float coc10=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+5.0*sampleOffsets)).a-1.;if(isBackground){coc=abs(coc0)*0.095474+(abs(coc1)+abs(coc10))*0.084264+(abs(coc2)+abs(coc9))*0.088139+(abs(coc3)+abs(coc8))*0.091276+(abs(coc4)+abs(coc7))*0.093585+(abs(coc5)+abs(coc6))*0.094998;}else{coc=min(coc0,0.0);coc=min(coc1*0.3,coc);coc=min(coc2*0.5,coc);coc=min(coc3*0.75,coc);coc=min(coc4*0.8,coc);coc=min(coc5*0.95,coc);coc=min(coc6*0.95,coc);coc=min(coc7*0.8,coc);coc=min(coc8*0.75,coc);coc=min(coc9*0.5,coc);coc=min(coc10*0.3,coc);if(abs(coc0)>abs(coc))coc=coc0;}return coc;}void main(){vec2 offset=2.*direction/colorTextureSize;bool isBackground=getDepth(vUv)>1.0-0.001;float coc=expandNear(offset,isBackground);gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*coc+0.5);\n#include <encodings_fragment>\n}"},["colorTexture"])}render(e,i,r,n,a){if(!this.enabled)return;if(!r)return void console.error("DepthOfFieldPluginPass: No readBuffer");const o=e.renderManager,s={minFilter:t.NearestFilter,magFilter:t.NearestFilter,type:t.HalfFloatType,colorSpace:t.LinearSRGBColorSpace,sizeMultiplier:.5,format:t.RGBAFormat,depthBuffer:!1,generateMipmaps:!1},l=o.getTempTarget(s),c=o.getTempTarget(s);if(this.computeCocMaterial.uniforms.colorTexture.value=r.texture,o.blit(l,{material:this.computeCocMaterial}),this.expandCocMaterial.uniforms.colorTexture.value=l.texture,this.expandCocMaterial.uniforms.direction.value.set(1,0),o.blit(c,{material:this.expandCocMaterial}),this.expandCocMaterial.uniforms.colorTexture.value=c.texture,this.expandCocMaterial.uniforms.direction.value.set(0,1),o.blit(l,{material:this.expandCocMaterial}),this.dofBlurMaterial.uniforms.frameCount)this.dofBlurMaterial.uniforms.colorTexture.value=l.texture,o.blit(c,{material:this.dofBlurMaterial});else{const e=o.getTempTarget(s);this.dofBlurMaterial.uniforms.cocTexture.value=l.texture,this.dofBlurMaterial.uniforms.colorTexture.value=l.texture,this.dofBlurMaterial.uniforms.direction.value.set(1,0),o.blit(e,{material:this.dofBlurMaterial}),this.dofBlurMaterial.uniforms.colorTexture.value=e.texture,this.dofBlurMaterial.uniforms.direction.value.set(0,1),o.blit(c,{material:this.dofBlurMaterial}),o.releaseTempTarget(e)}this.material.uniforms.blurTexture.value=c.texture,this.material.uniforms.cocTexture.value=l.texture,super.render(e,i,r,n,a),o.releaseTempTarget(l),o.releaseTempTarget(c)}},_([t.bindToValue({obj:"focalDepthRange",key:"y"}),t.uiSlider("Depth Range",[.25,3])],e.DepthOfFieldPluginPass.prototype,"depthRange",2),_([t.bindToValue({obj:"nearFarBlurScale",key:"x"}),t.uiSlider("Near Blur Scale",[0,1])],e.DepthOfFieldPluginPass.prototype,"nearBlurScale",2),_([t.bindToValue({obj:"nearFarBlurScale",key:"y"}),t.uiSlider("Far Blur Scale",[0,1])],e.DepthOfFieldPluginPass.prototype,"farBlurScale",2),_([t.serialize(),t.uniform()],e.DepthOfFieldPluginPass.prototype,"nearFarBlurScale",2),_([t.serialize(),t.uniform()],e.DepthOfFieldPluginPass.prototype,"focalDepthRange",2),_([t.uniform()],e.DepthOfFieldPluginPass.prototype,"crossCenter",2),_([t.uniform()],e.DepthOfFieldPluginPass.prototype,"crossRadius",2),_([t.uniform()],e.DepthOfFieldPluginPass.prototype,"crossAlpha",2),_([t.uniform()],e.DepthOfFieldPluginPass.prototype,"crossColor",2),e.DepthOfFieldPluginPass=_([t.uiFolderContainer("DepthOfField Pass")],e.DepthOfFieldPluginPass);const b="#ifndef SSRT_PARS_SNIP\n#define SSRT_PARS_SNIP\n#define pow2(a) a*a\nfloat getDepth2(const in vec2 uv,const in float lod){float viewDepth=getDepth(uv);return depthToViewZ(viewDepth);}\n#define LOD_DEPTH 1.0\n#define LOD_COLOR 5.0\nvoid _traceRay(in vec4 ray_origin,in vec4 ray_dir,in float tolerance,inout vec3 state,in int loopMax,in float iStepCount){vec4 sample_uv;float d,hit;float dLod=0.;\n#pragma unroll_loop_start\nfor(int i=0;i<8;i++){if(UNROLLED_LOOP_INDEX<loopMax){sample_uv=ray_origin+ray_dir*state.y;d=getDepth2(sample_uv.xy,dLod);d=sample_uv.z/sample_uv.w-d;if(abs(d+tolerance)<tolerance){hit=clamp(state.x/(state.x-d),0.,1.)-1.;hit=(state.y+hit*iStepCount);state.z=min(state.z,hit);}state.x=d;state.y+=1.*iStepCount;}}\n#pragma unroll_loop_end\n}vec3 traceRay(in vec3 ray_origin_view,in vec3 ray_dir_view,in float tolerance,inout vec3 state,in int _STEP_COUNT){vec4 sample_uv;vec4 ray_origin=viewToScreen3(ray_origin_view);vec3 ray_end_view=ray_origin_view+ray_dir_view;vec4 ray_dir=viewToScreen3(ray_end_view);vec2 clamp_end=clamp(ray_dir.xy,vec2(0.),vec2(1.));vec2 correction=abs(ray_dir.xy-clamp_end);correction=(step(0.01,correction)*correction/(abs(clamp_end-ray_origin.xy)+0.01))+1.;correction.x=1./min(max(correction.y,correction.x),10.);ray_dir=ray_dir-ray_origin;ray_dir.xyw*=correction.x;float iStepCount=1./float(_STEP_COUNT);tolerance*=0.125;_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT,iStepCount);if(_STEP_COUNT>8&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-8,iStepCount);if(_STEP_COUNT>15&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);if(_STEP_COUNT>23&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);sample_uv=ray_origin+ray_dir*state.z;sample_uv.z/=sample_uv.w;state.z=state.z<0.999 ? state.z : 9999999.;return sample_uv.xyz;}/**for ray clippinga=ray_originb=ray_endc=clamp(b)x=c.y-a.yy=b.y-c.y(c.y-a.y)/(b.y-c.y)=m/(l-m)m/(l-m)=km=kl-kmm=kl/(1+k)((c-a)/(b-c))/(1+(c-a)/(b-c))x/(y*(1+x/y))x/(y+x)1/(y/x+1)x/(y+yx)1/(y/x+y)ray scale=k/(1+k)1/(1/k+1)=1/((b-c)/(c-a)+1)**/\n#endif\n";var C=Object.defineProperty,w=Object.getOwnPropertyDescriptor,E=(e,t,i,r)=>{for(var n,a=r>1?void 0:r?w(t,i):t,o=e.length-1;o>=0;o--)(n=e[o])&&(a=(r?n(t,i,a):n(a))||a);return r&&a&&C(t,i,a),a};e.SSContactShadowsPlugin=class extends t.AViewerPluginSync{constructor(i=!0){super(),this.enabled=!0,this._uniforms={sscsRadius:{value:.03},sscsIntensity:{value:1},sscsTolerance:{value:1.5},frameCount:{value:0},projection:{value:new t.Matrix4},cameraPositionWorld:{value:new t.Vector3},cameraNearFar:{value:new t.Vector2(.1,1e3)},sceneBoundingRadius:{value:0}},this.radius=.015,this.intensity=1,this.tolerance=1.5,this._defines={PERSPECTIVE_CAMERA:1},this.onlySSCSDebug=!1,this.stepCount=2,this.dependencies=[t.GBufferPlugin],this.materialExtension={uuid:e.SSContactShadowsPlugin.PluginType,shaderExtender:(e,i,r)=>{var n,a;if(!e.defines.SSCS_ENABLED)return;const o=t.glsl`
147
8
  #ifndef D_sceneBoundingRadius
148
9
  #define D_sceneBoundingRadius
149
10
  uniform float sceneBoundingRadius;
@@ -161,76 +22,7 @@ for(int i=0;i<8;i++){if(UNROLLED_LOOP_INDEX<loopMax){sample_uv=ray_origin+ray_di
161
22
  #if defined(SSCS_DEBUG) && SSCS_DEBUG > 0
162
23
  return state.z;
163
24
  #endif
164
- `,l=`
165
- #if SSCS_ENABLED
166
-
167
- uniform float sscsIntensity;
168
- uniform float sscsRadius;
169
- uniform float sscsTolerance;
170
-
171
- #define THREE_PACKING_INCLUDED // by threejs
172
- #include <cameraHelpers>
173
- #include <randomHelpers>
174
- ${R}
175
-
176
- #endif
177
-
178
- `+e.shaderReplaceString(e.ShaderChunk.shadowmap_pars_fragment,a,`${s}
179
- `).replace("return shadow;","return min(shadow, state.z);");r.fragmentShader=e.shaderReplaceString(r.fragmentShader,"#include <shadowmap_pars_fragment>",l),r.fragmentShader=r.fragmentShader.replace("#include <lights_fragment_begin>",e.ShaderChunk.lights_fragment_begin),r.fragmentShader=e.shaderReplaceString(r.fragmentShader,"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;","directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ], directLight.direction ) : 1.0;"),r.fragmentShader=e.shaderReplaceString(r.fragmentShader,"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;","directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;"),(f=(c=this._gbufferUnpackExtension)==null?void 0:c.shaderExtender)==null||f.call(c,r,n,i)},onObjectRender:(r,n,i)=>{var s,l;const a=this.enabled&&i.userData.screenSpaceRendering!==!1&&!((s=n.userData)!=null&&s.pluginsDisabled)&&!((l=n.userData)!=null&&l.sscsDisabled)?1:0;e.updateMaterialDefines({...this._defines,SSCS_ENABLED:a},n)},extraUniforms:{...this._uniforms},extraDefines:{},computeCacheKey:r=>this.isDisabled()?"0":"1",isCompatible:r=>r.isPhysicalMaterial,updaters:()=>{var r,n,i,a;return[(r=this._viewer)==null?void 0:r.getPlugin(e.ProgressivePlugin),(n=this._viewer)==null?void 0:n.scene.renderCamera,(i=this._viewer)==null?void 0:i.renderManager,(a=this._viewer)==null?void 0:a.scene]}},this._gbufferUnpackExtension=void 0,this._gbufferUnpackExtensionChanged=()=>{if(!this._viewer)throw new Error("SSContactShadowPlugin: pass/viewer not created yet");const r=this._viewer.renderManager.gbufferUnpackExtension;this._gbufferUnpackExtension!==r&&(this._gbufferUnpackExtension&&this.setGBufferUnpackExtension(void 0),this._gbufferUnpackExtension=r,this._gbufferUnpackExtension?this.setGBufferUnpackExtension(this._gbufferUnpackExtension):this._viewer.console.warn("SSContactShadowPlugin: GBuffer unpack extension removed"))},this.enabled=t}setDirty(){var t,r,n;(r=(t=this.materialExtension)==null?void 0:t.setDirty)==null||r.call(t),(n=this._viewer)==null||n.setDirty()}onAdded(t){super.onAdded(t),t.assetManager.materials.registerMaterialExtension(this.materialExtension),t.getPlugin(e.BaseGroundPlugin)&&(t.getPlugin(e.BaseGroundPlugin).material.userData.sscsDisabled=!1),this._gbufferUnpackExtensionChanged(),t.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged)}onRemove(t){var r;return(r=t.assetManager.materials)==null||r.unregisterMaterialExtension(this.materialExtension),t.renderManager.removeEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),super.onRemove(t)}setGBufferUnpackExtension(t){this._gbufferUnpackExtension=t,this._gbufferUnpackExtension&&(Object.assign(this.materialExtension.extraUniforms,this._gbufferUnpackExtension.extraUniforms),Object.assign(this.materialExtension.extraDefines,this._gbufferUnpackExtension.extraDefines))}},o.SSContactShadowsPlugin.PluginType="SSContactShadows",o.SSContactShadowsPlugin.OldPluginType="SSContactShadowsPlugin",y([e.uiToggle("Enabled"),e.serialize(),e.onChange(o.SSContactShadowsPlugin.prototype.setDirty)],o.SSContactShadowsPlugin.prototype,"enabled",2),y([e.uniform({propKey:"sscsRadius",onChange:o.SSContactShadowsPlugin.prototype.setDirty}),e.uiSlider("Radius",[1e-4,.1],1e-4),e.serialize()],o.SSContactShadowsPlugin.prototype,"radius",2),y([e.uniform({propKey:"sscsIntensity",onChange:o.SSContactShadowsPlugin.prototype.setDirty}),e.uiSlider("Intensity",[1e-4,1],1e-4),e.serialize()],o.SSContactShadowsPlugin.prototype,"intensity",2),y([e.uniform({propKey:"sscsTolerance",onChange:o.SSContactShadowsPlugin.prototype.setDirty}),e.uiSlider("Tolerance",[.1,5]),e.serialize()],o.SSContactShadowsPlugin.prototype,"tolerance",2),y([e.matDefine("SSCS_DEBUG",void 0,!0,o.SSContactShadowsPlugin.prototype.setDirty),e.uiToggle("Debug only SSCS"),e.serialize()],o.SSContactShadowsPlugin.prototype,"onlySSCSDebug",2),y([e.matDefine("SSCS_STEP_COUNT",void 0,!0,o.SSContactShadowsPlugin.prototype.setDirty),e.uiSlider("Step count",[1,8],1),e.serialize()],o.SSContactShadowsPlugin.prototype,"stepCount",2),o.SSContactShadowsPlugin=y([e.uiFolderContainer("SS Contact Shadows")],o.SSContactShadowsPlugin);const F=`#define PI 3.141592653589793
180
- mat3 GetTangentBasis(vec3 TangentZ){vec3 up=vec3(0.0,0.0,1.0);vec3 TangentX=normalize(cross(dot(TangentZ,up)<0.8 ? up : vec3(1.0,0.0,0.0),TangentZ));vec3 TangentY=cross(TangentZ,TangentX);return mat3(TangentX,TangentY,TangentZ);}vec4 CosineSampleHemisphere(vec2 E){float Phi=2.*PI*E.x;float CosTheta=sqrt(E.y);float SinTheta=sqrt(1.-CosTheta*CosTheta);vec3 H;H.x=SinTheta*cos(Phi);H.y=SinTheta*sin(Phi);H.z=CosTheta;float PDF=CosTheta*(1.0/PI);return vec4(H,PDF);}vec4 UniformSampleHemisphere(vec2 E){float Phi=2.*PI*E.x;float CosTheta=E.y;float SinTheta=sqrt(1.-CosTheta*CosTheta);vec3 H;H.x=SinTheta*cos(Phi);H.y=SinTheta*sin(Phi);H.z=CosTheta;float PDF=1.0/(2.*PI);return vec4(H,PDF);}vec2 UniformSampleDiskConcentric(vec2 E){vec2 p=2.*E-1.;float Radius;float Phi;if(abs(p.x)>abs(p.y)){Radius=p.x;Phi=(PI/4.)*(p.y/p.x);}else{Radius=p.y;Phi=(PI/2.)-(PI/4.)*(p.x/p.y);}return vec2(Radius*cos(Phi),Radius*sin(Phi));}vec2 UniformSampleDiskConcentricApprox(vec2 E){vec2 sf=E*sqrt(2.0)-sqrt(0.5);vec2 sq=sf*sf;float root=sqrt(2.0*max(sq.x,sq.y)-min(sq.x,sq.y));if(sq.x>sq.y){sf.x=sf.x>0. ? root :-root;}else{sf.y=sf.y>0. ? root :-root;}return sf;}`,L=`uniform float currentFrameCount;uniform float frameCount;uniform float objectRadius;uniform float radius;uniform float tolerance;uniform bool autoRadius;
181
- #ifndef D_sceneBoundingRadius
182
- #define D_sceneBoundingRadius
183
- uniform float sceneBoundingRadius;
184
- #endif
185
- vec3 ComputeReflectionL(vec3 N,vec2 E,vec3 V,float rough){float rough4=rough*rough*rough*rough;float phi=2.0*PI*E.x;float cos_theta=pow(max(E.y,0.000001),rough4/(2.0-rough4));float sin_theta=sqrt(max(0.,1.0-cos_theta*cos_theta));vec3 half_vec=vec3(sin_theta*cos(phi),sin_theta*sin(phi),cos_theta);vec3 tangentX=normalize(cross(abs(N.z)<0.999 ? vec3(0.0,0.0,1.0): vec3(1.0,0.0,0.0),N));vec3 tangentY=cross(N,tangentX);half_vec=half_vec.x*tangentX+half_vec.y*tangentY+half_vec.z*N;vec3 ray_dir=(2.0*dot(V,half_vec))*half_vec-V;return ray_dir;}vec2 GetRandomE(float seed){vec2 rand_e;rand_e.x=interleavedGradientNoise(gl_FragCoord.xy,frameCount*117.);rand_e.y=fract(rand_e.x*38.65435);rand_e.y=mix(rand_e.y,1.0,0.7);return rand_e;}vec4 calculateSSR(in float seed,in vec3 screenPos,in vec3 normal,in float radiusFactor,in float roughness){vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);normal=normalize(normal);vec2 E=GetRandomE(seed);vec3 L=ComputeReflectionL(normal,E,-normalize(viewPos),roughness);L=normalize(L);float cameraDist=length(cameraPositionWorld);float rayLen=autoRadius ?mix((cameraDist+objectRadius*sceneBoundingRadius)+viewPos.z,-viewPos.z-max(0.0,cameraDist-objectRadius*sceneBoundingRadius),L.z*0.5+0.5):objectRadius*sceneBoundingRadius;rayLen*=radiusFactor;float r=interleavedGradientNoise(gl_FragCoord.xy,frameCount+seed);rayLen=max(rayLen,0.001);int steps=SSR_STEP_COUNT/(currentFrameCount<float(SSR_LOW_QUALITY_FRAMES)? 2 : 1);vec3 state=vec3(0.,(r+0.5)/float(steps),2.);viewPos+=normal*max(-0.0001*viewPos.z,0.001);vec3 screenHitP=traceRay(viewPos,L*rayLen,tolerance*rayLen,state,steps);if(state.z<0.99){vec3 hitColor=(tLastFrameTexelToLinear(texture2D(tLastFrame,screenHitP.xy))).rgb;float ssrWeight=1.;return vec4(hitColor*ssrWeight,1.);}return vec4(0.);}`,oe=`
186
- #if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
187
- vec3 screenPos=viewToScreen(geometry.position);vec4 ssrColor=vec4(0,0,0,0);float alphaModifier=1.0-clamp(material.roughness*.3,0.,1.);alphaModifier*=ssrIntensity;
188
- #if defined(SSR_MASK_FRONT_RAYS) && SSR_MASK_FRONT_RAYS > 0
189
- alphaModifier*=clamp(-4.0*dot(geometry.viewDir,normal)+(4.0+ssrMaskFrontFactor),0.0,1.0);
190
- #endif
191
- #ifdef USE_TRANSMISSION
192
- alphaModifier*=1.-transmission;
193
- #endif
194
- float vignette=1.;if(true){float fadeStrength=0.1;float dist=min(min(1.-screenPos.x,1.-screenPos.y),min(screenPos.x,screenPos.y));float fade=dist*dist/(fadeStrength+0.001);fade=clamp(fade,0.0,1.0);fade=pow(fade,0.3);vignette=fade;}alphaModifier*=vignette;vec3 specularColor=EnvironmentBRDF(geometry.normal,geometry.viewDir,material.specularColor.rgb,material.specularF90,material.roughness);if(length(specularColor.rgb)*alphaModifier>0.01&&roughnessFactor<0.9){
195
- #if defined(SSR_INLINE) && SSR_INLINE > 0
196
- ssrColor=calculateSSR(8.,vec3(screenPos.xy,geometry.position.z),geometry.normal,1.,material.roughness);
197
- #else
198
- ssrColor=tSSReflMapTexelToLinear(texture2D(tSSReflMap,screenPos.xy));
199
- #endif
200
- }ssrColor.rgb*=ssrBoost;ssrColor.a*=alphaModifier;ssrColor.rgb=pow(ssrColor.rgb,vec3(ssrPower));ssrColor.a=min(ssrColor.a,1.0);
201
- #if defined(SSR_NON_PHYSICAL) && SSR_NON_PHYSICAL > 0
202
- diffuseColor.a=max(ssrColor.a,diffuseColor.a*diffuseColor.a);reflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,saturate(diffuseColor.rgb*ssrColor.rgb),1.0);reflectedLight.indirectDiffuse=diffuseColor.rgb*(1.0-ssrColor.a);reflectedLight.directDiffuse=vec3(0.0);reflectedLight.directSpecular=vec3(0.0);
203
- #else
204
- reflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,(specularColor.rgb*ssrColor.rgb),ssrColor.a);
205
- #endif
206
- #endif
207
- `,se=`void main(){vec4 texel=tDiffuseTexelToLinear(texture2D(tDiffuse,vUv));vec4 lastAO=tLastThisTexelToLinear(texture2D(tLastThis,vUv));float depth;vec3 normal;getDepthNormal(vUv,depth,normal);if(depth>=0.999){discard;}float viewZ=depthToViewZ(depth);vec3 screenPos=vec3(vUv.x,vUv.y,viewZ);vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);viewPos.z=viewZ/viewPos.z;vec4 ao=vec4(0.);ao+=calculateSSR(8.,screenPos,normal,1.,0.1);ao.rgb=min(vec3(3.),ao.rgb);ao.rgb=max(vec3(0.),ao.rgb);if(currentFrameCount<2.){gl_FragColor=ao;return;}if(ao.a<0.01){gl_FragColor.rgb=lastAO.rgb;gl_FragColor.a=(((lastAO.a)*currentFrameCount)/(currentFrameCount+1.));}else{gl_FragColor=((ao+(lastAO)*currentFrameCount)/(currentFrameCount+1.));}
208
- #include <encodings_fragment>
209
- }`;var le=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,g=(u,t,r,n)=>{for(var i=n>1?void 0:n?ce(t,r):t,a=u.length-1,s;a>=0;a--)(s=u[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&le(t,r,i),i};const ue="ssrefl";o.SSReflectionPlugin=class extends e.PipelinePassPlugin{constructor(t=!0,r=e.UnsignedByteType,n=1,i=!0){super(),this.inlineShaderRayTrace=t,this.passId=ue,this.dependencies=[e.GBufferPlugin,e.SSAAPlugin],this._gbufferUnpackExtension=void 0,this._gbufferUnpackExtensionChanged=()=>{if(!this._pass||!this._viewer)throw new Error("SSReflectionPlugin: pass/viewer not created yet");const a=this._viewer.renderManager.gbufferUnpackExtension;this._gbufferUnpackExtension!==a&&(this._gbufferUnpackExtension&&this._pass.setGBufferUnpackExtension(void 0),this._gbufferUnpackExtension=a,this._gbufferUnpackExtension?this._pass.setGBufferUnpackExtension(this._gbufferUnpackExtension):this._viewer.console.warn("SSReflectionPlugin: GBuffer unpack extension removed"))},this.enabled=i,this.bufferType=r,this.sizeMultiplier=n}_createTarget(t=!0){this._viewer&&(t&&this._disposeTarget(),!this.inlineShaderRayTrace&&(this.target||(this.target=this._viewer.renderManager.createTarget({depthBuffer:!1,type:this.bufferType,sizeMultiplier:this.sizeMultiplier})),this.texture=this.target.texture,this.texture.name="ssreflBuffer",this._pass&&(this._pass.target=this.target)))}_disposeTarget(){this._viewer&&(this.target&&(this._viewer.renderManager.disposeTarget(this.target),this.target=void 0),this.texture=void 0)}_createPass(){if(!this._viewer)throw new Error("SSReflectionPlugin: viewer not set");if(!this._viewer.renderManager.gbufferTarget||!this._viewer.renderManager.gbufferUnpackExtension)throw new Error("SSReflectionPlugin: GBuffer target not created. GBufferPlugin is required.");return this._createTarget(!0),new o.SSReflectionPluginPass(this.passId,this.target,this.inlineShaderRayTrace)}onAdded(t){super.onAdded(t),t.getPlugin("Ground")&&console.error("GroundPlugin must be added after SSReflectionPlugin"),this._gbufferUnpackExtensionChanged(),t.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged)}onRemove(t){return this._disposeTarget(),t.renderManager.removeEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),super.onRemove(t)}_beforeRender(t,r,n){var i;return this._viewer?((i=this._pass)==null||i.updateShaderProperties([this._viewer.getPlugin(e.ProgressivePlugin)]),super._beforeRender(t,r,n)):!1}get ssrTarget(){return console.warn("SSReflectionPlugin: ssrTarget is deprecated, use target instead"),this.target}},o.SSReflectionPlugin.PluginType="SSReflection",o.SSReflectionPlugin.OldPluginType="SSReflectionPlugin",g([e.uiImage("SSReflection Buffer")],o.SSReflectionPlugin.prototype,"texture",2),g([e.uiConfig()],o.SSReflectionPlugin.prototype,"_pass",2),o.SSReflectionPlugin=g([e.uiFolderContainer("SSReflection Plugin")],o.SSReflectionPlugin),o.SSReflectionPluginPass=class extends e.ExtendedShaderPass{constructor(t,r,n=!0){super({defines:{SSR_STEP_COUNT:16,SSR_LOW_QUALITY_FRAMES:2,SSR_INLINE:n?"1":"0",SSR_MASK_FRONT_RAYS:!0,PERSPECTIVE_CAMERA:1},uniforms:{tLastThis:{value:null},tLastFrame:{value:null},screenSize:{value:new e.Vector2(0,0)},currentFrameCount:{value:0},frameCount:{value:0},cameraNearFar:{value:new e.Vector2(.1,1e3)},cameraPositionWorld:{value:new e.Vector3},projection:{value:new e.Matrix4},saoBiasEpsilon:{value:new e.Vector3(1,1,1)},opacity:{value:1},intensity:{value:0},boost:{value:new e.Vector3(0,0,0)},objectRadius:{value:0},autoRadius:{value:!1},power:{value:0},maskFrontFactor:{value:-.1},tolerance:{value:0},sceneBoundingRadius:{value:0}},vertexShader:e.shaderUtils.defaultVertex,fragmentShader:`
210
- varying vec2 vUv;
211
-
212
- // for gbuffer
213
- #include <packing>
214
- #define THREE_PACKING_INCLUDED
215
- #include <cameraHelpers>
216
- #include <randomHelpers>
217
- ${F}
218
-
219
- ${R}
220
-
221
- ${L}
222
-
223
- ${se}
224
- `},"tDiffuse","tLastThis","tLastFrame"),this.target=r,this.inlineShaderRayTrace=n,this.before=["render"],this.after=["gbuffer","depth"],this.required=["render","progressive"],this.intensity=1,this.boost=new e.Vector3(1,1,1),this.objectRadius=1,this.autoRadius=!0,this.power=1.1,this.tolerance=.5,this.stepCount=16,this.lowQualityFrames=0,this.maskFrontRays=!0,this.maskFrontFactor=-.2,this.materialExtension={extraUniforms:{tSSReflMap:()=>{var i;return{value:((i=e.getOrCall(this.target))==null?void 0:i.texture)??null}},ssrPower:this.material.uniforms.power,ssrIntensity:this.material.uniforms.intensity,ssrMaskFrontFactor:this.material.uniforms.maskFrontFactor,ssrBoost:this.material.uniforms.boost},extraDefines:{SSR_STEP_COUNT:()=>this.material.defines.SSR_STEP_COUNT,SSR_LOW_QUALITY_FRAMES:()=>this.material.defines.SSR_LOW_QUALITY_FRAMES,SSR_INLINE:()=>this.material.defines.SSR_INLINE,SSR_MASK_FRONT_RAYS:()=>this.material.defines.SSR_MASK_FRONT_RAYS,PERSPECTIVE_CAMERA:()=>this.material.defines.PERSPECTIVE_CAMERA},shaderExtender:(i,a,s)=>{var c,f;if(!i.defines.SSREFL_ENABLED)return;const l=`
225
-
226
- ${oe}
227
-
228
- // reflectedLight.directDiffuse = vec3(0.);
229
- // reflectedLight.indirectDiffuse = vec3(0.);
230
- // reflectedLight.directSpecular = vec3(0.);
231
- // reflectedLight.indirectSpecular = vec3(0.);
232
-
233
- `;i.fragmentShader=e.shaderReplaceString(i.fragmentShader,"#glMarker beforeModulation",l,{prepend:!0}),(f=(c=this._gbufferUnpackExtension)==null?void 0:c.shaderExtender)==null||f.call(c,i,a,s)},onObjectRender:(i,a,s)=>{var c,f,d;let l=this.enabled&&s.userData.screenSpaceRendering!==!1&&!((c=a.userData)!=null&&c.pluginsDisabled)&&!((f=a.userData)!=null&&f.ssreflDisabled)?1:0;a.defines.SSREFL_ENABLED!==l&&(a.defines.SSREFL_ENABLED=l,a.needsUpdate=!0),l=(d=a.userData)!=null&&d.ssreflNonPhysical?1:0,a.defines.SSR_NON_PHYSICAL!==l&&(a.defines.SSR_NON_PHYSICAL=l,a.needsUpdate=!0)},parsFragmentSnippet:i=>{var a;return e.glsl`
25
+ `,s=`\n#if SSCS_ENABLED\n\n uniform float sscsIntensity;\n uniform float sscsRadius;\n uniform float sscsTolerance;\n\n #define THREE_PACKING_INCLUDED // by threejs\n #include <cameraHelpers>\n #include <randomHelpers>\n ${b}\n \n#endif\n `+t.shaderReplaceString(t.ShaderChunk.shadowmap_pars_fragment,"float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {",`${o}\n`).replace("return shadow;","return min(shadow, state.z);");e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"#include <shadowmap_pars_fragment>",s),e.fragmentShader=e.fragmentShader.replace("#include <lights_fragment_begin>",t.ShaderChunk.lights_fragment_begin),e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;","directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ], directLight.direction ) : 1.0;"),e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;","directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;"),null==(a=null==(n=this._gbufferUnpackExtension)?void 0:n.shaderExtender)||a.call(n,e,i,r)},onObjectRender:(e,i,r)=>{var n,a;const o=!this.enabled||!1===r.userData.screenSpaceRendering||(null==(n=i.userData)?void 0:n.pluginsDisabled)||(null==(a=i.userData)?void 0:a.sscsDisabled)?0:1;t.updateMaterialDefines({...this._defines,SSCS_ENABLED:o},i)},extraUniforms:{...this._uniforms},extraDefines:{},computeCacheKey:e=>this.isDisabled()?"0":"1",isCompatible:e=>e.isPhysicalMaterial,updaters:()=>{var e,i,r,n;return[null==(e=this._viewer)?void 0:e.getPlugin(t.ProgressivePlugin),null==(i=this._viewer)?void 0:i.scene.renderCamera,null==(r=this._viewer)?void 0:r.renderManager,null==(n=this._viewer)?void 0:n.scene]}},this._gbufferUnpackExtension=void 0,this._gbufferUnpackExtensionChanged=()=>{if(!this._viewer)throw new Error("SSContactShadowPlugin: pass/viewer not created yet");const e=this._viewer.renderManager.gbufferUnpackExtension;this._gbufferUnpackExtension!==e&&(this._gbufferUnpackExtension&&this.setGBufferUnpackExtension(void 0),this._gbufferUnpackExtension=e,this._gbufferUnpackExtension?this.setGBufferUnpackExtension(this._gbufferUnpackExtension):this._viewer.console.warn("SSContactShadowPlugin: GBuffer unpack extension removed"))},this.enabled=i}setDirty(){var e,t,i;null==(t=null==(e=this.materialExtension)?void 0:e.setDirty)||t.call(e),null==(i=this._viewer)||i.setDirty()}onAdded(e){super.onAdded(e),e.assetManager.materials.registerMaterialExtension(this.materialExtension),e.getPlugin(t.BaseGroundPlugin)&&(e.getPlugin(t.BaseGroundPlugin).material.userData.sscsDisabled=!1),this._gbufferUnpackExtensionChanged(),e.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged)}onRemove(e){var t;return null==(t=e.assetManager.materials)||t.unregisterMaterialExtension(this.materialExtension),e.renderManager.removeEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),super.onRemove(e)}setGBufferUnpackExtension(e){this._gbufferUnpackExtension=e,this._gbufferUnpackExtension&&(Object.assign(this.materialExtension.extraUniforms,this._gbufferUnpackExtension.extraUniforms),Object.assign(this.materialExtension.extraDefines,this._gbufferUnpackExtension.extraDefines))}},e.SSContactShadowsPlugin.PluginType="SSContactShadows",e.SSContactShadowsPlugin.OldPluginType="SSContactShadowsPlugin",E([t.uiToggle("Enabled"),t.serialize(),t.onChange(e.SSContactShadowsPlugin.prototype.setDirty)],e.SSContactShadowsPlugin.prototype,"enabled",2),E([t.uniform({propKey:"sscsRadius",onChange:e.SSContactShadowsPlugin.prototype.setDirty}),t.uiSlider("Radius",[1e-4,.1],1e-4),t.serialize()],e.SSContactShadowsPlugin.prototype,"radius",2),E([t.uniform({propKey:"sscsIntensity",onChange:e.SSContactShadowsPlugin.prototype.setDirty}),t.uiSlider("Intensity",[1e-4,1],1e-4),t.serialize()],e.SSContactShadowsPlugin.prototype,"intensity",2),E([t.uniform({propKey:"sscsTolerance",onChange:e.SSContactShadowsPlugin.prototype.setDirty}),t.uiSlider("Tolerance",[.1,5]),t.serialize()],e.SSContactShadowsPlugin.prototype,"tolerance",2),E([t.matDefine("SSCS_DEBUG",void 0,!0,e.SSContactShadowsPlugin.prototype.setDirty),t.uiToggle("Debug only SSCS"),t.serialize()],e.SSContactShadowsPlugin.prototype,"onlySSCSDebug",2),E([t.matDefine("SSCS_STEP_COUNT",void 0,!0,e.SSContactShadowsPlugin.prototype.setDirty),t.uiSlider("Step count",[1,8],1),t.serialize()],e.SSContactShadowsPlugin.prototype,"stepCount",2),e.SSContactShadowsPlugin=E([t.uiFolderContainer("SS Contact Shadows")],e.SSContactShadowsPlugin);const D="#define PI 3.141592653589793\nmat3 GetTangentBasis(vec3 TangentZ){vec3 up=vec3(0.0,0.0,1.0);vec3 TangentX=normalize(cross(dot(TangentZ,up)<0.8 ? up : vec3(1.0,0.0,0.0),TangentZ));vec3 TangentY=cross(TangentZ,TangentX);return mat3(TangentX,TangentY,TangentZ);}vec4 CosineSampleHemisphere(vec2 E){float Phi=2.*PI*E.x;float CosTheta=sqrt(E.y);float SinTheta=sqrt(1.-CosTheta*CosTheta);vec3 H;H.x=SinTheta*cos(Phi);H.y=SinTheta*sin(Phi);H.z=CosTheta;float PDF=CosTheta*(1.0/PI);return vec4(H,PDF);}vec4 UniformSampleHemisphere(vec2 E){float Phi=2.*PI*E.x;float CosTheta=E.y;float SinTheta=sqrt(1.-CosTheta*CosTheta);vec3 H;H.x=SinTheta*cos(Phi);H.y=SinTheta*sin(Phi);H.z=CosTheta;float PDF=1.0/(2.*PI);return vec4(H,PDF);}vec2 UniformSampleDiskConcentric(vec2 E){vec2 p=2.*E-1.;float Radius;float Phi;if(abs(p.x)>abs(p.y)){Radius=p.x;Phi=(PI/4.)*(p.y/p.x);}else{Radius=p.y;Phi=(PI/2.)-(PI/4.)*(p.x/p.y);}return vec2(Radius*cos(Phi),Radius*sin(Phi));}vec2 UniformSampleDiskConcentricApprox(vec2 E){vec2 sf=E*sqrt(2.0)-sqrt(0.5);vec2 sq=sf*sf;float root=sqrt(2.0*max(sq.x,sq.y)-min(sq.x,sq.y));if(sq.x>sq.y){sf.x=sf.x>0. ? root :-root;}else{sf.y=sf.y>0. ? root :-root;}return sf;}",R="uniform float currentFrameCount;uniform float frameCount;uniform float objectRadius;uniform float radius;uniform float tolerance;uniform bool autoRadius;\n#ifndef D_sceneBoundingRadius\n#define D_sceneBoundingRadius\nuniform float sceneBoundingRadius;\n#endif\nvec3 ComputeReflectionL(vec3 N,vec2 E,vec3 V,float rough){float rough4=rough*rough*rough*rough;float phi=2.0*PI*E.x;float cos_theta=pow(max(E.y,0.000001),rough4/(2.0-rough4));float sin_theta=sqrt(max(0.,1.0-cos_theta*cos_theta));vec3 half_vec=vec3(sin_theta*cos(phi),sin_theta*sin(phi),cos_theta);vec3 tangentX=normalize(cross(abs(N.z)<0.999 ? vec3(0.0,0.0,1.0): vec3(1.0,0.0,0.0),N));vec3 tangentY=cross(N,tangentX);half_vec=half_vec.x*tangentX+half_vec.y*tangentY+half_vec.z*N;vec3 ray_dir=(2.0*dot(V,half_vec))*half_vec-V;return ray_dir;}vec2 GetRandomE(float seed){vec2 rand_e;rand_e.x=interleavedGradientNoise(gl_FragCoord.xy,frameCount*117.);rand_e.y=fract(rand_e.x*38.65435);rand_e.y=mix(rand_e.y,1.0,0.7);return rand_e;}vec4 calculateSSR(in float seed,in vec3 screenPos,in vec3 normal,in float radiusFactor,in float roughness){vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);normal=normalize(normal);vec2 E=GetRandomE(seed);vec3 L=ComputeReflectionL(normal,E,-normalize(viewPos),roughness);L=normalize(L);float cameraDist=length(cameraPositionWorld);float rayLen=objectRadius*sceneBoundingRadius;rayLen=autoRadius ?min(max(mix(max(0.0,(cameraDist+rayLen)+viewPos.z),max(0.0,-viewPos.z-max(0.0,cameraDist-rayLen)),L.z*0.5+0.5),rayLen*0.1),rayLen*5.):rayLen;rayLen*=radiusFactor;float r=interleavedGradientNoise(gl_FragCoord.xy,frameCount+seed);rayLen=max(rayLen,0.001);int steps=SSR_STEP_COUNT/(currentFrameCount<float(SSR_LOW_QUALITY_FRAMES)? 2 : 1);vec3 state=vec3(0.,(r+0.5)/float(steps),2.);viewPos+=normal*max(-0.0001*viewPos.z,0.001);vec3 screenHitP=traceRay(viewPos,L*rayLen,tolerance*rayLen,state,steps);if(state.z<0.99){vec3 hitColor=(tLastFrameTexelToLinear(texture2D(tLastFrame,screenHitP.xy))).rgb;float ssrWeight=1.;return vec4(hitColor*ssrWeight,1.);}return vec4(0.);}";var U=Object.defineProperty,M=Object.getOwnPropertyDescriptor,B=(e,t,i,r)=>{for(var n,a=r>1?void 0:r?M(t,i):t,o=e.length-1;o>=0;o--)(n=e[o])&&(a=(r?n(t,i,a):n(a))||a);return r&&a&&U(t,i,a),a};e.SSReflectionPlugin=class extends t.PipelinePassPlugin{constructor(e=!0,i=t.UnsignedByteType,r=1,n=!0){super(),this.inlineShaderRayTrace=e,this.passId="ssrefl",this.dependencies=[t.GBufferPlugin,t.SSAAPlugin],this._gbufferUnpackExtension=void 0,this._gbufferUnpackExtensionChanged=()=>{if(!this._pass||!this._viewer)throw new Error("SSReflectionPlugin: pass/viewer not created yet");const e=this._viewer.renderManager.gbufferUnpackExtension;this._gbufferUnpackExtension!==e&&(this._gbufferUnpackExtension&&this._pass.setGBufferUnpackExtension(void 0),this._gbufferUnpackExtension=e,this._gbufferUnpackExtension?this._pass.setGBufferUnpackExtension(this._gbufferUnpackExtension):this._viewer.console.warn("SSReflectionPlugin: GBuffer unpack extension removed"))},this.enabled=n,this.bufferType=i,this.sizeMultiplier=r}_createTarget(e=!0){this._viewer&&(e&&this._disposeTarget(),this.inlineShaderRayTrace||(this.target||(this.target=this._viewer.renderManager.createTarget({depthBuffer:!1,type:this.bufferType,sizeMultiplier:this.sizeMultiplier})),this.texture=this.target.texture,this.texture.name="ssreflBuffer",this._pass&&(this._pass.target=this.target)))}_disposeTarget(){this._viewer&&(this.target&&(this._viewer.renderManager.disposeTarget(this.target),this.target=void 0),this.texture=void 0)}_createPass(){if(!this._viewer)throw new Error("SSReflectionPlugin: viewer not set");if(!this._viewer.renderManager.gbufferTarget||!this._viewer.renderManager.gbufferUnpackExtension)throw new Error("SSReflectionPlugin: GBuffer target not created. GBufferPlugin is required.");return this._createTarget(!0),new e.SSReflectionPluginPass(this.passId,this.target,this.inlineShaderRayTrace)}onAdded(e){super.onAdded(e),(e.getPlugin("Ground")||e.getPlugin("BaseGroundPlugin"))&&console.error("GroundPlugin must be added after SSReflectionPlugin"),this._gbufferUnpackExtensionChanged(),e.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged)}onRemove(e){return this._disposeTarget(),e.renderManager.removeEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),super.onRemove(e)}_beforeRender(e,i,r){var n;return!!this._viewer&&(null==(n=this._pass)||n.updateShaderProperties([this._viewer.getPlugin(t.ProgressivePlugin)]),super._beforeRender(e,i,r))}get ssrTarget(){return console.warn("SSReflectionPlugin: ssrTarget is deprecated, use target instead"),this.target}},e.SSReflectionPlugin.PluginType="SSReflection",e.SSReflectionPlugin.OldPluginType="SSReflectionPlugin",B([t.uiImage("SSReflection Buffer")],e.SSReflectionPlugin.prototype,"texture",2),B([t.uiConfig()],e.SSReflectionPlugin.prototype,"_pass",2),e.SSReflectionPlugin=B([t.uiFolderContainer("SSReflection Plugin")],e.SSReflectionPlugin),e.SSReflectionPluginPass=class extends t.ExtendedShaderPass{constructor(i,r,n=!0){super({defines:{SSR_STEP_COUNT:16,SSR_LOW_QUALITY_FRAMES:2,SSR_INLINE:n?"1":"0",SSR_MASK_FRONT_RAYS:!0,PERSPECTIVE_CAMERA:1},uniforms:{tLastThis:{value:null},tLastFrame:{value:null},screenSize:{value:new t.Vector2(0,0)},currentFrameCount:{value:0},frameCount:{value:0},cameraNearFar:{value:new t.Vector2(.1,1e3)},cameraPositionWorld:{value:new t.Vector3},projection:{value:new t.Matrix4},saoBiasEpsilon:{value:new t.Vector3(1,1,1)},opacity:{value:1},intensity:{value:0},boost:{value:new t.Vector3(0,0,0)},objectRadius:{value:0},autoRadius:{value:!1},power:{value:0},maskFrontFactor:{value:-.1},tolerance:{value:0},sceneBoundingRadius:{value:0}},vertexShader:t.shaderUtils.defaultVertex,fragmentShader:`\nvarying vec2 vUv;\n\n// for gbuffer\n#include <packing>\n#define THREE_PACKING_INCLUDED\n#include <cameraHelpers>\n#include <randomHelpers>\n${D}\n\n${b}\n\n${R}\n\nvoid main(){vec4 texel=tDiffuseTexelToLinear(texture2D(tDiffuse,vUv));vec4 lastAO=tLastThisTexelToLinear(texture2D(tLastThis,vUv));float depth;vec3 normal;getDepthNormal(vUv,depth,normal);if(depth>=0.999){discard;}float viewZ=depthToViewZ(depth);vec3 screenPos=vec3(vUv.x,vUv.y,viewZ);vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);viewPos.z=viewZ/viewPos.z;vec4 ao=vec4(0.);ao+=calculateSSR(8.,screenPos,normal,1.,0.1);ao.rgb=min(vec3(3.),ao.rgb);ao.rgb=max(vec3(0.),ao.rgb);if(currentFrameCount<2.){gl_FragColor=ao;return;}if(ao.a<0.01){gl_FragColor.rgb=lastAO.rgb;gl_FragColor.a=(((lastAO.a)*currentFrameCount)/(currentFrameCount+1.));}else{gl_FragColor=((ao+(lastAO)*currentFrameCount)/(currentFrameCount+1.));}\n#include <encodings_fragment>\n}\n `},"tDiffuse","tLastThis","tLastFrame"),this.target=r,this.inlineShaderRayTrace=n,this.before=["render"],this.after=["gbuffer","depth"],this.required=["render","progressive"],this.intensity=1,this.boost=new t.Vector3(1,1,1),this.objectRadius=1,this.autoRadius=!0,this.power=1.1,this.tolerance=.5,this.stepCount=16,this.lowQualityFrames=0,this.maskFrontRays=!0,this.maskFrontFactor=-.2,this.materialExtension={extraUniforms:{tSSReflMap:()=>{var e;return{value:(null==(e=t.getOrCall(this.target))?void 0:e.texture)??null}},ssrPower:this.material.uniforms.power,ssrIntensity:this.material.uniforms.intensity,ssrMaskFrontFactor:this.material.uniforms.maskFrontFactor,ssrBoost:this.material.uniforms.boost},extraDefines:{SSR_STEP_COUNT:()=>this.material.defines.SSR_STEP_COUNT,SSR_LOW_QUALITY_FRAMES:()=>this.material.defines.SSR_LOW_QUALITY_FRAMES,SSR_INLINE:()=>this.material.defines.SSR_INLINE,SSR_MASK_FRONT_RAYS:()=>this.material.defines.SSR_MASK_FRONT_RAYS,PERSPECTIVE_CAMERA:()=>this.material.defines.PERSPECTIVE_CAMERA},shaderExtender:(e,i,r)=>{var n,a;if(!e.defines.SSREFL_ENABLED)return;e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"#glMarker beforeModulation","\n \n \n#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0\nvec3 screenPos=viewToScreen(geometry.position);vec4 ssrColor=vec4(0,0,0,0);float alphaModifier=1.0-clamp(material.roughness*.3,0.,1.);alphaModifier*=ssrIntensity;\n#if defined(SSR_MASK_FRONT_RAYS) && SSR_MASK_FRONT_RAYS > 0\nalphaModifier*=clamp(-4.0*dot(geometry.viewDir,normal)+(4.0+ssrMaskFrontFactor),0.0,1.0);\n#endif\n#ifdef USE_TRANSMISSION\nalphaModifier*=1.-transmission;\n#endif\nfloat vignette=1.;if(true){float fadeStrength=0.1;float dist=max(0.,min(min(1.-screenPos.x,1.-screenPos.y),min(screenPos.x,screenPos.y)));float fade=dist*dist/(fadeStrength+0.001);fade=clamp(fade,0.0,1.0);fade=pow(fade,0.3);vignette=fade;}alphaModifier*=vignette;vec3 specularColor=EnvironmentBRDF(geometry.normal,geometry.viewDir,material.specularColor.rgb,material.specularF90,material.roughness);if(length(specularColor.rgb)*alphaModifier>0.01&&roughnessFactor<0.9){\n#if defined(SSR_INLINE) && SSR_INLINE > 0\nssrColor=calculateSSR(8.,vec3(screenPos.xy,geometry.position.z),geometry.normal,1.,material.roughness);\n#else\nssrColor=tSSReflMapTexelToLinear(texture2D(tSSReflMap,screenPos.xy));\n#endif\n}ssrColor.rgb*=ssrBoost;ssrColor.a*=alphaModifier;ssrColor.rgb=pow(max(vec3(0.),ssrColor.rgb),vec3(ssrPower));ssrColor.a=min(ssrColor.a,1.0);\n#if defined(SSR_NON_PHYSICAL) && SSR_NON_PHYSICAL > 0\ndiffuseColor.a=max(ssrColor.a,diffuseColor.a*diffuseColor.a);reflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,saturate(diffuseColor.rgb*ssrColor.rgb),1.0);reflectedLight.indirectDiffuse=diffuseColor.rgb*(1.0-ssrColor.a);reflectedLight.directDiffuse=vec3(0.0);reflectedLight.directSpecular=vec3(0.0);\n#else\nreflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,(specularColor.rgb*ssrColor.rgb),ssrColor.a);\n#endif\n#endif\n\n \n // reflectedLight.directDiffuse = vec3(0.);\n // reflectedLight.indirectDiffuse = vec3(0.);\n // reflectedLight.directSpecular = vec3(0.);\n // reflectedLight.indirectSpecular = vec3(0.);\n \n ",{prepend:!0}),null==(a=null==(n=this._gbufferUnpackExtension)?void 0:n.shaderExtender)||a.call(n,e,i,r)},onObjectRender:(e,t,i)=>{var r,n,a;let o=!this.enabled||!1===i.userData.screenSpaceRendering||(null==(r=t.userData)?void 0:r.pluginsDisabled)||(null==(n=t.userData)?void 0:n.ssreflDisabled)?0:1;t.defines.SSREFL_ENABLED!==o&&(t.defines.SSREFL_ENABLED=o,t.needsUpdate=!0),o=(null==(a=t.userData)?void 0:a.ssreflNonPhysical)?1:0,t.defines.SSR_NON_PHYSICAL!==o&&(t.defines.SSR_NON_PHYSICAL=o,t.needsUpdate=!0)},parsFragmentSnippet:e=>{var i;return t.glsl`
234
26
  #if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
235
27
  uniform float ssrPower;
236
28
  uniform float ssrIntensity;
@@ -238,17 +30,10 @@ ${se}
238
30
  uniform vec3 ssrBoost;
239
31
  uniform sampler2D tSSReflMap;
240
32
  uniform sampler2D tLastFrame;
241
- ${e.getTexelDecoding("tSSReflMap",(a=e.getOrCall(this.target))==null?void 0:a.texture,i.capabilities.isWebGL2)}
242
- ${e.getTexelDecoding("tLastFrame",this.material.uniforms.tLastFrame.value,i.capabilities.isWebGL2)}
243
- ${this.inlineShaderRayTrace?`
244
- #define THREE_PACKING_INCLUDED // by threejs
245
- #include <cameraHelpers>
246
- #include <randomHelpers>
247
- ${F}
248
- ${R}
249
- ${L}
250
- `:""}
33
+ ${t.getTexelDecoding("tSSReflMap",null==(i=t.getOrCall(this.target))?void 0:i.texture,e.capabilities.isWebGL2)}
34
+ ${t.getTexelDecoding("tLastFrame",this.material.uniforms.tLastFrame.value,e.capabilities.isWebGL2)}
35
+ ${this.inlineShaderRayTrace?`\n#define THREE_PACKING_INCLUDED // by threejs\n#include <cameraHelpers>\n#include <randomHelpers>\n${D}\n${b}\n${R}\n `:""}
251
36
  #include <simpleCameraHelpers>
252
37
  #endif
253
- `},computeCacheKey:()=>{var i,a;return this.enabled?"1":"0"+((a=(i=e.getOrCall(this.target))==null?void 0:i.texture)==null?void 0:a.colorSpace)+Object.values(this.material.defines).map(s=>s+"").join(",")},uuid:o.SSReflectionPlugin.PluginType,...e.uiConfigMaterialExtension(this._getUiConfig.bind(this),o.SSReflectionPlugin.PluginType),isCompatible:i=>i.isPhysicalMaterial},this.passId=t,this.needsSwap=!1,this.clear=!0,n&&Object.assign(this.materialExtension.extraUniforms,{tNormalDepth:this.material.uniforms.tNormalDepth,tLastFrame:this.material.uniforms.tLastFrame,objectRadius:this.material.uniforms.objectRadius,autoRadius:this.material.uniforms.autoRadius,tolerance:this.material.uniforms.tolerance,frameCount:this.material.uniforms.frameCount,projection:this.material.uniforms.projection,cameraPositionWorld:this.material.uniforms.cameraPositionWorld,cameraNearFar:this.material.uniforms.cameraNearFar,sceneBoundingRadius:this.material.uniforms.sceneBoundingRadius})}render(t,r,n,i,a){if(!this.enabled)return;if(this.inlineShaderRayTrace){this.needsSwap=!1;return}const s=e.getOrCall(this.target);if(!s){console.warn("SSReflectionPluginPass: target not defined. It must be set when inlineShaderRayTrace is false");return}this.material.defines.HAS_GBUFFER||console.warn("SSReflectionPluginPass: DepthNormalBuffer required for ssrefl"),t.renderManager.blit(r,{source:s.texture}),this.uniforms.tLastThis.value=r.texture,super.render(t,s,n,i,a),this.needsSwap=!1}beforeRender(t,r,n){this.enabled&&this.updateShaderProperties([t,r,n])}_getUiConfig(t){return{type:"folder",label:"SSReflection",children:[{type:"checkbox",label:"Enabled",get value(){return!(t.userData.ssreflDisabled??!1)},set value(r){r!==!(t.userData.ssreflDisabled??!1)&&(t.userData.ssreflDisabled=!r,t.setDirty())},onChange:this.setDirty},{type:"checkbox",label:"Non Physical",get value(){return t.userData.ssreflNonPhysical??!1},set value(r){r!==(t.userData.ssreflNonPhysical??!1)&&(t.userData.ssreflNonPhysical=r,t.setDirty())},onChange:this.setDirty}]}}set uniformsNeedUpdate(t){this.material.uniformsNeedUpdate=t,this.setDirty()}setGBufferUnpackExtension(t){this._gbufferUnpackExtension!==t&&(this._gbufferUnpackExtension&&this.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]),this._gbufferUnpackExtension=t,this._gbufferUnpackExtension&&this.material.registerMaterialExtensions([this._gbufferUnpackExtension]),this._gbufferUnpackExtension&&(Object.assign(this.materialExtension.extraUniforms,this._gbufferUnpackExtension.extraUniforms),Object.assign(this.materialExtension.extraDefines,this._gbufferUnpackExtension.extraDefines)))}},g([e.uiSlider("Intensity",[0,4]),e.serialize(),e.uniform()],o.SSReflectionPluginPass.prototype,"intensity",2),g([e.uiVector("Boost"),e.serialize(),e.uniform()],o.SSReflectionPluginPass.prototype,"boost",2),g([e.uiSlider("Object Radius",[.01,2]),e.serialize(),e.uniform()],o.SSReflectionPluginPass.prototype,"objectRadius",2),g([e.uiToggle("Auto radius"),e.serialize(),e.uniform()],o.SSReflectionPluginPass.prototype,"autoRadius",2),g([e.uiSlider("Power",[0,3]),e.serialize(),e.uniform()],o.SSReflectionPluginPass.prototype,"power",2),g([e.uiSlider("Tolerance",[.1,5]),e.serialize(),e.uniform()],o.SSReflectionPluginPass.prototype,"tolerance",2),g([e.uiSlider("Step count",[1,32],1),e.serialize(),e.matDefine("SSR_STEP_COUNT",void 0,void 0,o.SSReflectionPluginPass.prototype.setDirty)],o.SSReflectionPluginPass.prototype,"stepCount",2),g([e.uiSlider("Low Quality Frames",[0,4],1),e.serialize(),e.matDefine("SSR_LOW_QUALITY_FRAMES",void 0,void 0,o.SSReflectionPluginPass.prototype.setDirty)],o.SSReflectionPluginPass.prototype,"lowQualityFrames",2),g([e.uiToggle("Ignore front rays"),e.serialize(),e.matDefineBool("SSR_MASK_FRONT_RAYS",void 0,void 0,o.SSReflectionPluginPass.prototype.setDirty)],o.SSReflectionPluginPass.prototype,"maskFrontRays",2),g([e.uiSlider("Mask front rays factor",[-1,1],.01,u=>({hidden:()=>!u.maskFrontRays})),e.serialize(),e.uniform()],o.SSReflectionPluginPass.prototype,"maskFrontFactor",2),o.SSReflectionPluginPass=g([e.uiFolderContainer("SSReflection Pass")],o.SSReflectionPluginPass);const fe=[x,o.VelocityBufferPlugin,M,o.SSReflectionPlugin,o.SSContactShadowsPlugin,p];o.BloomPlugin=M,o.DepthOfFieldPlugin=p,o.SSVelocityMaterial=U,o.TemporalAAPlugin=x,o.TemporalAAPluginPass=b,o.webgiPlugins=fe,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
38
+ `},computeCacheKey:()=>{var e,i;return this.enabled?"1":"0"+(null==(i=null==(e=t.getOrCall(this.target))?void 0:e.texture)?void 0:i.colorSpace)+Object.values(this.material.defines).map((e=>e+"")).join(",")},uuid:e.SSReflectionPlugin.PluginType,...t.uiConfigMaterialExtension(this._getUiConfig.bind(this),e.SSReflectionPlugin.PluginType),isCompatible:e=>e.isPhysicalMaterial},this.passId=i,this.needsSwap=!1,this.clear=!0,n&&Object.assign(this.materialExtension.extraUniforms,{tNormalDepth:this.material.uniforms.tNormalDepth,tLastFrame:this.material.uniforms.tLastFrame,objectRadius:this.material.uniforms.objectRadius,autoRadius:this.material.uniforms.autoRadius,tolerance:this.material.uniforms.tolerance,frameCount:this.material.uniforms.frameCount,projection:this.material.uniforms.projection,cameraPositionWorld:this.material.uniforms.cameraPositionWorld,cameraNearFar:this.material.uniforms.cameraNearFar,sceneBoundingRadius:this.material.uniforms.sceneBoundingRadius})}render(e,i,r,n,a){if(!this.enabled)return;if(this.inlineShaderRayTrace)return void(this.needsSwap=!1);const o=t.getOrCall(this.target);o?(this.material.defines.HAS_GBUFFER||console.warn("SSReflectionPluginPass: DepthNormalBuffer required for ssrefl"),e.renderManager.blit(i,{source:o.texture}),this.uniforms.tLastThis.value=i.texture,super.render(e,o,r,n,a),this.needsSwap=!1):console.warn("SSReflectionPluginPass: target not defined. It must be set when inlineShaderRayTrace is false")}beforeRender(e,t,i){this.enabled&&this.updateShaderProperties([e,t,i])}_getUiConfig(e){return{type:"folder",label:"SSReflection",children:[{type:"checkbox",label:"Enabled",get value(){return!e.userData.ssreflDisabled},set value(t){t!==!e.userData.ssreflDisabled&&(e.userData.ssreflDisabled=!t,e.setDirty())},onChange:this.setDirty},{type:"checkbox",label:"Non Physical",get value(){return e.userData.ssreflNonPhysical??!1},set value(t){t!==(e.userData.ssreflNonPhysical??!1)&&(e.userData.ssreflNonPhysical=t,e.setDirty())},onChange:this.setDirty}]}}set uniformsNeedUpdate(e){this.material.uniformsNeedUpdate=e,this.setDirty()}setGBufferUnpackExtension(e){this._gbufferUnpackExtension!==e&&(this._gbufferUnpackExtension&&this.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]),this._gbufferUnpackExtension=e,this._gbufferUnpackExtension&&this.material.registerMaterialExtensions([this._gbufferUnpackExtension]),this._gbufferUnpackExtension&&(Object.assign(this.materialExtension.extraUniforms,this._gbufferUnpackExtension.extraUniforms),Object.assign(this.materialExtension.extraDefines,this._gbufferUnpackExtension.extraDefines)))}},B([t.uiSlider("Intensity",[0,4]),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"intensity",2),B([t.uiVector("Boost"),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"boost",2),B([t.uiSlider("Object Radius",[.01,2]),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"objectRadius",2),B([t.uiToggle("Auto radius"),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"autoRadius",2),B([t.uiSlider("Power",[0,3]),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"power",2),B([t.uiSlider("Tolerance",[.1,5]),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"tolerance",2),B([t.uiSlider("Step count",[1,32],1),t.serialize(),t.matDefine("SSR_STEP_COUNT",void 0,void 0,e.SSReflectionPluginPass.prototype.setDirty)],e.SSReflectionPluginPass.prototype,"stepCount",2),B([t.uiSlider("Low Quality Frames",[0,4],1),t.serialize(),t.matDefine("SSR_LOW_QUALITY_FRAMES",void 0,void 0,e.SSReflectionPluginPass.prototype.setDirty)],e.SSReflectionPluginPass.prototype,"lowQualityFrames",2),B([t.uiToggle("Ignore front rays"),t.serialize(),t.matDefineBool("SSR_MASK_FRONT_RAYS",void 0,void 0,e.SSReflectionPluginPass.prototype.setDirty)],e.SSReflectionPluginPass.prototype,"maskFrontRays",2),B([t.uiSlider("Mask front rays factor",[-1,1],.01,(e=>({hidden:()=>!e.maskFrontRays}))),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"maskFrontFactor",2),e.SSReflectionPluginPass=B([t.uiFolderContainer("SSReflection Pass")],e.SSReflectionPluginPass);const F=[s,e.VelocityBufferPlugin,m,e.SSReflectionPlugin,e.SSContactShadowsPlugin,y];e.BloomPlugin=m,e.DepthOfFieldPlugin=y,e.SSVelocityMaterial=f,e.TemporalAAPlugin=s,e.TemporalAAPluginPass=l,e.webgiPlugins=F,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
254
39
  //# sourceMappingURL=index.js.map