@threepipe/webgi-plugins 0.6.1 → 0.6.2
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/LICENSE +2 -7
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/postprocessing/OutlinePlugin.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -19,11 +19,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
19
19
|
|
|
20
20
|
ADDITIONAL TERMS FOR WEBGI-PLUGINS
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
The free set of plugins included in this package can be used by everyone, both for personal and commercial purposes, without any restrictions. The source code shall be used in accordance with the terms of the GNU General Public License (GPL) v3.0.
|
|
22
|
+
The free set of plugins included in this package can be used by everyone, both for personal and commercial purposes, without any restrictions. The source code shall be used in accordance with the terms of the GNU General Public License (GPL) v3.0.
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
- Individuals or companies with **less than $100,000 USD in annual revenue or funding** may use the paid plugins by adding an attribution without purchasing a license.
|
|
27
|
-
- Companies or individuals exceeding this revenue or funding threshold must purchase a commercial license to use the paid plugins.
|
|
28
|
-
|
|
29
|
-
For more details or to purchase a license, visit the website at <https://webgi.dev/pricing.html> or contact us at <contact@ijewel3d.com>.
|
|
24
|
+
For more details or to checkout other paid packages, visit the website at <https://webgi.dev/pricing.html>.
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
#endif
|
|
35
35
|
`,computeCacheKey:()=>(this.enabled?"1":"0")+t.getOrCall(this.target)?.texture?.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,a&&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,ssrRoughnessFactor:this.material.uniforms.ssrRoughnessFactor,frameCount:this.material.uniforms.frameCount,currentFrameCount:this.material.uniforms.currentFrameCount,projection:this.material.uniforms.projection,cameraPositionWorld:this.material.uniforms.cameraPositionWorld,cameraNearFar:this.material.uniforms.cameraNearFar,sceneBoundingRadius:this.material.uniforms.sceneBoundingRadius,currentProjectionViewMatrix:this.material.uniforms.currentProjectionViewMatrix,lastProjectionViewMatrix:this.material.uniforms.lastProjectionViewMatrix,inverseViewMatrix:this.material.uniforms.inverseViewMatrix,ssrSplitX:this.material.uniforms.ssrSplitX})}setDirty(){this.materialExtension?.setDirty?.(),super.setDirty()}render(e,i,r,a,n){if(!this.enabled)return;if(this.inlineShaderRayTrace)return void(this.needsSwap=!1);const s=t.getOrCall(this.target);s?(this.material.defines.HAS_GBUFFER||console.warn("SSReflectionPluginPass: DepthNormalBuffer required for ssrefl"),e.renderManager.blit(i,{source:s.texture}),this.uniforms.tLastThis.value=i.texture,super.render(e,s,r,a,n),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)))}},L([t.uiSlider("Intensity",[0,4]),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"intensity",2),L([t.uiVector("Boost"),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"boost",2),L([t.uiSlider("Object Radius",[.01,2]),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"objectRadius",2),L([t.uiToggle("Auto radius"),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"autoRadius",2),L([t.uiSlider("Power",[0,3]),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"power",2),L([t.uiSlider("Tolerance",[.1,5]),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"tolerance",2),L([t.uiSlider("Roughness Factor",[.1,1.25]),t.serialize(),t.uniform({propKey:"ssrRoughnessFactor"})],e.SSReflectionPluginPass.prototype,"roughnessFactor",2),L([t.uiSlider("Step count",[1,32],1,{tags:["performance"]}),t.serialize(),t.matDefine("SSR_STEP_COUNT",void 0,void 0,e.SSReflectionPluginPass.prototype.setDirty)],e.SSReflectionPluginPass.prototype,"stepCount",2),L([t.uiSlider("Ray count",[1,8],1,{tags:["performance"]}),t.serialize(),t.matDefine("SSR_RAY_COUNT",void 0,void 0,e.SSReflectionPluginPass.prototype.setDirty)],e.SSReflectionPluginPass.prototype,"rayCount",2),L([t.uiToggle("Ray Blend MAX"),t.serialize(),t.matDefineBool("SSR_RAY_BLEND_MAX",void 0,void 0,e.SSReflectionPluginPass.prototype.setDirty,!0)],e.SSReflectionPluginPass.prototype,"rayBlendMax",2),L([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),L([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),L([t.uiSlider("Mask front rays factor",[-1,1],.01,e=>({hidden:()=>!e.maskFrontRays})),t.serialize(),t.uniform()],e.SSReflectionPluginPass.prototype,"maskFrontFactor",2),L([t.uiSlider("Split",[0,1],.01,{tags:["debug"]}),t.serialize(),t.uniform({propKey:"ssrSplitX",onChange:e.SSReflectionPluginPass.prototype.setDirty})],e.SSReflectionPluginPass.prototype,"split",2),e.SSReflectionPluginPass=L([t.uiFolderContainer("SSReflection Pass")],e.SSReflectionPluginPass);var N=Object.defineProperty,F=Object.getOwnPropertyDescriptor,k=(e,t,i,r)=>{for(var a,n=r>1?void 0:r?F(t,i):t,s=e.length-1;s>=0;s--)(a=e[s])&&(n=(r?a(t,i,n):a(n))||n);return r&&n&&N(t,i,n),n};e.OutlinePlugin=class extends t.AScreenPassExtensionPlugin{constructor(e=!0,i=t.UnsignedByteType){super(),this.passId="outline",this.extraUniforms={outlineIntensity:{value:1},outlineThickness:{value:2},highlightTransparency:{value:1},outlineColor:{value:new t.Color(15305317)},enableHighlight:{value:!0},dpr:{value:1},outlineBuffer:{value:null},tDiffuseSize:{value:new t.Vector2(1024,1024)}},this.extraDefines={DEBUG_OUTLINE:"0"},this.priority=-101,this.enableHighlight=!1,this.enableDynamicSelection=!0,this.intensity=2,this.highlightTransparency=.84,this.color=new t.Color(15305317),this.thickness=2,this.debugOutline=!1,this.highlightSelectedMaterials=!1,this.highlightMaterialSameNames=!1,this.transparency=0,this.parsFragmentSnippet=()=>this.isDisabled()?"":t.glsl`
|
|
36
36
|
${"uniform sampler2D outlineBuffer;uniform vec2 tDiffuseSize;uniform vec3 outlineColor;uniform float outlineThickness;uniform float outlineIntensity;uniform float highlightTransparency;uniform bool enableHighlight;uniform float dpr;float isSelected(vec2 uv){return 1.-texture2D(outlineBuffer,uv).b;}vec4 outline(in vec4 color){vec2 invSize=1.0/tDiffuseSize;\n#if DEBUG_OUTLINE > 0\ncolor=vec4(0.,0.,0.,1.);\n#endif\nvec3 finalColor=color.rgb;float c=isSelected(vUv);if(c>0.){vec4 uvOffset=1.5*dpr*outlineThickness*vec4(1.0,0.0,-1.0,1.0)*vec4(invSize,invSize);float c1=isSelected(vUv+uvOffset.xy);float c2=isSelected(vUv-uvOffset.xy);float c3=isSelected(vUv+uvOffset.yw);float c4=isSelected(vUv-uvOffset.yw);float diff1=(c1-c2)*0.5;float diff2=(c3-c4)*0.5;float d=length(vec2(diff1,diff2));vec4 highlightColor=enableHighlight ? vec4(c*outlineColor,(1.-highlightTransparency)*c): vec4(0.);vec4 edgeColor=vec4(outlineColor,1.)*vec4(d);float gbufferDepth=getDepth(vUv);float outlineDepth=unpack16(texture2D(outlineBuffer,vUv).xy);outlineDepth*=outlineDepth;outlineDepth-=0.005;if(gbufferDepth<outlineDepth){highlightColor.rgb=highlightColor.rgb*0.3;edgeColor.rgb=edgeColor.rgb*0.5;}vec4 outColor=edgeColor+highlightColor*(1.-d);finalColor=mix(color.rgb,outlineIntensity*outColor.rgb,outColor.a);}else{finalColor.rgb=color.rgb;}return vec4(finalColor.rgb,color.a);}"}
|
|
37
|
-
`,this._shaderPatch="diffuseColor = outline(diffuseColor);",this.dependencies=[t.PickingPlugin,t.GBufferPlugin],this._pickingWidgetDisabled=!1,this.material=new t.ShaderMaterial({uniforms:{cameraNearFar:{value:new t.Vector2(.1,100)}},vertexShader:"#ifdef USE_ALPHAMAP\n#define USE_UV\n#endif\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec3 vViewPosition;void main(){\n#include <skinbase_vertex>\n#include <begin_vertex>\n#include <morphtarget_vertex>\n#include <skinning_vertex>\n#include <displacementmap_vertex>\n#include <project_vertex>\n#include <logdepthbuf_vertex>\n#include <clipping_planes_vertex>\nvViewPosition=-mvPosition.xyz;}",fragmentShader:"uniform vec2 cameraNearFar;varying vec3 vViewPosition;vec2 pack16(float value){float sMax=65535.0;int v=int(clamp(value,0.0,1.0)*sMax+0.5);int digit0=v/256;int digit1=v-digit0*256;return vec2(float(digit0)/255.0,float(digit1)/255.0);}float linstep(float edge0,float edge1,float value){return clamp((value-edge0)/(edge1-edge0),0.0,1.0);}void main(){float linearZ=linstep(-cameraNearFar.x,-cameraNearFar.y,-vViewPosition.z);vec2 packedZ=pack16(pow(max(0.,linearZ),0.5));gl_FragColor=vec4(packedZ.x,packedZ.y,0.,0.);}",side:t.DoubleSide}),this._getSelectedObject=()=>{if(!this._viewer)return null;const e=this._viewer.getPlugin(t.PickingPlugin);if(this.highlightSelectedMaterials){const t=e?.getSelectedObject()?.material||null;if(this.highlightMaterialSameNames&&t){const e=Array.isArray(t)?t.map(e=>e.name):[t.name],i=new Set;for(const t of e){const e=this._viewer?.assetManager?.materials?.findMaterialsByName(t);e?.forEach(e=>i.add(e))}return[...i]}return t}return e?.getSelectedObject()||null},this._viewerListeners={preRender:()=>{!this.isDisabled()&&this._viewer&&(this.extraUniforms.dpr.value=2*this._viewer.renderManager.renderScale)}},this.mouseInOutAnimationEnabled=!0,this._state="in",this.enabled=e,this.bufferType=i}setDirty(){if(super.setDirty(),!this._viewer)return;const e=this._viewer.getPlugin(t.PickingPlugin);let i=!this.isDisabled();if(i){const t=e?.getSelectedObject();"string"==typeof t?.type&&t?.type?.includes("Line")&&(i=!1)}e&&(i&&e.widgetEnabled?(e.widgetEnabled=!1,this._pickingWidgetDisabled=!0):!i&&this._pickingWidgetDisabled&&(e.widgetEnabled=!0,this._pickingWidgetDisabled=!1)),this._viewer.setDirty()}onAdded(e){super.onAdded(e),this.setDirty(),this._pass=this._createPass(),this._pass.onDirty?.push(e.setDirty),e.renderManager.registerPass(this._pass);const i=e.getPlugin(t.PickingPlugin);i?.addEventListener("selectedObjectChanged",()=>{!this._animationCallBack&&this&&(i?.getSelectedObject()?this.enableDynamicSelection?(this.transparency=1,this._animationCallBack=this._startTransparencyAnimation(1,this.highlightTransparency,400)):this.transparency=this.highlightTransparency:this.transparency=1)}),document.addEventListener("mousemove",t=>{if(!this)return;if(!this.mouseInOutAnimationEnabled)return;if(!this.enableHighlight)return;const r=i?.getSelectedObject();r&&this.enableDynamicSelection?t.target!==e.canvas?this._animationCallBack||"in"!==this._state||(this._animationCallBack=this._startTransparencyAnimation(this.highlightTransparency,1,600),this._state="out"):this._animationCallBack||"out"!==this._state||(this._animationCallBack=this._startTransparencyAnimation(1,this.highlightTransparency,600),this._state="in"):this.transparency=r?this.highlightTransparency:1})}onRemove(e){return this._disposeTarget(),this._pass&&(e.renderManager.unregisterPass(this._pass),this._pass.dispose&&this._pass.dispose()),this._pass=void 0,super.onRemove(e)}_createTarget(e=!0){this._viewer&&(e&&this._disposeTarget(),this.target||(this.target=this._viewer.renderManager.createTarget({sizeMultiplier:1,type:this.bufferType})),this.texture=this.target.texture,this.texture.name="normalBuffer")}_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("OutlinePlugin: target not created");this.material.userData.isOutlinePluginMaterial=!0;return new e.OutlineRenderPass(this.passId,this._getSelectedObject,()=>this.target,this.material)}async _startTransparencyAnimation(e,i,r){return t.animateTarget(this,"transparency",{from:e,to:i,duration:r,onComplete:()=>{this._animationCallBack=void 0}})}get outlineIntensity(){return console.warn("OutlinePlugin.outlineIntensity is deprecated, use OutlinePlugin.intensity instead"),this.intensity}set outlineIntensity(e){console.warn("OutlinePlugin.outlineIntensity is deprecated, use OutlinePlugin.intensity instead"),this.intensity=e}get outlineColor(){return console.warn("OutlinePlugin.outlineColor is deprecated, use OutlinePlugin.intensity instead"),this.intensity}set outlineColor(e){console.warn("OutlinePlugin.outlineColor is deprecated, use OutlinePlugin.intensity instead"),this.intensity=e}},e.OutlinePlugin.PluginType="OutlinePlugin",e.OutlinePlugin.OldPluginType="Outline",k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiToggle("Enable"),t.serialize()],e.OutlinePlugin.prototype,"enabled",2),k([t.uiToggle("Highlight"),t.uniform({propKey:"enableHighlight"}),t.serialize()],e.OutlinePlugin.prototype,"enableHighlight",2),k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiToggle("DynamicSelection"),t.serialize()],e.OutlinePlugin.prototype,"enableDynamicSelection",2),k([t.uiSlider("Intensity",[0,4],.001),t.uniform({propKey:"outlineIntensity"}),t.serialize("outlineIntensity")],e.OutlinePlugin.prototype,"intensity",2),k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiSlider("Transparency",[0,1],.01),t.serialize()],e.OutlinePlugin.prototype,"highlightTransparency",2),k([t.uiColor("Color"),t.uniform({propKey:"outlineColor"}),t.serialize("outlineColor")],e.OutlinePlugin.prototype,"color",2),k([t.uiSlider("Thickness",[0,10],.01),t.uniform({propKey:"outlineThickness"}),t.serialize("outlineThickness")],e.OutlinePlugin.prototype,"thickness",2),k([t.uiToggle("Debug"),t.matDefineBool("DEBUG_OUTLINE",void 0,!0)],e.OutlinePlugin.prototype,"debugOutline",2),k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiToggle("Highlight Selected Materials")],e.OutlinePlugin.prototype,"highlightSelectedMaterials",2),k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiToggle("Highlight Materials (same name)")],e.OutlinePlugin.prototype,"highlightMaterialSameNames",2),k([t.uniform({propKey:"highlightTransparency"})],e.OutlinePlugin.prototype,"transparency",2),k([t.uniform({propKey:"outlineBuffer"}),t.uiImage("Outline Buffer",{readOnly:!0})],e.OutlinePlugin.prototype,"texture",2),e.OutlinePlugin=k([t.uiFolderContainer("Selection Outline")],e.OutlinePlugin),e.OutlineRenderPass=class extends t.RenderPass{constructor(e,i,r,a){super(void 0,void 0,a,new t.Color(1,1,1),1),this.passId=e,this._getSelectedObjectOrMaterial=i,this.target=r,this.isOutlineRenderPass=!0,this.enabled=!0,this.before=["render"],this.after=["gbuffer"],this.required=["render","gbuffer"],this.onDirty=[]}render(e,i,r,a,n){if(!this.scene||!this.camera||!this.enabled)return;const s=e.getRenderTarget(),o=e.getActiveCubeFace(),l=e.getActiveMipmapLevel(),c=this._getSelectedObjectOrMaterial();if(c)this._renderSelectedObject(e,c,i||null,a,n);else{e.setRenderTarget(t.getOrCall(this.target)||null);const i=new t.Color;e.getClearColor(i),e.setClearColor(new t.Color(16777215)),e.clear(!0,!0),e.setClearColor(i)}e.setRenderTarget(s,o,l)}_renderSelectedObject(e,i,r,a,n){if(!this.camera||!i)return;const s=(Array.isArray(i)?i:[i]).flatMap(e=>e?.isTexture?[...e.appliedObjects?.values()||[]]:e).flatMap(e=>e?.isMaterial||e?.isBufferGeometry?[...e.appliedMeshes?.values()||[]]:e);for(const t of s)t&&t.traverse(e=>{e.layers.enable(6)});const o=this.camera.layers.mask;this.camera.layers.set(6);const l=e.userData;l||console.error("threejs is not patched?"),l.transmissionRenderTarget=r,e.renderWithModes({shadowMapRender:!1,backgroundRender:!1,opaqueRender:!0,transparentRender:!0,transmissionRender:!0,mainRenderPass:!1},()=>super.render(e,r,t.getOrCall(this.target),a,n)),l.transmissionRenderTarget=void 0,s.forEach(e=>e.traverse(e=>{e.layers.disable(6)})),this.camera.layers.mask=o}dispose(){this.onDirty=[],this.scene=void 0,this.camera=void 0,super.dispose?.()}setDirty(){this.onDirty.forEach(e=>e())}beforeRender(e,t,i){this.scene=e,this.camera=t,t.updateShaderProperties(this.overrideMaterial)}},k([t.uiToggle("Enabled")],e.OutlineRenderPass.prototype,"enabled",2),e.OutlineRenderPass=k([t.uiFolderContainer(e=>e.passId+" Render Pass")],e.OutlineRenderPass);var z=Object.defineProperty,I=(e,t,i,r)=>{for(var a,n=void 0,s=e.length-1;s>=0;s--)(a=e[s])&&(n=a(t,i,n)||n);return n&&z(t,i,n),n};class V extends t.ExtendedShaderPass{constructor(e,i="rgba"){super({vertexShader:t.CopyShader.vertexShader,fragmentShader:"\n// for gbuffer\n#include <packing>\n#define THREE_PACKING_INCLUDED\nuniform vec2 tDiffuseSize;uniform vec2 bilDirection;varying vec2 vUv;uniform bool smoothEnabled;uniform float edgeSharpness;vec4 bilaterialAO(){vec4 color=clamp((texture2D(tDiffuse,vUv.xy)).B_SRC_ACCESSOR,0.,5.);if(!smoothEnabled)return color;float depth;vec3 normal;getDepthNormal(vUv.xy,depth,normal);float gaussianWeights[4];gaussianWeights[0]=0.153170;gaussianWeights[1]=0.144893;gaussianWeights[2]=0.122649;gaussianWeights[3]=0.092902;float Z=gaussianWeights[0]+0.03;vec4 final_colour=Z*color;vec2 nuv;vec4 cc;float dp;vec3 nor;vec2 direction=bilDirection/tDiffuseSize.xy;\n#pragma unroll_loop_start\nfor(int i=0;i<6;i++){direction*=-1.;nuv=vUv+2.*direction*float(UNROLLED_LOOP_INDEX/2+1);getDepthNormal(nuv,dp,nor);if(dp<0.999){float normalCloseness=dot(normal,nor);normalCloseness*=normalCloseness;float normalError=(1.0-normalCloseness)*8.;float normalWeight=max((1.0-normalError*edgeSharpness),0.00);float depthWeight=max(0.0,1.0-edgeSharpness*4000.*abs(depth-dp));float kernelWeight=gaussianWeights[UNROLLED_LOOP_INDEX/2]+0.03;float bilateralWeight=kernelWeight*depthWeight*normalWeight;Z+=bilateralWeight;cc=clamp((texture2D(tDiffuse,nuv)).B_SRC_ACCESSOR,0.,5.);final_colour+=bilateralWeight*cc;}}\n#pragma unroll_loop_end\nfinal_colour/=Z;return final_colour;}void main(){vec4 ao=clamp(bilaterialAO(),vec4(0.),vec4(1.));gl_FragColor=ao;}",uniforms:{bilDirection:{value:new t.Vector2(1,0)},tDiffuse:{value:null},tDiffuseSize:{value:new t.Vector2}},defines:{B_SRC_ACCESSOR:i}},"tDiffuse"),this.target=e,this.smoothEnabled=!0,this.edgeSharpness=.1,this.clear=!1,this.needsSwap=!1}render(e,i,r,a,n){if(!this.enabled)return;const s=t.getOrCall(this.target);s&&(this.uniforms.bilDirection.value.set(1,0),this.uniforms.tDiffuse.value=s.texture,this.uniforms.tDiffuseSize.value.set(this.uniforms.tDiffuse.value?.image.width||0,this.uniforms.tDiffuse.value?.image.height||0),super.render(e,i,s,a,n),this.uniforms.bilDirection.value.set(0,1),this.uniforms.tDiffuse.value=i.texture,this.uniforms.tDiffuseSize.value.set(this.uniforms.tDiffuse.value?.image.width||0,this.uniforms.tDiffuse.value?.image.height||0),super.render(e,s,i,a,n))}}I([t.serialize(),t.uniform()],V.prototype,"smoothEnabled"),I([t.serialize(),t.uniform()],V.prototype,"edgeSharpness");var G=Object.defineProperty,j=Object.getOwnPropertyDescriptor,H=(e,t,i,r)=>{for(var a,n=r>1?void 0:r?j(t,i):t,s=e.length-1;s>=0;s--)(a=e[s])&&(n=(r?a(t,i,n):a(n))||n);return r&&n&&G(t,i,n),n};e.SSGIPlugin=class extends t.PipelinePassPlugin{constructor(e=t.UnsignedByteType,i=1,r=!0){super(),this.passId="ssrtgi",this.dependencies=[t.GBufferPlugin,t.SSAAPlugin],this._gbufferUnpackExtension=void 0,this._gbufferUnpackExtensionChanged=()=>{if(!this._pass||!this._viewer)throw new Error("SSGIPlugin: 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("SSGIPlugin: GBuffer unpack extension removed"))},this.enabled=r,this.bufferType=e,this.sizeMultiplier=i}_createTarget(e=!0){this._viewer&&(e&&this._disposeTarget(),this.target||(this.target=this._viewer.renderManager.createTarget({depthBuffer:!1,type:this.bufferType,sizeMultiplier:this.sizeMultiplier})),this.texture=this.target.texture,this.texture.name="ssgiBuffer")}_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("SSGIPlugin: viewer not set");if(!this._viewer.renderManager.gbufferTarget||!this._viewer.renderManager.gbufferUnpackExtension)throw new Error("SSGIPlugin: GBuffer target not created. GBufferPlugin is required.");return this._createTarget(!0),new e.SSGIPluginPass(this.passId,()=>this.target)}onAdded(t){super.onAdded(t),(t.getPlugin("Ground")||t.getPlugin("BaseGroundPlugin"))&&console.warn("GroundPlugin must be added after SSGIPlugin"),this._gbufferUnpackExtensionChanged(),t.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),t.forPlugin(e.VelocityBufferPlugin,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)}fromJSON(e,t){return e.passes?.ssrtgi&&((e={...e}).pass=e.passes.ssrtgi,delete e.passes,void 0!==e.pass.enabled&&(e.enabled=e.pass.enabled)),super.fromJSON(e,t)}_beforeRender(i,r,a){if(!this._viewer)return!1;const n=super._beforeRender(i,r,a);if(n){const t=this._viewer?.getPlugin("SSAOPlugin");t&&!t.isDisabled()&&t.disable(e.SSGIPlugin.PluginType)}if(!n)return n;const s=this._viewer.getPlugin(t.ProgressivePlugin);return this._pass?.updateShaderProperties([s]),n}get rtgiTarget(){return console.warn("SSGIPlugin: rtgiTarget is deprecated, use target instead"),this.target}},e.SSGIPlugin.PluginType="SSGIPlugin",e.SSGIPlugin.OldPluginType="SSGI",H([t.uiImage("SSGI Buffer",{readOnly:!0})],e.SSGIPlugin.prototype,"texture",2),H([t.uiConfig(void 0,{unwrapContents:!0})],e.SSGIPlugin.prototype,"_pass",2),e.SSGIPlugin=H([t.uiFolderContainer("SSGI Plugin")],e.SSGIPlugin),e.SSGIPluginPass=class extends t.ExtendedShaderPass{constructor(i,r,a=!0){super({defines:{RTAO_STEP_COUNT:16,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},opacity:{value:1},intensity:{value:0},objectRadius:{value:0},autoRadius:{value:!a},rayCount:{value:.1},bias:{value:.015},falloff:{value:.7},power:{value:1.1},tolerance:{value:0},sceneBoundingRadius:{value:0},currentProjectionViewMatrix:{value:new t.Matrix4},lastProjectionViewMatrix:{value:new t.Matrix4},inverseViewMatrix:{value:new t.Matrix4},ssrtaoSplitX:{value:.5}},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${A}\n\n${C}\n\n${n().calculateGI}\n `},"tDiffuse","tLastThis","tLastFrame"),this.target=r,this.before=["render"],this.after=["gbuffer","depth"],this.required=["render","progressive"],this.giEnabled=!0,this.intensity=2,this.power=1.1,this.autoRadius=!0,this.objectRadius=1,this.tolerance=1,this.bias=.001,this.falloff=.7,this.rayCount=4,this.stepCount=8,this.smoothEnabled=!0,this.renderWithCamera=!0,this.split=0,this.materialExtension={extraUniforms:{tSSGIMap:()=>({value:t.getOrCall(this.target)?.texture??null}),ssaoPower:this.material.uniforms.power,ssgiIntensity:this.material.uniforms.intensity,ssrtaoSplitX:this.material.uniforms.ssrtaoSplitX},extraDefines:{SSGI_ENABLED:()=>this.material.defines.SSGI_ENABLED},shaderExtender:(e,i,r)=>{if(!e.defines?.SSRTAO_ENABLED)return;e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"vec3 totalDiffuse =","\n \n \n#if defined(SSRTAO_ENABLED) && SSRTAO_ENABLED > 0\nvec3 screenPos_gi=viewToScreen(vViewPosition.xyz);\n#if SSRTAO_ENABLED == 2\nif(screenPos_gi.x>ssrtaoSplitX){\n#endif\nvec4 ssgi=tSSGIMapTexelToLinear(texture2D(tSSGIMap,screenPos_gi.xy));float ambientOcclusion=1.-ssgi.a;ambientOcclusion=max(0.,ambientOcclusion);ambientOcclusion=pow(ambientOcclusion,ssaoPower);ambientOcclusion=min(1.,ambientOcclusion);reflectedLight.indirectDiffuse*=ambientOcclusion;\n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\nvec3 ssgiColor=ssgi.rgb*ssgiIntensity;reflectedLight.indirectDiffuse+=ssgiColor*(material.diffuseColor.rgb);\n#endif\n#if defined( USE_ENVMAP )\nfloat dotNV=saturate(dot(geometryNormal,geometryViewDir));float specularOcclusion=saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*material.roughness-1.0))-1.0+ambientOcclusion);reflectedLight.indirectSpecular*=specularOcclusion;\n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\n#if !defined(SSR_ENABLED) || SSR_ENABLED < 1\nreflectedLight.indirectSpecular+=ssgiColor*material.specularColor;\n#endif\n#endif\n#endif\n#if SSRTAO_ENABLED == 2\n}\n#endif\n#endif\n\n \n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\n // reflectedLight.directDiffuse = vec3(0.);\n // reflectedLight.indirectDiffuse = vec3(0.);\n // reflectedLight.directSpecular = vec3(0.);\n // reflectedLight.indirectSpecular = vec3(0.);\n#endif \n ",{prepend:!0}),e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"#include <aomap_fragment>","")},onObjectRender:(e,t,i)=>{let r=!this.enabled||!(this.renderWithCamera||i.renderManager.frameCount>1)||!1===i.userData.screenSpaceRendering||t.userData?.pluginsDisabled||t.userData?.ssrtaoDisabled||t.userData?.ssaoDisabled?0:this.split>0?2:1;t.defines.SSRTAO_ENABLED!==r&&(t.defines.SSRTAO_ENABLED=r,t.needsUpdate=!0)},parsFragmentSnippet:e=>t.glsl`
|
|
37
|
+
`,this._shaderPatch="diffuseColor = outline(diffuseColor);",this.dependencies=[t.PickingPlugin,t.GBufferPlugin],this._pickingWidgetDisabled=!1,this.material=new t.ShaderMaterial({uniforms:{cameraNearFar:{value:new t.Vector2(.1,100)}},vertexShader:"#ifdef USE_ALPHAMAP\n#define USE_UV\n#endif\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec3 vViewPosition;void main(){\n#include <skinbase_vertex>\n#include <begin_vertex>\n#include <morphtarget_vertex>\n#include <skinning_vertex>\n#include <displacementmap_vertex>\n#include <project_vertex>\n#include <logdepthbuf_vertex>\n#include <clipping_planes_vertex>\nvViewPosition=-mvPosition.xyz;}",fragmentShader:"uniform vec2 cameraNearFar;varying vec3 vViewPosition;vec2 pack16(float value){float sMax=65535.0;int v=int(clamp(value,0.0,1.0)*sMax+0.5);int digit0=v/256;int digit1=v-digit0*256;return vec2(float(digit0)/255.0,float(digit1)/255.0);}float linstep(float edge0,float edge1,float value){return clamp((value-edge0)/(edge1-edge0),0.0,1.0);}void main(){float linearZ=linstep(-cameraNearFar.x,-cameraNearFar.y,-vViewPosition.z);vec2 packedZ=pack16(pow(max(0.,linearZ),0.5));gl_FragColor=vec4(packedZ.x,packedZ.y,0.,0.);}",side:t.DoubleSide}),this._getSelectedObject=()=>{if(!this._viewer)return null;const e=this._viewer.getPlugin(t.PickingPlugin);if(this.highlightSelectedMaterials){const t=e?.getSelectedObject()?.material||null;if(this.highlightMaterialSameNames&&t){const e=Array.isArray(t)?t.map(e=>e.name):[t.name],i=new Set;for(const t of e){const e=this._viewer?.assetManager?.materials?.findMaterialsByName(t);e?.forEach(e=>i.add(e))}return[...i]}return t}const i=e?e.getSelectedObjects?e.getSelectedObjects():[e.getSelectedObject()||null]:null;return i&&i.length>0?1===i.length?i[0]:i:null},this._viewerListeners={preRender:()=>{!this.isDisabled()&&this._viewer&&(this.extraUniforms.dpr.value=2*this._viewer.renderManager.renderScale)}},this.mouseInOutAnimationEnabled=!0,this._state="in",this.enabled=e,this.bufferType=i}setDirty(){if(super.setDirty(),!this._viewer)return;const e=this._viewer.getPlugin(t.PickingPlugin);let i=!this.isDisabled();if(i){const t=e?.getSelectedObject();"string"==typeof t?.type&&t?.type?.includes("Line")&&(i=!1)}e&&(i&&e.widgetEnabled?(e.widgetEnabled=!1,this._pickingWidgetDisabled=!0):!i&&this._pickingWidgetDisabled&&(e.widgetEnabled=!0,this._pickingWidgetDisabled=!1)),this._viewer.setDirty()}onAdded(e){super.onAdded(e),this.setDirty(),this._pass=this._createPass(),this._pass.onDirty?.push(e.setDirty),e.renderManager.registerPass(this._pass);const i=e.getPlugin(t.PickingPlugin);i?.addEventListener("selectedObjectChanged",()=>{!this._animationCallBack&&this&&(i?.getSelectedObject()?this.enableDynamicSelection?(this.transparency=1,this._animationCallBack=this._startTransparencyAnimation(1,this.highlightTransparency,400)):this.transparency=this.highlightTransparency:this.transparency=1)}),document.addEventListener("mousemove",t=>{if(!this)return;if(!this.mouseInOutAnimationEnabled)return;if(!this.enableHighlight)return;const r=i?.getSelectedObject();r&&this.enableDynamicSelection?t.target!==e.canvas?this._animationCallBack||"in"!==this._state||(this._animationCallBack=this._startTransparencyAnimation(this.highlightTransparency,1,600),this._state="out"):this._animationCallBack||"out"!==this._state||(this._animationCallBack=this._startTransparencyAnimation(1,this.highlightTransparency,600),this._state="in"):this.transparency=r?this.highlightTransparency:1})}onRemove(e){return this._disposeTarget(),this._pass&&(e.renderManager.unregisterPass(this._pass),this._pass.dispose&&this._pass.dispose()),this._pass=void 0,super.onRemove(e)}_createTarget(e=!0){this._viewer&&(e&&this._disposeTarget(),this.target||(this.target=this._viewer.renderManager.createTarget({sizeMultiplier:1,type:this.bufferType})),this.texture=this.target.texture,this.texture.name="normalBuffer")}_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("OutlinePlugin: target not created");this.material.userData.isOutlinePluginMaterial=!0;return new e.OutlineRenderPass(this.passId,this._getSelectedObject,()=>this.target,this.material)}async _startTransparencyAnimation(e,i,r){return t.animateTarget(this,"transparency",{from:e,to:i,duration:r,onComplete:()=>{this._animationCallBack=void 0}})}get outlineIntensity(){return console.warn("OutlinePlugin.outlineIntensity is deprecated, use OutlinePlugin.intensity instead"),this.intensity}set outlineIntensity(e){console.warn("OutlinePlugin.outlineIntensity is deprecated, use OutlinePlugin.intensity instead"),this.intensity=e}get outlineColor(){return console.warn("OutlinePlugin.outlineColor is deprecated, use OutlinePlugin.intensity instead"),this.intensity}set outlineColor(e){console.warn("OutlinePlugin.outlineColor is deprecated, use OutlinePlugin.intensity instead"),this.intensity=e}},e.OutlinePlugin.PluginType="OutlinePlugin",e.OutlinePlugin.OldPluginType="Outline",k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiToggle("Enable"),t.serialize()],e.OutlinePlugin.prototype,"enabled",2),k([t.uiToggle("Highlight"),t.uniform({propKey:"enableHighlight"}),t.serialize()],e.OutlinePlugin.prototype,"enableHighlight",2),k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiToggle("DynamicSelection"),t.serialize()],e.OutlinePlugin.prototype,"enableDynamicSelection",2),k([t.uiSlider("Intensity",[0,4],.001),t.uniform({propKey:"outlineIntensity"}),t.serialize("outlineIntensity")],e.OutlinePlugin.prototype,"intensity",2),k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiSlider("Transparency",[0,1],.01),t.serialize()],e.OutlinePlugin.prototype,"highlightTransparency",2),k([t.uiColor("Color"),t.uniform({propKey:"outlineColor"}),t.serialize("outlineColor")],e.OutlinePlugin.prototype,"color",2),k([t.uiSlider("Thickness",[0,10],.01),t.uniform({propKey:"outlineThickness"}),t.serialize("outlineThickness")],e.OutlinePlugin.prototype,"thickness",2),k([t.uiToggle("Debug"),t.matDefineBool("DEBUG_OUTLINE",void 0,!0)],e.OutlinePlugin.prototype,"debugOutline",2),k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiToggle("Highlight Selected Materials")],e.OutlinePlugin.prototype,"highlightSelectedMaterials",2),k([t.onChange(e.OutlinePlugin.prototype.setDirty),t.uiToggle("Highlight Materials (same name)")],e.OutlinePlugin.prototype,"highlightMaterialSameNames",2),k([t.uniform({propKey:"highlightTransparency"})],e.OutlinePlugin.prototype,"transparency",2),k([t.uniform({propKey:"outlineBuffer"}),t.uiImage("Outline Buffer",{readOnly:!0})],e.OutlinePlugin.prototype,"texture",2),e.OutlinePlugin=k([t.uiFolderContainer("Selection Outline")],e.OutlinePlugin),e.OutlineRenderPass=class extends t.RenderPass{constructor(e,i,r,a){super(void 0,void 0,a,new t.Color(1,1,1),1),this.passId=e,this._getSelectedObjectOrMaterial=i,this.target=r,this.isOutlineRenderPass=!0,this.enabled=!0,this.before=["render"],this.after=["gbuffer"],this.required=["render","gbuffer"],this.onDirty=[]}render(e,i,r,a,n){if(!this.scene||!this.camera||!this.enabled)return;const s=e.getRenderTarget(),o=e.getActiveCubeFace(),l=e.getActiveMipmapLevel(),c=this._getSelectedObjectOrMaterial();if(c)this._renderSelectedObject(e,c,i||null,a,n);else{e.setRenderTarget(t.getOrCall(this.target)||null);const i=new t.Color;e.getClearColor(i),e.setClearColor(new t.Color(16777215)),e.clear(!0,!0),e.setClearColor(i)}e.setRenderTarget(s,o,l)}_renderSelectedObject(e,i,r,a,n){if(!this.camera||!i)return;const s=(Array.isArray(i)?i:[i]).flatMap(e=>e?.isTexture?[...e.appliedObjects?.values()||[]]:e).flatMap(e=>e?.isMaterial||e?.isBufferGeometry?[...e.appliedMeshes?.values()||[]]:e);for(const t of s)t&&t.traverse(e=>{e.layers.enable(6)});const o=this.camera.layers.mask;this.camera.layers.set(6);const l=e.userData;l||console.error("threejs is not patched?"),l.transmissionRenderTarget=r,e.renderWithModes({shadowMapRender:!1,backgroundRender:!1,opaqueRender:!0,transparentRender:!0,transmissionRender:!0,mainRenderPass:!1},()=>super.render(e,r,t.getOrCall(this.target),a,n)),l.transmissionRenderTarget=void 0,s.forEach(e=>e.traverse(e=>{e.layers.disable(6)})),this.camera.layers.mask=o}dispose(){this.onDirty=[],this.scene=void 0,this.camera=void 0,super.dispose?.()}setDirty(){this.onDirty.forEach(e=>e())}beforeRender(e,t,i){this.scene=e,this.camera=t,t.updateShaderProperties(this.overrideMaterial)}},k([t.uiToggle("Enabled")],e.OutlineRenderPass.prototype,"enabled",2),e.OutlineRenderPass=k([t.uiFolderContainer(e=>e.passId+" Render Pass")],e.OutlineRenderPass);var z=Object.defineProperty,I=(e,t,i,r)=>{for(var a,n=void 0,s=e.length-1;s>=0;s--)(a=e[s])&&(n=a(t,i,n)||n);return n&&z(t,i,n),n};class V extends t.ExtendedShaderPass{constructor(e,i="rgba"){super({vertexShader:t.CopyShader.vertexShader,fragmentShader:"\n// for gbuffer\n#include <packing>\n#define THREE_PACKING_INCLUDED\nuniform vec2 tDiffuseSize;uniform vec2 bilDirection;varying vec2 vUv;uniform bool smoothEnabled;uniform float edgeSharpness;vec4 bilaterialAO(){vec4 color=clamp((texture2D(tDiffuse,vUv.xy)).B_SRC_ACCESSOR,0.,5.);if(!smoothEnabled)return color;float depth;vec3 normal;getDepthNormal(vUv.xy,depth,normal);float gaussianWeights[4];gaussianWeights[0]=0.153170;gaussianWeights[1]=0.144893;gaussianWeights[2]=0.122649;gaussianWeights[3]=0.092902;float Z=gaussianWeights[0]+0.03;vec4 final_colour=Z*color;vec2 nuv;vec4 cc;float dp;vec3 nor;vec2 direction=bilDirection/tDiffuseSize.xy;\n#pragma unroll_loop_start\nfor(int i=0;i<6;i++){direction*=-1.;nuv=vUv+2.*direction*float(UNROLLED_LOOP_INDEX/2+1);getDepthNormal(nuv,dp,nor);if(dp<0.999){float normalCloseness=dot(normal,nor);normalCloseness*=normalCloseness;float normalError=(1.0-normalCloseness)*8.;float normalWeight=max((1.0-normalError*edgeSharpness),0.00);float depthWeight=max(0.0,1.0-edgeSharpness*4000.*abs(depth-dp));float kernelWeight=gaussianWeights[UNROLLED_LOOP_INDEX/2]+0.03;float bilateralWeight=kernelWeight*depthWeight*normalWeight;Z+=bilateralWeight;cc=clamp((texture2D(tDiffuse,nuv)).B_SRC_ACCESSOR,0.,5.);final_colour+=bilateralWeight*cc;}}\n#pragma unroll_loop_end\nfinal_colour/=Z;return final_colour;}void main(){vec4 ao=clamp(bilaterialAO(),vec4(0.),vec4(1.));gl_FragColor=ao;}",uniforms:{bilDirection:{value:new t.Vector2(1,0)},tDiffuse:{value:null},tDiffuseSize:{value:new t.Vector2}},defines:{B_SRC_ACCESSOR:i}},"tDiffuse"),this.target=e,this.smoothEnabled=!0,this.edgeSharpness=.1,this.clear=!1,this.needsSwap=!1}render(e,i,r,a,n){if(!this.enabled)return;const s=t.getOrCall(this.target);s&&(this.uniforms.bilDirection.value.set(1,0),this.uniforms.tDiffuse.value=s.texture,this.uniforms.tDiffuseSize.value.set(this.uniforms.tDiffuse.value?.image.width||0,this.uniforms.tDiffuse.value?.image.height||0),super.render(e,i,s,a,n),this.uniforms.bilDirection.value.set(0,1),this.uniforms.tDiffuse.value=i.texture,this.uniforms.tDiffuseSize.value.set(this.uniforms.tDiffuse.value?.image.width||0,this.uniforms.tDiffuse.value?.image.height||0),super.render(e,s,i,a,n))}}I([t.serialize(),t.uniform()],V.prototype,"smoothEnabled"),I([t.serialize(),t.uniform()],V.prototype,"edgeSharpness");var G=Object.defineProperty,j=Object.getOwnPropertyDescriptor,H=(e,t,i,r)=>{for(var a,n=r>1?void 0:r?j(t,i):t,s=e.length-1;s>=0;s--)(a=e[s])&&(n=(r?a(t,i,n):a(n))||n);return r&&n&&G(t,i,n),n};e.SSGIPlugin=class extends t.PipelinePassPlugin{constructor(e=t.UnsignedByteType,i=1,r=!0){super(),this.passId="ssrtgi",this.dependencies=[t.GBufferPlugin,t.SSAAPlugin],this._gbufferUnpackExtension=void 0,this._gbufferUnpackExtensionChanged=()=>{if(!this._pass||!this._viewer)throw new Error("SSGIPlugin: 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("SSGIPlugin: GBuffer unpack extension removed"))},this.enabled=r,this.bufferType=e,this.sizeMultiplier=i}_createTarget(e=!0){this._viewer&&(e&&this._disposeTarget(),this.target||(this.target=this._viewer.renderManager.createTarget({depthBuffer:!1,type:this.bufferType,sizeMultiplier:this.sizeMultiplier})),this.texture=this.target.texture,this.texture.name="ssgiBuffer")}_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("SSGIPlugin: viewer not set");if(!this._viewer.renderManager.gbufferTarget||!this._viewer.renderManager.gbufferUnpackExtension)throw new Error("SSGIPlugin: GBuffer target not created. GBufferPlugin is required.");return this._createTarget(!0),new e.SSGIPluginPass(this.passId,()=>this.target)}onAdded(t){super.onAdded(t),(t.getPlugin("Ground")||t.getPlugin("BaseGroundPlugin"))&&console.warn("GroundPlugin must be added after SSGIPlugin"),this._gbufferUnpackExtensionChanged(),t.renderManager.addEventListener("gbufferUnpackExtensionChanged",this._gbufferUnpackExtensionChanged),t.forPlugin(e.VelocityBufferPlugin,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)}fromJSON(e,t){return e.passes?.ssrtgi&&((e={...e}).pass=e.passes.ssrtgi,delete e.passes,void 0!==e.pass.enabled&&(e.enabled=e.pass.enabled)),super.fromJSON(e,t)}_beforeRender(i,r,a){if(!this._viewer)return!1;const n=super._beforeRender(i,r,a);if(n){const t=this._viewer?.getPlugin("SSAOPlugin");t&&!t.isDisabled()&&t.disable(e.SSGIPlugin.PluginType)}if(!n)return n;const s=this._viewer.getPlugin(t.ProgressivePlugin);return this._pass?.updateShaderProperties([s]),n}get rtgiTarget(){return console.warn("SSGIPlugin: rtgiTarget is deprecated, use target instead"),this.target}},e.SSGIPlugin.PluginType="SSGIPlugin",e.SSGIPlugin.OldPluginType="SSGI",H([t.uiImage("SSGI Buffer",{readOnly:!0})],e.SSGIPlugin.prototype,"texture",2),H([t.uiConfig(void 0,{unwrapContents:!0})],e.SSGIPlugin.prototype,"_pass",2),e.SSGIPlugin=H([t.uiFolderContainer("SSGI Plugin")],e.SSGIPlugin),e.SSGIPluginPass=class extends t.ExtendedShaderPass{constructor(i,r,a=!0){super({defines:{RTAO_STEP_COUNT:16,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},opacity:{value:1},intensity:{value:0},objectRadius:{value:0},autoRadius:{value:!a},rayCount:{value:.1},bias:{value:.015},falloff:{value:.7},power:{value:1.1},tolerance:{value:0},sceneBoundingRadius:{value:0},currentProjectionViewMatrix:{value:new t.Matrix4},lastProjectionViewMatrix:{value:new t.Matrix4},inverseViewMatrix:{value:new t.Matrix4},ssrtaoSplitX:{value:.5}},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${A}\n\n${C}\n\n${n().calculateGI}\n `},"tDiffuse","tLastThis","tLastFrame"),this.target=r,this.before=["render"],this.after=["gbuffer","depth"],this.required=["render","progressive"],this.giEnabled=!0,this.intensity=2,this.power=1.1,this.autoRadius=!0,this.objectRadius=1,this.tolerance=1,this.bias=.001,this.falloff=.7,this.rayCount=4,this.stepCount=8,this.smoothEnabled=!0,this.renderWithCamera=!0,this.split=0,this.materialExtension={extraUniforms:{tSSGIMap:()=>({value:t.getOrCall(this.target)?.texture??null}),ssaoPower:this.material.uniforms.power,ssgiIntensity:this.material.uniforms.intensity,ssrtaoSplitX:this.material.uniforms.ssrtaoSplitX},extraDefines:{SSGI_ENABLED:()=>this.material.defines.SSGI_ENABLED},shaderExtender:(e,i,r)=>{if(!e.defines?.SSRTAO_ENABLED)return;e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"vec3 totalDiffuse =","\n \n \n#if defined(SSRTAO_ENABLED) && SSRTAO_ENABLED > 0\nvec3 screenPos_gi=viewToScreen(vViewPosition.xyz);\n#if SSRTAO_ENABLED == 2\nif(screenPos_gi.x>ssrtaoSplitX){\n#endif\nvec4 ssgi=tSSGIMapTexelToLinear(texture2D(tSSGIMap,screenPos_gi.xy));float ambientOcclusion=1.-ssgi.a;ambientOcclusion=max(0.,ambientOcclusion);ambientOcclusion=pow(ambientOcclusion,ssaoPower);ambientOcclusion=min(1.,ambientOcclusion);reflectedLight.indirectDiffuse*=ambientOcclusion;\n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\nvec3 ssgiColor=ssgi.rgb*ssgiIntensity;reflectedLight.indirectDiffuse+=ssgiColor*(material.diffuseColor.rgb);\n#endif\n#if defined( USE_ENVMAP )\nfloat dotNV=saturate(dot(geometryNormal,geometryViewDir));float specularOcclusion=saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*material.roughness-1.0))-1.0+ambientOcclusion);reflectedLight.indirectSpecular*=specularOcclusion;\n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\n#if !defined(SSR_ENABLED) || SSR_ENABLED < 1\nreflectedLight.indirectSpecular+=ssgiColor*material.specularColor;\n#endif\n#endif\n#endif\n#if SSRTAO_ENABLED == 2\n}\n#endif\n#endif\n\n \n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\n // reflectedLight.directDiffuse = vec3(0.);\n // reflectedLight.indirectDiffuse = vec3(0.);\n // reflectedLight.directSpecular = vec3(0.);\n // reflectedLight.indirectSpecular = vec3(0.);\n#endif \n ",{prepend:!0}),e.fragmentShader=t.shaderReplaceString(e.fragmentShader,"#include <aomap_fragment>","")},onObjectRender:(e,t,i)=>{let r=!this.enabled||!(this.renderWithCamera||i.renderManager.frameCount>1)||!1===i.userData.screenSpaceRendering||t.userData?.pluginsDisabled||t.userData?.ssrtaoDisabled||t.userData?.ssaoDisabled?0:this.split>0?2:1;t.defines.SSRTAO_ENABLED!==r&&(t.defines.SSRTAO_ENABLED=r,t.needsUpdate=!0)},parsFragmentSnippet:e=>t.glsl`
|
|
38
38
|
#if defined(SSRTAO_ENABLED) && SSRTAO_ENABLED > 0
|
|
39
39
|
uniform float ssaoPower;
|
|
40
40
|
uniform float ssgiIntensity;
|