@threepipe/webgi-plugins 0.1.0 → 0.2.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,125 +1,100 @@
1
- import { PipelinePassPlugin as I, GBufferPlugin as T, ProgressivePlugin as O, generateUiConfig as Y, uiToggle as R, uiConfig as Q, ExtendedShaderPass as $, CopyShader as ce, Vector2 as d, Matrix4 as E, serialize as c, uniform as f, uiVector as ue, matDefineBool as fe, shaderReplaceString as B, UnsignedByteType as de, LinearSRGBColorSpace as pe, GBufferRenderPass as Te, Color as he, uiImage as ve, uiFolderContainer as z, ShaderMaterial as be, Matrix3 as Pe, NoBlending as me, DoubleSide as Ce, uiConfigMaterialExtension as ge, updateBit as we, Vector4 as Ee, HalfFloatType as K, AdditiveBlending as De, uiSlider as u, onChange as N, matDefine as V, Vector3 as U, PickingPlugin as j, now as re, FrameFadePlugin as Re, ExtendedShaderMaterial as Z, shaderUtils as k, bindToValue as X, NearestFilter as ie, RGBAFormat as Ue, AViewerPluginSync as Me, glsl as _e, ShaderChunk as ae, updateMaterialDefines as Le, BaseGroundPlugin as se, SSAAPlugin as Fe, getOrCall as H, getTexelDecoding as oe } from "threepipe";
2
1
  /**
3
2
  * @license
4
- * @threepipe/webgi-plugins v0.1.0
5
- * Copyright 2022-2024 repalash <palash@shaders.app>
3
+ * @threepipe/webgi-plugins v0.2.0
4
+ * Copyright 2022-2025 repalash <palash@shaders.app>
6
5
  * GPL-3.0-only License
7
6
  */
8
- const Be = `#if defined(HAS_VELOCITY_BUFFER)
9
- uniform 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.));}
10
- #endif
11
- `, Ae = `#ifdef USE_ALPHAMAP
12
- #define USE_UV
13
- #endif
14
- #include <uv_pars_vertex>
15
- #include <morphtarget_pars_vertex>
16
- #include <skinning_pars_vertex>
17
- #include <logdepthbuf_pars_vertex>
18
- #include <clipping_planes_pars_vertex>
19
- varying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 modelMatrixPrevious;void main(){
20
- #include <uv_vertex>
21
- #include <skinbase_vertex>
22
- #include <begin_vertex>
23
- #include <morphtarget_vertex>
24
- #include <skinning_vertex>
25
- #include <displacementmap_vertex>
26
- vec4 mvPosition=vec4(transformed,1.0);
27
- #ifdef USE_INSTANCING
28
- mvPosition=instanceMatrix*mvPosition;
29
- #endif
30
- vWorldPosition=(modelMatrix*mvPosition).xyz;vWorldPositionPrevious=(modelMatrixPrevious*mvPosition).xyz;mvPosition=modelViewMatrix*mvPosition;gl_Position=projectionMatrix*mvPosition;
31
- #include <logdepthbuf_vertex>
32
- #include <clipping_planes_vertex>
33
- }`, ze = "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.);}", Ne = `#include <common>
34
- #include <gbuffer_unpack>
35
- #ifdef HAS_VELOCITY_BUFFER
36
- #endif
37
- #include <cameraHelpers>
38
- varying vec2 vUv;uniform vec2 previousRTSize;uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;uniform mat4 inverseViewMatrix;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;
39
- #ifndef HAS_VELOCITY_BUFFER
40
- #define HAS_VELOCITY_BUFFER 0
41
- #endif
42
- vec3 find_closest_fragment_3x3(const in vec2 uv){const vec3 offset=vec3(-1.0,1.0,0.0);vec2 texelSize=1.0/previousRTSize;vec3 dtr=vec3(1,1,getDepth(uv+offset.yy*texelSize));vec3 dtc=vec3(0,1,getDepth(uv+offset.zy*texelSize));vec3 dtl=vec3(-1,1,getDepth(uv+offset.xy*texelSize));vec3 dml=vec3(-1,0,getDepth(uv+offset.xz*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dmr=vec3(1,0,getDepth(uv+offset.yz*texelSize));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.xx*texelSize));vec3 dbc=vec3(0,-1,getDepth(uv+offset.zx*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.yx*texelSize));vec3 dmin=dtl;if(dmin.z>dtc.z)dmin=dtc;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dml.z)dmin=dml;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dmr.z)dmin=dmr;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbc.z)dmin=dbc;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+texelSize.xy*dmin.xy,dmin.z);}vec3 find_closest_fragment_5tap(const in vec2 uv){vec2 texelSize=1.0/previousRTSize;vec2 offset=vec2(1.0,-1.0);vec3 dtl=vec3(-1,1,getDepth(uv+offset.yx*texelSize));vec3 dtr=vec3(1,1,getDepth(uv+offset.xx*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.yy*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.xy*texelSize));vec3 dmin=dtl;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+dmin.xy*texelSize,dmin.z);}vec4 clip_aabb(const in vec4 aabb_min,const in vec4 aabb_max,vec4 p){const float FLT_EPS=1e-8;vec4 p_clip=0.5*(aabb_max+aabb_min);vec4 e_clip=0.5*(aabb_max-aabb_min)+FLT_EPS;vec4 v_clip=p-p_clip;vec4 v_unit=abs(v_clip/e_clip);float ma_unit=max(v_unit.x,max(v_unit.y,v_unit.z));if(ma_unit>1.0)return p_clip+v_clip/ma_unit;else return p;}
43
- #if HAS_VELOCITY_BUFFER == 0
44
- vec2 computeScreenSpaceVelocity(const in vec3 worldPosition){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(worldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(worldPosition,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}
45
- #endif
46
- vec4 computeTAA(const in vec2 uv,const in vec2 screenSpaceVelocity){vec2 jitterOffset=jitterSample/previousRTSize;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=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yx*texelSize));vec4 tc=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.zx*texelSize));vec4 tr=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.xx*texelSize));vec4 ml=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yz*texelSize));vec4 mc=currentColor;vec4 mr=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.xz*texelSize));vec4 bl=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yy*texelSize));vec4 bc=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.zy*texelSize));vec4 br=currentRTTexelToLinear(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,k_feedback);}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(){vec2 jitterOffset=jitterSample/previousRTSize;
47
- #if HAS_VELOCITY_BUFFER == 0
48
- #if QUALITY == 1
49
- vec3 c_frag=find_closest_fragment_3x3(vUv);
50
- #else
51
- vec3 c_frag=find_closest_fragment_5tap(vUv);
52
- #endif
53
- #else
54
- vec3 c_frag=vec3(0.0);
55
- #endif
56
- if(c_frag.z>=0.999){gl_FragColor=currentRTTexelToLinear(texture2D(currentRT,vUv-jitterOffset));}else{
57
- #if HAS_VELOCITY_BUFFER == 0
58
- float sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);
59
- #else
60
- screenSpaceVelocity=getVelocity(vUv);
61
- #endif
62
- gl_FragColor=firstFrame ? currentRTTexelToLinear(texture2D(currentRT,vUv)): computeTAA(vUv,screenSpaceVelocity);
63
- #ifdef DEBUG_VELOCITY
64
- gl_FragColor=vec4(10.*length(screenSpaceVelocity));
65
- #endif
66
- }
67
- #include <encodings_fragment>
68
- }`;
69
- var Oe = Object.defineProperty, ke = Object.getOwnPropertyDescriptor, q = (a, e, i, r) => {
70
- for (var t = r > 1 ? void 0 : r ? ke(e, i) : e, s = a.length - 1, o; s >= 0; s--)
71
- (o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
72
- return r && t && Oe(e, i, t), t;
7
+ var _a;
8
+ import { PipelinePassPlugin, GBufferPlugin, ProgressivePlugin, generateUiConfig, uiToggle, uiConfig, ExtendedShaderPass, CopyShader, Vector2, Matrix4, getOrCall, serialize, uniform, uiVector, matDefineBool, shaderReplaceString, UnsignedByteType, LinearSRGBColorSpace, GBufferRenderPass, Color, uiImage, uiFolderContainer, ShaderMaterial, Matrix3, NoBlending, DoubleSide, uiConfigMaterialExtension, updateBit, Vector4, HalfFloatType, AdditiveBlending, uiSlider, onChange, onChange2, Vector3, PickingPlugin, now, FrameFadePlugin, ExtendedShaderMaterial, shaderUtils, bindToValue, NearestFilter, RGBAFormat, AViewerPluginSync, glsl, ShaderChunk, updateMaterialDefines, BaseGroundPlugin, matDefine, SSAAPlugin, getTexelDecoding } from "threepipe";
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
+ 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
+ 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$5 = Object.defineProperty;
14
+ var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
15
+ var __decorateClass$5 = (decorators, target, key, kind) => {
16
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
17
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
18
+ if (decorator = decorators[i])
19
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
20
+ if (kind && result) __defProp$5(target, key, result);
21
+ return result;
73
22
  };
74
- const Ie = "taa", G = class G extends I {
23
+ const passId$3 = "taa";
24
+ const _TemporalAAPlugin = class _TemporalAAPlugin extends PipelinePassPlugin {
75
25
  // readonly materialExtension: MaterialExtension = uiConfigMaterialExtension(this._getUiConfig.bind(this), TemporalAAPlugin.PluginType)
76
- constructor(e = !0) {
77
- super(), this.passId = Ie, this._stableNoise = !0, this._gbufferUnpackExtension = void 0, this._gbufferUnpackExtensionChanged = () => {
78
- if (!this._pass || !this._viewer)
79
- throw new Error("TemporalAAPlugin: pass/viewer not created yet");
80
- const i = this._viewer.renderManager.gbufferUnpackExtension;
81
- this._gbufferUnpackExtension !== i && (this._gbufferUnpackExtension && this._pass.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]), this._gbufferUnpackExtension = i, this._gbufferUnpackExtension ? this._pass.material.registerMaterialExtensions([this._gbufferUnpackExtension]) : this._viewer.console.warn("TemporalAAPlugin: GBuffer unpack extension removed"));
82
- }, this.dependencies = [T, O], this.uiConfig = {
26
+ constructor(enabled = true) {
27
+ super();
28
+ this.passId = passId$3;
29
+ this._stableNoise = true;
30
+ this._gbufferUnpackExtension = void 0;
31
+ this._gbufferUnpackExtensionChanged = () => {
32
+ if (!this._pass || !this._viewer) throw new Error("TemporalAAPlugin: pass/viewer not created yet");
33
+ const newExtension = this._viewer.renderManager.gbufferUnpackExtension;
34
+ if (this._gbufferUnpackExtension === newExtension) return;
35
+ if (this._gbufferUnpackExtension) this._pass.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]);
36
+ this._gbufferUnpackExtension = newExtension;
37
+ if (this._gbufferUnpackExtension) this._pass.material.registerMaterialExtensions([this._gbufferUnpackExtension]);
38
+ else this._viewer.console.warn("TemporalAAPlugin: GBuffer unpack extension removed");
39
+ };
40
+ this.dependencies = [GBufferPlugin, ProgressivePlugin];
41
+ this.uiConfig = {
83
42
  type: "folder",
84
43
  label: "TemporalAA Plugin",
85
44
  onChange: this.setDirty.bind(this),
86
45
  children: [
87
- ...Y(this) || []
46
+ ...generateUiConfig(this) || []
88
47
  ]
89
- }, this.enabled = e, this.setDirty = this.setDirty.bind(this);
48
+ };
49
+ this.enabled = enabled;
50
+ this.setDirty = this.setDirty.bind(this);
90
51
  }
91
52
  get stableNoise() {
92
- var e;
93
- return ((e = this._viewer) == null ? void 0 : e.renderManager.stableNoise) ?? this._stableNoise;
53
+ var _a2;
54
+ return ((_a2 = this._viewer) == null ? void 0 : _a2.renderManager.stableNoise) ?? this._stableNoise;
94
55
  }
95
- set stableNoise(e) {
96
- this._viewer && (this._viewer.renderManager.stableNoise = e), this._stableNoise = e;
56
+ set stableNoise(v) {
57
+ if (this._viewer) this._viewer.renderManager.stableNoise = v;
58
+ this._stableNoise = v;
97
59
  }
98
60
  _createPass() {
99
- if (!this._viewer)
100
- throw new Error("TemporalAAPlugin: viewer not set");
61
+ if (!this._viewer) throw new Error("TemporalAAPlugin: viewer not set");
101
62
  if (!this._viewer.renderManager.gbufferTarget || !this._viewer.renderManager.gbufferUnpackExtension)
102
63
  throw new Error("TemporalAAPlugin: GBuffer target not created. GBufferPlugin is required.");
103
- return new ee(this.passId, this._viewer.getPlugin(O).target);
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;
68
+ }, applyOnBackground);
69
+ return t;
104
70
  }
105
71
  // todo use gbufferUnpackExtension from render manager to support depth buffer plugin as well.
106
- onAdded(e) {
107
- super.onAdded(e), this._gbufferUnpackExtensionChanged(), e.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged), e.renderManager.addEventListener("resize", this._pass.onSizeUpdate);
72
+ onAdded(viewer) {
73
+ super.onAdded(viewer);
74
+ this._gbufferUnpackExtensionChanged();
75
+ viewer.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
76
+ viewer.renderManager.addEventListener("resize", this._pass.onSizeUpdate);
108
77
  }
109
- onRemove(e) {
110
- e.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged), e.renderManager.removeEventListener("resize", this._pass.onSizeUpdate), super.onRemove(e);
78
+ onRemove(viewer) {
79
+ viewer.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
80
+ viewer.renderManager.removeEventListener("resize", this._pass.onSizeUpdate);
81
+ super.onRemove(viewer);
111
82
  }
