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