@react-three/postprocessing 2.14.9 → 2.14.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -912,7 +912,7 @@ void main() {
912
912
  #define SAMPLES 16
913
913
  #define FSAMPLES 16.0
914
914
  uniform sampler2D sceneDiffuse;
915
- uniform sampler2D sceneNormal;
915
+ uniform highp sampler2D sceneNormal;
916
916
  uniform highp sampler2D sceneDepth;
917
917
  uniform mat4 projectionMatrixInv;
918
918
  uniform mat4 viewMatrixInv;
@@ -962,7 +962,7 @@ uniform sampler2D bluenoise;
962
962
  float b = farZ * nearZ / (nearZ - farZ);
963
963
  float linDepth = a + b / depth;
964
964
  vec4 clipVec = vec4(uv, linDepth, 1.0) * 2.0 - 1.0;
965
- vec4 wpos = viewMatrixInv * projectionMatrixInv * clipVec;
965
+ vec4 wpos = projectionMatrixInv * clipVec;
966
966
  return wpos.xyz / wpos.w;
967
967
  }
968
968
  vec3 getWorldPos(float depth, vec2 coord) {
@@ -973,7 +973,7 @@ uniform sampler2D bluenoise;
973
973
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
974
974
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
975
975
  // Perspective division
976
- vec4 worldSpacePosition = viewMatrixInv * viewSpacePosition;
976
+ vec4 worldSpacePosition = viewSpacePosition;
977
977
  worldSpacePosition.xyz /= worldSpacePosition.w;
978
978
  return worldSpacePosition.xyz;
979
979
  }
@@ -1052,7 +1052,7 @@ void main() {
1052
1052
  ;
1053
1053
  float moveAmt = samplesR[int(mod(i + noise.a * FSAMPLES, FSAMPLES))];
1054
1054
  vec3 samplePos = worldPos + radiusToUse * moveAmt * sampleDirection;
1055
- vec4 offset = projViewMat * vec4(samplePos, 1.0);
1055
+ vec4 offset = projMat * vec4(samplePos, 1.0);
1056
1056
  offset.xyz /= offset.w;
1057
1057
  offset.xyz = offset.xyz * 0.5 + 0.5;
1058
1058
  float sampleDepth = textureLod(sceneDepth, offset.xy, 0.0).x;
@@ -1155,6 +1155,24 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1155
1155
  },
1156
1156
  "distanceFalloff": {
1157
1157
  value: 1
1158
+ },
1159
+ "fog": {
1160
+ value: false
1161
+ },
1162
+ "fogExp": {
1163
+ value: false
1164
+ },
1165
+ "fogDensity": {
1166
+ value: 0
1167
+ },
1168
+ "fogNear": {
1169
+ value: Infinity
1170
+ },
1171
+ "fogFar": {
1172
+ value: Infinity
1173
+ },
1174
+ "colorMultiply": {
1175
+ value: true
1158
1176
  }
1159
1177
  },