112
- _beforeRender(e, i, r) {
113
- if (!super._beforeRender(e, i, r))
114
- return !1;
115
- const t = this.pass, s = this._viewer;
116
- if (!t || !s)
117
- return !1;
118
- const o = r.frameCount;
119
- if (t.taaEnabled = o <= 1 && e.renderCamera === e.mainCamera, !t.taaEnabled)
120
- return !1;
121
- const n = i;
122
- return n ? (n.updateMatrixWorld(!0), n.updateShaderProperties(t.material), t.updateCameraProperties(n), t.target = s.getPlugin(O).target, !0) : !1;
83
+ _beforeRender(scene, camera, renderManager) {
84
+ if (!super._beforeRender(scene, camera, renderManager)) return false;
85
+ const pass = this.pass;
86
+ const v = this._viewer;
87
+ if (!pass || !v) return false;
88
+ const frame = renderManager.frameCount;
89
+ pass.taaEnabled = frame <= 1 && scene.renderCamera === scene.mainCamera;
90
+ if (!pass.taaEnabled) return false;
91
+ const cam = camera;
92
+ if (!cam) return false;
93
+ cam.updateMatrixWorld(true);
94
+ cam.updateShaderProperties(pass.material);
95
+ pass.updateCameraProperties(cam);
96
+ pass.target = v.getPlugin(ProgressivePlugin).target;
97
+ return true;
123
98
  }
124
99
  // region to be done or removed
125
100
  // static AddTemporalAAData(material: IMaterial, params?: IMaterialUserData['TemporalAA'], setDirty = true): IMaterialUserData['TemporalAA']|null {
@@ -166,39 +141,46 @@ const Ie = "taa", G = class G extends I {
166
141
  // }
167
142
  // endregion
168
143
  };
169
- G.PluginType = "TAA", G.OldPluginType = "TemporalAAPlugin";
170
- let M = G;
171
- q([
172
- R("Stable Noise (Total frame count)")
173
- ], M.prototype, "stableNoise", 1);
174
- q([
175
- Q()
176
- ], M.prototype, "_pass", 2);
177
- class ee extends $ {
178
- constructor(e, i) {
179
- var r;
144
+ _TemporalAAPlugin.PluginType = "TAA";
145
+ _TemporalAAPlugin.OldPluginType = "TemporalAAPlugin";
146
+ let TemporalAAPlugin = _TemporalAAPlugin;
147
+ __decorateClass$5([
148
+ uiToggle("Stable Noise (Total frame count)")
149
+ ], TemporalAAPlugin.prototype, "stableNoise", 1);
150
+ __decorateClass$5([
151
+ uiConfig()
152
+ ], TemporalAAPlugin.prototype, "_pass", 2);
153
+ class TemporalAAPluginPass extends ExtendedShaderPass {
154
+ constructor(pid, target, applyOnBackground = true) {
155
+ var _a2;
180
156
  super({
181
- vertexShader: ce.vertexShader,
182
- fragmentShader: Ne,
157
+ vertexShader: CopyShader.vertexShader,
158
+ fragmentShader: taaShader,
183
159
  uniforms: {
184
160
  currentRT: { value: null },
185
161
  previousRT: { value: null },
186
- previousRTSize: { value: new d() },
187
- cameraNearFar: { value: new d() },
188
- lastProjectionViewMatrix: { value: new E() },
189
- currentProjectionViewMatrix: { value: new E() },
190
- projection: { value: new E() },
191
- inverseViewMatrix: { value: new E() },
192
- jitterSample: { value: new d() },
193
- firstFrame: { value: !0 }
162
+ previousRTSize: { value: new Vector2() },
163
+ cameraNearFar: { value: new Vector2() },
164
+ lastProjectionViewMatrix: { value: new Matrix4() },
165
+ currentProjectionViewMatrix: { value: new Matrix4() },
166
+ projection: { value: new Matrix4() },
167
+ inverseViewMatrix: { value: new Matrix4() },
168
+ jitterSample: { value: new Vector2() },
169
+ firstFrame: { value: true }
194
170
  },
195
171
  defines: {
196
- // eslint-disable-next-line @typescript-eslint/naming-convention
197
- QUALITY: 1,
198
- // eslint-disable-next-line @typescript-eslint/naming-convention
199
- UNJITTER: 0
172
+ ["QUALITY"]: 1,
173
+ ["UNJITTER"]: 0,
174
+ ["BACKGROUND_TAA"]: applyOnBackground ? 1 : 0
200
175
  }
201
- }, "currentRT", "previousRT"), this.before = ["progressive"], this.after = [], this.required = ["render", "progressive"], this.taaEnabled = !0, this.feedBack = new d(0.88, 0.97), this.debugVelocity = !1, this.uiConfig = {
176
+ }, "currentRT", "previousRT");
177
+ this.before = ["progressive"];
178
+ this.after = [];
179
+ this.required = ["render", "progressive"];
180
+ this.taaEnabled = true;
181
+ this.feedBack = new Vector2(0.88, 0.97);
182
+ this.debugVelocity = false;
183
+ this.uiConfig = {
202
184
  type: "folder",
203
185
  label: "Temporal AA Pass",
204
186
  onChange: this.setDirty,
@@ -209,261 +191,325 @@ class ee extends $ {
209
191
  property: [this, "enabled"],
210
192
  onChange: () => this.onSizeUpdate()
211
193
  },
212
- ...((r = Y(this)) == null ? void 0 : r.filter((t) => t && t.label !== "Enabled")) || []
194
+ ...((_a2 = generateUiConfig(this)) == null ? void 0 : _a2.filter((c) => c && c.label !== "Enabled")) || []
213
195
  ]
214
- }, this.passId = e, this.onSizeUpdate = this.onSizeUpdate.bind(this), this.target = i, this.clear = !1, this.needsSwap = !0;
196
+ };
197
+ this.passId = pid;
198
+ this.onSizeUpdate = this.onSizeUpdate.bind(this);
199
+ this.target = target;
200
+ this.clear = false;
201
+ this.needsSwap = true;
215
202
  }
216
- render(e, i, r, t, s) {
203
+ render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
204
+ var _a2;
217
205
  if (!this.taaEnabled || !this.enabled) {
218
- this.needsSwap = !1;
206
+ this.needsSwap = false;
219
207
  return;
220
208
  }
221
- this.needsSwap = !0, this.uniforms.previousRT.value = this.target.texture, super.render(e, i, r, t, s), this.uniforms.lastProjectionViewMatrix.value.copy(this.uniforms.currentProjectionViewMatrix.value), this.uniforms.firstFrame.value = !1;
209
+ this.needsSwap = true;
210
+ this.uniforms.previousRT.value = ((_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) ?? null;
211
+ super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
212
+ this.uniforms.lastProjectionViewMatrix.value.copy(this.uniforms.currentProjectionViewMatrix.value);
213
+ this.uniforms.firstFrame.value = false;
222
214
  }
223
- updateCameraProperties(e) {
224
- e && (this.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse), this.uniforms.inverseViewMatrix.value.copy(e.matrixWorld));
215
+ updateCameraProperties(camera) {
216
+ if (!camera) return;
217
+ this.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
218
+ this.uniforms.inverseViewMatrix.value.copy(camera.matrixWorld);
225
219
  }
226
220
  onSizeUpdate() {
227
- this.uniforms.firstFrame.value = !0, this.setDirty();
221
+ this.uniforms.firstFrame.value = true;
222
+ this.setDirty();
228
223
  }
229
- setSize(e, i) {
230
- super.setSize(e, i), this.onSizeUpdate();
224
+ setSize(width, height) {
225
+ super.setSize(width, height);
226
+ this.onSizeUpdate();
231
227
  }
232
228
  }
233
- q([
234
- c(),
235
- f(),
236
- ue("Feedback", void 0, 1e-4)
237
- ], ee.prototype, "feedBack", 2);
238
- q([
239
- R(),
240
- fe("DEBUG_VELOCITY", void 0, !1, void 0, !0)
241
- ], ee.prototype, "debugVelocity", 2);
242
- var Ve = Object.defineProperty, je = Object.getOwnPropertyDescriptor, xe = (a, e, i, r) => {
243
- for (var t = r > 1 ? void 0 : r ? je(e, i) : e, s = a.length - 1, o; s >= 0; s--)
244
- (o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
245
- return r && t && Ve(e, i, t), t;
229
+ __decorateClass$5([
230
+ serialize(),
231
+ uniform(),
232
+ uiVector("Feedback", void 0, 1e-4)
233
+ ], TemporalAAPluginPass.prototype, "feedBack", 2);
234
+ __decorateClass$5([
235
+ uiToggle(),
236
+ matDefineBool("DEBUG_VELOCITY", void 0, false, void 0, true)
237
+ ], TemporalAAPluginPass.prototype, "debugVelocity", 2);
238
+ var __defProp$4 = Object.defineProperty;
239
+ var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
240
+ var __decorateClass$4 = (decorators, target, key, kind) => {
241
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
242
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
243
+ if (decorator = decorators[i])
244
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
245
+ if (kind && result) __defProp$4(target, key, result);
246
+ return result;
246
247
  };
247
- let L = class extends I {
248
- constructor(a = de, e = !0, i = !0) {
249
- super(), this.passId = "velocityBuffer", this.material = new He(), this.unpackExtension = {
250
- shaderExtender: (r) => {
251
- r.fragmentShader = B(
252
- r.fragmentShader,
253
- "//velocity_unpack",
254
- `
255
- ` + Be + `
256
- `
248
+ let VelocityBufferPlugin = class extends PipelinePassPlugin {
249
+ constructor(bufferType = UnsignedByteType, enabled = true, _attachToTaa = true) {
250
+ super();
251
+ this.passId = "velocityBuffer";
252
+ this.material = new SSVelocityMaterial();
253
+ this.unpackExtension = {
254
+ shaderExtender: (shader) => {
255
+ shader.fragmentShader = shaderReplaceString(
256
+ shader.fragmentShader,
257
+ "#pragma <velocity_unpack>",
258
+ "\n" + VelocityBufferUnpack + "\n"
257
259
  );
258
260
  },
259
261
  extraUniforms: {
260
262
  tVelocity: () => {
261
- var r;
262
- return { value: (r = this.target) == null ? void 0 : r.texture };
263
+ var _a2;
264
+ return { value: (_a2 = this.target) == null ? void 0 : _a2.texture };
263
265
  }
264
266
  },
265
267
  extraDefines: {
266
- HAS_VELOCITY_BUFFER: () => {
267
- var r;
268
- return (r = this.target) != null && r.texture ? 1 : void 0;
268
+ ["HAS_VELOCITY_BUFFER"]: () => {
269
+ var _a2;
270
+ return ((_a2 = this.target) == null ? void 0 : _a2.texture) ? 1 : void 0;
269
271
  }
270
272
  },
271
273
  priority: 100,
272
- isCompatible: () => !0
273
- }, this.enabled = e, this.bufferType = a, this._attachToTaa = i;
274
+ isCompatible: () => true
275
+ };
276
+ this.enabled = enabled;
277
+ this.bufferType = bufferType;
278
+ this._attachToTaa = _attachToTaa;
274
279
  }
275
280
  // cannot be changed after creation (for now)
276
- _createTarget(a = !0) {
277
- this._viewer && (a && this._disposeTarget(), this.target || (this.target = this._viewer.renderManager.createTarget(
281
+ _createTarget(recreate = true) {
282
+ if (!this._viewer) return;
283
+ if (recreate) this._disposeTarget();
284
+ if (!this.target) this.target = this._viewer.renderManager.createTarget(
278
285
  {
279
- depthBuffer: !0,
286
+ depthBuffer: true,
280
287
  // samples: v.renderManager.composerTarget.samples || 0,
281
288
  samples: 0,
282
289
  type: this.bufferType,
283
290
  // magFilter: NearestFilter,
284
291
  // minFilter: NearestFilter,
285
- generateMipmaps: !1,
286
- colorSpace: pe
292
+ generateMipmaps: false,
293
+ colorSpace: LinearSRGBColorSpace
287
294
  }
288
- )), this.texture = this.target.texture, this.texture.name = "velocityBuffer", this._pass && (this._pass.target = this.target));
295
+ );
296
+ this.texture = this.target.texture;
297
+ this.texture.name = "velocityBuffer";
298
+ if (this._pass) this._pass.target = this.target;
289
299
  }
290
300
  _disposeTarget() {
291
- this._viewer && (this.target && (this._viewer.renderManager.disposeTarget(this.target), this.target = void 0), this.texture = void 0);
301
+ if (!this._viewer) return;
302
+ if (this.target) {
303
+ this._viewer.renderManager.disposeTarget(this.target);
304
+ this.target = void 0;
305
+ }
306
+ this.texture = void 0;
292
307
  }
293
308
  _createPass() {
294
- if (this._createTarget(!0), !this.target)
295
- throw new Error("VelocityBufferPlugin: target not created");
296
- this.material.userData.isGBufferMaterial = !0;
297
- const a = this._viewer, e = new class extends Te {
309
+ this._createTarget(true);
310
+ if (!this.target) throw new Error("VelocityBufferPlugin: target not created");
311
+ this.material.userData.isGBufferMaterial = true;
312
+ const v = this._viewer;
313
+ const pass = new class extends GBufferRenderPass {
298
314
  constructor() {
299
- super(...arguments), this._firstCall = !0;
315
+ super(...arguments);
316
+ this._firstCall = true;
300
317
  }
301
- render(r, t, s, o, n) {
302
- if (a.renderManager.frameCount > 0 || !this.enabled || !this.camera)
303
- return;
304
- const l = this.overrideMaterial;
305
- l.uniforms.currentProjectionViewMatrix.value.copy(this.camera.projectionMatrix).multiply(this.camera.matrixWorldInverse), this._firstCall && (l.uniforms.lastProjectionViewMatrix.value.copy(l.uniforms.currentProjectionViewMatrix.value), this._firstCall = !1), super.render(r, t, s, o, n), l.uniforms.lastProjectionViewMatrix.value.copy(l.uniforms.currentProjectionViewMatrix.value);
318
+ render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
319
+ if (v.renderManager.frameCount > 0) return;
320
+ if (!this.enabled || !this.camera) return;
321
+ const mat = this.overrideMaterial;
322
+ mat.uniforms.currentProjectionViewMatrix.value.copy(this.camera.projectionMatrix).multiply(this.camera.matrixWorldInverse);
323
+ if (this._firstCall) {
324
+ mat.uniforms.lastProjectionViewMatrix.value.copy(mat.uniforms.currentProjectionViewMatrix.value);
325
+ this._firstCall = false;
326
+ }
327
+ super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
328
+ mat.uniforms.lastProjectionViewMatrix.value.copy(mat.uniforms.currentProjectionViewMatrix.value);
306
329
  }
307
- }(this.passId, this.target, this.material, new he(0.5, 0.5, 0.5), 1), i = e.preprocessMaterial;
308
- return e.preprocessMaterial = (r) => {
309
- var t;
310
- return i(r, (t = r.userData[L.PluginType]) == null ? void 0 : t.disabled);
311
- }, e.before = ["render"], e.after = [], e.required = ["render"], e;
330
+ }(this.passId, this.target, this.material, new Color(0.5, 0.5, 0.5), 1);
331
+ const preprocessMaterial = pass.preprocessMaterial;
332
+ pass.preprocessMaterial = (m) => {
333
+ var _a2;
334
+ return preprocessMaterial(m, (_a2 = m.userData[VelocityBufferPlugin.PluginType]) == null ? void 0 : _a2.disabled);
335
+ };
336
+ pass.before = ["render"];
337
+ pass.after = [];
338
+ pass.required = ["render"];
339
+ return pass;
312
340
  }
313
- onAdded(a) {
314
- var e;
315
- if (super.onAdded(a), this._attachToTaa) {
316
- const i = a.getPlugin(M);
317
- i ? (e = i.pass) == null || e.material.registerMaterialExtensions([this.unpackExtension]) : a.console.warn("VelocityBufferPlugin: TemporalAAPlugin not found, set attachToTaa to false if not required");
341
+ onAdded(viewer) {
342
+ var _a2;
343
+ super.onAdded(viewer);
344
+ if (this._attachToTaa) {
345
+ const taa = viewer.getPlugin(TemporalAAPlugin);
346
+ if (taa) (_a2 = taa.pass) == null ? void 0 : _a2.material.registerMaterialExtensions([this.unpackExtension]);
347
+ else viewer.console.warn("VelocityBufferPlugin: TemporalAAPlugin not found, set attachToTaa to false if not required");
318
348
  }
319
349
  }
320
- onRemove(a) {
321
- var e, i;
322
- return this._disposeTarget(), this._attachToTaa && ((i = (e = a.getPlugin(M)) == null ? void 0 : e.pass) == null || i.material.unregisterMaterialExtensions([this.unpackExtension])), super.onRemove(a);
350
+ onRemove(viewer) {
351
+ var _a2, _b;
352
+ this._disposeTarget();
353
+ if (this._attachToTaa) (_b = (_a2 = viewer.getPlugin(TemporalAAPlugin)) == null ? void 0 : _a2.pass) == null ? void 0 : _b.material.unregisterMaterialExtensions([this.unpackExtension]);
354
+ return super.onRemove(viewer);
323
355
  }
324
- _beforeRender(a, e, i) {
325
- if (!super._beforeRender(a, e, i))
326
- return !1;
327
- const r = this.pass;
328
- return !r || i.frameCount > 0 ? !1 : (r.scene = a, r.camera = e, e.updateShaderProperties(r.overrideMaterial), !0);
356
+ _beforeRender(scene, camera, renderManager) {
357
+ if (!super._beforeRender(scene, camera, renderManager)) return false;
358
+ const pass = this.pass;
359
+ if (!pass) return false;
360
+ if (renderManager.frameCount > 0) return false;
361
+ pass.scene = scene;
362
+ pass.camera = camera;
363
+ camera.updateShaderProperties(pass.overrideMaterial);
364
+ return true;
329
365
  }
330
366
  };
331
- L.PluginType = "VelocityBuffer";
332
- L.OldPluginType = "VelocityBufferPlugin";
333
- xe([
334
- ve(
367
+ VelocityBufferPlugin.PluginType = "VelocityBuffer";
368
+ VelocityBufferPlugin.OldPluginType = "VelocityBufferPlugin";
369
+ __decorateClass$4([
370
+ uiImage(
335
371
  "Velocity Buffer"
336
372
  /* {readOnly: true}*/
337
373
  )
338
- ], L.prototype, "texture", 2);
339
- L = xe([
340
- z("Velocity Buffer Plugin (for TAA)")
341
- ], L);
342
- class He extends be {
374
+ ], VelocityBufferPlugin.prototype, "texture", 2);
375
+ VelocityBufferPlugin = __decorateClass$4([
376
+ uiFolderContainer("Velocity Buffer Plugin (for TAA)")
377
+ ], VelocityBufferPlugin);
378
+ class SSVelocityMaterial extends ShaderMaterial {
343
379
  constructor() {
344
380
  super({
345
- vertexShader: Ae,
346
- fragmentShader: ze,
381
+ vertexShader: ssVelocityVert,
382
+ fragmentShader: ssVelocityFrag,
347
383
  uniforms: {
348
- cameraNearFar: { value: new d(0.1, 1e3) },
384
+ cameraNearFar: { value: new Vector2(0.1, 1e3) },
349
385
  alphaMap: { value: null },
350
386
  alphaTest: { value: null },
351
- alphaMapTransform: { value: /* @__PURE__ */ new Pe() },
352
- currentProjectionViewMatrix: { value: new E() },
353
- lastProjectionViewMatrix: { value: new E() }
387
+ alphaMapTransform: { value: /* @__PURE__ */ new Matrix3() },
388
+ currentProjectionViewMatrix: { value: new Matrix4() },
389
+ lastProjectionViewMatrix: { value: new Matrix4() }
354
390
  },
355
- blending: me
391
+ blending: NoBlending
356
392
  // todo?
357
- }), this.extraUniformsToUpload = {
358
- modelMatrixPrevious: { value: new E().identity() }
359
- }, this._previousWorldMatrices = {};
393
+ });
394
+ this.extraUniformsToUpload = {
395
+ modelMatrixPrevious: { value: new Matrix4().identity() }
396
+ };
397
+ this._previousWorldMatrices = {};
360
398
  }
361
399
  // this gets called for each object.
362
- onBeforeRender(e, i, r, t, s) {
363
- const o = this._previousWorldMatrices[s.uuid];
364
- this.extraUniformsToUpload.modelMatrixPrevious.value.copy(o ?? s.matrixWorld), o ? o.copy(s.matrixWorld) : this._previousWorldMatrices[s.uuid] = s.matrixWorld.clone();
365
- let n = s.material;
366
- Array.isArray(n) && (n = n[0]), this.uniforms.alphaMap.value = (n == null ? void 0 : n.alphaMap) ?? null, this.uniforms.alphaTest.value = !n || !n.alphaTest || n.alphaTest < 1e-7 ? 1e-3 : n.alphaTest;
367
- let l = this.uniforms.alphaMap.value ? 1 : void 0;
368
- l !== this.defines.USE_ALPHAMAP && (l === void 0 ? delete this.defines.USE_ALPHAMAP : this.defines.USE_ALPHAMAP = l, this.needsUpdate = !0), l = n != null && n.userData.ALPHA_I_RGBA_PACKING ? 1 : void 0, l !== this.defines.ALPHA_I_RGBA_PACKING && (l === void 0 ? delete this.defines.ALPHA_I_RGBA_PACKING : this.defines.ALPHA_I_RGBA_PACKING = l, this.needsUpdate = !0), this.side = (n == null ? void 0 : n.side) ?? Ce;
400
+ onBeforeRender(_r, _s, _c, _geometry, object) {
401
+ const prevMatrix = this._previousWorldMatrices[object.uuid];
402
+ this.extraUniformsToUpload.modelMatrixPrevious.value.copy(prevMatrix ?? object.matrixWorld);
403
+ if (prevMatrix) {
404
+ prevMatrix.copy(object.matrixWorld);
405
+ } else {
406
+ this._previousWorldMatrices[object.uuid] = object.matrixWorld.clone();
407
+ }
408
+ let mat = object.material;
409
+ if (Array.isArray(mat)) {
410
+ mat = mat[0];
411
+ }
412
+ this.uniforms.alphaMap.value = (mat == null ? void 0 : mat.alphaMap) ?? null;
413
+ this.uniforms.alphaTest.value = !mat || !mat.alphaTest || mat.alphaTest < 1e-7 ? 1e-3 : mat.alphaTest;
414
+ let x = this.uniforms.alphaMap.value ? 1 : void 0;
415
+ if (x !== this.defines.USE_ALPHAMAP) {
416
+ if (x === void 0) delete this.defines.USE_ALPHAMAP;
417
+ else this.defines.USE_ALPHAMAP = x;
418
+ this.needsUpdate = true;
419
+ }
420
+ x = (mat == null ? void 0 : mat.userData.ALPHA_I_RGBA_PACKING) ? 1 : void 0;
421
+ if (x !== this.defines.ALPHA_I_RGBA_PACKING) {
422
+ if (x === void 0) delete this.defines.ALPHA_I_RGBA_PACKING;
423
+ else this.defines.ALPHA_I_RGBA_PACKING = x;
424
+ this.needsUpdate = true;
425
+ }
426
+ this.side = (mat == null ? void 0 : mat.side) ?? DoubleSide;
369
427
  }
370
428
  }
371
- const Ge = `#include <packing>
372
- uniform float intensity;uniform float opacity;uniform vec2 tDiffuseSize;varying vec2 vUv;uniform float weight;
373
- #if PASS_STEP == 0
374
- uniform vec4 prefilter;vec4 Prefilter(vec4 c){
375
- #ifdef HAS_GBUFFER
376
- #if !BACKGROUND_BLOOM
377
- if(getDepth(vUv)>0.999){return vec4(0.0);}
378
- #endif
379
- #endif
380
- float 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);}
381
- #endif
382
- vec4 Sample(vec2 uv){return 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){
383
- #ifdef WebGL2Context
384
- return(number/4)% 2;
385
- #else
386
- return int(mod(floor(float(number)/4.),2.));
387
- #endif
388
- }void main(){
389
- #if PASS_STEP == 0
390
- #ifdef GBUFFER_HAS_FLAGS
391
- int doBloom=getBloomBit(getGBufferFlags(vUv).a);
392
- #else
393
- int doBloom=1;
394
- #endif
395
- gl_FragColor=float(doBloom)*weight*Prefilter(SampleBox(vUv,1.));gl_FragColor.a=1.;
396
- #elif PASS_STEP == 1
397
- gl_FragColor=weight*(SampleBox(vUv,1.));gl_FragColor.a=1.;
398
- #elif PASS_STEP == 2
399
- gl_FragColor=(SampleBox(vUv,0.5));gl_FragColor.a=1.;
400
- #elif PASS_STEP == 3
401
- vec4 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;
402
- #elif PASS_STEP == 4
403
- vec4 texel=vec4(0.);texel.rgb+=intensity*SampleBox(vUv,0.5).rgb;texel.a=1.;gl_FragColor=texel;
404
- #endif
405
- #include <encodings_fragment>
406
- }`;
407
- var We = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, P = (a, e, i, r) => {
408
- for (var t = r > 1 ? void 0 : r ? Ye(e, i) : e, s = a.length - 1, o; s >= 0; s--)
409
- (o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
410
- return r && t && We(e, i, t), t;
429
+ 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}";
430
+ var __defProp$3 = Object.defineProperty;
431
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
432
+ var __decorateClass$3 = (decorators, target, key, kind) => {
433
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
434
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
435
+ if (decorator = decorators[i])
436
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
437
+ if (kind && result) __defProp$3(target, key, result);
438
+ return result;
411
439
  };
412
- const $e = "bloom";
413
- var _;
414
- const Se = (_ = class extends I {
440
+ const passId$2 = "bloom";
441
+ const _BloomPlugin = (_a = class extends PipelinePassPlugin {
415
442
  constructor() {
416
- super(...arguments), this.passId = $e, this.materialExtension = ge(this._getUiConfig.bind(this), _.PluginType), this.dependencies = [T], this._onPluginAdd = (e) => {
417
- var r, t, s, o;
418
- if (((t = (r = e.plugin) == null ? void 0 : r.constructor) == null ? void 0 : t.PluginType) !== T.PluginType)
419
- return;
420
- const i = e.plugin;
421
- i.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this)), (s = this._pass) == null || s.material.registerMaterialExtensions([i.unpackExtension]), (o = this._viewer) == null || o.removeEventListener("addPlugin", this._onPluginAdd);
422
- }, this.uiConfig = {
443
+ super(...arguments);
444
+ this.passId = passId$2;
445
+ this.materialExtension = uiConfigMaterialExtension(this._getUiConfig.bind(this), _a.PluginType);
446
+ this.dependencies = [GBufferPlugin];
447
+ this._onPluginAdd = (e) => {
448
+ var _a2, _b, _c, _d;
449
+ if (((_b = (_a2 = e.plugin) == null ? void 0 : _a2.constructor) == null ? void 0 : _b.PluginType) !== GBufferPlugin.PluginType) return;
450
+ const gbuffer = e.plugin;
451
+ gbuffer.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this));
452
+ (_c = this._pass) == null ? void 0 : _c.material.registerMaterialExtensions([gbuffer.unpackExtension]);
453
+ (_d = this._viewer) == null ? void 0 : _d.removeEventListener("addPlugin", this._onPluginAdd);
454
+ };
455
+ this.uiConfig = {
423
456
  type: "folder",
424
457
  label: "Bloom Plugin",
425
458
  onChange: this.setDirty.bind(this),
426
459
  children: [
427
- ...Y(this) || []
460
+ ...generateUiConfig(this) || []
428
461
  ]
429
462
  };
430
463
  }
431
464
  _createPass() {
432
- return new h(this.passId);
465
+ var _a2;
466
+ const pass = new BloomPluginPass(this.passId, Math.min(8, ((_a2 = this._viewer) == null ? void 0 : _a2.renderManager.maxHDRIntensity) || 8));
467
+ return pass;
433
468
  }
434
- onAdded(e) {
435
- super.onAdded(e);
436
- const i = e.getPlugin(T);
437
- i ? (i.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this)), this._pass.material.registerMaterialExtensions([i.unpackExtension])) : e.addEventListener("addPlugin", this._onPluginAdd), e.materialManager.registerMaterialExtension(this.materialExtension);
469
+ onAdded(viewer) {
470
+ super.onAdded(viewer);
471
+ const gbuffer = viewer.getPlugin(GBufferPlugin);
472
+ if (gbuffer) {
473
+ gbuffer.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this));
474
+ this._pass.material.registerMaterialExtensions([gbuffer.unpackExtension]);
475
+ } else viewer.addEventListener("addPlugin", this._onPluginAdd);
476
+ viewer.materialManager.registerMaterialExtension(this.materialExtension);
438
477
  }
439
- onRemove(e) {
440
- var r;
441
- e.removeEventListener("addPlugin", this._onPluginAdd);
442
- const i = e.getPlugin(T);
443
- i == null || i.unregisterGBufferUpdater(this.constructor.PluginType), i && ((r = this._pass) == null || r.material.unregisterMaterialExtensions([i.unpackExtension])), e.materialManager.unregisterMaterialExtension(this.materialExtension), super.onRemove(e);
478
+ onRemove(viewer) {
479
+ var _a2;
480
+ viewer.removeEventListener("addPlugin", this._onPluginAdd);
481
+ const gbuffer = viewer.getPlugin(GBufferPlugin);
482
+ gbuffer == null ? void 0 : gbuffer.unregisterGBufferUpdater(this.constructor.PluginType);
483
+ gbuffer && ((_a2 = this._pass) == null ? void 0 : _a2.material.unregisterMaterialExtensions([gbuffer.unpackExtension]));
484
+ viewer.materialManager.unregisterMaterialExtension(this.materialExtension);
485
+ super.onRemove(viewer);
444
486
  }
445
- updateGBufferFlags(e, i) {
446
- var s;
447
- if (!i.material || !i.material.userData)
448
- return;
449
- const t = ((s = i.material.userData[_.PluginType]) == null ? void 0 : s.enable) === !1 || i.material.userData.pluginsDisabled ? 0 : 1;
450
- e.w = we(e.w, 2, t);
487
+ updateGBufferFlags(data, c) {
488
+ var _a2;
489
+ if (!c.material || !c.material.userData) return;
490
+ const disabled = ((_a2 = c.material.userData[_a.PluginType]) == null ? void 0 : _a2.enable) === false || c.material.userData.pluginsDisabled;
491
+ const x = disabled ? 0 : 1;
492
+ data.w = updateBit(data.w, 2, x);
451
493
  }
452
- static AddBloomData(e, i, r = !0) {
453
- const t = e == null ? void 0 : e.userData;
454
- if (!t)
455
- return null;
456
- t[_.PluginType] || (t[_.PluginType] = {});
457
- const s = t[_.PluginType];
458
- return s.enable = !0, i && Object.assign(s, i), r && e.setDirty && e.setDirty(), s;
494
+ static AddBloomData(material, params, setDirty = true) {
495
+ const ud = material == null ? void 0 : material.userData;
496
+ if (!ud) return null;
497
+ if (!ud[_a.PluginType]) {
498
+ ud[_a.PluginType] = {};
499
+ }
500
+ const data = ud[_a.PluginType];
501
+ data.enable = true;
502
+ params && Object.assign(data, params);
503
+ if (setDirty && material.setDirty) material.setDirty();
504
+ return data;
459
505
  }
460
506
  /**
461
507
  * This uiConfig is added to each material by extension
462
508
  * @param material
463
509
  * @private
464
510
  */
465
- _getUiConfig(e) {
466
- const i = {
511
+ _getUiConfig(material) {
512
+ const config = {
467
513
  type: "folder",
468
514
  label: "Bloom",
469
515
  children: [
@@ -471,31 +517,36 @@ const Se = (_ = class extends I {
471
517
  type: "checkbox",
472
518
  label: "Enabled",
473
519
  get value() {
474
- var r;
475
- return ((r = e.userData[_.PluginType]) == null ? void 0 : r.enable) ?? !0;
520
+ var _a2;
521
+ return ((_a2 = material.userData[_a.PluginType]) == null ? void 0 : _a2.enable) ?? true;
476
522
  },
477
- set value(r) {
478
- var s;
479
- let t = e.userData[_.PluginType];
480
- r !== (t == null ? void 0 : t.enable) && (t || (t = _.AddBloomData(e, void 0, !1)), t.enable = r, e.setDirty(), (s = i.uiRefresh) == null || s.call(i, !0, "postFrame"));
523
+ set value(v) {
524
+ var _a2;
525
+ let data = material.userData[_a.PluginType];
526
+ if (v === (data == null ? void 0 : data.enable)) return;
527
+ if (!data) data = _a.AddBloomData(material, void 0, false);
528
+ data.enable = v;
529
+ material.setDirty();
530
+ (_a2 = config.uiRefresh) == null ? void 0 : _a2.call(config, true, "postFrame");
481
531
  },
482
532
  onChange: this.setDirty
483
533
  }
484
534
  ]
485
535
  };
486
- return i;
536
+ return config;
487
537
  }
488
- }, _.PluginType = "Bloom", _.OldPluginType = "BloomPlugin", _);
489
- P([
490
- Q()
491
- ], Se.prototype, "_pass", 2);
492
- let qe = Se, h = class extends $ {
493
- constructor(a) {
538
+ }, _a.PluginType = "Bloom", _a.OldPluginType = "BloomPlugin", _a);
539
+ __decorateClass$3([
540
+ uiConfig()
541
+ ], _BloomPlugin.prototype, "_pass", 2);
542
+ let BloomPlugin = _BloomPlugin;
543
+ let BloomPluginPass = class extends ExtendedShaderPass {
544
+ constructor(pid, maxIntensity = 16) {
494
545
  super({
495
- vertexShader: ce.vertexShader,
546
+ vertexShader: CopyShader.vertexShader,
496
547
  defines: {
497
- // eslint-disable-next-line @typescript-eslint/naming-convention
498
- PASS_STEP: 1
548
+ ["PASS_STEP"]: 1,
549
+ ["MAX_INTENSITY"]: Math.min(maxIntensity, 16)
499
550
  },
500
551
  uniforms: {
501
552
  tSource: { value: null },
@@ -503,213 +554,323 @@ let qe = Se, h = class extends $ {
503
554
  // intensity: {value: 0.2},
504
555
  opacity: { value: 1 },
505
556
  // prefilter: {value: new Vector4(1, 0.5, 0, 0)},
506
- tDiffuseSize: { value: new d() },
557
+ tDiffuseSize: { value: new Vector2() },
507
558
  weight: { value: 1 }
508
559
  // tNormalDepth: {value: null},
509
560
  // tGBufferFlags: {value: null},
510
561
  },
511
- fragmentShader: Ge
512
- }, "tDiffuse", "tSource"), this.uiConfig = void 0, this.before = ["screen"], this.after = ["render", "progressive"], this.required = ["render"], this.prefilter = new Ee(2, 0.5, 0, 0), this.threshold = 2, this.softThreshold = 0.5, this.intensity = 0.2, this.backgroundBloom = !1, this.bloomIterations = 4, this.radius = 0.6, this.power = 1, this.bloomDebug = !1, this._weights = [], this.passId = a, this._updateWeights = this._updateWeights.bind(this), this._thresholdsUpdated = this._thresholdsUpdated.bind(this), this._updateWeights(), this._thresholdsUpdated(), this.clear = !0;
562
+ fragmentShader: hdrBloom
563
+ }, "tDiffuse", "tSource");
564
+ this.uiConfig = void 0;
565
+ this.before = ["screen"];
566
+ this.after = ["render", "progressive"];
567
+ this.required = ["render"];
568
+ this.prefilter = new Vector4(2, 0.5, 0, 0);
569
+ this.threshold = 2;
570
+ this.softThreshold = 0.5;
571
+ this.intensity = 0.2;
572
+ this.backgroundBloom = false;
573
+ this.bloomIterations = 4;
574
+ this._currentIterations = 0;
575
+ this.radius = 0.6;
576
+ this.power = 1;
577
+ this.bloomDebug = false;
578
+ this._weights = [];
579
+ this.passId = pid;
580
+ this._updateWeights = this._updateWeights.bind(this);
581
+ this._thresholdsUpdated = this._thresholdsUpdated.bind(this);
582
+ this._updateWeights();
583
+ this._thresholdsUpdated();
584
+ this.clear = true;
513
585
  }
514
586
  _thresholdsUpdated() {
515
- this.prefilter.x = this.threshold, this.prefilter.y = this.softThreshold, this.prefilter.z = 2 * this.prefilter.x * this.prefilter.y, this.prefilter.w = 0.125 / (this.uniforms.prefilter.value.z + 1e-5);
587
+ var _a2;
588
+ this.prefilter.x = this.threshold;
589
+ this.prefilter.y = this.softThreshold;
590
+ this.prefilter.z = 2 * this.prefilter.x * this.prefilter.y;
591
+ this.prefilter.w = ((_a2 = this.uniforms) == null ? void 0 : _a2.prefilter) ? 0.125 / (this.uniforms.prefilter.value.z + 1e-5) : 0;
516
592
  }
517
- render(a, e, i, r, t) {
518
- const s = a.renderManager;
519
- this.material.defines.PASS_STEP = 0, this.clear = !0, this.needsSwap = !1;
520
- const o = i;
521
- if (!o) {
593
+ render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
594
+ const renderManager = renderer.renderManager;
595
+ this.material.defines.PASS_STEP = 0;
596
+ this.clear = true;
597
+ this.needsSwap = false;
598
+ const source = readBuffer;
599
+ if (!source) {
522
600
  console.warn("BloomPluginPass: No source to read from");
523
601
  return;
524
602
  }
525
- this.needsSwap = !0;
526
- let n = 0.5, l = o.width * n, m = o.height * n;
527
- const g = [];
528
- let C = s.getTempTarget({ sizeMultiplier: 1, type: K });
529
- g.push(C);
530
- let w = o;
531
- this.material.needsUpdate = !0, this.material.uniforms.weight.value = this._weights[0], super.render(a, C, w, r, t), w = C;
532
- let y = 1;
533
- for (; y < this.bloomIterations && (l /= 2, m /= 2, n /= 2, !(m < 2 || l < 2)); y++) {
534
- C = s.getTempTarget({ sizeMultiplier: n, type: K }), g.push(C), this.material.defines.PASS_STEP = 1;
535
- let te = this._weights[y];
536
- te = this._weights[y - 1] !== 0 ? this._weights[y] / this._weights[y - 1] : this._weights[y], this.material.uniforms.weight.value = te, this.material.needsUpdate = !0, super.render(a, C, w, r, t), w = C;
603
+ this.needsSwap = true;
604
+ let sizeMultiplier = 0.5;
605
+ let width = source.width * sizeMultiplier;
606
+ let height = source.height * sizeMultiplier;
607
+ const textures = [];
608
+ let currentDestination = renderManager.getTempTarget({ sizeMultiplier: 1, type: HalfFloatType });
609
+ textures.push(currentDestination);
610
+ let currentSource = source;
611
+ this.material.needsUpdate = true;
612
+ this.material.uniforms.weight.value = this._weights[0];
613
+ super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
614
+ currentSource = currentDestination;
615
+ const ci = this._currentIterations;
616
+ let i = 1;
617
+ const iter = Math.max(2, this.bloomIterations);
618
+ for (; i < iter; i++) {
619
+ width /= 2;
620
+ height /= 2;
621
+ sizeMultiplier /= 2;
622
+ if (height < 2 || width < 2) {
623
+ break;
624
+ }
625
+ currentDestination = renderManager.getTempTarget({ sizeMultiplier, type: HalfFloatType });
626
+ textures.push(currentDestination);
627
+ this.material.defines.PASS_STEP = 1;
628
+ let modifiedWeight = this._weights[i];
629
+ {
630
+ modifiedWeight = this._weights[i - 1] !== 0 ? this._weights[i] / this._weights[i - 1] : this._weights[i];
631
+ }
632
+ this.material.uniforms.weight.value = modifiedWeight;
633
+ this.material.needsUpdate = true;
634
+ super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
635
+ currentSource = currentDestination;
636
+ this._currentIterations = i + 1;
637
+ }
638
+ if (ci !== this._currentIterations)
639
+ this._updateWeights(false);
640
+ this.clear = false;
641
+ const oldAutoClear = renderer.autoClear;
642
+ renderer.autoClear = false;
643
+ for (i -= 2; i >= 0; i--) {
644
+ currentDestination = textures[i];
645
+ textures[i] = void 0;
646
+ this.material.defines.PASS_STEP = 2;
647
+ this.material.transparent = true;
648
+ this.material.blending = AdditiveBlending;
649
+ this.material.needsUpdate = true;
650
+ renderer.autoClear = false;
651
+ super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
652
+ this.material.blending = NoBlending;
653
+ renderManager.releaseTempTarget(currentSource);
654
+ currentSource = currentDestination;
537
655
  }
538
- this.clear = !1;
539
- const ye = a.autoClear;
540
- for (a.autoClear = !1, y -= 2; y >= 0; y--)
541
- C = g[y], g[y] = void 0, this.material.defines.PASS_STEP = 2, this.material.transparent = !0, this.material.blending = De, this.material.needsUpdate = !0, a.autoClear = !1, super.render(a, C, w, r, t), this.material.blending = me, s.releaseTempTarget(w), w = C;
542
- this.clear = !0, a.autoClear = ye, a.autoClear = !0, this.bloomDebug ? (this.material.defines.PASS_STEP = 4, this.material.needsUpdate = !0, super.render(a, e, w, r, t)) : (this.uniforms.tSource.value = o.texture, this.material.defines.PASS_STEP = 3, this.material.needsUpdate = !0, super.render(a, e, w, r, t), this.uniforms.tSource.value = null), s.releaseTempTarget(w);
656
+ this.clear = true;
657
+ renderer.autoClear = oldAutoClear;
658
+ renderer.autoClear = true;
659
+ if (this.bloomDebug) {
660
+ this.material.defines.PASS_STEP = 4;
661
+ this.material.needsUpdate = true;
662
+ super.render(renderer, writeBuffer, currentSource, deltaTime, maskActive);
663
+ } else {
664
+ this.uniforms.tSource.value = source.texture;
665
+ this.material.defines.PASS_STEP = 3;
666
+ this.material.needsUpdate = true;
667
+ super.render(renderer, writeBuffer, currentSource, deltaTime, maskActive);
668
+ this.uniforms.tSource.value = null;
669
+ }
670
+ renderManager.releaseTempTarget(currentSource);
543
671
  }
544
- _updateWeights() {
545
- if (!this._weights)
546
- return;
547
- const a = Math.max(Math.min(this.radius, 1), 0), e = 1 / (this.bloomIterations - 1);
548
- for (let i = 0; i < this.bloomIterations; i++) {
549
- let r = i * e + 0.1, t = 1.2 - r;
550
- r = Math.pow(r, this.power), t = Math.pow(t, this.power), this._weights[i] = t * (1 - a) + r * a;
672
+ _updateWeights(setDirty = true) {
673
+ if (!this._weights) return;
674
+ const radius = Math.max(Math.min(this.radius, 1), 0);
675
+ const iter = Math.max(2, this._currentIterations || this.bloomIterations);
676
+ const delta = 1 / (iter - 1);
677
+ for (let i = 0; i < iter; i++) {
678
+ let f = i * delta + 0.1;
679
+ let oneMinusF = 1.2 - f;
680
+ f = Math.pow(f, this.power);
681
+ oneMinusF = Math.pow(oneMinusF, this.power);
682
+ this._weights[i] = oneMinusF * (1 - radius) + f * radius;
551
683
  }
552
- this.setDirty();
684
+ if (setDirty !== false) this.setDirty();
553
685
  }
554
686
  };
555
- P([
556
- f()
557
- ], h.prototype, "prefilter", 2);
558
- P([
559
- u("Threshold", [0, 2]),
560
- N(h.prototype._thresholdsUpdated),
561
- c()
562
- ], h.prototype, "threshold", 2);
563
- P([
564
- u("Soft Threshold", [0, 1]),
565
- N(h.prototype._thresholdsUpdated),
566
- c()
567
- ], h.prototype, "softThreshold", 2);
568
- P([
569
- u("Intensity", [0, 3]),
570
- c(),
571
- f()
572
- ], h.prototype, "intensity", 2);
573
- P([
574
- R("Background Bloom"),
575
- c(),
576
- V("BACKGROUND_BLOOM", void 0, !1, void 0, (a) => a ? "1" : "0", (a) => a && a !== "0")
577
- ], h.prototype, "backgroundBloom", 2);
578
- P([
579
- u("Iterations", [0, 7], 1),
580
- N(h.prototype._updateWeights),
581
- c()
582
- ], h.prototype, "bloomIterations", 2);
583
- P([
584
- u("Radius", [0, 1], 0.01),
585
- N(h.prototype._updateWeights),
586
- c()
587
- ], h.prototype, "radius", 2);
588
- P([
589
- u("Power", [0.2, 10], 0.01),
590
- N(h.prototype._updateWeights),
591
- c()
592
- ], h.prototype, "power", 2);
593
- P([
594
- R("Debug")
595
- ], h.prototype, "bloomDebug", 2);
596
- h = P([
597
- z("Bloom Pass")
598
- ], h);
599
- const Ke = `#include <common>
600
- #include <packing>
601
- varying 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);}
602
- #include <encodings_fragment>
603
- }`, Ze = `#include <randomHelpers>
604
- #include <common>
605
- varying vec2 vUv;uniform vec2 colorTextureSize;uniform float blurRadius;uniform float frameCount;vec4 CircularBlur(){vec4 color=colorTextureTexelToLinear(texture2D(colorTexture,vUv));
606
- #ifdef DOF_MODE
607
- float blurDist=blurRadius*(2.*color.a-1.);
608
- #else
609
- float blurDist=blurRadius*color.a;
610
- #endif
611
- float 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();
612
- #pragma unroll_loop_start
613
- for(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));
614
- #ifdef DOF_MODE
615
- sampleColor.a=abs(sampleColor.a*2.0-1.0);sampleColor.a*=sampleColor.a*sampleColor.a;
616
- #endif
617
- colorSum+=sampleColor.rgb*sampleColor.a;weightSum+=sampleColor.a;}
618
- #pragma unroll_loop_end
619
- colorSum/=weightSum;return vec4(min(vec3(72.),max(vec3(0.),colorSum)),1.0);}void main(){gl_FragColor=CircularBlur();
620
- #include <encodings_fragment>
621
- }`, Je = "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);}", Qe = `#include <common>
622
- #include <packing>
623
- varying 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);
624
- #include <encodings_fragment>
625
- }`, Xe = `#include <common>
626
- #include <gbuffer_unpack>
627
- varying 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);
628
- #include <encodings_fragment>
629
- }`;
630
- var et = Object.defineProperty, tt = Object.getOwnPropertyDescriptor, S = (a, e, i, r) => {
631
- for (var t = r > 1 ? void 0 : r ? tt(e, i) : e, s = a.length - 1, o; s >= 0; s--)
632
- (o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
633
- return r && t && et(e, i, t), t;
687
+ __decorateClass$3([
688
+ uniform()
689
+ ], BloomPluginPass.prototype, "prefilter", 2);
690
+ __decorateClass$3([
691
+ uiSlider("Threshold", [0, 2]),
692
+ onChange(BloomPluginPass.prototype._thresholdsUpdated),
693
+ serialize()
694
+ ], BloomPluginPass.prototype, "threshold", 2);
695
+ __decorateClass$3([
696
+ uiSlider("Soft Threshold", [0, 1]),
697
+ onChange(BloomPluginPass.prototype._thresholdsUpdated),
698
+ serialize()
699
+ ], BloomPluginPass.prototype, "softThreshold", 2);
700
+ __decorateClass$3([
701
+ uiSlider("Intensity", [0, 3]),
702
+ serialize(),
703
+ uniform()
704
+ ], BloomPluginPass.prototype, "intensity", 2);
705
+ __decorateClass$3([
706
+ uiToggle("Background Bloom"),
707
+ serialize(),
708
+ matDefineBool("BACKGROUND_BLOOM")
709
+ ], BloomPluginPass.prototype, "backgroundBloom", 2);
710
+ __decorateClass$3([
711
+ uiSlider("Iterations", [2, 7], 1),
712
+ onChange2(BloomPluginPass.prototype._updateWeights),
713
+ serialize()
714
+ ], BloomPluginPass.prototype, "bloomIterations", 2);
715
+ __decorateClass$3([
716
+ uiSlider("Radius", [0, 1], 0.01),
717
+ onChange2(BloomPluginPass.prototype._updateWeights),
718
+ serialize()
719
+ ], BloomPluginPass.prototype, "radius", 2);
720
+ __decorateClass$3([
721
+ uiSlider("Power", [0.2, 10], 0.01),
722
+ onChange2(BloomPluginPass.prototype._updateWeights),
723
+ serialize()
724
+ ], BloomPluginPass.prototype, "power", 2);
725
+ __decorateClass$3([
726
+ uiToggle("Debug")
727
+ ], BloomPluginPass.prototype, "bloomDebug", 2);
728
+ BloomPluginPass = __decorateClass$3([
729
+ uiFolderContainer("Bloom Pass")
730
+ ], BloomPluginPass);
731
+ 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}";
732
+ const dofPoissonBox = "#include <randomHelpers>\n#include <common>\nvarying vec2 vUv;uniform vec2 colorTextureSize;uniform float blurRadius;uniform float frameCount;vec4 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}";
733
+ 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);}";
734
+ 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}";
735
+ 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}";
736
+ var __defProp$2 = Object.defineProperty;
737
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
738
+ var __decorateClass$2 = (decorators, target, key, kind) => {
739
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
740
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
741
+ if (decorator = decorators[i])
742
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
743
+ if (kind && result) __defProp$2(target, key, result);
744
+ return result;
634
745
  };
635
- const rt = "depthOfField", W = class W extends I {
746
+ const passId$1 = "depthOfField";
747
+ const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin {
636
748
  // ms
637
- constructor(e = !0, i = !1) {
638
- super(), this.passId = rt, this.enableEdit = !1, this._focalPointHit = new U(0, 0, 0), this.crossFadeTime = 200, this._focalPointHitTime = 0, this.dependencies = [T], this._onPluginAdd = (r) => {
639
- var s, o, n, l, m;
640
- const t = r.plugin;
641
- if (t) {
642
- if (((s = t.constructor) == null ? void 0 : s.PluginType) === T.PluginType) {
643
- const g = t;
644
- (o = this._pass) == null || o.material.registerMaterialExtensions([g.unpackExtension]), (n = this._pass) == null || n.computeCocMaterial.registerMaterialExtensions([g.unpackExtension]), (l = this._pass) == null || l.expandCocMaterial.registerMaterialExtensions([g.unpackExtension]);
645
- }
646
- ((m = t.constructor) == null ? void 0 : m.PluginType) === j.PluginType && t.addEventListener("hitObject", this._onObjectHit);
749
+ constructor(enabled = true, enableEdit = false) {
750
+ super();
751
+ this.passId = passId$1;
752
+ this.enableEdit = false;
753
+ this._focalPointHit = new Vector3(0, 0, 0);
754
+ this.crossFadeTime = 200;
755
+ this._focalPointHitTime = 0;
756
+ this.dependencies = [GBufferPlugin];
757
+ this._onPluginAdd = (e) => {
758
+ var _a2, _b, _c, _d, _e;
759
+ const plugin = e.plugin;
760
+ if (!plugin) return;
761
+ if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
762
+ const gbuffer = plugin;
763
+ (_b = this._pass) == null ? void 0 : _b.material.registerMaterialExtensions([gbuffer.unpackExtension]);
764
+ (_c = this._pass) == null ? void 0 : _c.computeCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
765
+ (_d = this._pass) == null ? void 0 : _d.expandCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
647
766
  }
648
- }, this._onPluginRemove = (r) => {
649
- var s, o, n, l, m;
650
- const t = r.plugin;
651
- if (t) {
652
- if (((s = t.constructor) == null ? void 0 : s.PluginType) === T.PluginType) {
653
- const g = r.plugin;
654
- (o = this._pass) == null || o.material.unregisterMaterialExtensions([g.unpackExtension]), (n = this._pass) == null || n.computeCocMaterial.unregisterMaterialExtensions([g.unpackExtension]), (l = this._pass) == null || l.expandCocMaterial.unregisterMaterialExtensions([g.unpackExtension]);
655
- }
656
- ((m = t.constructor) == null ? void 0 : m.PluginType) === j.PluginType && r.plugin.removeEventListener("hitObject", this._onObjectHit);
767
+ if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
768
+ const picking = plugin;
769
+ picking.addEventListener("hitObject", this._onObjectHit);
657
770
  }
658
- }, this.uiConfig = {
771
+ };
772
+ this._onPluginRemove = (e) => {
773
+ var _a2, _b, _c, _d, _e;
774
+ const plugin = e.plugin;
775
+ if (!plugin) return;
776
+ if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
777
+ const gbuffer = e.plugin;
778
+ (_b = this._pass) == null ? void 0 : _b.material.unregisterMaterialExtensions([gbuffer.unpackExtension]);
779
+ (_c = this._pass) == null ? void 0 : _c.computeCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
780
+ (_d = this._pass) == null ? void 0 : _d.expandCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
781
+ }
782
+ if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
783
+ const picking = e.plugin;
784
+ picking.removeEventListener("hitObject", this._onObjectHit);
785
+ }
786
+ };
787
+ this.uiConfig = {
659
788
  type: "folder",
660
789
  label: "DepthOfField",
661
790
  onChange: this.setDirty.bind(this),
662
791
  children: [
663
- ...Y(this) || [],
792
+ ...generateUiConfig(this) || [],
664
793
  () => {
665
- var r;
666
- return (r = this._pass) == null ? void 0 : r.uiConfig;
794
+ var _a2;
795
+ return (_a2 = this._pass) == null ? void 0 : _a2.uiConfig;
667
796
  }
668
797
  ]
669
- }, this._tempVec = new U(), this.enabled = e, this.enableEdit = i, this._onObjectHit = this._onObjectHit.bind(this), this.setDirty = this.setDirty.bind(this);
798
+ };
799
+ this._tempVec = new Vector3();
800
+ this.enabled = enabled;
801
+ this.enableEdit = enableEdit;
802
+ this._onObjectHit = this._onObjectHit.bind(this);
803
+ this.setDirty = this.setDirty.bind(this);
670
804
  }
671
805
  get _frameFadeTime() {
672
806
  return this.crossFadeTime * 2.5;
673
807
  }
674
808
  // todo make this a property.
675
- setFocalPoint(e, i = !0, r = !1) {
676
- var t, s;
677
- this._focalPointHit.copy(e), i && ((s = (t = this._viewer) == null ? void 0 : t.getPlugin("FrameFadePlugin")) == null || s.startTransition(this._frameFadeTime)), r && (this._focalPointHitTime = re()), this.setDirty();
809
+ setFocalPoint(p, fade = true, showGizmo = false) {
810
+ var _a2, _b;
811
+ this._focalPointHit.copy(p);
812
+ if (fade) (_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin("FrameFadePlugin")) == null ? void 0 : _b.startTransition(this._frameFadeTime);
813
+ if (showGizmo) this._focalPointHitTime = now();
814
+ this.setDirty();
678
815
  }
679
816
  getFocalPoint() {
680
817
  return this._focalPointHit;
681
818
  }
682
819
  _onObjectHit(e) {
683
- var i, r;
684
- !this._pass || !e.intersects.intersect || this.isDisabled() || !this.enableEdit || (this._focalPointHit.copy(e.intersects.intersect.point), this._focalPointHitTime = e.time, e.intersects.selectedObject = null, (r = (i = this._viewer) == null ? void 0 : i.getPlugin(Re)) == null || r.startTransition(this._frameFadeTime), this.setDirty());
820
+ var _a2, _b;
821
+ if (!this._pass || !e.intersects.intersect || this.isDisabled() || !this.enableEdit) return;
822
+ this._focalPointHit.copy(e.intersects.intersect.point);
823
+ this._focalPointHitTime = e.time;
824
+ e.intersects.selectedObject = null;
825
+ (_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(FrameFadePlugin)) == null ? void 0 : _b.startTransition(this._frameFadeTime);
826
+ this.setDirty();
685
827
  }
686
828
  _createPass() {
687
- return new b(this.passId);
829
+ const pass = new DepthOfFieldPluginPass(this.passId);
830
+ return pass;
688
831
  }
689
832
  // todo use gbufferUnpackExtension from render manager to support depth buffer plugin as well.
690
- onAdded(e) {
691
- super.onAdded(e), e.addEventListener("addPlugin", this._onPluginAdd), e.addEventListener("removePlugin", this._onPluginRemove), this._onPluginAdd({ plugin: e.getPlugin(T) }), this._onPluginAdd({ plugin: e.getPlugin(j) });
833
+ onAdded(viewer) {
834
+ super.onAdded(viewer);
835
+ viewer.addEventListener("addPlugin", this._onPluginAdd);
836
+ viewer.addEventListener("removePlugin", this._onPluginRemove);
837
+ this._onPluginAdd({ plugin: viewer.getPlugin(GBufferPlugin) });
838
+ this._onPluginAdd({ plugin: viewer.getPlugin(PickingPlugin) });
692
839
  }
693
- onRemove(e) {
694
- e.removeEventListener("addPlugin", this._onPluginAdd), e.removeEventListener("removePlugin", this._onPluginRemove), this._onPluginRemove({ plugin: e.getPlugin(T) }), this._onPluginRemove({ plugin: e.getPlugin(j) }), super.onRemove(e);
840
+ onRemove(viewer) {
841
+ viewer.removeEventListener("addPlugin", this._onPluginAdd);
842
+ viewer.removeEventListener("removePlugin", this._onPluginRemove);
843
+ this._onPluginRemove({ plugin: viewer.getPlugin(GBufferPlugin) });
844
+ this._onPluginRemove({ plugin: viewer.getPlugin(PickingPlugin) });
845
+ super.onRemove(viewer);
695
846
  }
696
- _beforeRender(e, i, r) {
697
- if (!super._beforeRender(e, i, r))
698
- return !1;
699
- const t = this.pass;
700
- if (!t)
701
- return !1;
702
- t.dofBlurMaterial.uniforms.frameCount && (r == null || r.updateShaderProperties(t.dofBlurMaterial));
703
- const s = i;
704
- if (!s)
705
- return !1;
706
- s.updateMatrixWorld(!0), s.updateShaderProperties(t.material), s.getWorldPosition(this._tempVec), this._tempVec.subVectors(this._focalPointHit, this._tempVec), t.focalDepthRange.x = this._tempVec.length(), t.focalDepthRange.x *= s.getWorldDirection(new U()).dot(this._tempVec.normalize());
707
- let o = (re() - this._focalPointHitTime) / this.crossFadeTime;
708
- if (o = 1 - Math.min(1, Math.max(0, o)), Math.abs(o - t.crossAlpha) > 0.01 && (t.crossAlpha = o, this.setDirty()), o > 0) {
709
- const n = this._tempVec.copy(this._focalPointHit).project(s).addScalar(1).divideScalar(2);
710
- t.crossCenter.set(n.x, n.y), t.computeCocMaterial.uniformsNeedUpdate = !0, t.expandCocMaterial.uniformsNeedUpdate = !0;
847
+ _beforeRender(scene, camera, renderManager) {
848
+ if (!super._beforeRender(scene, camera, renderManager)) return false;
849
+ const pass = this.pass;
850
+ if (!pass) return false;
851
+ if (pass.dofBlurMaterial.uniforms.frameCount)
852
+ renderManager == null ? void 0 : renderManager.updateShaderProperties(pass.dofBlurMaterial);
853
+ const cam = camera;
854
+ if (!cam) return false;
855
+ cam.updateMatrixWorld(true);
856
+ cam.updateShaderProperties(pass.material);
857
+ cam.getWorldPosition(this._tempVec);
858
+ this._tempVec.subVectors(this._focalPointHit, this._tempVec);
859
+ pass.focalDepthRange.x = this._tempVec.length();
860
+ pass.focalDepthRange.x *= cam.getWorldDirection(new Vector3()).dot(this._tempVec.normalize());
861
+ let crossAlpha = (now() - this._focalPointHitTime) / this.crossFadeTime;
862
+ crossAlpha = 1 - Math.min(1, Math.max(0, crossAlpha));
863
+ if (Math.abs(crossAlpha - pass.crossAlpha) > 0.01) {
864
+ pass.crossAlpha = crossAlpha;
865
+ this.setDirty();
866
+ }
867
+ if (crossAlpha > 0) {
868
+ const projectedPoint = this._tempVec.copy(this._focalPointHit).project(cam).addScalar(1).divideScalar(2);
869
+ pass.crossCenter.set(projectedPoint.x, projectedPoint.y);
870
+ pass.computeCocMaterial.uniformsNeedUpdate = true;
871
+ pass.expandCocMaterial.uniformsNeedUpdate = true;
711
872
  }
712
- return !0;
873
+ return true;
713
874
  }
714
875
  // region to be done or removed
715
876
  // static AddDepthOfFieldData(material: IMaterial, params?: IMaterialUserData['DepthOfField'], setDirty = true): IMaterialUserData['DepthOfField']|null {
@@ -789,174 +950,213 @@ const rt = "depthOfField", W = class W extends I {
789
950
  // }
790
951
  // endregion
791
952
  };
792
- W.PluginType = "DepthOfField", W.OldPluginType = "DepthOfFieldPlugin";
793
- let A = W;
794
- S([
795
- c(),
796
- R()
797
- ], A.prototype, "enableEdit", 2);
798
- S([
799
- c("focalPoint")
800
- ], A.prototype, "_focalPointHit", 2);
801
- S([
802
- c()
803
- ], A.prototype, "crossFadeTime", 2);
804
- const it = new Z({
953
+ _DepthOfFieldPlugin.PluginType = "DepthOfField";
954
+ _DepthOfFieldPlugin.OldPluginType = "DepthOfFieldPlugin";
955
+ let DepthOfFieldPlugin = _DepthOfFieldPlugin;
956
+ __decorateClass$2([
957
+ serialize(),
958
+ uiToggle()
959
+ ], DepthOfFieldPlugin.prototype, "enableEdit", 2);
960
+ __decorateClass$2([
961
+ serialize("focalPoint")
962
+ ], DepthOfFieldPlugin.prototype, "_focalPointHit", 2);
963
+ __decorateClass$2([
964
+ serialize()
965
+ ], DepthOfFieldPlugin.prototype, "crossFadeTime", 2);
966
+ const dofBlurMaterialPoisson = new ExtendedShaderMaterial({
805
967
  uniforms: {
806
968
  colorTexture: { value: null },
807
- colorTextureSize: { value: new d() },
808
- direction: { value: new d() },
969
+ colorTextureSize: { value: new Vector2() },
970
+ direction: { value: new Vector2() },
809
971
  frameCount: { value: 0 },
810
972
  blurRadius: { value: 16 }
811
973
  },
812
- vertexShader: k.defaultVertex,
813
- fragmentShader: Je + `
814
- ` + Ze,
974
+ vertexShader: shaderUtils.defaultVertex,
975
+ fragmentShader: poissonDiskSamples + "\n" + dofPoissonBox,
815
976
  defines: {
816
- DOF_MODE: 1
977
+ ["DOF_MODE"]: 1
817
978
  }
818
979
  }, ["colorTexture"]);
819
- let b = class extends $ {
820
- constructor(a) {
980
+ let DepthOfFieldPluginPass = class extends ExtendedShaderPass {
981
+ constructor(pid) {
821
982
  super({
822
983
  uniforms: {
823
984
  colorTexture: { value: null },
824
985
  blurTexture: { value: null },
825
986
  cocTexture: { value: null },
826
- cocTextureSize: { value: new d() },
827
- cameraNearFar: { value: new d() }
987
+ cocTextureSize: { value: new Vector2() },
988
+ cameraNearFar: { value: new Vector2() }
828
989
  },
829
- vertexShader: k.defaultVertex,
830
- fragmentShader: Ke
831
- }, "colorTexture", "cocTexture", "blurTexture"), this.uiConfig = void 0, this.before = ["progressive", "screen"], this.after = ["render"], this.required = ["render"], this.dofBlurMaterial = it, this.nearFarBlurScale = new d(0.25, 0.25), this.focalDepthRange = new d(0.5, 1.5), this.crossCenter = new d(0.5, 0.5), this.crossRadius = 0.04, this.crossAlpha = 1, this.crossColor = new he(16750848), this.passId = a, this.computeCocMaterial = new Z({
990
+ vertexShader: shaderUtils.defaultVertex,
991
+ fragmentShader: dofCombine
992
+ }, "colorTexture", "cocTexture", "blurTexture");
993
+ this.uiConfig = void 0;
994
+ this.before = ["progressive", "screen"];
995
+ this.after = ["render"];
996
+ this.required = ["render"];
997
+ this.dofBlurMaterial = dofBlurMaterialPoisson;
998
+ this.nearFarBlurScale = new Vector2(0.25, 0.25);
999
+ this.focalDepthRange = new Vector2(0.5, 1.5);
1000
+ this.crossCenter = new Vector2(0.5, 0.5);
1001
+ this.crossRadius = 0.04;
1002
+ this.crossAlpha = 1;
1003
+ this.crossColor = new Color(16750848);
1004
+ this.passId = pid;
1005
+ this.computeCocMaterial = new ExtendedShaderMaterial({
832
1006
  uniforms: {
833
1007
  colorTexture: { value: null },
834
1008
  cameraNearFar: this.uniforms.cameraNearFar,
835
1009
  nearFarBlurScale: this.uniforms.nearFarBlurScale,
836
1010
  focalDepthRange: this.uniforms.focalDepthRange
837
1011
  },
838
- vertexShader: k.defaultVertex,
839
- fragmentShader: Qe
840
- }, ["colorTexture"]), this.expandCocMaterial = new Z({
1012
+ vertexShader: shaderUtils.defaultVertex,
1013
+ fragmentShader: dofComputeCoC
1014
+ }, ["colorTexture"]);
1015
+ this.expandCocMaterial = new ExtendedShaderMaterial({
841
1016
  uniforms: {
842
1017
  colorTexture: { value: null },
843
- colorTextureSize: { value: new d() },
844
- direction: { value: new d() },
1018
+ colorTextureSize: { value: new Vector2() },
1019
+ direction: { value: new Vector2() },
845
1020
  nearFarBlurScale: this.uniforms.nearFarBlurScale
846
1021
  },
847
- vertexShader: k.defaultVertex,
848
- fragmentShader: Xe
1022
+ vertexShader: shaderUtils.defaultVertex,
1023
+ fragmentShader: dofExpandCoC
849
1024
  }, ["colorTexture"]);
850
1025
  }
851
- render(a, e, i, r, t) {
852
- if (!this.enabled)
853
- return;
854
- if (!i) {
1026
+ render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
1027
+ if (!this.enabled) return;
1028
+ if (!readBuffer) {
855
1029
  console.error("DepthOfFieldPluginPass: No readBuffer");
856
1030
  return;
857
1031
  }
858
- const s = a.renderManager, o = {
859
- minFilter: ie,
860
- magFilter: ie,
1032
+ const renderManager = renderer.renderManager;
1033
+ const halfPars = {
1034
+ minFilter: NearestFilter,
1035
+ magFilter: NearestFilter,
861
1036
  // type: UnsignedByteType,
862
1037
  // encoding: RGBM16Encoding,
863
- type: K,
1038
+ type: HalfFloatType,
864
1039
  // encoding: LinearEncoding,
865
- colorSpace: pe,
1040
+ colorSpace: LinearSRGBColorSpace,
866
1041
  sizeMultiplier: 0.5,
867
1042
  // samples: 1,
868
- format: Ue,
869
- depthBuffer: !1,
870
- generateMipmaps: !1
871
- }, n = s.getTempTarget(o), l = s.getTempTarget(o);
872
- if (this.computeCocMaterial.uniforms.colorTexture.value = i.texture, s.blit(n, { material: this.computeCocMaterial }), this.expandCocMaterial.uniforms.colorTexture.value = n.texture, this.expandCocMaterial.uniforms.direction.value.set(1, 0), s.blit(l, { material: this.expandCocMaterial }), this.expandCocMaterial.uniforms.colorTexture.value = l.texture, this.expandCocMaterial.uniforms.direction.value.set(0, 1), s.blit(n, { material: this.expandCocMaterial }), this.dofBlurMaterial.uniforms.frameCount)
873
- this.dofBlurMaterial.uniforms.colorTexture.value = n.texture, s.blit(l, { material: this.dofBlurMaterial });
874
- else {
875
- const m = s.getTempTarget(o);
876
- this.dofBlurMaterial.uniforms.cocTexture.value = n.texture, this.dofBlurMaterial.uniforms.colorTexture.value = n.texture, this.dofBlurMaterial.uniforms.direction.value.set(1, 0), s.blit(m, { material: this.dofBlurMaterial }), this.dofBlurMaterial.uniforms.colorTexture.value = m.texture, this.dofBlurMaterial.uniforms.direction.value.set(0, 1), s.blit(l, { material: this.dofBlurMaterial }), s.releaseTempTarget(m);
1043
+ format: RGBAFormat,
1044
+ depthBuffer: false,
1045
+ generateMipmaps: false
1046
+ };
1047
+ const cocRt = renderManager.getTempTarget(halfPars);
1048
+ const renderTargetBlurTemp = renderManager.getTempTarget(halfPars);
1049
+ this.computeCocMaterial.uniforms.colorTexture.value = readBuffer.texture;
1050
+ renderManager.blit(cocRt, { material: this.computeCocMaterial });
1051
+ this.expandCocMaterial.uniforms.colorTexture.value = cocRt.texture;
1052
+ this.expandCocMaterial.uniforms.direction.value.set(1, 0);
1053
+ renderManager.blit(renderTargetBlurTemp, { material: this.expandCocMaterial });
1054
+ this.expandCocMaterial.uniforms.colorTexture.value = renderTargetBlurTemp.texture;
1055
+ this.expandCocMaterial.uniforms.direction.value.set(0, 1);
1056
+ renderManager.blit(cocRt, { material: this.expandCocMaterial });
1057
+ if (this.dofBlurMaterial.uniforms.frameCount) {
1058
+ this.dofBlurMaterial.uniforms.colorTexture.value = cocRt.texture;
1059
+ renderManager.blit(renderTargetBlurTemp, { material: this.dofBlurMaterial });
1060
+ } else {
1061
+ const renderTargetBlurTemp2 = renderManager.getTempTarget(halfPars);
1062
+ this.dofBlurMaterial.uniforms.cocTexture.value = cocRt.texture;
1063
+ this.dofBlurMaterial.uniforms.colorTexture.value = cocRt.texture;
1064
+ this.dofBlurMaterial.uniforms.direction.value.set(1, 0);
1065
+ renderManager.blit(renderTargetBlurTemp2, { material: this.dofBlurMaterial });
1066
+ this.dofBlurMaterial.uniforms.colorTexture.value = renderTargetBlurTemp2.texture;
1067
+ this.dofBlurMaterial.uniforms.direction.value.set(0, 1);
1068
+ renderManager.blit(renderTargetBlurTemp, { material: this.dofBlurMaterial });
1069
+ renderManager.releaseTempTarget(renderTargetBlurTemp2);
877
1070
  }
878
- this.material.uniforms.blurTexture.value = l.texture, this.material.uniforms.cocTexture.value = n.texture, super.render(a, e, i, r, t), s.releaseTempTarget(n), s.releaseTempTarget(l);
1071
+ this.material.uniforms.blurTexture.value = renderTargetBlurTemp.texture;
1072
+ this.material.uniforms.cocTexture.value = cocRt.texture;
1073
+ super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
1074
+ renderManager.releaseTempTarget(cocRt);
1075
+ renderManager.releaseTempTarget(renderTargetBlurTemp);
879
1076
  }
880
1077
  };
881
- S([
882
- X({ obj: "focalDepthRange", key: "y" }),
883
- u("Depth Range", [0.25, 3])
884
- ], b.prototype, "depthRange", 2);
885
- S([
886
- X({ obj: "nearFarBlurScale", key: "x" }),
887
- u("Near Blur Scale", [0, 1])
888
- ], b.prototype, "nearBlurScale", 2);
889
- S([
890
- X({ obj: "nearFarBlurScale", key: "y" }),
891
- u("Far Blur Scale", [0, 1])
892
- ], b.prototype, "farBlurScale", 2);
893
- S([
894
- c(),
895
- f()
896
- ], b.prototype, "nearFarBlurScale", 2);
897
- S([
898
- c(),
899
- f()
900
- ], b.prototype, "focalDepthRange", 2);
901
- S([
902
- f()
903
- ], b.prototype, "crossCenter", 2);
904
- S([
905
- f()
906
- ], b.prototype, "crossRadius", 2);
907
- S([
908
- f()
909
- ], b.prototype, "crossAlpha", 2);
910
- S([
911
- f()
912
- ], b.prototype, "crossColor", 2);
913
- b = S([
914
- z("DepthOfField Pass")
915
- ], b);
916
- const J = `#ifndef SSRT_PARS_SNIP
917
- #define SSRT_PARS_SNIP
918
- #define pow2(a) a*a
919
- float getDepth2(const in vec2 uv,const in float lod){float viewDepth=getDepth(uv);return depthToViewZ(viewDepth);}
920
- #define LOD_DEPTH 1.0
921
- #define LOD_COLOR 5.0
922
- void _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.;
923
- #pragma unroll_loop_start
924
- for(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;}}
925
- #pragma unroll_loop_end
926
- }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)**/
927
- #endif
928
- `;
929
- var at = Object.defineProperty, st = Object.getOwnPropertyDescriptor, F = (a, e, i, r) => {
930
- for (var t = r > 1 ? void 0 : r ? st(e, i) : e, s = a.length - 1, o; s >= 0; s--)
931
- (o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
932
- return r && t && at(e, i, t), t;
1078
+ __decorateClass$2([
1079
+ bindToValue({ obj: "focalDepthRange", key: "y" }),
1080
+ uiSlider("Depth Range", [0.25, 3])
1081
+ ], DepthOfFieldPluginPass.prototype, "depthRange", 2);
1082
+ __decorateClass$2([
1083
+ bindToValue({ obj: "nearFarBlurScale", key: "x" }),
1084
+ uiSlider("Near Blur Scale", [0, 1])
1085
+ ], DepthOfFieldPluginPass.prototype, "nearBlurScale", 2);
1086
+ __decorateClass$2([
1087
+ bindToValue({ obj: "nearFarBlurScale", key: "y" }),
1088
+ uiSlider("Far Blur Scale", [0, 1])
1089
+ ], DepthOfFieldPluginPass.prototype, "farBlurScale", 2);
1090
+ __decorateClass$2([
1091
+ serialize(),
1092
+ uniform()
1093
+ ], DepthOfFieldPluginPass.prototype, "nearFarBlurScale", 2);
1094
+ __decorateClass$2([
1095
+ serialize(),
1096
+ uniform()
1097
+ ], DepthOfFieldPluginPass.prototype, "focalDepthRange", 2);
1098
+ __decorateClass$2([
1099
+ uniform()
1100
+ ], DepthOfFieldPluginPass.prototype, "crossCenter", 2);
1101
+ __decorateClass$2([
1102
+ uniform()
1103
+ ], DepthOfFieldPluginPass.prototype, "crossRadius", 2);
1104
+ __decorateClass$2([
1105
+ uniform()
1106
+ ], DepthOfFieldPluginPass.prototype, "crossAlpha", 2);
1107
+ __decorateClass$2([
1108
+ uniform()
1109
+ ], DepthOfFieldPluginPass.prototype, "crossColor", 2);
1110
+ DepthOfFieldPluginPass = __decorateClass$2([
1111
+ uiFolderContainer("DepthOfField Pass")
1112
+ ], DepthOfFieldPluginPass);
1113
+ 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";
1114
+ var __defProp$1 = Object.defineProperty;
1115
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
1116
+ var __decorateClass$1 = (decorators, target, key, kind) => {
1117
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
1118
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1119
+ if (decorator = decorators[i])
1120
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1121
+ if (kind && result) __defProp$1(target, key, result);
1122
+ return result;
933
1123
  };
934
- let p = class extends Me {
1124
+ let SSContactShadowsPlugin = class extends AViewerPluginSync {
935
1125
  // private _loaderCreate({loader}: {loader: GLTFLoader2}) {
936
1126
  // if (!loader.isGLTFLoader2) return
937
1127
  // loader.register((p) => new GLTFMaterialsSSContactShadowsExtensionImport(p))
938
1128
  // }
939
- constructor(a = !0) {
940
- super(), this.enabled = !0, this._uniforms = {
1129
+ constructor(enabled = true) {
1130
+ super();
1131
+ this.enabled = true;
1132
+ this._uniforms = {
941
1133
  sscsRadius: { value: 0.03 },
942
1134
  sscsIntensity: { value: 1 },
943
1135
  sscsTolerance: { value: 1.5 },
944
1136
  // tLastFrame: {value: null}, // not needed since we dont need color
945
1137
  frameCount: { value: 0 },
946
- projection: { value: new E() },
947
- cameraPositionWorld: { value: new U() },
948
- cameraNearFar: { value: new d(0.1, 1e3) },
1138
+ projection: { value: new Matrix4() },
1139
+ cameraPositionWorld: { value: new Vector3() },
1140
+ cameraNearFar: { value: new Vector2(0.1, 1e3) },
949
1141
  sceneBoundingRadius: { value: 0 }
950
- }, this.radius = 0.015, this.intensity = 1, this.tolerance = 1.5, this._defines = {
951
- PERSPECTIVE_CAMERA: 1
1142
+ };
1143
+ this.radius = 0.015;
1144
+ this.intensity = 1;
1145
+ this.tolerance = 1.5;
1146
+ this._defines = {
1147
+ ["PERSPECTIVE_CAMERA"]: 1
952
1148
  // set in PerspectiveCamera2
953
- }, this.onlySSCSDebug = !1, this.stepCount = 2, this.dependencies = [T], this.materialExtension = {
954
- uuid: p.PluginType,
955
- shaderExtender: (e, i, r) => {
956
- var n, l;
957
- if (!e.defines.SSCS_ENABLED)
958
- return;
959
- const t = "float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {", s = _e`
1149
+ };
1150
+ this.onlySSCSDebug = false;
1151
+ this.stepCount = 2;
1152
+ this.dependencies = [GBufferPlugin];
1153
+ this.materialExtension = {
1154
+ uuid: SSContactShadowsPlugin.PluginType,
1155
+ shaderExtender: (shader, _material, _renderer) => {
1156
+ var _a2, _b;
1157
+ if (!shader.defines.SSCS_ENABLED) return;
1158
+ const rsS = "float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {";
1159
+ const lsS = glsl`
960
1160
  #ifndef D_sceneBoundingRadius
961
1161
  #define D_sceneBoundingRadius
962
1162
  uniform float sceneBoundingRadius;
@@ -974,7 +1174,8 @@ let p = class extends Me {
974
1174
  #if defined(SSCS_DEBUG) && SSCS_DEBUG > 0
975
1175
  return state.z;
976
1176
  #endif
977
- `, o = `
1177
+ `;
1178
+ const shadowChunk = `
978
1179
  #if SSCS_ENABLED
979
1180
 
980
1181
  uniform float sscsIntensity;
@@ -984,37 +1185,44 @@ let p = class extends Me {
984
1185
  #define THREE_PACKING_INCLUDED // by threejs
985
1186
  #include <cameraHelpers>
986
1187
  #include <randomHelpers>
987
- ${J}
1188
+ ${ssrtShader}
988
1189
 
989
1190
  #endif
990
-
991
- ` + B(ae.shadowmap_pars_fragment, t, `${s}
1191
+ ` + shaderReplaceString(ShaderChunk.shadowmap_pars_fragment, rsS, `${lsS}
992
1192
  `).replace("return shadow;", "return min(shadow, state.z);");
993
- e.fragmentShader = B(e.fragmentShader, "#include <shadowmap_pars_fragment>", o), e.fragmentShader = e.fragmentShader.replace("#include <lights_fragment_begin>", ae.lights_fragment_begin), e.fragmentShader = B(
994
- e.fragmentShader,
1193
+ shader.fragmentShader = shaderReplaceString(shader.fragmentShader, "#include <shadowmap_pars_fragment>", shadowChunk);
1194
+ shader.fragmentShader = shader.fragmentShader.replace("#include <lights_fragment_begin>", ShaderChunk.lights_fragment_begin);
1195
+ shader.fragmentShader = shaderReplaceString(
1196
+ shader.fragmentShader,
995
1197
  "directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;",
996
1198
  "directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ], directLight.direction ) : 1.0;"
997
- ), e.fragmentShader = B(
998
- e.fragmentShader,
1199
+ );
1200
+ shader.fragmentShader = shaderReplaceString(
1201
+ shader.fragmentShader,
999
1202
  "directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;",
1000
1203
  "directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;"
1001
- ), (l = (n = this._gbufferUnpackExtension) == null ? void 0 : n.shaderExtender) == null || l.call(n, e, i, r);
1204
+ );
1205
+ (_b = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b.call(_a2, shader, _material, _renderer);
1002
1206
  },
1003
- onObjectRender: (e, i, r) => {
1004
- var s, o;
1005
- const t = this.enabled && r.userData.screenSpaceRendering !== !1 && !((s = i.userData) != null && s.pluginsDisabled) && !((o = i.userData) != null && o.sscsDisabled) ? 1 : 0;
1006
- Le({
1207
+ onObjectRender: (_, material, renderer) => {
1208
+ var _a2, _b;
1209
+ 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;
1210
+ updateMaterialDefines({
1007
1211
  ...this._defines,
1008
- SSCS_ENABLED: t
1009
- }, i);
1212
+ ["SSCS_ENABLED"]: enabled2
1213
+ }, material);
1010
1214
  },
1011
1215
  extraUniforms: {
1012
1216
  ...this._uniforms
1013
1217
  // todo should not be static because of multiple viewers
1014
1218
  },
1015
1219
  extraDefines: {},
1016
- computeCacheKey: (e) => this.isDisabled() ? "0" : "1",
1017
- isCompatible: (e) => e.isPhysicalMaterial,
1220
+ computeCacheKey: (_) => {
1221
+ return this.isDisabled() ? "0" : "1";
1222
+ },
1223
+ isCompatible: (material1) => {
1224
+ return material1.isPhysicalMaterial;
1225
+ },
1018
1226
  // getUiConfig: (material: PhysicalMaterial) => {
1019
1227
  // const viewer = this._viewer!
1020
1228
  // if (material.userData._clearcoatTint === undefined) material.userData._clearcoatTint = {}
@@ -1069,185 +1277,210 @@ let p = class extends Me {
1069
1277
  // return config
1070
1278
  // },
1071
1279
  updaters: () => {
1072
- var e, i, r, t;
1280
+ var _a2, _b, _c, _d;
1073
1281
  return [
1074
1282
  // this._viewer?.getPlugin(GBufferPlugin),
1075
- (e = this._viewer) == null ? void 0 : e.getPlugin(O),
1076
- (i = this._viewer) == null ? void 0 : i.scene.renderCamera,
1077
- (r = this._viewer) == null ? void 0 : r.renderManager,
1078
- (t = this._viewer) == null ? void 0 : t.scene
1283
+ (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(ProgressivePlugin),
1284
+ (_b = this._viewer) == null ? void 0 : _b.scene.renderCamera,
1285
+ (_c = this._viewer) == null ? void 0 : _c.renderManager,
1286
+ (_d = this._viewer) == null ? void 0 : _d.scene
1079
1287
  ];
1080
1288
  }
1081
- }, this._gbufferUnpackExtension = void 0, this._gbufferUnpackExtensionChanged = () => {
1082
- if (!this._viewer)
1083
- throw new Error("SSContactShadowPlugin: pass/viewer not created yet");
1084
- const e = this._viewer.renderManager.gbufferUnpackExtension;
1085
- this._gbufferUnpackExtension !== e && (this._gbufferUnpackExtension && this.setGBufferUnpackExtension(void 0), this._gbufferUnpackExtension = e, this._gbufferUnpackExtension ? this.setGBufferUnpackExtension(this._gbufferUnpackExtension) : this._viewer.console.warn("SSContactShadowPlugin: GBuffer unpack extension removed"));
1086
- }, this.enabled = a;
1289
+ };
1290
+ this._gbufferUnpackExtension = void 0;
1291
+ this._gbufferUnpackExtensionChanged = () => {
1292
+ if (!this._viewer) throw new Error("SSContactShadowPlugin: pass/viewer not created yet");
1293
+ const newExtension = this._viewer.renderManager.gbufferUnpackExtension;
1294
+ if (this._gbufferUnpackExtension === newExtension) return;
1295
+ if (this._gbufferUnpackExtension) this.setGBufferUnpackExtension(void 0);
1296
+ this._gbufferUnpackExtension = newExtension;
1297
+ if (this._gbufferUnpackExtension) this.setGBufferUnpackExtension(this._gbufferUnpackExtension);
1298
+ else this._viewer.console.warn("SSContactShadowPlugin: GBuffer unpack extension removed");
1299
+ };
1300
+ this.enabled = enabled;
1087
1301
  }
1088
1302
  setDirty() {
1089
- var a, e, i;
1090
- (e = (a = this.materialExtension) == null ? void 0 : a.setDirty) == null || e.call(a), (i = this._viewer) == null || i.setDirty();
1303
+ var _a2, _b, _c;
1304
+ (_b = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b.call(_a2);
1305
+ (_c = this._viewer) == null ? void 0 : _c.setDirty();
1091
1306
  }
1092
- onAdded(a) {
1093
- super.onAdded(a), a.assetManager.materials.registerMaterialExtension(this.materialExtension), a.getPlugin(se) && (a.getPlugin(se).material.userData.sscsDisabled = !1), this._gbufferUnpackExtensionChanged(), a.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1307
+ onAdded(v) {
1308
+ super.onAdded(v);
1309
+ v.assetManager.materials.registerMaterialExtension(this.materialExtension);
1310
+ if (v.getPlugin(BaseGroundPlugin)) v.getPlugin(BaseGroundPlugin).material.userData.sscsDisabled = false;
1311
+ this._gbufferUnpackExtensionChanged();
1312
+ v.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1094
1313
  }
1095
- onRemove(a) {
1096
- var e;
1097
- return (e = a.assetManager.materials) == null || e.unregisterMaterialExtension(this.materialExtension), a.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged), super.onRemove(a);
1314
+ onRemove(v) {
1315
+ var _a2;
1316
+ (_a2 = v.assetManager.materials) == null ? void 0 : _a2.unregisterMaterialExtension(this.materialExtension);
1317
+ v.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1318
+ return super.onRemove(v);
1098
1319
  }
1099
- setGBufferUnpackExtension(a) {
1100
- this._gbufferUnpackExtension = a, this._gbufferUnpackExtension && (Object.assign(this.materialExtension.extraUniforms, this._gbufferUnpackExtension.extraUniforms), Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines));
1320
+ setGBufferUnpackExtension(extension) {
1321
+ this._gbufferUnpackExtension = extension;
1322
+ if (!this._gbufferUnpackExtension) return;
1323
+ Object.assign(this.materialExtension.extraUniforms, this._gbufferUnpackExtension.extraUniforms);
1324
+ Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines);
1101
1325
  }
1102
1326
  // public static readonly CLEARCOAT_TINT_GLTF_EXTENSION = 'WEBGI_materials_clearcoat_tint'
1103
1327
  };
1104
- p.PluginType = "SSContactShadows";
1105
- p.OldPluginType = "SSContactShadowsPlugin";
1106
- F([
1107
- R("Enabled"),
1108
- c(),
1109
- N(p.prototype.setDirty)
1110
- ], p.prototype, "enabled", 2);
1111
- F([
1112
- f({ propKey: "sscsRadius", onChange: p.prototype.setDirty }),
1113
- u("Radius", [1e-4, 0.1], 1e-4),
1114
- c()
1115
- ], p.prototype, "radius", 2);
1116
- F([
1117
- f({ propKey: "sscsIntensity", onChange: p.prototype.setDirty }),
1118
- u("Intensity", [1e-4, 1], 1e-4),
1119
- c()
1120
- ], p.prototype, "intensity", 2);
1121
- F([
1122
- f({ propKey: "sscsTolerance", onChange: p.prototype.setDirty }),
1123
- u("Tolerance", [0.1, 5]),
1124
- c()
1125
- ], p.prototype, "tolerance", 2);
1126
- F([
1127
- V("SSCS_DEBUG", void 0, !0, p.prototype.setDirty),
1128
- R("Debug only SSCS"),
1129
- c()
1130
- ], p.prototype, "onlySSCSDebug", 2);
1131
- F([
1132
- V("SSCS_STEP_COUNT", void 0, !0, p.prototype.setDirty),
1133
- u("Step count", [1, 8], 1),
1134
- c()
1135
- ], p.prototype, "stepCount", 2);
1136
- p = F([
1137
- z("SS Contact Shadows")
1138
- ], p);
1139
- const ne = `#define PI 3.141592653589793
1140
- mat3 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;}`, le = `uniform float currentFrameCount;uniform float frameCount;uniform float objectRadius;uniform float radius;uniform float tolerance;uniform bool autoRadius;
1141
- #ifndef D_sceneBoundingRadius
1142
- #define D_sceneBoundingRadius
1143
- uniform float sceneBoundingRadius;
1144
- #endif
1145
- vec3 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*117.);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);L=normalize(L);float cameraDist=length(cameraPositionWorld);float rayLen=autoRadius ?mix((cameraDist+objectRadius*sceneBoundingRadius)+viewPos.z,-viewPos.z-max(0.0,cameraDist-objectRadius*sceneBoundingRadius),L.z*0.5+0.5):objectRadius*sceneBoundingRadius;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.);}`, ot = `
1146
- #if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
1147
- vec3 screenPos=viewToScreen(geometry.position);vec4 ssrColor=vec4(0,0,0,0);float alphaModifier=1.0-clamp(material.roughness*.3,0.,1.);alphaModifier*=ssrIntensity;
1148
- #if defined(SSR_MASK_FRONT_RAYS) && SSR_MASK_FRONT_RAYS > 0
1149
- alphaModifier*=clamp(-4.0*dot(geometry.viewDir,normal)+(4.0+ssrMaskFrontFactor),0.0,1.0);
1150
- #endif
1151
- #ifdef USE_TRANSMISSION
1152
- alphaModifier*=1.-transmission;
1153
- #endif
1154
- float vignette=1.;if(true){float fadeStrength=0.1;float dist=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(geometry.normal,geometry.viewDir,material.specularColor.rgb,material.specularF90,material.roughness);if(length(specularColor.rgb)*alphaModifier>0.01&&roughnessFactor<0.9){
1155
- #if defined(SSR_INLINE) && SSR_INLINE > 0
1156
- ssrColor=calculateSSR(8.,vec3(screenPos.xy,geometry.position.z),geometry.normal,1.,material.roughness);
1157
- #else
1158
- ssrColor=tSSReflMapTexelToLinear(texture2D(tSSReflMap,screenPos.xy));
1159
- #endif
1160
- }ssrColor.rgb*=ssrBoost;ssrColor.a*=alphaModifier;ssrColor.rgb=pow(ssrColor.rgb,vec3(ssrPower));ssrColor.a=min(ssrColor.a,1.0);
1161
- #if defined(SSR_NON_PHYSICAL) && SSR_NON_PHYSICAL > 0
1162
- diffuseColor.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);
1163
- #else
1164
- reflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,(specularColor.rgb*ssrColor.rgb),ssrColor.a);
1165
- #endif
1166
- #endif
1167
- `, nt = `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.));}
1168
- #include <encodings_fragment>
1169
- }`;
1170
- var lt = Object.defineProperty, ct = Object.getOwnPropertyDescriptor, x = (a, e, i, r) => {
1171
- for (var t = r > 1 ? void 0 : r ? ct(e, i) : e, s = a.length - 1, o; s >= 0; s--)
1172
- (o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
1173
- return r && t && lt(e, i, t), t;
1328
+ SSContactShadowsPlugin.PluginType = "SSContactShadows";
1329
+ SSContactShadowsPlugin.OldPluginType = "SSContactShadowsPlugin";
1330
+ __decorateClass$1([
1331
+ uiToggle("Enabled"),
1332
+ serialize(),
1333
+ onChange(SSContactShadowsPlugin.prototype.setDirty)
1334
+ ], SSContactShadowsPlugin.prototype, "enabled", 2);
1335
+ __decorateClass$1([
1336
+ uniform({ propKey: "sscsRadius", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1337
+ uiSlider("Radius", [1e-4, 0.1], 1e-4),
1338
+ serialize()
1339
+ ], SSContactShadowsPlugin.prototype, "radius", 2);
1340
+ __decorateClass$1([
1341
+ uniform({ propKey: "sscsIntensity", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1342
+ uiSlider("Intensity", [1e-4, 1], 1e-4),
1343
+ serialize()
1344
+ ], SSContactShadowsPlugin.prototype, "intensity", 2);
1345
+ __decorateClass$1([
1346
+ uniform({ propKey: "sscsTolerance", onChange: SSContactShadowsPlugin.prototype.setDirty }),
1347
+ uiSlider("Tolerance", [0.1, 5]),
1348
+ serialize()
1349
+ ], SSContactShadowsPlugin.prototype, "tolerance", 2);
1350
+ __decorateClass$1([
1351
+ matDefine("SSCS_DEBUG", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
1352
+ uiToggle("Debug only SSCS"),
1353
+ serialize()
1354
+ ], SSContactShadowsPlugin.prototype, "onlySSCSDebug", 2);
1355
+ __decorateClass$1([
1356
+ matDefine("SSCS_STEP_COUNT", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
1357
+ uiSlider("Step count", [1, 8], 1),
1358
+ serialize()
1359
+ ], SSContactShadowsPlugin.prototype, "stepCount", 2);
1360
+ SSContactShadowsPlugin = __decorateClass$1([
1361
+ uiFolderContainer("SS Contact Shadows")
1362
+ ], SSContactShadowsPlugin);
1363
+ 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;}";
1364
+ const ssrShader = "uniform float currentFrameCount;uniform float frameCount;uniform float objectRadius;uniform float radius;uniform float tolerance;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*117.);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);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.);}";
1365
+ const ssreflPatch = "\n#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0\nvec3 screenPos=viewToScreen(geometry.position);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(geometry.viewDir,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(geometry.normal,geometry.viewDir,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\nssrColor=calculateSSR(8.,vec3(screenPos.xy,geometry.position.z),geometry.normal,1.,material.roughness);\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";
1366
+ 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}";
1367
+ var __defProp = Object.defineProperty;
1368
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1369
+ var __decorateClass = (decorators, target, key, kind) => {
1370
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
1371
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1372
+ if (decorator = decorators[i])
1373
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1374
+ if (kind && result) __defProp(target, key, result);
1375
+ return result;
1174
1376
  };
1175
- const ut = "ssrefl";
1176
- let D = class extends I {
1377
+ const passId = "ssrefl";
1378
+ let SSReflectionPlugin = class extends PipelinePassPlugin {
1177
1379
  // cannot be changed after creation (for now)
1178
- constructor(a = !0, e = de, i = 1, r = !0) {
1179
- super(), this.inlineShaderRayTrace = a, this.passId = ut, this.dependencies = [T, Fe], this._gbufferUnpackExtension = void 0, this._gbufferUnpackExtensionChanged = () => {
1180
- if (!this._pass || !this._viewer)
1181
- throw new Error("SSReflectionPlugin: pass/viewer not created yet");
1182
- const t = this._viewer.renderManager.gbufferUnpackExtension;
1183
- this._gbufferUnpackExtension !== t && (this._gbufferUnpackExtension && this._pass.setGBufferUnpackExtension(void 0), this._gbufferUnpackExtension = t, this._gbufferUnpackExtension ? this._pass.setGBufferUnpackExtension(this._gbufferUnpackExtension) : this._viewer.console.warn("SSReflectionPlugin: GBuffer unpack extension removed"));
1184
- }, this.enabled = r, this.bufferType = e, this.sizeMultiplier = i;
1380
+ constructor(inlineShaderRayTrace = true, bufferType = UnsignedByteType, sizeMultiplier = 1, enabled = true) {
1381
+ super();
1382
+ this.inlineShaderRayTrace = inlineShaderRayTrace;
1383
+ this.passId = passId;
1384
+ this.dependencies = [GBufferPlugin, SSAAPlugin];
1385
+ this._gbufferUnpackExtension = void 0;
1386
+ this._gbufferUnpackExtensionChanged = () => {
1387
+ if (!this._pass || !this._viewer) throw new Error("SSReflectionPlugin: pass/viewer not created yet");
1388
+ const newExtension = this._viewer.renderManager.gbufferUnpackExtension;
1389
+ if (this._gbufferUnpackExtension === newExtension) return;
1390
+ if (this._gbufferUnpackExtension) this._pass.setGBufferUnpackExtension(void 0);
1391
+ this._gbufferUnpackExtension = newExtension;
1392
+ if (this._gbufferUnpackExtension) this._pass.setGBufferUnpackExtension(this._gbufferUnpackExtension);
1393
+ else this._viewer.console.warn("SSReflectionPlugin: GBuffer unpack extension removed");
1394
+ };
1395
+ this.enabled = enabled;
1396
+ this.bufferType = bufferType;
1397
+ this.sizeMultiplier = sizeMultiplier;
1185
1398
  }
1186
- _createTarget(a = !0) {
1187
- this._viewer && (a && this._disposeTarget(), !this.inlineShaderRayTrace && (this.target || (this.target = this._viewer.renderManager.createTarget(
1188
- {
1189
- depthBuffer: !1,
1190
- type: this.bufferType,
1191
- sizeMultiplier: this.sizeMultiplier
1192
- // magFilter: NearestFilter,
1193
- // minFilter: NearestFilter,
1194
- // generateMipmaps: false,
1195
- // encoding: LinearEncoding,
1196
- }
1197
- )), this.texture = this.target.texture, this.texture.name = "ssreflBuffer", this._pass && (this._pass.target = this.target)));
1399
+ _createTarget(recreate = true) {
1400
+ if (!this._viewer) return;
1401
+ if (recreate) this._disposeTarget();
1402
+ if (this.inlineShaderRayTrace) return;
1403
+ if (!this.target)
1404
+ this.target = this._viewer.renderManager.createTarget(
1405
+ {
1406
+ depthBuffer: false,
1407
+ type: this.bufferType,
1408
+ sizeMultiplier: this.sizeMultiplier
1409
+ // magFilter: NearestFilter,
1410
+ // minFilter: NearestFilter,
1411
+ // generateMipmaps: false,
1412
+ // encoding: LinearEncoding,
1413
+ }
1414
+ );
1415
+ this.texture = this.target.texture;
1416
+ this.texture.name = "ssreflBuffer";
1417
+ if (this._pass) this._pass.target = this.target;
1198
1418
  }
1199
1419
  _disposeTarget() {
1200
- this._viewer && (this.target && (this._viewer.renderManager.disposeTarget(this.target), this.target = void 0), this.texture = void 0);
1420
+ if (!this._viewer) return;
1421
+ if (this.target) {
1422
+ this._viewer.renderManager.disposeTarget(this.target);
1423
+ this.target = void 0;
1424
+ }
1425
+ this.texture = void 0;
1201
1426
  }
1202
1427
  _createPass() {
1203
- if (!this._viewer)
1204
- throw new Error("SSReflectionPlugin: viewer not set");
1428
+ if (!this._viewer) throw new Error("SSReflectionPlugin: viewer not set");
1205
1429
  if (!this._viewer.renderManager.gbufferTarget || !this._viewer.renderManager.gbufferUnpackExtension)
1206
1430
  throw new Error("SSReflectionPlugin: GBuffer target not created. GBufferPlugin is required.");
1207
- return this._createTarget(!0), new v(this.passId, this.target, this.inlineShaderRayTrace);
1431
+ this._createTarget(true);
1432
+ return new SSReflectionPluginPass(this.passId, this.target, this.inlineShaderRayTrace);
1208
1433
  }
1209
- onAdded(a) {
1210
- super.onAdded(a), a.getPlugin("Ground") && console.error("GroundPlugin must be added after SSReflectionPlugin"), this._gbufferUnpackExtensionChanged(), a.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1434
+ onAdded(viewer) {
1435
+ super.onAdded(viewer);
1436
+ if (viewer.getPlugin("Ground") || viewer.getPlugin("BaseGroundPlugin")) console.error("GroundPlugin must be added after SSReflectionPlugin");
1437
+ this._gbufferUnpackExtensionChanged();
1438
+ viewer.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1211
1439
  }
1212
- onRemove(a) {
1213
- return this._disposeTarget(), a.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged), super.onRemove(a);
1440
+ onRemove(viewer) {
1441
+ this._disposeTarget();
1442
+ viewer.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
1443
+ return super.onRemove(viewer);
1214
1444
  }
1215
- _beforeRender(a, e, i) {
1216
- var r;
1217
- return this._viewer ? ((r = this._pass) == null || r.updateShaderProperties([this._viewer.getPlugin(O)]), super._beforeRender(a, e, i)) : !1;
1445
+ _beforeRender(_, _1, _2) {
1446
+ var _a2;
1447
+ if (!this._viewer) return false;
1448
+ (_a2 = this._pass) == null ? void 0 : _a2.updateShaderProperties([this._viewer.getPlugin(ProgressivePlugin)]);
1449
+ return super._beforeRender(_, _1, _2);
1218
1450
  }
1219
1451
  /**
1220
1452
  * @deprecated use {@link target} instead
1221
1453
  */
1222
1454
  get ssrTarget() {
1223
- return console.warn("SSReflectionPlugin: ssrTarget is deprecated, use target instead"), this.target;
1455
+ console.warn("SSReflectionPlugin: ssrTarget is deprecated, use target instead");
1456
+ return this.target;
1224
1457
  }
1225
1458
  };
1226
- D.PluginType = "SSReflection";
1227
- D.OldPluginType = "SSReflectionPlugin";
1228
- x([
1229
- ve(
1459
+ SSReflectionPlugin.PluginType = "SSReflection";
1460
+ SSReflectionPlugin.OldPluginType = "SSReflectionPlugin";
1461
+ __decorateClass([
1462
+ uiImage(
1230
1463
  "SSReflection Buffer"
1231
1464
  /* {readOnly: true}*/
1232
1465
  )
1233
- ], D.prototype, "texture", 2);
1234
- x([
1235
- Q()
1236
- ], D.prototype, "_pass", 2);
1237
- D = x([
1238
- z("SSReflection Plugin")
1239
- ], D);
1240
- let v = class extends $ {
1241
- constructor(a, e, i = !0) {
1466
+ ], SSReflectionPlugin.prototype, "texture", 2);
1467
+ __decorateClass([
1468
+ uiConfig()
1469
+ ], SSReflectionPlugin.prototype, "_pass", 2);
1470
+ SSReflectionPlugin = __decorateClass([
1471
+ uiFolderContainer("SSReflection Plugin")
1472
+ ], SSReflectionPlugin);
1473
+ let SSReflectionPluginPass = class extends ExtendedShaderPass {
1474
+ constructor(pid, target, inlineShaderRayTrace = true) {
1242
1475
  super({
1243
1476
  defines: {
1244
- SSR_STEP_COUNT: 16,
1245
- SSR_LOW_QUALITY_FRAMES: 2,
1477
+ ["SSR_STEP_COUNT"]: 16,
1478
+ ["SSR_LOW_QUALITY_FRAMES"]: 2,
1246
1479
  // todo: only on mobile
1247
- SSR_INLINE: i ? "1" : "0",
1480
+ ["SSR_INLINE"]: inlineShaderRayTrace ? "1" : "0",
1248
1481
  // ['SSR_NON_PHYSICAL']: '0', only in inline, so it should not be here
1249
- SSR_MASK_FRONT_RAYS: !0,
1250
- PERSPECTIVE_CAMERA: 1
1482
+ ["SSR_MASK_FRONT_RAYS"]: true,
1483
+ ["PERSPECTIVE_CAMERA"]: 1
1251
1484
  // set in PerspectiveCamera2
1252
1485
  // ['SSREFL_PACKING']: 1, // 1 is (r: ssrefl, gba: depth), 2 is (rgb: ssrefl, a: 1), 3 is (rgba: packed_ssrefl), 4 is (rgb: packed_ssrefl, a: 1)
1253
1486
  },
@@ -1256,32 +1489,32 @@ let v = class extends $ {
1256
1489
  tLastFrame: { value: null },
1257
1490
  // set in progressive plugin
1258
1491
  // TODO required?
1259
- screenSize: { value: new d(0, 0) },
1492
+ screenSize: { value: new Vector2(0, 0) },
1260
1493
  // set in ExtendedRenderMaterial
1261
1494
  currentFrameCount: { value: 0 },
1262
1495
  // set in RenderManager
1263
1496
  frameCount: { value: 0 },
1264
1497
  // set in RenderManager
1265
- cameraNearFar: { value: new d(0.1, 1e3) },
1498
+ cameraNearFar: { value: new Vector2(0.1, 1e3) },
1266
1499
  // set in PerspectiveCamera2
1267
- cameraPositionWorld: { value: new U() },
1500
+ cameraPositionWorld: { value: new Vector3() },
1268
1501
  // set in PerspectiveCamera2
1269
- projection: { value: new E() },
1502
+ projection: { value: new Matrix4() },
1270
1503
  // set in PerspectiveCamera2
1271
- saoBiasEpsilon: { value: new U(1, 1, 1) },
1504
+ saoBiasEpsilon: { value: new Vector3(1, 1, 1) },
1272
1505
  opacity: { value: 1 },
1273
1506
  // todo?
1274
1507
  intensity: { value: 0 },
1275
- boost: { value: new U(0, 0, 0) },
1508
+ boost: { value: new Vector3(0, 0, 0) },
1276
1509
  objectRadius: { value: 0 },
1277
- autoRadius: { value: !1 },
1510
+ autoRadius: { value: false },
1278
1511
  power: { value: 0 },
1279
1512
  maskFrontFactor: { value: -0.1 },
1280
1513
  tolerance: { value: 0 },
1281
1514
  sceneBoundingRadius: { value: 0 }
1282
1515
  // todo do same in SSAO
1283
1516
  },
1284
- vertexShader: k.defaultVertex,
1517
+ vertexShader: shaderUtils.defaultVertex,
1285
1518
  fragmentShader: `
1286
1519
  varying vec2 vUv;
1287
1520
 
@@ -1290,19 +1523,35 @@ varying vec2 vUv;
1290
1523
  #define THREE_PACKING_INCLUDED
1291
1524
  #include <cameraHelpers>
1292
1525
  #include <randomHelpers>
1293
- ${ne}
1526
+ ${samplePointHelpers}
1294
1527
 
1295
- ${J}
1528
+ ${ssrtShader}
1296
1529
 
1297
- ${le}
1530
+ ${ssrShader}
1298
1531
 
1299
- ${nt}
1532
+ ${ssrShaderMain}
1300
1533
  `
1301
- }, "tDiffuse", "tLastThis", "tLastFrame"), this.target = e, this.inlineShaderRayTrace = i, this.before = ["render"], this.after = ["gbuffer", "depth"], this.required = ["render", "progressive"], this.intensity = 1, this.boost = new U(1, 1, 1), this.objectRadius = 1, this.autoRadius = !0, this.power = 1.1, this.tolerance = 0.5, this.stepCount = 16, this.lowQualityFrames = 0, this.maskFrontRays = !0, this.maskFrontFactor = -0.2, this.materialExtension = {
1534
+ }, "tDiffuse", "tLastThis", "tLastFrame");
1535
+ this.target = target;
1536
+ this.inlineShaderRayTrace = inlineShaderRayTrace;
1537
+ this.before = ["render"];
1538
+ this.after = ["gbuffer", "depth"];
1539
+ this.required = ["render", "progressive"];
1540
+ this.intensity = 1;
1541
+ this.boost = new Vector3(1, 1, 1);
1542
+ this.objectRadius = 1;
1543
+ this.autoRadius = true;
1544
+ this.power = 1.1;
1545
+ this.tolerance = 0.5;
1546
+ this.stepCount = 16;
1547
+ this.lowQualityFrames = 0;
1548
+ this.maskFrontRays = true;
1549
+ this.maskFrontFactor = -0.2;
1550
+ this.materialExtension = {
1302
1551
  extraUniforms: {
1303
1552
  tSSReflMap: () => {
1304
- var r;
1305
- return { value: ((r = H(this.target)) == null ? void 0 : r.texture) ?? null };
1553
+ var _a2;
1554
+ return { value: ((_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) ?? null };
1306
1555
  },
1307
1556
  ssrPower: this.material.uniforms.power,
1308
1557
  ssrIntensity: this.material.uniforms.intensity,
@@ -1310,20 +1559,19 @@ ${nt}
1310
1559
  ssrBoost: this.material.uniforms.boost
1311
1560
  },
1312
1561
  extraDefines: {
1313
- SSR_STEP_COUNT: () => this.material.defines.SSR_STEP_COUNT,
1314
- SSR_LOW_QUALITY_FRAMES: () => this.material.defines.SSR_LOW_QUALITY_FRAMES,
1315
- SSR_INLINE: () => this.material.defines.SSR_INLINE,
1316
- SSR_MASK_FRONT_RAYS: () => this.material.defines.SSR_MASK_FRONT_RAYS,
1317
- PERSPECTIVE_CAMERA: () => this.material.defines.PERSPECTIVE_CAMERA
1562
+ ["SSR_STEP_COUNT"]: () => this.material.defines.SSR_STEP_COUNT,
1563
+ ["SSR_LOW_QUALITY_FRAMES"]: () => this.material.defines.SSR_LOW_QUALITY_FRAMES,
1564
+ ["SSR_INLINE"]: () => this.material.defines.SSR_INLINE,
1565
+ ["SSR_MASK_FRONT_RAYS"]: () => this.material.defines.SSR_MASK_FRONT_RAYS,
1566
+ ["PERSPECTIVE_CAMERA"]: () => this.material.defines.PERSPECTIVE_CAMERA
1318
1567
  // todo gbuffer stuff
1319
1568
  },
1320
- shaderExtender: (r, t, s) => {
1321
- var n, l;
1322
- if (!r.defines.SSREFL_ENABLED)
1323
- return;
1324
- const o = `
1569
+ shaderExtender: (shader, _material, _renderer) => {
1570
+ var _a2, _b;
1571
+ if (!shader.defines.SSREFL_ENABLED) return;
1572
+ const ls = `
1325
1573
 
1326
- ${ot}
1574
+ ${ssreflPatch}
1327
1575
 
1328
1576
  // reflectedLight.directDiffuse = vec3(0.);
1329
1577
  // reflectedLight.indirectDiffuse = vec3(0.);
@@ -1331,21 +1579,30 @@ ${nt}
1331
1579
  // reflectedLight.indirectSpecular = vec3(0.);
1332
1580
 
1333
1581
  `;
1334
- r.fragmentShader = B(
1335
- r.fragmentShader,
1582
+ shader.fragmentShader = shaderReplaceString(
1583
+ shader.fragmentShader,
1336
1584
  "#glMarker beforeModulation",
1337
- o,
1338
- { prepend: !0 }
1339
- ), (l = (n = this._gbufferUnpackExtension) == null ? void 0 : n.shaderExtender) == null || l.call(n, r, t, s);
1585
+ ls,
1586
+ { prepend: true }
1587
+ );
1588
+ (_b = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b.call(_a2, shader, _material, _renderer);
1340
1589
  },
1341
- onObjectRender: (r, t, s) => {
1342
- var n, l, m;
1343
- let o = this.enabled && s.userData.screenSpaceRendering !== !1 && !((n = t.userData) != null && n.pluginsDisabled) && !((l = t.userData) != null && l.ssreflDisabled) ? 1 : 0;
1344
- t.defines.SSREFL_ENABLED !== o && (t.defines.SSREFL_ENABLED = o, t.needsUpdate = !0), o = (m = t.userData) != null && m.ssreflNonPhysical ? 1 : 0, t.defines.SSR_NON_PHYSICAL !== o && (t.defines.SSR_NON_PHYSICAL = o, t.needsUpdate = !0);
1590
+ onObjectRender: (_object, material, renderer) => {
1591
+ var _a2, _b, _c;
1592
+ 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;
1593
+ if (material.defines.SSREFL_ENABLED !== x) {
1594
+ material.defines.SSREFL_ENABLED = x;
1595
+ material.needsUpdate = true;
1596
+ }
1597
+ x = ((_c = material.userData) == null ? void 0 : _c.ssreflNonPhysical) ? 1 : 0;
1598
+ if (material.defines.SSR_NON_PHYSICAL !== x) {
1599
+ material.defines.SSR_NON_PHYSICAL = x;
1600
+ material.needsUpdate = true;
1601
+ }
1345
1602
  },
1346
- parsFragmentSnippet: (r) => {
1347
- var t;
1348
- return _e`
1603
+ parsFragmentSnippet: (renderer) => {
1604
+ var _a2;
1605
+ return glsl`
1349
1606
  #if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
1350
1607
  uniform float ssrPower;
1351
1608
  uniform float ssrIntensity;
@@ -1353,59 +1610,73 @@ ${nt}
1353
1610
  uniform vec3 ssrBoost;
1354
1611
  uniform sampler2D tSSReflMap;
1355
1612
  uniform sampler2D tLastFrame;
1356
- ${oe("tSSReflMap", (t = H(this.target)) == null ? void 0 : t.texture, r.capabilities.isWebGL2)}
1357
- ${oe("tLastFrame", this.material.uniforms.tLastFrame.value, r.capabilities.isWebGL2)}
1358
- ${this.inlineShaderRayTrace ? `
1613
+ ${getTexelDecoding("tSSReflMap", (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture, renderer.capabilities.isWebGL2)}
1614
+ ${getTexelDecoding("tLastFrame", this.material.uniforms.tLastFrame.value, renderer.capabilities.isWebGL2)}
1615
+ ${!this.inlineShaderRayTrace ? "" : `
1359
1616
  #define THREE_PACKING_INCLUDED // by threejs
1360
1617
  #include <cameraHelpers>
1361
1618
  #include <randomHelpers>
1362
- ${ne}
1363
- ${J}
1364
- ${le}
1365
- ` : ""}
1619
+ ${samplePointHelpers}
1620
+ ${ssrtShader}
1621
+ ${ssrShader}
1622
+ `}
1366
1623
  #include <simpleCameraHelpers>
1367
1624
  #endif
1368
1625
  `;
1369
1626
  },
1370
1627
  computeCacheKey: () => {
1371
- var r, t;
1372
- return this.enabled ? "1" : "0" + ((t = (r = H(this.target)) == null ? void 0 : r.texture) == null ? void 0 : t.colorSpace) + Object.values(this.material.defines).map((s) => s + "").join(",");
1628
+ var _a2, _b;
1629
+ 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(",");
1373
1630
  },
1374
- uuid: D.PluginType,
1375
- ...ge(this._getUiConfig.bind(this), D.PluginType),
1376
- isCompatible: (r) => r.isPhysicalMaterial
1377
- }, this.passId = a, this.needsSwap = !1, this.clear = !0, i && Object.assign(this.materialExtension.extraUniforms, {
1378
- tNormalDepth: this.material.uniforms.tNormalDepth,
1379
- tLastFrame: this.material.uniforms.tLastFrame,
1380
- objectRadius: this.material.uniforms.objectRadius,
1381
- autoRadius: this.material.uniforms.autoRadius,
1382
- tolerance: this.material.uniforms.tolerance,
1383
- frameCount: this.material.uniforms.frameCount,
1384
- // currentFrameCount: this.material.uniforms.currentFrameCount, // todo required?
1385
- projection: this.material.uniforms.projection,
1386
- cameraPositionWorld: this.material.uniforms.cameraPositionWorld,
1387
- cameraNearFar: this.material.uniforms.cameraNearFar,
1388
- sceneBoundingRadius: this.material.uniforms.sceneBoundingRadius
1389
- });
1631
+ uuid: SSReflectionPlugin.PluginType,
1632
+ ...uiConfigMaterialExtension(this._getUiConfig.bind(this), SSReflectionPlugin.PluginType),
1633
+ isCompatible: (material) => {
1634
+ return material.isPhysicalMaterial;
1635
+ }
1636
+ };
1637
+ this.passId = pid;
1638
+ this.needsSwap = false;
1639
+ this.clear = true;
1640
+ if (inlineShaderRayTrace) {
1641
+ Object.assign(this.materialExtension.extraUniforms, {
1642
+ tNormalDepth: this.material.uniforms.tNormalDepth,
1643
+ tLastFrame: this.material.uniforms.tLastFrame,
1644
+ objectRadius: this.material.uniforms.objectRadius,
1645
+ autoRadius: this.material.uniforms.autoRadius,
1646
+ tolerance: this.material.uniforms.tolerance,
1647
+ frameCount: this.material.uniforms.frameCount,
1648
+ // currentFrameCount: this.material.uniforms.currentFrameCount, // todo required?
1649
+ projection: this.material.uniforms.projection,
1650
+ cameraPositionWorld: this.material.uniforms.cameraPositionWorld,
1651
+ cameraNearFar: this.material.uniforms.cameraNearFar,
1652
+ sceneBoundingRadius: this.material.uniforms.sceneBoundingRadius
1653
+ });
1654
+ }
1390
1655
  }
1391
- render(a, e, i, r, t) {
1392
- if (!this.enabled)
1393
- return;
1656
+ render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
1657
+ if (!this.enabled) return;
1394
1658
  if (this.inlineShaderRayTrace) {
1395
- this.needsSwap = !1;
1659
+ this.needsSwap = false;
1396
1660
  return;
1397
1661
  }
1398
- const s = H(this.target);
1399
- if (!s) {
1662
+ const target = getOrCall(this.target);
1663
+ if (!target) {
1400
1664
  console.warn("SSReflectionPluginPass: target not defined. It must be set when inlineShaderRayTrace is false");
1401
1665
  return;
1402
1666
  }
1403
- this.material.defines.HAS_GBUFFER || console.warn("SSReflectionPluginPass: DepthNormalBuffer required for ssrefl"), a.renderManager.blit(e, {
1404
- source: s.texture
1405
- }), this.uniforms.tLastThis.value = e.texture, super.render(a, s, i, r, t), this.needsSwap = !1;
1667
+ if (!this.material.defines.HAS_GBUFFER) {
1668
+ console.warn("SSReflectionPluginPass: DepthNormalBuffer required for ssrefl");
1669
+ }
1670
+ renderer.renderManager.blit(writeBuffer, {
1671
+ source: target.texture
1672
+ });
1673
+ this.uniforms.tLastThis.value = writeBuffer.texture;
1674
+ super.render(renderer, target, readBuffer, deltaTime, maskActive);
1675
+ this.needsSwap = false;
1406
1676
  }
1407
- beforeRender(a, e, i) {
1408
- this.enabled && this.updateShaderProperties([a, e, i]);
1677
+ beforeRender(scene, camera, renderManager) {
1678
+ if (!this.enabled) return;
1679
+ this.updateShaderProperties([scene, camera, renderManager]);
1409
1680
  }
1410
1681
  /**
1411
1682
  * Returns a uiConfig to toggle SSReflection on a material.
@@ -1413,7 +1684,7 @@ ${le}
1413
1684
  * @param material
1414
1685
  * @private
1415
1686
  */
1416
- _getUiConfig(a) {
1687
+ _getUiConfig(material) {
1417
1688
  return {
1418
1689
  type: "folder",
1419
1690
  label: "SSReflection",
@@ -1422,10 +1693,12 @@ ${le}
1422
1693
  type: "checkbox",
1423
1694
  label: "Enabled",
1424
1695
  get value() {
1425
- return !(a.userData.ssreflDisabled ?? !1);
1696
+ return !(material.userData.ssreflDisabled ?? false);
1426
1697
  },
1427
- set value(e) {
1428
- e !== !(a.userData.ssreflDisabled ?? !1) && (a.userData.ssreflDisabled = !e, a.setDirty());
1698
+ set value(v) {
1699
+ if (v === !(material.userData.ssreflDisabled ?? false)) return;
1700
+ material.userData.ssreflDisabled = !v;
1701
+ material.setDirty();
1429
1702
  },
1430
1703
  onChange: this.setDirty
1431
1704
  },
@@ -1433,96 +1706,105 @@ ${le}
1433
1706
  type: "checkbox",
1434
1707
  label: "Non Physical",
1435
1708
  get value() {
1436
- return a.userData.ssreflNonPhysical ?? !1;
1709
+ return material.userData.ssreflNonPhysical ?? false;
1437
1710
  },
1438
- set value(e) {
1439
- e !== (a.userData.ssreflNonPhysical ?? !1) && (a.userData.ssreflNonPhysical = e, a.setDirty());
1711
+ set value(v) {
1712
+ if (v === (material.userData.ssreflNonPhysical ?? false)) return;
1713
+ material.userData.ssreflNonPhysical = v;
1714
+ material.setDirty();
1440
1715
  },
1441
1716
  onChange: this.setDirty
1442
1717
  }
1443
1718
  ]
1444
1719
  };
1445
1720
  }
1446
- set uniformsNeedUpdate(a) {
1447
- this.material.uniformsNeedUpdate = a, this.setDirty();
1721
+ set uniformsNeedUpdate(value) {
1722
+ this.material.uniformsNeedUpdate = value;
1723
+ this.setDirty();
1448
1724
  }
1449
- setGBufferUnpackExtension(a) {
1450
- this._gbufferUnpackExtension !== a && (this._gbufferUnpackExtension && this.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]), this._gbufferUnpackExtension = a, this._gbufferUnpackExtension && this.material.registerMaterialExtensions([this._gbufferUnpackExtension]), this._gbufferUnpackExtension && (Object.assign(this.materialExtension.extraUniforms, this._gbufferUnpackExtension.extraUniforms), Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines)));
1725
+ setGBufferUnpackExtension(extension) {
1726
+ if (this._gbufferUnpackExtension === extension) return;
1727
+ if (this._gbufferUnpackExtension) this.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]);
1728
+ this._gbufferUnpackExtension = extension;
1729
+ if (this._gbufferUnpackExtension) this.material.registerMaterialExtensions([this._gbufferUnpackExtension]);
1730
+ if (!this._gbufferUnpackExtension) return;
1731
+ Object.assign(this.materialExtension.extraUniforms, this._gbufferUnpackExtension.extraUniforms);
1732
+ Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines);
1451
1733
  }
1452
1734
  };
1453
- x([
1454
- u("Intensity", [0, 4]),
1455
- c(),
1456
- f()
1457
- ], v.prototype, "intensity", 2);
1458
- x([
1459
- ue("Boost"),
1460
- c(),
1461
- f()
1462
- ], v.prototype, "boost", 2);
1463
- x([
1464
- u("Object Radius", [0.01, 2]),
1465
- c(),
1466
- f()
1467
- ], v.prototype, "objectRadius", 2);
1468
- x([
1469
- R("Auto radius"),
1470
- c(),
1471
- f()
1472
- ], v.prototype, "autoRadius", 2);
1473
- x([
1474
- u("Power", [0, 3]),
1475
- c(),
1476
- f()
1477
- ], v.prototype, "power", 2);
1478
- x([
1479
- u("Tolerance", [0.1, 5]),
1480
- c(),
1481
- f()
1482
- ], v.prototype, "tolerance", 2);
1483
- x([
1484
- u("Step count", [1, 32], 1),
1485
- c(),
1486
- V("SSR_STEP_COUNT", void 0, void 0, v.prototype.setDirty)
1487
- ], v.prototype, "stepCount", 2);
1488
- x([
1489
- u("Low Quality Frames", [0, 4], 1),
1490
- c(),
1491
- V("SSR_LOW_QUALITY_FRAMES", void 0, void 0, v.prototype.setDirty)
1492
- ], v.prototype, "lowQualityFrames", 2);
1493
- x([
1494
- R("Ignore front rays"),
1495
- c(),
1496
- fe("SSR_MASK_FRONT_RAYS", void 0, void 0, v.prototype.setDirty)
1497
- ], v.prototype, "maskFrontRays", 2);
1498
- x([
1499
- u("Mask front rays factor", [-1, 1], 0.01, (a) => ({ hidden: () => !a.maskFrontRays })),
1500
- c(),
1501
- f()
1502
- ], v.prototype, "maskFrontFactor", 2);
1503
- v = x([
1504
- z("SSReflection Pass")
1505
- ], v);
1506
- const dt = [
1507
- M,
1508
- L,
1509
- qe,
1510
- D,
1511
- p,
1512
- A
1735
+ __decorateClass([
1736
+ uiSlider("Intensity", [0, 4]),
1737
+ serialize(),
1738
+ uniform()
1739
+ ], SSReflectionPluginPass.prototype, "intensity", 2);
1740
+ __decorateClass([
1741
+ uiVector("Boost"),
1742
+ serialize(),
1743
+ uniform()
1744
+ ], SSReflectionPluginPass.prototype, "boost", 2);
1745
+ __decorateClass([
1746
+ uiSlider("Object Radius", [0.01, 2]),
1747
+ serialize(),
1748
+ uniform()
1749
+ ], SSReflectionPluginPass.prototype, "objectRadius", 2);
1750
+ __decorateClass([
1751
+ uiToggle("Auto radius"),
1752
+ serialize(),
1753
+ uniform()
1754
+ ], SSReflectionPluginPass.prototype, "autoRadius", 2);
1755
+ __decorateClass([
1756
+ uiSlider("Power", [0, 3]),
1757
+ serialize(),
1758
+ uniform()
1759
+ ], SSReflectionPluginPass.prototype, "power", 2);
1760
+ __decorateClass([
1761
+ uiSlider("Tolerance", [0.1, 5]),
1762
+ serialize(),
1763
+ uniform()
1764
+ ], SSReflectionPluginPass.prototype, "tolerance", 2);
1765
+ __decorateClass([
1766
+ uiSlider("Step count", [1, 32], 1),
1767
+ serialize(),
1768
+ matDefine("SSR_STEP_COUNT", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1769
+ ], SSReflectionPluginPass.prototype, "stepCount", 2);
1770
+ __decorateClass([
1771
+ uiSlider("Low Quality Frames", [0, 4], 1),
1772
+ serialize(),
1773
+ matDefine("SSR_LOW_QUALITY_FRAMES", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1774
+ ], SSReflectionPluginPass.prototype, "lowQualityFrames", 2);
1775
+ __decorateClass([
1776
+ uiToggle("Ignore front rays"),
1777
+ serialize(),
1778
+ matDefineBool("SSR_MASK_FRONT_RAYS", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
1779
+ ], SSReflectionPluginPass.prototype, "maskFrontRays", 2);
1780
+ __decorateClass([
1781
+ uiSlider("Mask front rays factor", [-1, 1], 0.01, (that) => ({ hidden: () => !that.maskFrontRays })),
1782
+ serialize(),
1783
+ uniform()
1784
+ ], SSReflectionPluginPass.prototype, "maskFrontFactor", 2);
1785
+ SSReflectionPluginPass = __decorateClass([
1786
+ uiFolderContainer("SSReflection Pass")
1787
+ ], SSReflectionPluginPass);
1788
+ const webgiPlugins = [
1789
+ TemporalAAPlugin,
1790
+ VelocityBufferPlugin,
1791
+ BloomPlugin,
1792
+ SSReflectionPlugin,
1793
+ SSContactShadowsPlugin,
1794
+ DepthOfFieldPlugin
1513
1795
  ];
1514
1796
  export {
1515
- qe as BloomPlugin,
1516
- h as BloomPluginPass,
1517
- A as DepthOfFieldPlugin,
1518
- b as DepthOfFieldPluginPass,
1519
- p as SSContactShadowsPlugin,
1520
- D as SSReflectionPlugin,
1521
- v as SSReflectionPluginPass,
1522
- He as SSVelocityMaterial,
1523
- M as TemporalAAPlugin,
1524
- ee as TemporalAAPluginPass,
1525
- L as VelocityBufferPlugin,
1526
- dt as webgiPlugins
1797
+ BloomPlugin,
1798
+ BloomPluginPass,
1799
+ DepthOfFieldPlugin,
1800
+ DepthOfFieldPluginPass,
1801
+ SSContactShadowsPlugin,
1802
+ SSReflectionPlugin,
1803
+ SSReflectionPluginPass,
1804
+ SSVelocityMaterial,
1805
+ TemporalAAPlugin,
1806
+ TemporalAAPluginPass,
1807
+ VelocityBufferPlugin,
1808
+ webgiPlugins
1527
1809
  };
1528
1810
  //# sourceMappingURL=index.mjs.map