@threepipe/webgi-plugins 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,23 +1,42 @@
1
1
  /**
2
2
  * @license
3
- * @threepipe/webgi-plugins v0.5.1
3
+ * @threepipe/webgi-plugins v0.5.3
4
4
  * Copyright 2022-2025 repalash <palash@shaders.app> (https://repalash.com)
5
5
  * SEE LICENSE IN LICENSE
6
6
  */
7
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";
8
+ import { ShaderChunk, 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, 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, uiDropdown, uiInput, uiButton } 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(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
- var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
15
- var __decorateClass$e = (decorators, target, key, kind) => {
16
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
12
+ const computeScreenSpaceVelocity = "uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;vec2 computeScreenSpaceVelocity(const in vec3 worldPosition){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(worldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(worldPosition,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}";
13
+ const getWorldPositionFromViewZ = "uniform mat4 inverseViewMatrix;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;}";
14
+ const temporalaa = "#include <common>\n#include <gbuffer_unpack>\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#else\n#define HAS_VELOCITY_BUFFER 0\n#endif\n#include <cameraHelpers>\nvarying vec2 vUv;uniform vec2 previousRTSize;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;vec3 find_closest_fragment_3x3(const in vec2 uv){const vec3 offset=vec3(-1.0,1.0,0.0);vec2 texelSize=1.0/previousRTSize;vec3 dtr=vec3(1,1,getDepth(uv+offset.yy*texelSize));vec3 dtc=vec3(0,1,getDepth(uv+offset.zy*texelSize));vec3 dtl=vec3(-1,1,getDepth(uv+offset.xy*texelSize));vec3 dml=vec3(-1,0,getDepth(uv+offset.xz*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dmr=vec3(1,0,getDepth(uv+offset.yz*texelSize));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.xx*texelSize));vec3 dbc=vec3(0,-1,getDepth(uv+offset.zx*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.yx*texelSize));vec3 dmin=dtl;if(dmin.z>dtc.z)dmin=dtc;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dml.z)dmin=dml;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dmr.z)dmin=dmr;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbc.z)dmin=dbc;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+texelSize.xy*dmin.xy,dmin.z);}vec3 find_closest_fragment_5tap(const in vec2 uv){vec2 texelSize=1.0/previousRTSize;vec2 offset=vec2(1.0,-1.0);vec3 dtl=vec3(-1,1,getDepth(uv+offset.yx*texelSize));vec3 dtr=vec3(1,1,getDepth(uv+offset.xx*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.yy*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.xy*texelSize));vec3 dmin=dtl;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+dmin.xy*texelSize,dmin.z);}vec4 clip_aabb(const in vec4 aabb_min,const in vec4 aabb_max,vec4 p){const float FLT_EPS=1e-8;vec4 p_clip=0.5*(aabb_max+aabb_min);vec4 e_clip=0.5*(aabb_max-aabb_min)+FLT_EPS;vec4 v_clip=p-p_clip;vec4 v_unit=abs(v_clip/e_clip);float ma_unit=max(v_unit.x,max(v_unit.y,v_unit.z));if(ma_unit>1.0)return p_clip+v_clip/ma_unit;else return p;}\n#if HAS_VELOCITY_BUFFER == 0 || defined(DEBUG_VELOCITY)\n#include <computeScreenSpaceVelocity>\n#include <getWorldPositionFromViewZ>\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.));}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}";
15
+ const ssreflection = "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\n#if SSREFL_ENABLED == 2\nuniform float ssrSplitX;\n#endif\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#else\n#define HAS_VELOCITY_BUFFER 0\n#endif\n#if HAS_VELOCITY_BUFFER == 0\n#include <computeScreenSpaceVelocity>\n#include <getWorldPositionFromViewZ>\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){if(currentFrameCount<1.){\n#if HAS_VELOCITY_BUFFER == 0\nvec3 worldPosition=getWorldPositionFromViewZ(screenHitP.xy,screenHitP.z);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);\n#else\nvec2 screenSpaceVelocity=getVelocity(screenHitP.xy);\n#endif\nscreenHitP.xy-=screenSpaceVelocity;}vec3 hitColor=(tLastFrameTexelToLinear(texture2D(tLastFrame,screenHitP.xy))).rgb;float ssrWeight=1.;return vec4(hitColor*ssrWeight,1.);}return vec4(0.);}";
16
+ const ssrtao = "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;\n#ifndef D_sceneBoundingRadius\n#define D_sceneBoundingRadius\nuniform float sceneBoundingRadius;\n#endif\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#else\n#define HAS_VELOCITY_BUFFER 0\n#endif\n#if HAS_VELOCITY_BUFFER == 0\n#include <computeScreenSpaceVelocity>\n#include <getWorldPositionFromViewZ>\n#endif\nvec3 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\nif(currentFrameCount<1.){\n#if HAS_VELOCITY_BUFFER == 0\nvec3 worldPosition=getWorldPositionFromViewZ(screenHitP.xy,screenHitP.z);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);\n#else\nvec2 screenSpaceVelocity=getVelocity(screenHitP.xy);\n#endif\nscreenHitP.xy-=screenSpaceVelocity;}vec3 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.));}";
17
+ const shadersUtils2 = {
18
+ computeScreenSpaceVelocity,
19
+ getWorldPositionFromViewZ,
20
+ temporalAA: temporalaa,
21
+ ssReflection: ssreflection,
22
+ calculateGI: ssrtao,
23
+ ["__inited"]: false
24
+ };
25
+ function getShaders() {
26
+ if (!shadersUtils2.__inited) {
27
+ shadersUtils2.__inited = true;
28
+ Object.assign(ShaderChunk, shadersUtils2);
29
+ }
30
+ return shadersUtils2;
31
+ }
32
+ var __defProp$f = Object.defineProperty;
33
+ var __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor;
34
+ var __decorateClass$f = (decorators, target, key, kind) => {
35
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target;
17
36
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
18
37
  if (decorator = decorators[i2])
19
38
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
20
- if (kind && result) __defProp$e(target, key, result);
39
+ if (kind && result) __defProp$f(target, key, result);
21
40
  return result;
22
41
  };
23
42
  const passId$4 = "taa";
@@ -50,8 +69,7 @@ const _TemporalAAPlugin = class _TemporalAAPlugin extends PipelinePassPlugin {
50
69
  this.setDirty = this.setDirty.bind(this);
51
70
  }
52
71
  get stableNoise() {
53
- var _a2;
54
- return ((_a2 = this._viewer) == null ? void 0 : _a2.renderManager.stableNoise) ?? this._stableNoise;
72
+ return this._viewer?.renderManager.stableNoise ?? this._stableNoise;
55
73
  }
56
74
  set stableNoise(v) {
57
75
  if (this._viewer) this._viewer.renderManager.stableNoise = v;
@@ -62,10 +80,7 @@ const _TemporalAAPlugin = class _TemporalAAPlugin extends PipelinePassPlugin {
62
80
  if (!this._viewer.renderManager.gbufferTarget || !this._viewer.renderManager.gbufferUnpackExtension)
63
81
  throw new Error("TemporalAAPlugin: GBuffer target not created. GBufferPlugin is required.");
64
82
  const applyOnBackground = !!this._viewer.renderManager.msaa;
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
- }, applyOnBackground);
83
+ const t2 = new TemporalAAPluginPass(this.passId, () => this._viewer?.getPlugin(ProgressivePlugin)?.target, applyOnBackground);
69
84
  return t2;
70
85
  }
71
86
  // todo use gbufferUnpackExtension from render manager to support depth buffer plugin as well.
@@ -144,18 +159,17 @@ const _TemporalAAPlugin = class _TemporalAAPlugin extends PipelinePassPlugin {
144
159
  _TemporalAAPlugin.PluginType = "TAA";
145
160
  _TemporalAAPlugin.OldPluginType = "TemporalAAPlugin";
146
161
  let TemporalAAPlugin = _TemporalAAPlugin;
147
- __decorateClass$e([
162
+ __decorateClass$f([
148
163
  uiToggle("Stable Noise (Total frame count)")
149
164
  ], TemporalAAPlugin.prototype, "stableNoise", 1);
150
- __decorateClass$e([
151
- uiConfig()
165
+ __decorateClass$f([
166
+ uiConfig(void 0, { unwrapContents: true })
152
167
  ], TemporalAAPlugin.prototype, "_pass", 2);
153
168
  class TemporalAAPluginPass extends ExtendedShaderPass {
154
169
  constructor(pid, target, applyOnBackground = false) {
155
- var _a2;
156
170
  super({
157
171
  vertexShader: CopyShader.vertexShader,
158
- fragmentShader: taaShader,
172
+ fragmentShader: getShaders().temporalAA,
159
173
  uniforms: {
160
174
  currentRT: { value: null },
161
175
  previousRT: { value: null },
@@ -191,7 +205,7 @@ class TemporalAAPluginPass extends ExtendedShaderPass {
191
205
  property: [this, "enabled"],
192
206
  onChange: () => this.onSizeUpdate()
193
207
  },
194
- ...((_a2 = generateUiConfig(this)) == null ? void 0 : _a2.filter((c) => c && c.label !== "Enabled")) || []
208
+ ...generateUiConfig(this)?.filter((c) => c && c.label !== "Enabled") || []
195
209
  ]
196
210
  };
197
211
  this.passId = pid;
@@ -201,13 +215,12 @@ class TemporalAAPluginPass extends ExtendedShaderPass {
201
215
  this.needsSwap = true;
202
216
  }
203
217
  render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
204
- var _a2;
205
218
  if (!this.taaEnabled || !this.enabled) {
206
219
  this.needsSwap = false;
207
220
  return;
208
221
  }
209
222
  this.needsSwap = true;
210
- this.uniforms.previousRT.value = ((_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) ?? null;
223
+ this.uniforms.previousRT.value = getOrCall(this.target)?.texture ?? null;
211
224
  super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
212
225
  this.uniforms.lastProjectionViewMatrix.value.copy(this.uniforms.currentProjectionViewMatrix.value);
213
226
  this.uniforms.firstFrame.value = false;
@@ -226,23 +239,23 @@ class TemporalAAPluginPass extends ExtendedShaderPass {
226
239
  this.onSizeUpdate();
227
240
  }
228
241
  }
229
- __decorateClass$e([
242
+ __decorateClass$f([
230
243
  serialize(),
231
244
  uniform(),
232
245
  uiVector("Feedback", void 0, 1e-4)
233
246
  ], TemporalAAPluginPass.prototype, "feedBack", 2);
234
- __decorateClass$e([
247
+ __decorateClass$f([
235
248
  uiToggle(),
236
249
  matDefineBool("DEBUG_VELOCITY", void 0, false, void 0, true)
237
250
  ], TemporalAAPluginPass.prototype, "debugVelocity", 2);
238
- var __defProp$d = Object.defineProperty;
239
- var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
240
- var __decorateClass$d = (decorators, target, key, kind) => {
241
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
251
+ var __defProp$e = Object.defineProperty;
252
+ var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
253
+ var __decorateClass$e = (decorators, target, key, kind) => {
254
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
242
255
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
243
256
  if (decorator = decorators[i2])
244
257
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
245
- if (kind && result) __defProp$d(target, key, result);
258
+ if (kind && result) __defProp$e(target, key, result);
246
259
  return result;
247
260
  };
248
261
  let VelocityBufferPlugin = class extends PipelinePassPlugin {
@@ -261,16 +274,10 @@ let VelocityBufferPlugin = class extends PipelinePassPlugin {
261
274
  },
262
275
  computeCacheKey: () => this.isDisabled() ? "" : "vb",
263
276
  extraUniforms: {
264
- tVelocity: () => {
265
- var _a2;
266
- return { value: !this.isDisabled() ? (_a2 = this.target) == null ? void 0 : _a2.texture : null };
267
- }
277
+ tVelocity: () => ({ value: !this.isDisabled() ? this.target?.texture : null })
268
278
  },
269
279
  extraDefines: {
270
- ["HAS_VELOCITY_BUFFER"]: () => {
271
- var _a2;
272
- return !this.isDisabled() && ((_a2 = this.target) == null ? void 0 : _a2.texture) ? 1 : void 0;
273
- }
280
+ ["HAS_VELOCITY_BUFFER"]: () => !this.isDisabled() && this.target?.texture ? 1 : void 0
274
281
  },
275
282
  priority: 100,
276
283
  isCompatible: () => true
@@ -331,34 +338,27 @@ let VelocityBufferPlugin = class extends PipelinePassPlugin {
331
338
  }
332
339
  }(this.passId, this.target, this.material, new Color(0.5, 0.5, 0.5), 1);
333
340
  const preprocessMaterial = pass.preprocessMaterial;
334
- pass.preprocessMaterial = (m) => {
335
- var _a2;
336
- return preprocessMaterial(m, (_a2 = m.userData[VelocityBufferPlugin.PluginType]) == null ? void 0 : _a2.disabled);
337
- };
341
+ pass.preprocessMaterial = (m) => preprocessMaterial(m, m.userData[VelocityBufferPlugin.PluginType]?.disabled);
338
342
  pass.before = ["render"];
339
343
  pass.after = [];
340
344
  pass.required = ["render"];
341
345
  return pass;
342
346
  }
343
347
  onAdded(viewer) {
344
- var _a2;
345
348
  super.onAdded(viewer);
346
- if (this._attachToTaa) {
347
- const taa = viewer.getPlugin(TemporalAAPlugin);
348
- if (taa) (_a2 = taa.pass) == null ? void 0 : _a2.material.registerMaterialExtensions([this.unpackExtension]);
349
- else viewer.console.warn("VelocityBufferPlugin: TemporalAAPlugin not found, set attachToTaa to false if not required");
350
- }
349
+ viewer.forPlugin(TemporalAAPlugin, (taa) => {
350
+ this._attachToTaa && taa.pass?.material.registerMaterialExtensions([this.unpackExtension]);
351
+ }, (taa) => {
352
+ taa.pass?.material?.unregisterMaterialExtensions([this.unpackExtension]);
353
+ });
351
354
  }
352
355
  onRemove(viewer) {
353
- var _a2, _b2;
354
356
  this._disposeTarget();
355
- if (this._attachToTaa) (_b2 = (_a2 = viewer.getPlugin(TemporalAAPlugin)) == null ? void 0 : _a2.pass) == null ? void 0 : _b2.material.unregisterMaterialExtensions([this.unpackExtension]);
356
357
  return super.onRemove(viewer);
357
358
  }
358
359
  setDirty() {
359
- var _a2, _b2;
360
360
  super.setDirty();
361
- (_b2 = (_a2 = this.unpackExtension).setDirty) == null ? void 0 : _b2.call(_a2);
361
+ this.unpackExtension.setDirty?.();
362
362
  }
363
363
  _beforeRender(scene, camera, renderManager) {
364
364
  if (!super._beforeRender(scene, camera, renderManager)) return false;
@@ -373,10 +373,10 @@ let VelocityBufferPlugin = class extends PipelinePassPlugin {
373
373
  };
374
374
  VelocityBufferPlugin.PluginType = "VelocityBuffer";
375
375
  VelocityBufferPlugin.OldPluginType = "VelocityBufferPlugin";
376
- __decorateClass$d([
376
+ __decorateClass$e([
377
377
  uiImage("Velocity Buffer", { readOnly: true })
378
378
  ], VelocityBufferPlugin.prototype, "texture", 2);
379
- VelocityBufferPlugin = __decorateClass$d([
379
+ VelocityBufferPlugin = __decorateClass$e([
380
380
  uiFolderContainer("Velocity Buffer Plugin (for TAA)")
381
381
  ], VelocityBufferPlugin);
382
382
  class SSVelocityMaterial extends ShaderMaterial {
@@ -413,7 +413,7 @@ class SSVelocityMaterial extends ShaderMaterial {
413
413
  if (Array.isArray(mat)) {
414
414
  mat = mat[0];
415
415
  }
416
- this.uniforms.alphaMap.value = (mat == null ? void 0 : mat.alphaMap) ?? null;
416
+ this.uniforms.alphaMap.value = mat?.alphaMap ?? null;
417
417
  this.uniforms.alphaTest.value = !mat || !mat.alphaTest || mat.alphaTest < 1e-7 ? 1e-3 : mat.alphaTest;
418
418
  let x = this.uniforms.alphaMap.value ? 1 : void 0;
419
419
  if (x !== this.defines.USE_ALPHAMAP) {
@@ -421,24 +421,24 @@ class SSVelocityMaterial extends ShaderMaterial {
421
421
  else this.defines.USE_ALPHAMAP = x;
422
422
  this.needsUpdate = true;
423
423
  }
424
- x = (mat == null ? void 0 : mat.userData.ALPHA_I_RGBA_PACKING) ? 1 : void 0;
424
+ x = mat?.userData.ALPHA_I_RGBA_PACKING ? 1 : void 0;
425
425
  if (x !== this.defines.ALPHA_I_RGBA_PACKING) {
426
426
  if (x === void 0) delete this.defines.ALPHA_I_RGBA_PACKING;
427
427
  else this.defines.ALPHA_I_RGBA_PACKING = x;
428
428
  this.needsUpdate = true;
429
429
  }
430
- this.side = (mat == null ? void 0 : mat.side) ?? DoubleSide;
430
+ this.side = mat?.side ?? DoubleSide;
431
431
  }
432
432
  }
433
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}";
434
- var __defProp$c = Object.defineProperty;
435
- var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
436
- var __decorateClass$c = (decorators, target, key, kind) => {
437
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
434
+ var __defProp$d = Object.defineProperty;
435
+ var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
436
+ var __decorateClass$d = (decorators, target, key, kind) => {
437
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
438
438
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
439
439
  if (decorator = decorators[i2])
440
440
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
441
- if (kind && result) __defProp$c(target, key, result);
441
+ if (kind && result) __defProp$d(target, key, result);
442
442
  return result;
443
443
  };
444
444
  const passId$3 = "bloom";
@@ -449,12 +449,11 @@ const _BloomPlugin = (_a = class extends PipelinePassPlugin {
449
449
  this.materialExtension = uiConfigMaterialExtension(this._getUiConfig.bind(this), _a.PluginType);
450
450
  this.dependencies = [GBufferPlugin];
451
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;
452
+ if (e2.plugin?.constructor?.PluginType !== GBufferPlugin.PluginType) return;
454
453
  const gbuffer = e2.plugin;
455
454
  gbuffer.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this));
456
- (_c = this._pass) == null ? void 0 : _c.material.registerMaterialExtensions([gbuffer.unpackExtension]);
457
- (_d = this._viewer) == null ? void 0 : _d.removeEventListener("addPlugin", this._onPluginAdd);
455
+ this._pass?.material.registerMaterialExtensions([gbuffer.unpackExtension]);
456
+ this._viewer?.removeEventListener("addPlugin", this._onPluginAdd);
458
457
  };
459
458
  this.uiConfig = {
460
459
  type: "folder",
@@ -466,8 +465,7 @@ const _BloomPlugin = (_a = class extends PipelinePassPlugin {
466
465
  };
467
466
  }
468
467
  _createPass() {
469
- var _a2;
470
- const pass = new BloomPluginPass(this.passId, Math.min(8, ((_a2 = this._viewer) == null ? void 0 : _a2.renderManager.maxHDRIntensity) || 8));
468
+ const pass = new BloomPluginPass(this.passId, Math.min(8, this._viewer?.renderManager.maxHDRIntensity || 8));
471
469
  return pass;
472
470
  }
473
471
  onAdded(viewer) {
@@ -480,23 +478,21 @@ const _BloomPlugin = (_a = class extends PipelinePassPlugin {
480
478
  viewer.materialManager.registerMaterialExtension(this.materialExtension);
481
479
  }
482
480
  onRemove(viewer) {
483
- var _a2;
484
481
  viewer.removeEventListener("addPlugin", this._onPluginAdd);
485
482
  const gbuffer = viewer.getPlugin(GBufferPlugin);
486
- gbuffer == null ? void 0 : gbuffer.unregisterGBufferUpdater(this.constructor.PluginType);
487
- gbuffer && ((_a2 = this._pass) == null ? void 0 : _a2.material.unregisterMaterialExtensions([gbuffer.unpackExtension]));
483
+ gbuffer?.unregisterGBufferUpdater(this.constructor.PluginType);
484
+ gbuffer && this._pass?.material.unregisterMaterialExtensions([gbuffer.unpackExtension]);
488
485
  viewer.materialManager.unregisterMaterialExtension(this.materialExtension);
489
486
  super.onRemove(viewer);
490
487
  }
491
488
  updateGBufferFlags(data, c) {
492
- var _a2;
493
489
  if (!c.material || !c.material.userData) return;
494
- const disabled = ((_a2 = c.material.userData[_a.PluginType]) == null ? void 0 : _a2.enable) === false || c.material.userData.pluginsDisabled;
490
+ const disabled = c.material.userData[_a.PluginType]?.enable === false || c.material.userData.pluginsDisabled;
495
491
  const x = disabled ? 0 : 1;
496
492
  data.w = updateBit(data.w, 2, x);
497
493
  }
498
494
  static AddBloomData(material, params, setDirty = true) {
499
- const ud = material == null ? void 0 : material.userData;
495
+ const ud = material?.userData;
500
496
  if (!ud) return null;
501
497
  if (!ud[_a.PluginType]) {
502
498
  ud[_a.PluginType] = {};
@@ -521,17 +517,15 @@ const _BloomPlugin = (_a = class extends PipelinePassPlugin {
521
517
  type: "checkbox",
522
518
  label: "Enabled",
523
519
  get value() {
524
- var _a2;
525
- return ((_a2 = material.userData[_a.PluginType]) == null ? void 0 : _a2.enable) ?? true;
520
+ return material.userData[_a.PluginType]?.enable ?? true;
526
521
  },
527
522
  set value(v) {
528
- var _a2;
529
523
  let data = material.userData[_a.PluginType];
530
- if (v === (data == null ? void 0 : data.enable)) return;
524
+ if (v === data?.enable) return;
531
525
  if (!data) data = _a.AddBloomData(material, void 0, false);
532
526
  data.enable = v;
533
527
  material.setDirty();
534
- (_a2 = config.uiRefresh) == null ? void 0 : _a2.call(config, true, "postFrame");
528
+ config.uiRefresh?.(true, "postFrame");
535
529
  },
536
530
  onChange: this.setDirty
537
531
  }
@@ -540,8 +534,8 @@ const _BloomPlugin = (_a = class extends PipelinePassPlugin {
540
534
  return config;
541
535
  }
542
536
  }, _a.PluginType = "Bloom", _a.OldPluginType = "BloomPlugin", _a);
543
- __decorateClass$c([
544
- uiConfig()
537
+ __decorateClass$d([
538
+ uiConfig(void 0, { unwrapContents: true })
545
539
  ], _BloomPlugin.prototype, "_pass", 2);
546
540
  let BloomPlugin = _BloomPlugin;
547
541
  let BloomPluginPass = class extends ExtendedShaderPass {
@@ -588,11 +582,10 @@ let BloomPluginPass = class extends ExtendedShaderPass {
588
582
  this.clear = true;
589
583
  }
590
584
  _thresholdsUpdated() {
591
- var _a2;
592
585
  this.prefilter.x = this.threshold;
593
586
  this.prefilter.y = this.softThreshold;
594
587
  this.prefilter.z = 2 * this.prefilter.x * this.prefilter.y;
595
- this.prefilter.w = ((_a2 = this.uniforms) == null ? void 0 : _a2.prefilter) ? 0.125 / (this.uniforms.prefilter.value.z + 1e-5) : 0;
588
+ this.prefilter.w = this.uniforms?.prefilter ? 0.125 / (this.uniforms.prefilter.value.z + 1e-5) : 0;
596
589
  }
597
590
  render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
598
591
  const renderManager = renderer.renderManager;
@@ -688,48 +681,48 @@ let BloomPluginPass = class extends ExtendedShaderPass {
688
681
  if (setDirty !== false) this.setDirty();
689
682
  }
690
683
  };
691
- __decorateClass$c([
684
+ __decorateClass$d([
692
685
  uniform()
693
686
  ], BloomPluginPass.prototype, "prefilter", 2);
694
- __decorateClass$c([
687
+ __decorateClass$d([
695
688
  uiSlider("Threshold", [0, 2]),
696
689
  onChange(BloomPluginPass.prototype._thresholdsUpdated),
697
690
  serialize()
698
691
  ], BloomPluginPass.prototype, "threshold", 2);
699
- __decorateClass$c([
692
+ __decorateClass$d([
700
693
  uiSlider("Soft Threshold", [0, 1]),
701
694
  onChange(BloomPluginPass.prototype._thresholdsUpdated),
702
695
  serialize()
703
696
  ], BloomPluginPass.prototype, "softThreshold", 2);
704
- __decorateClass$c([
697
+ __decorateClass$d([
705
698
  uiSlider("Intensity", [0, 3]),
706
699
  serialize(),
707
700
  uniform()
708
701
  ], BloomPluginPass.prototype, "intensity", 2);
709
- __decorateClass$c([
702
+ __decorateClass$d([
710
703
  uiToggle("Background Bloom"),
711
704
  serialize(),
712
705
  matDefineBool("BACKGROUND_BLOOM")
713
706
  ], BloomPluginPass.prototype, "backgroundBloom", 2);
714
- __decorateClass$c([
707
+ __decorateClass$d([
715
708
  uiSlider("Iterations", [2, 7], 1),
716
709
  onChange2(BloomPluginPass.prototype._updateWeights),
717
710
  serialize()
718
711
  ], BloomPluginPass.prototype, "bloomIterations", 2);
719
- __decorateClass$c([
712
+ __decorateClass$d([
720
713
  uiSlider("Radius", [0, 1], 0.01),
721
714
  onChange2(BloomPluginPass.prototype._updateWeights),
722
715
  serialize()
723
716
  ], BloomPluginPass.prototype, "radius", 2);
724
- __decorateClass$c([
717
+ __decorateClass$d([
725
718
  uiSlider("Power", [0.2, 10], 0.01),
726
719
  onChange2(BloomPluginPass.prototype._updateWeights),
727
720
  serialize()
728
721
  ], BloomPluginPass.prototype, "power", 2);
729
- __decorateClass$c([
722
+ __decorateClass$d([
730
723
  uiToggle("Debug")
731
724
  ], BloomPluginPass.prototype, "bloomDebug", 2);
732
- BloomPluginPass = __decorateClass$c([
725
+ BloomPluginPass = __decorateClass$d([
733
726
  uiFolderContainer("Bloom Pass")
734
727
  ], BloomPluginPass);
735
728
  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}";
@@ -737,14 +730,14 @@ const dofPoissonBox = "#include <randomHelpers>\n#include <common>\nvarying vec2
737
730
  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);}";
738
731
  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}";
739
732
  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}";
740
- var __defProp$b = Object.defineProperty;
741
- var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
742
- var __decorateClass$b = (decorators, target, key, kind) => {
743
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
733
+ var __defProp$c = Object.defineProperty;
734
+ var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
735
+ var __decorateClass$c = (decorators, target, key, kind) => {
736
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
744
737
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
745
738
  if (decorator = decorators[i2])
746
739
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
747
- if (kind && result) __defProp$b(target, key, result);
740
+ if (kind && result) __defProp$c(target, key, result);
748
741
  return result;
749
742
  };
750
743
  const passId$2 = "depthOfField";
@@ -759,31 +752,29 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
759
752
  this._focalPointHitTime = 0;
760
753
  this.dependencies = [GBufferPlugin];
761
754
  this._onPluginAdd = (e2) => {
762
- var _a2, _b2, _c, _d, _e;
763
755
  const plugin = e2.plugin;
764
756
  if (!plugin) return;
765
- if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
757
+ if (plugin.constructor?.PluginType === GBufferPlugin.PluginType) {
766
758
  const gbuffer = plugin;
767
- (_b2 = this._pass) == null ? void 0 : _b2.material.registerMaterialExtensions([gbuffer.unpackExtension]);
768
- (_c = this._pass) == null ? void 0 : _c.computeCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
769
- (_d = this._pass) == null ? void 0 : _d.expandCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
759
+ this._pass?.material.registerMaterialExtensions([gbuffer.unpackExtension]);
760
+ this._pass?.computeCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
761
+ this._pass?.expandCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
770
762
  }
771
- if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
763
+ if (plugin.constructor?.PluginType === PickingPlugin.PluginType) {
772
764
  const picking = plugin;
773
765
  picking.addEventListener("hitObject", this._onObjectHit);
774
766
  }
775
767
  };
776
768
  this._onPluginRemove = (e2) => {
777
- var _a2, _b2, _c, _d, _e;
778
769
  const plugin = e2.plugin;
779
770
  if (!plugin) return;
780
- if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
771
+ if (plugin.constructor?.PluginType === GBufferPlugin.PluginType) {
781
772
  const gbuffer = e2.plugin;
782
- (_b2 = this._pass) == null ? void 0 : _b2.material.unregisterMaterialExtensions([gbuffer.unpackExtension]);
783
- (_c = this._pass) == null ? void 0 : _c.computeCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
784
- (_d = this._pass) == null ? void 0 : _d.expandCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
773
+ this._pass?.material.unregisterMaterialExtensions([gbuffer.unpackExtension]);
774
+ this._pass?.computeCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
775
+ this._pass?.expandCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
785
776
  }
786
- if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
777
+ if (plugin.constructor?.PluginType === PickingPlugin.PluginType) {
787
778
  const picking = e2.plugin;
788
779
  picking.removeEventListener("hitObject", this._onObjectHit);
789
780
  }
@@ -794,10 +785,7 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
794
785
  onChange: this.setDirty.bind(this),
795
786
  children: [
796
787
  ...generateUiConfig(this) || [],
797
- () => {
798
- var _a2;
799
- return (_a2 = this._pass) == null ? void 0 : _a2.uiConfig;
800
- }
788
+ () => this._pass?.uiConfig
801
789
  ]
802
790
  };
803
791
  this._tempVec = new Vector3();
@@ -811,9 +799,8 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
811
799
  }
812
800
  // todo make this a property.
813
801
  setFocalPoint(p, fade = true, showGizmo = false) {
814
- var _a2, _b2;
815
802
  this._focalPointHit.copy(p);
816
- if (fade) (_b2 = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin("FrameFadePlugin")) == null ? void 0 : _b2.startTransition(this._frameFadeTime);
803
+ if (fade) this._viewer?.getPlugin("FrameFadePlugin")?.startTransition(this._frameFadeTime);
817
804
  if (showGizmo) this._focalPointHitTime = now();
818
805
  this.setDirty();
819
806
  }
@@ -821,12 +808,11 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
821
808
  return this._focalPointHit;
822
809
  }
823
810
  _onObjectHit(e2) {
824
- var _a2, _b2;
825
811
  if (!this._pass || !e2.intersects.intersect || this.isDisabled() || !this.enableEdit) return;
826
812
  this._focalPointHit.copy(e2.intersects.intersect.point);
827
813
  this._focalPointHitTime = e2.time;
828
814
  e2.intersects.selectedObject = null;
829
- (_b2 = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(FrameFadePlugin)) == null ? void 0 : _b2.startTransition(this._frameFadeTime);
815
+ this._viewer?.getPlugin(FrameFadePlugin)?.startTransition(this._frameFadeTime);
830
816
  this.setDirty();
831
817
  }
832
818
  _createPass() {
@@ -853,7 +839,7 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
853
839
  const pass = this.pass;
854
840
  if (!pass) return false;
855
841
  if (pass.dofBlurMaterial.uniforms.frameCount)
856
- renderManager == null ? void 0 : renderManager.updateShaderProperties(pass.dofBlurMaterial);
842
+ renderManager?.updateShaderProperties(pass.dofBlurMaterial);
857
843
  const cam = camera;
858
844
  if (!cam) return false;
859
845
  cam.updateMatrixWorld(true);
@@ -957,14 +943,14 @@ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin
957
943
  _DepthOfFieldPlugin.PluginType = "DepthOfField";
958
944
  _DepthOfFieldPlugin.OldPluginType = "DepthOfFieldPlugin";
959
945
  let DepthOfFieldPlugin = _DepthOfFieldPlugin;
960
- __decorateClass$b([
946
+ __decorateClass$c([
961
947
  serialize(),
962
948
  uiToggle()
963
949
  ], DepthOfFieldPlugin.prototype, "enableEdit", 2);
964
- __decorateClass$b([
950
+ __decorateClass$c([
965
951
  serialize("focalPoint")
966
952
  ], DepthOfFieldPlugin.prototype, "_focalPointHit", 2);
967
- __decorateClass$b([
953
+ __decorateClass$c([
968
954
  serialize()
969
955
  ], DepthOfFieldPlugin.prototype, "crossFadeTime", 2);
970
956
  const dofBlurMaterialPoisson = new ExtendedShaderMaterial({
@@ -1079,50 +1065,50 @@ let DepthOfFieldPluginPass = class extends ExtendedShaderPass {
1079
1065
  renderManager.releaseTempTarget(renderTargetBlurTemp);
1080
1066
  }
1081
1067
  };
1082
- __decorateClass$b([
1068
+ __decorateClass$c([
1083
1069
  bindToValue({ obj: "focalDepthRange", key: "y" }),
1084
1070
  uiSlider("Depth Range", [0.25, 3])
1085
1071
  ], DepthOfFieldPluginPass.prototype, "depthRange", 2);
1086
- __decorateClass$b([
1072
+ __decorateClass$c([
1087
1073
  bindToValue({ obj: "nearFarBlurScale", key: "x" }),
1088
1074
  uiSlider("Near Blur Scale", [0, 1])
1089
1075
  ], DepthOfFieldPluginPass.prototype, "nearBlurScale", 2);
1090
- __decorateClass$b([
1076
+ __decorateClass$c([
1091
1077
  bindToValue({ obj: "nearFarBlurScale", key: "y" }),
1092
1078
  uiSlider("Far Blur Scale", [0, 1])
1093
1079
  ], DepthOfFieldPluginPass.prototype, "farBlurScale", 2);
1094
- __decorateClass$b([
1080
+ __decorateClass$c([
1095
1081
  serialize(),
1096
1082
  uniform()
1097
1083
  ], DepthOfFieldPluginPass.prototype, "nearFarBlurScale", 2);
1098
- __decorateClass$b([
1084
+ __decorateClass$c([
1099
1085
  serialize(),
1100
1086
  uniform()
1101
1087
  ], DepthOfFieldPluginPass.prototype, "focalDepthRange", 2);
1102
- __decorateClass$b([
1088
+ __decorateClass$c([
1103
1089
  uniform()
1104
1090
  ], DepthOfFieldPluginPass.prototype, "crossCenter", 2);
1105
- __decorateClass$b([
1091
+ __decorateClass$c([
1106
1092
  uniform()
1107
1093
  ], DepthOfFieldPluginPass.prototype, "crossRadius", 2);
1108
- __decorateClass$b([
1094
+ __decorateClass$c([
1109
1095
  uniform()
1110
1096
  ], DepthOfFieldPluginPass.prototype, "crossAlpha", 2);
1111
- __decorateClass$b([
1097
+ __decorateClass$c([
1112
1098
  uniform()
1113
1099
  ], DepthOfFieldPluginPass.prototype, "crossColor", 2);
1114
- DepthOfFieldPluginPass = __decorateClass$b([
1100
+ DepthOfFieldPluginPass = __decorateClass$c([
1115
1101
  uiFolderContainer("DepthOfField Pass")
1116
1102
  ], DepthOfFieldPluginPass);
1117
1103
  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";
1118
- var __defProp$a = Object.defineProperty;
1119
- var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
1120
- var __decorateClass$a = (decorators, target, key, kind) => {
1121
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
1104
+ var __defProp$b = Object.defineProperty;
1105
+ var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
1106
+ var __decorateClass$b = (decorators, target, key, kind) => {
1107
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
1122
1108
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
1123
1109
  if (decorator = decorators[i2])
1124
1110
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1125
- if (kind && result) __defProp$a(target, key, result);
1111
+ if (kind && result) __defProp$b(target, key, result);
1126
1112
  return result;
1127
1113
  };
1128
1114
  let SSContactShadowsPlugin = class extends AViewerPluginSync {
@@ -1158,7 +1144,6 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1158
1144
  uuid: SSContactShadowsPlugin.PluginType,
1159
1145
  priority: 5,
1160
1146
  shaderExtender: (shader, _material, _renderer) => {
1161
- var _a2, _b2;
1162
1147
  if (!shader.defines.SSCS_ENABLED) return;
1163
1148
  const rsS = "float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {";
1164
1149
  const lsS = glsl`
@@ -1210,11 +1195,10 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1210
1195
  "directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;",
1211
1196
  "directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;"
1212
1197
  );
1213
- (_b2 = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b2.call(_a2, shader, _material, _renderer);
1198
+ this._gbufferUnpackExtension?.shaderExtender?.(shader, _material, _renderer);
1214
1199
  },
1215
1200
  onObjectRender: (_, material, renderer) => {
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;
1201
+ const enabled2 = this.enabled && renderer.userData.screenSpaceRendering !== false && !material.userData?.pluginsDisabled && !material.userData?.sscsDisabled ? 1 : 0;
1218
1202
  updateMaterialDefines({
1219
1203
  ...this._defines,
1220
1204
  ["SSCS_ENABLED"]: enabled2
@@ -1284,16 +1268,13 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1284
1268
  // }
1285
1269
  // return config
1286
1270
  // },
1287
- updaters: () => {
1288
- var _a2, _b2, _c, _d;
1289
- return [
1290
- // this._viewer?.getPlugin(GBufferPlugin),
1291
- (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(ProgressivePlugin),
1292
- (_b2 = this._viewer) == null ? void 0 : _b2.scene.renderCamera,
1293
- (_c = this._viewer) == null ? void 0 : _c.renderManager,
1294
- (_d = this._viewer) == null ? void 0 : _d.scene
1295
- ];
1296
- }
1271
+ updaters: () => [
1272
+ // this._viewer?.getPlugin(GBufferPlugin),
1273
+ this._viewer?.getPlugin(ProgressivePlugin),
1274
+ this._viewer?.scene.renderCamera,
1275
+ this._viewer?.renderManager,
1276
+ this._viewer?.scene
1277
+ ]
1297
1278
  };
1298
1279
  this._gbufferUnpackExtension = void 0;
1299
1280
  this._gbufferUnpackExtensionChanged = () => {
@@ -1308,9 +1289,8 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1308
1289
  this.enabled = enabled;
1309
1290
  }
1310
1291
  setDirty() {
1311
- var _a2, _b2, _c;
1312
- (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
1313
- (_c = this._viewer) == null ? void 0 : _c.setDirty();
1292
+ this.materialExtension?.setDirty?.();
1293
+ this._viewer?.setDirty();
1314
1294
  }
1315
1295
  onAdded(v) {
1316
1296
  super.onAdded(v);
@@ -1320,8 +1300,7 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1320
1300
  v.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1321
1301
  }
1322
1302
  onRemove(v) {
1323
- var _a2;
1324
- (_a2 = v.assetManager.materials) == null ? void 0 : _a2.unregisterMaterialExtension(this.materialExtension);
1303
+ v.assetManager.materials?.unregisterMaterialExtension(this.materialExtension);
1325
1304
  v.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1326
1305
  return super.onRemove(v);
1327
1306
  }
@@ -1335,51 +1314,50 @@ let SSContactShadowsPlugin = class extends AViewerPluginSync {
1335
1314
  };
1336
1315
  SSContactShadowsPlugin.PluginType = "SSContactShadows";
1337
1316
  SSContactShadowsPlugin.OldPluginType = "SSContactShadowsPlugin";
1338
- __decorateClass$a([
1317
+ __decorateClass$b([
1339
1318
  uiToggle("Enabled"),
1340
1319
  serialize(),
1341
1320
  onChange(SSContactShadowsPlugin.prototype.setDirty)
1342
1321
  ], SSContactShadowsPlugin.prototype, "enabled", 2);
1343
- __decorateClass$a([
1322
+ __decorateClass$b([
1344
1323
  uniform({ propKey: "sscsRadius", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1345
1324
  uiSlider("Radius", [1e-4, 0.1], 1e-4),
1346
1325
  serialize()
1347
1326
  ], SSContactShadowsPlugin.prototype, "radius", 2);
1348
- __decorateClass$a([
1327
+ __decorateClass$b([
1349
1328
  uniform({ propKey: "sscsIntensity", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1350
1329
  uiSlider("Intensity", [1e-4, 1], 1e-4),
1351
1330
  serialize()
1352
1331
  ], SSContactShadowsPlugin.prototype, "intensity", 2);
1353
- __decorateClass$a([
1332
+ __decorateClass$b([
1354
1333
  uniform({ propKey: "sscsTolerance", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1355
1334
  uiSlider("Tolerance", [0.1, 5]),
1356
1335
  serialize()
1357
1336
  ], SSContactShadowsPlugin.prototype, "tolerance", 2);
1358
- __decorateClass$a([
1337
+ __decorateClass$b([
1359
1338
  matDefine("SSCS_DEBUG", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
1360
1339
  uiToggle("Debug only SSCS"),
1361
1340
  serialize()
1362
1341
  ], SSContactShadowsPlugin.prototype, "onlySSCSDebug", 2);
1363
- __decorateClass$a([
1342
+ __decorateClass$b([
1364
1343
  matDefine("SSCS_STEP_COUNT", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
1365
1344
  uiSlider("Step count", [1, 8], 1),
1366
1345
  serialize()
1367
1346
  ], SSContactShadowsPlugin.prototype, "stepCount", 2);
1368
- SSContactShadowsPlugin = __decorateClass$a([
1347
+ SSContactShadowsPlugin = __decorateClass$b([
1369
1348
  uiFolderContainer("SS Contact Shadows")
1370
1349
  ], SSContactShadowsPlugin);
1371
1350
  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;}";
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.);}";
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";
1351
+ const ssreflPatch = "\n#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0\nvec3 screenPos=viewToScreen(geometryPosition);\n#if SSREFL_ENABLED == 2\nif(screenPos.x>ssrSplitX){\n#endif\nvec4 ssrColor=vec4(0,0,0,0);float alphaModifier=1.0-clamp(material.roughness*.3,0.,1.);alphaModifier*=ssrIntensity;\n#if defined(SSR_MASK_FRONT_RAYS) && SSR_MASK_FRONT_RAYS > 0\nalphaModifier*=clamp(-4.0*dot(geometryViewDir,normal)+(4.0+ssrMaskFrontFactor),0.0,1.0);\n#endif\n#ifdef USE_TRANSMISSION\nalphaModifier*=1.-transmission;\n#endif\nfloat vignette=1.;if(true){float fadeStrength=0.1;float dist=max(0.,min(min(1.-screenPos.x,1.-screenPos.y),min(screenPos.x,screenPos.y)));float fade=dist*dist/(fadeStrength+0.001);fade=clamp(fade,0.0,1.0);fade=pow(fade,0.3);vignette=fade;}alphaModifier*=vignette;vec3 specularColor=EnvironmentBRDF(geometryNormal,geometryViewDir,material.specularColor.rgb,material.specularF90,material.roughness);if(length(specularColor.rgb)*alphaModifier>0.01&&roughnessFactor<0.9){\n#if defined(SSR_INLINE) && SSR_INLINE > 0\nvec3 scPos=vec3(screenPos.xy,geometryPosition.z);vec4 scol=vec4(0,0,0,0);\n#pragma unroll_loop_start\nfor(int i=0;i<8;i++){if(SSR_RAY_COUNT>UNROLLED_LOOP_INDEX){scol=calculateSSR(float(UNROLLED_LOOP_INDEX),scPos,geometryNormal,UNROLLED_LOOP_INDEX%3==0?1.:UNROLLED_LOOP_INDEX%3==1?0.5:1.5,material.roughness);\n#ifdef SSR_RAY_BLEND_MAX\nssrColor=max(ssrColor,scol);\n#else\nssrColor+=scol;\n#endif\n}}\n#pragma unroll_loop_end\n#ifndef SSR_RAY_BLEND_MAX\nssrColor*=ssrColor.a>0.001 ? 1.0/ssrColor.a : 1.0;\n#endif\n#else\nssrColor=tSSReflMapTexelToLinear(texture2D(tSSReflMap,screenPos.xy));\n#endif\n}ssrColor.rgb*=ssrBoost;ssrColor.a*=alphaModifier;ssrColor.rgb=pow(max(vec3(0.),ssrColor.rgb),vec3(ssrPower));ssrColor.a=min(ssrColor.a,1.0);\n#if defined(SSR_NON_PHYSICAL) && SSR_NON_PHYSICAL > 0\ndiffuseColor.a=max(ssrColor.a,diffuseColor.a*diffuseColor.a);reflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,saturate(diffuseColor.rgb*ssrColor.rgb),1.0);reflectedLight.indirectDiffuse=diffuseColor.rgb*(1.0-ssrColor.a);reflectedLight.directDiffuse=vec3(0.0);reflectedLight.directSpecular=vec3(0.0);\n#else\nreflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,(specularColor.rgb*ssrColor.rgb),ssrColor.a);\n#endif\n#if SSREFL_ENABLED == 2\n}\n#endif\n#endif\n";
1374
1352
  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}";
1375
- var __defProp$9 = Object.defineProperty;
1376
- var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
1377
- var __decorateClass$9 = (decorators, target, key, kind) => {
1378
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
1353
+ var __defProp$a = Object.defineProperty;
1354
+ var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
1355
+ var __decorateClass$a = (decorators, target, key, kind) => {
1356
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
1379
1357
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
1380
1358
  if (decorator = decorators[i2])
1381
1359
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1382
- if (kind && result) __defProp$9(target, key, result);
1360
+ if (kind && result) __defProp$a(target, key, result);
1383
1361
  return result;
1384
1362
  };
1385
1363
  const passId$1 = "ssrefl";
@@ -1400,6 +1378,20 @@ let SSReflectionPlugin = class extends PipelinePassPlugin {
1400
1378
  if (this._gbufferUnpackExtension) this._pass.setGBufferUnpackExtension(this._gbufferUnpackExtension);
1401
1379
  else this._viewer.console.warn("SSReflectionPlugin: GBuffer unpack extension removed");
1402
1380
  };
1381
+ this._viewerListeners = {
1382
+ preRender: () => {
1383
+ if (!this._viewer || this.isDisabled()) return;
1384
+ if (!this._pass) return;
1385
+ const renderCamera = this._viewer.scene.renderCamera;
1386
+ this._pass.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(renderCamera.projectionMatrix, renderCamera.matrixWorldInverse);
1387
+ this._pass.uniforms.inverseViewMatrix.value.copy(renderCamera.matrixWorld);
1388
+ },
1389
+ postRender: () => {
1390
+ if (!this._viewer || this.isDisabled()) return;
1391
+ if (!this._pass) return;
1392
+ this._pass.uniforms.lastProjectionViewMatrix.value.copy(this._pass.uniforms.currentProjectionViewMatrix.value);
1393
+ }
1394
+ };
1403
1395
  this.enabled = enabled;
1404
1396
  this.bufferType = bufferType;
1405
1397
  this.sizeMultiplier = sizeMultiplier;
@@ -1443,6 +1435,11 @@ let SSReflectionPlugin = class extends PipelinePassPlugin {
1443
1435
  if (viewer.getPlugin("Ground") || viewer.getPlugin("BaseGroundPlugin")) console.error("GroundPlugin must be added after SSReflectionPlugin");
1444
1436
  this._gbufferUnpackExtensionChanged();
1445
1437
  viewer.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1438
+ viewer.forPlugin(VelocityBufferPlugin, (vbp) => {
1439
+ this._pass?.material.registerMaterialExtensions([vbp.unpackExtension]);
1440
+ }, (vbp) => {
1441
+ this._pass?.material?.unregisterMaterialExtensions([vbp.unpackExtension]);
1442
+ });
1446
1443
  }
1447
1444
  onRemove(viewer) {
1448
1445
  this._disposeTarget();
@@ -1450,12 +1447,11 @@ let SSReflectionPlugin = class extends PipelinePassPlugin {
1450
1447
  return super.onRemove(viewer);
1451
1448
  }
1452
1449
  _beforeRender(_, _1, _2) {
1453
- var _a2;
1454
1450
  if (!this._viewer) return false;
1455
1451
  const e2 = super._beforeRender(_, _1, _2);
1456
1452
  if (!e2) return e2;
1457
1453
  const progressive = this._viewer.getPlugin(ProgressivePlugin);
1458
- (_a2 = this._pass) == null ? void 0 : _a2.updateShaderProperties([progressive]);
1454
+ this._pass?.updateShaderProperties([progressive]);
1459
1455
  return e2;
1460
1456
  }
1461
1457
  /**
@@ -1466,8 +1462,7 @@ let SSReflectionPlugin = class extends PipelinePassPlugin {
1466
1462
  return this.target;
1467
1463
  }
1468
1464
  fromJSON(data, meta) {
1469
- var _a2;
1470
- if ((_a2 = data.passes) == null ? void 0 : _a2.ssr) {
1465
+ if (data.passes?.ssr) {
1471
1466
  data = { ...data };
1472
1467
  data.pass = data.passes.ssr;
1473
1468
  delete data.passes;
@@ -1478,13 +1473,13 @@ let SSReflectionPlugin = class extends PipelinePassPlugin {
1478
1473
  };
1479
1474
  SSReflectionPlugin.PluginType = "SSReflectionPlugin";
1480
1475
  SSReflectionPlugin.OldPluginType = "SSReflection";
1481
- __decorateClass$9([
1476
+ __decorateClass$a([
1482
1477
  uiImage("SSReflection Buffer", { readOnly: true, hideOnEmpty: true })
1483
1478
  ], SSReflectionPlugin.prototype, "texture", 2);
1484
- __decorateClass$9([
1485
- uiConfig()
1479
+ __decorateClass$a([
1480
+ uiConfig(void 0, { unwrapContents: true })
1486
1481
  ], SSReflectionPlugin.prototype, "_pass", 2);
1487
- SSReflectionPlugin = __decorateClass$9([
1482
+ SSReflectionPlugin = __decorateClass$a([
1488
1483
  uiFolderContainer("SSReflection Plugin")
1489
1484
  ], SSReflectionPlugin);
1490
1485
  let SSReflectionPluginPass = class extends ExtendedShaderPass {
@@ -1531,8 +1526,14 @@ let SSReflectionPluginPass = class extends ExtendedShaderPass {
1531
1526
  maskFrontFactor: { value: -0.1 },
1532
1527
  tolerance: { value: 0 },
1533
1528
  ssrRoughnessFactor: { value: 1 },
1534
- sceneBoundingRadius: { value: 0 }
1529
+ sceneBoundingRadius: { value: 0 },
1535
1530
  // todo do same in SSAO
1531
+ // reprojection/velocity
1532
+ currentProjectionViewMatrix: { value: new Matrix4() },
1533
+ lastProjectionViewMatrix: { value: new Matrix4() },
1534
+ inverseViewMatrix: { value: new Matrix4() },
1535
+ // split mode
1536
+ ssrSplitX: { value: 0.5 }
1536
1537
  },
1537
1538
  vertexShader: shaderUtils.defaultVertex,
1538
1539
  fragmentShader: `
@@ -1547,7 +1548,7 @@ ${samplePointHelpers}
1547
1548
 
1548
1549
  ${ssrtShader}
1549
1550
 
1550
- ${ssrShader}
1551
+ ${getShaders().ssReflection}
1551
1552
 
1552
1553
  ${ssrShaderMain}
1553
1554
  `
@@ -1570,12 +1571,10 @@ ${ssrShaderMain}
1570
1571
  this.lowQualityFrames = 0;
1571
1572
  this.maskFrontRays = true;
1572
1573
  this.maskFrontFactor = -0.2;
1574
+ this.split = 0;
1573
1575
  this.materialExtension = {
1574
1576
  extraUniforms: {
1575
- tSSReflMap: () => {
1576
- var _a2;
1577
- return { value: ((_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) ?? null };
1578
- },
1577
+ tSSReflMap: () => ({ value: getOrCall(this.target)?.texture ?? null }),
1579
1578
  ssrPower: this.material.uniforms.power,
1580
1579
  ssrIntensity: this.material.uniforms.intensity,
1581
1580
  ssrMaskFrontFactor: this.material.uniforms.maskFrontFactor,
@@ -1592,8 +1591,7 @@ ${ssrShaderMain}
1592
1591
  // todo gbuffer stuff
1593
1592
  },
1594
1593
  shaderExtender: (shader, _material, _renderer) => {
1595
- var _a2, _b2;
1596
- if (!shader.defines.SSREFL_ENABLED) return;
1594
+ if (!shader.defines?.SSREFL_ENABLED) return;
1597
1595
  const ls = `
1598
1596
 
1599
1597
  ${ssreflPatch}
@@ -1610,24 +1608,21 @@ ${ssrShaderMain}
1610
1608
  ls,
1611
1609
  { prepend: true }
1612
1610
  );
1613
- (_b2 = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b2.call(_a2, shader, _material, _renderer);
1611
+ this._gbufferUnpackExtension?.shaderExtender?.(shader, _material, _renderer);
1614
1612
  },
1615
1613
  onObjectRender: (_object, material, renderer) => {
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;
1614
+ let x = this.enabled && renderer.userData.screenSpaceRendering !== false && !material.userData?.pluginsDisabled && !material.userData?.ssreflDisabled ? this.split > 0 ? 2 : 1 : 0;
1618
1615
  if (material.defines.SSREFL_ENABLED !== x) {
1619
1616
  material.defines.SSREFL_ENABLED = x;
1620
1617
  material.needsUpdate = true;
1621
1618
  }
1622
- x = ((_c = material.userData) == null ? void 0 : _c.ssreflNonPhysical) ? 1 : 0;
1619
+ x = material.userData?.ssreflNonPhysical ? 1 : 0;
1623
1620
  if (material.defines.SSR_NON_PHYSICAL !== x) {
1624
1621
  material.defines.SSR_NON_PHYSICAL = x;
1625
1622
  material.needsUpdate = true;
1626
1623
  }
1627
1624
  },
1628
- parsFragmentSnippet: () => {
1629
- var _a2, _b2;
1630
- return glsl`
1625
+ parsFragmentSnippet: () => glsl`
1631
1626
  #if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
1632
1627
  uniform float ssrPower;
1633
1628
  uniform float ssrIntensity;
@@ -1635,23 +1630,21 @@ ${ssrShaderMain}
1635
1630
  uniform vec3 ssrBoost;
1636
1631
  uniform sampler2D tSSReflMap;
1637
1632
  uniform sampler2D tLastFrame;
1638
- ${getTexelDecoding("tSSReflMap", (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture.colorSpace)}
1639
- ${getTexelDecoding("tLastFrame", (_b2 = this.material.uniforms.tLastFrame.value) == null ? void 0 : _b2.colorSpace)}
1633
+ ${getTexelDecoding("tSSReflMap", getOrCall(this.target)?.texture.colorSpace)}
1634
+ ${getTexelDecoding("tLastFrame", this.material.uniforms.tLastFrame.value?.colorSpace)}
1640
1635
  ${!this.inlineShaderRayTrace ? "" : `
1641
1636
  #define THREE_PACKING_INCLUDED // by threejs
1642
1637
  #include <cameraHelpers>
1643
1638
  #include <randomHelpers>
1644
1639
  ${samplePointHelpers}
1645
1640
  ${ssrtShader}
1646
- ${ssrShader}
1641
+ ${getShaders().ssReflection}
1647
1642
  `}
1648
1643
  #include <simpleCameraHelpers>
1649
1644
  #endif
1650
- `;
1651
- },
1645
+ `,
1652
1646
  computeCacheKey: () => {
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(",");
1647
+ return (this.enabled ? "1" : "0") + getOrCall(this.target)?.texture?.colorSpace + Object.values(this.material.defines).map((v) => v + "").join(",");
1655
1648
  },
1656
1649
  uuid: SSReflectionPlugin.PluginType,
1657
1650
  ...uiConfigMaterialExtension(this._getUiConfig.bind(this), SSReflectionPlugin.PluginType),
@@ -1675,13 +1668,17 @@ ${ssrShader}
1675
1668
  projection: this.material.uniforms.projection,
1676
1669
  cameraPositionWorld: this.material.uniforms.cameraPositionWorld,
1677
1670
  cameraNearFar: this.material.uniforms.cameraNearFar,
1678
- sceneBoundingRadius: this.material.uniforms.sceneBoundingRadius
1671
+ sceneBoundingRadius: this.material.uniforms.sceneBoundingRadius,
1672
+ // reprojection
1673
+ currentProjectionViewMatrix: this.material.uniforms.currentProjectionViewMatrix,
1674
+ lastProjectionViewMatrix: this.material.uniforms.lastProjectionViewMatrix,
1675
+ inverseViewMatrix: this.material.uniforms.inverseViewMatrix,
1676
+ ssrSplitX: this.material.uniforms.ssrSplitX
1679
1677
  });
1680
1678
  }
1681
1679
  }
1682
1680
  setDirty() {
1683
- var _a2, _b2;
1684
- (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
1681
+ this.materialExtension?.setDirty?.();
1685
1682
  super.setDirty();
1686
1683
  }
1687
1684
  render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
@@ -1763,85 +1760,90 @@ ${ssrShader}
1763
1760
  Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines);
1764
1761
  }
1765
1762
  };
1766
- __decorateClass$9([
1763
+ __decorateClass$a([
1767
1764
  uiSlider("Intensity", [0, 4]),
1768
1765
  serialize(),
1769
1766
  uniform()
1770
1767
  ], SSReflectionPluginPass.prototype, "intensity", 2);
1771
- __decorateClass$9([
1768
+ __decorateClass$a([
1772
1769
  uiVector("Boost"),
1773
1770
  serialize(),
1774
1771
  uniform()
1775
1772
  ], SSReflectionPluginPass.prototype, "boost", 2);
1776
- __decorateClass$9([
1773
+ __decorateClass$a([
1777
1774
  uiSlider("Object Radius", [0.01, 2]),
1778
1775
  serialize(),
1779
1776
  uniform()
1780
1777
  ], SSReflectionPluginPass.prototype, "objectRadius", 2);
1781
- __decorateClass$9([
1778
+ __decorateClass$a([
1782
1779
  uiToggle("Auto radius"),
1783
1780
  serialize(),
1784
1781
  uniform()
1785
1782
  ], SSReflectionPluginPass.prototype, "autoRadius", 2);
1786
- __decorateClass$9([
1783
+ __decorateClass$a([
1787
1784
  uiSlider("Power", [0, 3]),
1788
1785
  serialize(),
1789
1786
  uniform()
1790
1787
  ], SSReflectionPluginPass.prototype, "power", 2);
1791
- __decorateClass$9([
1788
+ __decorateClass$a([
1792
1789
  uiSlider("Tolerance", [0.1, 5]),
1793
1790
  serialize(),
1794
1791
  uniform()
1795
1792
  ], SSReflectionPluginPass.prototype, "tolerance", 2);
1796
- __decorateClass$9([
1793
+ __decorateClass$a([
1797
1794
  uiSlider("Roughness Factor", [0.1, 1.25]),
1798
1795
  serialize(),
1799
1796
  uniform({ propKey: "ssrRoughnessFactor" })
1800
1797
  ], SSReflectionPluginPass.prototype, "roughnessFactor", 2);
1801
- __decorateClass$9([
1802
- uiSlider("Step count", [1, 32], 1),
1798
+ __decorateClass$a([
1799
+ uiSlider("Step count", [1, 32], 1, { tags: ["performance"] }),
1803
1800
  serialize(),
1804
1801
  matDefine("SSR_STEP_COUNT", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1805
1802
  ], SSReflectionPluginPass.prototype, "stepCount", 2);
1806
- __decorateClass$9([
1807
- uiSlider("Ray count", [1, 8], 1),
1803
+ __decorateClass$a([
1804
+ uiSlider("Ray count", [1, 8], 1, { tags: ["performance"] }),
1808
1805
  serialize(),
1809
1806
  matDefine("SSR_RAY_COUNT", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1810
1807
  ], SSReflectionPluginPass.prototype, "rayCount", 2);
1811
- __decorateClass$9([
1808
+ __decorateClass$a([
1812
1809
  uiToggle("Ray Blend MAX"),
1813
1810
  serialize(),
1814
1811
  matDefineBool("SSR_RAY_BLEND_MAX", void 0, void 0, SSReflectionPluginPass.prototype.setDirty, true)
1815
1812
  ], SSReflectionPluginPass.prototype, "rayBlendMax", 2);
1816
- __decorateClass$9([
1813
+ __decorateClass$a([
1817
1814
  uiSlider("Low Quality Frames", [0, 4], 1),
1818
1815
  serialize(),
1819
1816
  matDefine("SSR_LOW_QUALITY_FRAMES", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1820
1817
  ], SSReflectionPluginPass.prototype, "lowQualityFrames", 2);
1821
- __decorateClass$9([
1818
+ __decorateClass$a([
1822
1819
  uiToggle("Ignore front rays"),
1823
1820
  serialize(),
1824
1821
  matDefineBool("SSR_MASK_FRONT_RAYS", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1825
1822
  ], SSReflectionPluginPass.prototype, "maskFrontRays", 2);
1826
- __decorateClass$9([
1823
+ __decorateClass$a([
1827
1824
  uiSlider("Mask front rays factor", [-1, 1], 0.01, (that) => ({ hidden: () => !that.maskFrontRays })),
1828
1825
  serialize(),
1829
1826
  uniform()
1830
1827
  ], SSReflectionPluginPass.prototype, "maskFrontFactor", 2);
1831
- SSReflectionPluginPass = __decorateClass$9([
1828
+ __decorateClass$a([
1829
+ uiSlider("Split", [0, 1], 0.01, { tags: ["debug"] }),
1830
+ serialize(),
1831
+ uniform({ propKey: "ssrSplitX", onChange: SSReflectionPluginPass.prototype.setDirty })
1832
+ ], SSReflectionPluginPass.prototype, "split", 2);
1833
+ SSReflectionPluginPass = __decorateClass$a([
1832
1834
  uiFolderContainer("SSReflection Pass")
1833
1835
  ], SSReflectionPluginPass);
1834
1836
  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);}";
1835
1837
  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;}";
1836
1838
  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.);}";
1837
- var __defProp$8 = Object.defineProperty;
1838
- var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
1839
- var __decorateClass$8 = (decorators, target, key, kind) => {
1840
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
1839
+ var __defProp$9 = Object.defineProperty;
1840
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
1841
+ var __decorateClass$9 = (decorators, target, key, kind) => {
1842
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
1841
1843
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
1842
1844
  if (decorator = decorators[i2])
1843
1845
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1844
- if (kind && result) __defProp$8(target, key, result);
1846
+ if (kind && result) __defProp$9(target, key, result);
1845
1847
  return result;
1846
1848
  };
1847
1849
  let OutlinePlugin = class extends AScreenPassExtensionPlugin {
@@ -1890,23 +1892,22 @@ let OutlinePlugin = class extends AScreenPassExtensionPlugin {
1890
1892
  side: DoubleSide
1891
1893
  });
1892
1894
  this._getSelectedObject = () => {
1893
- var _a2, _b2, _c, _d;
1894
1895
  if (!this._viewer) return;
1895
1896
  const picking = this._viewer.getPlugin(PickingPlugin);
1896
1897
  if (this.highlightSelectedMaterials) {
1897
- const mat = (_a2 = picking == null ? void 0 : picking.getSelectedObject()) == null ? void 0 : _a2.material;
1898
+ const mat = picking?.getSelectedObject()?.material;
1898
1899
  if (this.highlightMaterialSameNames && mat) {
1899
1900
  const names = Array.isArray(mat) ? mat.map((m) => m.name) : [mat.name];
1900
1901
  const mats = /* @__PURE__ */ new Set();
1901
1902
  for (const name of names) {
1902
- const mats1 = (_d = (_c = (_b2 = this._viewer) == null ? void 0 : _b2.assetManager) == null ? void 0 : _c.materials) == null ? void 0 : _d.findMaterialsByName(name);
1903
- mats1 == null ? void 0 : mats1.forEach((m) => mats.add(m));
1903
+ const mats1 = this._viewer?.assetManager?.materials?.findMaterialsByName(name);
1904
+ mats1?.forEach((m) => mats.add(m));
1904
1905
  }
1905
1906
  return [...mats];
1906
1907
  }
1907
1908
  return mat;
1908
1909
  }
1909
- return picking == null ? void 0 : picking.getSelectedObject();
1910
+ return picking?.getSelectedObject();
1910
1911
  };
1911
1912
  this._viewerListeners = {
1912
1913
  preRender: () => {
@@ -1922,28 +1923,29 @@ let OutlinePlugin = class extends AScreenPassExtensionPlugin {
1922
1923
  setDirty() {
1923
1924
  super.setDirty();
1924
1925
  if (!this._viewer) return;
1925
- const picking = this._viewer.getPlugin(PickingPlugin);
1926
1926
  const enabled = !this.isDisabled();
1927
- if (enabled && picking.widgetEnabled) {
1928
- picking.widgetEnabled = false;
1929
- this._pickingWidgetDisabled = true;
1930
- } else if (!enabled && this._pickingWidgetDisabled) {
1931
- picking.widgetEnabled = true;
1932
- this._pickingWidgetDisabled = false;
1927
+ const picking = this._viewer.getPlugin(PickingPlugin);
1928
+ if (picking) {
1929
+ if (enabled && picking.widgetEnabled) {
1930
+ picking.widgetEnabled = false;
1931
+ this._pickingWidgetDisabled = true;
1932
+ } else if (!enabled && this._pickingWidgetDisabled) {
1933
+ picking.widgetEnabled = true;
1934
+ this._pickingWidgetDisabled = false;
1935
+ }
1933
1936
  }
1934
1937
  this._viewer.setDirty();
1935
1938
  }
1936
1939
  onAdded(viewer) {
1937
- var _a2;
1938
1940
  super.onAdded(viewer);
1939
1941
  this.setDirty();
1940
1942
  this._pass = this._createPass();
1941
- (_a2 = this._pass.onDirty) == null ? void 0 : _a2.push(viewer.setDirty);
1943
+ this._pass.onDirty?.push(viewer.setDirty);
1942
1944
  viewer.renderManager.registerPass(this._pass);
1943
1945
  const pickingPlugin = viewer.getPlugin(PickingPlugin);
1944
- pickingPlugin == null ? void 0 : pickingPlugin.addEventListener("selectedObjectChanged", () => {
1946
+ pickingPlugin?.addEventListener("selectedObjectChanged", () => {
1945
1947
  if (!this._animationCallBack && this) {
1946
- if (pickingPlugin == null ? void 0 : pickingPlugin.getSelectedObject()) {
1948
+ if (pickingPlugin?.getSelectedObject()) {
1947
1949
  if (this.enableDynamicSelection) {
1948
1950
  this.transparency = 1;
1949
1951
  this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 400);
@@ -1959,7 +1961,7 @@ let OutlinePlugin = class extends AScreenPassExtensionPlugin {
1959
1961
  if (!this) return;
1960
1962
  if (!this.mouseInOutAnimationEnabled) return;
1961
1963
  if (!this.enableHighlight) return;
1962
- const selectedObject = pickingPlugin == null ? void 0 : pickingPlugin.getSelectedObject();
1964
+ const selectedObject = pickingPlugin?.getSelectedObject();
1963
1965
  if (selectedObject && this.enableDynamicSelection) {
1964
1966
  if (e2.target !== viewer.canvas) {
1965
1967
  if (!this._animationCallBack && this._state === "in") {
@@ -2051,61 +2053,61 @@ let OutlinePlugin = class extends AScreenPassExtensionPlugin {
2051
2053
  };
2052
2054
  OutlinePlugin.PluginType = "OutlinePlugin";
2053
2055
  OutlinePlugin.OldPluginType = "Outline";
2054
- __decorateClass$8([
2056
+ __decorateClass$9([
2055
2057
  onChange(OutlinePlugin.prototype.setDirty),
2056
2058
  uiToggle("Enable"),
2057
2059
  serialize()
2058
2060
  ], OutlinePlugin.prototype, "enabled", 2);
2059
- __decorateClass$8([
2061
+ __decorateClass$9([
2060
2062
  uiToggle("Highlight"),
2061
2063
  uniform({ propKey: "enableHighlight" }),
2062
2064
  serialize()
2063
2065
  ], OutlinePlugin.prototype, "enableHighlight", 2);
2064
- __decorateClass$8([
2066
+ __decorateClass$9([
2065
2067
  onChange(OutlinePlugin.prototype.setDirty),
2066
2068
  uiToggle("DynamicSelection"),
2067
2069
  serialize()
2068
2070
  ], OutlinePlugin.prototype, "enableDynamicSelection", 2);
2069
- __decorateClass$8([
2071
+ __decorateClass$9([
2070
2072
  uiSlider("Intensity", [0, 4], 1e-3),
2071
2073
  uniform({ propKey: "outlineIntensity" }),
2072
2074
  serialize("outlineIntensity")
2073
2075
  ], OutlinePlugin.prototype, "intensity", 2);
2074
- __decorateClass$8([
2076
+ __decorateClass$9([
2075
2077
  onChange(OutlinePlugin.prototype.setDirty),
2076
2078
  uiSlider("Transparency", [0, 1], 0.01),
2077
2079
  serialize()
2078
2080
  ], OutlinePlugin.prototype, "highlightTransparency", 2);
2079
- __decorateClass$8([
2081
+ __decorateClass$9([
2080
2082
  uiColor("Color"),
2081
2083
  uniform({ propKey: "outlineColor" }),
2082
2084
  serialize("outlineColor")
2083
2085
  ], OutlinePlugin.prototype, "color", 2);
2084
- __decorateClass$8([
2086
+ __decorateClass$9([
2085
2087
  uiSlider("Thickness", [0, 10], 0.01),
2086
2088
  uniform({ propKey: "outlineThickness" }),
2087
2089
  serialize("outlineThickness")
2088
2090
  ], OutlinePlugin.prototype, "thickness", 2);
2089
- __decorateClass$8([
2091
+ __decorateClass$9([
2090
2092
  uiToggle("Debug"),
2091
2093
  matDefineBool("DEBUG_OUTLINE", void 0, true)
2092
2094
  ], OutlinePlugin.prototype, "debugOutline", 2);
2093
- __decorateClass$8([
2095
+ __decorateClass$9([
2094
2096
  onChange(OutlinePlugin.prototype.setDirty),
2095
2097
  uiToggle("Highlight Selected Materials")
2096
2098
  ], OutlinePlugin.prototype, "highlightSelectedMaterials", 2);
2097
- __decorateClass$8([
2099
+ __decorateClass$9([
2098
2100
  onChange(OutlinePlugin.prototype.setDirty),
2099
2101
  uiToggle("Highlight Materials (same name)")
2100
2102
  ], OutlinePlugin.prototype, "highlightMaterialSameNames", 2);
2101
- __decorateClass$8([
2103
+ __decorateClass$9([
2102
2104
  uniform({ propKey: "highlightTransparency" })
2103
2105
  ], OutlinePlugin.prototype, "transparency", 2);
2104
- __decorateClass$8([
2106
+ __decorateClass$9([
2105
2107
  uniform({ propKey: "outlineBuffer" }),
2106
2108
  uiImage("Outline Buffer", { readOnly: true })
2107
2109
  ], OutlinePlugin.prototype, "texture", 2);
2108
- OutlinePlugin = __decorateClass$8([
2110
+ OutlinePlugin = __decorateClass$9([
2109
2111
  uiFolderContainer("Outline")
2110
2112
  ], OutlinePlugin);
2111
2113
  let OutlineRenderPass = class extends RenderPass {
@@ -2153,10 +2155,7 @@ let OutlineRenderPass = class extends RenderPass {
2153
2155
  _renderSelectedObject(renderer, selectedObject, writeBuffer, deltaTime, maskActive) {
2154
2156
  if (!this.camera) return;
2155
2157
  const selectionLayer = 6;
2156
- const objs = (Array.isArray(selectedObject) ? selectedObject : [selectedObject]).map((o) => {
2157
- var _a2;
2158
- return (o == null ? void 0 : o.isMaterial) ? [...(_a2 = o.appliedMeshes) == null ? void 0 : _a2.values()] : o;
2159
- }).flat();
2158
+ const objs = (Array.isArray(selectedObject) ? selectedObject : [selectedObject]).map((o) => o?.isMaterial ? [...o.appliedMeshes?.values()] : o).flat();
2160
2159
  for (const o1 of objs) {
2161
2160
  o1.traverse((o) => {
2162
2161
  o.layers.enable(selectionLayer);
@@ -2182,11 +2181,10 @@ let OutlineRenderPass = class extends RenderPass {
2182
2181
  this.camera.layers.mask = mask;
2183
2182
  }
2184
2183
  dispose() {
2185
- var _a2;
2186
2184
  this.onDirty = [];
2187
2185
  this.scene = void 0;
2188
2186
  this.camera = void 0;
2189
- (_a2 = super.dispose) == null ? void 0 : _a2.call(this);
2187
+ super.dispose?.();
2190
2188
  }
2191
2189
  setDirty() {
2192
2190
  this.onDirty.forEach((v) => v());
@@ -2197,22 +2195,21 @@ let OutlineRenderPass = class extends RenderPass {
2197
2195
  camera.updateShaderProperties(this.overrideMaterial);
2198
2196
  }
2199
2197
  };
2200
- __decorateClass$8([
2198
+ __decorateClass$9([
2201
2199
  uiToggle("Enabled")
2202
2200
  ], OutlineRenderPass.prototype, "enabled", 2);
2203
- OutlineRenderPass = __decorateClass$8([
2201
+ OutlineRenderPass = __decorateClass$9([
2204
2202
  uiFolderContainer((c) => c.passId + " Render Pass")
2205
2203
  ], OutlineRenderPass);
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";
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.));}";
2204
+ const ssgiPatch = "\n#if defined(SSRTAO_ENABLED) && SSRTAO_ENABLED > 0\nvec3 screenPos_gi=viewToScreen(vViewPosition.xyz);\n#if SSRTAO_ENABLED == 2\nif(screenPos_gi.x>ssrtaoSplitX){\n#endif\nvec4 ssgi=tSSGIMapTexelToLinear(texture2D(tSSGIMap,screenPos_gi.xy));float ambientOcclusion=1.-ssgi.a;ambientOcclusion=max(0.,ambientOcclusion);ambientOcclusion=pow(ambientOcclusion,ssaoPower);ambientOcclusion=min(1.,ambientOcclusion);reflectedLight.indirectDiffuse*=ambientOcclusion;\n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\nvec3 ssgiColor=ssgi.rgb*ssgiIntensity;reflectedLight.indirectDiffuse+=ssgiColor*(material.diffuseColor.rgb);\n#endif\n#if defined( USE_ENVMAP )\nfloat dotNV=saturate(dot(geometryNormal,geometryViewDir));float specularOcclusion=saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*material.roughness-1.0))-1.0+ambientOcclusion);reflectedLight.indirectSpecular*=specularOcclusion;\n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\n#if !defined(SSR_ENABLED) || SSR_ENABLED < 1\nreflectedLight.indirectSpecular+=ssgiColor*material.specularColor;\n#endif\n#endif\n#endif\n#if SSRTAO_ENABLED == 2\n}\n#endif\n#endif\n";
2208
2205
  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;}";
2209
- var __defProp$7 = Object.defineProperty;
2210
- var __decorateClass$7 = (decorators, target, key, kind) => {
2206
+ var __defProp$8 = Object.defineProperty;
2207
+ var __decorateClass$8 = (decorators, target, key, kind) => {
2211
2208
  var result = void 0;
2212
2209
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
2213
2210
  if (decorator = decorators[i2])
2214
2211
  result = decorator(target, key, result) || result;
2215
- if (result) __defProp$7(target, key, result);
2212
+ if (result) __defProp$8(target, key, result);
2216
2213
  return result;
2217
2214
  };
2218
2215
  class BilateralFilterPass extends ExtendedShaderPass {
@@ -2243,36 +2240,35 @@ class BilateralFilterPass extends ExtendedShaderPass {
2243
2240
  this.needsSwap = false;
2244
2241
  }
2245
2242
  render(renderer, writeBuffer, _readBuffer, deltaTime, maskActive) {
2246
- var _a2, _b2, _c, _d;
2247
2243
  if (!this.enabled) return;
2248
2244
  const target = getOrCall(this.target);
2249
2245
  if (!target) return;
2250
2246
  this.uniforms.bilDirection.value.set(1, 0);
2251
2247
  this.uniforms.tDiffuse.value = target.texture;
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);
2248
+ this.uniforms.tDiffuseSize.value.set(this.uniforms.tDiffuse.value?.image.width || 0, this.uniforms.tDiffuse.value?.image.height || 0);
2253
2249
  super.render(renderer, writeBuffer, target, deltaTime, maskActive);
2254
2250
  this.uniforms.bilDirection.value.set(0, 1);
2255
2251
  this.uniforms.tDiffuse.value = writeBuffer.texture;
2256
- this.uniforms.tDiffuseSize.value.set(((_c = this.uniforms.tDiffuse.value) == null ? void 0 : _c.image.width) || 0, ((_d = this.uniforms.tDiffuse.value) == null ? void 0 : _d.image.height) || 0);
2252
+ this.uniforms.tDiffuseSize.value.set(this.uniforms.tDiffuse.value?.image.width || 0, this.uniforms.tDiffuse.value?.image.height || 0);
2257
2253
  super.render(renderer, target, writeBuffer, deltaTime, maskActive);
2258
2254
  }
2259
2255
  }
2260
- __decorateClass$7([
2256
+ __decorateClass$8([
2261
2257
  serialize(),
2262
2258
  uniform()
2263
2259
  ], BilateralFilterPass.prototype, "smoothEnabled");
2264
- __decorateClass$7([
2260
+ __decorateClass$8([
2265
2261
  serialize(),
2266
2262
  uniform()
2267
2263
  ], BilateralFilterPass.prototype, "edgeSharpness");
2268
- var __defProp$6 = Object.defineProperty;
2269
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
2270
- var __decorateClass$6 = (decorators, target, key, kind) => {
2271
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
2264
+ var __defProp$7 = Object.defineProperty;
2265
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
2266
+ var __decorateClass$7 = (decorators, target, key, kind) => {
2267
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
2272
2268
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
2273
2269
  if (decorator = decorators[i2])
2274
2270
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2275
- if (kind && result) __defProp$6(target, key, result);
2271
+ if (kind && result) __defProp$7(target, key, result);
2276
2272
  return result;
2277
2273
  };
2278
2274
  const passId = "ssrtgi";
@@ -2334,6 +2330,11 @@ let SSGIPlugin = class extends PipelinePassPlugin {
2334
2330
  if (viewer.getPlugin("Ground") || viewer.getPlugin("BaseGroundPlugin")) console.error("GroundPlugin must be added after SSGIPlugin");
2335
2331
  this._gbufferUnpackExtensionChanged();
2336
2332
  viewer.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
2333
+ viewer.forPlugin(VelocityBufferPlugin, (vbp) => {
2334
+ this._pass?.material.registerMaterialExtensions([vbp.unpackExtension]);
2335
+ }, (vbp) => {
2336
+ this._pass?.material?.unregisterMaterialExtensions([vbp.unpackExtension]);
2337
+ });
2337
2338
  }
2338
2339
  onRemove(viewer) {
2339
2340
  this._disposeTarget();
@@ -2341,8 +2342,7 @@ let SSGIPlugin = class extends PipelinePassPlugin {
2341
2342
  return super.onRemove(viewer);
2342
2343
  }
2343
2344
  fromJSON(data, meta) {
2344
- var _a2;
2345
- if ((_a2 = data.passes) == null ? void 0 : _a2.ssrtgi) {
2345
+ if (data.passes?.ssrtgi) {
2346
2346
  data = { ...data };
2347
2347
  data.pass = data.passes.ssrtgi;
2348
2348
  delete data.passes;
@@ -2351,18 +2351,17 @@ let SSGIPlugin = class extends PipelinePassPlugin {
2351
2351
  return super.fromJSON(data, meta);
2352
2352
  }
2353
2353
  _beforeRender(_, _1, _2) {
2354
- var _a2, _b2;
2355
2354
  if (!this._viewer) return false;
2356
2355
  const e2 = super._beforeRender(_, _1, _2);
2357
2356
  if (e2) {
2358
- const ssao = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin("SSAOPlugin");
2357
+ const ssao = this._viewer?.getPlugin("SSAOPlugin");
2359
2358
  if (ssao && !ssao.isDisabled()) {
2360
2359
  ssao.disable(SSGIPlugin.PluginType);
2361
2360
  }
2362
2361
  }
2363
2362
  if (!e2) return e2;
2364
2363
  const progressive = this._viewer.getPlugin(ProgressivePlugin);
2365
- (_b2 = this._pass) == null ? void 0 : _b2.updateShaderProperties([progressive]);
2364
+ this._pass?.updateShaderProperties([progressive]);
2366
2365
  return e2;
2367
2366
  }
2368
2367
  /**
@@ -2375,13 +2374,13 @@ let SSGIPlugin = class extends PipelinePassPlugin {
2375
2374
  };
2376
2375
  SSGIPlugin.PluginType = "SSGIPlugin";
2377
2376
  SSGIPlugin.OldPluginType = "SSGI";
2378
- __decorateClass$6([
2377
+ __decorateClass$7([
2379
2378
  uiImage("SSGI Buffer", { readOnly: true })
2380
2379
  ], SSGIPlugin.prototype, "texture", 2);
2381
- __decorateClass$6([
2382
- uiConfig()
2380
+ __decorateClass$7([
2381
+ uiConfig(void 0, { unwrapContents: true })
2383
2382
  ], SSGIPlugin.prototype, "_pass", 2);
2384
- SSGIPlugin = __decorateClass$6([
2383
+ SSGIPlugin = __decorateClass$7([
2385
2384
  uiFolderContainer("SSGI Plugin")
2386
2385
  ], SSGIPlugin);
2387
2386
  let SSGIPluginPass = class extends ExtendedShaderPass {
@@ -2430,8 +2429,14 @@ let SSGIPluginPass = class extends ExtendedShaderPass {
2430
2429
  // maskFrontFactor: {value: -0.1},
2431
2430
  tolerance: { value: 0 },
2432
2431
  // ssrtaoRoughnessFactor: {value: 1},
2433
- sceneBoundingRadius: { value: 0 }
2432
+ sceneBoundingRadius: { value: 0 },
2434
2433
  // todo do same in SSAO
2434
+ // reprojection/velocity
2435
+ currentProjectionViewMatrix: { value: new Matrix4() },
2436
+ lastProjectionViewMatrix: { value: new Matrix4() },
2437
+ inverseViewMatrix: { value: new Matrix4() },
2438
+ // split mode
2439
+ ssrtaoSplitX: { value: 0.5 }
2435
2440
  },
2436
2441
  vertexShader: shaderUtils.defaultVertex,
2437
2442
  fragmentShader: `
@@ -2446,7 +2451,7 @@ ${samplePointHelpers}
2446
2451
 
2447
2452
  ${ssrtShader}
2448
2453
 
2449
- ${ssrtaoShader}
2454
+ ${getShaders().calculateGI}
2450
2455
  `
2451
2456
  }, "tDiffuse", "tLastThis", "tLastFrame");
2452
2457
  this.target = target;
@@ -2465,15 +2470,14 @@ ${ssrtaoShader}
2465
2470
  this.stepCount = 8;
2466
2471
  this.smoothEnabled = true;
2467
2472
  this.renderWithCamera = true;
2473
+ this.split = 0;
2468
2474
  this.materialExtension = {
2469
2475
  // todo set priority wrt ssr etc
2470
2476
  extraUniforms: {
2471
- tSSGIMap: () => {
2472
- var _a2;
2473
- return { value: ((_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) ?? null };
2474
- },
2477
+ tSSGIMap: () => ({ value: getOrCall(this.target)?.texture ?? null }),
2475
2478
  ssaoPower: this.material.uniforms.power,
2476
- ssgiIntensity: this.material.uniforms.intensity
2479
+ ssgiIntensity: this.material.uniforms.intensity,
2480
+ ssrtaoSplitX: this.material.uniforms.ssrtaoSplitX
2477
2481
  // ssrMaskFrontFactor: this.material.uniforms.maskFrontFactor,
2478
2482
  },
2479
2483
  extraDefines: {
@@ -2485,7 +2489,7 @@ ${ssrtaoShader}
2485
2489
  // todo gbuffer stuff
2486
2490
  },
2487
2491
  shaderExtender: (shader, _material, _renderer) => {
2488
- if (!shader.defines.SSRTAO_ENABLED) return;
2492
+ if (!shader.defines?.SSRTAO_ENABLED) return;
2489
2493
  const ls = `
2490
2494
 
2491
2495
  ${ssgiPatch}
@@ -2506,34 +2510,32 @@ ${ssrtaoShader}
2506
2510
  shader.fragmentShader = shaderReplaceString(shader.fragmentShader, "#include <aomap_fragment>", "");
2507
2511
  },
2508
2512
  onObjectRender: (_object, material, renderer) => {
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;
2513
+ let x = this.enabled && (this.renderWithCamera || renderer.renderManager.frameCount > 1) && renderer.userData.screenSpaceRendering !== false && !material.userData?.pluginsDisabled && !material.userData?.ssrtaoDisabled && !material.userData?.ssaoDisabled ? this.split > 0 ? 2 : 1 : 0;
2511
2514
  if (material.defines.SSRTAO_ENABLED !== x) {
2512
2515
  material.defines.SSRTAO_ENABLED = x;
2513
2516
  material.needsUpdate = true;
2514
2517
  }
2515
2518
  },
2516
- parsFragmentSnippet: (_renderer) => {
2517
- var _a2;
2518
- return glsl`
2519
+ parsFragmentSnippet: (_renderer) => glsl`
2519
2520
  #if defined(SSRTAO_ENABLED) && SSRTAO_ENABLED > 0
2520
2521
  uniform float ssaoPower;
2521
2522
  uniform float ssgiIntensity;
2522
2523
  uniform sampler2D tSSGIMap;
2523
- ${getTexelDecoding("tSSGIMap", (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture.colorSpace)}
2524
+ #if defined(SSRTAO_ENABLED) && SSRTAO_ENABLED == 2
2525
+ uniform float ssrtaoSplitX;
2526
+ #endif
2527
+ ${getTexelDecoding("tSSGIMap", getOrCall(this.target)?.texture.colorSpace)}
2524
2528
  ${/*tLastFrame not requried in material extension
2525
- // uniform sampler2D tLastFrame;
2526
- ${getTexelDecoding('tLastFrame', this.material.uniforms!.tLastFrame.value?.colorSpace)}
2527
- */
2528
- ""}
2529
+ // uniform sampler2D tLastFrame;
2530
+ ${getTexelDecoding('tLastFrame', this.material.uniforms!.tLastFrame.value?.colorSpace)}
2531
+ */
2532
+ ""}
2529
2533
  #include <simpleCameraHelpers>
2530
2534
  #endif
2531
- `;
2532
- },
2535
+ `,
2533
2536
  computeCacheKey: () => {
2534
- var _a2;
2535
- const tex = (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture;
2536
- return (this.enabled ? "1" : "0") + (tex == null ? void 0 : tex.colorSpace) + (tex == null ? void 0 : tex.uuid) + Object.values(this.material.defines).map((v) => v + "").join(",");
2537
+ const tex = getOrCall(this.target)?.texture;
2538
+ return (this.enabled ? "1" : "0") + tex?.colorSpace + tex?.uuid + Object.values(this.material.defines).map((v) => v + "").join(",");
2537
2539
  },
2538
2540
  uuid: SSGIPlugin.PluginType,
2539
2541
  ...uiConfigMaterialExtension(this._getUiConfig.bind(this), SSGIPlugin.PluginType),
@@ -2569,10 +2571,13 @@ ${ssrtaoShader}
2569
2571
  if (this.smoothEnabled) {
2570
2572
  this.bilateralPass.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
2571
2573
  }
2574
+ this.uniforms.lastProjectionViewMatrix.value.copy(this.uniforms.currentProjectionViewMatrix.value);
2572
2575
  }
2573
2576
  beforeRender(scene, camera, renderManager) {
2574
2577
  if (!this.enabled) return;
2575
2578
  this.updateShaderProperties([scene, camera, renderManager]);
2579
+ this.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
2580
+ this.uniforms.inverseViewMatrix.value.copy(camera.matrixWorld);
2576
2581
  }
2577
2582
  /**
2578
2583
  * Returns a uiConfig to toggle SSGI on a material.
@@ -2634,84 +2639,88 @@ ${ssrtaoShader}
2634
2639
  }
2635
2640
  // todo update gbuffer flag like in AO?
2636
2641
  setDirty() {
2637
- var _a2, _b2;
2638
- (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
2642
+ this.materialExtension?.setDirty?.();
2639
2643
  super.setDirty();
2640
2644
  }
2641
2645
  };
2642
- __decorateClass$6([
2646
+ __decorateClass$7([
2643
2647
  serialize()
2644
2648
  ], SSGIPluginPass.prototype, "bilateralPass", 2);
2645
- __decorateClass$6([
2649
+ __decorateClass$7([
2646
2650
  uiToggle("GI Enabled"),
2647
2651
  serialize(),
2648
2652
  matDefineBool("SSGI_ENABLED", void 0, void 0, SSGIPluginPass.prototype.setDirty, false)
2649
2653
  ], SSGIPluginPass.prototype, "giEnabled", 2);
2650
- __decorateClass$6([
2654
+ __decorateClass$7([
2651
2655
  uiSlider("Intensity", [0, 4]),
2652
2656
  serialize(),
2653
2657
  uniform()
2654
2658
  ], SSGIPluginPass.prototype, "intensity", 2);
2655
- __decorateClass$6([
2659
+ __decorateClass$7([
2656
2660
  uiSlider("Power", [0, 3]),
2657
2661
  serialize(),
2658
2662
  uniform()
2659
2663
  ], SSGIPluginPass.prototype, "power", 2);
2660
- __decorateClass$6([
2664
+ __decorateClass$7([
2661
2665
  uiToggle("Auto radius"),
2662
2666
  serialize(),
2663
2667
  uniform()
2664
2668
  ], SSGIPluginPass.prototype, "autoRadius", 2);
2665
- __decorateClass$6([
2669
+ __decorateClass$7([
2666
2670
  uiSlider("Object Radius", [0.01, 10]),
2667
2671
  serialize(),
2668
2672
  uniform()
2669
2673
  ], SSGIPluginPass.prototype, "objectRadius", 2);
2670
- __decorateClass$6([
2674
+ __decorateClass$7([
2671
2675
  uiSlider("Tolerance", [0.1, 5]),
2672
2676
  serialize(),
2673
2677
  uniform()
2674
2678
  ], SSGIPluginPass.prototype, "tolerance", 2);
2675
- __decorateClass$6([
2679
+ __decorateClass$7([
2676
2680
  uiSlider("Bias", [-0.3, 0.3]),
2677
2681
  serialize(),
2678
2682
  uniform()
2679
2683
  ], SSGIPluginPass.prototype, "bias", 2);
2680
- __decorateClass$6([
2684
+ __decorateClass$7([
2681
2685
  uiSlider("Falloff", [1e-4, 4]),
2682
2686
  serialize(),
2683
2687
  uniform()
2684
2688
  ], SSGIPluginPass.prototype, "falloff", 2);
2685
- __decorateClass$6([
2686
- uiSlider("Ray Count", [1, 5], 1),
2689
+ __decorateClass$7([
2690
+ uiSlider("Ray Count", [1, 5], 1, { tags: ["performance"] }),
2687
2691
  serialize(),
2688
2692
  uniform()
2689
2693
  ], SSGIPluginPass.prototype, "rayCount", 2);
2690
- __decorateClass$6([
2691
- uiSlider("Step count", [1, 16], 1),
2694
+ __decorateClass$7([
2695
+ uiSlider("Step count", [1, 16], 1, { tags: ["performance"] }),
2692
2696
  serialize(),
2693
2697
  matDefine("RTAO_STEP_COUNT", void 0, void 0, SSGIPluginPass.prototype.setDirty)
2694
2698
  ], SSGIPluginPass.prototype, "stepCount", 2);
2695
- __decorateClass$6([
2699
+ __decorateClass$7([
2696
2700
  uiToggle("Smooth Enabled"),
2697
2701
  serialize()
2698
2702
  ], SSGIPluginPass.prototype, "smoothEnabled", 2);
2699
- __decorateClass$6([
2703
+ __decorateClass$7([
2700
2704
  uiToggle("Render with Camera")
2701
2705
  ], SSGIPluginPass.prototype, "renderWithCamera", 2);
2702
- SSGIPluginPass = __decorateClass$6([
2706
+ __decorateClass$7([
2707
+ uiSlider("Split", [0, 1], 0.01, { tags: ["debug"] }),
2708
+ serialize(),
2709
+ uniform({ propKey: "ssrtaoSplitX", onChange: SSGIPluginPass.prototype.setDirty })
2710
+ ], SSGIPluginPass.prototype, "split", 2);
2711
+ SSGIPluginPass = __decorateClass$7([
2703
2712
  uiFolderContainer("SSGI Pass")
2704
2713
  ], SSGIPluginPass);
2705
2714
  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);}";
2706
2715
  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));";
2707
- var __defProp$5 = Object.defineProperty;
2708
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2709
- var __decorateClass$5 = (decorators, target, key, kind) => {
2710
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
2716
+ var __defProp$6 = Object.defineProperty;
2717
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
2718
+ var __decorateClass$6 = (decorators, target, key, kind) => {
2719
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
2711
2720
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
2712
2721
  if (decorator = decorators[i2])
2713
2722
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2714
- if (kind && result) __defProp$5(target, key, result);
2723
+ if (kind && result) __defProp$6(target, key, result);
2715
2724
  return result;
2716
2725
  };
2717
2726
  let AnisotropyPlugin = class extends AViewerPluginSync {
@@ -2734,9 +2743,8 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2734
2743
  priority: 10,
2735
2744
  // more than sscs(which is 5)
2736
2745
  shaderExtender: (shader, material, _renderer) => {
2737
- var _a2;
2738
- if (this.isDisabled() || !(material == null ? void 0 : material.userData._isAnisotropic)) return;
2739
- const rotMap = (_a2 = material.userData) == null ? void 0 : _a2._anisotropyDirectionMap;
2746
+ if (this.isDisabled() || !material?.userData._isAnisotropic) return;
2747
+ const rotMap = material.userData?._anisotropyDirectionMap;
2740
2748
  const bsdfs = glsl`
2741
2749
  //#if ANISOTROPY_ENABLED
2742
2750
  #include <randomHelpers>
@@ -2744,7 +2752,7 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2744
2752
  #define D_frameCount
2745
2753
  uniform float frameCount;
2746
2754
  #endif
2747
- ${rotMap ? getTexelDecoding("anisotropyDirectionMap", rotMap == null ? void 0 : rotMap.colorSpace) : ""}\n
2755
+ ${rotMap ? getTexelDecoding("anisotropyDirectionMap", rotMap?.colorSpace) : ""}\n
2748
2756
  `;
2749
2757
  shader.fragmentShader = shaderReplaceString(shader.fragmentShader, "#include <common>", bsdfs, { append: true });
2750
2758
  shader.fragmentShader = shader.fragmentShader.replace("#include <lights_fragment_begin>", ShaderChunk.lights_fragment_begin);
@@ -2819,22 +2827,22 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2819
2827
  `,
2820
2828
  { prepend: true }
2821
2829
  );
2830
+ if (!shader.defines) shader.defines = {};
2822
2831
  shader.defines.USE_ANISOTROPY_BRDF = "";
2823
2832
  shader.defines.USE_UV = "";
2824
2833
  shader.vertexTangents = true;
2825
2834
  },
2826
2835
  onObjectRender: (object, material) => {
2827
- var _a2, _b2;
2828
2836
  const userData = material.userData;
2829
- if (!(userData == null ? void 0 : userData._isAnisotropic)) return;
2837
+ if (!userData?._isAnisotropic) return;
2830
2838
  if (!object.isMesh || !object.geometry) return;
2831
2839
  if (!object.geometry.attributes.tangent) {
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);
2840
+ this._viewer?.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);
2833
2841
  }
2834
2842
  this._uniforms.anisotropyFactor.value = userData._anisotropyFactor ?? 1;
2835
2843
  this._uniforms.anisotropyNoise.value = userData._anisotropyNoise ?? 0;
2836
2844
  this._uniforms.anisotropyDirection.value = userData._anisotropyDirection ?? 1;
2837
- const tex = ((_b2 = userData._anisotropyDirectionMap) == null ? void 0 : _b2.isTexture) ? userData._anisotropyDirectionMap : null;
2845
+ const tex = userData._anisotropyDirectionMap?.isTexture ? userData._anisotropyDirectionMap : null;
2838
2846
  this._uniforms.anisotropyDirectionMap.value = tex;
2839
2847
  if (tex) {
2840
2848
  tex.updateMatrix();
@@ -2851,18 +2859,14 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2851
2859
  // ...this._uniforms, // done in constructor
2852
2860
  },
2853
2861
  computeCacheKey: (material1) => {
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);
2862
+ return (this.enabled ? "1" : "0") + (material1.userData?._isAnisotropic ? "1" : "0") + material1.userData?._anisotropyDirectionMap?.uuid;
2856
2863
  },
2857
2864
  isCompatible: (material1) => material1.isPhysicalMaterial,
2858
- updaters: () => {
2859
- var _a2;
2860
- return [
2861
- // this._viewer?.getPlugin(ProgressivePlugin),
2862
- // this._viewer?.scene.mainCamera,
2863
- (_a2 = this._viewer) == null ? void 0 : _a2.renderManager
2864
- ];
2865
- },
2865
+ updaters: () => [
2866
+ // this._viewer?.getPlugin(ProgressivePlugin),
2867
+ // this._viewer?.scene.mainCamera,
2868
+ this._viewer?.renderManager
2869
+ ],
2866
2870
  getUiConfig: (material) => {
2867
2871
  const viewer = this._viewer;
2868
2872
  const enableAnisotropy = this.enableAnisotropy.bind(this);
@@ -2882,7 +2886,6 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2882
2886
  return state._isAnisotropic || false;
2883
2887
  },
2884
2888
  set value(v) {
2885
- var _a2;
2886
2889
  if (v === state._isAnisotropic) return;
2887
2890
  if (v) {
2888
2891
  if (!enableAnisotropy(material))
@@ -2891,7 +2894,7 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2891
2894
  state._isAnisotropic = false;
2892
2895
  if (material.setDirty) material.setDirty();
2893
2896
  }
2894
- (_a2 = config.uiRefresh) == null ? void 0 : _a2.call(config, true, "postFrame");
2897
+ config.uiRefresh?.(true, "postFrame");
2895
2898
  }
2896
2899
  },
2897
2900
  {
@@ -2923,9 +2926,8 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2923
2926
  label: value
2924
2927
  })),
2925
2928
  onChange: () => {
2926
- var _a2;
2927
2929
  if (material.setDirty) material.setDirty();
2928
- (_a2 = config.uiRefresh) == null ? void 0 : _a2.call(config, true, "postFrame");
2930
+ config.uiRefresh?.(true, "postFrame");
2929
2931
  }
2930
2932
  },
2931
2933
  {
@@ -2952,35 +2954,29 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
2952
2954
  },
2953
2955
  // todo errors will be fixed on threepipe update
2954
2956
  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]));
2957
+ if (!material.userData?._isAnisotropic) return;
2958
+ material.userData.__appliedMeshes?.forEach((m) => this.tryComputeTangents(m, [material]));
2958
2959
  },
2959
2960
  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]));
2961
+ if (!material.userData?._isAnisotropic) return;
2962
+ material.userData.__appliedMeshes?.forEach((m) => this.tryComputeTangents(m, [material]));
2963
2963
  },
2964
2964
  onAddToMesh: (mesh) => {
2965
2965
  if (!mesh.isMesh) return;
2966
2966
  const m = mesh;
2967
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;
2968
+ if (!mats.find((m1) => m1?.userData?._isAnisotropic)) return;
2972
2969
  this.tryComputeTangents(m, mats);
2973
2970
  }
2974
2971
  };
2975
2972
  this.setDirty = () => {
2976
- var _a2, _b2, _c;
2977
- (_b2 = (_a2 = this.materialExtension).setDirty) == null ? void 0 : _b2.call(_a2);
2978
- (_c = this._viewer) == null ? void 0 : _c.setDirty();
2973
+ this.materialExtension.setDirty?.();
2974
+ this._viewer?.setDirty();
2979
2975
  };
2980
2976
  Object.assign(this.materialExtension.extraUniforms, this._uniforms);
2981
2977
  }
2982
2978
  enableAnisotropy(material, map, factor, noise, directionMode) {
2983
- const ud = material == null ? void 0 : material.userData;
2979
+ const ud = material?.userData;
2984
2980
  if (!ud) return false;
2985
2981
  if (ud._isAnisotropic === void 0) {
2986
2982
  const meshes = material.appliedMeshes;
@@ -3015,8 +3011,7 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
3015
3011
  }
3016
3012
  if (possible) m.geometry.computeTangents();
3017
3013
  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;
3014
+ if (m1?.userData?._isAnisotropic) m1.userData._isAnisotropic = false;
3020
3015
  });
3021
3016
  }
3022
3017
  }
@@ -3026,8 +3021,7 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
3026
3021
  v.assetManager.registerGltfExtension(anisotropyGLTFExtension);
3027
3022
  }
3028
3023
  onRemove(v) {
3029
- var _a2;
3030
- (_a2 = v.assetManager.materials) == null ? void 0 : _a2.unregisterMaterialExtension(this.materialExtension);
3024
+ v.assetManager.materials?.unregisterMaterialExtension(this.materialExtension);
3031
3025
  v.assetManager.unregisterGltfExtension(anisotropyGLTFExtension.name);
3032
3026
  return super.onRemove(v);
3033
3027
  }
@@ -3041,11 +3035,11 @@ let AnisotropyPlugin = class extends AViewerPluginSync {
3041
3035
  };
3042
3036
  AnisotropyPlugin.PluginType = "AnisotropyPlugin";
3043
3037
  AnisotropyPlugin.ANISOTROPY_GLTF_EXTENSION = "WEBGI_materials_anisotropy";
3044
- __decorateClass$5([
3038
+ __decorateClass$6([
3045
3039
  uiToggle("Enabled", (that) => ({ onChange: that.setDirty })),
3046
3040
  serialize()
3047
3041
  ], AnisotropyPlugin.prototype, "enabled", 2);
3048
- AnisotropyPlugin = __decorateClass$5([
3042
+ AnisotropyPlugin = __decorateClass$6([
3049
3043
  uiFolderContainer("Anisotropy (MatExt)")
3050
3044
  ], AnisotropyPlugin);
3051
3045
  class GLTFMaterialsAnisotropyExtensionImport {
@@ -3068,7 +3062,7 @@ class GLTFMaterialsAnisotropyExtensionImport {
3068
3062
  let { anisotropyDirectionMode, anisotropyDirection } = extension;
3069
3063
  if (!anisotropyDirectionMode) anisotropyDirectionMode = extension.anisotropyTextureMode;
3070
3064
  if (!anisotropyDirection) anisotropyDirection = extension.anisotropyRotation;
3071
- materialParams.userData._anisotropyDirectionMode = anisotropyDirectionMode && typeof (anisotropyDirection == null ? void 0 : anisotropyDirection.index) === "number" ? anisotropyDirectionMode : "CONSTANT";
3065
+ materialParams.userData._anisotropyDirectionMode = anisotropyDirectionMode && typeof anisotropyDirection?.index === "number" ? anisotropyDirectionMode : "CONSTANT";
3072
3066
  if (anisotropyDirectionMode === "ROTATION" || anisotropyDirectionMode === "DIRECTION") {
3073
3067
  pending.push(parser.assignTexture(materialParams.userData, "_anisotropyDirectionMap", anisotropyDirection).then((t2) => {
3074
3068
  t2.colorSpace = SRGBColorSpace;
@@ -3079,10 +3073,8 @@ class GLTFMaterialsAnisotropyExtensionImport {
3079
3073
  return Promise.all(pending);
3080
3074
  }
3081
3075
  afterRoot(result) {
3082
- var _a2;
3083
- (_a2 = result.scene) == null ? void 0 : _a2.traverse((object) => {
3084
- var _a3, _b2;
3085
- const mat = (_b2 = (_a3 = object.material) == null ? void 0 : _a3.userData) == null ? void 0 : _b2._isAnisotropic;
3076
+ result.scene?.traverse((object) => {
3077
+ const mat = object.material?.userData?._isAnisotropic;
3086
3078
  if (!mat) return;
3087
3079
  const geom = object.geometry;
3088
3080
  if (!geom.attributes.tangent) {
@@ -3124,13 +3116,13 @@ const anisotropyGLTFExtension = {
3124
3116
  };
3125
3117
  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
3118
  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) => {
3119
+ var __defProp$5 = Object.defineProperty;
3120
+ var __decorateClass$5 = (decorators, target, key, kind) => {
3129
3121
  var result = void 0;
3130
3122
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
3131
3123
  if (decorator = decorators[i2])
3132
3124
  result = decorator(target, key, result) || result;
3133
- if (result) __defProp$4(target, key, result);
3125
+ if (result) __defProp$5(target, key, result);
3134
3126
  return result;
3135
3127
  };
3136
3128
  const _Reflector2 = class _Reflector22 extends Mesh2 {
@@ -3195,10 +3187,7 @@ const _Reflector2 = class _Reflector22 extends Mesh2 {
3195
3187
  isCompatible: (material2) => {
3196
3188
  return material2.isPhysicalMaterial;
3197
3189
  },
3198
- setDirty: () => {
3199
- var _a2, _b2;
3200
- return (_b2 = (_a2 = this.materialExtension).__setDirty) == null ? void 0 : _b2.call(_a2);
3201
- }
3190
+ setDirty: () => this.materialExtension.__setDirty?.()
3202
3191
  };
3203
3192
  this._renderTarget = renderTarget;
3204
3193
  const reflectorPlane = new Plane();
@@ -3296,7 +3285,7 @@ const _Reflector2 = class _Reflector22 extends Mesh2 {
3296
3285
  const sceneBackground = scene.background;
3297
3286
  if (this.transparentReflectionBackground) scene.background = null;
3298
3287
  const renderBackground = !this.transparentReflectionBackground;
3299
- if ((sceneBackground == null ? void 0 : sceneBackground.isTexture) && renderBackground) {
3288
+ if (sceneBackground?.isTexture && renderBackground) {
3300
3289
  if (!sceneBackground.userData) sceneBackground.userData = {};
3301
3290
  sceneBackground.userData.flipX = !sceneBackground.userData.flipX;
3302
3291
  }
@@ -3309,14 +3298,14 @@ const _Reflector2 = class _Reflector22 extends Mesh2 {
3309
3298
  // todo: render transmissive objects somehow
3310
3299
  screenSpaceRendering: false
3311
3300
  }, () => renderer.render(scene, virtualCamera));
3312
- if ((sceneBackground == null ? void 0 : sceneBackground.isTexture) && renderBackground) {
3301
+ if (sceneBackground?.isTexture && renderBackground) {
3313
3302
  sceneBackground.userData.flipX = !sceneBackground.userData.flipX || void 0;
3314
3303
  }
3315
3304
  if (this.transparentReflectionBackground) scene.background = sceneBackground;
3316
3305
  renderer.xr.enabled = currentXrEnabled;
3317
3306
  renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
3318
3307
  renderer.setRenderTarget(currentRenderTarget);
3319
- if ((viewOffset == null ? void 0 : viewOffset.enabled) && camera.setViewOffset)
3308
+ if (viewOffset?.enabled && camera.setViewOffset)
3320
3309
  camera.setViewOffset(viewOffset.fullWidth, viewOffset.fullHeight, viewOffset.offsetX, viewOffset.offsetY, viewOffset.width, viewOffset.height);
3321
3310
  const viewport = camera.viewport;
3322
3311
  if (viewport !== void 0) {
@@ -3340,18 +3329,17 @@ const _Reflector2 = class _Reflector22 extends Mesh2 {
3340
3329
  }
3341
3330
  // todo change to reflectBackground or something
3342
3331
  _updateExtension() {
3343
- var _a2, _b2;
3344
3332
  this.transparentReflectionBackground = this.reflectorModePhysical;
3345
- (_b2 = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b2.call(_a2);
3333
+ this.materialExtension?.setDirty?.();
3346
3334
  }
3347
3335
  getRenderTarget() {
3348
3336
  return this._renderTarget;
3349
3337
  }
3350
3338
  };
3351
- __decorateClass$4([
3339
+ __decorateClass$5([
3352
3340
  onChange(_Reflector2.prototype._updateExtension)
3353
3341
  ], _Reflector2.prototype, "enabled");
3354
- __decorateClass$4([
3342
+ __decorateClass$5([
3355
3343
  onChange(_Reflector2.prototype._updateExtension)
3356
3344
  ], _Reflector2.prototype, "reflectorModePhysical");
3357
3345
  let Reflector2 = _Reflector2;
@@ -3425,13 +3413,13 @@ class a {
3425
3413
  return { next: () => Math.random() };
3426
3414
  }
3427
3415
  }
3428
- var __defProp$3 = Object.defineProperty;
3429
- var __decorateClass$3 = (decorators, target, key, kind) => {
3416
+ var __defProp$4 = Object.defineProperty;
3417
+ var __decorateClass$4 = (decorators, target, key, kind) => {
3430
3418
  var result = void 0;
3431
3419
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
3432
3420
  if (decorator = decorators[i2])
3433
3421
  result = decorator(target, key, result) || result;
3434
- if (result) __defProp$3(target, key, result);
3422
+ if (result) __defProp$4(target, key, result);
3435
3423
  return result;
3436
3424
  };
3437
3425
  class RandomizedDirectionalLight extends DirectionalLight2 {
@@ -3586,10 +3574,10 @@ class RandomizedDirectionalLight extends DirectionalLight2 {
3586
3574
  // this.updateMatrixWorld()
3587
3575
  // }
3588
3576
  }
3589
- __decorateClass$3([
3577
+ __decorateClass$4([
3590
3578
  serialize("shadowParams")
3591
3579
  ], RandomizedDirectionalLight.prototype, "_shadowParams");
3592
- __decorateClass$3([
3580
+ __decorateClass$4([
3593
3581
  serialize("randomParams")
3594
3582
  ], RandomizedDirectionalLight.prototype, "_randomParams");
3595
3583
  function getSample(rand, dir, extent) {
@@ -3602,13 +3590,13 @@ function getSample(rand, dir, extent) {
3602
3590
  const oneminus = Math.sqrt(1 - r2.y * r2.y);
3603
3591
  return o1.multiplyScalar(Math.cos(r2.x) * oneminus).add(o2.multiplyScalar(Math.sin(r2.x) * oneminus)).add(dir.multiplyScalar(r2.y));
3604
3592
  }
3605
- var __defProp$2 = Object.defineProperty;
3606
- var __decorateClass$2 = (decorators, target, key, kind) => {
3593
+ var __defProp$3 = Object.defineProperty;
3594
+ var __decorateClass$3 = (decorators, target, key, kind) => {
3607
3595
  var result = void 0;
3608
3596
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
3609
3597
  if (decorator = decorators[i2])
3610
3598
  result = decorator(target, key, result) || result;
3611
- if (result) __defProp$2(target, key, result);
3599
+ if (result) __defProp$3(target, key, result);
3612
3600
  return result;
3613
3601
  };
3614
3602
  class FSShadowMaterial extends ShadowMaterial {
@@ -3668,17 +3656,17 @@ gl_FragColor = packDepthToRGBA(mix(last, shadow, opacity));
3668
3656
  this.dispatchEvent({ ...options, type: "materialUpdate" });
3669
3657
  }
3670
3658
  }
3671
- __decorateClass$2([
3659
+ __decorateClass$3([
3672
3660
  uniform({ propKey: "tLastThis" })
3673
3661
  ], FSShadowMaterial.prototype, "lastFrameTexture");
3674
3662
  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) => {
3663
+ var __defProp$2 = Object.defineProperty;
3664
+ var __decorateClass$2 = (decorators, target, key, kind) => {
3677
3665
  var result = void 0;
3678
3666
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
3679
3667
  if (decorator = decorators[i2])
3680
3668
  result = decorator(target, key, result) || result;
3681
- if (result) __defProp$1(target, key, result);
3669
+ if (result) __defProp$2(target, key, result);
3682
3670
  return result;
3683
3671
  };
3684
3672
  const _ShadowMapBaker = class _ShadowMapBaker2 extends SimpleEventDispatcher {
@@ -3880,9 +3868,8 @@ const _ShadowMapBaker = class _ShadowMapBaker2 extends SimpleEventDispatcher {
3880
3868
  this.reset();
3881
3869
  }
3882
3870
  _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();
3871
+ this.materialExtension?.setDirty?.();
3872
+ this._viewer?.setDirty();
3886
3873
  }
3887
3874
  fromJSON(data, meta, _internal = false) {
3888
3875
  if (!_internal) {
@@ -4026,16 +4013,15 @@ const _ShadowMapBaker = class _ShadowMapBaker2 extends SimpleEventDispatcher {
4026
4013
  return true;
4027
4014
  }
4028
4015
  _updateMaterial(isNull = false) {
4029
- var _a2, _b2, _c;
4030
4016
  if (!this._attachedMesh) return;
4031
4017
  if (isNull) {
4032
- if (this._attachedMesh.material.alphaMap === ((_a2 = this._target) == null ? void 0 : _a2.texture)) {
4018
+ if (this._attachedMesh.material.alphaMap === this._target?.texture) {
4033
4019
  this._attachedMesh.material.alphaMap = null;
4034
4020
  }
4035
- if (this._attachedMesh.material.aoMap === ((_b2 = this._target) == null ? void 0 : _b2.texture)) {
4021
+ if (this._attachedMesh.material.aoMap === this._target?.texture) {
4036
4022
  this._attachedMesh.material.aoMap = null;
4037
4023
  }
4038
- if (this._attachedMesh.material.map === ((_c = this._target) == null ? void 0 : _c.texture)) {
4024
+ if (this._attachedMesh.material.map === this._target?.texture) {
4039
4025
  this._attachedMesh.material.map = null;
4040
4026
  }
4041
4027
  } else if (this._target) {
@@ -4069,44 +4055,44 @@ const _ShadowMapBaker = class _ShadowMapBaker2 extends SimpleEventDispatcher {
4069
4055
  // this._viewer.renderManager.renderModel(mesh, this._viewer.scene.activeCamera!)
4070
4056
  // }
4071
4057
  };
4072
- __decorateClass$1([
4058
+ __decorateClass$2([
4073
4059
  serialize("randomizedLight")
4074
4060
  ], _ShadowMapBaker.prototype, "_light");
4075
- __decorateClass$1([
4061
+ __decorateClass$2([
4076
4062
  onChange(_ShadowMapBaker.prototype.reset),
4077
4063
  serialize()
4078
4064
  ], _ShadowMapBaker.prototype, "maxFrameNumber");
4079
- __decorateClass$1([
4065
+ __decorateClass$2([
4080
4066
  onChange(_ShadowMapBaker.prototype.reset),
4081
4067
  serialize()
4082
4068
  ], _ShadowMapBaker.prototype, "smoothShadow");
4083
- __decorateClass$1([
4069
+ __decorateClass$2([
4084
4070
  serialize(),
4085
4071
  onChange(_ShadowMapBaker.prototype.reset)
4086
4072
  ], _ShadowMapBaker.prototype, "shadowMapType");
4087
- __decorateClass$1([
4073
+ __decorateClass$2([
4088
4074
  onChange(_ShadowMapBaker.prototype._groundMapModeChanged),
4089
4075
  serialize()
4090
4076
  ], _ShadowMapBaker.prototype, "groundMapMode");
4091
- __decorateClass$1([
4077
+ __decorateClass$2([
4092
4078
  serialize(),
4093
4079
  onChange(_ShadowMapBaker.prototype._alphaVignetteChanged)
4094
4080
  ], _ShadowMapBaker.prototype, "alphaVignette");
4095
- __decorateClass$1([
4081
+ __decorateClass$2([
4096
4082
  serialize(),
4097
4083
  onChange(_ShadowMapBaker.prototype._alphaVignetteChanged)
4098
4084
  ], _ShadowMapBaker.prototype, "alphaVignetteAxis");
4099
- __decorateClass$1([
4085
+ __decorateClass$2([
4100
4086
  serialize()
4101
4087
  ], _ShadowMapBaker.prototype, "maxBakeCount");
4102
4088
  let ShadowMapBaker = _ShadowMapBaker;
4103
- var __defProp = Object.defineProperty;
4104
- var __decorateClass = (decorators, target, key, kind) => {
4089
+ var __defProp$1 = Object.defineProperty;
4090
+ var __decorateClass$1 = (decorators, target, key, kind) => {
4105
4091
  var result = void 0;
4106
4092
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
4107
4093
  if (decorator = decorators[i2])
4108
4094
  result = decorator(target, key, result) || result;
4109
- if (result) __defProp(target, key, result);
4095
+ if (result) __defProp$1(target, key, result);
4110
4096
  return result;
4111
4097
  };
4112
4098
  const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
@@ -4118,8 +4104,7 @@ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4118
4104
  this.autoFrustumSize = true;
4119
4105
  this.autoBakeShadows = true;
4120
4106
  this.autoResetShadows = () => {
4121
- var _a2;
4122
- if (this.autoBakeShadows) (_a2 = this._shadowBaker) == null ? void 0 : _a2.reset();
4107
+ if (this.autoBakeShadows) this._shadowBaker?.reset();
4123
4108
  };
4124
4109
  this._onSceneUpdate = this._onSceneUpdate.bind(this);
4125
4110
  console.log(this.uiConfig);
@@ -4146,31 +4131,26 @@ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4146
4131
  * bake shadows manually, to be used with {@see autoBakeShadows} set to false
4147
4132
  */
4148
4133
  bakeShadows() {
4149
- var _a2;
4150
- (_a2 = this._shadowBaker) == null ? void 0 : _a2.reset();
4134
+ this._shadowBaker?.reset();
4151
4135
  }
4152
4136
  _createMesh(mesh) {
4153
4137
  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());
4138
+ const reflector = new Reflector2(this._geometry, () => this._viewer?.renderManager.createTarget({
4139
+ // type: HalfFloatType,
4140
+ type: UnsignedByteType,
4141
+ format: RGBAFormat,
4142
+ colorSpace: NoColorSpace,
4143
+ // todo: we can do rgbm if only opaque objects will be reflected
4144
+ size: { width: 1024, height: 1024 },
4145
+ generateMipmaps: true,
4146
+ depthBuffer: true,
4147
+ minFilter: LinearMipmapLinearFilter,
4148
+ magFilter: LinearFilter
4149
+ // isAntialiased: this._viewer.isAntialiased,
4150
+ }), 0, this._createMaterial());
4170
4151
  const superOnBeforeRender = reflector.onBeforeRender;
4171
4152
  reflector.onBeforeRender = (...params) => {
4172
- var _a2;
4173
- let ssr = (_a2 = this._viewer) == null ? void 0 : _a2.getPluginByType("SSReflectionPlugin");
4153
+ let ssr = this._viewer?.getPluginByType("SSReflectionPlugin");
4174
4154
  if (ssr && ssr.isDisabled()) ssr = void 0;
4175
4155
  if (ssr) ssr.disable(reflector.uuid, false);
4176
4156
  superOnBeforeRender(...params);
@@ -4198,16 +4178,15 @@ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4198
4178
  return super.onRemove(viewer);
4199
4179
  }
4200
4180
  _removeMaterial() {
4201
- var _a2, _b2, _c, _d;
4202
4181
  if (!this._material) return;
4203
4182
  if (this._shadowBaker && this._material.groundMatExtension) {
4204
- (_b2 = (_a2 = this._material).unregisterMaterialExtensions) == null ? void 0 : _b2.call(_a2, [this._shadowBaker.materialExtension]);
4183
+ this._material.unregisterMaterialExtensions?.([this._shadowBaker.materialExtension]);
4205
4184
  delete this._material.groundMatExtension;
4206
4185
  }
4207
4186
  if (this._material.reflectorMatExtension) {
4208
4187
  const ext = this._mesh.materialExtension;
4209
4188
  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]);
4189
+ this._material.unregisterMaterialExtensions?.([ext]);
4211
4190
  delete this._material.reflectorMatExtension;
4212
4191
  }
4213
4192
  super._removeMaterial();
@@ -4257,18 +4236,17 @@ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4257
4236
  return this;
4258
4237
  }
4259
4238
  _refreshMaterial() {
4260
- var _a2, _b2, _c, _d;
4261
4239
  if (!this._viewer) return false;
4262
4240
  super._refreshMaterial();
4263
4241
  if (!this._material) return;
4264
4242
  if (this.groundReflection && this._mesh.isReflector2 && !this._material.reflectorMatExtension) {
4265
4243
  const ext = this._mesh.materialExtension;
4266
4244
  ext.updaters = [this._viewer.scene, this._viewer.renderManager];
4267
- (_b2 = (_a2 = this._material).registerMaterialExtensions) == null ? void 0 : _b2.call(_a2, [ext]);
4245
+ this._material.registerMaterialExtensions?.([ext]);
4268
4246
  this._material.reflectorMatExtension = true;
4269
4247
  }
4270
4248
  if (this.bakedShadows && this._shadowBaker && !this._material.groundMatExtension) {
4271
- (_d = (_c = this._material).registerMaterialExtensions) == null ? void 0 : _d.call(_c, [this._shadowBaker.materialExtension]);
4249
+ this._material.registerMaterialExtensions?.([this._shadowBaker.materialExtension]);
4272
4250
  this._material.groundMatExtension = true;
4273
4251
  }
4274
4252
  this._material.userData.ssreflDisabled = this.groundReflection;
@@ -4276,7 +4254,6 @@ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4276
4254
  this._viewer.setDirty(this);
4277
4255
  }
4278
4256
  _extraUiConfig() {
4279
- var _a2, _b2, _c, _d, _e, _f, _g, _h;
4280
4257
  return [
4281
4258
  {
4282
4259
  label: "Shadow Frames",
@@ -4289,21 +4266,15 @@ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4289
4266
  {
4290
4267
  label: "Alpha Vignette",
4291
4268
  type: "checkbox",
4292
- hidden: () => !this._material || this._material.transmission < 1e-4 && !this._material.transparent,
4269
+ hidden: () => !this._material || (this._material.transmission || 0) < 1e-4 && !this._material.transparent,
4293
4270
  property: () => [this._shadowBaker, "alphaVignette"],
4294
4271
  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
- }
4272
+ onChange: () => this.uiConfig?.uiRefresh?.(true, "postFrame")
4299
4273
  },
4300
4274
  {
4301
4275
  label: "Alpha Vignette Axis",
4302
4276
  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
- },
4277
+ hidden: () => !this._shadowBaker?.alphaVignette || !this._material || (this._material.transmission || 0) < 1e-4 && !this._material.transparent,
4307
4278
  property: () => [this._shadowBaker, "alphaVignetteAxis"],
4308
4279
  children: ["x", "y", "xy"].map((v) => ({ label: v, value: v })),
4309
4280
  limitedUi: true
@@ -4340,10 +4311,7 @@ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4340
4311
  {
4341
4312
  type: "color",
4342
4313
  label: "Color",
4343
- property: () => {
4344
- var _a3;
4345
- return [(_a3 = this._shadowBaker) == null ? void 0 : _a3.light, "color"];
4346
- }
4314
+ property: () => [this._shadowBaker?.light, "color"]
4347
4315
  },
4348
4316
  // {
4349
4317
  // type: 'slider',
@@ -4360,110 +4328,241 @@ const _AdvancedGroundPlugin = (_b = class extends BaseGroundPlugin {
4360
4328
  {
4361
4329
  type: "slider",
4362
4330
  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
- },
4331
+ property: () => [this._shadowBaker?.light?.randomParams, "focus"],
4367
4332
  onChange: this.autoResetShadows
4368
4333
  },
4369
4334
  {
4370
4335
  type: "slider",
4371
4336
  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
- },
4337
+ property: () => [this._shadowBaker?.light?.randomParams, "spread"],
4376
4338
  onChange: this.autoResetShadows,
4377
4339
  limitedUi: true
4378
4340
  },
4379
4341
  {
4380
4342
  type: "slider",
4381
4343
  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]
4344
+ property: () => [this._shadowBaker?.light?.randomParams, "distanceScale"],
4345
+ onChange: [this._shadowBaker?.light?.updateShadowParams, this.autoResetShadows]
4387
4346
  },
4388
4347
  {
4389
4348
  type: "vec3",
4390
4349
  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
- },
4350
+ property: () => [this._shadowBaker?.light?.randomParams, "direction"],
4395
4351
  onChange: this.autoResetShadows,
4396
4352
  limitedUi: true
4397
4353
  },
4398
4354
  {
4399
4355
  type: "vec3",
4400
4356
  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
- },
4357
+ property: () => [this._shadowBaker?.light?.randomParams, "normalDirection"],
4405
4358
  onChange: this.autoResetShadows,
4406
4359
  limitedUi: true
4407
4360
  },
4408
4361
  {
4409
4362
  type: "slider",
4410
4363
  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]
4364
+ property: () => [this._shadowBaker?.light?.shadowParams, "radius"],
4365
+ onChange: [this._shadowBaker?.light?.updateShadowParams, this.autoResetShadows]
4416
4366
  },
4417
4367
  {
4418
4368
  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
- },
4369
+ property: () => [this._shadowBaker?.light?.shadowParams, "frustumSize"],
4423
4370
  hidden: () => this.autoFrustumSize,
4424
- onChange: [(_f = (_e = this._shadowBaker) == null ? void 0 : _e.light) == null ? void 0 : _f.updateShadowParams, this.autoResetShadows]
4371
+ onChange: [this._shadowBaker?.light?.updateShadowParams, this.autoResetShadows]
4425
4372
  },
4426
4373
  {
4427
4374
  type: "slider",
4428
4375
  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]
4376
+ property: () => [this._shadowBaker?.light?.shadowParams, "bias"],
4377
+ onChange: [this._shadowBaker?.light?.updateShadowParams, this.autoResetShadows]
4434
4378
  }
4435
4379
  ]
4436
4380
  }
4437
4381
  ];
4438
4382
  }
4439
4383
  }, _b.PluginType = "AdvancedGroundPlugin", _b);
4440
- __decorateClass([
4384
+ __decorateClass$1([
4441
4385
  onChange(_AdvancedGroundPlugin.prototype._refresh3),
4442
4386
  uiToggle("Baked Shadows"),
4443
4387
  serialize()
4444
4388
  ], _AdvancedGroundPlugin.prototype, "bakedShadows");
4445
- __decorateClass([
4389
+ __decorateClass$1([
4446
4390
  onChange(_AdvancedGroundPlugin.prototype._refresh3),
4447
4391
  uiToggle("Planar Reflections"),
4448
4392
  serialize()
4449
4393
  ], _AdvancedGroundPlugin.prototype, "groundReflection");
4450
- __decorateClass([
4394
+ __decorateClass$1([
4451
4395
  onChange(_AdvancedGroundPlugin.prototype._refresh3),
4452
4396
  uiToggle("Physical Reflections"),
4453
4397
  serialize()
4454
4398
  ], _AdvancedGroundPlugin.prototype, "physicalReflections");
4455
- __decorateClass([
4399
+ __decorateClass$1([
4456
4400
  onChange(_AdvancedGroundPlugin.prototype._refresh3),
4457
4401
  uiToggle("Auto Shadow Frustum Size"),
4458
4402
  serialize()
4459
4403
  ], _AdvancedGroundPlugin.prototype, "autoFrustumSize");
4460
- __decorateClass([
4404
+ __decorateClass$1([
4461
4405
  serialize("shadowBaker")
4462
4406
  ], _AdvancedGroundPlugin.prototype, "_shadowBaker");
4463
- __decorateClass([
4407
+ __decorateClass$1([
4464
4408
  bindToValue({ key: "groundReflection" })
4465
4409
  ], _AdvancedGroundPlugin.prototype, "planarReflections");
4466
4410
  let AdvancedGroundPlugin = _AdvancedGroundPlugin;
4411
+ var __defProp = Object.defineProperty;
4412
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4413
+ var __decorateClass = (decorators, target, key, kind) => {
4414
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
4415
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
4416
+ if (decorator = decorators[i2])
4417
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
4418
+ if (kind && result) __defProp(target, key, result);
4419
+ return result;
4420
+ };
4421
+ let WatchHandsPlugin = class extends AViewerPluginSync {
4422
+ constructor() {
4423
+ super(...arguments);
4424
+ this.enabled = true;
4425
+ this.dependencies = [];
4426
+ this.axis = "y";
4427
+ this.invertAxis = false;
4428
+ this.analog = true;
4429
+ this.hourOffset = 0;
4430
+ this.minuteOffset = 0;
4431
+ this.secondOffset = 0;
4432
+ this.hour = ".*hour.*";
4433
+ this.minute = ".*minute.*";
4434
+ this.second = ".*second.*";
4435
+ this.regex = true;
4436
+ this.hands = [];
4437
+ this._lastEnabled = true;
4438
+ this._preFrame = () => {
4439
+ if (!this.enabled) {
4440
+ if (this._lastEnabled) {
4441
+ this._lastEnabled = false;
4442
+ if (!this.hands.length) return;
4443
+ for (const h of this.hands) {
4444
+ h.object.rotation.fromArray(h.object.userData.initRotation);
4445
+ h.object.updateMatrixWorld();
4446
+ }
4447
+ this._viewer?.renderManager.resetShadows();
4448
+ this._viewer?.setDirty();
4449
+ }
4450
+ return;
4451
+ }
4452
+ this._lastEnabled = true;
4453
+ if (!this.hands.length) return;
4454
+ const time = /* @__PURE__ */ new Date();
4455
+ const invert = this.invertAxis ? -1 : 1;
4456
+ const secondHandRotation = invert * (time.getSeconds() + (this.analog ? time.getMilliseconds() / 1e3 : 0) - this.secondOffset) * (Math.PI * 2) / 60;
4457
+ const minuteHandRotation = invert * (time.getMinutes() - this.minuteOffset) * (Math.PI * 2) / 60 + secondHandRotation / 60;
4458
+ const hourHandRotation = invert * (time.getHours() - this.hourOffset) * (Math.PI * 2) / 12 + minuteHandRotation / 12;
4459
+ if (this.hands.find((h) => h.type === "second" && Math.abs(secondHandRotation - h.object.rotation[this.axis]) > 1e-3)) {
4460
+ for (const hand of this.hands) {
4461
+ if (hand.type === "second") {
4462
+ hand.object.rotation[this.axis] = secondHandRotation;
4463
+ }
4464
+ if (hand.type === "minute") {
4465
+ hand.object.rotation[this.axis] = minuteHandRotation;
4466
+ }
4467
+ if (hand.type === "hour") {
4468
+ hand.object.rotation[this.axis] = hourHandRotation;
4469
+ }
4470
+ }
4471
+ this._viewer?.renderManager.resetShadows();
4472
+ this._viewer?.setDirty();
4473
+ }
4474
+ };
4475
+ this._addSceneObject = async (e2) => {
4476
+ if (!e2.object) return;
4477
+ this.refresh();
4478
+ };
4479
+ }
4480
+ onAdded(viewer) {
4481
+ super.onAdded(viewer);
4482
+ viewer.scene.addEventListener("addSceneObject", this._addSceneObject);
4483
+ viewer.addEventListener("preFrame", this._preFrame);
4484
+ }
4485
+ onRemove(viewer) {
4486
+ viewer.scene.removeEventListener("addSceneObject", this._addSceneObject);
4487
+ viewer.removeEventListener("preFrame", this._preFrame);
4488
+ super.onRemove(viewer);
4489
+ }
4490
+ refresh() {
4491
+ this.hands = [];
4492
+ this._viewer?.scene.modelRoot.traverse((o) => {
4493
+ let isChild = false;
4494
+ o.traverseAncestors((oa) => {
4495
+ if (isChild) return;
4496
+ if (this.hands.find((h) => h.object === oa)) isChild = true;
4497
+ });
4498
+ if (isChild) return;
4499
+ if (o.name.match(this.regex ? new RegExp(this.hour) : this.hour)) {
4500
+ if (!o.userData.initRotation) o.userData.initRotation = o.rotation.toArray();
4501
+ this.hands.push({ type: "hour", object: o });
4502
+ }
4503
+ if (o.name.match(this.regex ? new RegExp(this.minute) : this.minute)) {
4504
+ if (!o.userData.initRotation) o.userData.initRotation = o.rotation.toArray();
4505
+ this.hands.push({ type: "minute", object: o });
4506
+ }
4507
+ if (o.name.match(this.regex ? new RegExp(this.second) : this.second)) {
4508
+ if (!o.userData.initRotation) o.userData.initRotation = o.rotation.toArray();
4509
+ this.hands.push({ type: "second", object: o });
4510
+ }
4511
+ });
4512
+ }
4513
+ };
4514
+ WatchHandsPlugin.PluginType = "WatchHandsPlugin";
4515
+ __decorateClass([
4516
+ uiToggle(),
4517
+ serialize()
4518
+ ], WatchHandsPlugin.prototype, "enabled", 2);
4519
+ __decorateClass([
4520
+ uiDropdown(void 0, ["x", "y", "z"].map((label) => ({ label }))),
4521
+ serialize()
4522
+ ], WatchHandsPlugin.prototype, "axis", 2);
4523
+ __decorateClass([
4524
+ uiToggle(),
4525
+ serialize()
4526
+ ], WatchHandsPlugin.prototype, "invertAxis", 2);
4527
+ __decorateClass([
4528
+ uiToggle(),
4529
+ serialize()
4530
+ ], WatchHandsPlugin.prototype, "analog", 2);
4531
+ __decorateClass([
4532
+ uiSlider(void 0, [0, 12], 1e-3),
4533
+ serialize()
4534
+ ], WatchHandsPlugin.prototype, "hourOffset", 2);
4535
+ __decorateClass([
4536
+ uiSlider(void 0, [0, 60], 1e-3),
4537
+ serialize()
4538
+ ], WatchHandsPlugin.prototype, "minuteOffset", 2);
4539
+ __decorateClass([
4540
+ uiSlider(void 0, [0, 60], 1e-3),
4541
+ serialize()
4542
+ ], WatchHandsPlugin.prototype, "secondOffset", 2);
4543
+ __decorateClass([
4544
+ uiInput(),
4545
+ serialize()
4546
+ ], WatchHandsPlugin.prototype, "hour", 2);
4547
+ __decorateClass([
4548
+ uiInput(),
4549
+ serialize()
4550
+ ], WatchHandsPlugin.prototype, "minute", 2);
4551
+ __decorateClass([
4552
+ uiInput(),
4553
+ serialize()
4554
+ ], WatchHandsPlugin.prototype, "second", 2);
4555
+ __decorateClass([
4556
+ uiToggle(),
4557
+ onChange("refresh"),
4558
+ serialize()
4559
+ ], WatchHandsPlugin.prototype, "regex", 2);
4560
+ __decorateClass([
4561
+ uiButton()
4562
+ ], WatchHandsPlugin.prototype, "refresh", 1);
4563
+ WatchHandsPlugin = __decorateClass([
4564
+ uiFolderContainer("Watch Hands Time")
4565
+ ], WatchHandsPlugin);
4467
4566
  const webgiPlugins = [
4468
4567
  TemporalAAPlugin,
4469
4568
  VelocityBufferPlugin,
@@ -4474,7 +4573,8 @@ const webgiPlugins = [
4474
4573
  OutlinePlugin,
4475
4574
  SSGIPlugin,
4476
4575
  AnisotropyPlugin,
4477
- AdvancedGroundPlugin
4576
+ AdvancedGroundPlugin,
4577
+ WatchHandsPlugin
4478
4578
  ];
4479
4579
  export {
4480
4580
  AdvancedGroundPlugin,
@@ -4494,6 +4594,7 @@ export {
4494
4594
  TemporalAAPlugin,
4495
4595
  TemporalAAPluginPass,
4496
4596
  VelocityBufferPlugin,
4597
+ WatchHandsPlugin,
4497
4598
  anisotropyGLTFExtension,
4498
4599
  webgiPlugins
4499
4600
  };