1160
1178
  vertexShader: (
@@ -1170,8 +1188,8 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1170
1188
  /* glsl */
1171
1189
  `
1172
1190
  uniform sampler2D sceneDiffuse;
1173
- uniform sampler2D sceneDepth;
1174
- uniform sampler2D downsampledDepth;
1191
+ uniform highp sampler2D sceneDepth;
1192
+ uniform highp sampler2D downsampledDepth;
1175
1193
  uniform sampler2D tDiffuse;
1176
1194
  uniform sampler2D blueNoise;
1177
1195
  uniform vec2 resolution;
@@ -1186,8 +1204,15 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1186
1204
  uniform bool logDepth;
1187
1205
  uniform bool ortho;
1188
1206
  uniform bool screenSpaceRadius;
1207
+ uniform bool fog;
1208
+ uniform bool fogExp;
1209
+ uniform bool colorMultiply;
1210
+ uniform float fogDensity;
1211
+ uniform float fogNear;
1212
+ uniform float fogFar;
1189
1213
  uniform float radius;
1190
1214
  uniform float distanceFalloff;
1215
+ uniform vec3 cameraPos;
1191
1216
  varying vec2 vUv;
1192
1217
  highp float linearize_depth(highp float d, highp float zNear,highp float zFar)
1193
1218
  {
@@ -1217,7 +1242,7 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1217
1242
  float b = farZ * nearZ / (nearZ - farZ);
1218
1243
  float linDepth = a + b / depth;
1219
1244
  vec4 clipVec = vec4(uv, linDepth, 1.0) * 2.0 - 1.0;
1220
- vec4 wpos = viewMatrixInv * projectionMatrixInv * clipVec;
1245
+ vec4 wpos = projectionMatrixInv * clipVec;
1221
1246
  return wpos.xyz / wpos.w;
1222
1247
  }
1223
1248
  vec3 getWorldPos(float depth, vec2 coord) {
@@ -1230,7 +1255,7 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1230
1255
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
1231
1256
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
1232
1257
  // Perspective division
1233
- vec4 worldSpacePosition = viewMatrixInv * viewSpacePosition;
1258
+ vec4 worldSpacePosition = viewSpacePosition;
1234
1259
  worldSpacePosition.xyz /= worldSpacePosition.w;
1235
1260
  return worldSpacePosition.xyz;
1236
1261
  }
@@ -1267,12 +1292,11 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1267
1292
  void main() {
1268
1293
  //vec4 texel = texture2D(tDiffuse, vUv);//vec3(0.0);
1269
1294
  vec4 sceneTexel = texture2D(sceneDiffuse, vUv);
1270
-
1271
- #ifdef HALFRES
1272
1295
  float depth = texture2D(
1273
1296
  sceneDepth,
1274
1297
  vUv
1275
1298
  ).x;
1299
+ #ifdef HALFRES
1276
1300
  vec4 texel;
1277
1301
  if (depth == 1.0) {
1278
1302
  texel = vec4(0.0, 0.0, 0.0, 1.0);
@@ -1320,10 +1344,24 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1320
1344
 
1321
1345
 
1322
1346
  float finalAo = pow(texel.a, intensity);
1347
+ float fogFactor;
1348
+ float fogDepth = distance(
1349
+ cameraPos,
1350
+ getWorldPos(depth, vUv)
1351
+ );
1352
+ if (fog) {
1353
+ if (fogExp) {
1354
+ fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );
1355
+ } else {
1356
+ fogFactor = smoothstep( fogNear, fogFar, fogDepth );
1357
+ }
1358
+ }
1359
+ finalAo = mix(finalAo, 1.0, fogFactor);
1360
+ vec3 aoApplied = color * mix(vec3(1.0), sceneTexel.rgb, float(colorMultiply));
1323
1361
  if (renderMode == 0.0) {
1324
- gl_FragColor = vec4( mix(sceneTexel.rgb, color * sceneTexel.rgb, 1.0 - finalAo), sceneTexel.a);
1362
+ gl_FragColor = vec4( mix(sceneTexel.rgb, aoApplied, 1.0 - finalAo), sceneTexel.a);
1325
1363
  } else if (renderMode == 1.0) {
1326
- gl_FragColor = vec4( mix(vec3(1.0), color * sceneTexel.rgb, 1.0 - finalAo), sceneTexel.a);
1364
+ gl_FragColor = vec4( mix(vec3(1.0), aoApplied, 1.0 - finalAo), sceneTexel.a);
1327
1365
  } else if (renderMode == 2.0) {
1328
1366
  gl_FragColor = vec4( sceneTexel.rgb, sceneTexel.a);
1329
1367
  } else if (renderMode == 3.0) {
@@ -1332,7 +1370,7 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1332
1370
  } else if (abs(vUv.x - 0.5) < 1.0 / resolution.x) {
1333
1371
  gl_FragColor = vec4(1.0);
1334
1372
  } else {
1335
- gl_FragColor = vec4( mix(sceneTexel.rgb, color * sceneTexel.rgb, 1.0 - finalAo), sceneTexel.a);
1373
+ gl_FragColor = vec4( mix(sceneTexel.rgb, aoApplied, 1.0 - finalAo), sceneTexel.a);
1336
1374
  }
1337
1375
  } else if (renderMode == 4.0) {
1338
1376
  if (vUv.x < 0.5) {
@@ -1340,7 +1378,7 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1340
1378
  } else if (abs(vUv.x - 0.5) < 1.0 / resolution.x) {
1341
1379
  gl_FragColor = vec4(1.0);
1342
1380
  } else {
1343
- gl_FragColor = vec4( mix(vec3(1.0), color * sceneTexel.rgb, 1.0 - finalAo), sceneTexel.a);
1381
+ gl_FragColor = vec4( mix(vec3(1.0), aoApplied, 1.0 - finalAo), sceneTexel.a);
1344
1382
  }
1345
1383
  }
1346
1384
  #include <dithering_fragment>
@@ -1472,7 +1510,7 @@ const $e52378cd0f5a973d$export$57856b59f317262e = {
1472
1510
  float b = farZ * nearZ / (nearZ - farZ);
1473
1511
  float linDepth = a + b / depth;
1474
1512
  vec4 clipVec = vec4(uv, linDepth, 1.0) * 2.0 - 1.0;
1475
- vec4 wpos = viewMatrixInv * projectionMatrixInv * clipVec;
1513
+ vec4 wpos = projectionMatrixInv * clipVec;
1476
1514
  return wpos.xyz / wpos.w;
1477
1515
  }
1478
1516
  vec3 getWorldPos(float depth, vec2 coord) {
@@ -1484,7 +1522,7 @@ const $e52378cd0f5a973d$export$57856b59f317262e = {
1484
1522
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
1485
1523
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
1486
1524
  // Perspective division
1487
- vec4 worldSpacePosition = viewMatrixInv * viewSpacePosition;
1525
+ vec4 worldSpacePosition = viewSpacePosition;
1488
1526
  worldSpacePosition.xyz /= worldSpacePosition.w;
1489
1527
  return worldSpacePosition.xyz;
1490
1528
  }
@@ -1501,6 +1539,10 @@ const $e52378cd0f5a973d$export$57856b59f317262e = {
1501
1539
  vec3 normal = data.rgb * 2.0 - 1.0;
1502
1540
  float count = 1.0;
1503
1541
  float d = texture2D(sceneDepth, vUv).x;
1542
+ if (d == 1.0) {
1543
+ gl_FragColor = data;
1544
+ return;
1545
+ }
1504
1546
  vec3 worldPos = getWorldPos(d, vUv);
1505
1547
  float size = radius;
1506
1548
  float angle;
@@ -1533,7 +1575,7 @@ const $e52378cd0f5a973d$export$57856b59f317262e = {
1533
1575
  float dSample = texture2D(sceneDepth, uv + offset).x;
1534
1576
  vec3 worldPosSample = getWorldPos(dSample, uv + offset);
1535
1577
  float tangentPlaneDist = abs(dot(worldPos - worldPosSample, normal));
1536
- float rangeCheck = exp(-1.0 * tangentPlaneDist * (1.0 / distanceFalloffToUse)) * max(dot(normal, normalSample), 0.0) * (1.0 - abs(occSample - baseOcc));
1578
+ float rangeCheck = dSample == 1.0 ? 0.0 :exp(-1.0 * tangentPlaneDist * (1.0 / distanceFalloffToUse)) * max(dot(normal, normalSample), 0.0) * (1.0 - abs(occSample - baseOcc));
1537
1579
  occlusion += occSample * rangeCheck;
1538
1580
  count += rangeCheck;
1539
1581
  }
@@ -1579,7 +1621,7 @@ const $26aca173e0984d99$export$1efdf491687cd442 = {
1579
1621
  fragmentShader: (
1580
1622
  /* glsl */
1581
1623
  `
1582
- uniform sampler2D sceneDepth;
1624
+ uniform highp sampler2D sceneDepth;
1583
1625
  uniform vec2 resolution;
1584
1626
  uniform float near;
1585
1627
  uniform float far;
@@ -1598,7 +1640,7 @@ const $26aca173e0984d99$export$1efdf491687cd442 = {
1598
1640
  float b = farZ * nearZ / (nearZ - farZ);
1599
1641
  float linDepth = a + b / depth;
1600
1642
  vec4 clipVec = vec4(uv, linDepth, 1.0) * 2.0 - 1.0;
1601
- vec4 wpos = viewMatrixInv * projectionMatrixInv * clipVec;
1643
+ vec4 wpos = projectionMatrixInv * clipVec;
1602
1644
  return wpos.xyz / wpos.w;
1603
1645
  }
1604
1646
  vec3 getWorldPos(float depth, vec2 coord) {
@@ -1609,7 +1651,7 @@ const $26aca173e0984d99$export$1efdf491687cd442 = {
1609
1651
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
1610
1652
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
1611
1653
  // Perspective division
1612
- vec4 worldSpacePosition = viewMatrixInv * viewSpacePosition;
1654
+ vec4 worldSpacePosition = viewSpacePosition;
1613
1655
  worldSpacePosition.xyz /= worldSpacePosition.w;
1614
1656
  return worldSpacePosition.xyz;
1615
1657
  }
@@ -1764,7 +1806,8 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
1764
1806
  logarithmicDepthBuffer: false,
1765
1807
  screenSpaceRadius: false,
1766
1808
  halfRes: false,
1767
- depthAwareUpsampling: true
1809
+ depthAwareUpsampling: true,
1810
+ colorMultiply: true
1768
1811
  }, {
1769
1812
  set: (target, propName, value) => {
1770
1813
  const oldProp = target[propName];
@@ -1798,6 +1841,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
1798
1841
  value: null
1799
1842
  }
1800
1843
  },
1844
+ depthWrite: false,
1801
1845
  vertexShader: `
1802
1846
  varying vec2 vUv;
1803
1847
  void main() {
@@ -1823,6 +1867,11 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
1823
1867
  magFilter: LinearFilter,
1824
1868
  depthBuffer: false
1825
1869
  });
1870
+ this.outputTargetInternal = new WebGLRenderTarget(this.width, this.height, {
1871
+ minFilter: LinearFilter,
1872
+ magFilter: LinearFilter,
1873
+ depthBuffer: false
1874
+ });
1826
1875
  this.bluenoise = new DataTexture($87431ee93b037844$var$bluenoiseBits, 128, 128);
1827
1876
  this.bluenoise.colorSpace = NoColorSpace;
1828
1877
  this.bluenoise.wrapS = RepeatWrapping;
@@ -1832,6 +1881,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
1832
1881
  this.bluenoise.needsUpdate = true;
1833
1882
  this.lastTime = 0;
1834
1883
  this.needsDepthTexture = true;
1884
+ this.needsSwap = true;
1835
1885
  this._r = new Vector2();
1836
1886
  this._c = new Color();
1837
1887
  }
@@ -1972,6 +2022,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
1972
2022
  this.readTargetInternal.setSize(width * c, height * c);
1973
2023
  if (this.configuration.halfRes)
1974
2024
  this.depthDownsampleTarget.setSize(width * c, height * c);
2025
+ this.outputTargetInternal.setSize(width, height);
1975
2026
  }
1976
2027
  setDepthTexture(depthTexture) {
1977
2028
  this.depthTexture = depthTexture;
@@ -1985,6 +2036,10 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
1985
2036
  this.configureDenoisePass(this.configuration.logarithmicDepthBuffer);
1986
2037
  this.configureEffectCompositer(this.configuration.logarithmicDepthBuffer);
1987
2038
  }
2039
+ if (inputBuffer.texture.type !== this.outputTargetInternal.texture.type) {
2040
+ this.outputTargetInternal.texture.type = inputBuffer.texture.type;
2041
+ this.outputTargetInternal.texture.needsUpdate = true;
2042
+ }
1988
2043
  let gl;
1989
2044
  let ext;
1990
2045
  let timerQuery;
@@ -2024,7 +2079,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
2024
2079
  this.effectShaderQuad.material.uniforms["projViewMat"].value = this.camera.projectionMatrix.clone().multiply(this.camera.matrixWorldInverse.clone());
2025
2080
  this.effectShaderQuad.material.uniforms["projectionMatrixInv"].value = this.camera.projectionMatrixInverse;
2026
2081
  this.effectShaderQuad.material.uniforms["viewMatrixInv"].value = this.camera.matrixWorld;
2027
- this.effectShaderQuad.material.uniforms["cameraPos"].value = this.camera.position;
2082
+ this.effectShaderQuad.material.uniforms["cameraPos"].value = this.camera.getWorldPosition(new Vector3());
2028
2083
  this.effectShaderQuad.material.uniforms["resolution"].value = this.configuration.halfRes ? this._r.clone().multiplyScalar(0.5).floor() : this._r;
2029
2084
  this.effectShaderQuad.material.uniforms["time"].value = performance.now() / 1e3;
2030
2085
  this.effectShaderQuad.material.uniforms["samples"].value = this.samples;
@@ -2050,7 +2105,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
2050
2105
  this.poissonBlurQuad.material.uniforms["viewMat"].value = this.camera.matrixWorldInverse;
2051
2106
  this.poissonBlurQuad.material.uniforms["projectionMatrixInv"].value = this.camera.projectionMatrixInverse;
2052
2107
  this.poissonBlurQuad.material.uniforms["viewMatrixInv"].value = this.camera.matrixWorld;
2053
- this.poissonBlurQuad.material.uniforms["cameraPos"].value = this.camera.position;
2108
+ this.poissonBlurQuad.material.uniforms["cameraPos"].value = this.camera.getWorldPosition(new Vector3());
2054
2109
  this.poissonBlurQuad.material.uniforms["resolution"].value = this.configuration.halfRes ? this._r.clone().multiplyScalar(0.5).floor() : this._r;
2055
2110
  this.poissonBlurQuad.material.uniforms["time"].value = performance.now() / 1e3;
2056
2111
  this.poissonBlurQuad.material.uniforms["blueNoise"].value = this.bluenoise;
@@ -2085,8 +2140,29 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends Pass {
2085
2140
  this.effectCompositerQuad.material.uniforms["gammaCorrection"].value = this.autosetGamma ? this.renderToScreen : this.configuration.gammaCorrection;
2086
2141
  this.effectCompositerQuad.material.uniforms["tDiffuse"].value = this.writeTargetInternal.texture;
2087
2142
  this.effectCompositerQuad.material.uniforms["color"].value = this._c.copy(this.configuration.color).convertSRGBToLinear();
2088
- renderer.setRenderTarget(this.renderToScreen ? null : outputBuffer);
2143
+ this.effectCompositerQuad.material.uniforms["colorMultiply"].value = this.configuration.colorMultiply;
2144
+ this.effectCompositerQuad.material.uniforms["cameraPos"].value = this.camera.getWorldPosition(new Vector3());
2145
+ this.effectCompositerQuad.material.uniforms["fog"].value = !!this.scene.fog;
2146
+ if (this.scene.fog) {
2147
+ if (this.scene.fog.isFog) {
2148
+ this.effectCompositerQuad.material.uniforms["fogExp"].value = false;
2149
+ this.effectCompositerQuad.material.uniforms["fogNear"].value = this.scene.fog.near;
2150
+ this.effectCompositerQuad.material.uniforms["fogFar"].value = this.scene.fog.far;
2151
+ } else if (this.scene.fog.isFogExp2) {
2152
+ this.effectCompositerQuad.material.uniforms["fogExp"].value = true;
2153
+ this.effectCompositerQuad.material.uniforms["fogDensity"].value = this.scene.fog.density;
2154
+ } else
2155
+ console.error(`Unsupported fog type ${this.scene.fog.constructor.name} in SSAOPass.`);
2156
+ }
2157
+ renderer.setRenderTarget(
2158
+ /* this.renderToScreen ? null :
2159
+ outputBuffer*/
2160
+ this.outputTargetInternal
2161
+ );
2089
2162
  this.effectCompositerQuad.render(renderer);
2163
+ renderer.setRenderTarget(this.renderToScreen ? null : outputBuffer);
2164
+ this.copyQuad.material.uniforms["tDiffuse"].value = this.outputTargetInternal.texture;
2165
+ this.copyQuad.render(renderer);
2090
2166
  if (this.debugMode) {
2091
2167
  gl.endQuery(ext.TIME_ELAPSED_EXT);
2092
2168
  $87431ee93b037844$var$checkTimerQuery(timerQuery, gl, this);