@threepipe/webgi-plugins 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/LICENSE +29 -0
  2. package/NOTICE +1 -0
  3. package/README.md +15 -0
  4. package/dist/dependencies.txt +32 -1
  5. package/dist/index.js +55 -11
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +1627 -260
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/plugins/buffer/VelocityBufferPlugin.d.ts.map +1 -1
  10. package/dist/plugins/extras/AdvancedGroundPlugin.d.ts +44 -0
  11. package/dist/plugins/extras/AdvancedGroundPlugin.d.ts.map +1 -0
  12. package/dist/plugins/extras/AnisotropyPlugin.d.ts +2 -1
  13. package/dist/plugins/extras/AnisotropyPlugin.d.ts.map +1 -1
  14. package/dist/plugins/index.d.ts +3 -1
  15. package/dist/plugins/index.d.ts.map +1 -1
  16. package/dist/plugins/postprocessing/OutlinePlugin.d.ts +3 -1
  17. package/dist/plugins/postprocessing/OutlinePlugin.d.ts.map +1 -1
  18. package/dist/plugins/postprocessing/SSGIPlugin.d.ts.map +1 -1
  19. package/dist/plugins/postprocessing/SSReflectionPlugin.d.ts.map +1 -1
  20. package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts.map +1 -1
  21. package/dist/utils/FSShadowMaterial.d.ts +15 -0
  22. package/dist/utils/FSShadowMaterial.d.ts.map +1 -0
  23. package/dist/utils/RandomizedDirectionalLight.d.ts +40 -0
  24. package/dist/utils/RandomizedDirectionalLight.d.ts.map +1 -0
  25. package/dist/utils/Reflector2.d.ts +50 -0
  26. package/dist/utils/Reflector2.d.ts.map +1 -0
  27. package/dist/utils/ShadowMapBaker.d.ts +40 -0
  28. package/dist/utils/ShadowMapBaker.d.ts.map +1 -0
  29. package/dist/version.d.ts +1 -1
  30. package/package.json +7 -5
  31. package/dist/plugins/extras/PhysicalGroundPlugin.d.ts +0 -1
  32. package/dist/plugins/extras/PhysicalGroundPlugin.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,23 +1,23 @@
1
1
  /**
2
2
  * @license
3
- * @threepipe/webgi-plugins v0.4.1
4
- * Copyright 2022-2025 repalash <palash@shaders.app>
5
- * GPL-3.0-only License
3
+ * @threepipe/webgi-plugins v0.5.1
4
+ * Copyright 2022-2025 repalash <palash@shaders.app> (https://repalash.com)
5
+ * SEE LICENSE IN LICENSE
6
6
  */
7
- var _a;
8
- import { PipelinePassPlugin, GBufferPlugin, ProgressivePlugin, generateUiConfig, uiToggle, uiConfig, ExtendedShaderPass, Vector2, Matrix4, CopyShader, getOrCall, serialize, uniform, uiVector, matDefineBool, UnsignedByteType, shaderReplaceString, LinearSRGBColorSpace, GBufferRenderPass, Color, ShaderMaterial, NoBlending, Matrix3, DoubleSide, uiImage, uiFolderContainer, uiConfigMaterialExtension, updateBit, Vector4, HalfFloatType, AdditiveBlending, uiSlider, onChange, onChange2, Vector3, PickingPlugin, now, FrameFadePlugin, shaderUtils, ExtendedShaderMaterial, RGBAFormat, NearestFilter, bindToValue, AViewerPluginSync, updateMaterialDefines, glsl, ShaderChunk, BaseGroundPlugin, matDefine, SSAAPlugin, getTexelDecoding, AScreenPassExtensionPlugin, animateTarget, RenderPass, uiColor, makeSamplerUi, SRGBColorSpace } from "threepipe";
7
+ var _a, _b;
8
+ import { PipelinePassPlugin, GBufferPlugin, ProgressivePlugin, generateUiConfig, uiToggle, uiConfig, ExtendedShaderPass, Vector2, Matrix4, CopyShader, getOrCall, serialize, uniform, uiVector, matDefineBool, UnsignedByteType, shaderReplaceString, LinearSRGBColorSpace, GBufferRenderPass, Color, ShaderMaterial, NoBlending, Matrix3, DoubleSide, uiImage, uiFolderContainer, uiConfigMaterialExtension, updateBit, Vector4, HalfFloatType, AdditiveBlending, uiSlider, onChange, onChange2, Vector3, PickingPlugin, now, FrameFadePlugin, shaderUtils, ExtendedShaderMaterial, RGBAFormat, NearestFilter, bindToValue, AViewerPluginSync, updateMaterialDefines, glsl, ShaderChunk, BaseGroundPlugin, matDefine, SSAAPlugin, getTexelDecoding, AScreenPassExtensionPlugin, animateTarget, RenderPass, uiColor, makeSamplerUi, SRGBColorSpace, Mesh2, Plane, PerspectiveCamera, MathUtils, DirectionalLight2, copyObject3DUserData, Serialization, ThreeSerialization, ShadowMaterial, SimpleEventDispatcher, BasicShadowMap, ShaderMaterial2, NoColorSpace, Layers, LinearFilter, LinearMipmapLinearFilter, PCFShadowMap, PCFSoftShadowMap, VSMShadowMap } from "threepipe";
9
9
  const VelocityBufferUnpack = "#if defined(HAS_VELOCITY_BUFFER)\nuniform sampler2D tVelocity;vec2 getVelocity(const in vec2 uv){vec2 screenSpaceVelocity=texture2D(tVelocity,uv).xy*2.0-1.0;return sign(screenSpaceVelocity)*pow(abs(screenSpaceVelocity),vec2(4.));}\n#endif\n";
10
10
  const ssVelocityVert = "#ifdef USE_ALPHAMAP\n#define USE_UV\n#endif\n#include <uv_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 modelMatrixPrevious;void main(){\n#include <uv_vertex>\n#include <skinbase_vertex>\n#include <begin_vertex>\n#include <morphtarget_vertex>\n#include <skinning_vertex>\n#include <displacementmap_vertex>\nvec4 mvPosition=vec4(transformed,1.0);\n#ifdef USE_INSTANCING\nmvPosition=instanceMatrix*mvPosition;\n#endif\nvWorldPosition=(modelMatrix*mvPosition).xyz;vWorldPositionPrevious=(modelMatrixPrevious*mvPosition).xyz;mvPosition=modelViewMatrix*mvPosition;gl_Position=projectionMatrix*mvPosition;\n#include <logdepthbuf_vertex>\n#include <clipping_planes_vertex>\n}";
11
11
  const ssVelocityFrag = "varying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 currentProjectionViewMatrix;uniform mat4 lastProjectionViewMatrix;vec2 computeScreenSpaceVelocity2(){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(vWorldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(vWorldPositionPrevious,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}void main(){vec2 velocity=clamp(computeScreenSpaceVelocity2(),-1.0,1.0);velocity=sign(velocity)*pow(abs(velocity),vec2(1./4.));velocity=velocity*0.5+0.5;gl_FragColor=vec4(velocity.x,velocity.y,1.,1.);}";
12
- const taaShader = "#include <common>\n#include <gbuffer_unpack>\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#endif\n#include <cameraHelpers>\nvarying vec2 vUv;uniform vec2 previousRTSize;uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;uniform mat4 inverseViewMatrix;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;\n#ifndef HAS_VELOCITY_BUFFER\n#define HAS_VELOCITY_BUFFER 0\n#endif\nvec3 find_closest_fragment_3x3(const in vec2 uv){const vec3 offset=vec3(-1.0,1.0,0.0);vec2 texelSize=1.0/previousRTSize;vec3 dtr=vec3(1,1,getDepth(uv+offset.yy*texelSize));vec3 dtc=vec3(0,1,getDepth(uv+offset.zy*texelSize));vec3 dtl=vec3(-1,1,getDepth(uv+offset.xy*texelSize));vec3 dml=vec3(-1,0,getDepth(uv+offset.xz*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dmr=vec3(1,0,getDepth(uv+offset.yz*texelSize));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.xx*texelSize));vec3 dbc=vec3(0,-1,getDepth(uv+offset.zx*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.yx*texelSize));vec3 dmin=dtl;if(dmin.z>dtc.z)dmin=dtc;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dml.z)dmin=dml;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dmr.z)dmin=dmr;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbc.z)dmin=dbc;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+texelSize.xy*dmin.xy,dmin.z);}vec3 find_closest_fragment_5tap(const in vec2 uv){vec2 texelSize=1.0/previousRTSize;vec2 offset=vec2(1.0,-1.0);vec3 dtl=vec3(-1,1,getDepth(uv+offset.yx*texelSize));vec3 dtr=vec3(1,1,getDepth(uv+offset.xx*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.yy*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.xy*texelSize));vec3 dmin=dtl;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+dmin.xy*texelSize,dmin.z);}vec4 clip_aabb(const in vec4 aabb_min,const in vec4 aabb_max,vec4 p){const float FLT_EPS=1e-8;vec4 p_clip=0.5*(aabb_max+aabb_min);vec4 e_clip=0.5*(aabb_max-aabb_min)+FLT_EPS;vec4 v_clip=p-p_clip;vec4 v_unit=abs(v_clip/e_clip);float ma_unit=max(v_unit.x,max(v_unit.y,v_unit.z));if(ma_unit>1.0)return p_clip+v_clip/ma_unit;else return p;}\n#if HAS_VELOCITY_BUFFER == 0\nvec2 computeScreenSpaceVelocity(const in vec3 worldPosition){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(worldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(worldPosition,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}\n#endif\nvec4 currentRTTexelToLinear1(vec4 a){if(isinf(a.x)||isinf(a.y)||isinf(a.z)||isinf(a.w)){return vec4(1.);}return currentRTTexelToLinear(a);}vec4 computeTAA(const in vec2 uv,const in vec2 screenSpaceVelocity,const in float feedbackScale){vec2 uvUnJitter=uv;vec4 currentColor=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter));vec4 previousColor=previousRTTexelToLinear(texture2D(previousRT,uv-screenSpaceVelocity));const vec3 offset=vec3(1.,-1.,0.);vec2 texelSize=1./previousRTSize;float texelSpeed=length(screenSpaceVelocity);vec4 tl=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yx*texelSize));vec4 tc=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.zx*texelSize));vec4 tr=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xx*texelSize));vec4 ml=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yz*texelSize));vec4 mc=currentColor;vec4 mr=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xz*texelSize));vec4 bl=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yy*texelSize));vec4 bc=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.zy*texelSize));vec4 br=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xy*texelSize));vec4 corners=2.0*(tr+bl+br+tl)-2.0*mc;mc+=(mc-(corners*0.166667))*2.718282*0.3;mc=max(vec4(0.0),mc);vec4 min5=min(tc,min(ml,min(mc,min(mr,bc))));vec4 max5=max(tc,max(ml,max(mc,max(mr,bc))));vec4 cmin=min(min5,min(tl,min(tr,min(bl,br))));vec4 cmax=max(min5,max(tl,max(tr,max(bl,br))));;cmin=0.5*(cmin+min5);cmax=0.5*(cmax+max5);previousColor=clip_aabb(cmin,cmax,previousColor);float lum0=luminance(currentColor.rgb);float lum1=luminance(previousColor.rgb);float unbiased_diff=abs(lum0-lum1)/max(lum0,max(lum1,0.2));float unbiased_weight=1.0-unbiased_diff;float unbiased_weight_sqr=unbiased_weight*unbiased_weight;float k_feedback=mix(feedBack.x,feedBack.y,unbiased_weight_sqr);return mix(currentColor,previousColor,clamp(k_feedback*feedbackScale,0.,1.));}vec3 getWorldPositionFromViewZ(const in vec2 uv,const in float viewDepth){vec2 uv_=2.*uv-1.;float xe=-(uv_.x+projection[2][0])*viewDepth/projection[0][0];float ye=-(uv_.y+projection[2][1])*viewDepth/projection[1][1];return(inverseViewMatrix*vec4(xe,ye,viewDepth,1.)).xyz;}void main(){\n#if HAS_VELOCITY_BUFFER == 0\n#if QUALITY == 1\nvec3 c_frag=find_closest_fragment_3x3(vUv);\n#else\nvec3 c_frag=find_closest_fragment_5tap(vUv);\n#endif\n#else\nvec3 c_frag=vec3(vUv,0.);\n#endif\nbool bg=firstFrame;\n#if BACKGROUND_TAA\nfloat d=c_frag.z;float edgef=min(1.,max(0.,1.-(d*100.-99.)));\n#else\nbg=bg||c_frag.z>0.999;\n#endif\nif(firstFrame){gl_FragColor=currentRTTexelToLinear1(texture2D(currentRT,vUv));}else{\n#if HAS_VELOCITY_BUFFER == 0\nfloat sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);\n#else\nvec2 screenSpaceVelocity=getVelocity(c_frag.xy);\n#endif\n#if BACKGROUND_TAA\ngl_FragColor=computeTAA(vUv,screenSpaceVelocity*edgef,edgef);\n#else\ngl_FragColor=computeTAA(vUv,screenSpaceVelocity,1.);\n#endif\n}\n#include <colorspace_fragment>\n#ifdef DEBUG_VELOCITY\nfloat sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);gl_FragColor=vec4(10.*length(screenSpaceVelocity),0.,0.,1.);\n#endif\n}";
13
- var __defProp$9 = Object.defineProperty;
12
+ const taaShader = "#include <common>\n#include <gbuffer_unpack>\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#endif\n#include <cameraHelpers>\nvarying vec2 vUv;uniform vec2 previousRTSize;uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;uniform mat4 inverseViewMatrix;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;\n#ifndef HAS_VELOCITY_BUFFER\n#define HAS_VELOCITY_BUFFER 0\n#endif\nvec3 find_closest_fragment_3x3(const in vec2 uv){const vec3 offset=vec3(-1.0,1.0,0.0);vec2 texelSize=1.0/previousRTSize;vec3 dtr=vec3(1,1,getDepth(uv+offset.yy*texelSize));vec3 dtc=vec3(0,1,getDepth(uv+offset.zy*texelSize));vec3 dtl=vec3(-1,1,getDepth(uv+offset.xy*texelSize));vec3 dml=vec3(-1,0,getDepth(uv+offset.xz*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dmr=vec3(1,0,getDepth(uv+offset.yz*texelSize));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.xx*texelSize));vec3 dbc=vec3(0,-1,getDepth(uv+offset.zx*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.yx*texelSize));vec3 dmin=dtl;if(dmin.z>dtc.z)dmin=dtc;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dml.z)dmin=dml;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dmr.z)dmin=dmr;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbc.z)dmin=dbc;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+texelSize.xy*dmin.xy,dmin.z);}vec3 find_closest_fragment_5tap(const in vec2 uv){vec2 texelSize=1.0/previousRTSize;vec2 offset=vec2(1.0,-1.0);vec3 dtl=vec3(-1,1,getDepth(uv+offset.yx*texelSize));vec3 dtr=vec3(1,1,getDepth(uv+offset.xx*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.yy*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.xy*texelSize));vec3 dmin=dtl;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+dmin.xy*texelSize,dmin.z);}vec4 clip_aabb(const in vec4 aabb_min,const in vec4 aabb_max,vec4 p){const float FLT_EPS=1e-8;vec4 p_clip=0.5*(aabb_max+aabb_min);vec4 e_clip=0.5*(aabb_max-aabb_min)+FLT_EPS;vec4 v_clip=p-p_clip;vec4 v_unit=abs(v_clip/e_clip);float ma_unit=max(v_unit.x,max(v_unit.y,v_unit.z));if(ma_unit>1.0)return p_clip+v_clip/ma_unit;else return p;}\n#if HAS_VELOCITY_BUFFER == 0\nvec2 computeScreenSpaceVelocity(const in vec3 worldPosition){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(worldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(worldPosition,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}\n#endif\nvec4 currentRTTexelToLinear1(vec4 a){if(isinf(a.x)||isinf(a.y)||isinf(a.z)||isinf(a.w)){return vec4(1.);}return currentRTTexelToLinear(a);}vec4 computeTAA(const in vec2 uv,const in vec2 screenSpaceVelocity,const in float feedbackScale){vec2 uvUnJitter=uv;vec4 currentColor=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter));vec4 previousColor=previousRTTexelToLinear(texture2D(previousRT,uv-screenSpaceVelocity));const vec3 offset=vec3(1.,-1.,0.);vec2 texelSize=1./previousRTSize;float texelSpeed=length(screenSpaceVelocity);vec4 tl=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yx*texelSize));vec4 tc=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.zx*texelSize));vec4 tr=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xx*texelSize));vec4 ml=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yz*texelSize));vec4 mc=currentColor;vec4 mr=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xz*texelSize));vec4 bl=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yy*texelSize));vec4 bc=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.zy*texelSize));vec4 br=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xy*texelSize));vec4 corners=2.0*(tr+bl+br+tl)-2.0*mc;mc+=(mc-(corners*0.166667))*2.718282*0.3;mc=max(vec4(0.0),mc);vec4 min5=min(tc,min(ml,min(mc,min(mr,bc))));vec4 max5=max(tc,max(ml,max(mc,max(mr,bc))));vec4 cmin=min(min5,min(tl,min(tr,min(bl,br))));vec4 cmax=max(min5,max(tl,max(tr,max(bl,br))));;cmin=0.5*(cmin+min5);cmax=0.5*(cmax+max5);previousColor=clip_aabb(cmin,cmax,previousColor);float lum0=luminance(currentColor.rgb);float lum1=luminance(previousColor.rgb);float unbiased_diff=abs(lum0-lum1)/max(lum0,max(lum1,0.2));float unbiased_weight=1.0-unbiased_diff;float unbiased_weight_sqr=unbiased_weight*unbiased_weight;float k_feedback=mix(feedBack.x,feedBack.y,unbiased_weight_sqr);return mix(currentColor,previousColor,clamp(k_feedback*feedbackScale,0.,1.));}vec3 getWorldPositionFromViewZ(const in vec2 uv,const in float viewDepth){vec2 uv_=2.*uv-1.;float xe=-(uv_.x+projection[2][0])*viewDepth/projection[0][0];float ye=-(uv_.y+projection[2][1])*viewDepth/projection[1][1];return(inverseViewMatrix*vec4(xe,ye,viewDepth,1.)).xyz;}void main(){\n#if HAS_VELOCITY_BUFFER == 0\n#if QUALITY == 1\nvec3 c_frag=find_closest_fragment_3x3(vUv);\n#else\nvec3 c_frag=find_closest_fragment_5tap(vUv);\n#endif\n#else\nvec3 c_frag=vec3(vUv,0.);\n#endif\nbool bg=firstFrame;\n#if BACKGROUND_TAA\nfloat d=c_frag.z;float edgef=min(1.,max(0.,1.-(d*100.-99.)));\n#else\nbg=bg||c_frag.z>0.999;\n#endif\nif(bg){gl_FragColor=currentRTTexelToLinear1(texture2D(currentRT,vUv));}else{\n#if HAS_VELOCITY_BUFFER == 0\nfloat sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);\n#else\nvec2 screenSpaceVelocity=getVelocity(c_frag.xy);\n#endif\n#if BACKGROUND_TAA\ngl_FragColor=computeTAA(vUv,screenSpaceVelocity*edgef,edgef);\n#else\ngl_FragColor=computeTAA(vUv,screenSpaceVelocity,1.);\n#endif\n}\n#include <colorspace_fragment>\n#ifdef DEBUG_VELOCITY\nfloat sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);gl_FragColor=vec4(10.*length(screenSpaceVelocity),0.,0.,1.);\n#endif\n}";
13
+ var __defProp$e = Object.defineProperty;
14
14
  var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
