@react-three/postprocessing 2.15.4 → 2.15.6

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.
Files changed (46) hide show
  1. package/dist/effects/N8AO/BlueNoise.cjs +4 -0
  2. package/dist/effects/N8AO/BlueNoise.cjs.map +1 -0
  3. package/dist/effects/N8AO/BlueNoise.js +5 -0
  4. package/dist/effects/N8AO/BlueNoise.js.map +1 -0
  5. package/dist/effects/N8AO/DepthDownSample.cjs +183 -0
  6. package/dist/effects/N8AO/DepthDownSample.cjs.map +1 -0
  7. package/dist/effects/N8AO/DepthDownSample.js +166 -0
  8. package/dist/effects/N8AO/DepthDownSample.js.map +1 -0
  9. package/dist/effects/N8AO/EffectCompositer.cjs +276 -0
  10. package/dist/effects/N8AO/EffectCompositer.cjs.map +1 -0
  11. package/dist/effects/N8AO/EffectCompositer.js +259 -0
  12. package/dist/effects/N8AO/EffectCompositer.js.map +1 -0
  13. package/dist/effects/N8AO/EffectShader.cjs +236 -0
  14. package/dist/effects/N8AO/EffectShader.cjs.map +1 -0
  15. package/dist/effects/N8AO/EffectShader.js +219 -0
  16. package/dist/effects/N8AO/EffectShader.js.map +1 -0
  17. package/dist/effects/N8AO/FullScreenTriangle.cjs +59 -0
  18. package/dist/effects/N8AO/FullScreenTriangle.cjs.map +1 -0
  19. package/dist/effects/N8AO/FullScreenTriangle.js +42 -0
  20. package/dist/effects/N8AO/FullScreenTriangle.js.map +1 -0
  21. package/dist/effects/N8AO/N8AOPostPass.cjs +501 -0
  22. package/dist/effects/N8AO/N8AOPostPass.cjs.map +1 -0
  23. package/dist/effects/N8AO/N8AOPostPass.js +484 -0
  24. package/dist/effects/N8AO/N8AOPostPass.js.map +1 -0
  25. package/dist/effects/N8AO/PoissionBlur.cjs +186 -0
  26. package/dist/effects/N8AO/PoissionBlur.cjs.map +1 -0
  27. package/dist/effects/N8AO/PoissionBlur.js +169 -0
  28. package/dist/effects/N8AO/PoissionBlur.js.map +1 -0
  29. package/dist/effects/{N8AO.cjs → N8AO/index.cjs} +3 -3
  30. package/dist/effects/N8AO/index.cjs.map +1 -0
  31. package/dist/effects/{N8AO.js → N8AO/index.js} +3 -3
  32. package/dist/effects/N8AO/index.js.map +1 -0
  33. package/dist/effects/SSR/screen-space-reflections.cjs +664 -105
  34. package/dist/effects/SSR/screen-space-reflections.cjs.map +1 -1
  35. package/dist/effects/SSR/screen-space-reflections.js +664 -105
  36. package/dist/effects/SSR/screen-space-reflections.js.map +1 -1
  37. package/dist/index.cjs +2 -2
  38. package/dist/index.js +1 -1
  39. package/package.json +2 -1
  40. package/dist/effects/N8AO.cjs.map +0 -1
  41. package/dist/effects/N8AO.js.map +0 -1
  42. package/dist/node_modules/n8ao/dist/N8AO.cjs +0 -1439
  43. package/dist/node_modules/n8ao/dist/N8AO.cjs.map +0 -1
  44. package/dist/node_modules/n8ao/dist/N8AO.js +0 -1439
  45. package/dist/node_modules/n8ao/dist/N8AO.js.map +0 -1
  46. /package/dist/effects/{N8AO.d.ts → N8AO/index.d.ts} +0 -0
@@ -2,10 +2,173 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const postprocessing = require("postprocessing");
4
4
  const THREE = require("three");
