@react-three/postprocessing 2.15.0 → 2.15.2
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/EffectComposer.cjs +126 -0
- package/dist/EffectComposer.cjs.map +1 -0
- package/dist/EffectComposer.js +126 -0
- package/dist/EffectComposer.js.map +1 -0
- package/dist/Selection.cjs +36 -0
- package/dist/Selection.cjs.map +1 -0
- package/dist/Selection.js +36 -0
- package/dist/Selection.js.map +1 -0
- package/dist/effects/ASCII.cjs +105 -0
- package/dist/effects/ASCII.cjs.map +1 -0
- package/dist/effects/ASCII.js +105 -0
- package/dist/effects/ASCII.js.map +1 -0
- package/dist/effects/Autofocus.cjs +126 -0
- package/dist/effects/Autofocus.cjs.map +1 -0
- package/dist/effects/Autofocus.js +109 -0
- package/dist/effects/Autofocus.js.map +1 -0
- package/dist/effects/Bloom.cjs +9 -0
- package/dist/effects/Bloom.cjs.map +1 -0
- package/dist/effects/Bloom.js +9 -0
- package/dist/effects/Bloom.js.map +1 -0
- package/dist/effects/BrightnessContrast.cjs +7 -0
- package/dist/effects/BrightnessContrast.cjs.map +1 -0
- package/dist/effects/BrightnessContrast.js +7 -0
- package/dist/effects/BrightnessContrast.js.map +1 -0
- package/dist/effects/ChromaticAberration.cjs +7 -0
- package/dist/effects/ChromaticAberration.cjs.map +1 -0
- package/dist/effects/ChromaticAberration.js +7 -0
- package/dist/effects/ChromaticAberration.js.map +1 -0
- package/dist/effects/ColorAverage.cjs +11 -0
- package/dist/effects/ColorAverage.cjs.map +1 -0
- package/dist/effects/ColorAverage.js +11 -0
- package/dist/effects/ColorAverage.js.map +1 -0
- package/dist/effects/ColorDepth.cjs +7 -0
- package/dist/effects/ColorDepth.cjs.map +1 -0
- package/dist/effects/ColorDepth.js +7 -0
- package/dist/effects/ColorDepth.js.map +1 -0
- package/dist/effects/Depth.cjs +7 -0
- package/dist/effects/Depth.cjs.map +1 -0
- package/dist/effects/Depth.js +7 -0
- package/dist/effects/Depth.js.map +1 -0
- package/dist/effects/DepthOfField.cjs +74 -0
- package/dist/effects/DepthOfField.cjs.map +1 -0
- package/dist/effects/DepthOfField.js +74 -0
- package/dist/effects/DepthOfField.js.map +1 -0
- package/dist/effects/DotScreen.cjs +7 -0
- package/dist/effects/DotScreen.cjs.map +1 -0
- package/dist/effects/DotScreen.js +7 -0
- package/dist/effects/DotScreen.js.map +1 -0
- package/dist/effects/FXAA.cjs +7 -0
- package/dist/effects/FXAA.cjs.map +1 -0
- package/dist/effects/FXAA.js +7 -0
- package/dist/effects/FXAA.js.map +1 -0
- package/dist/effects/Glitch.cjs +30 -0
- package/dist/effects/Glitch.cjs.map +1 -0
- package/dist/effects/Glitch.js +30 -0
- package/dist/effects/Glitch.js.map +1 -0
- package/dist/effects/GodRays.cjs +15 -0
- package/dist/effects/GodRays.cjs.map +1 -0
- package/dist/effects/GodRays.js +15 -0
- package/dist/effects/GodRays.js.map +1 -0
- package/dist/effects/Grid.cjs +18 -0
- package/dist/effects/Grid.cjs.map +1 -0
- package/dist/effects/Grid.js +18 -0
- package/dist/effects/Grid.js.map +1 -0
- package/dist/effects/HueSaturation.cjs +7 -0
- package/dist/effects/HueSaturation.cjs.map +1 -0
- package/dist/effects/HueSaturation.js +7 -0
- package/dist/effects/HueSaturation.js.map +1 -0
- package/dist/effects/LUT.cjs +20 -0
- package/dist/effects/LUT.cjs.map +1 -0
- package/dist/effects/LUT.js +20 -0
- package/dist/effects/LUT.js.map +1 -0
- package/dist/effects/LensFlare.cjs +189 -0
- package/dist/effects/LensFlare.cjs.map +1 -0
- package/dist/effects/LensFlare.js +172 -0
- package/dist/effects/LensFlare.js.map +1 -0
- package/dist/effects/N8AO.cjs +59 -0
- package/dist/effects/N8AO.cjs.map +1 -0
- package/dist/effects/N8AO.js +59 -0
- package/dist/effects/N8AO.js.map +1 -0
- package/dist/effects/Noise.cjs +7 -0
- package/dist/effects/Noise.cjs.map +1 -0
- package/dist/effects/Noise.js +7 -0
- package/dist/effects/Noise.js.map +1 -0
- package/dist/effects/Outline.cjs +93 -0
- package/dist/effects/Outline.cjs.map +1 -0
- package/dist/effects/Outline.js +93 -0
- package/dist/effects/Outline.js.map +1 -0
- package/dist/effects/Pixelation.cjs +11 -0
- package/dist/effects/Pixelation.cjs.map +1 -0
- package/dist/effects/Pixelation.js +11 -0
- package/dist/effects/Pixelation.js.map +1 -0
- package/dist/effects/SMAA.cjs +7 -0
- package/dist/effects/SMAA.cjs.map +1 -0
- package/dist/effects/SMAA.js +7 -0
- package/dist/effects/SMAA.js.map +1 -0
- package/dist/effects/SSAO.cjs +37 -0
- package/dist/effects/SSAO.cjs.map +1 -0
- package/dist/effects/SSAO.js +37 -0
- package/dist/effects/SSAO.js.map +1 -0
- package/dist/effects/SSR/index.cjs +33 -0
- package/dist/effects/SSR/index.cjs.map +1 -0
- package/dist/effects/SSR/index.js +33 -0
- package/dist/effects/SSR/index.js.map +1 -0
- package/dist/effects/SSR/screen-space-reflections.cjs +1133 -0
- package/dist/effects/SSR/screen-space-reflections.cjs.map +1 -0
- package/dist/effects/SSR/screen-space-reflections.js +1133 -0
- package/dist/effects/SSR/screen-space-reflections.js.map +1 -0
- package/dist/effects/ScanlineEffect.cjs +7 -0
- package/dist/effects/ScanlineEffect.cjs.map +1 -0
- package/dist/effects/ScanlineEffect.js +7 -0
- package/dist/effects/ScanlineEffect.js.map +1 -0
- package/dist/effects/SelectiveBloom.cjs +87 -0
- package/dist/effects/SelectiveBloom.cjs.map +1 -0
- package/dist/effects/SelectiveBloom.js +87 -0
- package/dist/effects/SelectiveBloom.js.map +1 -0
- package/dist/effects/Sepia.cjs +7 -0
- package/dist/effects/Sepia.cjs.map +1 -0
- package/dist/effects/Sepia.js +7 -0
- package/dist/effects/Sepia.js.map +1 -0
- package/dist/effects/ShockWave.cjs +7 -0
- package/dist/effects/ShockWave.cjs.map +1 -0
- package/dist/effects/ShockWave.js +7 -0
- package/dist/effects/ShockWave.js.map +1 -0
- package/dist/effects/Texture.cjs +18 -0
- package/dist/effects/Texture.cjs.map +1 -0
- package/dist/effects/Texture.js +18 -0
- package/dist/effects/Texture.js.map +1 -0
- package/dist/effects/TiltShift.cjs +7 -0
- package/dist/effects/TiltShift.cjs.map +1 -0
- package/dist/effects/TiltShift.js +7 -0
- package/dist/effects/TiltShift.js.map +1 -0
- package/dist/effects/TiltShift2.cjs +98 -0
- package/dist/effects/TiltShift2.cjs.map +1 -0
- package/dist/effects/TiltShift2.js +98 -0
- package/dist/effects/TiltShift2.js.map +1 -0
- package/dist/effects/ToneMapping.cjs +7 -0
- package/dist/effects/ToneMapping.cjs.map +1 -0
- package/dist/effects/ToneMapping.js +7 -0
- package/dist/effects/ToneMapping.js.map +1 -0
- package/dist/effects/Vignette.cjs +7 -0
- package/dist/effects/Vignette.cjs.map +1 -0
- package/dist/effects/Vignette.js +7 -0
- package/dist/effects/Vignette.js.map +1 -0
- package/dist/index.cjs +79 -3616
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -3557
- package/dist/index.js.map +1 -1
- package/dist/node_modules/n8ao/dist/N8AO.cjs +1439 -0
- package/dist/node_modules/n8ao/dist/N8AO.cjs.map +1 -0
- package/dist/node_modules/n8ao/dist/N8AO.js +1439 -0
- package/dist/node_modules/n8ao/dist/N8AO.js.map +1 -0
- package/dist/util.cjs +69 -0
- package/dist/util.cjs.map +1 -0
- package/dist/util.js +52 -0
- package/dist/util.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1133 @@
|
|
|
1
|
+
import { Effect, Selection, Pass, RenderPass, DepthPass } from "postprocessing";
|
|
2
|
+
import { ShaderChunk, Color, Vector2, WebGLCubeRenderTarget, Uniform, CubeCamera, PMREMGenerator, LinearFilter, Vector3, Texture, WebGLRenderTarget, HalfFloatType, WebGLMultipleRenderTargets, Quaternion, NearestFilter, FramebufferTexture, RGBAFormat, ShaderMaterial, Matrix3, REVISION, TangentSpaceNormalMap, GLSL3, Matrix4, VideoTexture, DataTexture, FloatType } from "three";
|
|
3
|
+
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;}";
|
|
4
|
+
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}";
|
|
5
|
+
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));}";
|
|
6
|
+
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);}";
|
|
7
|
+
class MRTMaterial extends ShaderMaterial {
|
|
8
|
+
constructor() {
|
|
9
|
+
super({
|
|
10
|
+
type: "MRTMaterial",
|
|
11
|
+
defines: {
|
|
12
|
+
USE_UV: "",
|
|
13
|
+
TEMPORAL_RESOLVE: ""
|
|
14
|
+
},
|
|
15
|
+
uniforms: {
|
|
16
|
+
opacity: new Uniform(1),
|
|
17
|
+
normalMap: new Uniform(null),
|
|
18
|
+
normalScale: new Uniform(new Vector2(1, 1)),
|
|
19
|
+
uvTransform: new Uniform(new Matrix3()),
|
|
20
|
+
roughness: new Uniform(1),
|
|
21
|
+
roughnessMap: new Uniform(null)
|
|
22
|
+
},
|
|
23
|
+
vertexShader: (
|
|
24
|
+
/* glsl */
|
|
25
|
+
`
|
|
26
|
+
#ifdef USE_MRT
|
|
27
|
+
varying vec2 vHighPrecisionZW;
|
|
28
|
+
#endif
|
|
29
|
+
#define NORMAL
|
|
30
|
+
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
|
|
31
|
+
varying vec3 vViewPosition;
|
|
32
|
+
#endif
|
|
33
|
+
#include <common>
|
|
34
|
+
#include <uv_pars_vertex>
|
|
35
|
+
#include <displacementmap_pars_vertex>
|
|
36
|
+
#include <normal_pars_vertex>
|
|
37
|
+
#include <morphtarget_pars_vertex>
|
|
38
|
+
#include <skinning_pars_vertex>
|
|
39
|
+
#include <logdepthbuf_pars_vertex>
|
|
40
|
+
#include <clipping_planes_pars_vertex>
|
|
41
|
+
#ifdef USE_UV
|
|
42
|
+
${REVISION.replace(/\D+/g, "") >= 151 ? "uniform mat3 uvTransform;" : ""}
|
|
43
|
+
#endif
|
|
44
|
+
void main() {
|
|
45
|
+
#include <uv_vertex>
|
|
46
|
+
#include <beginnormal_vertex>
|
|
47
|
+
#include <morphnormal_vertex>
|
|
48
|
+
#include <skinbase_vertex>
|
|
49
|
+
#include <skinnormal_vertex>
|
|
50
|
+
#include <defaultnormal_vertex>
|
|
51
|
+
#include <normal_vertex>
|
|
52
|
+
#include <begin_vertex>
|
|
53
|
+
#include <morphtarget_vertex>
|
|
54
|
+
#include <skinning_vertex>
|
|
55
|
+
#include <displacementmap_vertex>
|
|
56
|
+
#include <project_vertex>
|
|
57
|
+
#include <logdepthbuf_vertex>
|
|
58
|
+
#include <clipping_planes_vertex>
|
|
59
|
+
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
|
|
60
|
+
vViewPosition = - mvPosition.xyz;
|
|
61
|
+
#endif
|
|
62
|
+
#ifdef USE_MRT
|
|
63
|
+
vHighPrecisionZW = gl_Position.zw;
|
|
64
|
+
#endif
|
|
65
|
+
#ifdef USE_UV
|
|
66
|
+
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
|
|
67
|
+
#endif
|
|
68
|
+
}
|
|
69
|
+
`
|
|
70
|
+
),
|
|
71
|
+
fragmentShader: (
|
|
72
|
+
/* glsl */
|
|
73
|
+
`
|
|
74
|
+
#define NORMAL
|
|
75
|
+
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
|
|
76
|
+
varying vec3 vViewPosition;
|
|
77
|
+
#endif
|
|
78
|
+
#include <packing>
|
|
79
|
+
#include <uv_pars_fragment>
|
|
80
|
+
#include <normal_pars_fragment>
|
|
81
|
+
#include <bumpmap_pars_fragment>
|
|
82
|
+
#include <normalmap_pars_fragment>
|
|
83
|
+
#include <logdepthbuf_pars_fragment>
|
|
84
|
+
#include <clipping_planes_pars_fragment>
|
|
85
|
+
#include <roughnessmap_pars_fragment>
|
|
86
|
+
|
|
87
|
+
#ifdef USE_MRT
|
|
88
|
+
layout(location = 0) out vec4 gNormal;
|
|
89
|
+
layout(location = 1) out vec4 gDepth;
|
|
90
|
+
|
|
91
|
+
varying vec2 vHighPrecisionZW;
|
|
92
|
+
#endif
|
|
93
|
+
uniform float roughness;
|
|
94
|
+
void main() {
|
|
95
|
+
#include <clipping_planes_fragment>
|
|
96
|
+
#include <logdepthbuf_fragment>
|
|
97
|
+
#include <normal_fragment_begin>
|
|
98
|
+
#include <normal_fragment_maps>
|
|
99
|
+
|
|
100
|
+
float roughnessFactor = roughness;
|
|
101
|
+
|
|
102
|
+
if(roughness > 10.0e9){
|
|
103
|
+
roughnessFactor = 1.;
|
|
104
|
+
}else{
|
|
105
|
+
#ifdef useRoughnessMap
|
|
106
|
+
vec4 texelRoughness = texture2D( roughnessMap, vUv );
|
|
107
|
+
// reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
|
|
108
|
+
roughnessFactor *= texelRoughness.g;
|
|
109
|
+
#endif
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
vec3 normalColor = packNormalToRGB( normal );
|
|
113
|
+
#ifdef USE_MRT
|
|
114
|
+
float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
|
|
115
|
+
vec4 depthColor = packDepthToRGBA( fragCoordZ );
|
|
116
|
+
gNormal = vec4( normalColor, roughnessFactor );
|
|
117
|
+
gDepth = depthColor;
|
|
118
|
+
#else
|
|
119
|
+
gl_FragColor = vec4(normalColor, roughnessFactor);
|
|
120
|
+
#endif
|
|
121
|
+
}
|
|
122
|
+
`
|
|
123
|
+
),
|
|
124
|
+
toneMapped: false
|
|
125
|
+
});
|
|
126
|
+
this.normalMapType = TangentSpaceNormalMap;
|
|
127
|
+
this.normalScale = new Vector2(1, 1);
|
|
128
|
+
Object.defineProperty(this, "glslVersion", {
|
|
129
|
+
get() {
|
|
130
|
+
return "USE_MRT" in this.defines ? GLSL3 : null;
|
|
131
|
+
},
|
|
132
|
+
set(_) {
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
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);}";
|
|
138
|
+
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}";
|
|
139
|
+
class ReflectionsMaterial extends ShaderMaterial {
|
|
140
|
+
constructor() {
|
|
141
|
+
super({
|
|
142
|
+
type: "ReflectionsMaterial",
|
|
143
|
+
uniforms: {
|
|
144
|
+
inputTexture: new Uniform(null),
|
|
145
|
+
accumulatedTexture: new Uniform(null),
|
|
146
|
+
normalTexture: new Uniform(null),
|
|
147
|
+
depthTexture: new Uniform(null),
|
|
148
|
+
_projectionMatrix: new Uniform(new Matrix4()),
|
|
149
|
+
_inverseProjectionMatrix: new Uniform(new Matrix4()),
|
|
150
|
+
cameraMatrixWorld: new Uniform(new Matrix4()),
|
|
151
|
+
cameraNear: new Uniform(0),
|
|
152
|
+
cameraFar: new Uniform(0),
|
|
153
|
+
rayDistance: new Uniform(0),
|
|
154
|
+
intensity: new Uniform(0),
|
|
155
|
+
roughnessFade: new Uniform(0),
|
|
156
|
+
fade: new Uniform(0),
|
|
157
|
+
thickness: new Uniform(0),
|
|
158
|
+
ior: new Uniform(0),
|
|
159
|
+
maxDepthDifference: new Uniform(0),
|
|
160
|
+
jitter: new Uniform(0),
|
|
161
|
+
jitterRoughness: new Uniform(0),
|
|
162
|
+
maxRoughness: new Uniform(0),
|
|
163
|
+
samples: new Uniform(0),
|
|
164
|
+
envMap: new Uniform(null),
|
|
165
|
+
envMapPosition: new Uniform(new Vector3()),
|
|
166
|
+
envMapSize: new Uniform(new Vector3()),
|
|
167
|
+
viewMatrix: new Uniform(new Matrix4())
|
|
168
|
+
},
|
|
169
|
+
defines: {
|
|
170
|
+
steps: 20,
|
|
171
|
+
refineSteps: 5,
|
|
172
|
+
CUBEUV_TEXEL_WIDTH: 0,
|
|
173
|
+
CUBEUV_TEXEL_HEIGHT: 0,
|
|
174
|
+
CUBEUV_MAX_MIP: 0,
|
|
175
|
+
vWorldPosition: "worldPos"
|
|
176
|
+
},
|
|
177
|
+
fragmentShader: fragmentShader.replace("#include <helperFunctions>", helperFunctions),
|
|
178
|
+
vertexShader: vertexShader$1,
|
|
179
|
+
toneMapped: false,
|
|
180
|
+
depthWrite: false,
|
|
181
|
+
depthTest: false
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const getVisibleChildren = (object) => {
|
|
186
|
+
const queue = [object];
|
|
187
|
+
const objects = [];
|
|
188
|
+
while (queue.length !== 0) {
|
|
189
|
+
const mesh = queue.shift();
|
|
190
|
+
if (mesh.material)
|
|
191
|
+
objects.push(mesh);
|
|
192
|
+
for (const c of mesh.children) {
|
|
193
|
+
if (c.visible)
|
|
194
|
+
queue.push(c);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return objects;
|
|
198
|
+
};
|
|
199
|
+
const generateCubeUVSize = (parameters) => {
|
|
200
|
+
const imageHeight = parameters.envMapCubeUVHeight;
|
|
201
|
+
if (imageHeight === null)
|
|
202
|
+
return null;
|
|
203
|
+
const maxMip = Math.log2(imageHeight) - 2;
|
|
204
|
+
const texelHeight = 1 / imageHeight;
|
|
205
|
+
const texelWidth = 1 / (3 * Math.max(Math.pow(2, maxMip), 7 * 16));
|
|
206
|
+
return {
|
|
207
|
+
texelWidth,
|
|
208
|
+
texelHeight,
|
|
209
|
+
maxMip
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
const setupEnvMap = (reflectionsMaterial, envMap, envMapCubeUVHeight) => {
|
|
213
|
+
reflectionsMaterial.uniforms.envMap.value = envMap;
|
|
214
|
+
const envMapCubeUVSize = generateCubeUVSize({
|
|
215
|
+
envMapCubeUVHeight
|
|
216
|
+
});
|
|
217
|
+
reflectionsMaterial.defines.ENVMAP_TYPE_CUBE_UV = "";
|
|
218
|
+
reflectionsMaterial.defines.CUBEUV_TEXEL_WIDTH = envMapCubeUVSize.texelWidth;
|
|
219
|
+
reflectionsMaterial.defines.CUBEUV_TEXEL_HEIGHT = envMapCubeUVSize.texelHeight;
|
|
220
|
+
reflectionsMaterial.defines.CUBEUV_MAX_MIP = envMapCubeUVSize.maxMip + ".0";
|
|
221
|
+
reflectionsMaterial.needsUpdate = true;
|
|
222
|
+
};
|
|
223
|
+
const isWebGL2Available = () => {
|
|
224
|
+
try {
|
|
225
|
+
const canvas = document.createElement("canvas");
|
|
226
|
+
return !!(window.WebGL2RenderingContext && canvas.getContext("webgl2"));
|
|
227
|
+
} catch (e) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
class ReflectionsPass extends Pass {
|
|
232
|
+
constructor(ssrEffect, options = {}) {
|
|
233
|
+
super("ReflectionsPass");
|
|
234
|
+
this.ssrEffect = void 0;
|
|
235
|
+
this.cachedMaterials = /* @__PURE__ */ new WeakMap();
|
|
236
|
+
this.USE_MRT = false;
|
|
237
|
+
this.webgl1DepthPass = null;
|
|
238
|
+
this.visibleMeshes = [];
|
|
239
|
+
this.ssrEffect = ssrEffect;
|
|
240
|
+
this._scene = ssrEffect._scene;
|
|
241
|
+
this._camera = ssrEffect._camera;
|
|
242
|
+
this.fullscreenMaterial = new ReflectionsMaterial();
|
|
243
|
+
if (ssrEffect._camera.isPerspectiveCamera)
|
|
244
|
+
this.fullscreenMaterial.defines.PERSPECTIVE_CAMERA = "";
|
|
245
|
+
const width = options.width || typeof window !== "undefined" ? window.innerWidth : 2e3;
|
|
246
|
+
const height = options.height || typeof window !== "undefined" ? window.innerHeight : 1e3;
|
|
247
|
+
this.renderTarget = new WebGLRenderTarget(width, height, {
|
|
248
|
+
minFilter: LinearFilter,
|
|
249
|
+
magFilter: LinearFilter,
|
|
250
|
+
type: HalfFloatType,
|
|
251
|
+
depthBuffer: false
|
|
252
|
+
});
|
|
253
|
+
this.renderPass = new RenderPass(this._scene, this._camera);
|
|
254
|
+
this.USE_MRT = isWebGL2Available();
|
|
255
|
+
if (this.USE_MRT) {
|
|
256
|
+
this.gBuffersRenderTarget = new WebGLMultipleRenderTargets(width, height, 2, {
|
|
257
|
+
minFilter: LinearFilter,
|
|
258
|
+
magFilter: LinearFilter
|
|
259
|
+
});
|
|
260
|
+
this.normalTexture = this.gBuffersRenderTarget.texture[0];
|
|
261
|
+
this.depthTexture = this.gBuffersRenderTarget.texture[1];
|
|
262
|
+
} else {
|
|
263
|
+
this.webgl1DepthPass = new DepthPass(this._scene, this._camera);
|
|
264
|
+
this.webgl1DepthPass.renderTarget.minFilter = LinearFilter;
|
|
265
|
+
this.webgl1DepthPass.renderTarget.magFilter = LinearFilter;
|
|
266
|
+
this.webgl1DepthPass.renderTarget.texture.minFilter = LinearFilter;
|
|
267
|
+
this.webgl1DepthPass.renderTarget.texture.magFilter = LinearFilter;
|
|
268
|
+
this.webgl1DepthPass.setSize(
|
|
269
|
+
typeof window !== "undefined" ? window.innerWidth : 2e3,
|
|
270
|
+
typeof window !== "undefined" ? window.innerHeight : 1e3
|
|
271
|
+
);
|
|
272
|
+
this.gBuffersRenderTarget = new WebGLRenderTarget(width, height, {
|
|
273
|
+
minFilter: LinearFilter,
|
|
274
|
+
magFilter: LinearFilter
|
|
275
|
+
});
|
|
276
|
+
this.normalTexture = this.gBuffersRenderTarget.texture;
|
|
277
|
+
this.depthTexture = this.webgl1DepthPass.texture;
|
|
278
|
+
}
|
|
279
|
+
this.fullscreenMaterial.uniforms.normalTexture.value = this.normalTexture;
|
|
280
|
+
this.fullscreenMaterial.uniforms.depthTexture.value = this.depthTexture;
|
|
281
|
+
this.fullscreenMaterial.uniforms.accumulatedTexture.value = this.ssrEffect.temporalResolvePass.accumulatedTexture;
|
|
282
|
+
this.fullscreenMaterial.uniforms.cameraMatrixWorld.value = this._camera.matrixWorld;
|
|
283
|
+
this.fullscreenMaterial.uniforms._projectionMatrix.value = this._camera.projectionMatrix;
|
|
284
|
+
this.fullscreenMaterial.uniforms._inverseProjectionMatrix.value = this._camera.projectionMatrixInverse;
|
|
285
|
+
}
|
|
286
|
+
setSize(width, height) {
|
|
287
|
+
this.renderTarget.setSize(width * this.ssrEffect.resolutionScale, height * this.ssrEffect.resolutionScale);
|
|
288
|
+
this.gBuffersRenderTarget.setSize(width * this.ssrEffect.resolutionScale, height * this.ssrEffect.resolutionScale);
|
|
289
|
+
this.fullscreenMaterial.uniforms.accumulatedTexture.value = this.ssrEffect.temporalResolvePass.accumulatedTexture;
|
|
290
|
+
this.fullscreenMaterial.needsUpdate = true;
|
|
291
|
+
}
|
|
292
|
+
dispose() {
|
|
293
|
+
this.renderTarget.dispose();
|
|
294
|
+
this.gBuffersRenderTarget.dispose();
|
|
295
|
+
this.renderPass.dispose();
|
|
296
|
+
if (!this.USE_MRT)
|
|
297
|
+
this.webgl1DepthPass.dispose();
|
|
298
|
+
this.fullscreenMaterial.dispose();
|
|
299
|
+
this.normalTexture = null;
|
|
300
|
+
this.depthTexture = null;
|
|
301
|
+
this.velocityTexture = null;
|
|
302
|
+
}
|
|
303
|
+
keepMaterialMapUpdated(mrtMaterial, originalMaterial, prop, define) {
|
|
304
|
+
if (this.ssrEffect[define]) {
|
|
305
|
+
if (originalMaterial[prop] !== mrtMaterial[prop]) {
|
|
306
|
+
mrtMaterial[prop] = originalMaterial[prop];
|
|
307
|
+
mrtMaterial.uniforms[prop].value = originalMaterial[prop];
|
|
308
|
+
if (originalMaterial[prop]) {
|
|
309
|
+
mrtMaterial.defines[define] = "";
|
|
310
|
+
} else {
|
|
311
|
+
delete mrtMaterial.defines[define];
|
|
312
|
+
}
|
|
313
|
+
mrtMaterial.needsUpdate = true;
|
|
314
|
+
}
|
|
315
|
+
} else if (mrtMaterial[prop] !== void 0) {
|
|
316
|
+
mrtMaterial[prop] = void 0;
|
|
317
|
+
mrtMaterial.uniforms[prop].value = void 0;
|
|
318
|
+
delete mrtMaterial.defines[define];
|
|
319
|
+
mrtMaterial.needsUpdate = true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
setMRTMaterialInScene() {
|
|
323
|
+
this.visibleMeshes = getVisibleChildren(this._scene);
|
|
324
|
+
for (const c of this.visibleMeshes) {
|
|
325
|
+
if (c.material) {
|
|
326
|
+
const originalMaterial = c.material;
|
|
327
|
+
let [cachedOriginalMaterial, mrtMaterial] = this.cachedMaterials.get(c) || [];
|
|
328
|
+
if (originalMaterial !== cachedOriginalMaterial) {
|
|
329
|
+
if (mrtMaterial)
|
|
330
|
+
mrtMaterial.dispose();
|
|
331
|
+
mrtMaterial = new MRTMaterial();
|
|
332
|
+
if (this.USE_MRT)
|
|
333
|
+
mrtMaterial.defines.USE_MRT = "";
|
|
334
|
+
mrtMaterial.normalScale = originalMaterial.normalScale;
|
|
335
|
+
mrtMaterial.uniforms.normalScale.value = originalMaterial.normalScale;
|
|
336
|
+
const map = originalMaterial.map || originalMaterial.normalMap || originalMaterial.roughnessMap || originalMaterial.metalnessMap;
|
|
337
|
+
if (map)
|
|
338
|
+
mrtMaterial.uniforms.uvTransform.value = map.matrix;
|
|
339
|
+
this.cachedMaterials.set(c, [originalMaterial, mrtMaterial]);
|
|
340
|
+
}
|
|
341
|
+
this.keepMaterialMapUpdated(mrtMaterial, originalMaterial, "normalMap", "useNormalMap");
|
|
342
|
+
this.keepMaterialMapUpdated(mrtMaterial, originalMaterial, "roughnessMap", "useRoughnessMap");
|
|
343
|
+
mrtMaterial.uniforms.roughness.value = this.ssrEffect.selection.size === 0 || this.ssrEffect.selection.has(c) ? originalMaterial.roughness || 0 : 1e11;
|
|
344
|
+
c.material = mrtMaterial;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
unsetMRTMaterialInScene() {
|
|
349
|
+
for (const c of this.visibleMeshes) {
|
|
350
|
+
var _c$material;
|
|
351
|
+
if (((_c$material = c.material) == null ? void 0 : _c$material.type) === "MRTMaterial") {
|
|
352
|
+
c.visible = true;
|
|
353
|
+
const [originalMaterial] = this.cachedMaterials.get(c);
|
|
354
|
+
c.material = originalMaterial;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
render(renderer, inputBuffer) {
|
|
359
|
+
this.setMRTMaterialInScene();
|
|
360
|
+
renderer.setRenderTarget(this.gBuffersRenderTarget);
|
|
361
|
+
this.renderPass.render(renderer, this.gBuffersRenderTarget);
|
|
362
|
+
this.unsetMRTMaterialInScene();
|
|
363
|
+
if (!this.USE_MRT)
|
|
364
|
+
this.webgl1DepthPass.renderPass.render(renderer, this.webgl1DepthPass.renderTarget);
|
|
365
|
+
this.fullscreenMaterial.uniforms.inputTexture.value = inputBuffer.texture;
|
|
366
|
+
this.fullscreenMaterial.uniforms.samples.value = this.ssrEffect.temporalResolvePass.samples;
|
|
367
|
+
this.fullscreenMaterial.uniforms.cameraNear.value = this._camera.near;
|
|
368
|
+
this.fullscreenMaterial.uniforms.cameraFar.value = this._camera.far;
|
|
369
|
+
this.fullscreenMaterial.uniforms.viewMatrix.value.copy(this._camera.matrixWorldInverse);
|
|
370
|
+
renderer.setRenderTarget(this.renderTarget);
|
|
371
|
+
renderer.render(this.scene, this.camera);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const defaultSSROptions = {
|
|
375
|
+
intensity: 1,
|
|
376
|
+
exponent: 1,
|
|
377
|
+
distance: 10,
|
|
378
|
+
fade: 0,
|
|
379
|
+
roughnessFade: 1,
|
|
380
|
+
thickness: 10,
|
|
381
|
+
ior: 1.45,
|
|
382
|
+
maxRoughness: 1,
|
|
383
|
+
maxDepthDifference: 10,
|
|
384
|
+
blend: 0.9,
|
|
385
|
+
correction: 1,
|
|
386
|
+
correctionRadius: 1,
|
|
387
|
+
blur: 0.5,
|
|
388
|
+
blurKernel: 1,
|
|
389
|
+
blurSharpness: 10,
|
|
390
|
+
jitter: 0,
|
|
391
|
+
jitterRoughness: 0,
|
|
392
|
+
steps: 20,
|
|
393
|
+
refineSteps: 5,
|
|
394
|
+
missedRays: true,
|
|
395
|
+
useNormalMap: true,
|
|
396
|
+
useRoughnessMap: true,
|
|
397
|
+
resolutionScale: 1,
|
|
398
|
+
velocityResolutionScale: 1
|
|
399
|
+
};
|
|
400
|
+
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);}";
|
|
401
|
+
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);}";
|
|
402
|
+
class TemporalResolveMaterial extends ShaderMaterial {
|
|
403
|
+
constructor(customComposeShader) {
|
|
404
|
+
const fragmentShader2 = temporalResolve.replace("#include <custom_compose_shader>", customComposeShader);
|
|
405
|
+
super({
|
|
406
|
+
type: "TemporalResolveMaterial",
|
|
407
|
+
uniforms: {
|
|
408
|
+
inputTexture: new Uniform(null),
|
|
409
|
+
accumulatedTexture: new Uniform(null),
|
|
410
|
+
velocityTexture: new Uniform(null),
|
|
411
|
+
lastVelocityTexture: new Uniform(null),
|
|
412
|
+
samples: new Uniform(1),
|
|
413
|
+
blend: new Uniform(0.5),
|
|
414
|
+
correction: new Uniform(1),
|
|
415
|
+
exponent: new Uniform(1),
|
|
416
|
+
invTexSize: new Uniform(new Vector2())
|
|
417
|
+
},
|
|
418
|
+
defines: {
|
|
419
|
+
correctionRadius: 1
|
|
420
|
+
},
|
|
421
|
+
vertexShader,
|
|
422
|
+
fragmentShader: fragmentShader2
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
const prev_skinning_pars_vertex = (
|
|
427
|
+
/* glsl */
|
|
428
|
+
`
|
|
429
|
+
#ifdef USE_SKINNING
|
|
430
|
+
#ifdef BONE_TEXTURE
|
|
431
|
+
uniform sampler2D prevBoneTexture;
|
|
432
|
+
mat4 getPrevBoneMatrix( const in float i ) {
|
|
433
|
+
float j = i * 4.0;
|
|
434
|
+
float x = mod( j, float( boneTextureSize ) );
|
|
435
|
+
float y = floor( j / float( boneTextureSize ) );
|
|
436
|
+
float dx = 1.0 / float( boneTextureSize );
|
|
437
|
+
float dy = 1.0 / float( boneTextureSize );
|
|
438
|
+
y = dy * ( y + 0.5 );
|
|
439
|
+
vec4 v1 = texture2D( prevBoneTexture, vec2( dx * ( x + 0.5 ), y ) );
|
|
440
|
+
vec4 v2 = texture2D( prevBoneTexture, vec2( dx * ( x + 1.5 ), y ) );
|
|
441
|
+
vec4 v3 = texture2D( prevBoneTexture, vec2( dx * ( x + 2.5 ), y ) );
|
|
442
|
+
vec4 v4 = texture2D( prevBoneTexture, vec2( dx * ( x + 3.5 ), y ) );
|
|
443
|
+
mat4 bone = mat4( v1, v2, v3, v4 );
|
|
444
|
+
return bone;
|
|
445
|
+
}
|
|
446
|
+
#else
|
|
447
|
+
uniform mat4 prevBoneMatrices[ MAX_BONES ];
|
|
448
|
+
mat4 getPrevBoneMatrix( const in float i ) {
|
|
449
|
+
mat4 bone = prevBoneMatrices[ int(i) ];
|
|
450
|
+
return bone;
|
|
451
|
+
}
|
|
452
|
+
#endif
|
|
453
|
+
#endif
|
|
454
|
+
`
|
|
455
|
+
);
|
|
456
|
+
const velocity_vertex = (
|
|
457
|
+
/* glsl */
|
|
458
|
+
`
|
|
459
|
+
vec3 transformed;
|
|
460
|
+
|
|
461
|
+
// Get the normal
|
|
462
|
+
${ShaderChunk.skinbase_vertex}
|
|
463
|
+
${ShaderChunk.beginnormal_vertex}
|
|
464
|
+
${ShaderChunk.skinnormal_vertex}
|
|
465
|
+
${ShaderChunk.defaultnormal_vertex}
|
|
466
|
+
|
|
467
|
+
// Get the current vertex position
|
|
468
|
+
transformed = vec3( position );
|
|
469
|
+
${ShaderChunk.skinning_vertex}
|
|
470
|
+
newPosition = velocityMatrix * vec4( transformed, 1.0 );
|
|
471
|
+
|
|
472
|
+
// Get the previous vertex position
|
|
473
|
+
transformed = vec3( position );
|
|
474
|
+
${ShaderChunk.skinbase_vertex.replace(/mat4 /g, "").replace(/getBoneMatrix/g, "getPrevBoneMatrix")}
|
|
475
|
+
${ShaderChunk.skinning_vertex.replace(/vec4 /g, "")}
|
|
476
|
+
prevPosition = prevVelocityMatrix * vec4( transformed, 1.0 );
|
|
477
|
+
|
|
478
|
+
gl_Position = newPosition;
|
|
479
|
+
`
|
|
480
|
+
);
|
|
481
|
+
class VelocityMaterial extends ShaderMaterial {
|
|
482
|
+
constructor() {
|
|
483
|
+
super({
|
|
484
|
+
uniforms: {
|
|
485
|
+
prevVelocityMatrix: {
|
|
486
|
+
value: new Matrix4()
|
|
487
|
+
},
|
|
488
|
+
velocityMatrix: {
|
|
489
|
+
value: new Matrix4()
|
|
490
|
+
},
|
|
491
|
+
prevBoneTexture: {
|
|
492
|
+
value: null
|
|
493
|
+
},
|
|
494
|
+
interpolateGeometry: {
|
|
495
|
+
value: 0
|
|
496
|
+
},
|
|
497
|
+
intensity: {
|
|
498
|
+
value: 1
|
|
499
|
+
},
|
|
500
|
+
boneTexture: {
|
|
501
|
+
value: null
|
|
502
|
+
},
|
|
503
|
+
alphaTest: {
|
|
504
|
+
value: 0
|
|
505
|
+
},
|
|
506
|
+
map: {
|
|
507
|
+
value: null
|
|
508
|
+
},
|
|
509
|
+
alphaMap: {
|
|
510
|
+
value: null
|
|
511
|
+
},
|
|
512
|
+
opacity: {
|
|
513
|
+
value: 1
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
vertexShader: (
|
|
517
|
+
/* glsl */
|
|
518
|
+
`
|
|
519
|
+
#define MAX_BONES 1024
|
|
520
|
+
|
|
521
|
+
${ShaderChunk.skinning_pars_vertex}
|
|
522
|
+
${prev_skinning_pars_vertex}
|
|
523
|
+
|
|
524
|
+
uniform mat4 velocityMatrix;
|
|
525
|
+
uniform mat4 prevVelocityMatrix;
|
|
526
|
+
uniform float interpolateGeometry;
|
|
527
|
+
varying vec4 prevPosition;
|
|
528
|
+
varying vec4 newPosition;
|
|
529
|
+
varying vec2 vHighPrecisionZW;
|
|
530
|
+
|
|
531
|
+
void main() {
|
|
532
|
+
|
|
533
|
+
${velocity_vertex}
|
|
534
|
+
|
|
535
|
+
vHighPrecisionZW = gl_Position.zw;
|
|
536
|
+
|
|
537
|
+
}`
|
|
538
|
+
),
|
|
539
|
+
fragmentShader: (
|
|
540
|
+
/* glsl */
|
|
541
|
+
`
|
|
542
|
+
uniform float intensity;
|
|
543
|
+
varying vec4 prevPosition;
|
|
544
|
+
varying vec4 newPosition;
|
|
545
|
+
varying vec2 vHighPrecisionZW;
|
|
546
|
+
|
|
547
|
+
void main() {
|
|
548
|
+
#ifdef FULL_MOVEMENT
|
|
549
|
+
gl_FragColor = vec4( 1., 1., 1. - gl_FragCoord.z, 0. );
|
|
550
|
+
return;
|
|
551
|
+
#endif
|
|
552
|
+
|
|
553
|
+
vec2 pos0 = (prevPosition.xy / prevPosition.w) * 0.5 + 0.5;
|
|
554
|
+
vec2 pos1 = (newPosition.xy / newPosition.w) * 0.5 + 0.5;
|
|
555
|
+
|
|
556
|
+
vec2 vel = pos1 - pos0;
|
|
557
|
+
|
|
558
|
+
float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
|
|
559
|
+
|
|
560
|
+
gl_FragColor = vec4( vel, 1. - fragCoordZ, 0. );
|
|
561
|
+
|
|
562
|
+
}`
|
|
563
|
+
)
|
|
564
|
+
});
|
|
565
|
+
this.isVelocityMaterial = true;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const backgroundColor = new Color(0);
|
|
569
|
+
const updateProperties = ["visible", "wireframe", "side"];
|
|
570
|
+
class VelocityPass extends Pass {
|
|
571
|
+
constructor(scene, camera) {
|
|
572
|
+
var _window, _window2;
|
|
573
|
+
super("VelocityPass");
|
|
574
|
+
this.cachedMaterials = /* @__PURE__ */ new WeakMap();
|
|
575
|
+
this.lastCameraTransform = {
|
|
576
|
+
position: new Vector3(),
|
|
577
|
+
quaternion: new Quaternion()
|
|
578
|
+
};
|
|
579
|
+
this.visibleMeshes = [];
|
|
580
|
+
this.renderedMeshesThisFrame = 0;
|
|
581
|
+
this.renderedMeshesLastFrame = 0;
|
|
582
|
+
this._scene = scene;
|
|
583
|
+
this._camera = camera;
|
|
584
|
+
this.renderTarget = new WebGLRenderTarget(
|
|
585
|
+
((_window = window) == null ? void 0 : _window.innerWidth) || 1e3,
|
|
586
|
+
((_window2 = window) == null ? void 0 : _window2.innerHeight) || 1e3,
|
|
587
|
+
{
|
|
588
|
+
type: HalfFloatType
|
|
589
|
+
}
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
setVelocityMaterialInScene() {
|
|
593
|
+
this.renderedMeshesThisFrame = 0;
|
|
594
|
+
this.visibleMeshes = getVisibleChildren(this._scene);
|
|
595
|
+
for (const c of this.visibleMeshes) {
|
|
596
|
+
var _c$skeleton2;
|
|
597
|
+
const originalMaterial = c.material;
|
|
598
|
+
let [cachedOriginalMaterial, velocityMaterial] = this.cachedMaterials.get(c) || [];
|
|
599
|
+
if (originalMaterial !== cachedOriginalMaterial) {
|
|
600
|
+
var _c$skeleton;
|
|
601
|
+
velocityMaterial = new VelocityMaterial();
|
|
602
|
+
velocityMaterial.lastMatrixWorld = new Matrix4();
|
|
603
|
+
c.material = velocityMaterial;
|
|
604
|
+
if ((_c$skeleton = c.skeleton) != null && _c$skeleton.boneTexture)
|
|
605
|
+
this.saveBoneTexture(c);
|
|
606
|
+
this.cachedMaterials.set(c, [originalMaterial, velocityMaterial]);
|
|
607
|
+
}
|
|
608
|
+
velocityMaterial.uniforms.velocityMatrix.value.multiplyMatrices(this._camera.projectionMatrix, c.modelViewMatrix);
|
|
609
|
+
if (c.userData.needsUpdatedReflections || originalMaterial.map instanceof VideoTexture) {
|
|
610
|
+
if (!("FULL_MOVEMENT" in velocityMaterial.defines))
|
|
611
|
+
velocityMaterial.needsUpdate = true;
|
|
612
|
+
velocityMaterial.defines.FULL_MOVEMENT = "";
|
|
613
|
+
} else {
|
|
614
|
+
if ("FULL_MOVEMENT" in velocityMaterial.defines) {
|
|
615
|
+
delete velocityMaterial.defines.FULL_MOVEMENT;
|
|
616
|
+
velocityMaterial.needsUpdate = true;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
c.visible = this.cameraMovedThisFrame || !c.matrixWorld.equals(velocityMaterial.lastMatrixWorld) || c.skeleton || "FULL_MOVEMENT" in velocityMaterial.defines;
|
|
620
|
+
c.material = velocityMaterial;
|
|
621
|
+
if (!c.visible)
|
|
622
|
+
continue;
|
|
623
|
+
this.renderedMeshesThisFrame++;
|
|
624
|
+
for (const prop of updateProperties)
|
|
625
|
+
velocityMaterial[prop] = originalMaterial[prop];
|
|
626
|
+
if ((_c$skeleton2 = c.skeleton) != null && _c$skeleton2.boneTexture) {
|
|
627
|
+
velocityMaterial.defines.USE_SKINNING = "";
|
|
628
|
+
velocityMaterial.defines.BONE_TEXTURE = "";
|
|
629
|
+
velocityMaterial.uniforms.boneTexture.value = c.skeleton.boneTexture;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
saveBoneTexture(object) {
|
|
634
|
+
let boneTexture = object.material.uniforms.prevBoneTexture.value;
|
|
635
|
+
if (boneTexture && boneTexture.image.width === object.skeleton.boneTexture.width) {
|
|
636
|
+
boneTexture = object.material.uniforms.prevBoneTexture.value;
|
|
637
|
+
boneTexture.image.data.set(object.skeleton.boneTexture.image.data);
|
|
638
|
+
} else {
|
|
639
|
+
var _boneTexture;
|
|
640
|
+
(_boneTexture = boneTexture) == null ? void 0 : _boneTexture.dispose();
|
|
641
|
+
const boneMatrices = object.skeleton.boneTexture.image.data.slice();
|
|
642
|
+
const size = object.skeleton.boneTexture.image.width;
|
|
643
|
+
boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
|
|
644
|
+
object.material.uniforms.prevBoneTexture.value = boneTexture;
|
|
645
|
+
boneTexture.needsUpdate = true;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
unsetVelocityMaterialInScene() {
|
|
649
|
+
for (const c of this.visibleMeshes) {
|
|
650
|
+
if (c.material.isVelocityMaterial) {
|
|
651
|
+
var _c$skeleton3;
|
|
652
|
+
c.visible = true;
|
|
653
|
+
c.material.lastMatrixWorld.copy(c.matrixWorld);
|
|
654
|
+
c.material.uniforms.prevVelocityMatrix.value.multiplyMatrices(this._camera.projectionMatrix, c.modelViewMatrix);
|
|
655
|
+
if ((_c$skeleton3 = c.skeleton) != null && _c$skeleton3.boneTexture)
|
|
656
|
+
this.saveBoneTexture(c);
|
|
657
|
+
c.material = this.cachedMaterials.get(c)[0];
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
setSize(width, height) {
|
|
662
|
+
this.renderTarget.setSize(width, height);
|
|
663
|
+
}
|
|
664
|
+
renderVelocity(renderer) {
|
|
665
|
+
renderer.setRenderTarget(this.renderTarget);
|
|
666
|
+
if (this.renderedMeshesThisFrame > 0) {
|
|
667
|
+
const { background } = this._scene;
|
|
668
|
+
this._scene.background = backgroundColor;
|
|
669
|
+
renderer.render(this._scene, this._camera);
|
|
670
|
+
this._scene.background = background;
|
|
671
|
+
} else {
|
|
672
|
+
renderer.clearColor();
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
checkCameraMoved() {
|
|
676
|
+
const moveDist = this.lastCameraTransform.position.distanceToSquared(this._camera.position);
|
|
677
|
+
const rotateDist = 8 * (1 - this.lastCameraTransform.quaternion.dot(this._camera.quaternion));
|
|
678
|
+
if (moveDist > 1e-6 || rotateDist > 1e-6) {
|
|
679
|
+
this.lastCameraTransform.position.copy(this._camera.position);
|
|
680
|
+
this.lastCameraTransform.quaternion.copy(this._camera.quaternion);
|
|
681
|
+
return true;
|
|
682
|
+
}
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
render(renderer) {
|
|
686
|
+
this.cameraMovedThisFrame = this.checkCameraMoved();
|
|
687
|
+
this.setVelocityMaterialInScene();
|
|
688
|
+
if (this.renderedMeshesThisFrame > 0 || this.renderedMeshesLastFrame > 0)
|
|
689
|
+
this.renderVelocity(renderer);
|
|
690
|
+
this.unsetVelocityMaterialInScene();
|
|
691
|
+
this.renderedMeshesLastFrame = this.renderedMeshesThisFrame;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
const zeroVec2 = new Vector2();
|
|
695
|
+
class TemporalResolvePass extends Pass {
|
|
696
|
+
constructor(scene, camera, customComposeShader, options = {}) {
|
|
697
|
+
super("TemporalResolvePass");
|
|
698
|
+
this.velocityPass = null;
|
|
699
|
+
this.velocityResolutionScale = 1;
|
|
700
|
+
this.samples = 1;
|
|
701
|
+
this.lastCameraTransform = {
|
|
702
|
+
position: new Vector3(),
|
|
703
|
+
quaternion: new Quaternion()
|
|
704
|
+
};
|
|
705
|
+
this._scene = scene;
|
|
706
|
+
this._camera = camera;
|
|
707
|
+
this.renderTarget = new WebGLRenderTarget(1, 1, {
|
|
708
|
+
minFilter: LinearFilter,
|
|
709
|
+
magFilter: LinearFilter,
|
|
710
|
+
type: HalfFloatType,
|
|
711
|
+
depthBuffer: false
|
|
712
|
+
});
|
|
713
|
+
this.velocityPass = new VelocityPass(scene, camera);
|
|
714
|
+
this.fullscreenMaterial = new TemporalResolveMaterial(customComposeShader);
|
|
715
|
+
this.fullscreenMaterial.defines.correctionRadius = options.correctionRadius || 1;
|
|
716
|
+
if (options.dilation)
|
|
717
|
+
this.fullscreenMaterial.defines.dilation = "";
|
|
718
|
+
if (options.boxBlur)
|
|
719
|
+
this.fullscreenMaterial.defines.boxBlur = "";
|
|
720
|
+
this.setupFramebuffers(1, 1);
|
|
721
|
+
this.checkCanUseSharedVelocityTexture();
|
|
722
|
+
}
|
|
723
|
+
dispose() {
|
|
724
|
+
if (this._scene.userData.velocityTexture === this.velocityPass.renderTarget.texture) {
|
|
725
|
+
delete this._scene.userData.velocityTexture;
|
|
726
|
+
delete this._scene.userData.lastVelocityTexture;
|
|
727
|
+
}
|
|
728
|
+
this.renderTarget.dispose();
|
|
729
|
+
this.accumulatedTexture.dispose();
|
|
730
|
+
this.fullscreenMaterial.dispose();
|
|
731
|
+
this.velocityPass.dispose();
|
|
732
|
+
}
|
|
733
|
+
setSize(width, height) {
|
|
734
|
+
this.renderTarget.setSize(width, height);
|
|
735
|
+
this.velocityPass.setSize(width * this.velocityResolutionScale, height * this.velocityResolutionScale);
|
|
736
|
+
this.velocityPass.renderTarget.texture.minFilter = this.velocityResolutionScale === 1 ? NearestFilter : LinearFilter;
|
|
737
|
+
this.velocityPass.renderTarget.texture.magFilter = this.velocityResolutionScale === 1 ? NearestFilter : LinearFilter;
|
|
738
|
+
this.velocityPass.renderTarget.texture.needsUpdate = true;
|
|
739
|
+
this.fullscreenMaterial.uniforms.invTexSize.value.set(1 / width, 1 / height);
|
|
740
|
+
this.setupFramebuffers(width, height);
|
|
741
|
+
}
|
|
742
|
+
setupFramebuffers(width, height) {
|
|
743
|
+
if (this.accumulatedTexture)
|
|
744
|
+
this.accumulatedTexture.dispose();
|
|
745
|
+
if (this.lastVelocityTexture)
|
|
746
|
+
this.lastVelocityTexture.dispose();
|
|
747
|
+
this.accumulatedTexture = new FramebufferTexture(width, height, RGBAFormat);
|
|
748
|
+
this.accumulatedTexture.minFilter = LinearFilter;
|
|
749
|
+
this.accumulatedTexture.magFilter = LinearFilter;
|
|
750
|
+
this.accumulatedTexture.type = HalfFloatType;
|
|
751
|
+
this.lastVelocityTexture = new FramebufferTexture(
|
|
752
|
+
width * this.velocityResolutionScale,
|
|
753
|
+
height * this.velocityResolutionScale,
|
|
754
|
+
RGBAFormat
|
|
755
|
+
);
|
|
756
|
+
this.lastVelocityTexture.minFilter = this.velocityResolutionScale === 1 ? NearestFilter : LinearFilter;
|
|
757
|
+
this.lastVelocityTexture.magFilter = this.velocityResolutionScale === 1 ? NearestFilter : LinearFilter;
|
|
758
|
+
this.lastVelocityTexture.type = HalfFloatType;
|
|
759
|
+
this.fullscreenMaterial.uniforms.accumulatedTexture.value = this.accumulatedTexture;
|
|
760
|
+
this.fullscreenMaterial.uniforms.lastVelocityTexture.value = this.lastVelocityTexture;
|
|
761
|
+
this.fullscreenMaterial.needsUpdate = true;
|
|
762
|
+
}
|
|
763
|
+
checkCanUseSharedVelocityTexture() {
|
|
764
|
+
const canUseSharedVelocityTexture = this._scene.userData.velocityTexture && this.velocityPass.renderTarget.texture !== this._scene.userData.velocityTexture;
|
|
765
|
+
if (canUseSharedVelocityTexture) {
|
|
766
|
+
if (this.velocityPass.renderTarget.texture === this.fullscreenMaterial.uniforms.velocityTexture.value) {
|
|
767
|
+
this.fullscreenMaterial.uniforms.lastVelocityTexture.value = this._scene.userData.lastVelocityTexture;
|
|
768
|
+
this.fullscreenMaterial.uniforms.velocityTexture.value = this._scene.userData.velocityTexture;
|
|
769
|
+
this.fullscreenMaterial.needsUpdate = true;
|
|
770
|
+
}
|
|
771
|
+
} else {
|
|
772
|
+
if (this.velocityPass.renderTarget.texture !== this.fullscreenMaterial.uniforms.velocityTexture.value) {
|
|
773
|
+
this.fullscreenMaterial.uniforms.velocityTexture.value = this.velocityPass.renderTarget.texture;
|
|
774
|
+
this.fullscreenMaterial.uniforms.lastVelocityTexture.value = this.lastVelocityTexture;
|
|
775
|
+
this.fullscreenMaterial.needsUpdate = true;
|
|
776
|
+
if (!this._scene.userData.velocityTexture) {
|
|
777
|
+
this._scene.userData.velocityTexture = this.velocityPass.renderTarget.texture;
|
|
778
|
+
this._scene.userData.lastVelocityTexture = this.lastVelocityTexture;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return this.velocityPass.renderTarget.texture !== this.fullscreenMaterial.uniforms.velocityTexture.value;
|
|
783
|
+
}
|
|
784
|
+
checkNeedsResample() {
|
|
785
|
+
const moveDist = this.lastCameraTransform.position.distanceToSquared(this._camera.position);
|
|
786
|
+
const rotateDist = 8 * (1 - this.lastCameraTransform.quaternion.dot(this._camera.quaternion));
|
|
787
|
+
if (moveDist > 1e-6 || rotateDist > 1e-6) {
|
|
788
|
+
this.samples = 1;
|
|
789
|
+
this.lastCameraTransform.position.copy(this._camera.position);
|
|
790
|
+
this.lastCameraTransform.quaternion.copy(this._camera.quaternion);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
render(renderer) {
|
|
794
|
+
this.samples++;
|
|
795
|
+
this.checkNeedsResample();
|
|
796
|
+
this.fullscreenMaterial.uniforms.samples.value = this.samples;
|
|
797
|
+
renderer.setRenderTarget(this.renderTarget);
|
|
798
|
+
renderer.render(this.scene, this.camera);
|
|
799
|
+
renderer.copyFramebufferToTexture(zeroVec2, this.accumulatedTexture);
|
|
800
|
+
renderer.setRenderTarget(this.velocityPass.renderTarget);
|
|
801
|
+
renderer.copyFramebufferToTexture(zeroVec2, this.lastVelocityTexture);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
const halton = function halton2(index, base) {
|
|
805
|
+
let fraction = 1;
|
|
806
|
+
let result = 0;
|
|
807
|
+
while (index > 0) {
|
|
808
|
+
fraction /= base;
|
|
809
|
+
result += fraction * (index % base);
|
|
810
|
+
index = ~~(index / base);
|
|
811
|
+
}
|
|
812
|
+
return result;
|
|
813
|
+
};
|
|
814
|
+
const generateHalton23Points = (count) => {
|
|
815
|
+
const data = [];
|
|
816
|
+
let i = 1;
|
|
817
|
+
const end = i + count;
|
|
818
|
+
for (; i < end; i++) {
|
|
819
|
+
data.push([halton(i, 2) - 0.5, halton(i, 3) - 0.5]);
|
|
820
|
+
}
|
|
821
|
+
return data;
|
|
822
|
+
};
|
|
823
|
+
function escapeRegExp(string) {
|
|
824
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
825
|
+
}
|
|
826
|
+
const worldposReplace = (
|
|
827
|
+
/* glsl */
|
|
828
|
+
`
|
|
829
|
+
#if defined( USE_ENVMAP ) || defined( ) || defined ( USE_SHADOWMAP )
|
|
830
|
+
vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );
|
|
831
|
+
|
|
832
|
+
#ifdef BOX_PROJECTED_ENV_MAP
|
|
833
|
+
vWorldPosition = worldPosition.xyz;
|
|
834
|
+
#endif
|
|
835
|
+
#endif
|
|
836
|
+
`
|
|
837
|
+
);
|
|
838
|
+
const boxProjectDefinitions = (
|
|
839
|
+
/* glsl */
|
|
840
|
+
`
|
|
841
|
+
#ifdef BOX_PROJECTED_ENV_MAP
|
|
842
|
+
uniform vec3 envMapSize;
|
|
843
|
+
uniform vec3 envMapPosition;
|
|
844
|
+
varying vec3 vWorldPosition;
|
|
845
|
+
|
|
846
|
+
vec3 parallaxCorrectNormal( vec3 v, vec3 cubeSize, vec3 cubePos ) {
|
|
847
|
+
vec3 nDir = normalize( v );
|
|
848
|
+
|
|
849
|
+
vec3 rbmax = ( .5 * cubeSize + cubePos - vWorldPosition ) / nDir;
|
|
850
|
+
vec3 rbmin = ( -.5 * cubeSize + cubePos - vWorldPosition ) / nDir;
|
|
851
|
+
|
|
852
|
+
vec3 rbminmax;
|
|
853
|
+
|
|
854
|
+
rbminmax.x = ( nDir.x > 0. ) ? rbmax.x : rbmin.x;
|
|
855
|
+
rbminmax.y = ( nDir.y > 0. ) ? rbmax.y : rbmin.y;
|
|
856
|
+
rbminmax.z = ( nDir.z > 0. ) ? rbmax.z : rbmin.z;
|
|
857
|
+
|
|
858
|
+
float correction = min( min( rbminmax.x, rbminmax.y ), rbminmax.z );
|
|
859
|
+
vec3 boxIntersection = vWorldPosition + nDir * correction;
|
|
860
|
+
|
|
861
|
+
return boxIntersection - cubePos;
|
|
862
|
+
}
|
|
863
|
+
#endif
|
|
864
|
+
`
|
|
865
|
+
);
|
|
866
|
+
const getIBLIrradiance_patch = (
|
|
867
|
+
/* glsl */
|
|
868
|
+
`
|
|
869
|
+
#ifdef BOX_PROJECTED_ENV_MAP
|
|
870
|
+
worldNormal = parallaxCorrectNormal( worldNormal, envMapSize, envMapPosition );
|
|
871
|
+
#endif
|
|
872
|
+
`
|
|
873
|
+
);
|
|
874
|
+
const getIBLRadiance_patch = (
|
|
875
|
+
/* glsl */
|
|
876
|
+
`
|
|
877
|
+
#ifdef BOX_PROJECTED_ENV_MAP
|
|
878
|
+
reflectVec = parallaxCorrectNormal( reflectVec, envMapSize, envMapPosition );
|
|
879
|
+
#endif
|
|
880
|
+
`
|
|
881
|
+
);
|
|
882
|
+
function useBoxProjectedEnvMap(shader, envMapPosition, envMapSize) {
|
|
883
|
+
shader.defines.BOX_PROJECTED_ENV_MAP = "";
|
|
884
|
+
shader.uniforms.envMapPosition = {
|
|
885
|
+
value: envMapPosition
|
|
886
|
+
};
|
|
887
|
+
shader.uniforms.envMapSize = {
|
|
888
|
+
value: envMapSize
|
|
889
|
+
};
|
|
890
|
+
const line1 = new RegExp(
|
|
891
|
+
escapeRegExp("vec3 worldNormal = inverseTransformDirection ( normal , viewMatrix ) ;").replaceAll(" ", "\\s*"),
|
|
892
|
+
"g"
|
|
893
|
+
);
|
|
894
|
+
const line2 = new RegExp(
|
|
895
|
+
escapeRegExp("reflectVec = inverseTransformDirection ( reflectVec , viewMatrix ) ;").replaceAll(" ", "\\s*"),
|
|
896
|
+
"g"
|
|
897
|
+
);
|
|
898
|
+
shader.vertexShader = "varying vec3 vWorldPosition;\n" + shader.vertexShader.replace("#include <worldpos_vertex>", worldposReplace);
|
|
899
|
+
shader.fragmentShader = boxProjectDefinitions + "\n" + shader.fragmentShader.replace("#include <envmap_physical_pars_fragment>", ShaderChunk.envmap_physical_pars_fragment).replace(
|
|
900
|
+
line1,
|
|
901
|
+
`vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
902
|
+
${getIBLIrradiance_patch}`
|
|
903
|
+
).replace(
|
|
904
|
+
line2,
|
|
905
|
+
`reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
|
|
906
|
+
${getIBLRadiance_patch}`
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
const finalFragmentShader = finalSSRShader.replace("#include <helperFunctions>", helperFunctions).replace("#include <boxBlur>", boxBlur);
|
|
910
|
+
const noResetSamplesProperties = ["blur", "blurSharpness", "blurKernel"];
|
|
911
|
+
const defaultCubeRenderTarget = new WebGLCubeRenderTarget(1);
|
|
912
|
+
let pmremGenerator;
|
|
913
|
+
class SSREffect extends Effect {
|
|
914
|
+
/**
|
|
915
|
+
* @param {THREE.Scene} scene The scene of the SSR effect
|
|
916
|
+
* @param {THREE.Camera} camera The camera with which SSR is being rendered
|
|
917
|
+
* @param {SSROptions} [options] The optional options for the SSR effect
|
|
918
|
+
*/
|
|
919
|
+
constructor(scene, camera, options = defaultSSROptions) {
|
|
920
|
+
super("SSREffect", finalFragmentShader, {
|
|
921
|
+
type: "FinalSSRMaterial",
|
|
922
|
+
uniforms: /* @__PURE__ */ new Map([
|
|
923
|
+
["reflectionsTexture", new Uniform(null)],
|
|
924
|
+
["blur", new Uniform(0)],
|
|
925
|
+
["blurSharpness", new Uniform(0)],
|
|
926
|
+
["blurKernel", new Uniform(0)]
|
|
927
|
+
]),
|
|
928
|
+
defines: /* @__PURE__ */ new Map([["RENDER_MODE", "0"]])
|
|
929
|
+
});
|
|
930
|
+
this.haltonSequence = generateHalton23Points(1024);
|
|
931
|
+
this.haltonIndex = 0;
|
|
932
|
+
this.selection = new Selection();
|
|
933
|
+
this.lastSize = void 0;
|
|
934
|
+
this.cubeCamera = new CubeCamera(1e-3, 1e3, defaultCubeRenderTarget);
|
|
935
|
+
this.usingBoxProjectedEnvMap = false;
|
|
936
|
+
this._scene = scene;
|
|
937
|
+
this._camera = camera;
|
|
938
|
+
const trOptions = {
|
|
939
|
+
boxBlur: true,
|
|
940
|
+
dilation: true
|
|
941
|
+
};
|
|
942
|
+
options = { ...defaultSSROptions, ...options, ...trOptions };
|
|
943
|
+
this.temporalResolvePass = new TemporalResolvePass(scene, camera, trCompose, options);
|
|
944
|
+
this.uniforms.get("reflectionsTexture").value = this.temporalResolvePass.renderTarget.texture;
|
|
945
|
+
this.reflectionsPass = new ReflectionsPass(this, options);
|
|
946
|
+
this.temporalResolvePass.fullscreenMaterial.uniforms.inputTexture.value = this.reflectionsPass.renderTarget.texture;
|
|
947
|
+
this.lastSize = {
|
|
948
|
+
width: options.width,
|
|
949
|
+
height: options.height,
|
|
950
|
+
resolutionScale: options.resolutionScale,
|
|
951
|
+
velocityResolutionScale: options.velocityResolutionScale
|
|
952
|
+
};
|
|
953
|
+
this.setSize(options.width, options.height);
|
|
954
|
+
this.makeOptionsReactive(options);
|
|
955
|
+
}
|
|
956
|
+
makeOptionsReactive(options) {
|
|
957
|
+
let needsUpdate = false;
|
|
958
|
+
const reflectionPassFullscreenMaterialUniforms = this.reflectionsPass.fullscreenMaterial.uniforms;
|
|
959
|
+
const reflectionPassFullscreenMaterialUniformsKeys = Object.keys(reflectionPassFullscreenMaterialUniforms);
|
|
960
|
+
for (const key of Object.keys(options)) {
|
|
961
|
+
Object.defineProperty(this, key, {
|
|
962
|
+
get() {
|
|
963
|
+
return options[key];
|
|
964
|
+
},
|
|
965
|
+
set(value) {
|
|
966
|
+
if (options[key] === value && needsUpdate)
|
|
967
|
+
return;
|
|
968
|
+
options[key] = value;
|
|
969
|
+
if (!noResetSamplesProperties.includes(key)) {
|
|
970
|
+
this.setSize(this.lastSize.width, this.lastSize.height, true);
|
|
971
|
+
}
|
|
972
|
+
switch (key) {
|
|
973
|
+
case "resolutionScale":
|
|
974
|
+
this.setSize(this.lastSize.width, this.lastSize.height);
|
|
975
|
+
break;
|
|
976
|
+
case "velocityResolutionScale":
|
|
977
|
+
this.temporalResolvePass.velocityResolutionScale = value;
|
|
978
|
+
this.setSize(this.lastSize.width, this.lastSize.height, true);
|
|
979
|
+
break;
|
|
980
|
+
case "blur":
|
|
981
|
+
this.uniforms.get("blur").value = value;
|
|
982
|
+
break;
|
|
983
|
+
case "blurSharpness":
|
|
984
|
+
this.uniforms.get("blurSharpness").value = value;
|
|
985
|
+
break;
|
|
986
|
+
case "blurKernel":
|
|
987
|
+
this.uniforms.get("blurKernel").value = value;
|
|
988
|
+
break;
|
|
989
|
+
case "steps":
|
|
990
|
+
this.reflectionsPass.fullscreenMaterial.defines.steps = parseInt(value);
|
|
991
|
+
this.reflectionsPass.fullscreenMaterial.needsUpdate = needsUpdate;
|
|
992
|
+
break;
|
|
993
|
+
case "refineSteps":
|
|
994
|
+
this.reflectionsPass.fullscreenMaterial.defines.refineSteps = parseInt(value);
|
|
995
|
+
this.reflectionsPass.fullscreenMaterial.needsUpdate = needsUpdate;
|
|
996
|
+
break;
|
|
997
|
+
case "missedRays":
|
|
998
|
+
if (value) {
|
|
999
|
+
this.reflectionsPass.fullscreenMaterial.defines.missedRays = "";
|
|
1000
|
+
} else {
|
|
1001
|
+
delete this.reflectionsPass.fullscreenMaterial.defines.missedRays;
|
|
1002
|
+
}
|
|
1003
|
+
this.reflectionsPass.fullscreenMaterial.needsUpdate = needsUpdate;
|
|
1004
|
+
break;
|
|
1005
|
+
case "correctionRadius":
|
|
1006
|
+
this.temporalResolvePass.fullscreenMaterial.defines.correctionRadius = Math.round(value);
|
|
1007
|
+
this.temporalResolvePass.fullscreenMaterial.needsUpdate = needsUpdate;
|
|
1008
|
+
break;
|
|
1009
|
+
case "blend":
|
|
1010
|
+
this.temporalResolvePass.fullscreenMaterial.uniforms.blend.value = value;
|
|
1011
|
+
break;
|
|
1012
|
+
case "correction":
|
|
1013
|
+
this.temporalResolvePass.fullscreenMaterial.uniforms.correction.value = value;
|
|
1014
|
+
break;
|
|
1015
|
+
case "exponent":
|
|
1016
|
+
this.temporalResolvePass.fullscreenMaterial.uniforms.exponent.value = value;
|
|
1017
|
+
break;
|
|
1018
|
+
case "distance":
|
|
1019
|
+
reflectionPassFullscreenMaterialUniforms.rayDistance.value = value;
|
|
1020
|
+
default:
|
|
1021
|
+
if (reflectionPassFullscreenMaterialUniformsKeys.includes(key)) {
|
|
1022
|
+
reflectionPassFullscreenMaterialUniforms[key].value = value;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
this[key] = options[key];
|
|
1028
|
+
}
|
|
1029
|
+
needsUpdate = true;
|
|
1030
|
+
}
|
|
1031
|
+
setSize(width, height, force = false) {
|
|
1032
|
+
if (!force && width === this.lastSize.width && height === this.lastSize.height && this.resolutionScale === this.lastSize.resolutionScale && this.velocityResolutionScale === this.lastSize.velocityResolutionScale)
|
|
1033
|
+
return;
|
|
1034
|
+
this.temporalResolvePass.setSize(width, height);
|
|
1035
|
+
this.reflectionsPass.setSize(width, height);
|
|
1036
|
+
this.lastSize = {
|
|
1037
|
+
width,
|
|
1038
|
+
height,
|
|
1039
|
+
resolutionScale: this.resolutionScale,
|
|
1040
|
+
velocityResolutionScale: this.velocityResolutionScale
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
generateBoxProjectedEnvMapFallback(renderer, position = new Vector3(), size = new Vector3(), envMapSize = 512) {
|
|
1044
|
+
this.cubeCamera.renderTarget.dispose();
|
|
1045
|
+
this.cubeCamera.renderTarget = new WebGLCubeRenderTarget(envMapSize);
|
|
1046
|
+
this.cubeCamera.position.copy(position);
|
|
1047
|
+
this.cubeCamera.updateMatrixWorld();
|
|
1048
|
+
this.cubeCamera.update(renderer, this._scene);
|
|
1049
|
+
if (!pmremGenerator) {
|
|
1050
|
+
pmremGenerator = new PMREMGenerator(renderer);
|
|
1051
|
+
pmremGenerator.compileCubemapShader();
|
|
1052
|
+
}
|
|
1053
|
+
const envMap = pmremGenerator.fromCubemap(this.cubeCamera.renderTarget.texture).texture;
|
|
1054
|
+
envMap.minFilter = LinearFilter;
|
|
1055
|
+
envMap.magFilter = LinearFilter;
|
|
1056
|
+
const reflectionsMaterial = this.reflectionsPass.fullscreenMaterial;
|
|
1057
|
+
useBoxProjectedEnvMap(reflectionsMaterial, position, size);
|
|
1058
|
+
reflectionsMaterial.fragmentShader = reflectionsMaterial.fragmentShader.replace("vec3 worldPos", "worldPos").replace("varying vec3 vWorldPosition;", "vec3 worldPos;");
|
|
1059
|
+
reflectionsMaterial.uniforms.envMapPosition.value.copy(position);
|
|
1060
|
+
reflectionsMaterial.uniforms.envMapSize.value.copy(size);
|
|
1061
|
+
setupEnvMap(reflectionsMaterial, envMap, envMapSize);
|
|
1062
|
+
this.usingBoxProjectedEnvMap = true;
|
|
1063
|
+
return envMap;
|
|
1064
|
+
}
|
|
1065
|
+
setIBLRadiance(iblRadiance, renderer) {
|
|
1066
|
+
this._scene.traverse((c) => {
|
|
1067
|
+
if (c.material) {
|
|
1068
|
+
var _renderer$properties$;
|
|
1069
|
+
const uniforms = (_renderer$properties$ = renderer.properties.get(c.material)) == null ? void 0 : _renderer$properties$.uniforms;
|
|
1070
|
+
if (uniforms && "disableIBLRadiance" in uniforms) {
|
|
1071
|
+
uniforms.disableIBLRadiance.value = iblRadiance;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
deleteBoxProjectedEnvMapFallback() {
|
|
1077
|
+
const reflectionsMaterial = this.reflectionsPass.fullscreenMaterial;
|
|
1078
|
+
reflectionsMaterial.uniforms.envMap.value = null;
|
|
1079
|
+
reflectionsMaterial.fragmentShader = reflectionsMaterial.fragmentShader.replace("worldPos = ", "vec3 worldPos = ");
|
|
1080
|
+
delete reflectionsMaterial.defines.BOX_PROJECTED_ENV_MAP;
|
|
1081
|
+
reflectionsMaterial.needsUpdate = true;
|
|
1082
|
+
this.usingBoxProjectedEnvMap = false;
|
|
1083
|
+
}
|
|
1084
|
+
dispose() {
|
|
1085
|
+
super.dispose();
|
|
1086
|
+
this.reflectionsPass.dispose();
|
|
1087
|
+
this.temporalResolvePass.dispose();
|
|
1088
|
+
}
|
|
1089
|
+
update(renderer, inputBuffer) {
|
|
1090
|
+
if (!this.usingBoxProjectedEnvMap && this._scene.environment) {
|
|
1091
|
+
const reflectionsMaterial = this.reflectionsPass.fullscreenMaterial;
|
|
1092
|
+
let envMap = null;
|
|
1093
|
+
this._scene.traverse((c) => {
|
|
1094
|
+
if (!envMap && c.material && !c.material.envMap) {
|
|
1095
|
+
const properties = renderer.properties.get(c.material);
|
|
1096
|
+
if ("envMap" in properties && properties.envMap instanceof Texture)
|
|
1097
|
+
envMap = properties.envMap;
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
if (envMap) {
|
|
1101
|
+
const envMapCubeUVHeight = this._scene.environment.image.height;
|
|
1102
|
+
setupEnvMap(reflectionsMaterial, envMap, envMapCubeUVHeight);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
this.haltonIndex = (this.haltonIndex + 1) % this.haltonSequence.length;
|
|
1106
|
+
const [x, y] = this.haltonSequence[this.haltonIndex];
|
|
1107
|
+
const { width, height } = this.lastSize;
|
|
1108
|
+
this.temporalResolvePass.velocityPass.render(renderer);
|
|
1109
|
+
if (this._camera.setViewOffset)
|
|
1110
|
+
this._camera.setViewOffset(width, height, x, y, width, height);
|
|
1111
|
+
this.reflectionsPass.render(renderer, inputBuffer);
|
|
1112
|
+
this.temporalResolvePass.render(renderer);
|
|
1113
|
+
this._camera.clearViewOffset();
|
|
1114
|
+
}
|
|
1115
|
+
static patchDirectEnvIntensity(envMapIntensity = 0) {
|
|
1116
|
+
if (envMapIntensity === 0) {
|
|
1117
|
+
ShaderChunk.envmap_physical_pars_fragment = ShaderChunk.envmap_physical_pars_fragment.replace(
|
|
1118
|
+
"vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {",
|
|
1119
|
+
"vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { return vec3(0.0);"
|
|
1120
|
+
);
|
|
1121
|
+
} else {
|
|
1122
|
+
ShaderChunk.envmap_physical_pars_fragment = ShaderChunk.envmap_physical_pars_fragment.replace(
|
|
1123
|
+
"vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );",
|
|
1124
|
+
"vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness ) * " + envMapIntensity.toFixed(5) + ";"
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
export {
|
|
1130
|
+
SSREffect,
|
|
1131
|
+
defaultSSROptions
|
|
1132
|
+
};
|
|
1133
|
+
//# sourceMappingURL=screen-space-reflections.js.map
|