@threepipe/webgi-plugins 0.6.2 → 0.6.4
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 +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/extras/AdvancedGroundPlugin.d.ts +1 -1
- package/dist/plugins/extras/AdvancedGroundPlugin.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ var e,t;import{RenderManager as r,PipelinePassPlugin as i,GBufferPlugin as a,Pro
|
|
|
7
7
|
#define D_frameCount
|
|
8
8
|
uniform float frameCount;
|
|
9
9
|
#endif
|
|
10
|
-
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, vec3 lightDirection ) {
|
|
10
|
+
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, vec3 lightDirection ) {
|
|
11
11
|
vec3 ray_origin_view = -vViewPosition;
|
|
12
12
|
float rnd = interleavedGradientNoise(gl_FragCoord.xy, frameCount+34.);
|
|
13
13
|
float cameraDist = length(cameraPositionWorld);
|
|
@@ -19,7 +19,7 @@ var e,t;import{RenderManager as r,PipelinePassPlugin as i,GBufferPlugin as a,Pro
|
|
|
19
19
|
#if defined(SSCS_DEBUG) && SSCS_DEBUG > 0
|
|
20
20
|
return state.z;
|
|
21
21
|
#endif
|
|
22
|
-
`,a=`\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 ${Qe}\n \n#endif\n `+y(it.shadowmap_pars_fragment,"float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {",`${i}\n`).replace("return shadow;","return min(shadow, state.z);");e.fragmentShader=y(e.fragmentShader,"#include <shadowmap_pars_fragment>",a),e.fragmentShader=e.fragmentShader.replace("#include <lights_fragment_begin>",it.lights_fragment_begin),e.fragmentShader=y(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=y(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;"),this._gbufferUnpackExtension?.shaderExtender?.(e,t,r)},onObjectRender:(e,t,r)=>{const i=!this.enabled||!1===r.userData.screenSpaceRendering||t.userData?.pluginsDisabled||t.userData?.sscsDisabled?0:1;X({...this._defines,SSCS_ENABLED:i},t)},extraUniforms:{...this._uniforms},extraDefines:{},computeCacheKey:e=>this.isDisabled()?"0":"1",isCompatible:e=>e.isPhysicalMaterial,updaters:()=>[this._viewer?.getPlugin(s),this._viewer?.scene.renderCamera,this._viewer?.renderManager,this._viewer?.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=e}setDirty(){this.materialExtension?.setDirty?.(),this._viewer?.setDirty()}onAdded(e){super.onAdded(e),e.assetManager.materials.registerMaterialExtension(this.materialExtension),e.getPlugin(q)&&(e.getPlugin(q).material.userData.sscsDisabled=!1),this._gbufferUnpackExtensionChanged(),e.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged)}onRemove(e){return e.assetManager.materials?.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))}};at.PluginType="SSContactShadows",at.OldPluginType="SSContactShadowsPlugin",rt([o("Enabled"),f(),B(at.prototype.setDirty)],at.prototype,"enabled",2),rt([m({propKey:"sscsRadius",onChange:at.prototype.setDirty}),O("Radius",[1e-4,.1],1e-4),f()],at.prototype,"radius",2),rt([m({propKey:"sscsIntensity",onChange:at.prototype.setDirty}),O("Intensity",[1e-4,1],1e-4),f()],at.prototype,"intensity",2),rt([m({propKey:"sscsTolerance",onChange:at.prototype.setDirty}),O("Tolerance",[.1,5]),f()],at.prototype,"tolerance",2),rt([Z("SSCS_DEBUG",void 0,!0,at.prototype.setDirty),o("Debug only SSCS"),f()],at.prototype,"onlySSCSDebug",2),rt([Z("SSCS_STEP_COUNT",void 0,!0,at.prototype.setDirty),O("Step count",[1,8],1),f()],at.prototype,"stepCount",2),at=rt([E("SS Contact Shadows")],at);const st="#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;}";var nt=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,lt=(e,t,r,i)=>{for(var a,s=i>1?void 0:i?ot(t,r):t,n=e.length-1;n>=0;n--)(a=e[n])&&(s=(i?a(t,r,s):a(s))||s);return i&&s&&nt(t,r,s),s};let ct=class extends i{constructor(e=!0,t=_,r=1,i=!0){super(),this.inlineShaderRayTrace=e,this.passId="ssrefl",this.dependencies=[a,J],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._viewerListeners={preRender:()=>{if(!this._viewer||this.isDisabled())return;if(!this._pass)return;const e=this._viewer.scene.renderCamera;this._pass.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._pass.uniforms.inverseViewMatrix.value.copy(e.matrixWorld)},postRender:()=>{this._viewer&&!this.isDisabled()&&this._pass&&this._pass.uniforms.lastProjectionViewMatrix.value.copy(this._pass.uniforms.currentProjectionViewMatrix.value)}},this.enabled=i,this.bufferType=t,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"))}_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 dt(this.passId,()=>this.target,this.inlineShaderRayTrace)}onAdded(e){super.onAdded(e),(e.getPlugin("Ground")||e.getPlugin("BaseGroundPlugin"))&&console.warn("GroundPlugin must be added after SSReflectionPlugin"),this._gbufferUnpackExtensionChanged(),e.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),e.forPlugin(ke,e=>{this._pass?.material.registerMaterialExtensions([e.unpackExtension])},e=>{this._pass?.material?.unregisterMaterialExtensions([e.unpackExtension])},this)}onRemove(e){return this._disposeTarget(),e.renderManager.removeEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),super.onRemove(e)}_beforeRender(e,t,r){if(!this._viewer)return!1;const i=super._beforeRender(e,t,r);if(!i)return i;const a=this._viewer.getPlugin(s);return this._pass?.updateShaderProperties([a]),i}get ssrTarget(){return console.warn("SSReflectionPlugin: ssrTarget is deprecated, use target instead"),this.target}fromJSON(e,t){return e.passes?.ssr&&((e={...e}).pass=e.passes.ssr,delete e.passes,void 0!==e.pass.enabled&&(e.enabled=e.pass.enabled)),super.fromJSON(e,t)}};ct.PluginType="SSReflectionPlugin",ct.OldPluginType="SSReflection",lt([M("SSReflection Buffer",{readOnly:!0,hideOnEmpty:!0})],ct.prototype,"texture",2),lt([l(void 0,{unwrapContents:!0})],ct.prototype,"_pass",2),ct=lt([E("SSReflection Plugin")],ct);let dt=class extends c{constructor(e,t,r=!0){super({defines:{SSR_STEP_COUNT:16,SSR_RAY_COUNT:4,SSR_RAY_BLEND_MAX:0,SSR_LOW_QUALITY_FRAMES:0,SSR_INLINE:r?"1":"0",SSR_MASK_FRONT_RAYS:!0,PERSPECTIVE_CAMERA:1},uniforms:{tLastThis:{value:null},tLastFrame:{value:null},screenSize:{value:new d(0,0)},currentFrameCount:{value:0},frameCount:{value:0},cameraNearFar:{value:new d(.1,1e3)},cameraPositionWorld:{value:new F},projection:{value:new u},opacity:{value:1},intensity:{value:0},boost:{value:new F(0,0,0)},objectRadius:{value:0},autoRadius:{value:!1},power:{value:0},maskFrontFactor:{value:-.1},tolerance:{value:0},ssrRoughnessFactor:{value:1},sceneBoundingRadius:{value:0},currentProjectionViewMatrix:{value:new u},lastProjectionViewMatrix:{value:new u},inverseViewMatrix:{value:new u},ssrSplitX:{value:.5}},vertexShader:V.defaultVertex,fragmentShader:`\nvarying vec2 vUv;\n\n// for gbuffer\n#include <packing>\n#define THREE_PACKING_INCLUDED\n#include <cameraHelpers>\n#include <randomHelpers>\n${st}\n\n${Qe}\n\n${Ee().ssReflection}\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 <colorspace_fragment>\n}\n `},"tDiffuse","tLastThis","tLastFrame"),this.target=t,this.inlineShaderRayTrace=r,this.before=["render"],this.after=["gbuffer","depth"],this.required=["render","progressive"],this.intensity=1,this.boost=new F(1,1,1),this.objectRadius=1,this.autoRadius=!0,this.power=1.1,this.tolerance=.5,this.roughnessFactor=1,this.stepCount=16,this.rayCount=1,this.rayBlendMax=!1,this.lowQualityFrames=0,this.maskFrontRays=!0,this.maskFrontFactor=-.2,this.split=0,this.materialExtension={extraUniforms:{tSSReflMap:()=>({value:p(this.target)?.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_RAY_COUNT:()=>this.material.defines.SSR_RAY_COUNT,SSR_RAY_BLEND_MAX:()=>this.material.defines.SSR_RAY_BLEND_MAX,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,t,r)=>{if(!e.defines?.SSREFL_ENABLED)return;e.fragmentShader=y(e.fragmentShader,"#glMarker beforeModulation","\n \n \n#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0\nvec3 screenPos=viewToScreen(geometryPosition);\n#if SSREFL_ENABLED == 2\nif(screenPos.x>ssrSplitX){\n#endif\nvec4 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(geometryViewDir,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(geometryNormal,geometryViewDir,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\nvec3 scPos=vec3(screenPos.xy,geometryPosition.z);vec4 scol=vec4(0,0,0,0);\n#pragma unroll_loop_start\nfor(int i=0;i<8;i++){if(SSR_RAY_COUNT>UNROLLED_LOOP_INDEX){scol=calculateSSR(float(UNROLLED_LOOP_INDEX),scPos,geometryNormal,UNROLLED_LOOP_INDEX%3==0?1.:UNROLLED_LOOP_INDEX%3==1?0.5:1.5,material.roughness);\n#ifdef SSR_RAY_BLEND_MAX\nssrColor=max(ssrColor,scol);\n#else\nssrColor+=scol;\n#endif\n}}\n#pragma unroll_loop_end\n#ifndef SSR_RAY_BLEND_MAX\nssrColor*=ssrColor.a>0.001 ? 1.0/ssrColor.a : 1.0;\n#endif\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#if SSREFL_ENABLED == 2\n}\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}),this._gbufferUnpackExtension?.shaderExtender?.(e,t,r)},onObjectRender:(e,t,r)=>{let i=!this.enabled||!1===r.userData.screenSpaceRendering||t.userData?.pluginsDisabled||t.userData?.ssreflDisabled?0:this.split>0?2:1;t.defines.SSREFL_ENABLED!==i&&(t.defines.SSREFL_ENABLED=i,t.needsUpdate=!0),i=t.userData?.ssreflNonPhysical?1:0,t.defines.SSR_NON_PHYSICAL!==i&&(t.defines.SSR_NON_PHYSICAL=i,t.needsUpdate=!0)},parsFragmentSnippet:()=>K`
|
|
22
|
+
`,a=`\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 ${Qe}\n \n#endif\n `+y(it.shadowmap_pars_fragment,"float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {",`${i}\n`).replace("return mix( 1.0, shadow, shadowIntensity );","return mix( 1.0, min(shadow, state.z), shadowIntensity );");e.fragmentShader=y(e.fragmentShader,"#include <shadowmap_pars_fragment>",a),e.fragmentShader=e.fragmentShader.replace("#include <lights_fragment_begin>",it.lights_fragment_begin),e.fragmentShader=y(e.fragmentShader,"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;","directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ], directLight.direction ) : 1.0;"),e.fragmentShader=y(e.fragmentShader,"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;","directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;"),this._gbufferUnpackExtension?.shaderExtender?.(e,t,r)},onObjectRender:(e,t,r)=>{const i=!this.enabled||!1===r.userData.screenSpaceRendering||t.userData?.pluginsDisabled||t.userData?.sscsDisabled?0:1;X({...this._defines,SSCS_ENABLED:i},t)},extraUniforms:{...this._uniforms},extraDefines:{},computeCacheKey:e=>this.isDisabled()?"0":"1",isCompatible:e=>e.isPhysicalMaterial,updaters:()=>[this._viewer?.getPlugin(s),this._viewer?.scene.renderCamera,this._viewer?.renderManager,this._viewer?.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=e}setDirty(){this.materialExtension?.setDirty?.(),this._viewer?.setDirty()}onAdded(e){super.onAdded(e),e.assetManager.materials.registerMaterialExtension(this.materialExtension),e.getPlugin(q)&&(e.getPlugin(q).material.userData.sscsDisabled=!1),this._gbufferUnpackExtensionChanged(),e.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged)}onRemove(e){return e.assetManager.materials?.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))}};at.PluginType="SSContactShadows",at.OldPluginType="SSContactShadowsPlugin",rt([o("Enabled"),f(),B(at.prototype.setDirty)],at.prototype,"enabled",2),rt([m({propKey:"sscsRadius",onChange:at.prototype.setDirty}),O("Radius",[1e-4,.1],1e-4),f()],at.prototype,"radius",2),rt([m({propKey:"sscsIntensity",onChange:at.prototype.setDirty}),O("Intensity",[1e-4,1],1e-4),f()],at.prototype,"intensity",2),rt([m({propKey:"sscsTolerance",onChange:at.prototype.setDirty}),O("Tolerance",[.1,5]),f()],at.prototype,"tolerance",2),rt([Z("SSCS_DEBUG",void 0,!0,at.prototype.setDirty),o("Debug only SSCS"),f()],at.prototype,"onlySSCSDebug",2),rt([Z("SSCS_STEP_COUNT",void 0,!0,at.prototype.setDirty),O("Step count",[1,8],1),f()],at.prototype,"stepCount",2),at=rt([E("SS Contact Shadows")],at);const st="#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;}";var nt=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,lt=(e,t,r,i)=>{for(var a,s=i>1?void 0:i?ot(t,r):t,n=e.length-1;n>=0;n--)(a=e[n])&&(s=(i?a(t,r,s):a(s))||s);return i&&s&&nt(t,r,s),s};let ct=class extends i{constructor(e=!0,t=_,r=1,i=!0){super(),this.inlineShaderRayTrace=e,this.passId="ssrefl",this.dependencies=[a,J],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._viewerListeners={preRender:()=>{if(!this._viewer||this.isDisabled())return;if(!this._pass)return;const e=this._viewer.scene.renderCamera;this._pass.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._pass.uniforms.inverseViewMatrix.value.copy(e.matrixWorld)},postRender:()=>{this._viewer&&!this.isDisabled()&&this._pass&&this._pass.uniforms.lastProjectionViewMatrix.value.copy(this._pass.uniforms.currentProjectionViewMatrix.value)}},this.enabled=i,this.bufferType=t,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"))}_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 dt(this.passId,()=>this.target,this.inlineShaderRayTrace)}onAdded(e){super.onAdded(e),(e.getPlugin("Ground")||e.getPlugin("BaseGroundPlugin"))&&console.warn("GroundPlugin must be added after SSReflectionPlugin"),this._gbufferUnpackExtensionChanged(),e.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),e.forPlugin(ke,e=>{this._pass?.material.registerMaterialExtensions([e.unpackExtension])},e=>{this._pass?.material?.unregisterMaterialExtensions([e.unpackExtension])},this)}onRemove(e){return this._disposeTarget(),e.renderManager.removeEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),super.onRemove(e)}_beforeRender(e,t,r){if(!this._viewer)return!1;const i=super._beforeRender(e,t,r);if(!i)return i;const a=this._viewer.getPlugin(s);return this._pass?.updateShaderProperties([a]),i}get ssrTarget(){return console.warn("SSReflectionPlugin: ssrTarget is deprecated, use target instead"),this.target}fromJSON(e,t){return e.passes?.ssr&&((e={...e}).pass=e.passes.ssr,delete e.passes,void 0!==e.pass.enabled&&(e.enabled=e.pass.enabled)),super.fromJSON(e,t)}};ct.PluginType="SSReflectionPlugin",ct.OldPluginType="SSReflection",lt([M("SSReflection Buffer",{readOnly:!0,hideOnEmpty:!0})],ct.prototype,"texture",2),lt([l(void 0,{unwrapContents:!0})],ct.prototype,"_pass",2),ct=lt([E("SSReflection Plugin")],ct);let dt=class extends c{constructor(e,t,r=!0){super({defines:{SSR_STEP_COUNT:16,SSR_RAY_COUNT:4,SSR_RAY_BLEND_MAX:0,SSR_LOW_QUALITY_FRAMES:0,SSR_INLINE:r?"1":"0",SSR_MASK_FRONT_RAYS:!0,PERSPECTIVE_CAMERA:1},uniforms:{tLastThis:{value:null},tLastFrame:{value:null},screenSize:{value:new d(0,0)},currentFrameCount:{value:0},frameCount:{value:0},cameraNearFar:{value:new d(.1,1e3)},cameraPositionWorld:{value:new F},projection:{value:new u},opacity:{value:1},intensity:{value:0},boost:{value:new F(0,0,0)},objectRadius:{value:0},autoRadius:{value:!1},power:{value:0},maskFrontFactor:{value:-.1},tolerance:{value:0},ssrRoughnessFactor:{value:1},sceneBoundingRadius:{value:0},currentProjectionViewMatrix:{value:new u},lastProjectionViewMatrix:{value:new u},inverseViewMatrix:{value:new u},ssrSplitX:{value:.5}},vertexShader:V.defaultVertex,fragmentShader:`\nvarying vec2 vUv;\n\n// for gbuffer\n#include <packing>\n#define THREE_PACKING_INCLUDED\n#include <cameraHelpers>\n#include <randomHelpers>\n${st}\n\n${Qe}\n\n${Ee().ssReflection}\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 <colorspace_fragment>\n}\n `},"tDiffuse","tLastThis","tLastFrame"),this.target=t,this.inlineShaderRayTrace=r,this.before=["render"],this.after=["gbuffer","depth"],this.required=["render","progressive"],this.intensity=1,this.boost=new F(1,1,1),this.objectRadius=1,this.autoRadius=!0,this.power=1.1,this.tolerance=.5,this.roughnessFactor=1,this.stepCount=16,this.rayCount=1,this.rayBlendMax=!1,this.lowQualityFrames=0,this.maskFrontRays=!0,this.maskFrontFactor=-.2,this.split=0,this.materialExtension={extraUniforms:{tSSReflMap:()=>({value:p(this.target)?.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_RAY_COUNT:()=>this.material.defines.SSR_RAY_COUNT,SSR_RAY_BLEND_MAX:()=>this.material.defines.SSR_RAY_BLEND_MAX,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,t,r)=>{if(!e.defines?.SSREFL_ENABLED)return;e.fragmentShader=y(e.fragmentShader,"#glMarker beforeModulation","\n \n \n#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0\nvec3 screenPos=viewToScreen(geometryPosition);\n#if SSREFL_ENABLED == 2\nif(screenPos.x>ssrSplitX){\n#endif\nvec4 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(geometryViewDir,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(geometryNormal,geometryViewDir,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\nvec3 scPos=vec3(screenPos.xy,geometryPosition.z);vec4 scol=vec4(0,0,0,0);\n#pragma unroll_loop_start\nfor(int i=0;i<8;i++){if(SSR_RAY_COUNT>UNROLLED_LOOP_INDEX){scol=calculateSSR(float(UNROLLED_LOOP_INDEX),scPos,geometryNormal,UNROLLED_LOOP_INDEX%3==0?1.:UNROLLED_LOOP_INDEX%3==1?0.5:1.5,material.roughness);\n#ifdef SSR_RAY_BLEND_MAX\nssrColor=max(ssrColor,scol);\n#else\nssrColor+=scol;\n#endif\n}}\n#pragma unroll_loop_end\n#ifndef SSR_RAY_BLEND_MAX\nssrColor*=ssrColor.a>0.001 ? 1.0/ssrColor.a : 1.0;\n#endif\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#if SSREFL_ENABLED == 2\n}\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}),this._gbufferUnpackExtension?.shaderExtender?.(e,t,r)},onObjectRender:(e,t,r)=>{let i=!this.enabled||!1===r.userData.screenSpaceRendering||t.userData?.pluginsDisabled||t.userData?.ssreflDisabled?0:this.split>0?2:1;t.defines.SSREFL_ENABLED!==i&&(t.defines.SSREFL_ENABLED=i,t.needsUpdate=!0),i=t.userData?.ssreflNonPhysical?1:0,t.defines.SSR_NON_PHYSICAL!==i&&(t.defines.SSR_NON_PHYSICAL=i,t.needsUpdate=!0)},parsFragmentSnippet:()=>K`
|
|
23
23
|
#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
|
|
24
24
|
uniform float ssrPower;
|
|
25
25
|
uniform float ssrIntensity;
|
|
@@ -102,5 +102,5 @@ gl_FragColor = packDepthToRGBA(mix(last, shadow, opacity));
|
|
|
102
102
|
gl_FragColor = saturate(gl_FragColor);
|
|
103
103
|
//gl_FragColor.a = 0.5;
|
|
104
104
|
#endif
|
|
105
|
-
`))},computeCacheKey:()=>this.groundMapMode+"."+this.alphaVignette+"."+this.alphaVignetteAxis,onObjectRender:(e,t)=>{t.userData.gMapMode!==this.groundMapMode&&(t.userData.gMapMode=this.groundMapMode,t.needsUpdate=!0)},isCompatible:e=>e.isPhysicalMaterial},this._viewer=e;const t=new Ht(16777215,10,{near:1.5,far:20,bias:0,frustumSize:4,width:1024,height:1024,enabled:!0,radius:10,normalBias:0},{direction:new F(.2,1,.2).normalize(),spread:.9,focus:1,distanceScale:20,minDistanceScale:new F(10,10,10),normalDirection:new F(0,1,0)});t.shadow.camera.updateProjectionMatrix(),t.layers.disableAll(),t.layers.set(this._lightLayer),this._light=t,e.scene.addObject(this._light,{addToRoot:!0}),this._shadowMat=new Xt({color:"#ffffff",toneMapped:!1,depthWrite:!1,depthTest:!1,premultipliedAlpha:!1,opacity:1,transparent:!1,blending:T}),this._shadowBlurMat=new ge({uniforms:{colorTexture:{value:null},step:{value:.1},size:{value:new d(.5,.5)},direction:{value:new d(.5,.5)}},vertexShader:V.defaultVertex,fragmentShader:"#include <packing>\nuniform sampler2D colorTexture;uniform vec2 size;uniform vec2 direction;uniform float step;varying vec2 vUv;void main(){float sum=0.0;vec2 uvDelta=step*direction/size;sum+=unpackRGBAToDepth(texture2D(colorTexture,vUv-1.*uvDelta))*0.3333;sum+=unpackRGBAToDepth(texture2D(colorTexture,vec2(vUv.x,vUv.y)))*0.3333;sum+=unpackRGBAToDepth(texture2D(colorTexture,vUv+1.*uvDelta))*0.3333;gl_FragColor=packDepthToRGBA(sum);}"})}get attachedMesh(){return this._attachedMesh}set attachedMesh(e){this._attachedMesh!==e&&(this._attachedMesh&&this.cleanupMaterial(),this._attachedMesh=e,this._attachedMesh&&this._updateMaterial())}get target(){return this._target}get light(){return this._light}dispose(){this._shadowMat.dispose(),this._target=void 0,this.reset()}cleanupMaterial(){this._updateMaterial(!0)}_groundMapModeChanged(){this._attachedMesh&&(this.cleanupMaterial(),this._updateMaterial(),"alphaMap"===this.groundMapMode?this._attachedMesh.material.transparent=!0:this._attachedMesh.material.transparent=!1),this.reset()}_alphaVignetteChanged(){this.materialExtension?.setDirty?.(),this._viewer?.setDirty()}fromJSON(e,t,r=!1){return r?(he.Deserialize(e,this,t,!0),this.reset(),this):he.Deserialize(e,this,t,!1)}reset(){this._frameNumber=0}get frameNumber(){return this._frameNumber}autoUpdateShadow(){return!!this.shadowAutoUpdate&&(!(this._bakeCounter>=this.maxBakeCount)&&(!!this.updateShadow()&&(this._frameNumber===this.maxFrameNumber?this.dispatchEvent({type:"shadowBaked",bakeCount:++this._bakeCounter}):this._frameNumber>0&&this._frameNumber<this.maxFrameNumber&&this.dispatchEvent({type:"shadowBaking",progress:this._frameNumber/this.maxFrameNumber,bakeCount:this._bakeCounter}),!0)))}updateShadow(){if(!this.enabled)return!1;const e=this._attachedMesh;if(!e)return!1;if(++this._frameNumber>this.maxFrameNumber)return!1;const t=1024;this._target||(this._target=this._viewer.renderManager.createTarget({type:_,depthBuffer:!1,size:new d(t,t),sizeMultiplier:void 0,colorSpace:ve,format:G})),this._frameNumber<3?this._light.randomizePosition(0,1,0):this._light.randomizePosition(this._frameNumber),e.castShadow=!1;const r=this._viewer.renderManager.renderer,i=r.shadowMap,a=i.type,s=i.needsUpdate,n=i.autoUpdate;i.type=this.shadowMapType,i.needsUpdate=!0,i.autoUpdate=!1;const o=this._viewer.scene,l=new _e;l.disableAll(),o.traverse(e=>{e.isLight&&e!==this._light&&(e.userData.__gp_layers=e.layers,e.layers=l)});const c=o.mainCamera;if(c.layers.mask&1<<this._lightLayer)throw"Camera can render pseudo directional light, check layers";c.layers.enable(this._lightLayer),e.layers.disable(this._lightLayer),r.renderWithModes({shadowMapRender:!0,backgroundRender:!1,sceneRender:!1},()=>r.render(o,o.mainCamera)),c.layers.disable(this._lightLayer);const u=c.layers.mask;c.layers.set(this._lightLayer),e.layers.enable(this._lightLayer);const h=this._viewer.renderManager.getTempTarget({type:_,depthBuffer:!1,size:new d(t,t),colorSpace:ve,format:G}),p=h.texture,f=p.colorSpace;p.colorSpace=ve,this._viewer.renderManager.blit(h,{clear:!0,source:this._target.texture});{const t=e.material,i=e.frustumCulled,a=r.getRenderTarget(),s=r.getActiveCubeFace(),n=r.getActiveMipmapLevel();e.material=this._shadowMat,e.frustumCulled=!1,r.setRenderTarget(this._target),this._shadowMat.opacity=Math.max(1/this.maxFrameNumber,1/this._frameNumber),this._shadowMat.lastFrameTexture=h.texture,this._shadowMat.needsUpdate=!0,r.renderWithModes({shadowMapRender:!1,backgroundRender:!1,opaqueRender:!0,transparentRender:!1,transmissionRender:!1},()=>r.render(o,o.mainCamera)),r.setRenderTarget(a,s,n),e.frustumCulled=i,e.material=t,this.smoothShadow&&this._applySmoothFilter(this._target,h)}return h.texture.colorSpace=f,this._viewer.renderManager.releaseTempTarget(h),e.layers.disable(this._lightLayer),c.layers.mask=u,o.modelObject.traverse(e=>{e.isLight&&e!==this._light.lightObject&&(e.layers=e.userData.__gp_layers,delete e.userData.__gp_layers)}),i.type=a,i.needsUpdate=s,i.autoUpdate=n,e.castShadow=!0,(this._frameNumber<3||this._frameNumber>Math.min(100,this.maxFrameNumber)&&this._frameNumber%4==0)&&(this._updateMaterial(),e.material.setDirty()),!0}_updateMaterial(e=!1){this._attachedMesh&&(e?(this._attachedMesh.material.alphaMap===this._target?.texture&&(this._attachedMesh.material.alphaMap=null),this._attachedMesh.material.aoMap===this._target?.texture&&(this._attachedMesh.material.aoMap=null),this._attachedMesh.material.map===this._target?.texture&&(this._attachedMesh.material.map=null)):this._target&&("alphaMap"===this.groundMapMode&&(this._attachedMesh.material.alphaMap=this._target.texture),"aoMap"===this.groundMapMode&&(this._attachedMesh.material.aoMap=this._target.texture),"map"===this.groundMapMode&&(this._attachedMesh.material.map=this._target.texture)),this._attachedMesh.material&&(this._attachedMesh.material.userData.ALPHA_I_RGBA_PACKING=!e&&"alphaMap"===this.groundMapMode,this._attachedMesh.material.alphaTest=e||"alphaMap"!==this.groundMapMode?0:.01,this._attachedMesh.material.needsUpdate=!0))}_applySmoothFilter(e,t){this._shadowBlurMat.uniforms.colorTexture.value=e.texture,this._shadowBlurMat.uniforms.direction.value.set(1,0),this._shadowBlurMat.uniforms.size.value.set(e.width,e.height),this._viewer.renderManager.blit(t,{material:this._shadowBlurMat}),this._shadowBlurMat.uniforms.colorTexture.value=t.texture,this._shadowBlurMat.uniforms.direction.value.set(0,1),this._shadowBlurMat.uniforms.size.value.set(t.width,t.height),this._viewer.renderManager.blit(e,{material:this._shadowBlurMat})}};qt([f("randomizedLight")],Jt.prototype,"_light"),qt([B(Jt.prototype.reset),f()],Jt.prototype,"maxFrameNumber"),qt([B(Jt.prototype.reset),f()],Jt.prototype,"smoothShadow"),qt([f(),B(Jt.prototype.reset)],Jt.prototype,"shadowMapType"),qt([B(Jt.prototype._groundMapModeChanged),f()],Jt.prototype,"groundMapMode"),qt([f(),B(Jt.prototype._alphaVignetteChanged)],Jt.prototype,"alphaVignette"),qt([f(),B(Jt.prototype._alphaVignetteChanged)],Jt.prototype,"alphaVignetteAxis"),qt([f()],Jt.prototype,"maxBakeCount");let $t=Jt;var Qt=Object.defineProperty,er=(e,t,r,i)=>{for(var a,s=void 0,n=e.length-1;n>=0;n--)(a=e[n])&&(s=a(t,r,s)||s);return s&&Qt(t,r,s),s};const tr=((t=class extends q{constructor(){super(),this.bakedShadows=!0,this.groundReflection=!1,this.physicalReflections=!1,this.autoFrustumSize=!0,this.autoBakeShadows=!0,this.autoResetShadows=()=>{this.autoBakeShadows&&this._shadowBaker?.reset()},this._onSceneUpdate=this._onSceneUpdate.bind(this);const e=n(this),t=e.find(e=>"function"==typeof e);this.uiConfig={label:"Ground",type:"folder",children:[...e.filter(e=>e!==t),...this._extraUiConfig(),t]}}get shadowBaker(){return this._shadowBaker}_refresh3(){this.refresh()}bakeShadows(){this._shadowBaker?.reset()}_createMesh(e){if(e)throw new Error("AdvancedGroundPlugin - mesh should not be provided");const t=new Ot(this._geometry,()=>this._viewer?.renderManager.createTarget({type:_,format:G,colorSpace:ve,size:{width:1024,height:1024},generateMipmaps:!0,depthBuffer:!0,minFilter:xe,magFilter:ye}),0,this._createMaterial()),r=t.onBeforeRender;return t.onBeforeRender=(...e)=>{let i=this._viewer?.getPluginByType("SSReflectionPlugin");i&&i.isDisabled()&&(i=void 0),i&&i.disable(t.uuid,!1),r(...e),i&&i.enable(t.uuid,!1)},t}onAdded(e){super.onAdded(e)}_postFrame(){super._postFrame(),this._viewer&&this.enabled&&this._shadowBaker&&this.bakedShadows&&this._shadowBaker.autoUpdateShadow()}_preRender(){super._preRender(),this._viewer&&(this._mesh.reflectionTargetNeedsUpdate=this._viewer.renderManager.frameCount<1)}onRemove(e){return super.onRemove(e)}_removeMaterial(){if(this._material){if(this._shadowBaker&&this._material.groundMatExtension&&(this._material.unregisterMaterialExtensions?.([this._shadowBaker.materialExtension]),delete this._material.groundMatExtension),this._material.reflectorMatExtension){const e=this._mesh.materialExtension;e||this._viewer?.console.warn("AdavancedGroundPlugin: unable to find the extension to unregister"),this._material.unregisterMaterialExtensions?.([e]),delete this._material.reflectorMatExtension}super._removeMaterial()}}_onSceneUpdate(e){super._onSceneUpdate(e),!1!==e.geometryChanged&&this.autoResetShadows()}refresh(){if(this._viewer){if(!this.isDisabled()){this.bakedShadows&&!this._shadowBaker?(this._shadowBaker=new $t(this._viewer),this._shadowBaker.attachedMesh=this._mesh):!this.bakedShadows&&this._shadowBaker&&(this._shadowBaker.reset(),this._shadowBaker.cleanupMaterial());const e=this._mesh;e.isReflector2&&(e.enabled=this.groundReflection,e.reflectorModePhysical=this.physicalReflections)}super.refresh()}}_refreshTransform(){if(!super._refreshTransform())return!1;if(this.autoFrustumSize){const e=this.shadowBaker;if(e){const t=this.size/2;t!==e.light.shadowParams.frustumSize&&(e.light.shadowParams.frustumSize=t,e.light.updateShadowParams(),e.reset())}}return!0}fromJSON(e,t){return super.fromJSON(e,t)?(void 0===e.autoFrustumSize&&(this.autoFrustumSize=!1),this):null}_refreshMaterial(){if(!this._viewer)return!1;if(super._refreshMaterial(),this._material){if(this.groundReflection&&this._mesh.isReflector2&&!this._material.reflectorMatExtension){const e=this._mesh.materialExtension;e.updaters=[this._viewer.scene,this._viewer.renderManager],this._material.registerMaterialExtensions?.([e]),this._material.reflectorMatExtension=!0}this.bakedShadows&&this._shadowBaker&&!this._material.groundMatExtension&&(this._material.registerMaterialExtensions?.([this._shadowBaker.materialExtension]),this._material.groundMatExtension=!0),this._material.userData.ssreflDisabled=this.groundReflection,this._material.userData.ssreflNonPhysical=!this.physicalReflections,this._material.userData.ssaoDisabled=!0,this._material.userData.sscsDisabled=!0,this._viewer.setDirty(this)}}_extraUiConfig(){return[{label:"Shadow Frames",type:"input",hidden:()=>!this._shadowBaker,stepSize:1,bounds:[1,1e3],property:()=>[this._shadowBaker,"maxFrameNumber"]},{label:"Alpha Vignette",type:"checkbox",hidden:()=>!this._material||(this._material.transmission||0)<1e-4&&!this._material.transparent,property:()=>[this._shadowBaker,"alphaVignette"],limitedUi:!0,onChange:()=>this.uiConfig?.uiRefresh?.(!0,"postFrame")},{label:"Alpha Vignette Axis",type:"dropdown",hidden:()=>!this._shadowBaker?.alphaVignette||!this._material||(this._material.transmission||0)<1e-4&&!this._material.transparent,property:()=>[this._shadowBaker,"alphaVignetteAxis"],children:["x","y","xy"].map(e=>({label:e,value:e})),limitedUi:!0},{label:"Shadow type",type:"dropdown",hidden:()=>!this._shadowBaker,property:()=>[this._shadowBaker,"groundMapMode"],children:[{label:"aoMap"},{label:"map"},{label:"alphaMap"}],limitedUi:!0},{label:"Smooth Shadow",type:"checkbox",property:()=>[this._shadowBaker,"smoothShadow"]},{label:"Baked shadow type",type:"dropdown",children:[["Basic",me],["PCF",Se],["PCFSoft",be],["VSM",we]].map(e=>({label:e[0].toString(),value:e[1]})),property:()=>[this._shadowBaker,"shadowMapType"]},{type:"folder",label:"Randomized Light",hidden:()=>!this._shadowBaker,limitedUi:!0,children:[{type:"color",label:"Color",property:()=>[this._shadowBaker?.light,"color"]},{type:"slider",bounds:[0,1],property:()=>[this._shadowBaker?.light?.randomParams,"focus"],onChange:this.autoResetShadows},{type:"slider",bounds:[0,1],property:()=>[this._shadowBaker?.light?.randomParams,"spread"],onChange:this.autoResetShadows,limitedUi:!0},{type:"slider",bounds:[.01,60],property:()=>[this._shadowBaker?.light?.randomParams,"distanceScale"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"vec3",bounds:[-1,1],property:()=>[this._shadowBaker?.light?.randomParams,"direction"],onChange:this.autoResetShadows,limitedUi:!0},{type:"vec3",bounds:[-1,1],property:()=>[this._shadowBaker?.light?.randomParams,"normalDirection"],onChange:this.autoResetShadows,limitedUi:!0},{type:"slider",bounds:[.01,10],property:()=>[this._shadowBaker?.light?.shadowParams,"radius"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"input",property:()=>[this._shadowBaker?.light?.shadowParams,"frustumSize"],hidden:()=>this.autoFrustumSize,onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"slider",bounds:[-.1,.1],property:()=>[this._shadowBaker?.light?.shadowParams,"bias"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]}]}]}}).PluginType="AdvancedGroundPlugin",t);er([B(tr.prototype._refresh3),o("Baked Shadows"),f()],tr.prototype,"bakedShadows"),er([B(tr.prototype._refresh3),o("Planar Reflections"),f()],tr.prototype,"groundReflection"),er([B(tr.prototype._refresh3),o("Physical Reflections"),f()],tr.prototype,"physicalReflections"),er([B(tr.prototype._refresh3),o("Auto Shadow Frustum Size"),f()],tr.prototype,"autoFrustumSize"),er([f("shadowBaker")],tr.prototype,"_shadowBaker"),er([W({key:"groundReflection"})],tr.prototype,"planarReflections");let rr=tr;var ir=Object.defineProperty,ar=Object.getOwnPropertyDescriptor,sr=(e,t,r,i)=>{for(var a,s=i>1?void 0:i?ar(t,r):t,n=e.length-1;n>=0;n--)(a=e[n])&&(s=(i?a(t,r,s):a(s))||s);return i&&s&&ir(t,r,s),s};let nr=class extends Y{constructor(){super(...arguments),this.enabled=!0,this.dependencies=[],this.axis="y",this.invertAxis=!1,this.analog=!0,this.hourOffset=0,this.minuteOffset=0,this.secondOffset=0,this.hour=".*hour.*",this.minute=".*minute.*",this.second=".*second.*",this.regex=!0,this.hands=[],this._lastEnabled=!0,this._preFrame=()=>{if(!this.enabled){if(this._lastEnabled){if(this._lastEnabled=!1,!this.hands.length)return;for(const e of this.hands)e.object.rotation.fromArray(e.object.userData.initRotation),e.object.updateMatrixWorld();this._viewer?.renderManager.resetShadows(),this._viewer?.setDirty()}return}if(this._lastEnabled=!0,!this.hands.length)return;const e=this._viewer?.getPlugin("ProgressivePlugin")?.postFrameConvergedRecordingDelta();if(0===e)return;const t=/* @__PURE__ */new Date,r=this.invertAxis?-1:1,i=r*(t.getSeconds()+(this.analog?t.getMilliseconds()/1e3:0)-this.secondOffset)*(2*Math.PI)/60,a=r*(t.getMinutes()-this.minuteOffset)*(2*Math.PI)/60+i/60,s=r*(t.getHours()-this.hourOffset)*(2*Math.PI)/12+a/12;if(this.hands.find(e=>"second"===e.type&&Math.abs(i-e.object.rotation[this.axis])>.001)){for(const e of this.hands)"second"===e.type&&(e.object.rotation[this.axis]=i),"minute"===e.type&&(e.object.rotation[this.axis]=a),"hour"===e.type&&(e.object.rotation[this.axis]=s);this._viewer?.renderManager.resetShadows(),this._viewer?.setDirty()}},this._addSceneObject=async e=>{e.object&&this.refresh()}}onAdded(e){super.onAdded(e),e.scene.addEventListener("addSceneObject",this._addSceneObject),e.addEventListener("preFrame",this._preFrame)}onRemove(e){e.scene.removeEventListener("addSceneObject",this._addSceneObject),e.removeEventListener("preFrame",this._preFrame),super.onRemove(e)}refresh(){this.hands=[],this._viewer?.scene.modelRoot.traverse(e=>{let t=!1;e.traverseAncestors(e=>{t||this.hands.find(t=>t.object===e)&&(t=!0)}),t||(e.name.match(this.regex?new RegExp(this.hour):this.hour)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"hour",object:e})),e.name.match(this.regex?new RegExp(this.minute):this.minute)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"minute",object:e})),e.name.match(this.regex?new RegExp(this.second):this.second)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"second",object:e})))})}};nr.PluginType="WatchHandsPlugin",sr([o(),f()],nr.prototype,"enabled",2),sr([Te(void 0,["x","y","z"].map(e=>({label:e}))),f()],nr.prototype,"axis",2),sr([o(),f()],nr.prototype,"invertAxis",2),sr([o(),f()],nr.prototype,"analog",2),sr([O(void 0,[0,12],.001),f()],nr.prototype,"hourOffset",2),sr([O(void 0,[0,60],.001),f()],nr.prototype,"minuteOffset",2),sr([O(void 0,[0,60],.001),f()],nr.prototype,"secondOffset",2),sr([De(),f()],nr.prototype,"hour",2),sr([De(),f()],nr.prototype,"minute",2),sr([De(),f()],nr.prototype,"second",2),sr([o(),B("refresh"),f()],nr.prototype,"regex",2),sr([Pe()],nr.prototype,"refresh",1),nr=sr([E("Watch Hands Time")],nr);const or=[Le,ke,He,ct,at,Ze,ft,bt,Et,rr,nr];export{rr as AdvancedGroundPlugin,Et as AnisotropyPlugin,He as BloomPlugin,We as BloomPluginPass,Ze as DepthOfFieldPlugin,$e as DepthOfFieldPluginPass,ft as OutlinePlugin,mt as OutlineRenderPass,at as SSContactShadowsPlugin,bt as SSGIPlugin,wt as SSGIPluginPass,ct as SSReflectionPlugin,dt as SSReflectionPluginPass,Ie as SSVelocityMaterial,Le as TemporalAAPlugin,Oe as TemporalAAPluginPass,ke as VelocityBufferPlugin,nr as WatchHandsPlugin,Rt as anisotropyGLTFExtension,or as webgiPlugins};
|
|
105
|
+
`))},computeCacheKey:()=>this.groundMapMode+"."+this.alphaVignette+"."+this.alphaVignetteAxis,onObjectRender:(e,t)=>{t.userData.gMapMode!==this.groundMapMode&&(t.userData.gMapMode=this.groundMapMode,t.needsUpdate=!0)},isCompatible:e=>e.isPhysicalMaterial},this._viewer=e;const t=new Ht(16777215,10,{near:1.5,far:20,bias:0,frustumSize:4,width:1024,height:1024,enabled:!0,radius:10,normalBias:0},{direction:new F(.2,1,.2).normalize(),spread:.9,focus:1,distanceScale:20,minDistanceScale:new F(10,10,10),normalDirection:new F(0,1,0)});t.shadow.camera.updateProjectionMatrix(),t.layers.disableAll(),t.layers.set(this._lightLayer),this._light=t,e.scene.addObject(this._light,{addToRoot:!0}),this._shadowMat=new Xt({color:"#ffffff",toneMapped:!1,depthWrite:!1,depthTest:!1,premultipliedAlpha:!1,opacity:1,transparent:!1,blending:T}),this._shadowBlurMat=new ge({uniforms:{colorTexture:{value:null},step:{value:.1},size:{value:new d(.5,.5)},direction:{value:new d(.5,.5)}},vertexShader:V.defaultVertex,fragmentShader:"#include <packing>\nuniform sampler2D colorTexture;uniform vec2 size;uniform vec2 direction;uniform float step;varying vec2 vUv;void main(){float sum=0.0;vec2 uvDelta=step*direction/size;sum+=unpackRGBAToDepth(texture2D(colorTexture,vUv-1.*uvDelta))*0.3333;sum+=unpackRGBAToDepth(texture2D(colorTexture,vec2(vUv.x,vUv.y)))*0.3333;sum+=unpackRGBAToDepth(texture2D(colorTexture,vUv+1.*uvDelta))*0.3333;gl_FragColor=packDepthToRGBA(sum);}"})}get attachedMesh(){return this._attachedMesh}set attachedMesh(e){this._attachedMesh!==e&&(this._attachedMesh&&this.cleanupMaterial(),this._attachedMesh=e,this._attachedMesh&&this._updateMaterial())}get target(){return this._target}get light(){return this._light}dispose(){this._shadowMat.dispose(),this._target=void 0,this.reset()}cleanupMaterial(){this._updateMaterial(!0)}_groundMapModeChanged(){this._attachedMesh&&(this.cleanupMaterial(),this._updateMaterial(),"alphaMap"===this.groundMapMode?this._attachedMesh.material.transparent=!0:this._attachedMesh.material.transparent=!1),this.reset()}_alphaVignetteChanged(){this.materialExtension?.setDirty?.(),this._viewer?.setDirty()}fromJSON(e,t,r=!1){return r?(he.Deserialize(e,this,t,!0),this.reset(),this):he.Deserialize(e,this,t,!1)}reset(){this._frameNumber=0}get frameNumber(){return this._frameNumber}autoUpdateShadow(){return!!this.shadowAutoUpdate&&(!(this._bakeCounter>=this.maxBakeCount)&&(!!this.updateShadow()&&(this._frameNumber===this.maxFrameNumber?this.dispatchEvent({type:"shadowBaked",bakeCount:++this._bakeCounter}):this._frameNumber>0&&this._frameNumber<this.maxFrameNumber&&this.dispatchEvent({type:"shadowBaking",progress:this._frameNumber/this.maxFrameNumber,bakeCount:this._bakeCounter}),!0)))}updateShadow(){if(!this.enabled)return!1;const e=this._attachedMesh;if(!e)return!1;if(++this._frameNumber>this.maxFrameNumber)return!1;const t=1024;this._target||(this._target=this._viewer.renderManager.createTarget({type:_,depthBuffer:!1,size:new d(t,t),sizeMultiplier:void 0,colorSpace:ve,format:G})),this._frameNumber<3?this._light.randomizePosition(0,1,0):this._light.randomizePosition(this._frameNumber),e.castShadow=!1;const r=this._viewer.renderManager.renderer,i=r.shadowMap,a=i.type,s=i.needsUpdate,n=i.autoUpdate;i.type=this.shadowMapType,i.needsUpdate=!0,i.autoUpdate=!1;const o=this._viewer.scene,l=new _e;l.disableAll(),o.traverse(e=>{e.isLight&&e!==this._light&&(e.userData.__gp_layers=e.layers,e.layers=l)});const c=o.mainCamera;if(c.layers.mask&1<<this._lightLayer)throw"Camera can render pseudo directional light, check layers";c.layers.enable(this._lightLayer),e.layers.disable(this._lightLayer),r.renderWithModes({shadowMapRender:!0,backgroundRender:!1,sceneRender:!1},()=>r.render(o,o.mainCamera)),c.layers.disable(this._lightLayer);const u=c.layers.mask;c.layers.set(this._lightLayer),e.layers.enable(this._lightLayer);const h=this._viewer.renderManager.getTempTarget({type:_,depthBuffer:!1,size:new d(t,t),colorSpace:ve,format:G}),p=h.texture,f=p.colorSpace;p.colorSpace=ve,this._viewer.renderManager.blit(h,{clear:!0,source:this._target.texture});{const t=e.material,i=e.frustumCulled,a=r.getRenderTarget(),s=r.getActiveCubeFace(),n=r.getActiveMipmapLevel();e.material=this._shadowMat,e.frustumCulled=!1,r.setRenderTarget(this._target),this._shadowMat.opacity=Math.max(1/this.maxFrameNumber,1/this._frameNumber),this._shadowMat.lastFrameTexture=h.texture,this._shadowMat.needsUpdate=!0,r.renderWithModes({shadowMapRender:!1,backgroundRender:!1,opaqueRender:!0,transparentRender:!1,transmissionRender:!1},()=>r.render(o,o.mainCamera)),r.setRenderTarget(a,s,n),e.frustumCulled=i,e.material=t,this.smoothShadow&&this._applySmoothFilter(this._target,h)}return h.texture.colorSpace=f,this._viewer.renderManager.releaseTempTarget(h),e.layers.disable(this._lightLayer),c.layers.mask=u,o.modelObject.traverse(e=>{e.isLight&&e!==this._light.lightObject&&(e.layers=e.userData.__gp_layers,delete e.userData.__gp_layers)}),i.type=a,i.needsUpdate=s,i.autoUpdate=n,e.castShadow=!0,(this._frameNumber<3||this._frameNumber>Math.min(100,this.maxFrameNumber)&&this._frameNumber%4==0)&&(this._updateMaterial(),e.material.setDirty()),!0}_updateMaterial(e=!1){this._attachedMesh&&(e?(this._attachedMesh.material.alphaMap===this._target?.texture&&(this._attachedMesh.material.alphaMap=null),this._attachedMesh.material.aoMap===this._target?.texture&&(this._attachedMesh.material.aoMap=null),this._attachedMesh.material.map===this._target?.texture&&(this._attachedMesh.material.map=null)):this._target&&("alphaMap"===this.groundMapMode&&(this._attachedMesh.material.alphaMap=this._target.texture),"aoMap"===this.groundMapMode&&(this._attachedMesh.material.aoMap=this._target.texture),"map"===this.groundMapMode&&(this._attachedMesh.material.map=this._target.texture)),this._attachedMesh.material&&(this._attachedMesh.material.userData.ALPHA_I_RGBA_PACKING=!e&&"alphaMap"===this.groundMapMode,this._attachedMesh.material.alphaTest=e||"alphaMap"!==this.groundMapMode?0:.01,this._attachedMesh.material.needsUpdate=!0))}_applySmoothFilter(e,t){this._shadowBlurMat.uniforms.colorTexture.value=e.texture,this._shadowBlurMat.uniforms.direction.value.set(1,0),this._shadowBlurMat.uniforms.size.value.set(e.width,e.height),this._viewer.renderManager.blit(t,{material:this._shadowBlurMat}),this._shadowBlurMat.uniforms.colorTexture.value=t.texture,this._shadowBlurMat.uniforms.direction.value.set(0,1),this._shadowBlurMat.uniforms.size.value.set(t.width,t.height),this._viewer.renderManager.blit(e,{material:this._shadowBlurMat})}};qt([f("randomizedLight")],Jt.prototype,"_light"),qt([B(Jt.prototype.reset),f()],Jt.prototype,"maxFrameNumber"),qt([B(Jt.prototype.reset),f()],Jt.prototype,"smoothShadow"),qt([f(),B(Jt.prototype.reset)],Jt.prototype,"shadowMapType"),qt([B(Jt.prototype._groundMapModeChanged),f()],Jt.prototype,"groundMapMode"),qt([f(),B(Jt.prototype._alphaVignetteChanged)],Jt.prototype,"alphaVignette"),qt([f(),B(Jt.prototype._alphaVignetteChanged)],Jt.prototype,"alphaVignetteAxis"),qt([f()],Jt.prototype,"maxBakeCount");let $t=Jt;var Qt=Object.defineProperty,er=(e,t,r,i)=>{for(var a,s=void 0,n=e.length-1;n>=0;n--)(a=e[n])&&(s=a(t,r,s)||s);return s&&Qt(t,r,s),s};const tr=((t=class extends q{constructor(){super(),this.bakedShadows=!0,this.groundReflection=!1,this.physicalReflections=!1,this.autoFrustumSize=!0,this.autoBakeShadows=!0,this.autoResetShadows=()=>{this.autoBakeShadows&&this._shadowBaker?.reset()},this._onSceneUpdate=this._onSceneUpdate.bind(this);const e=n(this),t=e.find(e=>"function"==typeof e);this.uiConfig={label:"Ground",type:"folder",children:[...e.filter(e=>e!==t),...this._extraUiConfig(),t]}}get shadowBaker(){return this._shadowBaker}_refresh3(){this.refresh()}bakeShadows(){this._shadowBaker?.reset()}_createMesh(e){if(e)throw new Error("AdvancedGroundPlugin - mesh should not be provided");const t=new Ot(this._geometry,()=>this._viewer?.renderManager.createTarget({type:_,format:G,colorSpace:ve,size:{width:1024,height:1024},generateMipmaps:!0,depthBuffer:!0,minFilter:xe,magFilter:ye}),0,this._createMaterial()),r=t.onBeforeRender;return t.onBeforeRender=(...e)=>{let i=this._viewer?.getPluginByType("SSReflectionPlugin");i&&i.isDisabled()&&(i=void 0),i&&i.disable(t.uuid,!1),r(...e),i&&i.enable(t.uuid,!1)},t}onAdded(e){super.onAdded(e)}_postFrame(){super._postFrame(),this._viewer&&this.enabled&&this._shadowBaker&&this.bakedShadows&&this._shadowBaker.autoUpdateShadow()}_preRender(){super._preRender(),this._viewer&&(this._mesh.reflectionTargetNeedsUpdate=this._viewer.renderManager.frameCount<1)}onRemove(e){return super.onRemove(e)}_removeMaterial(){if(this._material){if(this._shadowBaker&&this._material.groundMatExtension&&(this._material.unregisterMaterialExtensions?.([this._shadowBaker.materialExtension]),delete this._material.groundMatExtension),this._material.reflectorMatExtension){const e=this._mesh.materialExtension;e||this._viewer?.console.warn("AdavancedGroundPlugin: unable to find the extension to unregister"),this._material.unregisterMaterialExtensions?.([e]),delete this._material.reflectorMatExtension}super._removeMaterial()}}_onSceneUpdate(e){super._onSceneUpdate(e),"widget"===e?.object?.assetType||e?.object?.userData?.isWidgetRoot||!1!==e.geometryChanged&&this.autoResetShadows()}refresh(){if(this._viewer){if(!this.isDisabled()){this.bakedShadows&&!this._shadowBaker?(this._shadowBaker=new $t(this._viewer),this._shadowBaker.attachedMesh=this._mesh):!this.bakedShadows&&this._shadowBaker&&(this._shadowBaker.reset(),this._shadowBaker.cleanupMaterial());const e=this._mesh;e.isReflector2&&(e.enabled=this.groundReflection,e.reflectorModePhysical=this.physicalReflections)}super.refresh()}}_refreshTransform(){if(!super._refreshTransform())return!1;if(this.autoFrustumSize){const e=this.shadowBaker;if(e){const t=this.size/2;t!==e.light.shadowParams.frustumSize&&(e.light.shadowParams.frustumSize=t,e.light.updateShadowParams(),e.reset())}}return!0}fromJSON(e,t){return super.fromJSON(e,t)?(void 0===e.autoFrustumSize&&(this.autoFrustumSize=!1),this):null}_refreshMaterial(){if(!this._viewer)return!1;if(super._refreshMaterial(),this._material){if(this.groundReflection&&this._mesh.isReflector2&&!this._material.reflectorMatExtension){const e=this._mesh.materialExtension;e.updaters=[this._viewer.scene,this._viewer.renderManager],this._material.registerMaterialExtensions?.([e]),this._material.reflectorMatExtension=!0}this.bakedShadows&&this._shadowBaker&&!this._material.groundMatExtension&&(this._material.registerMaterialExtensions?.([this._shadowBaker.materialExtension]),this._material.groundMatExtension=!0),this._material.userData.ssreflDisabled=this.groundReflection,this._material.userData.ssreflNonPhysical=!this.physicalReflections,this._material.userData.ssaoDisabled=!0,this._material.userData.sscsDisabled=!0,this._viewer.setDirty(this)}}_extraUiConfig(){return[{label:"Shadow Frames",type:"input",hidden:()=>!this._shadowBaker,stepSize:1,bounds:[1,1e3],property:()=>[this._shadowBaker,"maxFrameNumber"]},{label:"Alpha Vignette",type:"checkbox",hidden:()=>!this._material||(this._material.transmission||0)<1e-4&&!this._material.transparent,property:()=>[this._shadowBaker,"alphaVignette"],limitedUi:!0,onChange:()=>this.uiConfig?.uiRefresh?.(!0,"postFrame")},{label:"Alpha Vignette Axis",type:"dropdown",hidden:()=>!this._shadowBaker?.alphaVignette||!this._material||(this._material.transmission||0)<1e-4&&!this._material.transparent,property:()=>[this._shadowBaker,"alphaVignetteAxis"],children:["x","y","xy"].map(e=>({label:e,value:e})),limitedUi:!0},{label:"Shadow type",type:"dropdown",hidden:()=>!this._shadowBaker,property:()=>[this._shadowBaker,"groundMapMode"],children:[{label:"aoMap"},{label:"map"},{label:"alphaMap"}],limitedUi:!0},{label:"Smooth Shadow",type:"checkbox",property:()=>[this._shadowBaker,"smoothShadow"]},{label:"Baked shadow type",type:"dropdown",children:[["Basic",me],["PCF",Se],["PCFSoft",be],["VSM",we]].map(e=>({label:e[0].toString(),value:e[1]})),property:()=>[this._shadowBaker,"shadowMapType"]},{type:"folder",label:"Randomized Light",hidden:()=>!this._shadowBaker,limitedUi:!0,children:[{type:"color",label:"Color",property:()=>[this._shadowBaker?.light,"color"]},{type:"slider",bounds:[0,1],property:()=>[this._shadowBaker?.light?.randomParams,"focus"],onChange:this.autoResetShadows},{type:"slider",bounds:[0,1],property:()=>[this._shadowBaker?.light?.randomParams,"spread"],onChange:this.autoResetShadows,limitedUi:!0},{type:"slider",bounds:[.01,60],property:()=>[this._shadowBaker?.light?.randomParams,"distanceScale"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"vec3",bounds:[-1,1],property:()=>[this._shadowBaker?.light?.randomParams,"direction"],onChange:this.autoResetShadows,limitedUi:!0},{type:"vec3",bounds:[-1,1],property:()=>[this._shadowBaker?.light?.randomParams,"normalDirection"],onChange:this.autoResetShadows,limitedUi:!0},{type:"slider",bounds:[.01,10],property:()=>[this._shadowBaker?.light?.shadowParams,"radius"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"input",property:()=>[this._shadowBaker?.light?.shadowParams,"frustumSize"],hidden:()=>this.autoFrustumSize,onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"slider",bounds:[-.1,.1],property:()=>[this._shadowBaker?.light?.shadowParams,"bias"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]}]}]}}).PluginType="AdvancedGroundPlugin",t);er([B(tr.prototype._refresh3),o("Baked Shadows"),f()],tr.prototype,"bakedShadows"),er([B(tr.prototype._refresh3),o("Planar Reflections"),f()],tr.prototype,"groundReflection"),er([B(tr.prototype._refresh3),o("Physical Reflections"),f()],tr.prototype,"physicalReflections"),er([B(tr.prototype._refresh3),o("Auto Shadow Frustum Size"),f()],tr.prototype,"autoFrustumSize"),er([f("shadowBaker")],tr.prototype,"_shadowBaker"),er([W({key:"groundReflection"})],tr.prototype,"planarReflections");let rr=tr;var ir=Object.defineProperty,ar=Object.getOwnPropertyDescriptor,sr=(e,t,r,i)=>{for(var a,s=i>1?void 0:i?ar(t,r):t,n=e.length-1;n>=0;n--)(a=e[n])&&(s=(i?a(t,r,s):a(s))||s);return i&&s&&ir(t,r,s),s};let nr=class extends Y{constructor(){super(...arguments),this.enabled=!0,this.dependencies=[],this.axis="y",this.invertAxis=!1,this.analog=!0,this.hourOffset=0,this.minuteOffset=0,this.secondOffset=0,this.hour=".*hour.*",this.minute=".*minute.*",this.second=".*second.*",this.regex=!0,this.hands=[],this._lastEnabled=!0,this._preFrame=()=>{if(!this.enabled){if(this._lastEnabled){if(this._lastEnabled=!1,!this.hands.length)return;for(const e of this.hands)e.object.rotation.fromArray(e.object.userData.initRotation),e.object.updateMatrixWorld();this._viewer?.renderManager.resetShadows(),this._viewer?.setDirty()}return}if(this._lastEnabled=!0,!this.hands.length)return;const e=this._viewer?.getPlugin("ProgressivePlugin")?.postFrameConvergedRecordingDelta();if(0===e)return;const t=/* @__PURE__ */new Date,r=this.invertAxis?-1:1,i=r*(t.getSeconds()+(this.analog?t.getMilliseconds()/1e3:0)-this.secondOffset)*(2*Math.PI)/60,a=r*(t.getMinutes()-this.minuteOffset)*(2*Math.PI)/60+i/60,s=r*(t.getHours()-this.hourOffset)*(2*Math.PI)/12+a/12;if(this.hands.find(e=>"second"===e.type&&Math.abs(i-e.object.rotation[this.axis])>.001)){for(const e of this.hands)"second"===e.type&&(e.object.rotation[this.axis]=i),"minute"===e.type&&(e.object.rotation[this.axis]=a),"hour"===e.type&&(e.object.rotation[this.axis]=s);this._viewer?.renderManager.resetShadows(),this._viewer?.setDirty()}},this._addSceneObject=async e=>{e.object&&this.refresh()}}onAdded(e){super.onAdded(e),e.scene.addEventListener("addSceneObject",this._addSceneObject),e.addEventListener("preFrame",this._preFrame)}onRemove(e){e.scene.removeEventListener("addSceneObject",this._addSceneObject),e.removeEventListener("preFrame",this._preFrame),super.onRemove(e)}refresh(){this.hands=[],this._viewer?.scene.modelRoot.traverse(e=>{let t=!1;e.traverseAncestors(e=>{t||this.hands.find(t=>t.object===e)&&(t=!0)}),t||(e.name.match(this.regex?new RegExp(this.hour):this.hour)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"hour",object:e})),e.name.match(this.regex?new RegExp(this.minute):this.minute)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"minute",object:e})),e.name.match(this.regex?new RegExp(this.second):this.second)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"second",object:e})))})}};nr.PluginType="WatchHandsPlugin",sr([o(),f()],nr.prototype,"enabled",2),sr([Te(void 0,["x","y","z"].map(e=>({label:e}))),f()],nr.prototype,"axis",2),sr([o(),f()],nr.prototype,"invertAxis",2),sr([o(),f()],nr.prototype,"analog",2),sr([O(void 0,[0,12],.001),f()],nr.prototype,"hourOffset",2),sr([O(void 0,[0,60],.001),f()],nr.prototype,"minuteOffset",2),sr([O(void 0,[0,60],.001),f()],nr.prototype,"secondOffset",2),sr([De(),f()],nr.prototype,"hour",2),sr([De(),f()],nr.prototype,"minute",2),sr([De(),f()],nr.prototype,"second",2),sr([o(),B("refresh"),f()],nr.prototype,"regex",2),sr([Pe()],nr.prototype,"refresh",1),nr=sr([E("Watch Hands Time")],nr);const or=[Le,ke,He,ct,at,Ze,ft,bt,Et,rr,nr];export{rr as AdvancedGroundPlugin,Et as AnisotropyPlugin,He as BloomPlugin,We as BloomPluginPass,Ze as DepthOfFieldPlugin,$e as DepthOfFieldPluginPass,ft as OutlinePlugin,mt as OutlineRenderPass,at as SSContactShadowsPlugin,bt as SSGIPlugin,wt as SSGIPluginPass,ct as SSReflectionPlugin,dt as SSReflectionPluginPass,Ie as SSVelocityMaterial,Le as TemporalAAPlugin,Oe as TemporalAAPluginPass,ke as VelocityBufferPlugin,nr as WatchHandsPlugin,Rt as anisotropyGLTFExtension,or as webgiPlugins};
|
|
106
106
|
//# sourceMappingURL=index.mjs.map
|