5
- 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;}";
6
- 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}";
7
- 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));}";
8
- 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);}";
5
+ const boxBlur = (
6
+ /* glsl */
7
+ `
8
+ uniform float blur;
9
+ uniform float blurSharpness;
10
+ uniform int blurKernel;
11
+
12
+ vec3 denoise(
13
+ vec3 center,
14
+ sampler2D tex,
15
+ vec2 uv,
16
+ vec2 invTexSize,
17
+ float blur,
18
+ float blurSharpness,
19
+ int blurKernel
20
+ ) {
21
+ vec3 color, col;
22
+ float total, weight;
23
+
24
+ for (int x = -blurKernel; x <= blurKernel; x++) {
25
+ for (int y=-blurKernel; y<=blurKernel; y++) {
26
+ col = textureLod(tex, uv + vec2(x,y) * invTexSize, 0.0).rgb;
27
+ weight = 1.0-abs(dot(col - center, vec3(0.25)));
28
+ weight = pow(weight, blurSharpness);
29
+ color += col * weight;
30
+ total += weight;
31
+ }
32
+ }
33
+
34
+ return color / total;
35
+ }
36
+ `
37
+ );
38
+ const finalSSRShader = (
39
+ /* glsl */
40
+ `
41
+ #define MODE_DEFAULT 0
42
+ #define MODE_REFLECTIONS 1
43
+ #define MODE_RAW_REFLECTION 2
44
+ #define MODE_BLURRED_REFLECTIONS 3
45
+ #define MODE_INPUT 4
46
+ #define MODE_BLUR_MIX 5
47
+ #define FLOAT_EPSILON 0.00001
48
+ // uniform sampler2D inputTexture;
49
+ uniform sampler2D reflectionsTexture;
50
+ // uniform float samples;
51
+
52
+ ${boxBlur}
53
+
54
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
55
+ vec4 reflectionsTexel=texture2D(reflectionsTexture, vUv);
56
+ ivec2 size = textureSize(reflectionsTexture, 0);
57
+ vec2 invTexSize= 1.0 / vec2(size.x, size.y);
58
+ vec3 reflectionClr = reflectionsTexel.xyz;
59
+ if (blur > FLOAT_EPSILON) {
60
+ vec3 blurredReflectionsColor = denoise(
61
+ reflectionsTexel.rgb,
62
+ reflectionsTexture,
63
+ vUv,
64
+ invTexSize,
65
+ blur,
66
+ blurSharpness,
67
+ blurKernel
68
+ );
69
+ reflectionClr = mix(reflectionClr, blurredReflectionsColor.rgb, blur);
70
+ }
71
+
72
+ #if RENDER_MODE == MODE_DEFAULT
73
+ outputColor = vec4(inputColor.rgb+reflectionClr, 1.0);
74
+ #endif
75
+ #if RENDER_MODE == MODE_REFLECTIONS
76
+ outputColor = vec4(reflectionClr, 1.0);
77
+ #endif
78
+ #if RENDER_MODE == MODE_RAW_REFLECTION
79
+ outputColor = vec4(reflectionsTexel.xyz, 1.0);
80
+ #endif
81
+ #if RENDER_MODE == MODE_BLURRED_REFLECTIONS
82
+ outputColor = vec4(blurredReflectionsTexel.xyz, 1.0);
83
+ #endif
84
+ #if RENDER_MODE == MODE_INPUT
85
+ outputColor = vec4(inputColor.xyz, 1.0);
86
+ #endif
87
+ #if RENDER_MODE == MODE_BLUR_MIX
88
+ outputColor = vec4(vec3(blur), 1.0);
89
+ #endif
90
+ }
91
+ `
92
+ );
93
+ const helperFunctions = (
94
+ /* glsl */
95
+ `
96
+ vec3 getViewPosition(const float depth) {
97
+ float clipW= _projectionMatrix[2][3] * depth + _projectionMatrix[3][3];
98
+ vec4 clipPosition = vec4((vec3(vUv, depth) - 0.5) * 2.0, 1.0);
99
+ clipPosition *= clipW;
100
+ return(_inverseProjectionMatrix * clipPosition).xyz;
101
+ }
102
+
103
+ float getViewZ(const in float depth) {
104
+ #ifdef PERSPECTIVE_CAMERA
105
+ return perspectiveDepthToViewZ(depth, cameraNear, cameraFar);
106
+ #else
107
+ return orthographicDepthToViewZ(depth, cameraNear, cameraFar);
108
+ #endif
109
+ }
110
+
111
+ vec3 screenSpaceToWorldSpace(const vec2 uv,const float depth){
112
+ vec4 ndc = vec4((uv.x - 0.5) * 2.0,(uv.y - 0.5)* 2.0, (depth - 0.5) * 2.0, 1.0);
113
+ vec4 clip= _inverseProjectionMatrix*ndc;
114
+ vec4 view = cameraMatrixWorld * (clip / clip.w);
115
+ return view.xyz;
116
+ }
117
+
118
+ #define Scale (vec3(0.8, 0.8, 0.8))
119
+ #define K (19.19)
120
+
121
+ vec3 hash(vec3 a) {
122
+ a = fract(a * Scale);
123
+ a += dot(a, a.yxz + K);
124
+ return fract((a.xxy + a.yxx) * a.zyx);
125
+ }
126
+
127
+ float fresnel_dielectric_cos(float cosi, float eta){
128
+ float c = abs(cosi);
129
+ float g = eta * eta - 1.0 + c* c;
130
+ float result;
131
+
132
+ if (g > 0.0){
133
+ g = sqrt(g);
134
+ float A = (g - c) / (g + c);
135
+ float B = (c* (g + c) - 1.0) / (c * (g - c) + 1.0);
136
+ result = 0.5 * A * A * (1.0 + B * B);
137
+ } else {
138
+ result = 1.0;
139
+ }
140
+
141
+ return result;
142
+ }
143
+
144
+ float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta){
145
+ float cosine = dot(Incoming, Normal);
146
+ return min(1.0, 5.0 * fresnel_dielectric_cos(cosine, eta));
147
+ }
148
+ `
149
+ );
150
+ const trCompose = (
151
+ /* glsl */
152
+ `
153
+ #define INV_EULER 0.36787944117144233
154
+
155
+ alpha = velocityDisocclusion < FLOAT_EPSILON ? (alpha + 0.0075) : 0.0;
156
+ alpha = clamp(alpha, 0.0, 1.0);
157
+ bool needsBlur = !didReproject || velocityDisocclusion > 0.5;
158
+
159
+ #ifdef boxBlur
160
+ if (needsBlur) inputColor = boxBlurredColor;
161
+ #endif
162
+
163
+ if (alpha == 1.0) {
164
+ outputColor = accumulatedColor;
165
+ } else {
166
+ float m = mix(alpha, 1.0, blend);
167
+ if (needsBlur) m = 0.0;
168
+ outputColor = accumulatedColor * m + inputColor * (1.0 - m);
169
+ }
170
+ `
171
+ );
9
172
  class MRTMaterial extends THREE.ShaderMaterial {
10
173
  constructor() {
11
174
  super({
@@ -25,103 +188,102 @@ class MRTMaterial extends THREE.ShaderMaterial {
25
188
  vertexShader: (
26
189
  /* glsl */
27
190
  `
28
- #ifdef USE_MRT
29
- varying vec2 vHighPrecisionZW;
30
- #endif
31
- #define NORMAL
32
- #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
33
- varying vec3 vViewPosition;
34
- #endif
35
- #include <common>
36
- #include <uv_pars_vertex>
37
- #include <displacementmap_pars_vertex>
38
- #include <normal_pars_vertex>
39
- #include <morphtarget_pars_vertex>
40
- #include <skinning_pars_vertex>
41
- #include <logdepthbuf_pars_vertex>
42
- #include <clipping_planes_pars_vertex>
43
- #ifdef USE_UV
44
- ${THREE.REVISION.replace(/\D+/g, "") >= 151 ? "uniform mat3 uvTransform;" : ""}
45
- #endif
46
- void main() {
47
- #include <uv_vertex>
48
- #include <beginnormal_vertex>
49
- #include <morphnormal_vertex>
50
- #include <skinbase_vertex>
51
- #include <skinnormal_vertex>
52
- #include <defaultnormal_vertex>
53
- #include <normal_vertex>
54
- #include <begin_vertex>
55
- #include <morphtarget_vertex>
56
- #include <skinning_vertex>
57
- #include <displacementmap_vertex>
58
- #include <project_vertex>
59
- #include <logdepthbuf_vertex>
60
- #include <clipping_planes_vertex>
61
- #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
62
- vViewPosition = - mvPosition.xyz;
63
- #endif
64
- #ifdef USE_MRT
65
- vHighPrecisionZW = gl_Position.zw;
66
- #endif
67
- #ifdef USE_UV
68
- vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
69
- #endif
70
- }
71
- `
191
+ #ifdef USE_MRT
192
+ varying vec2 vHighPrecisionZW;
193
+ #endif
194
+ #define NORMAL
195
+ #if defined(FLAT_SHADED) || defined(USE_BUMPMAP) || defined(TANGENTSPACE_NORMALMAP)
196
+ varying vec3 vViewPosition;
197
+ #endif
198
+ #include <common>
199
+ #include <uv_pars_vertex>
200
+ #include <displacementmap_pars_vertex>
201
+ #include <normal_pars_vertex>
202
+ #include <morphtarget_pars_vertex>
203
+ #include <skinning_pars_vertex>
204
+ #include <logdepthbuf_pars_vertex>
205
+ #include <clipping_planes_pars_vertex>
206
+ #ifdef USE_UV
207
+ ${THREE.REVISION.replace(/\D+/g, "") >= 151 ? "uniform mat3 uvTransform;" : ""}
208
+ #endif
209
+ void main() {
210
+ #include <uv_vertex>
211
+ #include <beginnormal_vertex>
212
+ #include <morphnormal_vertex>
213
+ #include <skinbase_vertex>
214
+ #include <skinnormal_vertex>
215
+ #include <defaultnormal_vertex>
216
+ #include <normal_vertex>
217
+ #include <begin_vertex>
218
+ #include <morphtarget_vertex>
219
+ #include <skinning_vertex>
220
+ #include <displacementmap_vertex>
221
+ #include <project_vertex>
222
+ #include <logdepthbuf_vertex>
223
+ #include <clipping_planes_vertex>
224
+ #if defined(FLAT_SHADED) || defined(USE_BUMPMAP) || defined(TANGENTSPACE_NORMALMAP)
225
+ vViewPosition = -mvPosition.xyz;
226
+ #endif
227
+ #ifdef USE_MRT
228
+ vHighPrecisionZW = gl_Position.zw;
229
+ #endif
230
+ #ifdef USE_UV
231
+ vUv = (uvTransform * vec3(uv, 1)).xy;
232
+ #endif
233
+ }
234
+ `
72
235
  ),
73
236
  fragmentShader: (
74
237
  /* glsl */
75
238
  `
76
- #define NORMAL
77
- #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
78
- varying vec3 vViewPosition;
79
- #endif
80
- #include <packing>
81
- #include <uv_pars_fragment>
82
- #include <normal_pars_fragment>
83
- #include <bumpmap_pars_fragment>
84
- #include <normalmap_pars_fragment>
85
- #include <logdepthbuf_pars_fragment>
86
- #include <clipping_planes_pars_fragment>
87
- #include <roughnessmap_pars_fragment>
88
-
89
- #ifdef USE_MRT
90
- layout(location = 0) out vec4 gNormal;
91
- layout(location = 1) out vec4 gDepth;
92
-
93
- varying vec2 vHighPrecisionZW;
94
- #endif
95
- uniform float roughness;
96
- void main() {
97
- #include <clipping_planes_fragment>
98
- #include <logdepthbuf_fragment>
99
- #include <normal_fragment_begin>
100
- #include <normal_fragment_maps>
101
-
102
- float roughnessFactor = roughness;
103
-
104
- if(roughness > 10.0e9){
105
- roughnessFactor = 1.;
106
- }else{
107
- #ifdef useRoughnessMap
108
- vec4 texelRoughness = texture2D( roughnessMap, vUv );
109
- // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
110
- roughnessFactor *= texelRoughness.g;
111
- #endif
112
- }
113
-
114
- vec3 normalColor = packNormalToRGB( normal );
115
- #ifdef USE_MRT
116
- float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
117
- vec4 depthColor = packDepthToRGBA( fragCoordZ );
118
- gNormal = vec4( normalColor, roughnessFactor );
119
- gDepth = depthColor;
120
- #else
121
- gl_FragColor = vec4(normalColor, roughnessFactor);
122
- #endif
123
- }
124
- `
239
+ #define NORMAL
240
+ #if defined(FLAT_SHADED) || defined(USE_BUMPMAP) || defined(TANGENTSPACE_NORMALMAP)
241
+ varying vec3 vViewPosition;
242
+ #endif
243
+ #include <packing>
244
+ #include <uv_pars_fragment>
245
+ #include <normal_pars_fragment>
246
+ #include <bumpmap_pars_fragment>
247
+ #include <normalmap_pars_fragment>
248
+ #include <logdepthbuf_pars_fragment>
249
+ #include <clipping_planes_pars_fragment>
250
+ #include <roughnessmap_pars_fragment>
251
+
252
+ #ifdef USE_MRT
253
+ layout(location = 0) out vec4 gNormal;
254
+ layout(location = 1) out vec4 gDepth;
255
+ varying vec2 vHighPrecisionZW;
256
+ #endif
257
+ uniform float roughness;
258
+ void main() {
259
+ #include <clipping_planes_fragment>
260
+ #include <logdepthbuf_fragment>
261
+ #include <normal_fragment_begin>
262
+ #include <normal_fragment_maps>
263
+
264
+ float roughnessFactor = roughness;
265
+
266
+ if (roughness > 10.0e9){
267
+ roughnessFactor = 1.;
268
+ } else {
269
+ #ifdef useRoughnessMap
270
+ vec4 texelRoughness = texture2D(roughnessMap, vUv);
271
+ // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
272
+ roughnessFactor *= texelRoughness.g;
273
+ #endif
274
+ }
275
+
276
+ vec3 normalColor = packNormalToRGB(normal);
277
+ #ifdef USE_MRT
278
+ float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
279
+ vec4 depthColor = packDepthToRGBA(fragCoordZ);
280
+ gNormal = vec4(normalColor, roughnessFactor);
281
+ gDepth = depthColor;
282
+ #else
283
+ gl_FragColor = vec4(normalColor, roughnessFactor);
284
+ #endif
285
+ }
286
+ `
125
287
  ),
126
288
  toneMapped: false
127
289
  });
@@ -136,8 +298,254 @@ class MRTMaterial extends THREE.ShaderMaterial {
136
298
  });
137
299
  }
138
300
  }
