@react-three/postprocessing 2.14.12 → 2.14.13

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.cjs CHANGED
@@ -7,7 +7,6 @@ const fiber = require("@react-three/fiber");
7
7
  const postprocessing = require("postprocessing");
8
8
  const threeStdlib = require("three-stdlib");
9
9
  const maath = require("maath");
10
- const screenSpaceReflections = require("screen-space-reflections");
11
10
  require("three-stdlib");
12
11
  function _interopNamespaceDefault(e) {
13
12
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -782,11 +781,1137 @@ const ASCII = React.forwardRef(
782
781
  return /* @__PURE__ */ jsxRuntime.jsx("primitive", { ref: fref, object: effect });
783
782
  }
784
783
  );
784
+ var boxBlur = "#define GLSLIFY 1\nuniform float blur;uniform float blurSharpness;uniform int blurKernel;vec3 denoise(vec3 center,sampler2D tex,vec2 uv,vec2 invTexSize,float blur,float blurSharpness,int blurKernel){vec3 color;float total;vec3 col;float weight;for(int x=-blurKernel;x<=blurKernel;x++){for(int y=-blurKernel;y<=blurKernel;y++){col=textureLod(tex,uv+vec2(x,y)*invTexSize,0.).rgb;weight=1.0-abs(dot(col-center,vec3(0.25)));weight=pow(weight,blurSharpness);color+=col*weight;total+=weight;}}return color/total;}";
785
+ var finalSSRShader = "#define GLSLIFY 1\n#define MODE_DEFAULT 0\n#define MODE_REFLECTIONS 1\n#define MODE_RAW_REFLECTION 2\n#define MODE_BLURRED_REFLECTIONS 3\n#define MODE_INPUT 4\n#define MODE_BLUR_MIX 5\n#define FLOAT_EPSILON 0.00001\nuniform sampler2D inputTexture;uniform sampler2D reflectionsTexture;uniform float samples;\n#include <boxBlur>\nvoid mainImage(const in vec4 inputColor,const in vec2 uv,out vec4 outputColor){vec4 reflectionsTexel=texture2D(reflectionsTexture,vUv);ivec2 size=textureSize(reflectionsTexture,0);vec2 invTexSize=1./vec2(size.x,size.y);vec3 reflectionClr=reflectionsTexel.xyz;if(blur>FLOAT_EPSILON){vec3 blurredReflectionsColor=denoise(reflectionsTexel.rgb,reflectionsTexture,vUv,invTexSize,blur,blurSharpness,blurKernel);reflectionClr=mix(reflectionClr,blurredReflectionsColor.rgb,blur);}\n#if RENDER_MODE == MODE_DEFAULT\noutputColor=vec4(inputColor.rgb+reflectionClr,1.0);\n#endif\n#if RENDER_MODE == MODE_REFLECTIONS\noutputColor=vec4(reflectionClr,1.0);\n#endif\n#if RENDER_MODE == MODE_RAW_REFLECTION\noutputColor=vec4(reflectionsTexel.xyz,1.0);\n#endif\n#if RENDER_MODE == MODE_BLURRED_REFLECTIONS\noutputColor=vec4(blurredReflectionsTexel.xyz,1.0);\n#endif\n#if RENDER_MODE == MODE_INPUT\noutputColor=vec4(inputColor.xyz,1.0);\n#endif\n#if RENDER_MODE == MODE_BLUR_MIX\noutputColor=vec4(vec3(blur),1.0);\n#endif\n}";
786
+ var helperFunctions = "#define GLSLIFY 1\nvec3 getViewPosition(const float depth){float clipW=_projectionMatrix[2][3]*depth+_projectionMatrix[3][3];vec4 clipPosition=vec4((vec3(vUv,depth)-0.5)*2.0,1.0);clipPosition*=clipW;return(_inverseProjectionMatrix*clipPosition).xyz;}float getViewZ(const in float depth){\n#ifdef PERSPECTIVE_CAMERA\nreturn perspectiveDepthToViewZ(depth,cameraNear,cameraFar);\n#else\nreturn orthographicDepthToViewZ(depth,cameraNear,cameraFar);\n#endif\n}vec3 screenSpaceToWorldSpace(const vec2 uv,const float depth){vec4 ndc=vec4((uv.x-0.5)*2.0,(uv.y-0.5)*2.0,(depth-0.5)*2.0,1.0);vec4 clip=_inverseProjectionMatrix*ndc;vec4 view=cameraMatrixWorld*(clip/clip.w);return view.xyz;}\n#define Scale (vec3(0.8, 0.8, 0.8))\n#define K (19.19)\nvec3 hash(vec3 a){a=fract(a*Scale);a+=dot(a,a.yxz+K);return fract((a.xxy+a.yxx)*a.zyx);}float fresnel_dielectric_cos(float cosi,float eta){float c=abs(cosi);float g=eta*eta-1.0+c*c;float result;if(g>0.0){g=sqrt(g);float A=(g-c)/(g+c);float B=(c*(g+c)-1.0)/(c*(g-c)+1.0);result=0.5*A*A*(1.0+B*B);}else{result=1.0;}return result;}float fresnel_dielectric(vec3 Incoming,vec3 Normal,float eta){float cosine=dot(Incoming,Normal);return min(1.0,5.0*fresnel_dielectric_cos(cosine,eta));}";
787
+ var trCompose = "#define GLSLIFY 1\n#define INV_EULER 0.36787944117144233\nalpha=velocityDisocclusion<FLOAT_EPSILON ?(alpha+0.0075): 0.0;alpha=clamp(alpha,0.0,1.0);bool needsBlur=!didReproject||velocityDisocclusion>0.5;\n#ifdef boxBlur\nif(needsBlur)inputColor=boxBlurredColor;\n#endif\nif(alpha==1.0){outputColor=accumulatedColor;}else{float m=mix(alpha,1.0,blend);if(needsBlur)m=0.0;outputColor=accumulatedColor*m+inputColor*(1.0-m);}";
788
+ class MRTMaterial extends THREE.ShaderMaterial {
789
+ constructor() {
790
+ super({
791
+ type: "MRTMaterial",
792
+ defines: {
793
+ USE_UV: "",
794
+ TEMPORAL_RESOLVE: ""
795
+ },
796
+ uniforms: {
797
+ opacity: new THREE.Uniform(1),
798
+ normalMap: new THREE.Uniform(null),
799
+ normalScale: new THREE.Uniform(new THREE.Vector2(1, 1)),
800
+ uvTransform: new THREE.Uniform(new THREE.Matrix3()),
801
+ roughness: new THREE.Uniform(1),
802
+ roughnessMap: new THREE.Uniform(null)
803
+ },
804
+ vertexShader: (
805
+ /* glsl */
806
+ `
807
+ #ifdef USE_MRT
808
+ varying vec2 vHighPrecisionZW;
809
+ #endif
810
+ #define NORMAL
811
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
812
+ varying vec3 vViewPosition;
813
+ #endif
814
+ #include <common>
815
+ #include <uv_pars_vertex>
816
+ #include <displacementmap_pars_vertex>
817
+ #include <normal_pars_vertex>
818
+ #include <morphtarget_pars_vertex>
819
+ #include <skinning_pars_vertex>
820
+ #include <logdepthbuf_pars_vertex>
821
+ #include <clipping_planes_pars_vertex>
822
+ #ifdef USE_UV
823
+ ${THREE.REVISION.replace(/\D+/g, "") >= 151 ? "uniform mat3 uvTransform;" : ""}
824
+ #endif
825
+ void main() {
826
+ #include <uv_vertex>
827
+ #include <beginnormal_vertex>
828
+ #include <morphnormal_vertex>
829
+ #include <skinbase_vertex>
830
+ #include <skinnormal_vertex>
831
+ #include <defaultnormal_vertex>
832
+ #include <normal_vertex>
833
+ #include <begin_vertex>
834
+ #include <morphtarget_vertex>
835
+ #include <skinning_vertex>
836
+ #include <displacementmap_vertex>
837
+ #include <project_vertex>
838
+ #include <logdepthbuf_vertex>
839
+ #include <clipping_planes_vertex>
840
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
841
+ vViewPosition = - mvPosition.xyz;
842
+ #endif
843
+ #ifdef USE_MRT
844
+ vHighPrecisionZW = gl_Position.zw;
845
+ #endif
846
+ #ifdef USE_UV
847
+ vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
848
+ #endif
849
+ }
850
+ `
851
+ ),
852
+ fragmentShader: (
853
+ /* glsl */
854
+ `
855
+ #define NORMAL
856
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
857
+ varying vec3 vViewPosition;
858
+ #endif
859
+ #include <packing>
860
+ #include <uv_pars_fragment>
861
+ #include <normal_pars_fragment>
862
+ #include <bumpmap_pars_fragment>
863
+ #include <normalmap_pars_fragment>
864
+ #include <logdepthbuf_pars_fragment>
865
+ #include <clipping_planes_pars_fragment>
866
+ #include <roughnessmap_pars_fragment>
867
+
868
+ #ifdef USE_MRT
869
+ layout(location = 0) out vec4 gNormal;
870
+ layout(location = 1) out vec4 gDepth;
871
+
872
+ varying vec2 vHighPrecisionZW;
873
+ #endif
874
+ uniform float roughness;
875
+ void main() {
876
+ #include <clipping_planes_fragment>
877
+ #include <logdepthbuf_fragment>
878
+ #include <normal_fragment_begin>
879
+ #include <normal_fragment_maps>
880
+
881
+ float roughnessFactor = roughness;
882
+
883
+ if(roughness > 10.0e9){
884
+ roughnessFactor = 1.;
885
+ }else{
886
+ #ifdef useRoughnessMap
887
+ vec4 texelRoughness = texture2D( roughnessMap, vUv );
888
+ // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
889
+ roughnessFactor *= texelRoughness.g;
890
+ #endif
891
+ }
892
+
893
+ vec3 normalColor = packNormalToRGB( normal );
894
+ #ifdef USE_MRT
895
+ float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
896
+ vec4 depthColor = packDepthToRGBA( fragCoordZ );
897
+ gNormal = vec4( normalColor, roughnessFactor );
898
+ gDepth = depthColor;
899
+ #else
900
+ gl_FragColor = vec4(normalColor, roughnessFactor);
901
+ #endif
902
+ }
903
+ `
904
+ ),
905
+ toneMapped: false
906
+ });
907
+ this.normalMapType = THREE.TangentSpaceNormalMap;
908
+ this.normalScale = new THREE.Vector2(1, 1);
909
+ Object.defineProperty(this, "glslVersion", {
910
+ get() {
911
+ return "USE_MRT" in this.defines ? THREE.GLSL3 : null;
912
+ },
913
+ set(_) {
914
+ }
915
+ });
916
+ }
917
+ }
918
+ var vertexShader$1 = "#define GLSLIFY 1\nvarying vec2 vUv;void main(){vUv=position.xy*0.5+0.5;gl_Position=vec4(position.xy,1.0,1.0);}";
919
+ var fragmentShader = "#define GLSLIFY 1\nvarying vec2 vUv;uniform sampler2D inputTexture;uniform sampler2D accumulatedTexture;uniform sampler2D normalTexture;uniform sampler2D depthTexture;uniform sampler2D envMap;uniform mat4 _projectionMatrix;uniform mat4 _inverseProjectionMatrix;uniform mat4 cameraMatrixWorld;uniform float cameraNear;uniform float cameraFar;uniform float rayDistance;uniform float intensity;uniform float maxDepthDifference;uniform float roughnessFade;uniform float maxRoughness;uniform float fade;uniform float thickness;uniform float ior;uniform float samples;uniform float jitter;uniform float jitterRoughness;\n#define INVALID_RAY_COORDS vec2(-1.0);\n#define EARLY_OUT_COLOR vec4(0.0, 0.0, 0.0, 1.0)\n#define FLOAT_EPSILON 0.00001\nfloat nearMinusFar;float nearMulFar;float farMinusNear;\n#include <packing>\n#include <helperFunctions>\nvec2 RayMarch(vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference);vec2 BinarySearch(in vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference);float fastGetViewZ(const in float depth);vec3 getIBLRadiance(const in vec3 viewDir,const in vec3 normal,const in float roughness);void main(){vec4 depthTexel=textureLod(depthTexture,vUv,0.0);if(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON){gl_FragColor=EARLY_OUT_COLOR;return;}float unpackedDepth=unpackRGBAToDepth(depthTexel);vec4 normalTexel=textureLod(normalTexture,vUv,0.0);float roughness=normalTexel.a;float specular=1.0-roughness;nearMinusFar=cameraNear-cameraFar;nearMulFar=cameraNear*cameraFar;farMinusNear=cameraFar-cameraNear;normalTexel.rgb=unpackRGBToNormal(normalTexel.rgb);float depth=fastGetViewZ(unpackedDepth);vec3 viewPos=getViewPosition(depth);vec3 viewDir=normalize(viewPos);vec3 viewNormal=normalTexel.xyz;vec3 worldPos=screenSpaceToWorldSpace(vUv,unpackedDepth);vec3 jitt=vec3(0.0);if(jitterRoughness!=0.0||jitter!=0.0){vec3 randomJitter=hash(50.0*samples*worldPos)-0.5;float spread=((2.0-specular)+roughness*jitterRoughness);float jitterMix=jitter*0.25+jitterRoughness*roughness;if(jitterMix>1.0)jitterMix=1.0;jitt=mix(vec3(0.0),randomJitter*spread,jitterMix);}viewNormal+=jitt;float fresnelFactor=fresnel_dielectric(viewDir,viewNormal,ior);vec3 iblRadiance=getIBLRadiance(-viewDir,viewNormal,0.)*fresnelFactor;float lastFrameAlpha=textureLod(accumulatedTexture,vUv,0.0).a;if(roughness>maxRoughness||(roughness>1.0-FLOAT_EPSILON&&roughnessFade>1.0-FLOAT_EPSILON)){gl_FragColor=vec4(iblRadiance,lastFrameAlpha);return;}vec3 reflected=reflect(viewDir,viewNormal);vec3 rayDir=reflected*-viewPos.z;vec3 hitPos=viewPos;float rayHitDepthDifference;vec2 coords=RayMarch(rayDir,hitPos,rayHitDepthDifference);if(coords.x==-1.0){gl_FragColor=vec4(iblRadiance,lastFrameAlpha);return;}vec4 SSRTexel=textureLod(inputTexture,coords.xy,0.0);vec4 SSRTexelReflected=textureLod(accumulatedTexture,coords.xy,0.0);vec3 SSR=SSRTexel.rgb+SSRTexelReflected.rgb;float roughnessFactor=mix(specular,1.0,max(0.0,1.0-roughnessFade));vec2 coordsNDC=(coords.xy*2.0-1.0);float screenFade=0.1;float maxDimension=min(1.0,max(abs(coordsNDC.x),abs(coordsNDC.y)));float reflectionIntensity=1.0-(max(0.0,maxDimension-screenFade)/(1.0-screenFade));reflectionIntensity=max(0.,reflectionIntensity);vec3 finalSSR=mix(iblRadiance,SSR,reflectionIntensity)*roughnessFactor;if(fade!=0.0){vec3 hitWorldPos=screenSpaceToWorldSpace(coords,rayHitDepthDifference);float reflectionDistance=distance(hitWorldPos,worldPos)+1.0;float opacity=1.0/(reflectionDistance*fade*0.1);if(opacity>1.0)opacity=1.0;finalSSR*=opacity;}finalSSR*=fresnelFactor*intensity;finalSSR=min(vec3(1.0),finalSSR);float alpha=hitPos.z==1.0 ? 1.0 : SSRTexelReflected.a;alpha=min(lastFrameAlpha,alpha);gl_FragColor=vec4(finalSSR,alpha);}vec2 RayMarch(vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference){dir=normalize(dir);dir*=rayDistance/float(steps);float depth;vec4 projectedCoord;vec4 lastProjectedCoord;float unpackedDepth;vec4 depthTexel;for(int i=0;i<steps;i++){hitPos+=dir;projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;\n#ifndef missedRays\nif(projectedCoord.x<0.0||projectedCoord.x>1.0||projectedCoord.y<0.0||projectedCoord.y>1.0){return INVALID_RAY_COORDS;}\n#endif\ndepthTexel=textureLod(depthTexture,projectedCoord.xy,0.0);unpackedDepth=unpackRGBAToDepth(depthTexel);depth=fastGetViewZ(unpackedDepth);rayHitDepthDifference=depth-hitPos.z;if(rayHitDepthDifference>=0.0&&rayHitDepthDifference<thickness){\n#if refineSteps == 0\nif(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON)return INVALID_RAY_COORDS;\n#else\nreturn BinarySearch(dir,hitPos,rayHitDepthDifference);\n#endif\n}\n#ifndef missedRays\nif(hitPos.z>0.0){return INVALID_RAY_COORDS;}\n#endif\nlastProjectedCoord=projectedCoord;}hitPos.z=1.0;\n#ifndef missedRays\nreturn INVALID_RAY_COORDS;\n#endif\nrayHitDepthDifference=unpackedDepth;return projectedCoord.xy;}vec2 BinarySearch(in vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference){float depth;vec4 projectedCoord;vec2 lastMinProjectedCoordXY;float unpackedDepth;vec4 depthTexel;for(int i=0;i<refineSteps;i++){projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;depthTexel=textureLod(depthTexture,projectedCoord.xy,0.0);unpackedDepth=unpackRGBAToDepth(depthTexel);depth=fastGetViewZ(unpackedDepth);rayHitDepthDifference=depth-hitPos.z;dir*=0.5;if(rayHitDepthDifference>0.0){hitPos-=dir;}else{hitPos+=dir;}}if(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON)return INVALID_RAY_COORDS;if(abs(rayHitDepthDifference)>maxDepthDifference)return INVALID_RAY_COORDS;projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;rayHitDepthDifference=unpackedDepth;return projectedCoord.xy;}float fastGetViewZ(const in float depth){\n#ifdef PERSPECTIVE_CAMERA\nreturn nearMulFar/(farMinusNear*depth-cameraFar);\n#else\nreturn depth*nearMinusFar-cameraNear;\n#endif\n}\n#include <common>\n#include <cube_uv_reflection_fragment>\nvec3 getIBLRadiance(const in vec3 viewDir,const in vec3 normal,const in float roughness){\n#if defined(ENVMAP_TYPE_CUBE_UV)\nvec3 reflectVec=reflect(-viewDir,normal);reflectVec=normalize(mix(reflectVec,normal,roughness*roughness));reflectVec=inverseTransformDirection(reflectVec,viewMatrix);vec4 envMapColor=textureCubeUV(envMap,reflectVec,roughness);return envMapColor.rgb*intensity;\n#else\nreturn vec3(0.0);\n#endif\n}";
920
+ class ReflectionsMaterial extends THREE.ShaderMaterial {
921
+ constructor() {
922
+ super({
923
+ type: "ReflectionsMaterial",
924
+ uniforms: {
925
+ inputTexture: new THREE.Uniform(null),
926
+ accumulatedTexture: new THREE.Uniform(null),
927
+ normalTexture: new THREE.Uniform(null),
928
+ depthTexture: new THREE.Uniform(null),
929
+ _projectionMatrix: new THREE.Uniform(new THREE.Matrix4()),
930
+ _inverseProjectionMatrix: new THREE.Uniform(new THREE.Matrix4()),
931
+ cameraMatrixWorld: new THREE.Uniform(new THREE.Matrix4()),
932
+ cameraNear: new THREE.Uniform(0),
933
+ cameraFar: new THREE.Uniform(0),
934
+ rayDistance: new THREE.Uniform(0),
935
+ intensity: new THREE.Uniform(0),
936
+ roughnessFade: new THREE.Uniform(0),
937
+ fade: new THREE.Uniform(0),
938
+ thickness: new THREE.Uniform(0),
939
+ ior: new THREE.Uniform(0),
940
+ maxDepthDifference: new THREE.Uniform(0),
941
+ jitter: new THREE.Uniform(0),
942
+ jitterRoughness: new THREE.Uniform(0),
943
+ maxRoughness: new THREE.Uniform(0),
944
+ samples: new THREE.Uniform(0),
945
+ envMap: new THREE.Uniform(null),
946
+ envMapPosition: new THREE.Uniform(new THREE.Vector3()),
947
+ envMapSize: new THREE.Uniform(new THREE.Vector3()),
948
+ viewMatrix: new THREE.Uniform(new THREE.Matrix4())
949
+ },
950
+ defines: {
951
+ steps: 20,
952
+ refineSteps: 5,
953
+ CUBEUV_TEXEL_WIDTH: 0,
954
+ CUBEUV_TEXEL_HEIGHT: 0,
955
+ CUBEUV_MAX_MIP: 0,
956
+ vWorldPosition: "worldPos"
957
+ },
958
+ fragmentShader: fragmentShader.replace("#include <helperFunctions>", helperFunctions),
959
+ vertexShader: vertexShader$1,
960
+ toneMapped: false,
961
+ depthWrite: false,
962
+ depthTest: false
963
+ });
964
+ }
965
+ }
966
+ const getVisibleChildren = (object) => {
967
+ const queue = [object];
968
+ const objects = [];
969
+ while (queue.length !== 0) {
970
+ const mesh = queue.shift();
971
+ if (mesh.material)
972
+ objects.push(mesh);
973
+ for (const c of mesh.children) {
974
+ if (c.visible)
975
+ queue.push(c);
976
+ }
977
+ }
978
+ return objects;
979
+ };
980
+ const generateCubeUVSize = (parameters) => {
981
+ const imageHeight = parameters.envMapCubeUVHeight;
982
+ if (imageHeight === null)
983
+ return null;
984
+ const maxMip = Math.log2(imageHeight) - 2;
985
+ const texelHeight = 1 / imageHeight;
986
+ const texelWidth = 1 / (3 * Math.max(Math.pow(2, maxMip), 7 * 16));
987
+ return {
988
+ texelWidth,
989
+ texelHeight,
990
+ maxMip
991
+ };
992
+ };
993
+ const setupEnvMap = (reflectionsMaterial, envMap, envMapCubeUVHeight) => {
994
+ reflectionsMaterial.uniforms.envMap.value = envMap;
995
+ const envMapCubeUVSize = generateCubeUVSize({
996
+ envMapCubeUVHeight
997
+ });
998
+ reflectionsMaterial.defines.ENVMAP_TYPE_CUBE_UV = "";
999
+ reflectionsMaterial.defines.CUBEUV_TEXEL_WIDTH = envMapCubeUVSize.texelWidth;
1000
+ reflectionsMaterial.defines.CUBEUV_TEXEL_HEIGHT = envMapCubeUVSize.texelHeight;
1001
+ reflectionsMaterial.defines.CUBEUV_MAX_MIP = envMapCubeUVSize.maxMip + ".0";
1002
+ reflectionsMaterial.needsUpdate = true;
1003
+ };
1004
+ const isWebGL2Available = () => {
1005
+ try {
1006
+ const canvas = document.createElement("canvas");
1007
+ return !!(window.WebGL2RenderingContext && canvas.getContext("webgl2"));
1008
+ } catch (e) {
1009
+ return false;
1010
+ }
1011
+ };
1012
+ class ReflectionsPass extends postprocessing.Pass {
1013
+ constructor(ssrEffect, options = {}) {
1014
+ super("ReflectionsPass");
1015
+ this.ssrEffect = void 0;
1016
+ this.cachedMaterials = /* @__PURE__ */ new WeakMap();
1017
+ this.USE_MRT = false;
1018
+ this.webgl1DepthPass = null;
1019
+ this.visibleMeshes = [];
1020
+ this.ssrEffect = ssrEffect;
1021
+ this._scene = ssrEffect._scene;
1022
+ this._camera = ssrEffect._camera;
1023
+ this.fullscreenMaterial = new ReflectionsMaterial();
1024
+ if (ssrEffect._camera.isPerspectiveCamera)
1025
+ this.fullscreenMaterial.defines.PERSPECTIVE_CAMERA = "";
1026
+ const width = options.width || typeof window !== "undefined" ? window.innerWidth : 2e3;
1027
+ const height = options.height || typeof window !== "undefined" ? window.innerHeight : 1e3;
1028
+ this.renderTarget = new THREE.WebGLRenderTarget(width, height, {
1029
+ minFilter: THREE.LinearFilter,
1030
+ magFilter: THREE.LinearFilter,
1031
+ type: THREE.HalfFloatType,
1032
+ depthBuffer: false
1033
+ });
1034
+ this.renderPass = new postprocessing.RenderPass(this._scene, this._camera);
1035
+ this.USE_MRT = isWebGL2Available();
1036
+ if (this.USE_MRT) {
1037
+ this.gBuffersRenderTarget = new THREE.WebGLMultipleRenderTargets(width, height, 2, {
1038
+ minFilter: THREE.LinearFilter,
1039
+ magFilter: THREE.LinearFilter
1040
+ });
1041
+ this.normalTexture = this.gBuffersRenderTarget.texture[0];
1042
+ this.depthTexture = this.gBuffersRenderTarget.texture[1];
1043
+ } else {
1044
+ this.webgl1DepthPass = new postprocessing.DepthPass(this._scene, this._camera);
1045
+ this.webgl1DepthPass.renderTarget.minFilter = THREE.LinearFilter;
1046
+ this.webgl1DepthPass.renderTarget.magFilter = THREE.LinearFilter;
1047
+ this.webgl1DepthPass.renderTarget.texture.minFilter = THREE.LinearFilter;
1048
+ this.webgl1DepthPass.renderTarget.texture.magFilter = THREE.LinearFilter;
1049
+ this.webgl1DepthPass.setSize(
1050
+ typeof window !== "undefined" ? window.innerWidth : 2e3,
1051
+ typeof window !== "undefined" ? window.innerHeight : 1e3
1052
+ );
1053
+ this.gBuffersRenderTarget = new THREE.WebGLRenderTarget(width, height, {
1054
+ minFilter: THREE.LinearFilter,
1055
+ magFilter: THREE.LinearFilter
1056
+ });
1057
+ this.normalTexture = this.gBuffersRenderTarget.texture;
1058
+ this.depthTexture = this.webgl1DepthPass.texture;
1059
+ }
1060
+ this.fullscreenMaterial.uniforms.normalTexture.value = this.normalTexture;
1061
+ this.fullscreenMaterial.uniforms.depthTexture.value = this.depthTexture;
1062
+ this.fullscreenMaterial.uniforms.accumulatedTexture.value = this.ssrEffect.temporalResolvePass.accumulatedTexture;
1063
+ this.fullscreenMaterial.uniforms.cameraMatrixWorld.value = this._camera.matrixWorld;
1064
+ this.fullscreenMaterial.uniforms._projectionMatrix.value = this._camera.projectionMatrix;
1065
+ this.fullscreenMaterial.uniforms._inverseProjectionMatrix.value = this._camera.projectionMatrixInverse;
1066
+ }
1067
+ setSize(width, height) {
1068
+ this.renderTarget.setSize(width * this.ssrEffect.resolutionScale, height * this.ssrEffect.resolutionScale);
1069
+ this.gBuffersRenderTarget.setSize(width * this.ssrEffect.resolutionScale, height * this.ssrEffect.resolutionScale);
1070
+ this.fullscreenMaterial.uniforms.accumulatedTexture.value = this.ssrEffect.temporalResolvePass.accumulatedTexture;
1071
+ this.fullscreenMaterial.needsUpdate = true;
1072
+ }
1073
+ dispose() {
1074
+ this.renderTarget.dispose();
1075
+ this.gBuffersRenderTarget.dispose();
1076
+ this.renderPass.dispose();
1077
+ if (!this.USE_MRT)
1078
+ this.webgl1DepthPass.dispose();
1079
+ this.fullscreenMaterial.dispose();
1080
+ this.normalTexture = null;
1081
+ this.depthTexture = null;
1082
+ this.velocityTexture = null;
1083
+ }
1084
+ keepMaterialMapUpdated(mrtMaterial, originalMaterial, prop, define) {
1085
+ if (this.ssrEffect[define]) {
1086
+ if (originalMaterial[prop] !== mrtMaterial[prop]) {
1087
+ mrtMaterial[prop] = originalMaterial[prop];
1088
+ mrtMaterial.uniforms[prop].value = originalMaterial[prop];
1089
+ if (originalMaterial[prop]) {
1090
+ mrtMaterial.defines[define] = "";
1091
+ } else {
1092
+ delete mrtMaterial.defines[define];
1093
+ }
1094
+ mrtMaterial.needsUpdate = true;
1095
+ }
1096
+ } else if (mrtMaterial[prop] !== void 0) {
1097
+ mrtMaterial[prop] = void 0;
1098
+ mrtMaterial.uniforms[prop].value = void 0;
1099
+ delete mrtMaterial.defines[define];
1100
+ mrtMaterial.needsUpdate = true;
1101
+ }
1102
+ }
1103
+ setMRTMaterialInScene() {
1104
+ this.visibleMeshes = getVisibleChildren(this._scene);
1105
+ for (const c of this.visibleMeshes) {
1106
+ if (c.material) {
1107
+ const originalMaterial = c.material;
1108
+ let [cachedOriginalMaterial, mrtMaterial] = this.cachedMaterials.get(c) || [];
1109
+ if (originalMaterial !== cachedOriginalMaterial) {
1110
+ if (mrtMaterial)
1111
+ mrtMaterial.dispose();
1112
+ mrtMaterial = new MRTMaterial();
1113
+ if (this.USE_MRT)
1114
+ mrtMaterial.defines.USE_MRT = "";
1115
+ mrtMaterial.normalScale = originalMaterial.normalScale;
1116
+ mrtMaterial.uniforms.normalScale.value = originalMaterial.normalScale;
1117
+ const map = originalMaterial.map || originalMaterial.normalMap || originalMaterial.roughnessMap || originalMaterial.metalnessMap;
1118
+ if (map)
1119
+ mrtMaterial.uniforms.uvTransform.value = map.matrix;
1120
+ this.cachedMaterials.set(c, [originalMaterial, mrtMaterial]);
1121
+ }
1122
+ this.keepMaterialMapUpdated(mrtMaterial, originalMaterial, "normalMap", "useNormalMap");
1123
+ this.keepMaterialMapUpdated(mrtMaterial, originalMaterial, "roughnessMap", "useRoughnessMap");
1124
+ mrtMaterial.uniforms.roughness.value = this.ssrEffect.selection.size === 0 || this.ssrEffect.selection.has(c) ? originalMaterial.roughness || 0 : 1e11;
1125
+ c.material = mrtMaterial;
1126
+ }
1127
+ }
1128
+ }
1129
+ unsetMRTMaterialInScene() {
1130
+ for (const c of this.visibleMeshes) {
1131
+ var _c$material;
1132
+ if (((_c$material = c.material) == null ? void 0 : _c$material.type) === "MRTMaterial") {
1133
+ c.visible = true;
1134
+ const [originalMaterial] = this.cachedMaterials.get(c);
1135
+ c.material = originalMaterial;
1136
+ }
1137
+ }
1138
+ }
1139
+ render(renderer, inputBuffer) {
1140
+ this.setMRTMaterialInScene();
1141
+ renderer.setRenderTarget(this.gBuffersRenderTarget);
1142
+ this.renderPass.render(renderer, this.gBuffersRenderTarget);
1143
+ this.unsetMRTMaterialInScene();
1144
+ if (!this.USE_MRT)
1145
+ this.webgl1DepthPass.renderPass.render(renderer, this.webgl1DepthPass.renderTarget);
1146
+ this.fullscreenMaterial.uniforms.inputTexture.value = inputBuffer.texture;
1147
+ this.fullscreenMaterial.uniforms.samples.value = this.ssrEffect.temporalResolvePass.samples;
1148
+ this.fullscreenMaterial.uniforms.cameraNear.value = this._camera.near;
1149
+ this.fullscreenMaterial.uniforms.cameraFar.value = this._camera.far;
1150
+ this.fullscreenMaterial.uniforms.viewMatrix.value.copy(this._camera.matrixWorldInverse);
1151
+ renderer.setRenderTarget(this.renderTarget);
1152
+ renderer.render(this.scene, this.camera);
1153
+ }
1154
+ }
1155
+ const defaultSSROptions = {
1156
+ intensity: 1,
1157
+ exponent: 1,
1158
+ distance: 10,
1159
+ fade: 0,
1160
+ roughnessFade: 1,
1161
+ thickness: 10,
1162
+ ior: 1.45,
1163
+ maxRoughness: 1,
1164
+ maxDepthDifference: 10,
1165
+ blend: 0.9,
1166
+ correction: 1,
1167
+ correctionRadius: 1,
1168
+ blur: 0.5,
1169
+ blurKernel: 1,
1170
+ blurSharpness: 10,
1171
+ jitter: 0,
1172
+ jitterRoughness: 0,
1173
+ steps: 20,
1174
+ refineSteps: 5,
1175
+ missedRays: true,
1176
+ useNormalMap: true,
1177
+ useRoughnessMap: true,
1178
+ resolutionScale: 1,
1179
+ velocityResolutionScale: 1
1180
+ };
1181
+ var vertexShader = "#define GLSLIFY 1\nvarying vec2 vUv;void main(){vUv=position.xy*0.5+0.5;gl_Position=vec4(position.xy,1.0,1.0);}";
1182
+ var temporalResolve = "#define GLSLIFY 1\nuniform sampler2D inputTexture;uniform sampler2D accumulatedTexture;uniform sampler2D velocityTexture;uniform sampler2D lastVelocityTexture;uniform float blend;uniform float correction;uniform float exponent;uniform float samples;uniform vec2 invTexSize;uniform mat4 curInverseProjectionMatrix;uniform mat4 curCameraMatrixWorld;uniform mat4 prevInverseProjectionMatrix;uniform mat4 prevCameraMatrixWorld;varying vec2 vUv;\n#define MAX_NEIGHBOR_DEPTH_DIFFERENCE 0.001\n#define FLOAT_EPSILON 0.00001\n#define FLOAT_ONE_MINUS_EPSILON 0.99999\nvec3 transformexponent;vec3 undoColorTransformExponent;vec3 transformColor(vec3 color){if(exponent==1.0)return color;return pow(abs(color),transformexponent);}vec3 undoColorTransform(vec3 color){if(exponent==1.0)return color;return max(pow(abs(color),undoColorTransformExponent),vec3(0.0));}void main(){if(exponent!=1.0){transformexponent=vec3(1.0/exponent);undoColorTransformExponent=vec3(exponent);}vec4 inputTexel=textureLod(inputTexture,vUv,0.0);vec4 accumulatedTexel;vec3 inputColor=transformColor(inputTexel.rgb);vec3 accumulatedColor;float alpha=inputTexel.a;float velocityDisocclusion;bool didReproject=false;\n#ifdef boxBlur\nvec3 boxBlurredColor=inputTexel.rgb;\n#endif\nvec4 velocity=textureLod(velocityTexture,vUv,0.0);bool isMoving=alpha<1.0||dot(velocity.xy,velocity.xy)>0.0;if(isMoving){vec3 minNeighborColor=inputColor;vec3 maxNeighborColor=inputColor;vec3 col;vec2 neighborUv;vec2 reprojectedUv=vUv-velocity.xy;vec4 lastVelocity=textureLod(lastVelocityTexture,reprojectedUv,0.0);float depth=velocity.b;float closestDepth=depth;float lastClosestDepth=lastVelocity.b;float neighborDepth;float lastNeighborDepth;for(int x=-correctionRadius;x<=correctionRadius;x++){for(int y=-correctionRadius;y<=correctionRadius;y++){if(x!=0||y!=0){neighborUv=vUv+vec2(x,y)*invTexSize;vec4 neigborVelocity=textureLod(velocityTexture,neighborUv,0.0);neighborDepth=neigborVelocity.b;col=textureLod(inputTexture,neighborUv,0.0).xyz;int absX=abs(x);int absY=abs(y);\n#ifdef dilation\nif(absX==1&&absY==1){if(neighborDepth>closestDepth){velocity=neigborVelocity;closestDepth=neighborDepth;}vec4 lastNeighborVelocity=textureLod(velocityTexture,vUv+vec2(x,y)*invTexSize,0.0);lastNeighborDepth=lastNeighborVelocity.b;if(neighborDepth>closestDepth){lastVelocity=lastNeighborVelocity;lastClosestDepth=lastNeighborDepth;}}\n#endif\nif(abs(depth-neighborDepth)<MAX_NEIGHBOR_DEPTH_DIFFERENCE){\n#ifdef boxBlur\nif(absX<=2&&absY<=2)boxBlurredColor+=col;\n#endif\ncol=transformColor(col);minNeighborColor=min(col,minNeighborColor);maxNeighborColor=max(col,maxNeighborColor);}}}}float velocityLength=length(lastVelocity.xy-velocity.xy);velocityDisocclusion=(velocityLength-0.000005)*10.0;velocityDisocclusion*=velocityDisocclusion;reprojectedUv=vUv-velocity.xy;\n#ifdef boxBlur\nfloat pxRadius=correctionRadius>5 ? 121.0 : pow(float(correctionRadius*2+1),2.0);boxBlurredColor/=pxRadius;boxBlurredColor=transformColor(boxBlurredColor);\n#endif\nif(reprojectedUv.x>=0.0&&reprojectedUv.x<=1.0&&reprojectedUv.y>=0.0&&reprojectedUv.y<=1.0){accumulatedTexel=textureLod(accumulatedTexture,reprojectedUv,0.0);accumulatedColor=transformColor(accumulatedTexel.rgb);vec3 clampedColor=clamp(accumulatedColor,minNeighborColor,maxNeighborColor);accumulatedColor=mix(accumulatedColor,clampedColor,correction);didReproject=true;}else{\n#ifdef boxBlur\naccumulatedColor=boxBlurredColor;\n#else\naccumulatedColor=inputColor;\n#endif\n}if(velocity.r>FLOAT_ONE_MINUS_EPSILON&&velocity.g>FLOAT_ONE_MINUS_EPSILON){alpha=0.0;velocityDisocclusion=1.0;}}else{accumulatedColor=transformColor(textureLod(accumulatedTexture,vUv,0.0).rgb);}vec3 outputColor=inputColor;\n#include <custom_compose_shader>\ngl_FragColor=vec4(undoColorTransform(outputColor),alpha);}";
1183
+ class TemporalResolveMaterial extends THREE.ShaderMaterial {
1184
+ constructor(customComposeShader) {
1185
+ const fragmentShader2 = temporalResolve.replace("#include <custom_compose_shader>", customComposeShader);
1186
+ super({
1187
+ type: "TemporalResolveMaterial",
1188
+ uniforms: {
1189
+ inputTexture: new THREE.Uniform(null),
1190
+ accumulatedTexture: new THREE.Uniform(null),
1191
+ velocityTexture: new THREE.Uniform(null),
1192
+ lastVelocityTexture: new THREE.Uniform(null),
1193
+ samples: new THREE.Uniform(1),
1194
+ blend: new THREE.Uniform(0.5),
1195
+ correction: new THREE.Uniform(1),
1196
+ exponent: new THREE.Uniform(1),
1197
+ invTexSize: new THREE.Uniform(new THREE.Vector2())
1198
+ },
1199
+ defines: {
1200
+ correctionRadius: 1
1201
+ },
1202
+ vertexShader,
1203
+ fragmentShader: fragmentShader2
1204
+ });
1205
+ }
1206
+ }
1207
+ const prev_skinning_pars_vertex = (
1208
+ /* glsl */
1209
+ `
1210
+ #ifdef USE_SKINNING
1211
+ #ifdef BONE_TEXTURE
1212
+ uniform sampler2D prevBoneTexture;
1213
+ mat4 getPrevBoneMatrix( const in float i ) {
1214
+ float j = i * 4.0;
1215
+ float x = mod( j, float( boneTextureSize ) );
1216
+ float y = floor( j / float( boneTextureSize ) );
1217
+ float dx = 1.0 / float( boneTextureSize );
1218
+ float dy = 1.0 / float( boneTextureSize );
1219
+ y = dy * ( y + 0.5 );
1220
+ vec4 v1 = texture2D( prevBoneTexture, vec2( dx * ( x + 0.5 ), y ) );
1221
+ vec4 v2 = texture2D( prevBoneTexture, vec2( dx * ( x + 1.5 ), y ) );
1222
+ vec4 v3 = texture2D( prevBoneTexture, vec2( dx * ( x + 2.5 ), y ) );
1223
+ vec4 v4 = texture2D( prevBoneTexture, vec2( dx * ( x + 3.5 ), y ) );
1224
+ mat4 bone = mat4( v1, v2, v3, v4 );
1225
+ return bone;
1226
+ }
1227
+ #else
1228
+ uniform mat4 prevBoneMatrices[ MAX_BONES ];
1229
+ mat4 getPrevBoneMatrix( const in float i ) {
1230
+ mat4 bone = prevBoneMatrices[ int(i) ];
1231
+ return bone;
1232
+ }
1233
+ #endif
1234
+ #endif
1235
+ `
1236
+ );
1237
+ const velocity_vertex = (
1238
+ /* glsl */
1239
+ `
1240
+ vec3 transformed;
1241
+
1242
+ // Get the normal
1243
+ ${THREE.ShaderChunk.skinbase_vertex}
1244
+ ${THREE.ShaderChunk.beginnormal_vertex}
1245
+ ${THREE.ShaderChunk.skinnormal_vertex}
1246
+ ${THREE.ShaderChunk.defaultnormal_vertex}
1247
+
1248
+ // Get the current vertex position
1249
+ transformed = vec3( position );
1250
+ ${THREE.ShaderChunk.skinning_vertex}
1251
+ newPosition = velocityMatrix * vec4( transformed, 1.0 );
1252
+
1253
+ // Get the previous vertex position
1254
+ transformed = vec3( position );
1255
+ ${THREE.ShaderChunk.skinbase_vertex.replace(/mat4 /g, "").replace(/getBoneMatrix/g, "getPrevBoneMatrix")}
1256
+ ${THREE.ShaderChunk.skinning_vertex.replace(/vec4 /g, "")}
1257
+ prevPosition = prevVelocityMatrix * vec4( transformed, 1.0 );
1258
+
1259
+ gl_Position = newPosition;
1260
+ `
1261
+ );
1262
+ class VelocityMaterial extends THREE.ShaderMaterial {
1263
+ constructor() {
1264
+ super({
1265
+ uniforms: {
1266
+ prevVelocityMatrix: {
1267
+ value: new THREE.Matrix4()
1268
+ },
1269
+ velocityMatrix: {
1270
+ value: new THREE.Matrix4()
1271
+ },
1272
+ prevBoneTexture: {
1273
+ value: null
1274
+ },
1275
+ interpolateGeometry: {
1276
+ value: 0
1277
+ },
1278
+ intensity: {
1279
+ value: 1
1280
+ },
1281
+ boneTexture: {
1282
+ value: null
1283
+ },
1284
+ alphaTest: {
1285
+ value: 0
1286
+ },
1287
+ map: {
1288
+ value: null
1289
+ },
1290
+ alphaMap: {
1291
+ value: null
1292
+ },
1293
+ opacity: {
1294
+ value: 1
1295
+ }
1296
+ },
1297
+ vertexShader: (
1298
+ /* glsl */
1299
+ `
1300
+ #define MAX_BONES 1024
1301
+
1302
+ ${THREE.ShaderChunk.skinning_pars_vertex}
1303
+ ${prev_skinning_pars_vertex}
1304
+
1305
+ uniform mat4 velocityMatrix;
1306
+ uniform mat4 prevVelocityMatrix;
1307
+ uniform float interpolateGeometry;
1308
+ varying vec4 prevPosition;
1309
+ varying vec4 newPosition;
1310
+ varying vec2 vHighPrecisionZW;
1311
+
1312
+ void main() {
1313
+
1314
+ ${velocity_vertex}
1315
+
1316
+ vHighPrecisionZW = gl_Position.zw;
1317
+
1318
+ }`
1319
+ ),
1320
+ fragmentShader: (
1321
+ /* glsl */
1322
+ `
1323
+ uniform float intensity;
1324
+ varying vec4 prevPosition;
1325
+ varying vec4 newPosition;
1326
+ varying vec2 vHighPrecisionZW;
1327
+
1328
+ void main() {
1329
+ #ifdef FULL_MOVEMENT
1330
+ gl_FragColor = vec4( 1., 1., 1. - gl_FragCoord.z, 0. );
1331
+ return;
1332
+ #endif
1333
+
1334
+ vec2 pos0 = (prevPosition.xy / prevPosition.w) * 0.5 + 0.5;
1335
+ vec2 pos1 = (newPosition.xy / newPosition.w) * 0.5 + 0.5;
1336
+
1337
+ vec2 vel = pos1 - pos0;
1338
+
1339
+ float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
1340
+
1341
+ gl_FragColor = vec4( vel, 1. - fragCoordZ, 0. );
1342
+
1343
+ }`
1344
+ )
1345
+ });
1346
+ this.isVelocityMaterial = true;
1347
+ }
1348
+ }
1349
+ const backgroundColor = new THREE.Color(0);
1350
+ const updateProperties = ["visible", "wireframe", "side"];
1351
+ class VelocityPass extends postprocessing.Pass {
1352
+ constructor(scene, camera) {
1353
+ var _window, _window2;
1354
+ super("VelocityPass");
1355
+ this.cachedMaterials = /* @__PURE__ */ new WeakMap();
1356
+ this.lastCameraTransform = {
1357
+ position: new THREE.Vector3(),
1358
+ quaternion: new THREE.Quaternion()
1359
+ };
1360
+ this.visibleMeshes = [];
1361
+ this.renderedMeshesThisFrame = 0;
1362
+ this.renderedMeshesLastFrame = 0;
1363
+ this._scene = scene;
1364
+ this._camera = camera;
1365
+ this.renderTarget = new THREE.WebGLRenderTarget(
1366
+ ((_window = window) == null ? void 0 : _window.innerWidth) || 1e3,
1367
+ ((_window2 = window) == null ? void 0 : _window2.innerHeight) || 1e3,
1368
+ {
1369
+ type: THREE.HalfFloatType
1370
+ }
1371
+ );
1372
+ }
1373
+ setVelocityMaterialInScene() {
1374
+ this.renderedMeshesThisFrame = 0;
1375
+ this.visibleMeshes = getVisibleChildren(this._scene);
1376
+ for (const c of this.visibleMeshes) {
1377
+ var _c$skeleton2;
1378
+ const originalMaterial = c.material;
1379
+ let [cachedOriginalMaterial, velocityMaterial] = this.cachedMaterials.get(c) || [];
1380
+ if (originalMaterial !== cachedOriginalMaterial) {
1381
+ var _c$skeleton;
1382
+ velocityMaterial = new VelocityMaterial();
1383
+ velocityMaterial.lastMatrixWorld = new THREE.Matrix4();
1384
+ c.material = velocityMaterial;
1385
+ if ((_c$skeleton = c.skeleton) != null && _c$skeleton.boneTexture)
1386
+ this.saveBoneTexture(c);
1387
+ this.cachedMaterials.set(c, [originalMaterial, velocityMaterial]);
1388
+ }
1389
+ velocityMaterial.uniforms.velocityMatrix.value.multiplyMatrices(this._camera.projectionMatrix, c.modelViewMatrix);
1390
+ if (c.userData.needsUpdatedReflections || originalMaterial.map instanceof THREE.VideoTexture) {
1391
+ if (!("FULL_MOVEMENT" in velocityMaterial.defines))
1392
+ velocityMaterial.needsUpdate = true;
1393
+ velocityMaterial.defines.FULL_MOVEMENT = "";
1394
+ } else {
1395
+ if ("FULL_MOVEMENT" in velocityMaterial.defines) {
1396
+ delete velocityMaterial.defines.FULL_MOVEMENT;
1397
+ velocityMaterial.needsUpdate = true;
1398
+ }
1399
+ }
1400
+ c.visible = this.cameraMovedThisFrame || !c.matrixWorld.equals(velocityMaterial.lastMatrixWorld) || c.skeleton || "FULL_MOVEMENT" in velocityMaterial.defines;
1401
+ c.material = velocityMaterial;
1402
+ if (!c.visible)
1403
+ continue;
1404
+ this.renderedMeshesThisFrame++;
1405
+ for (const prop of updateProperties)
1406
+ velocityMaterial[prop] = originalMaterial[prop];
1407
+ if ((_c$skeleton2 = c.skeleton) != null && _c$skeleton2.boneTexture) {
1408
+ velocityMaterial.defines.USE_SKINNING = "";
1409
+ velocityMaterial.defines.BONE_TEXTURE = "";
1410
+ velocityMaterial.uniforms.boneTexture.value = c.skeleton.boneTexture;
1411
+ }
1412
+ }
1413
+ }
1414
+ saveBoneTexture(object) {
1415
+ let boneTexture = object.material.uniforms.prevBoneTexture.value;
1416
+ if (boneTexture && boneTexture.image.width === object.skeleton.boneTexture.width) {
1417
+ boneTexture = object.material.uniforms.prevBoneTexture.value;
1418
+ boneTexture.image.data.set(object.skeleton.boneTexture.image.data);
1419
+ } else {
1420
+ var _boneTexture;
1421
+ (_boneTexture = boneTexture) == null ? void 0 : _boneTexture.dispose();
1422
+ const boneMatrices = object.skeleton.boneTexture.image.data.slice();
1423
+ const size = object.skeleton.boneTexture.image.width;
1424
+ boneTexture = new THREE.DataTexture(boneMatrices, size, size, THREE.RGBAFormat, THREE.FloatType);
1425
+ object.material.uniforms.prevBoneTexture.value = boneTexture;
1426
+ boneTexture.needsUpdate = true;
1427
+ }
1428
+ }
1429
+ unsetVelocityMaterialInScene() {
1430
+ for (const c of this.visibleMeshes) {
1431
+ if (c.material.isVelocityMaterial) {
1432
+ var _c$skeleton3;
1433
+ c.visible = true;
1434
+ c.material.lastMatrixWorld.copy(c.matrixWorld);
1435
+ c.material.uniforms.prevVelocityMatrix.value.multiplyMatrices(this._camera.projectionMatrix, c.modelViewMatrix);
1436
+ if ((_c$skeleton3 = c.skeleton) != null && _c$skeleton3.boneTexture)
1437
+ this.saveBoneTexture(c);
1438
+ c.material = this.cachedMaterials.get(c)[0];
1439
+ }
1440
+ }
1441
+ }
1442
+ setSize(width, height) {
1443
+ this.renderTarget.setSize(width, height);
1444
+ }
1445
+ renderVelocity(renderer) {
1446
+ renderer.setRenderTarget(this.renderTarget);
1447
+ if (this.renderedMeshesThisFrame > 0) {
1448
+ const { background } = this._scene;
1449
+ this._scene.background = backgroundColor;
1450
+ renderer.render(this._scene, this._camera);
1451
+ this._scene.background = background;
1452
+ } else {
1453
+ renderer.clearColor();
1454
+ }
1455
+ }
1456
+ checkCameraMoved() {
1457
+ const moveDist = this.lastCameraTransform.position.distanceToSquared(this._camera.position);
1458
+ const rotateDist = 8 * (1 - this.lastCameraTransform.quaternion.dot(this._camera.quaternion));
1459
+ if (moveDist > 1e-6 || rotateDist > 1e-6) {
1460
+ this.lastCameraTransform.position.copy(this._camera.position);
1461
+ this.lastCameraTransform.quaternion.copy(this._camera.quaternion);
1462
+ return true;
1463
+ }
1464
+ return false;
1465
+ }
1466
+ render(renderer) {
1467
+ this.cameraMovedThisFrame = this.checkCameraMoved();
1468
+ this.setVelocityMaterialInScene();
1469
+ if (this.renderedMeshesThisFrame > 0 || this.renderedMeshesLastFrame > 0)
1470
+ this.renderVelocity(renderer);
1471
+ this.unsetVelocityMaterialInScene();
1472
+ this.renderedMeshesLastFrame = this.renderedMeshesThisFrame;
1473
+ }
1474
+ }
1475
+ const zeroVec2 = new THREE.Vector2();
1476
+ class TemporalResolvePass extends postprocessing.Pass {
1477
+ constructor(scene, camera, customComposeShader, options = {}) {
1478
+ super("TemporalResolvePass");
1479
+ this.velocityPass = null;
1480
+ this.velocityResolutionScale = 1;
1481
+ this.samples = 1;
1482
+ this.lastCameraTransform = {
1483
+ position: new THREE.Vector3(),
1484
+ quaternion: new THREE.Quaternion()
1485
+ };
1486
+ this._scene = scene;
1487
+ this._camera = camera;
1488
+ this.renderTarget = new THREE.WebGLRenderTarget(1, 1, {
1489
+ minFilter: THREE.LinearFilter,
1490
+ magFilter: THREE.LinearFilter,
1491
+ type: THREE.HalfFloatType,
1492
+ depthBuffer: false
1493
+ });
1494
+ this.velocityPass = new VelocityPass(scene, camera);
1495
+ this.fullscreenMaterial = new TemporalResolveMaterial(customComposeShader);
1496
+ this.fullscreenMaterial.defines.correctionRadius = options.correctionRadius || 1;
1497
+ if (options.dilation)
1498
+ this.fullscreenMaterial.defines.dilation = "";
1499
+ if (options.boxBlur)
1500
+ this.fullscreenMaterial.defines.boxBlur = "";
1501
+ this.setupFramebuffers(1, 1);
1502
+ this.checkCanUseSharedVelocityTexture();
1503
+ }
1504
+ dispose() {
1505
+ if (this._scene.userData.velocityTexture === this.velocityPass.renderTarget.texture) {
1506
+ delete this._scene.userData.velocityTexture;
1507
+ delete this._scene.userData.lastVelocityTexture;
1508
+ }
1509
+ this.renderTarget.dispose();
1510
+ this.accumulatedTexture.dispose();
1511
+ this.fullscreenMaterial.dispose();
1512
+ this.velocityPass.dispose();
1513
+ }
1514
+ setSize(width, height) {
1515
+ this.renderTarget.setSize(width, height);
1516
+ this.velocityPass.setSize(width * this.velocityResolutionScale, height * this.velocityResolutionScale);
1517
+ this.velocityPass.renderTarget.texture.minFilter = this.velocityResolutionScale === 1 ? THREE.NearestFilter : THREE.LinearFilter;
1518
+ this.velocityPass.renderTarget.texture.magFilter = this.velocityResolutionScale === 1 ? THREE.NearestFilter : THREE.LinearFilter;
1519
+ this.velocityPass.renderTarget.texture.needsUpdate = true;
1520
+ this.fullscreenMaterial.uniforms.invTexSize.value.set(1 / width, 1 / height);
1521
+ this.setupFramebuffers(width, height);
1522
+ }
1523
+ setupFramebuffers(width, height) {
1524
+ if (this.accumulatedTexture)
1525
+ this.accumulatedTexture.dispose();
1526
+ if (this.lastVelocityTexture)
1527
+ this.lastVelocityTexture.dispose();
1528
+ this.accumulatedTexture = new THREE.FramebufferTexture(width, height, THREE.RGBAFormat);
1529
+ this.accumulatedTexture.minFilter = THREE.LinearFilter;
1530
+ this.accumulatedTexture.magFilter = THREE.LinearFilter;
1531
+ this.accumulatedTexture.type = THREE.HalfFloatType;
1532
+ this.lastVelocityTexture = new THREE.FramebufferTexture(
1533
+ width * this.velocityResolutionScale,
1534
+ height * this.velocityResolutionScale,
1535
+ THREE.RGBAFormat
1536
+ );
1537
+ this.lastVelocityTexture.minFilter = this.velocityResolutionScale === 1 ? THREE.NearestFilter : THREE.LinearFilter;
1538
+ this.lastVelocityTexture.magFilter = this.velocityResolutionScale === 1 ? THREE.NearestFilter : THREE.LinearFilter;
1539
+ this.lastVelocityTexture.type = THREE.HalfFloatType;
1540
+ this.fullscreenMaterial.uniforms.accumulatedTexture.value = this.accumulatedTexture;
1541
+ this.fullscreenMaterial.uniforms.lastVelocityTexture.value = this.lastVelocityTexture;
1542
+ this.fullscreenMaterial.needsUpdate = true;
1543
+ }
1544
+ checkCanUseSharedVelocityTexture() {
1545
+ const canUseSharedVelocityTexture = this._scene.userData.velocityTexture && this.velocityPass.renderTarget.texture !== this._scene.userData.velocityTexture;
1546
+ if (canUseSharedVelocityTexture) {
1547
+ if (this.velocityPass.renderTarget.texture === this.fullscreenMaterial.uniforms.velocityTexture.value) {
1548
+ this.fullscreenMaterial.uniforms.lastVelocityTexture.value = this._scene.userData.lastVelocityTexture;
1549
+ this.fullscreenMaterial.uniforms.velocityTexture.value = this._scene.userData.velocityTexture;
1550
+ this.fullscreenMaterial.needsUpdate = true;
1551
+ }
1552
+ } else {
1553
+ if (this.velocityPass.renderTarget.texture !== this.fullscreenMaterial.uniforms.velocityTexture.value) {
1554
+ this.fullscreenMaterial.uniforms.velocityTexture.value = this.velocityPass.renderTarget.texture;
1555
+ this.fullscreenMaterial.uniforms.lastVelocityTexture.value = this.lastVelocityTexture;
1556
+ this.fullscreenMaterial.needsUpdate = true;
1557
+ if (!this._scene.userData.velocityTexture) {
1558
+ this._scene.userData.velocityTexture = this.velocityPass.renderTarget.texture;
1559
+ this._scene.userData.lastVelocityTexture = this.lastVelocityTexture;
1560
+ }
1561
+ }
1562
+ }
1563
+ return this.velocityPass.renderTarget.texture !== this.fullscreenMaterial.uniforms.velocityTexture.value;
1564
+ }
1565
+ checkNeedsResample() {
1566
+ const moveDist = this.lastCameraTransform.position.distanceToSquared(this._camera.position);
1567
+ const rotateDist = 8 * (1 - this.lastCameraTransform.quaternion.dot(this._camera.quaternion));
1568
+ if (moveDist > 1e-6 || rotateDist > 1e-6) {
1569
+ this.samples = 1;
1570
+ this.lastCameraTransform.position.copy(this._camera.position);
1571
+ this.lastCameraTransform.quaternion.copy(this._camera.quaternion);
1572
+ }
1573
+ }
1574
+ render(renderer) {
1575
+ this.samples++;
1576
+ this.checkNeedsResample();
1577
+ this.fullscreenMaterial.uniforms.samples.value = this.samples;
1578
+ renderer.setRenderTarget(this.renderTarget);
1579
+ renderer.render(this.scene, this.camera);
1580
+ renderer.copyFramebufferToTexture(zeroVec2, this.accumulatedTexture);
1581
+ renderer.setRenderTarget(this.velocityPass.renderTarget);
1582
+ renderer.copyFramebufferToTexture(zeroVec2, this.lastVelocityTexture);
1583
+ }
1584
+ }
1585
+ const halton = function halton2(index, base) {
1586
+ let fraction = 1;
1587
+ let result = 0;
1588
+ while (index > 0) {
1589
+ fraction /= base;
1590
+ result += fraction * (index % base);
1591
+ index = ~~(index / base);
1592
+ }
1593
+ return result;
1594
+ };
1595
+ const generateHalton23Points = (count) => {
1596
+ const data = [];
1597
+ let i2 = 1;
1598
+ const end = i2 + count;
1599
+ for (; i2 < end; i2++) {
1600
+ data.push([halton(i2, 2) - 0.5, halton(i2, 3) - 0.5]);
1601
+ }
1602
+ return data;
1603
+ };
1604
+ function escapeRegExp(string) {
1605
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1606
+ }
1607
+ const worldposReplace = (
1608
+ /* glsl */
1609
+ `
1610
+ #if defined( USE_ENVMAP ) || defined( ) || defined ( USE_SHADOWMAP )
1611
+ vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );
1612
+
1613
+ #ifdef BOX_PROJECTED_ENV_MAP
1614
+ vWorldPosition = worldPosition.xyz;
1615
+ #endif
1616
+ #endif
1617
+ `
1618
+ );
1619
+ const boxProjectDefinitions = (
1620
+ /* glsl */
1621
+ `
1622
+ #ifdef BOX_PROJECTED_ENV_MAP
1623
+ uniform vec3 envMapSize;
1624
+ uniform vec3 envMapPosition;
1625
+ varying vec3 vWorldPosition;
1626
+
1627
+ vec3 parallaxCorrectNormal( vec3 v, vec3 cubeSize, vec3 cubePos ) {
1628
+ vec3 nDir = normalize( v );
1629
+
1630
+ vec3 rbmax = ( .5 * cubeSize + cubePos - vWorldPosition ) / nDir;
1631
+ vec3 rbmin = ( -.5 * cubeSize + cubePos - vWorldPosition ) / nDir;
1632
+
1633
+ vec3 rbminmax;
1634
+
1635
+ rbminmax.x = ( nDir.x > 0. ) ? rbmax.x : rbmin.x;
1636
+ rbminmax.y = ( nDir.y > 0. ) ? rbmax.y : rbmin.y;
1637
+ rbminmax.z = ( nDir.z > 0. ) ? rbmax.z : rbmin.z;
1638
+
1639
+ float correction = min( min( rbminmax.x, rbminmax.y ), rbminmax.z );
1640
+ vec3 boxIntersection = vWorldPosition + nDir * correction;
1641
+
1642
+ return boxIntersection - cubePos;
1643
+ }
1644
+ #endif
1645
+ `
1646
+ );
1647
+ const getIBLIrradiance_patch = (
1648
+ /* glsl */
1649
+ `
1650
+ #ifdef BOX_PROJECTED_ENV_MAP
1651
+ worldNormal = parallaxCorrectNormal( worldNormal, envMapSize, envMapPosition );
1652
+ #endif
1653
+ `
1654
+ );
1655
+ const getIBLRadiance_patch = (
1656
+ /* glsl */
1657
+ `
1658
+ #ifdef BOX_PROJECTED_ENV_MAP
1659
+ reflectVec = parallaxCorrectNormal( reflectVec, envMapSize, envMapPosition );
1660
+ #endif
1661
+ `
1662
+ );
1663
+ function useBoxProjectedEnvMap(shader, envMapPosition, envMapSize) {
1664
+ shader.defines.BOX_PROJECTED_ENV_MAP = "";
1665
+ shader.uniforms.envMapPosition = {
1666
+ value: envMapPosition
1667
+ };
1668
+ shader.uniforms.envMapSize = {
1669
+ value: envMapSize
1670
+ };
1671
+ const line1 = new RegExp(
1672
+ escapeRegExp("vec3 worldNormal = inverseTransformDirection ( normal , viewMatrix ) ;").replaceAll(" ", "\\s*"),
1673
+ "g"
1674
+ );
1675
+ const line2 = new RegExp(
1676
+ escapeRegExp("reflectVec = inverseTransformDirection ( reflectVec , viewMatrix ) ;").replaceAll(" ", "\\s*"),
1677
+ "g"
1678
+ );
1679
+ shader.vertexShader = "varying vec3 vWorldPosition;\n" + shader.vertexShader.replace("#include <worldpos_vertex>", worldposReplace);
1680
+ shader.fragmentShader = boxProjectDefinitions + "\n" + shader.fragmentShader.replace("#include <envmap_physical_pars_fragment>", THREE.ShaderChunk.envmap_physical_pars_fragment).replace(
1681
+ line1,
1682
+ `vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
1683
+ ${getIBLIrradiance_patch}`
1684
+ ).replace(
1685
+ line2,
1686
+ `reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
1687
+ ${getIBLRadiance_patch}`
1688
+ );
1689
+ }
1690
+ const finalFragmentShader = finalSSRShader.replace("#include <helperFunctions>", helperFunctions).replace("#include <boxBlur>", boxBlur);
1691
+ const noResetSamplesProperties = ["blur", "blurSharpness", "blurKernel"];
1692
+ const defaultCubeRenderTarget = new THREE.WebGLCubeRenderTarget(1);
1693
+ let pmremGenerator;
1694
+ class SSREffect extends postprocessing.Effect {
1695
+ /**
1696
+ * @param {THREE.Scene} scene The scene of the SSR effect
1697
+ * @param {THREE.Camera} camera The camera with which SSR is being rendered
1698
+ * @param {SSROptions} [options] The optional options for the SSR effect
1699
+ */
1700
+ constructor(scene, camera, options = defaultSSROptions) {
1701
+ super("SSREffect", finalFragmentShader, {
1702
+ type: "FinalSSRMaterial",
1703
+ uniforms: /* @__PURE__ */ new Map([
1704
+ ["reflectionsTexture", new THREE.Uniform(null)],
1705
+ ["blur", new THREE.Uniform(0)],
1706
+ ["blurSharpness", new THREE.Uniform(0)],
1707
+ ["blurKernel", new THREE.Uniform(0)]
1708
+ ]),
1709
+ defines: /* @__PURE__ */ new Map([["RENDER_MODE", "0"]])
1710
+ });
1711
+ this.haltonSequence = generateHalton23Points(1024);
1712
+ this.haltonIndex = 0;
1713
+ this.selection = new postprocessing.Selection();
1714
+ this.lastSize = void 0;
1715
+ this.cubeCamera = new THREE.CubeCamera(1e-3, 1e3, defaultCubeRenderTarget);
1716
+ this.usingBoxProjectedEnvMap = false;
1717
+ this._scene = scene;
1718
+ this._camera = camera;
1719
+ const trOptions = {
1720
+ boxBlur: true,
1721
+ dilation: true
1722
+ };
1723
+ options = { ...defaultSSROptions, ...options, ...trOptions };
1724
+ this.temporalResolvePass = new TemporalResolvePass(scene, camera, trCompose, options);
1725
+ this.uniforms.get("reflectionsTexture").value = this.temporalResolvePass.renderTarget.texture;
1726
+ this.reflectionsPass = new ReflectionsPass(this, options);
1727
+ this.temporalResolvePass.fullscreenMaterial.uniforms.inputTexture.value = this.reflectionsPass.renderTarget.texture;
1728
+ this.lastSize = {
1729
+ width: options.width,
1730
+ height: options.height,
1731
+ resolutionScale: options.resolutionScale,
1732
+ velocityResolutionScale: options.velocityResolutionScale
1733
+ };
1734
+ this.setSize(options.width, options.height);
1735
+ this.makeOptionsReactive(options);
1736
+ }
1737
+ makeOptionsReactive(options) {
1738
+ let needsUpdate = false;
1739
+ const reflectionPassFullscreenMaterialUniforms = this.reflectionsPass.fullscreenMaterial.uniforms;
1740
+ const reflectionPassFullscreenMaterialUniformsKeys = Object.keys(reflectionPassFullscreenMaterialUniforms);
1741
+ for (const key of Object.keys(options)) {
1742
+ Object.defineProperty(this, key, {
1743
+ get() {
1744
+ return options[key];
1745
+ },
1746
+ set(value) {
1747
+ if (options[key] === value && needsUpdate)
1748
+ return;
1749
+ options[key] = value;
1750
+ if (!noResetSamplesProperties.includes(key)) {
1751
+ this.setSize(this.lastSize.width, this.lastSize.height, true);
1752
+ }
1753
+ switch (key) {
1754
+ case "resolutionScale":
1755
+ this.setSize(this.lastSize.width, this.lastSize.height);
1756
+ break;
1757
+ case "velocityResolutionScale":
1758
+ this.temporalResolvePass.velocityResolutionScale = value;
1759
+ this.setSize(this.lastSize.width, this.lastSize.height, true);
1760
+ break;
1761
+ case "blur":
1762
+ this.uniforms.get("blur").value = value;
1763
+ break;
1764
+ case "blurSharpness":
1765
+ this.uniforms.get("blurSharpness").value = value;
1766
+ break;
1767
+ case "blurKernel":
1768
+ this.uniforms.get("blurKernel").value = value;
1769
+ break;
1770
+ case "steps":
1771
+ this.reflectionsPass.fullscreenMaterial.defines.steps = parseInt(value);
1772
+ this.reflectionsPass.fullscreenMaterial.needsUpdate = needsUpdate;
1773
+ break;
1774
+ case "refineSteps":
1775
+ this.reflectionsPass.fullscreenMaterial.defines.refineSteps = parseInt(value);
1776
+ this.reflectionsPass.fullscreenMaterial.needsUpdate = needsUpdate;
1777
+ break;
1778
+ case "missedRays":
1779
+ if (value) {
1780
+ this.reflectionsPass.fullscreenMaterial.defines.missedRays = "";
1781
+ } else {
1782
+ delete this.reflectionsPass.fullscreenMaterial.defines.missedRays;
1783
+ }
1784
+ this.reflectionsPass.fullscreenMaterial.needsUpdate = needsUpdate;
1785
+ break;
1786
+ case "correctionRadius":
1787
+ this.temporalResolvePass.fullscreenMaterial.defines.correctionRadius = Math.round(value);
1788
+ this.temporalResolvePass.fullscreenMaterial.needsUpdate = needsUpdate;
1789
+ break;
1790
+ case "blend":
1791
+ this.temporalResolvePass.fullscreenMaterial.uniforms.blend.value = value;
1792
+ break;
1793
+ case "correction":
1794
+ this.temporalResolvePass.fullscreenMaterial.uniforms.correction.value = value;
1795
+ break;
1796
+ case "exponent":
1797
+ this.temporalResolvePass.fullscreenMaterial.uniforms.exponent.value = value;
1798
+ break;
1799
+ case "distance":
1800
+ reflectionPassFullscreenMaterialUniforms.rayDistance.value = value;
1801
+ default:
1802
+ if (reflectionPassFullscreenMaterialUniformsKeys.includes(key)) {
1803
+ reflectionPassFullscreenMaterialUniforms[key].value = value;
1804
+ }
1805
+ }
1806
+ }
1807
+ });
1808
+ this[key] = options[key];
1809
+ }
1810
+ needsUpdate = true;
1811
+ }
1812
+ setSize(width, height, force = false) {
1813
+ if (!force && width === this.lastSize.width && height === this.lastSize.height && this.resolutionScale === this.lastSize.resolutionScale && this.velocityResolutionScale === this.lastSize.velocityResolutionScale)
1814
+ return;
1815
+ this.temporalResolvePass.setSize(width, height);
1816
+ this.reflectionsPass.setSize(width, height);
1817
+ this.lastSize = {
1818
+ width,
1819
+ height,
1820
+ resolutionScale: this.resolutionScale,
1821
+ velocityResolutionScale: this.velocityResolutionScale
1822
+ };
1823
+ }
1824
+ generateBoxProjectedEnvMapFallback(renderer, position = new THREE.Vector3(), size = new THREE.Vector3(), envMapSize = 512) {
1825
+ this.cubeCamera.renderTarget.dispose();
1826
+ this.cubeCamera.renderTarget = new THREE.WebGLCubeRenderTarget(envMapSize);
1827
+ this.cubeCamera.position.copy(position);
1828
+ this.cubeCamera.updateMatrixWorld();
1829
+ this.cubeCamera.update(renderer, this._scene);
1830
+ if (!pmremGenerator) {
1831
+ pmremGenerator = new THREE.PMREMGenerator(renderer);
1832
+ pmremGenerator.compileCubemapShader();
1833
+ }
1834
+ const envMap = pmremGenerator.fromCubemap(this.cubeCamera.renderTarget.texture).texture;
1835
+ envMap.minFilter = THREE.LinearFilter;
1836
+ envMap.magFilter = THREE.LinearFilter;
1837
+ const reflectionsMaterial = this.reflectionsPass.fullscreenMaterial;
1838
+ useBoxProjectedEnvMap(reflectionsMaterial, position, size);
1839
+ reflectionsMaterial.fragmentShader = reflectionsMaterial.fragmentShader.replace("vec3 worldPos", "worldPos").replace("varying vec3 vWorldPosition;", "vec3 worldPos;");
1840
+ reflectionsMaterial.uniforms.envMapPosition.value.copy(position);
1841
+ reflectionsMaterial.uniforms.envMapSize.value.copy(size);
1842
+ setupEnvMap(reflectionsMaterial, envMap, envMapSize);
1843
+ this.usingBoxProjectedEnvMap = true;
1844
+ return envMap;
1845
+ }
1846
+ setIBLRadiance(iblRadiance, renderer) {
1847
+ this._scene.traverse((c) => {
1848
+ if (c.material) {
1849
+ var _renderer$properties$;
1850
+ const uniforms = (_renderer$properties$ = renderer.properties.get(c.material)) == null ? void 0 : _renderer$properties$.uniforms;
1851
+ if (uniforms && "disableIBLRadiance" in uniforms) {
1852
+ uniforms.disableIBLRadiance.value = iblRadiance;
1853
+ }
1854
+ }
1855
+ });
1856
+ }
1857
+ deleteBoxProjectedEnvMapFallback() {
1858
+ const reflectionsMaterial = this.reflectionsPass.fullscreenMaterial;
1859
+ reflectionsMaterial.uniforms.envMap.value = null;
1860
+ reflectionsMaterial.fragmentShader = reflectionsMaterial.fragmentShader.replace("worldPos = ", "vec3 worldPos = ");
1861
+ delete reflectionsMaterial.defines.BOX_PROJECTED_ENV_MAP;
1862
+ reflectionsMaterial.needsUpdate = true;
1863
+ this.usingBoxProjectedEnvMap = false;
1864
+ }
1865
+ dispose() {
1866
+ super.dispose();
1867
+ this.reflectionsPass.dispose();
1868
+ this.temporalResolvePass.dispose();
1869
+ }
1870
+ update(renderer, inputBuffer) {
1871
+ if (!this.usingBoxProjectedEnvMap && this._scene.environment) {
1872
+ const reflectionsMaterial = this.reflectionsPass.fullscreenMaterial;
1873
+ let envMap = null;
1874
+ this._scene.traverse((c) => {
1875
+ if (!envMap && c.material && !c.material.envMap) {
1876
+ const properties = renderer.properties.get(c.material);
1877
+ if ("envMap" in properties && properties.envMap instanceof THREE.Texture)
1878
+ envMap = properties.envMap;
1879
+ }
1880
+ });
1881
+ if (envMap) {
1882
+ const envMapCubeUVHeight = this._scene.environment.image.height;
1883
+ setupEnvMap(reflectionsMaterial, envMap, envMapCubeUVHeight);
1884
+ }
1885
+ }
1886
+ this.haltonIndex = (this.haltonIndex + 1) % this.haltonSequence.length;
1887
+ const [x, y] = this.haltonSequence[this.haltonIndex];
1888
+ const { width, height } = this.lastSize;
1889
+ this.temporalResolvePass.velocityPass.render(renderer);
1890
+ if (this._camera.setViewOffset)
1891
+ this._camera.setViewOffset(width, height, x, y, width, height);
1892
+ this.reflectionsPass.render(renderer, inputBuffer);
1893
+ this.temporalResolvePass.render(renderer);
1894
+ this._camera.clearViewOffset();
1895
+ }
1896
+ static patchDirectEnvIntensity(envMapIntensity = 0) {
1897
+ if (envMapIntensity === 0) {
1898
+ THREE.ShaderChunk.envmap_physical_pars_fragment = THREE.ShaderChunk.envmap_physical_pars_fragment.replace(
1899
+ "vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {",
1900
+ "vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { return vec3(0.0);"
1901
+ );
1902
+ } else {
1903
+ THREE.ShaderChunk.envmap_physical_pars_fragment = THREE.ShaderChunk.envmap_physical_pars_fragment.replace(
1904
+ "vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );",
1905
+ "vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness ) * " + envMapIntensity.toFixed(5) + ";"
1906
+ );
1907
+ }
1908
+ }
1909
+ }
785
1910
  const SSR = React.forwardRef(function SSR2({ ENABLE_BLUR = true, USE_MRT = true, ...props }, ref) {
786
1911
  const { invalidate } = fiber.useThree();
787
1912
  const { scene, camera } = React.useContext(EffectComposerContext);
788
1913
  const effect = React.useMemo(
789
- () => new screenSpaceReflections.SSREffect(scene, camera, { ENABLE_BLUR, USE_MRT, ...props }),
1914
+ () => new SSREffect(scene, camera, { ENABLE_BLUR, USE_MRT, ...props }),
790
1915
  [scene, camera, ENABLE_BLUR, USE_MRT, props]
791
1916
  );
792
1917
  const api = React.useContext(selectionContext);