15
- var __decorateClass$9 = (decorators, target, key, kind) => {
15
+ var __decorateClass$e = (decorators, target, key, kind) => {
16
16
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
17
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
18
- if (decorator = decorators[i])
17
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
18
+ if (decorator = decorators[i2])
19
19
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
20
- if (kind && result) __defProp$9(target, key, result);
20
+ if (kind && result) __defProp$e(target, key, result);
21
21
  return result;
22
22
  };
23
23
  const passId$4 = "taa";
@@ -62,11 +62,11 @@ const _TemporalAAPlugin = class _TemporalAAPlugin extends PipelinePassPlugin {
62
62
  if (!this._viewer.renderManager.gbufferTarget || !this._viewer.renderManager.gbufferUnpackExtension)
63
63
  throw new Error("TemporalAAPlugin: GBuffer target not created. GBufferPlugin is required.");
64
64
  const applyOnBackground = !!this._viewer.renderManager.msaa;
65
- const t = new TemporalAAPluginPass(this.passId, () => {
66
- var _a2, _b;
67
- return (_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(ProgressivePlugin)) == null ? void 0 : _b.target;
65
+ const t2 = new TemporalAAPluginPass(this.passId, () => {
66
+ var _a2, _b2;
67
+ return (_b2 = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(ProgressivePlugin)) == null ? void 0 : _b2.target;
68
68
  }, applyOnBackground);
69
- return t;
69
+ return t2;
70
70
  }
71
71
  // todo use gbufferUnpackExtension from render manager to support depth buffer plugin as well.
72
72
  onAdded(viewer) {
@@ -144,14 +144,14 @@ const _TemporalAAPlugin = class _TemporalAAPlugin extends PipelinePassPlugin {
144
144
  _TemporalAAPlugin.PluginType = "TAA";
145
145
  _TemporalAAPlugin.OldPluginType = "TemporalAAPlugin";
146
146
  let TemporalAAPlugin = _TemporalAAPlugin;
147
- __decorateClass$9([
147
+ __decorateClass$e([
148
148
  uiToggle("Stable Noise (Total frame count)")
149
149
  ], TemporalAAPlugin.prototype, "stableNoise", 1);
150
- __decorateClass$9([
150
+ __decorateClass$e([
151
151
  uiConfig()
152
152
  ], TemporalAAPlugin.prototype, "_pass", 2);
153
153
  class TemporalAAPluginPass extends ExtendedShaderPass {
154
- constructor(pid, target, applyOnBackground = true) {
154
+ constructor(pid, target, applyOnBackground = false) {
155
155
  var _a2;
156
156
  super({
157
157
  vertexShader: CopyShader.vertexShader,
@@ -226,23 +226,23 @@ class TemporalAAPluginPass extends ExtendedShaderPass {
226
226
  this.onSizeUpdate();
227
227
  }
228
228
  }
229
- __decorateClass$9([
229
+ __decorateClass$e([
230
230
  serialize(),
231
231
  uniform(),
232
232
  uiVector("Feedback", void 0, 1e-4)
233
233
  ], TemporalAAPluginPass.prototype, "feedBack", 2);
234
- __decorateClass$9([
234
+ __decorateClass$e([
235
235
  uiToggle(),
236
236
  matDefineBool("DEBUG_VELOCITY", void 0, false, void 0, true)
237
237
  ], TemporalAAPluginPass.prototype, "debugVelocity", 2);
238
- var __defProp$8 = Object.defineProperty;
238
+ var __defProp$d = Object.defineProperty;
239
239
  var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
240
- var __decorateClass$8 = (decorators, target, key, kind) => {
240
+ var __decorateClass$d = (decorators, target, key, kind) => {
241
241
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
242
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
243
- if (decorator = decorators[i])
242
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
243
+ if (decorator = decorators[i2])
244
244
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
245
- if (kind && result) __defProp$8(target, key, result);
245
+ if (kind && result) __defProp$d(target, key, result);
246
246
  return result;
247
247
  };
248
248
  let VelocityBufferPlugin = class extends PipelinePassPlugin {
@@ -350,15 +350,15 @@ let VelocityBufferPlugin = class extends PipelinePassPlugin {
350
350
  }
351
351
  }
352
352
  onRemove(viewer) {
353
- var _a2, _b;
353
+ var _a2, _b2;
354
354
  this._disposeTarget();
355
- if (this._attachToTaa) (_b = (_a2 = viewer.getPlugin(TemporalAAPlugin)) == null ? void 0 : _a2.pass) == null ? void 0 : _b.material.unregisterMaterialExtensions([this.unpackExtension]);
355
+ if (this._attachToTaa) (_b2 = (_a2 = viewer.getPlugin(TemporalAAPlugin)) == null ? void 0 : _a2.pass) == null ? void 0 : _b2.material.unregisterMaterialExtensions([this.unpackExtension]);
356
356
  return super.onRemove(viewer);
357
357
  }
358
358
  setDirty() {
359
- var _a2, _b;
359
+ var _a2, _b2;
360
360
  super.setDirty();
361
- (_b = (_a2 = this.unpackExtension).setDirty) == null ? void 0 : _b.call(_a2);
361
+ (_b2 = (_a2 = this.unpackExtension).setDirty) == null ? void 0 : _b2.call(_a2);
362
362
  }
363
363
  _beforeRender(scene, camera, renderManager) {
364
364
  if (!super._beforeRender(scene, camera, renderManager)) return false;
@@ -373,13 +373,10 @@ let VelocityBufferPlugin = class extends PipelinePassPlugin {
373
373
  };
374
374
  VelocityBufferPlugin.PluginType = "VelocityBuffer";
375
375
  VelocityBufferPlugin.OldPluginType = "VelocityBufferPlugin";
376
- __decorateClass$8([
377
- uiImage(
378
- "Velocity Buffer"
379
- /* {readOnly: true}*/
380
- )
376
+ __decorateClass$d([
377
+ uiImage("Velocity Buffer", { readOnly: true })
381
378
  ], VelocityBufferPlugin.prototype, "texture", 2);
382
- VelocityBufferPlugin = __decorateClass$8([
379
+ VelocityBufferPlugin = __decorateClass$d([
383
380
  uiFolderContainer("Velocity Buffer Plugin (for TAA)")
384
381
  ], VelocityBufferPlugin);
385
382
  class SSVelocityMaterial extends ShaderMaterial {
@@ -434,14 +431,14 @@ class SSVelocityMaterial extends ShaderMaterial {
434
431
  }
435
432
  }
436
433
  const hdrBloom = "#include <packing>\nuniform float intensity;uniform float opacity;uniform vec2 tDiffuseSize;varying vec2 vUv;uniform float weight;\n#if PASS_STEP == 0\nuniform vec4 prefilter;vec4 Prefilter(vec4 c){\n#ifdef HAS_GBUFFER\n#if !BACKGROUND_BLOOM\nif(getDepth(vUv)>0.999){return vec4(0.0);}\n#endif\n#endif\nfloat brightness=max(c.r,max(c.g,c.b));float soft=brightness+prefilter.x*(prefilter.y-1.);soft=clamp(soft,0.,prefilter.z);soft=soft*soft*prefilter.w;float contribution=max(soft,brightness-prefilter.x);contribution/=max(brightness,0.001);return vec4(c.rgb*contribution,c.a);}\n#endif\nvec4 Sample(vec2 uv){return min(vec4(MAX_INTENSITY,MAX_INTENSITY,MAX_INTENSITY,1.),tDiffuseTexelToLinear(texture2D(tDiffuse,uv)));}vec4 SampleBox(vec2 uv,float delta){vec4 o=vec2(-delta,delta).xxyy/tDiffuseSize.xyxy;vec4 s=Sample(uv+o.xy)+Sample(uv+o.zy)+Sample(uv+o.xw)+Sample(uv+o.zw);return s*0.25;}int getBloomBit(in int number){\n#ifdef WebGL2Context\nreturn(number/4)% 2;\n#else\nreturn int(mod(floor(float(number)/4.),2.));\n#endif\n}void main(){\n#if PASS_STEP == 0\n#ifdef GBUFFER_HAS_FLAGS\nint doBloom=getBloomBit(getGBufferFlags(vUv).a);\n#else\nint doBloom=1;\n#endif\ngl_FragColor=float(doBloom)*weight*Prefilter(SampleBox(vUv,1.));gl_FragColor.a=1.;\n#elif PASS_STEP == 1\ngl_FragColor=weight*(SampleBox(vUv,1.));gl_FragColor.a=1.;\n#elif PASS_STEP == 2\ngl_FragColor=(SampleBox(vUv,0.5));gl_FragColor.a=1.;\n#elif PASS_STEP == 3\nvec4 texel=tSourceTexelToLinear(texture2D(tSource,vUv));vec4 bloom=intensity*SampleBox(vUv,0.5).rgba;float brightness=max(bloom.r,max(bloom.g,bloom.b));texel.rgb+=bloom.rgb;texel.a=min(1.,texel.a+brightness);gl_FragColor=texel;\n#elif PASS_STEP == 4\nvec4 texel=vec4(0.);texel.rgb+=intensity*SampleBox(vUv,0.5).rgb;texel.a=1.;gl_FragColor=texel;\n#endif\n#include <colorspace_fragment>\n}";
437
- var __defProp$7 = Object.defineProperty;
434
+ var __defProp$c = Object.defineProperty;
438
435
  var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
439
- var __decorateClass$7 = (decorators, target, key, kind) => {
436
+ var __decorateClass$c = (decorators, target, key, kind) => {
440
437
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
441
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
442
- if (decorator = decorators[i])
438
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
439
+ if (decorator = decorators[i2])
443
440
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
444
- if (kind && result) __defProp$7(target, key, result);
441
+ if (kind && result) __defProp$c(target, key, result);
445
442
  return result;
446
443
  };
447
444
  const passId$3 = "bloom";
@@ -451,10 +448,10 @@ const _BloomPlugin = (_a = class extends PipelinePassPlugin {
451
448
  this.passId = passId$3;
452
449
  this.materialExtension = uiConfigMaterialExtension(this._getUiConfig.bind(this), _a.PluginType);
453
450
  this.dependencies = [GBufferPlugin];
454
- this._onPluginAdd = (e) => {
455
- var _a2, _b, _c, _d;
456
- if (((_b = (_a2 = e.plugin) == null ? void 0 : _a2.constructor) == null ? void 0 : _b.PluginType) !== GBufferPlugin.PluginType) return;
457
- const gbuffer = e.plugin;
451
+ this._onPluginAdd = (e2) => {
452
+ var _a2, _b2, _c, _d;
453
+ if (((_b2 = (_a2 = e2.plugin) == null ? void 0 : _a2.constructor) == null ? void 0 : _b2.PluginType) !== GBufferPlugin.PluginType) return;
454
+ const gbuffer = e2.plugin;
458
455
  gbuffer.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this));
459
456
  (_c = this._pass) == null ? void 0 : _c.material.registerMaterialExtensions([gbuffer.unpackExtension]);
460
457
  (_d = this._viewer) == null ? void 0 : _d.removeEventListener("addPlugin", this._onPluginAdd);
@@ -543,7 +540,7 @@ const _BloomPlugin = (_a = class extends PipelinePassPlugin {
543
540
  return config;
544
541
  }
545
542
  }, _a.PluginType = "Bloom", _a.OldPluginType = "BloomPlugin", _a);
546
- __decorateClass$7([
543
+ __decorateClass$c([
547
544
  uiConfig()
548
545
  ], _BloomPlugin.prototype, "_pass", 2);
549
546
  let BloomPlugin = _BloomPlugin;
@@ -620,9 +617,9 @@ let BloomPluginPass = class extends ExtendedShaderPass {
620
617
  super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
621
618
  currentSource = currentDestination;
622
619
  const ci = this._currentIterations;
623
- let i = 1;
620
+ let i2 = 1;
624
621
  const iter = Math.max(2, this.bloomIterations);
625
- for (; i < iter; i++) {
622
+ for (; i2 < iter; i2++) {
626
623
  width /= 2;
627
624
  height /= 2;
628
625
  sizeMultiplier /= 2;
@@ -632,24 +629,24 @@ let BloomPluginPass = class extends ExtendedShaderPass {
632
629
  currentDestination = renderManager.getTempTarget({ sizeMultiplier, type: HalfFloatType });
633
630
  textures.push(currentDestination);
634
631
  this.material.defines.PASS_STEP = 1;
635
- let modifiedWeight = this._weights[i];
632
+ let modifiedWeight = this._weights[i2];
636
633
  {
637
- modifiedWeight = this._weights[i - 1] !== 0 ? this._weights[i] / this._weights[i - 1] : this._weights[i];
634
+ modifiedWeight = this._weights[i2 - 1] !== 0 ? this._weights[i2] / this._weights[i2 - 1] : this._weights[i2];
638
635
  }
639
636
  this.material.uniforms.weight.value = modifiedWeight;
640
637
  this.material.needsUpdate = true;
641
638
  super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
642
639
  currentSource = currentDestination;
643
- this._currentIterations = i + 1;
640
+ this._currentIterations = i2 + 1;
644
641
  }
645
642
  if (ci !== this._currentIterations)
646
643
  this._updateWeights(false);
647
644
  this.clear = false;
648
645
  const oldAutoClear = renderer.autoClear;
649
646
  renderer.autoClear = false;
650
- for (i -= 2; i >= 0; i--) {
651
- currentDestination = textures[i];
652
- textures[i] = void 0;
647
+ for (i2 -= 2; i2 >= 0; i2--) {
648
+ currentDestination = textures[i2];
649
+ textures[i2] = void 0;
653
650
  this.material.defines.PASS_STEP = 2;
654
651
  this.material.transparent = true;
655
652
  this.material.blending = AdditiveBlending;
@@ -681,73 +678,73 @@ let BloomPluginPass = class extends ExtendedShaderPass {
681
678
  const radius = Math.max(Math.min(this.radius, 1), 0);
682
679
  const iter = Math.max(2, this._currentIterations || this.bloomIterations);
683
680
  const delta = 1 / (iter - 1);
684
- for (let i = 0; i < iter; i++) {
685
- let f = i * delta + 0.1;
681
+ for (let i2 = 0; i2 < iter; i2++) {
682
+ let f = i2 * delta + 0.1;
686
683
  let oneMinusF = 1.2 - f;
687
684
  f = Math.pow(f, this.power);
688
685
  oneMinusF = Math.pow(oneMinusF, this.power);
689
- this._weights[i] = oneMinusF * (1 - radius) + f * radius;
686
+ this._weights[i2] = oneMinusF * (1 - radius) + f * radius;
690
687
  }
691
688
  if (setDirty !== false) this.setDirty();
692
689
  }
693
690
  };
694
- __decorateClass$7([
691
+ __decorateClass$c([
695
692
  uniform()
696
693
  ], BloomPluginPass.prototype, "prefilter", 2);
697
- __decorateClass$7([
694
+ __decorateClass$c([
698
695
  uiSlider("Threshold", [0, 2]),
699
696
  onChange(BloomPluginPass.prototype._thresholdsUpdated),
700
697
  serialize()
701
698
  ], BloomPluginPass.prototype, "threshold", 2);
702
- __decorateClass$7([
699
+ __decorateClass$c([
703
700
  uiSlider("Soft Threshold", [0, 1]),
704
701
  onChange(BloomPluginPass.prototype._thresholdsUpdated),
705
702
  serialize()
706
703
  ], BloomPluginPass.prototype, "softThreshold", 2);
707
- __decorateClass$7([
704
+ __decorateClass$c([
708
705
  uiSlider("Intensity", [0, 3]),
709
706
  serialize(),
710
707
  uniform()
711
708
  ], BloomPluginPass.prototype, "intensity", 2);
712
- __decorateClass$7([
709
+ __decorateClass$c([
713
710
  uiToggle("Background Bloom"),
714
711
  serialize(),
715
712
  matDefineBool("BACKGROUND_BLOOM")
716
713
  ], BloomPluginPass.prototype, "backgroundBloom", 2);
717
- __decorateClass$7([
714
+ __decorateClass$c([
718
715
  uiSlider("Iterations", [2, 7], 1),
719
716
  onChange2(BloomPluginPass.prototype._updateWeights),
720
717
  serialize()
721
718
  ], BloomPluginPass.prototype, "bloomIterations", 2);
722
- __decorateClass$7([
719
+ __decorateClass$c([
723
720
  uiSlider("Radius", [0, 1], 0.01),
724
721
  onChange2(BloomPluginPass.prototype._updateWeights),
725
722
  serialize()
726
723
  ], BloomPluginPass.prototype, "radius", 2);
727
- __decorateClass$7([
724
+ __decorateClass$c([
728
725
  uiSlider("Power", [0.2, 10], 0.01),
729
726
  onChange2(BloomPluginPass.prototype._updateWeights),
730
727
  serialize()
731
728
  ], BloomPluginPass.prototype, "power", 2);
732
- __decorateClass$7([
729
+ __decorateClass$c([
733
730
  uiToggle("Debug")
734
731
  ], BloomPluginPass.prototype, "bloomDebug", 2);
735
- BloomPluginPass = __decorateClass$7([
732
+ BloomPluginPass = __decorateClass$c([
736
733
  uiFolderContainer("Bloom Pass")
737
734
  ], BloomPluginPass);
738
735
  const dofCombine = "#include <common>\n#include <packing>\nvarying vec2 vUv;uniform vec2 cocTextureSize;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;uniform vec2 crossCenter;uniform float crossRadius;uniform float crossAlpha;uniform vec3 crossColor;float smoothBoundary(float d,float smooothFactor){smooothFactor*=0.5;float value=smoothstep(-smooothFactor,smooothFactor,d);return value;}float circle(vec2 p,float r){return min((length(p)-r),-(length(p)-r-0.01));}float computeCoc(){float depth=getDepth(vUv);if(depth>1.0-0.01)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){vec4 blur=blurTextureTexelToLinear(texture2D(blurTexture,vUv));float scale=0.5;blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(1.0,1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(-1.0,1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(-1.0,-1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(1.0,-1.0)/cocTextureSize));blur/=5.0;vec2 uvNearest=(floor(vUv*cocTextureSize)+0.5)/cocTextureSize;float coc=abs(min(2.*cocTextureTexelToLinear(texture2D(cocTexture,uvNearest)).a-1.,computeCoc()));float cocLower=0.005;float cocHigher=0.3;vec4 outColor=vec4(mix(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,blur.rgb,smoothstep(cocLower,cocHigher,coc)),1.0);vec2 d=vUv-crossCenter;if(length(d)>crossRadius+0.05){float dist=circle(d,crossRadius);gl_FragColor=outColor;}else{d.x*=cocTextureSize.x/cocTextureSize.y;float dist=circle(d,crossRadius);dist=smoothBoundary(dist,2.*fwidth(dist));vec4 color=outColor;vec3 dofCircleColor=mix(crossColor,color.rgb,1.-crossAlpha);gl_FragColor=vec4(mix(color.rgb,dofCircleColor,dist),color.a);}\n#include <colorspace_fragment>\n}";
739
736
  const dofPoissonBox = "#include <randomHelpers>\n#include <common>\nvarying vec2 vUv;uniform vec2 colorTextureSize;uniform float blurRadius;\n#ifndef D_frameCount\n#define D_frameCount\nuniform float frameCount;\n#endif\nvec4 CircularBlur(){vec4 color=colorTextureTexelToLinear(texture2D(colorTexture,vUv));\n#ifdef DOF_MODE\nfloat blurDist=blurRadius*(2.*color.a-1.);\n#else\nfloat blurDist=blurRadius*color.a;\n#endif\nfloat rnd=PI2*random3(vec3(vUv,frameCount*0.1));float costheta=cos(rnd);float sintheta=sin(rnd);vec4 rotationMatrix=vec4(costheta,-sintheta,sintheta,costheta);vec3 colorSum=vec3(0.0);float weightSum=0.001;vec2 ofs;vec4 sampleColor;setPds();\n#pragma unroll_loop_start\nfor(int i=0;i<16;i++){ofs=poisson_disk_samples[UNROLLED_LOOP_INDEX];ofs=vec2(dot(ofs,rotationMatrix.xy),dot(ofs,rotationMatrix.zw));sampleColor=colorTextureTexelToLinear(texture2D(colorTexture,vUv+blurDist*ofs/colorTextureSize.xy));\n#ifdef DOF_MODE\nsampleColor.a=abs(sampleColor.a*2.0-1.0);sampleColor.a*=sampleColor.a*sampleColor.a;\n#endif\ncolorSum+=sampleColor.rgb*sampleColor.a;weightSum+=sampleColor.a;}\n#pragma unroll_loop_end\ncolorSum/=weightSum;return vec4(min(vec3(72.),max(vec3(0.),colorSum)),1.0);}void main(){gl_FragColor=CircularBlur();\n#include <colorspace_fragment>\n}";
740
- const poissonDiskSamples = "vec2 poisson_disk_samples[16];void setPds(){poisson_disk_samples[0]=vec2(-0.399691779231,0.728591545584);poisson_disk_samples[1]=vec2(-0.48622557676,-0.84016533712);poisson_disk_samples[2]=vec2(0.770309468987,-0.24906070432);poisson_disk_samples[3]=vec2(0.556596796154,0.820359876432);poisson_disk_samples[4]=vec2(-0.933902004071,0.0600539051593);poisson_disk_samples[5]=vec2(0.330144964342,0.207477293384);poisson_disk_samples[6]=vec2(0.289013230975,-0.686749271417);poisson_disk_samples[7]=vec2(-0.0832470893559,-0.187351643125);poisson_disk_samples[8]=vec2(-0.296314525615,0.254474834305);poisson_disk_samples[9]=vec2(-0.850977666059,0.484642744689);poisson_disk_samples[10]=vec2(0.829287915319,0.2345063545);poisson_disk_samples[11]=vec2(-0.773042143899,-0.543741521254);poisson_disk_samples[12]=vec2(0.0561133030864,0.928419742597);poisson_disk_samples[13]=vec2(-0.205799249508,-0.562072714492);poisson_disk_samples[14]=vec2(-0.526991665882,-0.193690188118);poisson_disk_samples[15]=vec2(-0.051789270667,-0.935374050821);}";
737
+ const poissonDiskSamples$1 = "vec2 poisson_disk_samples[16];void setPds(){poisson_disk_samples[0]=vec2(-0.399691779231,0.728591545584);poisson_disk_samples[1]=vec2(-0.48622557676,-0.84016533712);poisson_disk_samples[2]=vec2(0.770309468987,-0.24906070432);poisson_disk_samples[3]=vec2(0.556596796154,0.820359876432);poisson_disk_samples[4]=vec2(-0.933902004071,0.0600539051593);poisson_disk_samples[5]=vec2(0.330144964342,0.207477293384);poisson_disk_samples[6]=vec2(0.289013230975,-0.686749271417);poisson_disk_samples[7]=vec2(-0.0832470893559,-0.187351643125);poisson_disk_samples[8]=vec2(-0.296314525615,0.254474834305);poisson_disk_samples[9]=vec2(-0.850977666059,0.484642744689);poisson_disk_samples[10]=vec2(0.829287915319,0.2345063545);poisson_disk_samples[11]=vec2(-0.773042143899,-0.543741521254);poisson_disk_samples[12]=vec2(0.0561133030864,0.928419742597);poisson_disk_samples[13]=vec2(-0.205799249508,-0.562072714492);poisson_disk_samples[14]=vec2(-0.526991665882,-0.193690188118);poisson_disk_samples[15]=vec2(-0.051789270667,-0.935374050821);}";
741
738
  const dofComputeCoC = "#include <common>\n#include <packing>\nvarying vec2 vUv;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;float computeCoc(){float depth=getDepth(vUv);if(depth==1.0)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*computeCoc()+0.5);\n#include <colorspace_fragment>\n}";
742
739
  const dofExpandCoC = "#include <common>\n#include <gbuffer_unpack>\nvarying vec2 vUv;uniform vec2 colorTextureSize;uniform vec2 direction;uniform vec2 nearFarBlurScale;const float MAXIMUM_BLUR_SIZE=4.0;float expandNear(const in vec2 offset,const in bool isBackground){float coc=0.0;vec2 sampleOffsets=MAXIMUM_BLUR_SIZE*offset/5.0;float coc0=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv)).a-1.;float coc1=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-5.0*sampleOffsets)).a-1.;float coc2=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-4.0*sampleOffsets)).a-1.;float coc3=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-3.0*sampleOffsets)).a-1.;float coc4=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-2.0*sampleOffsets)).a-1.;float coc5=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-1.0*sampleOffsets)).a-1.;float coc6=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+1.0*sampleOffsets)).a-1.;float coc7=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+2.0*sampleOffsets)).a-1.;float coc8=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+3.0*sampleOffsets)).a-1.;float coc9=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+4.0*sampleOffsets)).a-1.;float coc10=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+5.0*sampleOffsets)).a-1.;if(isBackground){coc=abs(coc0)*0.095474+(abs(coc1)+abs(coc10))*0.084264+(abs(coc2)+abs(coc9))*0.088139+(abs(coc3)+abs(coc8))*0.091276+(abs(coc4)+abs(coc7))*0.093585+(abs(coc5)+abs(coc6))*0.094998;}else{coc=min(coc0,0.0);coc=min(coc1*0.3,coc);coc=min(coc2*0.5,coc);coc=min(coc3*0.75,coc);coc=min(coc4*0.8,coc);coc=min(coc5*0.95,coc);coc=min(coc6*0.95,coc);coc=min(coc7*0.8,coc);coc=min(coc8*0.75,coc);coc=min(coc9*0.5,coc);coc=min(coc10*0.3,coc);if(abs(coc0)>abs(coc))coc=coc0;}return coc;}void main(){vec2 offset=2.*direction/colorTextureSize;bool isBackground=getDepth(vUv)>1.0-0.001;float coc=expandNear(offset,isBackground);gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*coc+0.5);\n#include <colorspace_fragment>\n}";
743
- var __defProp$6 = Object.defineProperty;
740
+ var __defProp$b = Object.defineProperty;
744
741
  var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
745
- var __decorateClass$6 = (decorators, target, key, kind) => {
742
+ var __decorateClass$b = (decorators, target, key, kind) => {
746
743
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
747
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
748
- if (decorator = decorators[i])
744
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
745
+ if (decorator = decorators[i2])
749
746
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
750
- if (kind && result) __defProp$6(target, key, result);
747
+ if (kind && result) __defProp$b(target, key, result);
751
748
  return result;
752
749
  };
753
750
  const passId$2 = "depthOfField";
@@ -761,13 +758,13 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
761
758
  this.crossFadeTime = 200;
762
759
  this._focalPointHitTime = 0;
763
760
  this.dependencies = [GBufferPlugin];
764
- this._onPluginAdd = (e) => {
765
- var _a2, _b, _c, _d, _e;
766
- const plugin = e.plugin;
761
+ this._onPluginAdd = (e2) => {
762
+ var _a2, _b2, _c, _d, _e;
763
+ const plugin = e2.plugin;
767
764
  if (!plugin) return;
768
765
  if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
769
766
  const gbuffer = plugin;
770
- (_b = this._pass) == null ? void 0 : _b.material.registerMaterialExtensions([gbuffer.unpackExtension]);
767
+ (_b2 = this._pass) == null ? void 0 : _b2.material.registerMaterialExtensions([gbuffer.unpackExtension]);
771
768
  (_c = this._pass) == null ? void 0 : _c.computeCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
772
769
  (_d = this._pass) == null ? void 0 : _d.expandCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
773
770
  }
@@ -776,18 +773,18 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
776
773
  picking.addEventListener("hitObject", this._onObjectHit);
777
774
  }
778
775
  };
779
- this._onPluginRemove = (e) => {
780
- var _a2, _b, _c, _d, _e;
781
- const plugin = e.plugin;
776
+ this._onPluginRemove = (e2) => {
777
+ var _a2, _b2, _c, _d, _e;
778
+ const plugin = e2.plugin;
782
779
  if (!plugin) return;
783
780
  if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
784
- const gbuffer = e.plugin;
785
- (_b = this._pass) == null ? void 0 : _b.material.unregisterMaterialExtensions([gbuffer.unpackExtension]);
781
+ const gbuffer = e2.plugin;
782
+ (_b2 = this._pass) == null ? void 0 : _b2.material.unregisterMaterialExtensions([gbuffer.unpackExtension]);
786
783
  (_c = this._pass) == null ? void 0 : _c.computeCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
787
784
  (_d = this._pass) == null ? void 0 : _d.expandCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
788
785
  }
789
786
  if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
790
- const picking = e.plugin;
787
+ const picking = e2.plugin;
791
788
  picking.removeEventListener("hitObject", this._onObjectHit);
792
789
  }
793
790
  };
@@ -814,22 +811,22 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
814
811
  }
815
812
  // todo make this a property.
816
813
  setFocalPoint(p, fade = true, showGizmo = false) {
817
- var _a2, _b;
814
+ var _a2, _b2;
818
815
  this._focalPointHit.copy(p);
819
- if (fade) (_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin("FrameFadePlugin")) == null ? void 0 : _b.startTransition(this._frameFadeTime);
816
+ if (fade) (_b2 = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin("FrameFadePlugin")) == null ? void 0 : _b2.startTransition(this._frameFadeTime);
820
817
  if (showGizmo) this._focalPointHitTime = now();
821
818
  this.setDirty();
822
819
  }
823
820
  getFocalPoint() {
824
821
  return this._focalPointHit;
825
822
  }
826
- _onObjectHit(e) {
827
- var _a2, _b;
828
- if (!this._pass || !e.intersects.intersect || this.isDisabled() || !this.enableEdit) return;
829
- this._focalPointHit.copy(e.intersects.intersect.point);
830
- this._focalPointHitTime = e.time;
831
- e.intersects.selectedObject = null;
832
- (_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(FrameFadePlugin)) == null ? void 0 : _b.startTransition(this._frameFadeTime);
823
+ _onObjectHit(e2) {
824
+ var _a2, _b2;
825
+ if (!this._pass || !e2.intersects.intersect || this.isDisabled() || !this.enableEdit) return;
826
+ this._focalPointHit.copy(e2.intersects.intersect.point);
827
+ this._focalPointHitTime = e2.time;
828
+ e2.intersects.selectedObject = null;
829
+ (_b2 = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(FrameFadePlugin)) == null ? void 0 : _b2.startTransition(this._frameFadeTime);
833
830
  this.setDirty();
834
831
  }
835
832
  _createPass() {
@@ -960,14 +957,14 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
960
957
  _DepthOfFieldPlugin.PluginType = "DepthOfField";
961
958
  _DepthOfFieldPlugin.OldPluginType = "DepthOfFieldPlugin";
962
959
  let DepthOfFieldPlugin = _DepthOfFieldPlugin;
963
- __decorateClass$6([
960
+ __decorateClass$b([
964
961
  serialize(),
965
962
  uiToggle()
966
963
  ], DepthOfFieldPlugin.prototype, "enableEdit", 2);
967
- __decorateClass$6([
964
+ __decorateClass$b([
968
965
  serialize("focalPoint")
969
966
  ], DepthOfFieldPlugin.prototype, "_focalPointHit", 2);
970
- __decorateClass$6([
967
+ __decorateClass$b([
971
968
  serialize()
972
969
  ], DepthOfFieldPlugin.prototype, "crossFadeTime", 2);
973
970
  const dofBlurMaterialPoisson = new ExtendedShaderMaterial({
@@ -979,7 +976,7 @@ const dofBlurMaterialPoisson = new ExtendedShaderMaterial({
979
976
  blurRadius: { value: 16 }
980
977
  },
981
978
  vertexShader: shaderUtils.defaultVertex,
982
- fragmentShader: poissonDiskSamples + "\n" + dofPoissonBox,
979
+ fragmentShader: poissonDiskSamples$1 + "\n" + dofPoissonBox,
983
980
  defines: {
984
981
  ["DOF_MODE"]: 1
985
982
  }
@@ -1082,50 +1079,50 @@ let DepthOfFieldPluginPass = class extends ExtendedShaderPass {
1082
1079
  renderManager.releaseTempTarget(renderTargetBlurTemp);
1083
1080
  }
1084
1081
  };
1085
- __decorateClass$6([
1082
+ __decorateClass$b([
1086
1083
  bindToValue({ obj: "focalDepthRange", key: "y" }),
1087
1084
  uiSlider("Depth Range", [0.25, 3])
1088
1085
  ], DepthOfFieldPluginPass.prototype, "depthRange", 2);
1089
- __decorateClass$6([
1086
+ __decorateClass$b([
1090
1087
  bindToValue({ obj: "nearFarBlurScale", key: "x" }),
1091
1088
  uiSlider("Near Blur Scale", [0, 1])
1092
1089
  ], DepthOfFieldPluginPass.prototype, "nearBlurScale", 2);
1093
- __decorateClass$6([
1090
+ __decorateClass$b([
1094
1091
  bindToValue({ obj: "nearFarBlurScale", key: "y" }),
1095
1092
  uiSlider("Far Blur Scale", [0, 1])
1096
1093
  ], DepthOfFieldPluginPass.prototype, "farBlurScale", 2);
1097
- __decorateClass$6([
1094
+ __decorateClass$b([
1098
1095
  serialize(),
1099
1096
  uniform()
1100
1097
  ], DepthOfFieldPluginPass.prototype, "nearFarBlurScale", 2);
1101
- __decorateClass$6([
1098
+ __decorateClass$b([
1102
1099
  serialize(),
1103
1100
  uniform()
1104
1101
  ], DepthOfFieldPluginPass.prototype, "focalDepthRange", 2);
1105
- __decorateClass$6([
1102
+ __decorateClass$b([
1106
1103
  uniform()
1107
1104
  ], DepthOfFieldPluginPass.prototype, "crossCenter", 2);
1108
- __decorateClass$6([
1105
+ __decorateClass$b([
1109
1106
  uniform()
1110
1107
  ], DepthOfFieldPluginPass.prototype, "crossRadius", 2);
1111
- __decorateClass$6([
1108
+ __decorateClass$b([
1112
1109
  uniform()
1113
1110
  ], DepthOfFieldPluginPass.prototype, "crossAlpha", 2);
1114
- __decorateClass$6([
1111
+ __decorateClass$b([
1115
1112
  uniform()
1116
1113
  ], DepthOfFieldPluginPass.prototype, "crossColor", 2);
1117
- DepthOfFieldPluginPass = __decorateClass$6([
1114
+ DepthOfFieldPluginPass = __decorateClass$b([
1118
1115
  uiFolderContainer("DepthOfField Pass")
1119
1116
  ], DepthOfFieldPluginPass);
1120
1117
  const ssrtShader = "#ifndef SSRT_PARS_SNIP\n#define SSRT_PARS_SNIP\n#define pow2(a) a*a\nfloat getDepth2(const in vec2 uv,const in float lod){float viewDepth=getDepth(uv);return depthToViewZ(viewDepth);}\n#define LOD_DEPTH 1.0\n#define LOD_COLOR 5.0\nvoid _traceRay(in vec4 ray_origin,in vec4 ray_dir,in float tolerance,inout vec3 state,in int loopMax,in float iStepCount){vec4 sample_uv;float d,hit;float dLod=0.;\n#pragma unroll_loop_start\nfor(int i=0;i<8;i++){if(UNROLLED_LOOP_INDEX<loopMax){sample_uv=ray_origin+ray_dir*state.y;d=getDepth2(sample_uv.xy,dLod);d=sample_uv.z/sample_uv.w-d;if(abs(d+tolerance)<tolerance){hit=clamp(state.x/(state.x-d),0.,1.)-1.;hit=(state.y+hit*iStepCount);state.z=min(state.z,hit);}state.x=d;state.y+=1.*iStepCount;}}\n#pragma unroll_loop_end\n}vec3 traceRay(in vec3 ray_origin_view,in vec3 ray_dir_view,in float tolerance,inout vec3 state,in int _STEP_COUNT){vec4 sample_uv;vec4 ray_origin=viewToScreen3(ray_origin_view);vec3 ray_end_view=ray_origin_view+ray_dir_view;vec4 ray_dir=viewToScreen3(ray_end_view);vec2 clamp_end=clamp(ray_dir.xy,vec2(0.),vec2(1.));vec2 correction=abs(ray_dir.xy-clamp_end);correction=(step(0.01,correction)*correction/(abs(clamp_end-ray_origin.xy)+0.01))+1.;correction.x=1./min(max(correction.y,correction.x),10.);ray_dir=ray_dir-ray_origin;ray_dir.xyw*=correction.x;float iStepCount=1./float(_STEP_COUNT);tolerance*=0.125;_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT,iStepCount);if(_STEP_COUNT>8&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-8,iStepCount);if(_STEP_COUNT>15&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);if(_STEP_COUNT>23&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);sample_uv=ray_origin+ray_dir*state.z;sample_uv.z/=sample_uv.w;state.z=state.z<0.999 ? state.z : 9999999.;return sample_uv.xyz;}/**for ray clippinga=ray_originb=ray_endc=clamp(b)x=c.y-a.yy=b.y-c.y(c.y-a.y)/(b.y-c.y)=m/(l-m)m/(l-m)=km=kl-kmm=kl/(1+k)((c-a)/(b-c))/(1+(c-a)/(b-c))x/(y*(1+x/y))x/(y+x)1/(y/x+1)x/(y+yx)1/(y/x+y)ray scale=k/(1+k)1/(1/k+1)=1/((b-c)/(c-a)+1)**/\n#endif\n";
1121
- var __defProp$5 = Object.defineProperty;
1118
+ var __defProp$a = Object.defineProperty;
1122
1119
  var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
1123
- var __decorateClass$5 = (decorators, target, key, kind) => {
1120
+ var __decorateClass$a = (decorators, target, key, kind) => {
1124
1121
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
1125
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
1126
- if (decorator = decorators[i])
1122
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
1123
+ if (decorator = decorators[i2])
1127
1124
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1128
- if (kind && result) __defProp$5(target, key, result);
1125
+ if (kind && result) __defProp$a(target, key, result);
1129
1126
  return result;
1130
1127
  };
1131
1128
  let SSContactShadowsPlugin = class extends AViewerPluginSync {
@@ -1161,7 +1158,7 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1161
1158
  uuid: SSContactShadowsPlugin.PluginType,
1162
1159
  priority: 5,
1163
1160
  shaderExtender: (shader, _material, _renderer) => {
1164
- var _a2, _b;
1161
+ var _a2, _b2;
1165
1162
  if (!shader.defines.SSCS_ENABLED) return;
1166
1163
  const rsS = "float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {";
1167
1164
  const lsS = glsl`
@@ -1213,11 +1210,11 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1213
1210
  "directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;",
1214
1211
  "directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;"
1215
1212
  );
1216
- (_b = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b.call(_a2, shader, _material, _renderer);
1213
+ (_b2 = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b2.call(_a2, shader, _material, _renderer);
1217
1214
  },
1218
1215
  onObjectRender: (_, material, renderer) => {
1219
- var _a2, _b;
1220
- const enabled2 = this.enabled && renderer.userData.screenSpaceRendering !== false && !((_a2 = material.userData) == null ? void 0 : _a2.pluginsDisabled) && !((_b = material.userData) == null ? void 0 : _b.sscsDisabled) ? 1 : 0;
1216
+ var _a2, _b2;
1217
+ const enabled2 = this.enabled && renderer.userData.screenSpaceRendering !== false && !((_a2 = material.userData) == null ? void 0 : _a2.pluginsDisabled) && !((_b2 = material.userData) == null ? void 0 : _b2.sscsDisabled) ? 1 : 0;
1221
1218
  updateMaterialDefines({
1222
1219
  ...this._defines,
1223
1220
  ["SSCS_ENABLED"]: enabled2
@@ -1288,11 +1285,11 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1288
1285
  // return config
1289
1286
  // },
1290
1287
  updaters: () => {
1291
- var _a2, _b, _c, _d;
1288
+ var _a2, _b2, _c, _d;
1292
1289
  return [
1293
1290
  // this._viewer?.getPlugin(GBufferPlugin),
1294
1291
  (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(ProgressivePlugin),
1295
- (_b = this._viewer) == null ? void 0 : _b.scene.renderCamera,
1292
+ (_b2 = this._viewer) == null ? void 0 : _b2.scene.renderCamera,
1296
1293
  (_c = this._viewer) == null ? void 0 : _c.renderManager,
1297
1294
  (_d = this._viewer) == null ? void 0 : _d.scene
1298
1295
  ];
@@ -1311,8 +1308,8 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1311
1308
  this.enabled = enabled;
1312
1309
  }
1313
1310
  setDirty() {
1314
- var _a2, _b, _c;
1315
- (_b = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b.call(_a2);
1311
+ var _a2, _b2, _c;
1312
+ (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
1316
1313
  (_c = this._viewer) == null ? void 0 : _c.setDirty();
1317
1314
  }
1318
1315
  onAdded(v) {
@@ -1338,51 +1335,51 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1338
1335
  };
1339
1336
  SSContactShadowsPlugin.PluginType = "SSContactShadows";
1340
1337
  SSContactShadowsPlugin.OldPluginType = "SSContactShadowsPlugin";
1341
- __decorateClass$5([
1338
+ __decorateClass$a([
1342
1339
  uiToggle("Enabled"),
1343
1340
  serialize(),
1344
1341
  onChange(SSContactShadowsPlugin.prototype.setDirty)
1345
1342
  ], SSContactShadowsPlugin.prototype, "enabled", 2);
1346
- __decorateClass$5([
1343
+ __decorateClass$a([
1347
1344
  uniform({ propKey: "sscsRadius", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1348
1345
  uiSlider("Radius", [1e-4, 0.1], 1e-4),
1349
1346
  serialize()
1350
1347
  ], SSContactShadowsPlugin.prototype, "radius", 2);
1351
- __decorateClass$5([
1348
+ __decorateClass$a([
1352
1349
  uniform({ propKey: "sscsIntensity", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1353
1350
  uiSlider("Intensity", [1e-4, 1], 1e-4),
1354
1351
  serialize()
1355
1352
  ], SSContactShadowsPlugin.prototype, "intensity", 2);
1356
- __decorateClass$5([
1353
+ __decorateClass$a([
1357
1354
  uniform({ propKey: "sscsTolerance", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1358
1355
  uiSlider("Tolerance", [0.1, 5]),
1359
1356
  serialize()
1360
1357
  ], SSContactShadowsPlugin.prototype, "tolerance", 2);
1361
- __decorateClass$5([
1358
+ __decorateClass$a([
1362
1359
  matDefine("SSCS_DEBUG", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
1363
1360
  uiToggle("Debug only SSCS"),
1364
1361
  serialize()
1365
1362
  ], SSContactShadowsPlugin.prototype, "onlySSCSDebug", 2);
1366
- __decorateClass$5([
1363
+ __decorateClass$a([
1367
1364
  matDefine("SSCS_STEP_COUNT", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
1368
1365
  uiSlider("Step count", [1, 8], 1),
1369
1366
  serialize()
1370
1367
  ], SSContactShadowsPlugin.prototype, "stepCount", 2);
1371
- SSContactShadowsPlugin = __decorateClass$5([
1368
+ SSContactShadowsPlugin = __decorateClass$a([
1372
1369
  uiFolderContainer("SS Contact Shadows")
1373
1370
  ], SSContactShadowsPlugin);
1374
1371
  const samplePointHelpers = "#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;}";
1375
1372
  const ssrShader = "uniform float currentFrameCount;\n#ifndef D_frameCount\n#define D_frameCount\nuniform float frameCount;\n#endif\nuniform float objectRadius;uniform float radius;uniform float tolerance;uniform float ssrRoughnessFactor;uniform bool autoRadius;\n#ifndef D_sceneBoundingRadius\n#define D_sceneBoundingRadius\nuniform float sceneBoundingRadius;\n#endif\nvec3 ComputeReflectionL(vec3 N,vec2 E,vec3 V,float rough){float rough4=rough*rough*rough*rough;float phi=2.0*PI*E.x;float cos_theta=pow(max(E.y,0.000001),rough4/(2.0-rough4));float sin_theta=sqrt(max(0.,1.0-cos_theta*cos_theta));vec3 half_vec=vec3(sin_theta*cos(phi),sin_theta*sin(phi),cos_theta);vec3 tangentX=normalize(cross(abs(N.z)<0.999 ? vec3(0.0,0.0,1.0): vec3(1.0,0.0,0.0),N));vec3 tangentY=cross(N,tangentX);half_vec=half_vec.x*tangentX+half_vec.y*tangentY+half_vec.z*N;vec3 ray_dir=(2.0*dot(V,half_vec))*half_vec-V;return ray_dir;}vec2 GetRandomE(float seed){vec2 rand_e;rand_e.x=interleavedGradientNoise(gl_FragCoord.xy,frameCount*34.+seed);rand_e.y=fract(rand_e.x*38.65435);rand_e.y=mix(rand_e.y,1.0,0.7);return rand_e;}vec4 calculateSSR(in float seed,in vec3 screenPos,in vec3 normal,in float radiusFactor,in float roughness){vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);normal=normalize(normal);vec2 E=GetRandomE(seed);vec3 L=ComputeReflectionL(normal,E,-normalize(viewPos),roughness*ssrRoughnessFactor);L=normalize(L);float cameraDist=length(cameraPositionWorld);float rayLen=objectRadius*sceneBoundingRadius;rayLen=autoRadius ?min(max(mix(max(0.0,(cameraDist+rayLen)+viewPos.z),max(0.0,-viewPos.z-max(0.0,cameraDist-rayLen)),L.z*0.5+0.5),rayLen*0.1),rayLen*5.):rayLen;rayLen*=radiusFactor;float r=interleavedGradientNoise(gl_FragCoord.xy,frameCount+seed);rayLen=max(rayLen,0.001);int steps=SSR_STEP_COUNT/(currentFrameCount<float(SSR_LOW_QUALITY_FRAMES)? 2 : 1);vec3 state=vec3(0.,(r+0.5)/float(steps),2.);viewPos+=normal*max(-0.0001*viewPos.z,0.001);vec3 screenHitP=traceRay(viewPos,L*rayLen,tolerance*rayLen,state,steps);if(state.z<0.99){vec3 hitColor=(tLastFrameTexelToLinear(texture2D(tLastFrame,screenHitP.xy))).rgb;float ssrWeight=1.;return vec4(hitColor*ssrWeight,1.);}return vec4(0.);}";
1376
1373
  const ssreflPatch = "\n#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0\nvec3 screenPos=viewToScreen(geometryPosition);vec4 ssrColor=vec4(0,0,0,0);float alphaModifier=1.0-clamp(material.roughness*.3,0.,1.);alphaModifier*=ssrIntensity;\n#if defined(SSR_MASK_FRONT_RAYS) && SSR_MASK_FRONT_RAYS > 0\nalphaModifier*=clamp(-4.0*dot(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#endif\n";
1377
1374
  const ssrShaderMain = "void main(){vec4 texel=tDiffuseTexelToLinear(texture2D(tDiffuse,vUv));vec4 lastAO=tLastThisTexelToLinear(texture2D(tLastThis,vUv));float depth;vec3 normal;getDepthNormal(vUv,depth,normal);if(depth>=0.999){discard;}float viewZ=depthToViewZ(depth);vec3 screenPos=vec3(vUv.x,vUv.y,viewZ);vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);viewPos.z=viewZ/viewPos.z;vec4 ao=vec4(0.);ao+=calculateSSR(8.,screenPos,normal,1.,0.1);ao.rgb=min(vec3(3.),ao.rgb);ao.rgb=max(vec3(0.),ao.rgb);if(currentFrameCount<2.){gl_FragColor=ao;return;}if(ao.a<0.01){gl_FragColor.rgb=lastAO.rgb;gl_FragColor.a=(((lastAO.a)*currentFrameCount)/(currentFrameCount+1.));}else{gl_FragColor=((ao+(lastAO)*currentFrameCount)/(currentFrameCount+1.));}\n#include <colorspace_fragment>\n}";
1378
- var __defProp$4 = Object.defineProperty;
1375
+ var __defProp$9 = Object.defineProperty;
1379
1376
  var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
1380
- var __decorateClass$4 = (decorators, target, key, kind) => {
1377
+ var __decorateClass$9 = (decorators, target, key, kind) => {
1381
1378
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
1382
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
1383
- if (decorator = decorators[i])
1379
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
1380
+ if (decorator = decorators[i2])
1384
1381
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1385
- if (kind && result) __defProp$4(target, key, result);
1382
+ if (kind && result) __defProp$9(target, key, result);
1386
1383
  return result;
1387
1384
  };
1388
1385
  const passId$1 = "ssrefl";
@@ -1455,11 +1452,11 @@ let SSReflectionPlugin = class extends PipelinePassPlugin {
1455
1452
  _beforeRender(_, _1, _2) {
1456
1453
  var _a2;
1457
1454
  if (!this._viewer) return false;
1458
- const e = super._beforeRender(_, _1, _2);
1459
- if (!e) return e;
1455
+ const e2 = super._beforeRender(_, _1, _2);
1456
+ if (!e2) return e2;
1460
1457
  const progressive = this._viewer.getPlugin(ProgressivePlugin);
1461
1458
  (_a2 = this._pass) == null ? void 0 : _a2.updateShaderProperties([progressive]);
1462
- return e;
1459
+ return e2;
1463
1460
  }
1464
1461
  /**
1465
1462
  * @deprecated use {@link target} instead
@@ -1481,16 +1478,13 @@ let SSReflectionPlugin = class extends PipelinePassPlugin {
1481
1478
  };
1482
1479
  SSReflectionPlugin.PluginType = "SSReflectionPlugin";
1483
1480
  SSReflectionPlugin.OldPluginType = "SSReflection";
1484
- __decorateClass$4([
1485
- uiImage(
1486
- "SSReflection Buffer"
1487
- /* {readOnly: true}*/
1488
- )
1481
+ __decorateClass$9([
1482
+ uiImage("SSReflection Buffer", { readOnly: true, hideOnEmpty: true })
1489
1483
  ], SSReflectionPlugin.prototype, "texture", 2);
1490
- __decorateClass$4([
1484
+ __decorateClass$9([
1491
1485
  uiConfig()
1492
1486
  ], SSReflectionPlugin.prototype, "_pass", 2);
1493
- SSReflectionPlugin = __decorateClass$4([
1487
+ SSReflectionPlugin = __decorateClass$9([
1494
1488
  uiFolderContainer("SSReflection Plugin")
1495
1489
  ], SSReflectionPlugin);
1496
1490
  let SSReflectionPluginPass = class extends ExtendedShaderPass {
@@ -1598,7 +1592,7 @@ ${ssrShaderMain}
1598
1592
  // todo gbuffer stuff
1599
1593
  },
1600
1594
  shaderExtender: (shader, _material, _renderer) => {
1601
- var _a2, _b;
1595
+ var _a2, _b2;
1602
1596
  if (!shader.defines.SSREFL_ENABLED) return;
1603
1597
  const ls = `
1604
1598
 
@@ -1616,11 +1610,11 @@ ${ssrShaderMain}
1616
1610
  ls,
1617
1611
  { prepend: true }
1618
1612
  );
1619
- (_b = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b.call(_a2, shader, _material, _renderer);
1613
+ (_b2 = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b2.call(_a2, shader, _material, _renderer);
1620
1614
  },
1621
1615
  onObjectRender: (_object, material, renderer) => {
1622
- var _a2, _b, _c;
1623
- let x = this.enabled && renderer.userData.screenSpaceRendering !== false && !((_a2 = material.userData) == null ? void 0 : _a2.pluginsDisabled) && !((_b = material.userData) == null ? void 0 : _b.ssreflDisabled) ? 1 : 0;
1616
+ var _a2, _b2, _c;
1617
+ let x = this.enabled && renderer.userData.screenSpaceRendering !== false && !((_a2 = material.userData) == null ? void 0 : _a2.pluginsDisabled) && !((_b2 = material.userData) == null ? void 0 : _b2.ssreflDisabled) ? 1 : 0;
1624
1618
  if (material.defines.SSREFL_ENABLED !== x) {
1625
1619
  material.defines.SSREFL_ENABLED = x;
1626
1620
  material.needsUpdate = true;
@@ -1632,7 +1626,7 @@ ${ssrShaderMain}
1632
1626
  }
1633
1627
  },
1634
1628
  parsFragmentSnippet: () => {
1635
- var _a2, _b;
1629
+ var _a2, _b2;
1636
1630
  return glsl`
1637
1631
  #if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
1638
1632
  uniform float ssrPower;
@@ -1642,7 +1636,7 @@ ${ssrShaderMain}
1642
1636
  uniform sampler2D tSSReflMap;
1643
1637
  uniform sampler2D tLastFrame;
1644
1638
  ${getTexelDecoding("tSSReflMap", (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture.colorSpace)}
1645
- ${getTexelDecoding("tLastFrame", (_b = this.material.uniforms.tLastFrame.value) == null ? void 0 : _b.colorSpace)}
1639
+ ${getTexelDecoding("tLastFrame", (_b2 = this.material.uniforms.tLastFrame.value) == null ? void 0 : _b2.colorSpace)}
1646
1640
  ${!this.inlineShaderRayTrace ? "" : `
1647
1641
  #define THREE_PACKING_INCLUDED // by threejs
1648
1642
  #include <cameraHelpers>
@@ -1656,8 +1650,8 @@ ${ssrShader}
1656
1650
  `;
1657
1651
  },
1658
1652
  computeCacheKey: () => {
1659
- var _a2, _b;
1660
- return (this.enabled ? "1" : "0") + ((_b = (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) == null ? void 0 : _b.colorSpace) + Object.values(this.material.defines).map((v) => v + "").join(",");
1653
+ var _a2, _b2;
1654
+ return (this.enabled ? "1" : "0") + ((_b2 = (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) == null ? void 0 : _b2.colorSpace) + Object.values(this.material.defines).map((v) => v + "").join(",");
1661
1655
  },
1662
1656
  uuid: SSReflectionPlugin.PluginType,
1663
1657
  ...uiConfigMaterialExtension(this._getUiConfig.bind(this), SSReflectionPlugin.PluginType),
@@ -1686,8 +1680,8 @@ ${ssrShader}
1686
1680
  }
1687
1681
  }
1688
1682
  setDirty() {
1689
- var _a2, _b;
1690
- (_b = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b.call(_a2);
1683
+ var _a2, _b2;
1684
+ (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
1691
1685
  super.setDirty();
1692
1686
  }
1693
1687
  render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
@@ -1769,85 +1763,85 @@ ${ssrShader}
1769
1763
  Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines);
1770
1764
  }
1771
1765
  };
1772
- __decorateClass$4([
1766
+ __decorateClass$9([
1773
1767
  uiSlider("Intensity", [0, 4]),
1774
1768
  serialize(),
1775
1769
  uniform()
1776
1770
  ], SSReflectionPluginPass.prototype, "intensity", 2);
1777
- __decorateClass$4([
1771
+ __decorateClass$9([
1778
1772
  uiVector("Boost"),
1779
1773
  serialize(),
1780
1774
  uniform()
1781
1775
  ], SSReflectionPluginPass.prototype, "boost", 2);
1782
- __decorateClass$4([
1776
+ __decorateClass$9([
1783
1777
  uiSlider("Object Radius", [0.01, 2]),
1784
1778
  serialize(),
1785
1779
  uniform()
1786
1780
  ], SSReflectionPluginPass.prototype, "objectRadius", 2);
1787
- __decorateClass$4([
1781
+ __decorateClass$9([
1788
1782
  uiToggle("Auto radius"),
1789
1783
  serialize(),
1790
1784
  uniform()
1791
1785
  ], SSReflectionPluginPass.prototype, "autoRadius", 2);
1792
- __decorateClass$4([
1786
+ __decorateClass$9([
1793
1787
  uiSlider("Power", [0, 3]),
1794
1788
  serialize(),
1795
1789
  uniform()
1796
1790
  ], SSReflectionPluginPass.prototype, "power", 2);
1797
- __decorateClass$4([
1791
+ __decorateClass$9([
1798
1792
  uiSlider("Tolerance", [0.1, 5]),
1799
1793
  serialize(),
1800
1794
  uniform()
1801
1795
  ], SSReflectionPluginPass.prototype, "tolerance", 2);
1802
- __decorateClass$4([
1796
+ __decorateClass$9([
1803
1797
  uiSlider("Roughness Factor", [0.1, 1.25]),
1804
1798
  serialize(),
1805
1799
  uniform({ propKey: "ssrRoughnessFactor" })
1806
1800
  ], SSReflectionPluginPass.prototype, "roughnessFactor", 2);
1807
- __decorateClass$4([
1801
+ __decorateClass$9([
1808
1802
  uiSlider("Step count", [1, 32], 1),
1809
1803
  serialize(),
1810
1804
  matDefine("SSR_STEP_COUNT", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1811
1805
  ], SSReflectionPluginPass.prototype, "stepCount", 2);
1812
- __decorateClass$4([
1806
+ __decorateClass$9([
1813
1807
  uiSlider("Ray count", [1, 8], 1),
1814
1808
  serialize(),
1815
1809
  matDefine("SSR_RAY_COUNT", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1816
1810
  ], SSReflectionPluginPass.prototype, "rayCount", 2);
1817
- __decorateClass$4([
1811
+ __decorateClass$9([
1818
1812
  uiToggle("Ray Blend MAX"),
1819
1813
  serialize(),
1820
1814
  matDefineBool("SSR_RAY_BLEND_MAX", void 0, void 0, SSReflectionPluginPass.prototype.setDirty, true)
1821
1815
  ], SSReflectionPluginPass.prototype, "rayBlendMax", 2);
1822
- __decorateClass$4([
1816
+ __decorateClass$9([
1823
1817
  uiSlider("Low Quality Frames", [0, 4], 1),
1824
1818
  serialize(),
1825
1819
  matDefine("SSR_LOW_QUALITY_FRAMES", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1826
1820
  ], SSReflectionPluginPass.prototype, "lowQualityFrames", 2);
1827
- __decorateClass$4([
1821
+ __decorateClass$9([
1828
1822
  uiToggle("Ignore front rays"),
1829
1823
  serialize(),
1830
1824
  matDefineBool("SSR_MASK_FRONT_RAYS", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1831
1825
  ], SSReflectionPluginPass.prototype, "maskFrontRays", 2);
1832
- __decorateClass$4([
1826
+ __decorateClass$9([
1833
1827
  uiSlider("Mask front rays factor", [-1, 1], 0.01, (that) => ({ hidden: () => !that.maskFrontRays })),
1834
1828
  serialize(),
1835
1829
  uniform()
1836
1830
  ], SSReflectionPluginPass.prototype, "maskFrontFactor", 2);
1837
- SSReflectionPluginPass = __decorateClass$4([
1831
+ SSReflectionPluginPass = __decorateClass$9([
1838
1832
  uiFolderContainer("SSReflection Pass")
1839
1833
  ], SSReflectionPluginPass);
1840
1834
  const outlineShader = "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);}";
1841
1835
  const outlineDepthVertex = "#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;}";
1842
1836
  const outlineDepthFrag = "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.);}";
1843
- var __defProp$3 = Object.defineProperty;
1837
+ var __defProp$8 = Object.defineProperty;
1844
1838
  var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
1845
- var __decorateClass$3 = (decorators, target, key, kind) => {
1839
+ var __decorateClass$8 = (decorators, target, key, kind) => {
1846
1840
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
1847
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
1848
- if (decorator = decorators[i])
1841
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
1842
+ if (decorator = decorators[i2])
1849
1843
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1850
- if (kind && result) __defProp$3(target, key, result);
1844
+ if (kind && result) __defProp$8(target, key, result);
1851
1845
  return result;
1852
1846
  };
1853
1847
  let OutlinePlugin = class extends AScreenPassExtensionPlugin {
@@ -1896,7 +1890,7 @@ let OutlinePlugin = class extends AScreenPassExtensionPlugin {
1896
1890
  side: DoubleSide
1897
1891
  });
1898
1892
  this._getSelectedObject = () => {
1899
- var _a2, _b, _c, _d;
1893
+ var _a2, _b2, _c, _d;
1900
1894
  if (!this._viewer) return;
1901
1895
  const picking = this._viewer.getPlugin(PickingPlugin);
1902
1896
  if (this.highlightSelectedMaterials) {
@@ -1905,7 +1899,7 @@ let OutlinePlugin = class extends AScreenPassExtensionPlugin {
1905
1899
  const names = Array.isArray(mat) ? mat.map((m) => m.name) : [mat.name];
1906
1900
  const mats = /* @__PURE__ */ new Set();
1907
1901
  for (const name of names) {
1908
- const mats1 = (_d = (_c = (_b = this._viewer) == null ? void 0 : _b.assetManager) == null ? void 0 : _c.materials) == null ? void 0 : _d.findMaterialsByName(name);
1902
+ const mats1 = (_d = (_c = (_b2 = this._viewer) == null ? void 0 : _b2.assetManager) == null ? void 0 : _c.materials) == null ? void 0 : _d.findMaterialsByName(name);
1909
1903
  mats1 == null ? void 0 : mats1.forEach((m) => mats.add(m));
1910
1904
  }
1911
1905
  return [...mats];
@@ -1961,12 +1955,13 @@ let OutlinePlugin = class extends AScreenPassExtensionPlugin {
1961
1955
  }
1962
1956
  }
1963
1957
  });
1964
- document.addEventListener("mousemove", (e) => {
1958
+ document.addEventListener("mousemove", (e2) => {
1965
1959
  if (!this) return;
1966
1960
  if (!this.mouseInOutAnimationEnabled) return;
1961
+ if (!this.enableHighlight) return;
1967
1962
  const selectedObject = pickingPlugin == null ? void 0 : pickingPlugin.getSelectedObject();
1968
1963
  if (selectedObject && this.enableDynamicSelection) {
1969
- if (e.target !== viewer.canvas) {
1964
+ if (e2.target !== viewer.canvas) {
1970
1965
  if (!this._animationCallBack && this._state === "in") {
1971
1966
  this._animationCallBack = this._startTransparencyAnimation(this.highlightTransparency, 1, 600);
1972
1967
  this._state = "out";
@@ -2056,64 +2051,61 @@ let OutlinePlugin = class extends AScreenPassExtensionPlugin {
2056
2051
  };
2057
2052
  OutlinePlugin.PluginType = "OutlinePlugin";
2058
2053
  OutlinePlugin.OldPluginType = "Outline";
2059
- __decorateClass$3([
2054
+ __decorateClass$8([
2060
2055
  onChange(OutlinePlugin.prototype.setDirty),
2061
2056
  uiToggle("Enable"),
2062
2057
  serialize()
2063
2058
  ], OutlinePlugin.prototype, "enabled", 2);
2064
- __decorateClass$3([
2059
+ __decorateClass$8([
2065
2060
  uiToggle("Highlight"),
2066
2061
  uniform({ propKey: "enableHighlight" }),
2067
2062
  serialize()
2068
2063
  ], OutlinePlugin.prototype, "enableHighlight", 2);
2069
- __decorateClass$3([
2064
+ __decorateClass$8([
2070
2065
  onChange(OutlinePlugin.prototype.setDirty),
2071
2066
  uiToggle("DynamicSelection"),
2072
2067
  serialize()
2073
2068
  ], OutlinePlugin.prototype, "enableDynamicSelection", 2);
2074
- __decorateClass$3([
2069
+ __decorateClass$8([
2075
2070
  uiSlider("Intensity", [0, 4], 1e-3),
2076
2071
  uniform({ propKey: "outlineIntensity" }),
2077
2072
  serialize("outlineIntensity")
2078
2073
  ], OutlinePlugin.prototype, "intensity", 2);
2079
- __decorateClass$3([
2074
+ __decorateClass$8([
2080
2075
  onChange(OutlinePlugin.prototype.setDirty),
2081
2076
  uiSlider("Transparency", [0, 1], 0.01),
2082
2077
  serialize()
2083
2078
  ], OutlinePlugin.prototype, "highlightTransparency", 2);
2084
- __decorateClass$3([
2079
+ __decorateClass$8([
2085
2080
  uiColor("Color"),
2086
2081
  uniform({ propKey: "outlineColor" }),
2087
2082
  serialize("outlineColor")
2088
2083
  ], OutlinePlugin.prototype, "color", 2);
2089
- __decorateClass$3([
2084
+ __decorateClass$8([
2090
2085
  uiSlider("Thickness", [0, 10], 0.01),
2091
2086
  uniform({ propKey: "outlineThickness" }),
2092
2087
  serialize("outlineThickness")
2093
2088
  ], OutlinePlugin.prototype, "thickness", 2);
2094
- __decorateClass$3([
2089
+ __decorateClass$8([
2095
2090
  uiToggle("Debug"),
2096
2091
  matDefineBool("DEBUG_OUTLINE", void 0, true)
2097
2092
  ], OutlinePlugin.prototype, "debugOutline", 2);
2098
- __decorateClass$3([
2093
+ __decorateClass$8([
2099
2094
  onChange(OutlinePlugin.prototype.setDirty),
2100
2095
  uiToggle("Highlight Selected Materials")
2101
2096
  ], OutlinePlugin.prototype, "highlightSelectedMaterials", 2);
2102
- __decorateClass$3([
2097
+ __decorateClass$8([
2103
2098
  onChange(OutlinePlugin.prototype.setDirty),
2104
2099
  uiToggle("Highlight Materials (same name)")
2105
2100
  ], OutlinePlugin.prototype, "highlightMaterialSameNames", 2);
2106
- __decorateClass$3([
2101
+ __decorateClass$8([
2107
2102
  uniform({ propKey: "highlightTransparency" })
2108
2103
  ], OutlinePlugin.prototype, "transparency", 2);
2109
- __decorateClass$3([
2104
+ __decorateClass$8([
2110
2105
  uniform({ propKey: "outlineBuffer" }),
2111
- uiImage(
2112
- "Outline Buffer"
2113
- /* {readOnly: true}*/
2114
- )
2106
+ uiImage("Outline Buffer", { readOnly: true })
2115
2107
  ], OutlinePlugin.prototype, "texture", 2);
2116
- OutlinePlugin = __decorateClass$3([
2108
+ OutlinePlugin = __decorateClass$8([
2117
2109
  uiFolderContainer("Outline")
2118
2110
  ], OutlinePlugin);
2119
2111
  let OutlineRenderPass = class extends RenderPass {
@@ -2142,7 +2134,7 @@ let OutlineRenderPass = class extends RenderPass {
2142
2134
  */
2143
2135
  render(renderer, writeBuffer, _1, deltaTime, maskActive) {
2144
2136
  if (!this.scene || !this.camera) return;
2145
- const t = renderer.getRenderTarget();
2137
+ const t2 = renderer.getRenderTarget();
2146
2138
  const activeCubeFace = renderer.getActiveCubeFace();
2147
2139
  const activeMipLevel = renderer.getActiveMipmapLevel();
2148
2140
  const selectedObject = this._getSelectedObjectOrMaterial();
@@ -2156,7 +2148,7 @@ let OutlineRenderPass = class extends RenderPass {
2156
2148
  renderer.clear(true, true);
2157
2149
  renderer.setClearColor(color);
2158
2150
  }
2159
- renderer.setRenderTarget(t, activeCubeFace, activeMipLevel);
2151
+ renderer.setRenderTarget(t2, activeCubeFace, activeMipLevel);
2160
2152
  }
2161
2153
  _renderSelectedObject(renderer, selectedObject, writeBuffer, deltaTime, maskActive) {
2162
2154
  if (!this.camera) return;
@@ -2205,22 +2197,22 @@ let OutlineRenderPass = class extends RenderPass {
2205
2197
  camera.updateShaderProperties(this.overrideMaterial);
2206
2198
  }
2207
2199
  };
2208
- __decorateClass$3([
2200
+ __decorateClass$8([
2209
2201
  uiToggle("Enabled")
2210
2202
  ], OutlineRenderPass.prototype, "enabled", 2);
2211
- OutlineRenderPass = __decorateClass$3([
2203
+ OutlineRenderPass = __decorateClass$8([
2212
2204
  uiFolderContainer((c) => c.passId + " Render Pass")
2213
2205
  ], OutlineRenderPass);
2214
2206
  const ssgiPatch = "\n#if defined(SSRTAO_ENABLED) && SSRTAO_ENABLED > 0\nvec4 ssgi=tSSGIMapTexelToLinear(texture2D(tSSGIMap,viewToScreen(vViewPosition.xyz).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#endif\n";
2215
2207
  const ssrtaoShader = "uniform float sceneBoundingRadius;uniform float currentFrameCount;uniform float intensity;uniform float objectRadius;uniform float rayCount;uniform float power;uniform float bias;uniform float falloff;uniform float tolerance;uniform bool autoRadius;uniform vec2 screenSize;vec3 ComputeUniformL(vec3 N,vec2 E){vec3 L;L.xy=E;L.z=interleavedGradientNoise(gl_FragCoord.xy,currentFrameCount*5.);L=L*2.-1.;return L;}vec2 GetRandomE(float seed){vec2 rand_e;rand_e.x=random3(vec3(gl_FragCoord.xy,currentFrameCount+seed));rand_e.y=random3(vec3(gl_FragCoord.yx,rand_e.x+(currentFrameCount)*7.));return rand_e;}float saturate2(float v,float mx){return max(0.,min(mx,v));}vec4 calculateGI(in float seed,in vec3 screenPos,in vec3 normal,in float radiusFactor){vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);normal=normalize(normal);vec2 E=GetRandomE(seed);vec3 L=ComputeUniformL(normal,E);L=normalize(L);L*=sign(dot(L,normal));float cameraDist=length(cameraPositionWorld);float rayLen=objectRadius*sceneBoundingRadius;rayLen=autoRadius ?min(max(mix(max(0.0,(cameraDist+rayLen)+viewPos.z),max(0.0,-viewPos.z-max(0.0,cameraDist-rayLen)),L.z*0.5+0.5),rayLen*0.1),rayLen*5.):rayLen;rayLen*=radiusFactor;float r=interleavedGradientNoise(gl_FragCoord.xy,currentFrameCount*14.+seed)+0.05;rayLen=max(rayLen,0.001);vec3 state=vec3(1.,(r+0.5)/float(RTAO_STEP_COUNT),2.);viewPos+=normal*max(-0.01*viewPos.z,0.001);vec3 screenHitP=traceRay(viewPos,L*rayLen,tolerance*rayLen,state,RTAO_STEP_COUNT);vec3 viewHitP=screenToView3(screenHitP.xy,screenHitP.z);vec3 LRes=viewHitP-viewPos;if(state.z>1.)LRes=vec3(9999999.);float dist=length(LRes)*falloff;float EPS=0.01;float zBias=(viewPos.z)*bias;float ao=(max(dot(normal,L)+zBias,0.))/(dist*dist+EPS);\n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\nvec3 hitColor=tLastFrameTexelToLinear(texture2D(tLastFrame,screenHitP.xy)).rgb;vec3 hitNormal=getViewNormal(screenHitP.xy);float giWeight=1.;giWeight=saturate2(giWeight/(dist+EPS),1.);giWeight*=saturate2((dot(normal,L)),1.0);giWeight*=saturate2((dot(hitNormal,-L)),1.0);return vec4(hitColor*giWeight,ao);\n#endif\nreturn vec4(0,0,0,ao);}float normpdf(in float x,in float sigma){return exp(-0.5*x*x/(sigma*sigma));}vec4 getLastThis(sampler2D tex,float depth,vec3 normal){vec2 direction=vec2(1,1);vec4 color=clamp(tLastThisTexelToLinear(texture2D(tex,vUv.xy)),0.,5.);return color;}void main(){float depth;vec3 normal;getDepthNormal(vUv,depth,normal);if(depth>0.99){discard;gl_FragColor=getLastThis(tLastThis,depth,normal);return;}float viewZ=depthToViewZ(depth);vec3 screenPos=vec3(vUv.x,vUv.y,viewZ);vec4 gi=vec4(0.);gi+=calculateGI(8.,screenPos,normal,1.);if(rayCount>1.5)gi=max(gi,calculateGI(2.,screenPos,normal,0.4));if(rayCount>2.5)gi=max(gi,calculateGI(3.,screenPos,normal,1.5));if(rayCount>3.5)gi=max(gi,calculateGI(1.,screenPos,normal,0.6));if(rayCount>4.5)gi=max(gi,calculateGI(3.,screenPos,normal,1.));gi.a=min(1.,gi.a);gi.a=max(0.,gi.a);gi.rgb=min(vec3(3.),gi.rgb);gi.rgb=max(vec3(0.),gi.rgb);if(currentFrameCount<3.){gl_FragColor=gi;return;}gl_FragColor=(texture2D(tLastThis,vUv));gl_FragColor=((gi+(gl_FragColor)*currentFrameCount)/(currentFrameCount+1.));}";
2216
2208
  const ssaoBilateral = "uniform 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;}";
2217
- var __defProp$2 = Object.defineProperty;
2218
- var __decorateClass$2 = (decorators, target, key, kind) => {
2209
+ var __defProp$7 = Object.defineProperty;
2210
+ var __decorateClass$7 = (decorators, target, key, kind) => {
2219
2211
  var result = void 0;
2220
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
2221
- if (decorator = decorators[i])
2212
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
2213
+ if (decorator = decorators[i2])
2222
2214
  result = decorator(target, key, result) || result;
2223
- if (result) __defProp$2(target, key, result);
2215
+ if (result) __defProp$7(target, key, result);
2224
2216
  return result;
2225
2217
  };
2226
2218
  class BilateralFilterPass extends ExtendedShaderPass {
@@ -2251,13 +2243,13 @@ class BilateralFilterPass extends ExtendedShaderPass {
2251
2243
  this.needsSwap = false;
2252
2244
  }
2253
2245
  render(renderer, writeBuffer, _readBuffer, deltaTime, maskActive) {
2254
- var _a2, _b, _c, _d;
2246
+ var _a2, _b2, _c, _d;
2255
2247
  if (!this.enabled) return;
2256
2248
  const target = getOrCall(this.target);
2257
2249
  if (!target) return;
2258
2250
  this.uniforms.bilDirection.value.set(1, 0);
2259
2251
  this.uniforms.tDiffuse.value = target.texture;
2260
- this.uniforms.tDiffuseSize.value.set(((_a2 = this.uniforms.tDiffuse.value) == null ? void 0 : _a2.image.width) || 0, ((_b = this.uniforms.tDiffuse.value) == null ? void 0 : _b.image.height) || 0);
2252
+ this.uniforms.tDiffuseSize.value.set(((_a2 = this.uniforms.tDiffuse.value) == null ? void 0 : _a2.image.width) || 0, ((_b2 = this.uniforms.tDiffuse.value) == null ? void 0 : _b2.image.height) || 0);
2261
2253
  super.render(renderer, writeBuffer, target, deltaTime, maskActive);
2262
2254
  this.uniforms.bilDirection.value.set(0, 1);
2263
2255
  this.uniforms.tDiffuse.value = writeBuffer.texture;
@@ -2265,22 +2257,22 @@ class BilateralFilterPass extends ExtendedShaderPass {
2265
2257
  super.render(renderer, target, writeBuffer, deltaTime, maskActive);
2266
2258
  }
2267
2259
  }
2268
- __decorateClass$2([
2260
+ __decorateClass$7([
2269
2261
  serialize(),
2270
2262
  uniform()
2271
2263
  ], BilateralFilterPass.prototype, "smoothEnabled");
2272
- __decorateClass$2([
2264
+ __decorateClass$7([
2273
2265
  serialize(),
2274
2266
  uniform()
2275
2267
  ], BilateralFilterPass.prototype, "edgeSharpness");
2276
- var __defProp$1 = Object.defineProperty;
2268
+ var __defProp$6 = Object.defineProperty;
2277
2269
  var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
2278
- var __decorateClass$1 = (decorators, target, key, kind) => {
2270
+ var __decorateClass$6 = (decorators, target, key, kind) => {
2279
2271
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
2280
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
2281
- if (decorator = decorators[i])
2272
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
2273
+ if (decorator = decorators[i2])
2282
2274
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2283
- if (kind && result) __defProp$1(target, key, result);
2275
+ if (kind && result) __defProp$6(target, key, result);
2284
2276
  return result;
2285
2277
  };
2286
2278
  const passId = "ssrtgi";
@@ -2359,19 +2351,19 @@ let SSGIPlugin = class extends PipelinePassPlugin {
2359
2351
  return super.fromJSON(data, meta);
2360
2352
  }
2361
2353
  _beforeRender(_, _1, _2) {
2362
- var _a2, _b;
2354
+ var _a2, _b2;
2363
2355
  if (!this._viewer) return false;
2364
- const e = super._beforeRender(_, _1, _2);
2365
- if (e) {
2356
+ const e2 = super._beforeRender(_, _1, _2);
2357
+ if (e2) {
2366
2358
  const ssao = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin("SSAOPlugin");
2367
2359
  if (ssao && !ssao.isDisabled()) {
2368
2360
  ssao.disable(SSGIPlugin.PluginType);
2369
2361
  }
2370
2362
  }
2371
- if (!e) return e;
2363
+ if (!e2) return e2;
2372
2364
  const progressive = this._viewer.getPlugin(ProgressivePlugin);
2373
- (_b = this._pass) == null ? void 0 : _b.updateShaderProperties([progressive]);
2374
- return e;
2365
+ (_b2 = this._pass) == null ? void 0 : _b2.updateShaderProperties([progressive]);
2366
+ return e2;
2375
2367
  }
2376
2368
  /**
2377
2369
  * @deprecated use {@link target} instead
@@ -2383,16 +2375,13 @@ let SSGIPlugin = class extends PipelinePassPlugin {
2383
2375
  };
2384
2376
  SSGIPlugin.PluginType = "SSGIPlugin";
2385
2377
  SSGIPlugin.OldPluginType = "SSGI";
2386
- __decorateClass$1([
2387
- uiImage(
2388
- "SSGI Buffer"
2389
- /* {readOnly: true}*/
2390
- )
2378
+ __decorateClass$6([
2379
+ uiImage("SSGI Buffer", { readOnly: true })
2391
2380
  ], SSGIPlugin.prototype, "texture", 2);
2392
- __decorateClass$1([
2381
+ __decorateClass$6([
2393
2382
  uiConfig()
2394
2383
  ], SSGIPlugin.prototype, "_pass", 2);
2395
- SSGIPlugin = __decorateClass$1([
2384
+ SSGIPlugin = __decorateClass$6([
2396
2385
  uiFolderContainer("SSGI Plugin")
2397
2386
  ], SSGIPlugin);
2398
2387
  let SSGIPluginPass = class extends ExtendedShaderPass {
@@ -2470,7 +2459,7 @@ ${ssrtaoShader}
2470
2459
  this.autoRadius = true;
2471
2460
  this.objectRadius = 1;
2472
2461
  this.tolerance = 1;
2473
- this.bias = 0.015;
2462
+ this.bias = 1e-3;
2474
2463
  this.falloff = 0.7;
2475
2464
  this.rayCount = 4;
2476
2465
  this.stepCount = 8;
@@ -2517,8 +2506,8 @@ ${ssrtaoShader}
2517
2506
  shader.fragmentShader = shaderReplaceString(shader.fragmentShader, "#include <aomap_fragment>", "");
2518
2507
  },
2519
2508
  onObjectRender: (_object, material, renderer) => {
2520
- var _a2, _b, _c;
2521
- let x = this.enabled && (this.renderWithCamera || renderer.renderManager.frameCount > 1) && renderer.userData.screenSpaceRendering !== false && !((_a2 = material.userData) == null ? void 0 : _a2.pluginsDisabled) && !((_b = material.userData) == null ? void 0 : _b.ssrtaoDisabled) && !((_c = material.userData) == null ? void 0 : _c.ssaoDisabled) ? 1 : 0;
2509
+ var _a2, _b2, _c;
2510
+ let x = this.enabled && (this.renderWithCamera || renderer.renderManager.frameCount > 1) && renderer.userData.screenSpaceRendering !== false && !((_a2 = material.userData) == null ? void 0 : _a2.pluginsDisabled) && !((_b2 = material.userData) == null ? void 0 : _b2.ssrtaoDisabled) && !((_c = material.userData) == null ? void 0 : _c.ssaoDisabled) ? 1 : 0;
2522
2511
  if (material.defines.SSRTAO_ENABLED !== x) {
2523
2512
  material.defines.SSRTAO_ENABLED = x;
2524
2513
  material.needsUpdate = true;
@@ -2645,84 +2634,84 @@ ${ssrtaoShader}
2645
2634
  }
2646
2635
  // todo update gbuffer flag like in AO?
2647
2636
  setDirty() {
2648
- var _a2, _b;
2649
- (_b = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b.call(_a2);
2637
+ var _a2, _b2;
2638
+ (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
2650
2639
  super.setDirty();
2651
2640
  }
2652
2641
  };
2653
- __decorateClass$1([
2642
+ __decorateClass$6([
2654
2643
  serialize()
2655
2644
  ], SSGIPluginPass.prototype, "bilateralPass", 2);
2656
- __decorateClass$1([
2645
+ __decorateClass$6([
2657
2646
  uiToggle("GI Enabled"),
2658
2647
  serialize(),
2659
2648
  matDefineBool("SSGI_ENABLED", void 0, void 0, SSGIPluginPass.prototype.setDirty, false)
2660
2649
  ], SSGIPluginPass.prototype, "giEnabled", 2);
2661
- __decorateClass$1([
2650
+ __decorateClass$6([
2662
2651
  uiSlider("Intensity", [0, 4]),
2663
2652
  serialize(),
2664
2653
  uniform()
2665
2654
  ], SSGIPluginPass.prototype, "intensity", 2);
2666
- __decorateClass$1([
2655
+ __decorateClass$6([
2667
2656
  uiSlider("Power", [0, 3]),
2668
2657
  serialize(),
2669
2658
  uniform()
2670
2659
  ], SSGIPluginPass.prototype, "power", 2);
2671
- __decorateClass$1([
2660
+ __decorateClass$6([
2672
2661
  uiToggle("Auto radius"),
2673
2662
  serialize(),
2674
2663
  uniform()
2675
2664
  ], SSGIPluginPass.prototype, "autoRadius", 2);
2676
- __decorateClass$1([
2665
+ __decorateClass$6([
2677
2666
  uiSlider("Object Radius", [0.01, 10]),
2678
2667
  serialize(),
2679
2668
  uniform()
2680
2669
  ], SSGIPluginPass.prototype, "objectRadius", 2);
2681
- __decorateClass$1([
2670
+ __decorateClass$6([
2682
2671
  uiSlider("Tolerance", [0.1, 5]),
2683
2672
  serialize(),
2684
2673
  uniform()
2685
2674
  ], SSGIPluginPass.prototype, "tolerance", 2);
2686
- __decorateClass$1([
2675
+ __decorateClass$6([
2687
2676
  uiSlider("Bias", [-0.3, 0.3]),
2688
2677
  serialize(),
2689
2678
  uniform()
2690
2679
  ], SSGIPluginPass.prototype, "bias", 2);
2691
- __decorateClass$1([
2680
+ __decorateClass$6([
2692
2681
  uiSlider("Falloff", [1e-4, 4]),
2693
2682
  serialize(),
2694
2683
  uniform()
2695
2684
  ], SSGIPluginPass.prototype, "falloff", 2);
2696
- __decorateClass$1([
2685
+ __decorateClass$6([
2697
2686
  uiSlider("Ray Count", [1, 5], 1),
2698
2687
  serialize(),
2699
2688
  uniform()
2700
2689
  ], SSGIPluginPass.prototype, "rayCount", 2);
2701
- __decorateClass$1([
2690
+ __decorateClass$6([
2702
2691
  uiSlider("Step count", [1, 16], 1),
2703
2692
  serialize(),
2704
2693
  matDefine("RTAO_STEP_COUNT", void 0, void 0, SSGIPluginPass.prototype.setDirty)
2705
2694
  ], SSGIPluginPass.prototype, "stepCount", 2);
2706
- __decorateClass$1([
2695
+ __decorateClass$6([
2707
2696
  uiToggle("Smooth Enabled"),
2708
2697
  serialize()
2709
2698
  ], SSGIPluginPass.prototype, "smoothEnabled", 2);
2710
- __decorateClass$1([
2699
+ __decorateClass$6([
2711
2700
  uiToggle("Render with Camera")
2712
2701
  ], SSGIPluginPass.prototype, "renderWithCamera", 2);
2713
- SSGIPluginPass = __decorateClass$1([
2702
+ SSGIPluginPass = __decorateClass$6([
2714
2703
  uiFolderContainer("SSGI Pass")
2715
2704
  ], SSGIPluginPass);
2716
2705
  const anisotropyBsdf = "uniform float anisotropyFactor;uniform float anisotropyNoise;\n#if ANISOTROPY_TEX_MODE == 0\nuniform float anisotropyDirection;\n#else\nuniform sampler2D anisotropyDirectionMap;varying vec2 vAnisotropy2MapUv;\n#endif\nconst float MIN_ROUGHNESS=0.05;vec3 indirectAnisotropyBentNormal(const in vec3 normal,const in vec3 viewDir,const in float roughness,const in vec3 anisotropicT,const in vec3 anisotropicB){vec3 aDirection=anisotropyFactor>=0.0 ? anisotropicB : anisotropicT;vec3 aTangent=cross(aDirection,viewDir);vec3 aNormal=cross(aTangent,aDirection);float bendFactor=abs(anisotropyFactor)*saturate(5.0*max(roughness,MIN_ROUGHNESS));return normalize(mix(normal,aNormal,bendFactor));}vec3 BRDF_GGX_Anisotropy(const in vec3 lightDir,const in vec3 viewDir,const in vec3 normal,const in vec3 f0,const in float f90,const in float roughness,const in vec3 anisotropicT,const in vec3 anisotropicB){float alpha=pow2(roughness);vec3 halfDir=normalize(lightDir+viewDir);float dotNL=saturate(dot(normal,lightDir));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float dotVH=saturate(dot(viewDir,halfDir));float dotTV=dot(anisotropicT,viewDir);float dotBV=dot(anisotropicB,viewDir);float dotTL=dot(anisotropicT,lightDir);float dotBL=dot(anisotropicB,lightDir);float dotTH=dot(anisotropicT,halfDir);float dotBH=dot(anisotropicB,halfDir);float aspect=sqrt(1.0-min(1.-MIN_ROUGHNESS,abs(anisotropyFactor)*0.9));if(anisotropyFactor>0.0)aspect=1.0/aspect;float at=roughness*aspect;float ab=roughness/aspect;vec3 F=F_Schlick(f0,f90,dotVH);float V=V_GGX_SmithCorrelated_Anisotropic(at,ab,dotTV,dotBV,dotTL,dotBL,dotNV,dotNL);float D=D_GGX_Anisotropic(at,ab,dotTH,dotBH,dotNH);return F*(V*D);}";
2717
2706
  const anisotropyTBN = "float rnd=(random2(vUv.xy,frameCount)-0.5)*anisotropyNoise*material.roughness;\n#if ANISOTROPY_TEX_MODE < 2\n#if ANISOTROPY_TEX_MODE == 0\nfloat rot=saturate(anisotropyDirection);\n#else\nfloat rot=(anisotropyDirectionMapTexelToLinear(texture2D(anisotropyDirectionMap,vAnisotropy2MapUv)).r);\n#endif\nrot=rot*2.*PI+rnd;vec2 rot2=vec2(sin(rot),cos(rot));\n#else\nvec2 rot2=(anisotropyDirectionMapTexelToLinear(texture2D(anisotropyDirectionMap,vAnisotropy2MapUv)).rg*2.-1.)+vec2(rnd,rnd);rot2=normalize(rot2);const float anisoSpecMultiplier=0.25;float matSpecAniso=(length(material.specularColor.rgb))*2.*PI;rot2=mix(rot2,vec2(sin(matSpecAniso),cos(matSpecAniso)),anisoSpecMultiplier);rot2=normalize(rot2);\n#endif\nvec3 anisotropicT=(tbn[0]*rot2.x+tbn[1]*rot2.y);anisotropicT=normalize(anisotropicT-normal*dot(anisotropicT,normal));vec3 anisotropicB=normalize(cross(normal,anisotropicT));";
2718
- var __defProp = Object.defineProperty;
2707
+ var __defProp$5 = Object.defineProperty;
2719
2708
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2720
- var __decorateClass = (decorators, target, key, kind) => {
2709
+ var __decorateClass$5 = (decorators, target, key, kind) => {
2721
2710
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
2722
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
2723
- if (decorator = decorators[i])
2711
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
2712
+ if (decorator = decorators[i2])
2724
2713
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2725
- if (kind && result) __defProp(target, key, result);
2714
+ if (kind && result) __defProp$5(target, key, result);
2726
2715
  return result;
2727
2716
  };
2728
2717
  let AnisotropyPlugin = class extends AViewerPluginSync {
@@ -2835,17 +2824,17 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2835
2824
  shader.vertexTangents = true;
2836
2825
  },
2837
2826
  onObjectRender: (object, material) => {
2838
- var _a2;
2827
+ var _a2, _b2;
2839
2828
  const userData = material.userData;
2840
2829
  if (!(userData == null ? void 0 : userData._isAnisotropic)) return;
2841
2830
  if (!object.isMesh || !object.geometry) return;
2842
2831
  if (!object.geometry.attributes.tangent) {
2843
- throw new Error("AnisotropyPlugin: No tangents on the geometry");
2832
+ (_a2 = this._viewer) == null ? void 0 : _a2.console.error("AnisotropyPlugin - No tangents on the geometry, cannot use anisotropy. Make sure the tangents are computed before rendering the model. The model will render as black.", object);
2844
2833
  }
2845
2834
  this._uniforms.anisotropyFactor.value = userData._anisotropyFactor ?? 1;
2846
2835
  this._uniforms.anisotropyNoise.value = userData._anisotropyNoise ?? 0;
2847
2836
  this._uniforms.anisotropyDirection.value = userData._anisotropyDirection ?? 1;
2848
- const tex = ((_a2 = userData._anisotropyDirectionMap) == null ? void 0 : _a2.isTexture) ? userData._anisotropyDirectionMap : null;
2837
+ const tex = ((_b2 = userData._anisotropyDirectionMap) == null ? void 0 : _b2.isTexture) ? userData._anisotropyDirectionMap : null;
2849
2838
  this._uniforms.anisotropyDirectionMap.value = tex;
2850
2839
  if (tex) {
2851
2840
  tex.updateMatrix();
@@ -2862,8 +2851,8 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2862
2851
  // ...this._uniforms, // done in constructor
2863
2852
  },
2864
2853
  computeCacheKey: (material1) => {
2865
- var _a2, _b, _c;
2866
- return (this.enabled ? "1" : "0") + (((_a2 = material1.userData) == null ? void 0 : _a2._isAnisotropic) ? "1" : "0") + ((_c = (_b = material1.userData) == null ? void 0 : _b._anisotropyDirectionMap) == null ? void 0 : _c.uuid);
2854
+ var _a2, _b2, _c;
2855
+ return (this.enabled ? "1" : "0") + (((_a2 = material1.userData) == null ? void 0 : _a2._isAnisotropic) ? "1" : "0") + ((_c = (_b2 = material1.userData) == null ? void 0 : _b2._anisotropyDirectionMap) == null ? void 0 : _c.uuid);
2867
2856
  },
2868
2857
  isCompatible: (material1) => material1.isPhysicalMaterial,
2869
2858
  updaters: () => {
@@ -2960,11 +2949,32 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2960
2949
  ]
2961
2950
  };
2962
2951
  return config;
2952
+ },
2953
+ // todo errors will be fixed on threepipe update
2954
+ onMaterialUpdate: (material) => {
2955
+ var _a2, _b2;
2956
+ if (!((_a2 = material.userData) == null ? void 0 : _a2._isAnisotropic)) return;
2957
+ (_b2 = material.userData.__appliedMeshes) == null ? void 0 : _b2.forEach((m) => this.tryComputeTangents(m, [material]));
2958
+ },
2959
+ onRegister: (material) => {
2960
+ var _a2, _b2;
2961
+ if (!((_a2 = material.userData) == null ? void 0 : _a2._isAnisotropic)) return;
2962
+ (_b2 = material.userData.__appliedMeshes) == null ? void 0 : _b2.forEach((m) => this.tryComputeTangents(m, [material]));
2963
+ },
2964
+ onAddToMesh: (mesh) => {
2965
+ if (!mesh.isMesh) return;
2966
+ const m = mesh;
2967
+ const mats = Array.isArray(m.material) ? m.material : [m.material];
2968
+ if (!mats.find((m1) => {
2969
+ var _a2;
2970
+ return (_a2 = m1 == null ? void 0 : m1.userData) == null ? void 0 : _a2._isAnisotropic;
2971
+ })) return;
2972
+ this.tryComputeTangents(m, mats);
2963
2973
  }
2964
2974
  };
2965
2975
  this.setDirty = () => {
2966
- var _a2, _b, _c;
2967
- (_b = (_a2 = this.materialExtension).setDirty) == null ? void 0 : _b.call(_a2);
2976
+ var _a2, _b2, _c;
2977
+ (_b2 = (_a2 = this.materialExtension).setDirty) == null ? void 0 : _b2.call(_a2);
2968
2978
  (_c = this._viewer) == null ? void 0 : _c.setDirty();
2969
2979
  };
2970
2980
  Object.assign(this.materialExtension.extraUniforms, this._uniforms);
@@ -2997,6 +3007,19 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2997
3007
  if (material.setDirty) material.setDirty();
2998
3008
  return true;
2999
3009
  }
3010
+ tryComputeTangents(m, mats) {
3011
+ if (m.geometry && !m.geometry.attributes.tangent) {
3012
+ let possible = true;
3013
+ if (!m.geometry.index || !m.geometry.attributes.position || !m.geometry.attributes.normal || !m.geometry.attributes.uv) {
3014
+ possible = false;
3015
+ }
3016
+ if (possible) m.geometry.computeTangents();
3017
+ else mats.map((m1) => {
3018
+ var _a2;
3019
+ if ((_a2 = m1 == null ? void 0 : m1.userData) == null ? void 0 : _a2._isAnisotropic) m1.userData._isAnisotropic = false;
3020
+ });
3021
+ }
3022
+ }
3000
3023
  onAdded(v) {
3001
3024
  super.onAdded(v);
3002
3025
  v.assetManager.materials.registerMaterialExtension(this.materialExtension);
@@ -3018,11 +3041,11 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
3018
3041
  };
3019
3042
  AnisotropyPlugin.PluginType = "AnisotropyPlugin";
3020
3043
  AnisotropyPlugin.ANISOTROPY_GLTF_EXTENSION = "WEBGI_materials_anisotropy";
3021
- __decorateClass([
3044
+ __decorateClass$5([
3022
3045
  uiToggle("Enabled", (that) => ({ onChange: that.setDirty })),
3023
3046
  serialize()
3024
3047
  ], AnisotropyPlugin.prototype, "enabled", 2);
3025
- AnisotropyPlugin = __decorateClass([
3048
+ AnisotropyPlugin = __decorateClass$5([
3026
3049
  uiFolderContainer("Anisotropy (MatExt)")
3027
3050
  ], AnisotropyPlugin);
3028
3051
  class GLTFMaterialsAnisotropyExtensionImport {
@@ -3047,8 +3070,8 @@ class GLTFMaterialsAnisotropyExtensionImport {
3047
3070
  if (!anisotropyDirection) anisotropyDirection = extension.anisotropyRotation;
3048
3071
  materialParams.userData._anisotropyDirectionMode = anisotropyDirectionMode && typeof (anisotropyDirection == null ? void 0 : anisotropyDirection.index) === "number" ? anisotropyDirectionMode : "CONSTANT";
3049
3072
  if (anisotropyDirectionMode === "ROTATION" || anisotropyDirectionMode === "DIRECTION") {
3050
- pending.push(parser.assignTexture(materialParams.userData, "_anisotropyDirectionMap", anisotropyDirection).then((t) => {
3051
- t.colorSpace = SRGBColorSpace;
3073
+ pending.push(parser.assignTexture(materialParams.userData, "_anisotropyDirectionMap", anisotropyDirection).then((t2) => {
3074
+ t2.colorSpace = SRGBColorSpace;
3052
3075
  }));
3053
3076
  } else {
3054
3077
  materialParams.userData._anisotropyDirection = anisotropyDirection ?? 0;
@@ -3058,8 +3081,8 @@ class GLTFMaterialsAnisotropyExtensionImport {
3058
3081
  afterRoot(result) {
3059
3082
  var _a2;
3060
3083
  (_a2 = result.scene) == null ? void 0 : _a2.traverse((object) => {
3061
- var _a3, _b;
3062
- const mat = (_b = (_a3 = object.material) == null ? void 0 : _a3.userData) == null ? void 0 : _b._isAnisotropic;
3084
+ var _a3, _b2;
3085
+ const mat = (_b2 = (_a3 = object.material) == null ? void 0 : _a3.userData) == null ? void 0 : _b2._isAnisotropic;
3063
3086
  if (!mat) return;
3064
3087
  const geom = object.geometry;
3065
3088
  if (!geom.attributes.tangent) {
@@ -3079,7 +3102,7 @@ const glTFMaterialsAnisotropyExtensionExport = (w) => ({
3079
3102
  extensionDef.anisotropyFactor = material.userData._anisotropyFactor || 1;
3080
3103
  extensionDef.anisotropyNoiseFactor = material.userData._anisotropyNoise || 0;
3081
3104
  extensionDef.anisotropyDirectionMode = material.userData._anisotropyDirectionMode || "CONSTANT";
3082
- if (material.userData._anisotropyDirectionMap && extensionDef.anisotropyDirectionMode !== "CONSTANT") {
3105
+ if (w.checkEmptyMap(material.userData._anisotropyDirectionMap) && extensionDef.anisotropyDirectionMode !== "CONSTANT") {
3083
3106
  const anisotropyDirectionMapDef = { index: w.processTexture(material.userData._anisotropyDirectionMap) };
3084
3107
  w.applyTextureTransform(anisotropyDirectionMapDef, material.userData._anisotropyDirectionMap);
3085
3108
  extensionDef.anisotropyDirection = anisotropyDirectionMapDef;
@@ -3099,6 +3122,1348 @@ const anisotropyGLTFExtension = {
3099
3122
  anisotropyDirection: "RGB"
3100
3123
  }
3101
3124
  };
3125
+ const poissonDiskSamples = "vec2 poisson_disk_samples[16];void setPds(){poisson_disk_samples[0]=vec2(-0.399691779231,0.728591545584);poisson_disk_samples[1]=vec2(-0.48622557676,-0.84016533712);poisson_disk_samples[2]=vec2(0.770309468987,-0.24906070432);poisson_disk_samples[3]=vec2(0.556596796154,0.820359876432);poisson_disk_samples[4]=vec2(-0.933902004071,0.0600539051593);poisson_disk_samples[5]=vec2(0.330144964342,0.207477293384);poisson_disk_samples[6]=vec2(0.289013230975,-0.686749271417);poisson_disk_samples[7]=vec2(-0.0832470893559,-0.187351643125);poisson_disk_samples[8]=vec2(-0.296314525615,0.254474834305);poisson_disk_samples[9]=vec2(-0.850977666059,0.484642744689);poisson_disk_samples[10]=vec2(0.829287915319,0.2345063545);poisson_disk_samples[11]=vec2(-0.773042143899,-0.543741521254);poisson_disk_samples[12]=vec2(0.0561133030864,0.928419742597);poisson_disk_samples[13]=vec2(-0.205799249508,-0.562072714492);poisson_disk_samples[14]=vec2(-0.526991665882,-0.193690188118);poisson_disk_samples[15]=vec2(-0.051789270667,-0.935374050821);}";
3126
+ const reflectorSample = "\n#include <randomHelpers>\n#ifndef D_sceneBoundingRadius\n#define D_sceneBoundingRadius\nuniform float sceneBoundingRadius;\n#endif\n#ifndef D_frameCount\n#define D_frameCount\nuniform float frameCount;\n#endif\nvarying vec4 vRefUv;uniform sampler2D tRefDiffuse;uniform vec2 tRefDiffuseSize;float getSpecularMIPLevel(const in float roughness,const in float maxMIPLevel){float sigma=PI*roughness*roughness/(1.0+roughness);float desiredMIPLevel=maxMIPLevel+log2(sigma);return clamp(desiredMIPLevel,0.0,maxMIPLevel);}vec4 getReflectionColor(const in float roughness,const in float depthModifier){float mip=getSpecularMIPLevel(roughness+depthModifier,4.0);vec4 color=texture2D(tRefDiffuse,vRefUv.xy/vRefUv.w,mip);float blurDist=saturate(2.0/(1.+pow(abs(vViewPosition.z),0.25)))*roughness*64.*color.a;float rnd=PI2*interleavedGradientNoise(vUv.xy,frameCount);vec4 rotationMatrix=vec4(cos(rnd),-sin(rnd),0.,0.);rotationMatrix.z=-rotationMatrix.y;rotationMatrix.w=rotationMatrix.x;vec3 colorSum=color.rgb*color.a;float weightSum=0.001+color.a;vec2 ofs;setPds();\n#pragma unroll_loop_start\nfor(int i=0;i<16;i++){ofs=poisson_disk_samples[UNROLLED_LOOP_INDEX];ofs=vec2(dot(ofs,rotationMatrix.xy),dot(ofs,rotationMatrix.zw));ofs=vRefUv.xy+vRefUv.w*blurDist*ofs/tRefDiffuseSize.xy;color=texture2D(tRefDiffuse,ofs/vRefUv.w,mip);colorSum+=color.rgb*color.a;weightSum+=color.a;}\n#pragma unroll_loop_end\nreturn vec4(colorSum/weightSum,1.0);}";
3127
+ var __defProp$4 = Object.defineProperty;
3128
+ var __decorateClass$4 = (decorators, target, key, kind) => {
3129
+ var result = void 0;
3130
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
3131
+ if (decorator = decorators[i2])
3132
+ result = decorator(target, key, result) || result;
3133
+ if (result) __defProp$4(target, key, result);
3134
+ return result;
3135
+ };
3136
+ const _Reflector2 = class _Reflector22 extends Mesh2 {
3137
+ constructor(geometry, renderTarget, clipBias = 0, material) {
3138
+ super(geometry, material);
3139
+ this.type = "Reflector";
3140
+ this.isReflector2 = true;
3141
+ this.enabled = true;
3142
+ this.reflectorModePhysical = true;
3143
+ this.reflectionTargetNeedsUpdate = true;
3144
+ this.transparentReflectionBackground = true;
3145
+ this.materialExtension = {
3146
+ extraUniforms: {
3147
+ // tRefDepth: {value: null},
3148
+ tRefDiffuse: { value: null },
3149
+ tRefDiffuseSize: { value: new Vector2() },
3150
+ refTextureMatrix: { value: new Matrix4() },
3151
+ frameCount: { value: 0 },
3152
+ sceneBoundingRadius: { value: 0 }
3153
+ },
3154
+ extraDefines: {
3155
+ // eslint-disable-next-line @typescript-eslint/naming-convention
3156
+ USE_UV: ""
3157
+ },
3158
+ updaters: [],
3159
+ shaderExtender: (shader, _material, _renderer) => {
3160
+ if (this.enabled) {
3161
+ shader.vertexShader = shaderReplaceString(shader.vertexShader, "void main() {", "void main() {\nvRefUv = refTextureMatrix * vec4( position, 1.0 );");
3162
+ const ls = "#glMarker beforeModulation";
3163
+ shader.fragmentShader = shaderReplaceString(shader.fragmentShader, ls, `
3164
+ if(roughnessFactor < 0.95) {
3165
+ float d = 0.;//textureProj(tRefDepth, vRefUv).r;
3166
+ // d = min(2., max(0., (d-0.06) * ((7./3.-ior)) * sceneBoundingRadius));
3167
+ vec4 refBaseColor = getReflectionColor(material.roughness, material.roughness * d);
3168
+ // refBaseColor.rgb = vec3(refBaseColor.a);
3169
+ // refBaseColor.a *= 1.0 - clamp(material.roughness * .3, 0., 1.);
3170
+ ` + (this.reflectorModePhysical ? `
3171
+ #if !defined(SSR_ENABLED) || SSR_ENABLED < 1
3172
+ vec3 specularColor = EnvironmentBRDF(geometryNormal, geometryViewDir, material.specularColor.rgb, material.specularF90, material.roughness);
3173
+ #endif
3174
+ reflectedLight.indirectSpecular = mix(vec3(reflectedLight.indirectSpecular), saturate(specularColor.rgb * refBaseColor.rgb), refBaseColor.a);
3175
+ ` : `
3176
+ reflectedLight.indirectSpecular = saturate(diffuseColor.rgb * refBaseColor.rgb);
3177
+ diffuseColor.a *= refBaseColor.a;
3178
+ `) + "}\n" + ls);
3179
+ }
3180
+ },
3181
+ parsVertexSnippet: () => !this.enabled ? "" : `
3182
+ uniform mat4 refTextureMatrix;
3183
+ varying vec4 vRefUv;
3184
+ `,
3185
+ parsFragmentSnippet: () => this.enabled ? poissonDiskSamples + "\n" + reflectorSample : "",
3186
+ computeCacheKey: (material2) => {
3187
+ return this.enabled + " " + material2.transparent + " " + this.reflectorModePhysical + " ";
3188
+ },
3189
+ onObjectRender: (_object, material2) => {
3190
+ if (material2.userData.__lastTransparent !== material2.transparent) {
3191
+ material2.needsUpdate = true;
3192
+ material2.userData.__lastTransparent = material2.transparent;
3193
+ }
3194
+ },
3195
+ isCompatible: (material2) => {
3196
+ return material2.isPhysicalMaterial;
3197
+ },
3198
+ setDirty: () => {
3199
+ var _a2, _b2;
3200
+ return (_b2 = (_a2 = this.materialExtension).__setDirty) == null ? void 0 : _b2.call(_a2);
3201
+ }
3202
+ };
3203
+ this._renderTarget = renderTarget;
3204
+ const reflectorPlane = new Plane();
3205
+ const normal = new Vector3();
3206
+ const reflectorWorldPosition = new Vector3();
3207
+ const cameraWorldPosition = new Vector3();
3208
+ const rotationMatrix = new Matrix4();
3209
+ const lookAtPosition = new Vector3(0, 0, -1);
3210
+ const clipPlane = new Vector4();
3211
+ const view = new Vector3();
3212
+ const target = new Vector3();
3213
+ const q = new Vector4();
3214
+ const textureMatrix = new Matrix4();
3215
+ const virtualCamera = new PerspectiveCamera();
3216
+ this.onBeforeRender = (renderer, scene, camera) => {
3217
+ if (!this.enabled || !renderer.userData.mainRenderPass) return;
3218
+ if (!this.reflectionTargetNeedsUpdate) {
3219
+ return;
3220
+ }
3221
+ const thisRenderTarget = this._getRenderTarget();
3222
+ if (!thisRenderTarget) {
3223
+ console.warn("Reflector2: No render target set.");
3224
+ return;
3225
+ }
3226
+ const viewOffset = camera.view ? Object.assign({}, camera.view) : null;
3227
+ viewOffset && camera.clearViewOffset && camera.clearViewOffset();
3228
+ reflectorWorldPosition.setFromMatrixPosition(this.matrixWorld);
3229
+ cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
3230
+ rotationMatrix.extractRotation(this.matrixWorld);
3231
+ normal.set(0, 0, 1);
3232
+ normal.applyMatrix4(rotationMatrix);
3233
+ view.subVectors(reflectorWorldPosition, cameraWorldPosition);
3234
+ if (view.dot(normal) > 0) return;
3235
+ view.reflect(normal).negate();
3236
+ view.add(reflectorWorldPosition);
3237
+ rotationMatrix.extractRotation(camera.matrixWorld);
3238
+ lookAtPosition.set(0, 0, -1);
3239
+ lookAtPosition.applyMatrix4(rotationMatrix);
3240
+ lookAtPosition.add(cameraWorldPosition);
3241
+ target.subVectors(reflectorWorldPosition, lookAtPosition);
3242
+ target.reflect(normal).negate();
3243
+ target.add(reflectorWorldPosition);
3244
+ virtualCamera.position.copy(view);
3245
+ virtualCamera.up.set(0, 1, 0);
3246
+ virtualCamera.up.applyMatrix4(rotationMatrix);
3247
+ virtualCamera.up.reflect(normal);
3248
+ virtualCamera.lookAt(target);
3249
+ virtualCamera.far = 2;
3250
+ virtualCamera.near = 0;
3251
+ virtualCamera.updateMatrixWorld();
3252
+ virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
3253
+ textureMatrix.set(
3254
+ 0.5,
3255
+ 0,
3256
+ 0,
3257
+ 0.5,
3258
+ 0,
3259
+ 0.5,
3260
+ 0,
3261
+ 0.5,
3262
+ 0,
3263
+ 0,
3264
+ 0.5,
3265
+ 0.5,
3266
+ 0,
3267
+ 0,
3268
+ 0,
3269
+ 1
3270
+ );
3271
+ textureMatrix.multiply(virtualCamera.projectionMatrix);
3272
+ textureMatrix.multiply(virtualCamera.matrixWorldInverse);
3273
+ textureMatrix.multiply(this.matrixWorld);
3274
+ reflectorPlane.setFromNormalAndCoplanarPoint(normal, reflectorWorldPosition);
3275
+ reflectorPlane.applyMatrix4(virtualCamera.matrixWorldInverse);
3276
+ clipPlane.set(reflectorPlane.normal.x, reflectorPlane.normal.y, reflectorPlane.normal.z, reflectorPlane.constant);
3277
+ const projectionMatrix = virtualCamera.projectionMatrix;
3278
+ q.x = (Math.sign(clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
3279
+ q.y = (Math.sign(clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
3280
+ q.z = -1;
3281
+ q.w = (1 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
3282
+ clipPlane.multiplyScalar(2 / clipPlane.dot(q));
3283
+ projectionMatrix.elements[2] = clipPlane.x;
3284
+ projectionMatrix.elements[6] = clipPlane.y;
3285
+ projectionMatrix.elements[10] = clipPlane.z + 1 - clipBias;
3286
+ projectionMatrix.elements[14] = clipPlane.w;
3287
+ this.visible = false;
3288
+ const currentRenderTarget = renderer.getRenderTarget();
3289
+ const currentXrEnabled = renderer.xr.enabled;
3290
+ const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
3291
+ renderer.xr.enabled = false;
3292
+ renderer.shadowMap.autoUpdate = false;
3293
+ renderer.setRenderTarget(thisRenderTarget);
3294
+ renderer.state.buffers.depth.setMask(true);
3295
+ if (renderer.autoClear === false) renderer.clear();
3296
+ const sceneBackground = scene.background;
3297
+ if (this.transparentReflectionBackground) scene.background = null;
3298
+ const renderBackground = !this.transparentReflectionBackground;
3299
+ if ((sceneBackground == null ? void 0 : sceneBackground.isTexture) && renderBackground) {
3300
+ if (!sceneBackground.userData) sceneBackground.userData = {};
3301
+ sceneBackground.userData.flipX = !sceneBackground.userData.flipX;
3302
+ }
3303
+ renderer.renderWithModes({
3304
+ shadowMapRender: false,
3305
+ backgroundRender: renderBackground,
3306
+ opaqueRender: true,
3307
+ transparentRender: true,
3308
+ transmissionRender: false,
3309
+ // todo: render transmissive objects somehow
3310
+ screenSpaceRendering: false
3311
+ }, () => renderer.render(scene, virtualCamera));
3312
+ if ((sceneBackground == null ? void 0 : sceneBackground.isTexture) && renderBackground) {
3313
+ sceneBackground.userData.flipX = !sceneBackground.userData.flipX || void 0;
3314
+ }
3315
+ if (this.transparentReflectionBackground) scene.background = sceneBackground;
3316
+ renderer.xr.enabled = currentXrEnabled;
3317
+ renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
3318
+ renderer.setRenderTarget(currentRenderTarget);
3319
+ if ((viewOffset == null ? void 0 : viewOffset.enabled) && camera.setViewOffset)
3320
+ camera.setViewOffset(viewOffset.fullWidth, viewOffset.fullHeight, viewOffset.offsetX, viewOffset.offsetY, viewOffset.width, viewOffset.height);
3321
+ const viewport = camera.viewport;
3322
+ if (viewport !== void 0) {
3323
+ renderer.state.viewport(viewport);
3324
+ }
3325
+ this.visible = true;
3326
+ this.reflectionTargetNeedsUpdate = false;
3327
+ };
3328
+ this.textureMatrix = textureMatrix;
3329
+ this.materialExtension.extraUniforms.refTextureMatrix.value = textureMatrix;
3330
+ }
3331
+ _getRenderTarget() {
3332
+ const target = getOrCall(this._renderTarget);
3333
+ if (target) {
3334
+ if (target.texture.generateMipmaps && (!MathUtils.isPowerOfTwo(target.texture.image.width) || !MathUtils.isPowerOfTwo(target.texture.image.height)))
3335
+ target.texture.generateMipmaps = false;
3336
+ this.materialExtension.extraUniforms.tRefDiffuse.value = target.texture;
3337
+ this.materialExtension.extraUniforms.tRefDiffuseSize.value.set(target.width, target.height);
3338
+ }
3339
+ return target;
3340
+ }
3341
+ // todo change to reflectBackground or something
3342
+ _updateExtension() {
3343
+ var _a2, _b2;
3344
+ this.transparentReflectionBackground = this.reflectorModePhysical;
3345
+ (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
3346
+ }
3347
+ getRenderTarget() {
3348
+ return this._renderTarget;
3349
+ }
3350
+ };
3351
+ __decorateClass$4([
3352
+ onChange(_Reflector2.prototype._updateExtension)
3353
+ ], _Reflector2.prototype, "enabled");
3354
+ __decorateClass$4([
3355
+ onChange(_Reflector2.prototype._updateExtension)
3356
+ ], _Reflector2.prototype, "reflectorModePhysical");
3357
+ let Reflector2 = _Reflector2;
3358
+ Reflector2.prototype.isReflector = true;
3359
+ class e {
3360
+ static _xfnv1a(e2) {
3361
+ let t2 = 2166136261;
3362
+ for (let i2 = 0; i2 < e2.length; i2++) t2 = Math.imul(t2 ^ e2.charCodeAt(i2), 16777619);
3363
+ return () => (t2 += t2 << 13, t2 ^= t2 >>> 7, t2 += t2 << 3, t2 ^= t2 >>> 17, (t2 += t2 << 5) >>> 0);
3364
+ }
3365
+ }
3366
+ class t extends e {
3367
+ constructor(e2) {
3368
+ super(), Object.defineProperty(this, "a", { enumerable: true, configurable: true, writable: true, value: void 0 }), this.a = t._xfnv1a(e2)();
3369
+ }
3370
+ next() {
3371
+ let e2 = this.a += 1831565813;
3372
+ return e2 = Math.imul(e2 ^ e2 >>> 15, 1 | e2), e2 ^= e2 + Math.imul(e2 ^ e2 >>> 7, 61 | e2), ((e2 ^ e2 >>> 14) >>> 0) / 4294967296;
3373
+ }
3374
+ }
3375
+ class i extends e {
3376
+ constructor(e2) {
3377
+ super(), Object.defineProperty(this, "a", { enumerable: true, configurable: true, writable: true, value: void 0 }), Object.defineProperty(this, "b", { enumerable: true, configurable: true, writable: true, value: void 0 }), Object.defineProperty(this, "c", { enumerable: true, configurable: true, writable: true, value: void 0 }), Object.defineProperty(this, "d", { enumerable: true, configurable: true, writable: true, value: void 0 });
3378
+ const t2 = i._xfnv1a(e2);
3379
+ this.a = t2(), this.b = t2(), this.c = t2(), this.d = t2();
3380
+ }
3381
+ next() {
3382
+ this.a >>>= 0, this.b >>>= 0, this.c >>>= 0, this.d >>>= 0;
3383
+ let e2 = this.a + this.b | 0;
3384
+ return this.a = this.b ^ this.b >>> 9, this.b = this.c + (this.c << 3) | 0, this.c = this.c << 21 | this.c >>> 11, this.d = this.d + 1 | 0, e2 = e2 + this.d | 0, this.c = this.c + e2 | 0, (e2 >>> 0) / 4294967296;
3385
+ }
3386
+ }
3387
+ class r extends e {
3388
+ constructor(e2) {
3389
+ super(), Object.defineProperty(this, "a", { enumerable: true, configurable: true, writable: true, value: void 0 }), Object.defineProperty(this, "b", { enumerable: true, configurable: true, writable: true, value: void 0 }), Object.defineProperty(this, "c", { enumerable: true, configurable: true, writable: true, value: void 0 }), Object.defineProperty(this, "d", { enumerable: true, configurable: true, writable: true, value: void 0 });
3390
+ const t2 = r._xfnv1a(e2);
3391
+ this.a = t2(), this.b = t2(), this.c = t2(), this.d = t2();
3392
+ }
3393
+ next() {
3394
+ const e2 = this.b << 9;
3395
+ let t2 = 5 * this.b;
3396
+ return t2 = 9 * (t2 << 7 | t2 >>> 25), this.c ^= this.a, this.d ^= this.b, this.b ^= this.c, this.a ^= this.d, this.c ^= e2, this.d = this.d << 11 | this.d >>> 21, (t2 >>> 0) / 4294967296;
3397
+ }
3398
+ }
3399
+ var s;
3400
+ !function(e2) {
3401
+ e2.sfc32 = "sfc32", e2.mulberry32 = "mulberry32", e2.xoshiro128ss = "xoshiro128ss";
3402
+ }(s || (s = {}));
3403
+ class a {
3404
+ constructor(e2, t2 = s.sfc32) {
3405
+ Object.defineProperty(this, "str", { enumerable: true, configurable: true, writable: true, value: void 0 }), Object.defineProperty(this, "prng", { enumerable: true, configurable: true, writable: true, value: void 0 }), Object.defineProperty(this, "generator", { enumerable: true, configurable: true, writable: true, value: void 0 }), this.str = e2, this.prng = t2, this.generator = this._initializeGenerator();
3406
+ }
3407
+ next() {
3408
+ return this.generator.next();
3409
+ }
3410
+ _initializeGenerator() {
3411
+ if (/* @__PURE__ */ ((e3) => null === e3)(e2 = this.str) || /* @__PURE__ */ ((e3) => void 0 === e3)(e2)) return this.wrap();
3412
+ var e2;
3413
+ switch (this.prng) {
3414
+ case "sfc32":
3415
+ return new i(this.str);
3416
+ case "mulberry32":
3417
+ return new t(this.str);
3418
+ case "xoshiro128ss":
3419
+ return new r(this.str);
3420
+ default:
3421
+ return this.wrap();
3422
+ }
3423
+ }
3424
+ wrap() {
3425
+ return { next: () => Math.random() };
3426
+ }
3427
+ }
3428
+ var __defProp$3 = Object.defineProperty;
3429
+ var __decorateClass$3 = (decorators, target, key, kind) => {
3430
+ var result = void 0;
3431
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
3432
+ if (decorator = decorators[i2])
3433
+ result = decorator(target, key, result) || result;
3434
+ if (result) __defProp$3(target, key, result);
3435
+ return result;
3436
+ };
3437
+ class RandomizedDirectionalLight extends DirectionalLight2 {
3438
+ // Set renderer.shadowMap settings if using shadows.
3439
+ constructor(color, intensity, shadow, random) {
3440
+ super(color, intensity);
3441
+ this._shadowParams = {
3442
+ enabled: true,
3443
+ radius: 2,
3444
+ width: 1024,
3445
+ height: 1024,
3446
+ bias: -1e-3,
3447
+ normalBias: 0,
3448
+ near: 1.5,
3449
+ far: 4,
3450
+ frustumSize: 4
3451
+ };
3452
+ this._randomParams = {
3453
+ focus: 1,
3454
+ // 0 to 1
3455
+ spread: 0.01,
3456
+ // 0 to 4
3457
+ distanceScale: 50,
3458
+ // distance from target sort of
3459
+ minDistanceScale: new Vector3(10, 10, 10),
3460
+ // distance from target sort of
3461
+ // normalDirection: new Vector3(0.01, 0.33, 0.9).normalize(),
3462
+ normalDirection: new Vector3(0.01, 0.98, 0.01).normalize(),
3463
+ direction: new Vector3(-0.9, 0.5, -1)
3464
+ // direction: new Vector3(3, 2, 1).multiply(this.camera.position),
3465
+ };
3466
+ this.isRandomizedDirectionalLight = true;
3467
+ this.shadowParams = shadow ?? {};
3468
+ this.randomParams = random ?? {};
3469
+ this.updateShadowParams = this.updateShadowParams.bind(this);
3470
+ }
3471
+ /**
3472
+ * call setter to change. or call updateShadowParams after changing
3473
+ */
3474
+ get shadowParams() {
3475
+ return this._shadowParams;
3476
+ }
3477
+ set shadowParams(value) {
3478
+ Object.keys(value).forEach((key) => value[key] === void 0 && delete value[key]);
3479
+ this._shadowParams = { ...this._shadowParams, ...value };
3480
+ this.updateShadowParams();
3481
+ }
3482
+ get randomParams() {
3483
+ return this._randomParams;
3484
+ }
3485
+ set randomParams(value) {
3486
+ Object.keys(value).forEach((key) => value[key] === void 0 && delete value[key]);
3487
+ Object.assign(this._randomParams, value);
3488
+ }
3489
+ updateShadowParams() {
3490
+ this.castShadow = this._shadowParams.enabled;
3491
+ this.shadow.mapSize.x = this._shadowParams.width;
3492
+ this.shadow.mapSize.y = this._shadowParams.height;
3493
+ this.shadow.bias = this._shadowParams.bias;
3494
+ this.shadow.normalBias = this._shadowParams.normalBias;
3495
+ this.refreshShadowCamNearFar();
3496
+ this.shadow.radius = this._shadowParams.radius;
3497
+ this.shadow.camera.right = this._shadowParams.frustumSize / 2;
3498
+ this.shadow.camera.left = -this._shadowParams.frustumSize / 2;
3499
+ this.shadow.camera.top = this._shadowParams.frustumSize / 2;
3500
+ this.shadow.camera.bottom = -this._shadowParams.frustumSize / 2;
3501
+ this.shadow.camera.updateProjectionMatrix();
3502
+ this.matrixWorldNeedsUpdate = true;
3503
+ }
3504
+ randomizePosition(seed, focus = null, spread = null) {
3505
+ const rand = new a(seed.toString());
3506
+ const rnd = new Vector2(rand.next() * Math.PI * 2, Math.asin(rand.next() * 2 - 1));
3507
+ let dir = new Vector3(Math.cos(rnd.x) * Math.cos(rnd.y), Math.sin(rnd.y), Math.sin(rnd.x) * Math.cos(rnd.y));
3508
+ const v2 = new Vector2();
3509
+ for (let kk = 0; kk < 5; kk++) {
3510
+ v2.set(rand.next(), rand.next());
3511
+ dir = getSample(v2, this._randomParams.normalDirection, 0.4);
3512
+ if (rand.next() < Math.sqrt(focus ?? this._randomParams.focus)) {
3513
+ v2.set(rand.next(), rand.next());
3514
+ dir = getSample(v2, this._randomParams.direction, Math.pow((spread ?? this._randomParams.spread) / 2, 2));
3515
+ }
3516
+ const cd = dir.dot(this._randomParams.normalDirection);
3517
+ if (cd > 0 && cd < 0.4) break;
3518
+ }
3519
+ dir.normalize();
3520
+ dir.multiplyScalar(this._randomParams.distanceScale);
3521
+ this.position.set(0, 0, 0);
3522
+ this.target.position.copy(dir.normalize().negate());
3523
+ this.target.updateMatrixWorld();
3524
+ this.refreshShadowCamNearFar();
3525
+ this.updateMatrixWorld();
3526
+ }
3527
+ refreshShadowCamNearFar() {
3528
+ const dist = new Vector3().subVectors(this.target.position, this.shadow.camera.position).length();
3529
+ this.shadow.camera.near = dist - this._shadowParams.near * this._shadowParams.frustumSize / 2;
3530
+ this.shadow.camera.far = dist + this._shadowParams.far * this._shadowParams.frustumSize / 2;
3531
+ }
3532
+ dispose() {
3533
+ }
3534
+ // todo move to commons and base class in threepipe like materials
3535
+ toJSON(meta, _internal = false) {
3536
+ const { userData, children } = this;
3537
+ this.userData = {};
3538
+ this.children = [];
3539
+ const data = super.toJSON(meta);
3540
+ const copiedData = copyObject3DUserData({}, userData);
3541
+ data.userData = Serialization.Serialize(copiedData);
3542
+ this.userData = userData;
3543
+ this.children = children;
3544
+ data.type = "DirectionalLight2";
3545
+ data.target = this.target.position.toArray();
3546
+ return {
3547
+ ...data,
3548
+ ...ThreeSerialization.Serialize(this, meta, true)
3549
+ // this will serialize the properties of this class(like defined with @serialize and @serialize attribute)
3550
+ };
3551
+ }
3552
+ // todo move to commons and base class in threepipe
3553
+ fromJSON(data, meta, _internal = false) {
3554
+ if (data.type !== "DirectionalLight2") return null;
3555
+ const target = data.target;
3556
+ const object = data.object;
3557
+ if (data.target) {
3558
+ this.target.position.fromArray(data.target);
3559
+ this.target.updateMatrixWorld();
3560
+ delete data.target;
3561
+ }
3562
+ if (data.object) {
3563
+ delete data.object;
3564
+ }
3565
+ ThreeSerialization.Deserialize(data, this, meta, true);
3566
+ if (target) {
3567
+ data.target = target;
3568
+ }
3569
+ if (object) {
3570
+ if (object.color !== void 0) this.color.set(object.color);
3571
+ if (object.intensity !== void 0) this.intensity = object.intensity;
3572
+ data.object = object;
3573
+ }
3574
+ this.updateShadowParams();
3575
+ return this;
3576
+ }
3577
+ // fromJSON(data: any, meta?: any): this | null {
3578
+ // // if (!super.fromJSON(data, meta)) return null
3579
+ // this.updateShadowParams()
3580
+ // return this
3581
+ // }
3582
+ //
3583
+ // setDefaultPosition() {
3584
+ // this.position.copy(this._randomParams.direction).multiplyScalar(this._randomParams.distanceScale)
3585
+ // this.position.z = 15. + 10 * this.position.z / 50;
3586
+ // this.updateMatrixWorld()
3587
+ // }
3588
+ }
3589
+ __decorateClass$3([
3590
+ serialize("shadowParams")
3591
+ ], RandomizedDirectionalLight.prototype, "_shadowParams");
3592
+ __decorateClass$3([
3593
+ serialize("randomParams")
3594
+ ], RandomizedDirectionalLight.prototype, "_randomParams");
3595
+ function getSample(rand, dir, extent) {
3596
+ dir = dir.clone().normalize();
3597
+ const o1 = new Vector3(0, -dir.z, dir.y).normalize();
3598
+ const o2 = new Vector3().crossVectors(dir, o1).normalize();
3599
+ const r2 = rand;
3600
+ r2.x = r2.x * 2 * Math.PI;
3601
+ r2.y = 1 - r2.y * extent;
3602
+ const oneminus = Math.sqrt(1 - r2.y * r2.y);
3603
+ return o1.multiplyScalar(Math.cos(r2.x) * oneminus).add(o2.multiplyScalar(Math.sin(r2.x) * oneminus)).add(dir.multiplyScalar(r2.y));
3604
+ }
3605
+ var __defProp$2 = Object.defineProperty;
3606
+ var __decorateClass$2 = (decorators, target, key, kind) => {
3607
+ var result = void 0;
3608
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
3609
+ if (decorator = decorators[i2])
3610
+ result = decorator(target, key, result) || result;
3611
+ if (result) __defProp$2(target, key, result);
3612
+ return result;
3613
+ };
3614
+ class FSShadowMaterial extends ShadowMaterial {
3615
+ constructor() {
3616
+ super(...arguments);
3617
+ this.typeSlug = "fsShadow";
3618
+ this.assetType = "material";
3619
+ this._uniforms = {};
3620
+ this.lastFrameTexture = null;
3621
+ }
3622
+ get materialObject() {
3623
+ return this;
3624
+ }
3625
+ onBeforeCompile(shader, renderer) {
3626
+ shader.vertexShader = shader.vertexShader.replace("#include <project_vertex>", `
3627
+ #include <project_vertex>
3628
+ gl_Position = vec4(uv*2.-1., 0, 1.);
3629
+ `);
3630
+ shader.vertexShader = shader.vertexShader.replace("void main() {", `
3631
+ varying vec2 vUv;
3632
+ void main() {
3633
+ vUv = uv;
3634
+ `);
3635
+ shader.fragmentShader = shader.fragmentShader.replace("void main() {", `
3636
+ varying vec2 vUv;
3637
+ uniform sampler2D tLastThis;
3638
+ void main() {
3639
+ `);
3640
+ shader.fragmentShader = shader.fragmentShader.replace("gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );", glsl`
3641
+ float shadow = getShadowMask();
3642
+
3643
+ //shift the color by dither_shift
3644
+ shadow = clamp(shadow + mix(-1./512., 1./512., rand( gl_FragCoord.xy )), 0., 1.);
3645
+
3646
+ float last = unpackRGBAToDepth(texture2D(tLastThis, vUv));
3647
+ gl_FragColor = packDepthToRGBA(mix(last, shadow, opacity));
3648
+ //if not useMovingAverage:
3649
+ //gl_FragColor = packDepthToRGBA(shadow * opacity + last);
3650
+ `);
3651
+ Object.assign(shader.uniforms, this._uniforms);
3652
+ super.onBeforeCompile(shader, renderer);
3653
+ }
3654
+ customProgramCacheKey() {
3655
+ return super.customProgramCacheKey();
3656
+ }
3657
+ toJSON() {
3658
+ throw new Error("Method not supported for this material.");
3659
+ }
3660
+ fromJSON() {
3661
+ throw new Error("Method not supported for this material.");
3662
+ }
3663
+ copyProps() {
3664
+ throw new Error("Method not supported for this material.");
3665
+ }
3666
+ setDirty(options) {
3667
+ this.needsUpdate = true;
3668
+ this.dispatchEvent({ ...options, type: "materialUpdate" });
3669
+ }
3670
+ }
3671
+ __decorateClass$2([
3672
+ uniform({ propKey: "tLastThis" })
3673
+ ], FSShadowMaterial.prototype, "lastFrameTexture");
3674
+ const seperableShadowBlur = "#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);}";
3675
+ var __defProp$1 = Object.defineProperty;
3676
+ var __decorateClass$1 = (decorators, target, key, kind) => {
3677
+ var result = void 0;
3678
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
3679
+ if (decorator = decorators[i2])
3680
+ result = decorator(target, key, result) || result;
3681
+ if (result) __defProp$1(target, key, result);
3682
+ return result;
3683
+ };
3684
+ const _ShadowMapBaker = class _ShadowMapBaker2 extends SimpleEventDispatcher {
3685
+ constructor(viewer) {
3686
+ super();
3687
+ this.enabled = true;
3688
+ this._lightLayer = 5;
3689
+ this._frameNumber = 0;
3690
+ this.maxFrameNumber = 400;
3691
+ this.smoothShadow = false;
3692
+ this.shadowMapType = BasicShadowMap;
3693
+ this.groundMapMode = "aoMap";
3694
+ this.alphaVignette = true;
3695
+ this.alphaVignetteAxis = "xy";
3696
+ this.shadowAutoUpdate = true;
3697
+ this._bakeCounter = 0;
3698
+ this.maxBakeCount = Infinity;
3699
+ this.materialExtension = {
3700
+ parsFragmentSnippet: (_renderer, _material) => {
3701
+ return glsl`
3702
+ uniform float transitionOpacity;
3703
+ `;
3704
+ },
3705
+ extraUniforms: {
3706
+ transitionOpacity: {
3707
+ value: 1
3708
+ }
3709
+ },
3710
+ shaderExtender: (shader, _material, renderer) => {
3711
+ if (this.groundMapMode === "aoMap") {
3712
+ shader.fragmentShader = shaderReplaceString(
3713
+ shader.fragmentShader,
3714
+ "#include <aomap_fragment>",
3715
+ shaderReplaceString(
3716
+ ShaderChunk.aomap_fragment,
3717
+ "float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;",
3718
+ "float ambientOcclusion = ( mix(1., unpackRGBAToDepth(texture2D( aoMap, vAoMapUv ) ), transitionOpacity) - 1.0) * aoMapIntensity + 1.0;"
3719
+ )
3720
+ );
3721
+ } else if (this.groundMapMode === "map") {
3722
+ shader.fragmentShader = shaderReplaceString(
3723
+ shader.fragmentShader,
3724
+ "#include <map_fragment>",
3725
+ shaderReplaceString(
3726
+ ShaderChunk.map_fragment,
3727
+ "diffuseColor *= sampledDiffuseColor",
3728
+ "float groundShadow = mix(1., unpackRGBAToDepth(sampledDiffuseColor), transitionOpacity); diffuseColor.rgb *= groundShadow; diffuseColor.a *= max(0., 1.-groundShadow) * transitionOpacity;"
3729
+ )
3730
+ );
3731
+ } else if (this.groundMapMode === "alphaMap") {
3732
+ shader.fragmentShader = shaderReplaceString(
3733
+ shader.fragmentShader,
3734
+ "#include <alphamap_fragment>",
3735
+ shaderReplaceString(
3736
+ ShaderChunk.alphamap_fragment,
3737
+ "texture2D( alphaMap, vAlphaMapUv ).g",
3738
+ "1. - unpackRGBAToDepth( texture2D( alphaMap, vAlphaMapUv ) )",
3739
+ { replaceAll: true }
3740
+ )
3741
+ );
3742
+ }
3743
+ shader.fragmentShader = shaderReplaceString(
3744
+ shader.fragmentShader,
3745
+ "#include <opaque_fragment>",
3746
+ glsl`#include <opaque_fragment>
3747
+ #ifndef OPAQUE
3748
+ #ifdef USE_AOMAP
3749
+ #if NUM_DIR_LIGHT_SHADOWS > 0
3750
+ // TODO find a better solution
3751
+ float alphaMod = length(reflectedLight.directDiffuse)*4./float(NUM_DIR_LIGHT_SHADOWS);
3752
+ #else
3753
+ float alphaMod = 1.;
3754
+ #endif
3755
+ float t1 = 1. - ambientOcclusion;
3756
+ float t2 = max(1. - alphaMod, 0.);
3757
+ float t = t1 + t2;
3758
+ gl_FragColor.a *= max(t, 0.);
3759
+ #endif
3760
+ #endif
3761
+ `
3762
+ );
3763
+ if (this.alphaVignette && renderer.capabilities.isWebGL2) {
3764
+ shader.defines.USE_UV = "";
3765
+ shader.fragmentShader = shaderReplaceString(
3766
+ shader.fragmentShader,
3767
+ "#include <opaque_fragment>",
3768
+ glsl`#include <opaque_fragment>
3769
+ #ifndef OPAQUE
3770
+ float weight = 0.;
3771
+ #ifdef USE_UV // why are we checking for this? this is always supposed to be true
3772
+ weight = 2.*abs(length(0.5 - vUv.${this.alphaVignetteAxis}));
3773
+ #endif
3774
+ #if defined(USE_LIGHTMAP) || defined(USE_AOMAP)
3775
+ weight = 2.*abs(length(0.5 - vAoMapUv.${this.alphaVignetteAxis}));
3776
+ #endif
3777
+ weight = min(1., max(0., weight))-0.5;
3778
+ weight = min(1., max(0., 1.0-2.*weight));
3779
+ weight = pow(weight, 1.5);
3780
+ gl_FragColor.a *= weight;
3781
+ //gl_FragColor.rgb /= max(0.01, weight);
3782
+ gl_FragColor = saturate(gl_FragColor);
3783
+ //gl_FragColor.a = 0.5;
3784
+ #endif
3785
+ `
3786
+ );
3787
+ }
3788
+ },
3789
+ computeCacheKey: () => {
3790
+ return this.groundMapMode + "." + this.alphaVignette + "." + this.alphaVignetteAxis;
3791
+ },
3792
+ onObjectRender: (_object, material) => {
3793
+ if (material.userData.gMapMode !== this.groundMapMode) {
3794
+ material.userData.gMapMode = this.groundMapMode;
3795
+ material.needsUpdate = true;
3796
+ }
3797
+ },
3798
+ isCompatible: (material) => {
3799
+ return material.isPhysicalMaterial;
3800
+ }
3801
+ };
3802
+ this._viewer = viewer;
3803
+ const light = new RandomizedDirectionalLight(16777215, 10, {
3804
+ near: 1.5,
3805
+ far: 20,
3806
+ bias: 0,
3807
+ frustumSize: 4,
3808
+ width: 1024,
3809
+ height: 1024,
3810
+ enabled: true,
3811
+ radius: 10,
3812
+ normalBias: 0
3813
+ }, {
3814
+ direction: new Vector3(0.2, 1, 0.2).normalize(),
3815
+ spread: 0.9,
3816
+ focus: 1,
3817
+ distanceScale: 20,
3818
+ minDistanceScale: new Vector3(10, 10, 10),
3819
+ normalDirection: new Vector3(0, 1, 0)
3820
+ });
3821
+ light.shadow.camera.updateProjectionMatrix();
3822
+ light.layers.disableAll();
3823
+ light.layers.set(this._lightLayer);
3824
+ this._light = light;
3825
+ viewer.scene.addObject(this._light, { addToRoot: true });
3826
+ this._shadowMat = new FSShadowMaterial({
3827
+ color: "#ffffff",
3828
+ toneMapped: false,
3829
+ depthWrite: false,
3830
+ depthTest: false,
3831
+ premultipliedAlpha: false,
3832
+ opacity: 1,
3833
+ transparent: false,
3834
+ blending: NoBlending
3835
+ });
3836
+ this._shadowBlurMat = new ShaderMaterial2({
3837
+ uniforms: {
3838
+ "colorTexture": { value: null },
3839
+ "step": { value: 0.1 },
3840
+ "size": { value: new Vector2(0.5, 0.5) },
3841
+ "direction": { value: new Vector2(0.5, 0.5) }
3842
+ },
3843
+ vertexShader: shaderUtils.defaultVertex,
3844
+ fragmentShader: seperableShadowBlur
3845
+ });
3846
+ }
3847
+ // do not serialize // this is to disable baking for a while, toggling this does not reset the baked shadow map
3848
+ get attachedMesh() {
3849
+ return this._attachedMesh;
3850
+ }
3851
+ set attachedMesh(value) {
3852
+ if (this._attachedMesh !== value) {
3853
+ this._attachedMesh && this.cleanupMaterial();
3854
+ this._attachedMesh = value;
3855
+ this._attachedMesh && this._updateMaterial();
3856
+ }
3857
+ }
3858
+ get target() {
3859
+ return this._target;
3860
+ }
3861
+ get light() {
3862
+ return this._light;
3863
+ }
3864
+ dispose() {
3865
+ this._shadowMat.dispose();
3866
+ this._target = void 0;
3867
+ this.reset();
3868
+ }
3869
+ cleanupMaterial() {
3870
+ this._updateMaterial(true);
3871
+ }
3872
+ // x or y or xy.
3873
+ _groundMapModeChanged() {
3874
+ if (this._attachedMesh) {
3875
+ this.cleanupMaterial();
3876
+ this._updateMaterial();
3877
+ if (this.groundMapMode === "alphaMap") this._attachedMesh.material.transparent = true;
3878
+ else this._attachedMesh.material.transparent = false;
3879
+ }
3880
+ this.reset();
3881
+ }
3882
+ _alphaVignetteChanged() {
3883
+ var _a2, _b2, _c;
3884
+ (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
3885
+ (_c = this._viewer) == null ? void 0 : _c.setDirty();
3886
+ }
3887
+ fromJSON(data, meta, _internal = false) {
3888
+ if (!_internal) {
3889
+ return ThreeSerialization.Deserialize(data, this, meta, false);
3890
+ } else {
3891
+ ThreeSerialization.Deserialize(data, this, meta, true);
3892
+ this.reset();
3893
+ }
3894
+ return this;
3895
+ }
3896
+ reset() {
3897
+ this._frameNumber = 0;
3898
+ }
3899
+ get frameNumber() {
3900
+ return this._frameNumber;
3901
+ }
3902
+ autoUpdateShadow() {
3903
+ if (this.shadowAutoUpdate) {
3904
+ if (this._bakeCounter >= this.maxBakeCount) return false;
3905
+ if (!this.updateShadow()) return false;
3906
+ if (this._frameNumber === this.maxFrameNumber) {
3907
+ this.dispatchEvent({ type: "shadowBaked", bakeCount: ++this._bakeCounter });
3908
+ } else if (this._frameNumber > 0 && this._frameNumber < this.maxFrameNumber) {
3909
+ this.dispatchEvent({ type: "shadowBaking", progress: this._frameNumber / this.maxFrameNumber, bakeCount: this._bakeCounter });
3910
+ }
3911
+ return true;
3912
+ }
3913
+ return false;
3914
+ }
3915
+ updateShadow() {
3916
+ if (!this.enabled) return false;
3917
+ const mesh = this._attachedMesh;
3918
+ if (!mesh) return false;
3919
+ if (++this._frameNumber > this.maxFrameNumber) return false;
3920
+ const customSize = 1024;
3921
+ if (!this._target) {
3922
+ this._target = this._viewer.renderManager.createTarget({
3923
+ // todo: dispose somewhere
3924
+ // type: HalfFloatType,
3925
+ type: UnsignedByteType,
3926
+ depthBuffer: false,
3927
+ size: new Vector2(customSize, customSize),
3928
+ sizeMultiplier: void 0,
3929
+ // encoding: sRGBEncoding,
3930
+ colorSpace: NoColorSpace,
3931
+ format: RGBAFormat
3932
+ });
3933
+ }
3934
+ if (this._frameNumber < 3)
3935
+ this._light.randomizePosition(0, 1, 0);
3936
+ else
3937
+ this._light.randomizePosition(this._frameNumber);
3938
+ mesh.castShadow = false;
3939
+ const renderer = this._viewer.renderManager.renderer;
3940
+ const shadowMap = renderer.shadowMap;
3941
+ const shadowMapType = shadowMap.type;
3942
+ const shadowMapNeedsUpdate = shadowMap.needsUpdate;
3943
+ const shadowMapAutoUpdate = shadowMap.autoUpdate;
3944
+ shadowMap.type = this.shadowMapType;
3945
+ shadowMap.needsUpdate = true;
3946
+ shadowMap.autoUpdate = false;
3947
+ const scene = this._viewer.scene;
3948
+ const sceneLightLayer = new Layers();
3949
+ sceneLightLayer.disableAll();
3950
+ scene.traverse((o) => {
3951
+ if (o.isLight && o !== this._light) {
3952
+ o.userData.__gp_layers = o.layers;
3953
+ o.layers = sceneLightLayer;
3954
+ }
3955
+ });
3956
+ const cam = scene.mainCamera;
3957
+ if ((cam.layers.mask & 1 << this._lightLayer) !== 0) throw "Camera can render pseudo directional light, check layers";
3958
+ cam.layers.enable(this._lightLayer);
3959
+ mesh.layers.disable(this._lightLayer);
3960
+ renderer.renderWithModes({
3961
+ shadowMapRender: true,
3962
+ backgroundRender: false,
3963
+ sceneRender: false
3964
+ }, () => renderer.render(scene, scene.mainCamera));
3965
+ cam.layers.disable(this._lightLayer);
3966
+ const camLayers = cam.layers.mask;
3967
+ cam.layers.set(this._lightLayer);
3968
+ mesh.layers.enable(this._lightLayer);
3969
+ const lastThisTarget = this._viewer.renderManager.getTempTarget({
3970
+ type: UnsignedByteType,
3971
+ depthBuffer: false,
3972
+ size: new Vector2(customSize, customSize),
3973
+ // encoding: sRGBEncoding,
3974
+ colorSpace: NoColorSpace,
3975
+ format: RGBAFormat
3976
+ });
3977
+ const texture = lastThisTarget.texture;
3978
+ const lastThisTargetColorSpace = texture.colorSpace;
3979
+ texture.colorSpace = NoColorSpace;
3980
+ this._viewer.renderManager.blit(lastThisTarget, { clear: true, source: this._target.texture });
3981
+ {
3982
+ const currentMaterial = mesh.material;
3983
+ const currentFrustumCulled = mesh.frustumCulled;
3984
+ const currentRt = renderer.getRenderTarget();
3985
+ const activeCubeFace = renderer.getActiveCubeFace();
3986
+ const activeMipLevel = renderer.getActiveMipmapLevel();
3987
+ mesh.material = this._shadowMat;
3988
+ mesh.frustumCulled = false;
3989
+ renderer.setRenderTarget(this._target);
3990
+ this._shadowMat.opacity = Math.max(1 / this.maxFrameNumber, 1 / this._frameNumber);
3991
+ this._shadowMat.lastFrameTexture = lastThisTarget.texture;
3992
+ this._shadowMat.needsUpdate = true;
3993
+ renderer.renderWithModes({
3994
+ shadowMapRender: false,
3995
+ backgroundRender: false,
3996
+ opaqueRender: true,
3997
+ transparentRender: false,
3998
+ transmissionRender: false
3999
+ }, () => renderer.render(scene, scene.mainCamera));
4000
+ renderer.setRenderTarget(currentRt, activeCubeFace, activeMipLevel);
4001
+ mesh.frustumCulled = currentFrustumCulled;
4002
+ mesh.material = currentMaterial;
4003
+ if (this.smoothShadow)
4004
+ this._applySmoothFilter(this._target, lastThisTarget);
4005
+ }
4006
+ lastThisTarget.texture.colorSpace = lastThisTargetColorSpace;
4007
+ {
4008
+ this._viewer.renderManager.releaseTempTarget(lastThisTarget);
4009
+ }
4010
+ mesh.layers.disable(this._lightLayer);
4011
+ cam.layers.mask = camLayers;
4012
+ scene.modelObject.traverse((o) => {
4013
+ if (o.isLight && o !== this._light.lightObject) {
4014
+ o.layers = o.userData.__gp_layers;
4015
+ delete o.userData.__gp_layers;
4016
+ }
4017
+ });
4018
+ shadowMap.type = shadowMapType;
4019
+ shadowMap.needsUpdate = shadowMapNeedsUpdate;
4020
+ shadowMap.autoUpdate = shadowMapAutoUpdate;
4021
+ mesh.castShadow = true;
4022
+ if (this._frameNumber < 3 || this._frameNumber > Math.min(100, this.maxFrameNumber) && this._frameNumber % 4 === 0) {
4023
+ this._updateMaterial();
4024
+ mesh.material.setDirty();
4025
+ }
4026
+ return true;
4027
+ }
4028
+ _updateMaterial(isNull = false) {
4029
+ var _a2, _b2, _c;
4030
+ if (!this._attachedMesh) return;
4031
+ if (isNull) {
4032
+ if (this._attachedMesh.material.alphaMap === ((_a2 = this._target) == null ? void 0 : _a2.texture)) {
4033
+ this._attachedMesh.material.alphaMap = null;
4034
+ }
4035
+ if (this._attachedMesh.material.aoMap === ((_b2 = this._target) == null ? void 0 : _b2.texture)) {
4036
+ this._attachedMesh.material.aoMap = null;
4037
+ }
4038
+ if (this._attachedMesh.material.map === ((_c = this._target) == null ? void 0 : _c.texture)) {
4039
+ this._attachedMesh.material.map = null;
4040
+ }
4041
+ } else if (this._target) {
4042
+ if (this.groundMapMode === "alphaMap") {
4043
+ this._attachedMesh.material.alphaMap = this._target.texture;
4044
+ }
4045
+ if (this.groundMapMode === "aoMap") {
4046
+ this._attachedMesh.material.aoMap = this._target.texture;
4047
+ }
4048
+ if (this.groundMapMode === "map") {
4049
+ this._attachedMesh.material.map = this._target.texture;
4050
+ }
4051
+ }
4052
+ if (this._attachedMesh.material) {
4053
+ this._attachedMesh.material.userData.ALPHA_I_RGBA_PACKING = !isNull && this.groundMapMode === "alphaMap";
4054
+ this._attachedMesh.material.alphaTest = !isNull && this.groundMapMode === "alphaMap" ? 0.01 : 0;
4055
+ this._attachedMesh.material.needsUpdate = true;
4056
+ }
4057
+ }
4058
+ _applySmoothFilter(shadowReadBuffer, shadowWriteBuffer) {
4059
+ this._shadowBlurMat.uniforms.colorTexture.value = shadowReadBuffer.texture;
4060
+ this._shadowBlurMat.uniforms.direction.value.set(1, 0);
4061
+ this._shadowBlurMat.uniforms.size.value.set(shadowReadBuffer.width, shadowReadBuffer.height);
4062
+ this._viewer.renderManager.blit(shadowWriteBuffer, { material: this._shadowBlurMat });
4063
+ this._shadowBlurMat.uniforms.colorTexture.value = shadowWriteBuffer.texture;
4064
+ this._shadowBlurMat.uniforms.direction.value.set(0, 1);
4065
+ this._shadowBlurMat.uniforms.size.value.set(shadowWriteBuffer.width, shadowWriteBuffer.height);
4066
+ this._viewer.renderManager.blit(shadowReadBuffer, { material: this._shadowBlurMat });
4067
+ }
4068
+ // render(mesh: Mesh<BufferGeometry, PhysicalMaterial) {
4069
+ // this._viewer.renderManager.renderModel(mesh, this._viewer.scene.activeCamera!)
4070
+ // }
4071
+ };
4072
+ __decorateClass$1([
4073
+ serialize("randomizedLight")
4074
+ ], _ShadowMapBaker.prototype, "_light");
4075
+ __decorateClass$1([
4076
+ onChange(_ShadowMapBaker.prototype.reset),
4077
+ serialize()
4078
+ ], _ShadowMapBaker.prototype, "maxFrameNumber");
4079
+ __decorateClass$1([
4080
+ onChange(_ShadowMapBaker.prototype.reset),
4081
+ serialize()
4082
+ ], _ShadowMapBaker.prototype, "smoothShadow");
4083
+ __decorateClass$1([
4084
+ serialize(),
4085
+ onChange(_ShadowMapBaker.prototype.reset)
4086
+ ], _ShadowMapBaker.prototype, "shadowMapType");
4087
+ __decorateClass$1([
4088
+ onChange(_ShadowMapBaker.prototype._groundMapModeChanged),
4089
+ serialize()
4090
+ ], _ShadowMapBaker.prototype, "groundMapMode");
4091
+ __decorateClass$1([
4092
+ serialize(),
4093
+ onChange(_ShadowMapBaker.prototype._alphaVignetteChanged)
4094
+ ], _ShadowMapBaker.prototype, "alphaVignette");
4095
+ __decorateClass$1([
4096
+ serialize(),
4097
+ onChange(_ShadowMapBaker.prototype._alphaVignetteChanged)
4098
+ ], _ShadowMapBaker.prototype, "alphaVignetteAxis");
4099
+ __decorateClass$1([
4100
+ serialize()
4101
+ ], _ShadowMapBaker.prototype, "maxBakeCount");
4102
+ let ShadowMapBaker = _ShadowMapBaker;
4103
+ var __defProp = Object.defineProperty;
4104
+ var __decorateClass = (decorators, target, key, kind) => {
4105
+ var result = void 0;
4106
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
4107
+ if (decorator = decorators[i2])
4108
+ result = decorator(target, key, result) || result;
4109
+ if (result) __defProp(target, key, result);
4110
+ return result;
4111
+ };
4112
+ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4113
+ constructor() {
4114
+ super();
4115
+ this.bakedShadows = true;
4116
+ this.groundReflection = false;
4117
+ this.physicalReflections = false;
4118
+ this.autoFrustumSize = true;
4119
+ this.autoBakeShadows = true;
4120
+ this.autoResetShadows = () => {
4121
+ var _a2;
4122
+ if (this.autoBakeShadows) (_a2 = this._shadowBaker) == null ? void 0 : _a2.reset();
4123
+ };
4124
+ this._onSceneUpdate = this._onSceneUpdate.bind(this);
4125
+ console.log(this.uiConfig);
4126
+ const generatedUi = generateUiConfig(this);
4127
+ const matUI = generatedUi.find((f) => typeof f === "function");
4128
+ this.uiConfig = {
4129
+ label: "Ground",
4130
+ type: "folder",
4131
+ children: [
4132
+ ...generatedUi.filter((f) => f !== matUI),
4133
+ ...this._extraUiConfig(),
4134
+ matUI
4135
+ ]
4136
+ };
4137
+ }
4138
+ get shadowBaker() {
4139
+ return this._shadowBaker;
4140
+ }
4141
+ // because of inheritance breaks onChange
4142
+ _refresh3() {
4143
+ this.refresh();
4144
+ }
4145
+ /**
4146
+ * bake shadows manually, to be used with {@see autoBakeShadows} set to false
4147
+ */
4148
+ bakeShadows() {
4149
+ var _a2;
4150
+ (_a2 = this._shadowBaker) == null ? void 0 : _a2.reset();
4151
+ }
4152
+ _createMesh(mesh) {
4153
+ if (mesh) throw new Error("AdvancedGroundPlugin - mesh should not be provided");
4154
+ const reflector = new Reflector2(this._geometry, () => {
4155
+ var _a2;
4156
+ return (_a2 = this._viewer) == null ? void 0 : _a2.renderManager.createTarget({
4157
+ // type: HalfFloatType,
4158
+ type: UnsignedByteType,
4159
+ format: RGBAFormat,
4160
+ colorSpace: NoColorSpace,
4161
+ // todo: we can do rgbm if only opaque objects will be reflected
4162
+ size: { width: 1024, height: 1024 },
4163
+ generateMipmaps: true,
4164
+ depthBuffer: true,
4165
+ minFilter: LinearMipmapLinearFilter,
4166
+ magFilter: LinearFilter
4167
+ // isAntialiased: this._viewer.isAntialiased,
4168
+ });
4169
+ }, 0, this._createMaterial());
4170
+ const superOnBeforeRender = reflector.onBeforeRender;
4171
+ reflector.onBeforeRender = (...params) => {
4172
+ var _a2;
4173
+ let ssr = (_a2 = this._viewer) == null ? void 0 : _a2.getPluginByType("SSReflectionPlugin");
4174
+ if (ssr && ssr.isDisabled()) ssr = void 0;
4175
+ if (ssr) ssr.disable(reflector.uuid, false);
4176
+ superOnBeforeRender(...params);
4177
+ if (ssr) ssr.enable(reflector.uuid, false);
4178
+ };
4179
+ return reflector;
4180
+ }
4181
+ onAdded(viewer) {
4182
+ super.onAdded(viewer);
4183
+ }
4184
+ _postFrame() {
4185
+ super._postFrame();
4186
+ if (!this._viewer) return;
4187
+ if (!this.enabled) return;
4188
+ if (this._shadowBaker && this.bakedShadows) {
4189
+ this._shadowBaker.autoUpdateShadow();
4190
+ }
4191
+ }
4192
+ _preRender() {
4193
+ super._preRender();
4194
+ if (!this._viewer) return;
4195
+ this._mesh.reflectionTargetNeedsUpdate = this._viewer.renderManager.frameCount < 1;
4196
+ }
4197
+ onRemove(viewer) {
4198
+ return super.onRemove(viewer);
4199
+ }
4200
+ _removeMaterial() {
4201
+ var _a2, _b2, _c, _d;
4202
+ if (!this._material) return;
4203
+ if (this._shadowBaker && this._material.groundMatExtension) {
4204
+ (_b2 = (_a2 = this._material).unregisterMaterialExtensions) == null ? void 0 : _b2.call(_a2, [this._shadowBaker.materialExtension]);
4205
+ delete this._material.groundMatExtension;
4206
+ }
4207
+ if (this._material.reflectorMatExtension) {
4208
+ const ext = this._mesh.materialExtension;
4209
+ if (!ext) console.warn("WebGi GroundPlugin: unable to find the extension to unregister");
4210
+ (_d = (_c = this._material).unregisterMaterialExtensions) == null ? void 0 : _d.call(_c, [ext]);
4211
+ delete this._material.reflectorMatExtension;
4212
+ }
4213
+ super._removeMaterial();
4214
+ }
4215
+ _onSceneUpdate(event) {
4216
+ super._onSceneUpdate(event);
4217
+ if (event.geometryChanged === false) return;
4218
+ this.autoResetShadows();
4219
+ }
4220
+ refresh() {
4221
+ if (!this._viewer) return;
4222
+ if (!this.isDisabled()) {
4223
+ if (this.bakedShadows && !this._shadowBaker) {
4224
+ this._shadowBaker = new ShadowMapBaker(this._viewer);
4225
+ this._shadowBaker.attachedMesh = this._mesh;
4226
+ } else if (!this.bakedShadows && this._shadowBaker) {
4227
+ this._shadowBaker.reset();
4228
+ this._shadowBaker.cleanupMaterial();
4229
+ }
4230
+ const ref = this._mesh;
4231
+ if (ref.isReflector2) {
4232
+ ref.enabled = this.groundReflection;
4233
+ ref.reflectorModePhysical = this.physicalReflections;
4234
+ }
4235
+ }
4236
+ super.refresh();
4237
+ }
4238
+ _refreshTransform() {
4239
+ if (!super._refreshTransform()) return false;
4240
+ if (this.autoFrustumSize) {
4241
+ const baker = this.shadowBaker;
4242
+ if (baker) {
4243
+ const fs = this.size / 2;
4244
+ if (fs !== baker.light.shadowParams.frustumSize) {
4245
+ baker.light.shadowParams.frustumSize = fs;
4246
+ baker.light.updateShadowParams();
4247
+ baker.reset();
4248
+ }
4249
+ }
4250
+ }
4251
+ return true;
4252
+ }
4253
+ // see BaseGroundPlugin
4254
+ fromJSON(data, meta) {
4255
+ if (!super.fromJSON(data, meta)) return null;
4256
+ if (data.autoFrustumSize === void 0) this.autoFrustumSize = false;
4257
+ return this;
4258
+ }
4259
+ _refreshMaterial() {
4260
+ var _a2, _b2, _c, _d;
4261
+ if (!this._viewer) return false;
4262
+ super._refreshMaterial();
4263
+ if (!this._material) return;
4264
+ if (this.groundReflection && this._mesh.isReflector2 && !this._material.reflectorMatExtension) {
4265
+ const ext = this._mesh.materialExtension;
4266
+ ext.updaters = [this._viewer.scene, this._viewer.renderManager];
4267
+ (_b2 = (_a2 = this._material).registerMaterialExtensions) == null ? void 0 : _b2.call(_a2, [ext]);
4268
+ this._material.reflectorMatExtension = true;
4269
+ }
4270
+ if (this.bakedShadows && this._shadowBaker && !this._material.groundMatExtension) {
4271
+ (_d = (_c = this._material).registerMaterialExtensions) == null ? void 0 : _d.call(_c, [this._shadowBaker.materialExtension]);
4272
+ this._material.groundMatExtension = true;
4273
+ }
4274
+ this._material.userData.ssreflDisabled = this.groundReflection;
4275
+ this._material.userData.ssreflNonPhysical = !this.physicalReflections;
4276
+ this._viewer.setDirty(this);
4277
+ }
4278
+ _extraUiConfig() {
4279
+ var _a2, _b2, _c, _d, _e, _f, _g, _h;
4280
+ return [
4281
+ {
4282
+ label: "Shadow Frames",
4283
+ type: "input",
4284
+ hidden: () => !this._shadowBaker,
4285
+ stepSize: 1,
4286
+ bounds: [1, 1e3],
4287
+ property: () => [this._shadowBaker, "maxFrameNumber"]
4288
+ },
4289
+ {
4290
+ label: "Alpha Vignette",
4291
+ type: "checkbox",
4292
+ hidden: () => !this._material || this._material.transmission < 1e-4 && !this._material.transparent,
4293
+ property: () => [this._shadowBaker, "alphaVignette"],
4294
+ limitedUi: true,
4295
+ onChange: () => {
4296
+ var _a3, _b3;
4297
+ return (_b3 = (_a3 = this.uiConfig) == null ? void 0 : _a3.uiRefresh) == null ? void 0 : _b3.call(_a3, true, "postFrame");
4298
+ }
4299
+ },
4300
+ {
4301
+ label: "Alpha Vignette Axis",
4302
+ type: "dropdown",
4303
+ hidden: () => {
4304
+ var _a3;
4305
+ return !((_a3 = this._shadowBaker) == null ? void 0 : _a3.alphaVignette) || !this._material || this._material.transmission < 1e-4 && !this._material.transparent;
4306
+ },
4307
+ property: () => [this._shadowBaker, "alphaVignetteAxis"],
4308
+ children: ["x", "y", "xy"].map((v) => ({ label: v, value: v })),
4309
+ limitedUi: true
4310
+ },
4311
+ {
4312
+ label: "Shadow type",
4313
+ type: "dropdown",
4314
+ hidden: () => !this._shadowBaker,
4315
+ property: () => [this._shadowBaker, "groundMapMode"],
4316
+ children: [
4317
+ { label: "aoMap" },
4318
+ { label: "map" },
4319
+ { label: "alphaMap" }
4320
+ ],
4321
+ limitedUi: true
4322
+ },
4323
+ {
4324
+ label: "Smooth Shadow",
4325
+ type: "checkbox",
4326
+ property: () => [this._shadowBaker, "smoothShadow"]
4327
+ },
4328
+ {
4329
+ label: "Baked shadow type",
4330
+ type: "dropdown",
4331
+ children: [["Basic", BasicShadowMap], ["PCF", PCFShadowMap], ["PCFSoft", PCFSoftShadowMap], ["VSM", VSMShadowMap]].map((v) => ({ label: v[0].toString(), value: v[1] })),
4332
+ property: () => [this._shadowBaker, "shadowMapType"]
4333
+ },
4334
+ {
4335
+ type: "folder",
4336
+ label: "Randomized Light",
4337
+ hidden: () => !this._shadowBaker,
4338
+ limitedUi: true,
4339
+ children: [
4340
+ {
4341
+ type: "color",
4342
+ label: "Color",
4343
+ property: () => {
4344
+ var _a3;
4345
+ return [(_a3 = this._shadowBaker) == null ? void 0 : _a3.light, "color"];
4346
+ }
4347
+ },
4348
+ // {
4349
+ // type: 'slider',
4350
+ // label: 'Intensity',
4351
+ // bounds: [0, 100],
4352
+ // property: ()=>[this._shadowBaker?.light, 'intensity'],
4353
+ // },
4354
+ // {
4355
+ // type: 'checkbox',
4356
+ // label: 'Shadow Enabled',
4357
+ // property: ()=>[this._shadowBaker?.light?.shadowParams, 'enabled'],
4358
+ // onChange: [this._shadowBaker?.light?.updateShadowParams, this.autoResetShadows],
4359
+ // },
4360
+ {
4361
+ type: "slider",
4362
+ bounds: [0, 1],
4363
+ property: () => {
4364
+ var _a3, _b3;
4365
+ return [(_b3 = (_a3 = this._shadowBaker) == null ? void 0 : _a3.light) == null ? void 0 : _b3.randomParams, "focus"];
4366
+ },
4367
+ onChange: this.autoResetShadows
4368
+ },
4369
+ {
4370
+ type: "slider",
4371
+ bounds: [0, 1],
4372
+ property: () => {
4373
+ var _a3, _b3;
4374
+ return [(_b3 = (_a3 = this._shadowBaker) == null ? void 0 : _a3.light) == null ? void 0 : _b3.randomParams, "spread"];
4375
+ },
4376
+ onChange: this.autoResetShadows,
4377
+ limitedUi: true
4378
+ },
4379
+ {
4380
+ type: "slider",
4381
+ bounds: [0.01, 60],
4382
+ property: () => {
4383
+ var _a3, _b3;
4384
+ return [(_b3 = (_a3 = this._shadowBaker) == null ? void 0 : _a3.light) == null ? void 0 : _b3.randomParams, "distanceScale"];
4385
+ },
4386
+ onChange: [(_b2 = (_a2 = this._shadowBaker) == null ? void 0 : _a2.light) == null ? void 0 : _b2.updateShadowParams, this.autoResetShadows]
4387
+ },
4388
+ {
4389
+ type: "vec3",
4390
+ bounds: [-1, 1],
4391
+ property: () => {
4392
+ var _a3, _b3;
4393
+ return [(_b3 = (_a3 = this._shadowBaker) == null ? void 0 : _a3.light) == null ? void 0 : _b3.randomParams, "direction"];
4394
+ },
4395
+ onChange: this.autoResetShadows,
4396
+ limitedUi: true
4397
+ },
4398
+ {
4399
+ type: "vec3",
4400
+ bounds: [-1, 1],
4401
+ property: () => {
4402
+ var _a3, _b3;
4403
+ return [(_b3 = (_a3 = this._shadowBaker) == null ? void 0 : _a3.light) == null ? void 0 : _b3.randomParams, "normalDirection"];
4404
+ },
4405
+ onChange: this.autoResetShadows,
4406
+ limitedUi: true
4407
+ },
4408
+ {
4409
+ type: "slider",
4410
+ bounds: [0.01, 10],
4411
+ property: () => {
4412
+ var _a3, _b3;
4413
+ return [(_b3 = (_a3 = this._shadowBaker) == null ? void 0 : _a3.light) == null ? void 0 : _b3.shadowParams, "radius"];
4414
+ },
4415
+ onChange: [(_d = (_c = this._shadowBaker) == null ? void 0 : _c.light) == null ? void 0 : _d.updateShadowParams, this.autoResetShadows]
4416
+ },
4417
+ {
4418
+ type: "input",
4419
+ property: () => {
4420
+ var _a3, _b3;
4421
+ return [(_b3 = (_a3 = this._shadowBaker) == null ? void 0 : _a3.light) == null ? void 0 : _b3.shadowParams, "frustumSize"];
4422
+ },
4423
+ hidden: () => this.autoFrustumSize,
4424
+ onChange: [(_f = (_e = this._shadowBaker) == null ? void 0 : _e.light) == null ? void 0 : _f.updateShadowParams, this.autoResetShadows]
4425
+ },
4426
+ {
4427
+ type: "slider",
4428
+ bounds: [-0.1, 0.1],
4429
+ property: () => {
4430
+ var _a3, _b3;
4431
+ return [(_b3 = (_a3 = this._shadowBaker) == null ? void 0 : _a3.light) == null ? void 0 : _b3.shadowParams, "bias"];
4432
+ },
4433
+ onChange: [(_h = (_g = this._shadowBaker) == null ? void 0 : _g.light) == null ? void 0 : _h.updateShadowParams, this.autoResetShadows]
4434
+ }
4435
+ ]
4436
+ }
4437
+ ];
4438
+ }
4439
+ }, _b.PluginType = "AdvancedGroundPlugin", _b);
4440
+ __decorateClass([
4441
+ onChange(_AdvancedGroundPlugin.prototype._refresh3),
4442
+ uiToggle("Baked Shadows"),
4443
+ serialize()
4444
+ ], _AdvancedGroundPlugin.prototype, "bakedShadows");
4445
+ __decorateClass([
4446
+ onChange(_AdvancedGroundPlugin.prototype._refresh3),
4447
+ uiToggle("Planar Reflections"),
4448
+ serialize()
4449
+ ], _AdvancedGroundPlugin.prototype, "groundReflection");
4450
+ __decorateClass([
4451
+ onChange(_AdvancedGroundPlugin.prototype._refresh3),
4452
+ uiToggle("Physical Reflections"),
4453
+ serialize()
4454
+ ], _AdvancedGroundPlugin.prototype, "physicalReflections");
4455
+ __decorateClass([
4456
+ onChange(_AdvancedGroundPlugin.prototype._refresh3),
4457
+ uiToggle("Auto Shadow Frustum Size"),
4458
+ serialize()
4459
+ ], _AdvancedGroundPlugin.prototype, "autoFrustumSize");
4460
+ __decorateClass([
4461
+ serialize("shadowBaker")
4462
+ ], _AdvancedGroundPlugin.prototype, "_shadowBaker");
4463
+ __decorateClass([
4464
+ bindToValue({ key: "groundReflection" })
4465
+ ], _AdvancedGroundPlugin.prototype, "planarReflections");
4466
+ let AdvancedGroundPlugin = _AdvancedGroundPlugin;
3102
4467
  const webgiPlugins = [
3103
4468
  TemporalAAPlugin,
3104
4469
  VelocityBufferPlugin,
@@ -3108,9 +4473,11 @@ const webgiPlugins = [
3108
4473
  DepthOfFieldPlugin,
3109
4474
  OutlinePlugin,
3110
4475
  SSGIPlugin,
3111
- AnisotropyPlugin
4476
+ AnisotropyPlugin,
4477
+ AdvancedGroundPlugin
3112
4478
  ];
3113
4479
  export {
4480
+ AdvancedGroundPlugin,
3114
4481
  AnisotropyPlugin,
3115
4482
  BloomPlugin,
3116
4483
  BloomPluginPass,