139
- 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);}";
140
- 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}";
301
+ const vertexShader = (
302
+ /* glsl */
303
+ `
304
+ varying vec2 vUv;
305
+
306
+ void main() {
307
+ vUv = position.xy * 0.5 + 0.5;
308
+ gl_Position = vec4(position.xy, 1.0, 1.0);
309
+ }
310
+ `
311
+ );
312
+ const fragmentShader = (
313
+ /* glsl */
314
+ `
315
+ varying vec2 vUv;
316
+ uniform sampler2D inputTexture;
317
+ uniform sampler2D accumulatedTexture;
318
+ uniform sampler2D normalTexture;
319
+ uniform sampler2D depthTexture;
320
+ uniform sampler2D envMap;
321
+ uniform mat4 _projectionMatrix;
322
+ uniform mat4 _inverseProjectionMatrix;
323
+ uniform mat4 cameraMatrixWorld;
324
+ uniform float cameraNear;
325
+ uniform float cameraFar;
326
+ uniform float rayDistance;
327
+ uniform float intensity;
328
+ uniform float maxDepthDifference;
329
+ uniform float roughnessFade;
330
+ uniform float maxRoughness;
331
+ uniform float fade;
332
+ uniform float thickness;
333
+ uniform float ior;
334
+ uniform float samples;
335
+ uniform float jitter;
336
+ uniform float jitterRoughness;
337
+
338
+ #define INVALID_RAY_COORDS vec2(-1.0);
339
+
340
+ #define EARLY_OUT_COLOR vec4(0.0, 0.0, 0.0, 1.0)
341
+ #define FLOAT_EPSILON 0.00001
342
+ float nearMinusFar;
343
+ float nearMulFar;
344
+ float farMinusNear;
345
+
346
+ #include <packing>
347
+
348
+ ${helperFunctions}
349
+
350
+ vec2 RayMarch(vec3 dir, inout vec3 hitPos, inout float rayHitDepthDifference);
351
+ vec2 BinarySearch(in vec3 dir, inout vec3 hitPos, inout float rayHitDepthDifference);
352
+ float fastGetViewZ(const in float depth);
353
+ vec3 getIBLRadiance(const in vec3 viewDir, const in vec3 normal, const in float roughness);
354
+
355
+ void main() {
356
+ vec4 depthTexel = textureLod(depthTexture, vUv, 0.0);
357
+
358
+ if (dot(depthTexel.rgb, depthTexel.rgb) < FLOAT_EPSILON) {
359
+ gl_FragColor = EARLY_OUT_COLOR;
360
+ return;
361
+ }
362
+
363
+ float unpackedDepth = unpackRGBAToDepth(depthTexel);
364
+ vec4 normalTexel = textureLod(normalTexture, vUv, 0.0);
365
+ float roughness = normalTexel.a;
366
+ float specular = 1.0 - roughness;
367
+
368
+ nearMinusFar = cameraNear - cameraFar;
369
+ nearMulFar = cameraNear * cameraFar;
370
+ farMinusNear = cameraFar - cameraNear;
371
+
372
+ normalTexel.rgb = unpackRGBToNormal(normalTexel.rgb);
373
+
374
+ float depth = fastGetViewZ(unpackedDepth);
375
+ vec3 viewPos = getViewPosition(depth);
376
+ vec3 viewDir = normalize(viewPos);
377
+ vec3 viewNormal = normalTexel.xyz;
378
+ vec3 worldPos = screenSpaceToWorldSpace(vUv, unpackedDepth);
379
+
380
+ vec3 jitt=vec3(0.0);
381
+ if (jitterRoughness != 0.0 || jitter!=0.0){
382
+ vec3 randomJitter = hash(50.0 * samples * worldPos) - 0.5;
383
+ float spread= ((2.0 - specular) + roughness * jitterRoughness);
384
+ float jitterMix = jitter * 0.25 + jitterRoughness * roughness;
385
+ if (jitterMix > 1.0) jitterMix = 1.0;
386
+ jitt = mix(vec3(0.0), randomJitter * spread, jitterMix);
387
+ }
388
+
389
+ viewNormal += jitt;
390
+ float fresnelFactor = fresnel_dielectric(viewDir, viewNormal, ior);
391
+ vec3 iblRadiance = getIBLRadiance(-viewDir, viewNormal, 0.0) * fresnelFactor;
392
+ float lastFrameAlpha = textureLod(accumulatedTexture, vUv, 0.0).a;
393
+ if (roughness > maxRoughness || (roughness > 1.0 - FLOAT_EPSILON && roughnessFade > 1.0 - FLOAT_EPSILON)) {
394
+ gl_FragColor=vec4(iblRadiance,lastFrameAlpha);
395
+ return;
396
+ }
397
+
398
+ vec3 reflected = reflect(viewDir, viewNormal);
399
+ vec3 rayDir = reflected *- viewPos.z;
400
+ vec3 hitPos = viewPos;
401
+ float rayHitDepthDifference;
402
+ vec2 coords = RayMarch(rayDir, hitPos, rayHitDepthDifference);
403
+ if (coords.x == -1.0){
404
+ gl_FragColor=vec4(iblRadiance, lastFrameAlpha);
405
+ return;
406
+ }
407
+
408
+ vec4 SSRTexel = textureLod(inputTexture, coords.xy, 0.0);
409
+ vec4 SSRTexelReflected = textureLod(accumulatedTexture, coords.xy, 0.0);
410
+ vec3 SSR = SSRTexel.rgb + SSRTexelReflected.rgb;
411
+ float roughnessFactor = mix(specular, 1.0, max(0.0, 1.0 - roughnessFade));
412
+ vec2 coordsNDC = (coords.xy * 2.0 - 1.0);
413
+ float screenFade = 0.1;
414
+ float maxDimension = min(1.0, max(abs(coordsNDC.x), abs(coordsNDC.y)));
415
+ float reflectionIntensity = 1.0 - (max(0.0, maxDimension - screenFade) / (1.0 - screenFade));
416
+ reflectionIntensity = max(0.0, reflectionIntensity);
417
+ vec3 finalSSR = mix(iblRadiance, SSR, reflectionIntensity) * roughnessFactor;
418
+
419
+ if (fade != 0.0) {
420
+ vec3 hitWorldPos = screenSpaceToWorldSpace(coords, rayHitDepthDifference);
421
+ float reflectionDistance = distance(hitWorldPos, worldPos) + 1.0;
422
+ float opacity = 1.0 / (reflectionDistance * fade * 0.1);
423
+ if(opacity > 1.0) opacity=1.0;
424
+ finalSSR *= opacity;
425
+ }
426
+
427
+ finalSSR *= fresnelFactor * intensity;
428
+ finalSSR = min(vec3(1.0), finalSSR);
429
+ float alpha = hitPos.z == 1.0 ? 1.0 : SSRTexelReflected.a;
430
+ alpha = min(lastFrameAlpha, alpha);
431
+ gl_FragColor = vec4(finalSSR, alpha);
432
+ }
433
+
434
+ vec2 RayMarch(vec3 dir, inout vec3 hitPos, inout float rayHitDepthDifference) {
435
+ dir=normalize(dir);
436
+ dir *= rayDistance / float(steps);
437
+ float depth;
438
+ vec4 projectedCoord;
439
+ vec4 lastProjectedCoord;
440
+ float unpackedDepth;
441
+ vec4 depthTexel;
442
+
443
+ for (int i = 0; i < steps; i++) {
444
+ hitPos += dir;
445
+ projectedCoord = _projectionMatrix * vec4(hitPos, 1.0);
446
+ projectedCoord.xy /= projectedCoord.w;
447
+ projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
448
+
449
+ #ifndef missedRays
450
+ if (
451
+ projectedCoord.x < 0.0 ||
452
+ projectedCoord.x > 1.0 ||
453
+ projectedCoord.y < 0.0 ||
454
+ projectedCoord.y > 1.0
455
+ ) {
456
+ return INVALID_RAY_COORDS;
457
+ }
458
+ #endif
459
+
460
+ depthTexel = textureLod(depthTexture, projectedCoord.xy, 0.0);
461
+ unpackedDepth = unpackRGBAToDepth(depthTexel);
462
+ depth = fastGetViewZ(unpackedDepth);
463
+ rayHitDepthDifference = depth - hitPos.z;
464
+
465
+ if (rayHitDepthDifference >= 0.0 && rayHitDepthDifference < thickness){
466
+ #if refineSteps == 0
467
+ if (dot(depthTexel.rgb, depthTexel.rgb) < FLOAT_EPSILON) return INVALID_RAY_COORDS;
468
+ #else
469
+ return BinarySearch(dir, hitPos, rayHitDepthDifference);
470
+ #endif
471
+ }
472
+
473
+ #ifndef missedRays
474
+ if (hitPos.z > 0.0) return INVALID_RAY_COORDS;
475
+ #endif
476
+
477
+ lastProjectedCoord = projectedCoord;
478
+ }
479
+
480
+ hitPos.z = 1.0;
481
+
482
+ #ifndef missedRays
483
+ return INVALID_RAY_COORDS;
484
+ #endif
485
+
486
+ rayHitDepthDifference = unpackedDepth;
487
+
488
+ return projectedCoord.xy;
489
+ }
490
+
491
+ vec2 BinarySearch(in vec3 dir, inout vec3 hitPos, inout float rayHitDepthDifference) {
492
+ float depth;
493
+ vec4 projectedCoord;
494
+ vec2 lastMinProjectedCoordXY;
495
+ float unpackedDepth;
496
+ vec4 depthTexel;
497
+
498
+ for (int i = 0; i < refineSteps; i++){
499
+ projectedCoord = _projectionMatrix * vec4(hitPos, 1.0);
500
+ projectedCoord.xy /= projectedCoord.w;
501
+ projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
502
+ depthTexel = textureLod(depthTexture, projectedCoord.xy, 0.0);
503
+ unpackedDepth = unpackRGBAToDepth(depthTexel);
504
+ depth = fastGetViewZ(unpackedDepth);
505
+ rayHitDepthDifference = depth - hitPos.z;
506
+ dir *= 0.5;
507
+
508
+ if (rayHitDepthDifference > 0.0) {
509
+ hitPos -= dir;
510
+ } else {
511
+ hitPos += dir;
512
+ }
513
+ }
514
+
515
+ if (dot(depthTexel.rgb, depthTexel.rgb) < FLOAT_EPSILON) return INVALID_RAY_COORDS;
516
+ if (abs(rayHitDepthDifference) > maxDepthDifference) return INVALID_RAY_COORDS;
517
+
518
+ projectedCoord = _projectionMatrix*vec4(hitPos, 1.0);
519
+ projectedCoord.xy /= projectedCoord.w;
520
+ projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
521
+ rayHitDepthDifference = unpackedDepth;
522
+ return projectedCoord.xy;
523
+ }
524
+
525
+ float fastGetViewZ(const in float depth){
526
+ #ifdef PERSPECTIVE_CAMERA
527
+ return nearMulFar / (farMinusNear * depth - cameraFar);
528
+ #else
529
+ return depth * nearMinusFar - cameraNear;
530
+ #endif
531
+ }
532
+
533
+ #include <common>
534
+ #include <cube_uv_reflection_fragment>
535
+
536
+ vec3 getIBLRadiance(const in vec3 viewDir, const in vec3 normal, const in float roughness){
537
+ #if defined(ENVMAP_TYPE_CUBE_UV)
538
+ vec3 reflectVec = reflect(-viewDir, normal);
539
+ reflectVec = normalize(mix(reflectVec, normal,roughness * roughness));
540
+ reflectVec = inverseTransformDirection(reflectVec, viewMatrix);
541
+ vec4 envMapColor = textureCubeUV(envMap, reflectVec, roughness);
542
+ return envMapColor.rgb * intensity;
543
+ #else
544
+ return vec3(0.0);
545
+ #endif
546
+ }
547
+ `
548
+ );
141
549
  class ReflectionsMaterial extends THREE.ShaderMaterial {
142
550
  constructor() {
143
551
  super({
@@ -176,8 +584,8 @@ class ReflectionsMaterial extends THREE.ShaderMaterial {
176
584
  CUBEUV_MAX_MIP: 0,
177
585
  vWorldPosition: "worldPos"
178
586
  },
179
- fragmentShader: fragmentShader.replace("#include <helperFunctions>", helperFunctions),
180
- vertexShader: vertexShader$1,
587
+ fragmentShader,
588
+ vertexShader,
181
589
  toneMapped: false,
182
590
  depthWrite: false,
183
591
  depthTest: false
@@ -399,8 +807,160 @@ const defaultSSROptions = {
399
807
  resolutionScale: 1,
400
808
  velocityResolutionScale: 1
401
809
  };
402
- 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);}";
403
- 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);}";
810
+ const temporalResolve = (
811
+ /* glsl */
812
+ `
813
+ uniform sampler2D inputTexture;
814
+ uniform sampler2D accumulatedTexture;
815
+ uniform sampler2D velocityTexture;
816
+ uniform sampler2D lastVelocityTexture;
817
+ uniform float blend;
818
+ uniform float correction;
819
+ uniform float exponent;
820
+ uniform float samples;
821
+ uniform vec2 invTexSize;
822
+ uniform mat4 curInverseProjectionMatrix;
823
+ uniform mat4 curCameraMatrixWorld;
824
+ uniform mat4 prevInverseProjectionMatrix;
825
+ uniform mat4 prevCameraMatrixWorld;
826
+ varying vec2 vUv;
827
+
828
+ #define MAX_NEIGHBOR_DEPTH_DIFFERENCE 0.001
829
+ #define FLOAT_EPSILON 0.00001
830
+ #define FLOAT_ONE_MINUS_EPSILON 0.99999
831
+
832
+ vec3 transformexponent;
833
+ vec3 undoColorTransformExponent;
834
+
835
+ vec3 transformColor(vec3 color) {
836
+ if (exponent == 1.0) return color;
837
+ return pow(abs(color), transformexponent);
838
+ }
839
+
840
+ vec3 undoColorTransform(vec3 color) {
841
+ if (exponent == 1.0) return color;
842
+ return max(pow(abs(color), undoColorTransformExponent), vec3(0.0));
843
+ }
844
+
845
+ void main() {
846
+ if (exponent != 1.0){
847
+ transformexponent = vec3(1.0 / exponent);
848
+ undoColorTransformExponent = vec3(exponent);
849
+ }
850
+
851
+ vec4 inputTexel = textureLod(inputTexture, vUv, 0.0);
852
+ vec4 accumulatedTexel;
853
+ vec3 inputColor = transformColor(inputTexel.rgb);
854
+ vec3 accumulatedColor;
855
+ float alpha = inputTexel.a;
856
+ float velocityDisocclusion;
857
+ bool didReproject = false;
858
+
859
+ #ifdef boxBlur
860
+ vec3 boxBlurredColor = inputTexel.rgb;
861
+ #endif
862
+
863
+ vec4 velocity = textureLod(velocityTexture, vUv, 0.0);
864
+ bool isMoving = alpha < 1.0 || dot(velocity.xy, velocity.xy) > 0.0;
865
+ if (isMoving) {
866
+ vec3 minNeighborColor = inputColor;
867
+ vec3 maxNeighborColor = inputColor;
868
+ vec3 col;
869
+ vec2 neighborUv;
870
+ vec2 reprojectedUv = vUv-velocity.xy;
871
+ vec4 lastVelocity = textureLod(lastVelocityTexture, reprojectedUv, 0.0);
872
+ float depth = velocity.b;
873
+ float closestDepth = depth;
874
+ float lastClosestDepth = lastVelocity.b;
875
+ float neighborDepth;
876
+ float lastNeighborDepth;
877
+
878
+ for (int x = -correctionRadius; x <= correctionRadius; x++) {
879
+ for (int y = -correctionRadius; y <= correctionRadius; y++) {
880
+ if (x != 0 || y != 0) {
881
+ neighborUv = vUv + vec2(x,y) * invTexSize;
882
+ vec4 neigborVelocity = textureLod(velocityTexture, neighborUv, 0.0);
883
+ neighborDepth = neigborVelocity.b;
884
+ col = textureLod(inputTexture, neighborUv, 0.0).xyz;
885
+ int absX = abs(x);
886
+ int absY = abs(y);
887
+
888
+ #ifdef dilation
889
+ if (absX == 1 && absY == 1) {
890
+ if (neighborDepth > closestDepth) {
891
+ velocity=neigborVelocity;
892
+ closestDepth=neighborDepth;
893
+ }
894
+
895
+ vec4 lastNeighborVelocity = textureLod(velocityTexture, vUv + vec2(x, y) * invTexSize, 0.0);
896
+ lastNeighborDepth = lastNeighborVelocity.b;
897
+
898
+ if (neighborDepth > closestDepth) {
899
+ lastVelocity = lastNeighborVelocity;
900
+ lastClosestDepth = lastNeighborDepth;
901
+ }
902
+ }
903
+ #endif
904
+
905
+ if (abs(depth-neighborDepth) < MAX_NEIGHBOR_DEPTH_DIFFERENCE) {
906
+ #ifdef boxBlur
907
+ if (absX <= 2 && absY <= 2) boxBlurredColor += col;
908
+ #endif
909
+
910
+ col = transformColor(col);
911
+ minNeighborColor = min(col, minNeighborColor);
912
+ maxNeighborColor = max(col, maxNeighborColor);
913
+ }
914
+ }
915
+ }
916
+ }
917
+
918
+ float velocityLength = length(lastVelocity.xy - velocity.xy);
919
+ velocityDisocclusion = (velocityLength - 0.000005) * 10.0;
920
+ velocityDisocclusion *= velocityDisocclusion;
921
+ reprojectedUv = vUv - velocity.xy;
922
+
923
+ #ifdef boxBlur
924
+ float pxRadius = correctionRadius > 5 ? 121.0 : pow(float(correctionRadius * 2 + 1), 2.0);
925
+ boxBlurredColor /= pxRadius;
926
+ boxBlurredColor = transformColor(boxBlurredColor);
927
+ #endif
928
+
929
+ if (
930
+ reprojectedUv.x >=0.0 &&
931
+ reprojectedUv.x <= 1.0 &&
932
+ reprojectedUv.y >= 0.0 &&
933
+ reprojectedUv.y <= 1.0
934
+ ) {
935
+ accumulatedTexel = textureLod(accumulatedTexture, reprojectedUv, 0.0);
936
+ accumulatedColor = transformColor(accumulatedTexel.rgb);
937
+ vec3 clampedColor = clamp(accumulatedColor, minNeighborColor, maxNeighborColor);
938
+ accumulatedColor = mix(accumulatedColor, clampedColor, correction);
939
+ didReproject = true;
940
+ } else {
941
+ #ifdef boxBlur
942
+ accumulatedColor=boxBlurredColor;
943
+ #else
944
+ accumulatedColor=inputColor;
945
+ #endif
946
+ }
947
+
948
+ if (velocity.r > FLOAT_ONE_MINUS_EPSILON && velocity.g > FLOAT_ONE_MINUS_EPSILON) {
949
+ alpha = 0.0;
950
+ velocityDisocclusion = 1.0;
951
+ }
952
+ } else {
953
+ accumulatedColor = transformColor(textureLod(accumulatedTexture, vUv, 0.0).rgb);
954
+ }
955
+
956
+ vec3 outputColor = inputColor;
957
+
958
+ #include <custom_compose_shader>
959
+
960
+ gl_FragColor = vec4(undoColorTransform(outputColor), alpha);
961
+ }
962
+ `
963
+ );
404
964
  class TemporalResolveMaterial extends THREE.ShaderMaterial {
405
965
  constructor(customComposeShader) {
406
966
  const fragmentShader2 = temporalResolve.replace("#include <custom_compose_shader>", customComposeShader);
@@ -908,7 +1468,6 @@ function useBoxProjectedEnvMap(shader, envMapPosition, envMapSize) {
908
1468
  ${getIBLRadiance_patch}`
909
1469
  );
910
1470
  }
911
- const finalFragmentShader = finalSSRShader.replace("#include <helperFunctions>", helperFunctions).replace("#include <boxBlur>", boxBlur);
912
1471
  const noResetSamplesProperties = ["blur", "blurSharpness", "blurKernel"];
913
1472
  const defaultCubeRenderTarget = new THREE.WebGLCubeRenderTarget(1);
914
1473
  let pmremGenerator;
@@ -919,7 +1478,7 @@ class SSREffect extends postprocessing.Effect {
919
1478
  * @param {SSROptions} [options] The optional options for the SSR effect
920
1479
  */
921
1480
  constructor(scene, camera, options = defaultSSROptions) {
922
- super("SSREffect", finalFragmentShader, {
1481
+ super("SSREffect", finalSSRShader, {
923
1482
  type: "FinalSSRMaterial",
924
1483
  uniforms: /* @__PURE__ */ new Map([
925
1484
  ["reflectionsTexture", new THREE.Uniform(null)],