@threepipe/webgi-plugins 0.4.0 → 0.5.0

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