@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.
@@ -8,7 +8,7 @@ export type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] & Part
8
8
  }>;
9
9
  export declare const Outline: import("react").ForwardRefExoticComponent<{
10
10
  blendFunction?: import("postprocessing").BlendFunction | undefined;
11
- patternTexture?: number | undefined;
11
+ patternTexture?: import("three").Texture | undefined;
12
12
  patternScale?: number | undefined;
13
13
  edgeStrength?: number | undefined;
14
14
  pulseSpeed?: number | undefined;
package/dist/index.cjs CHANGED
@@ -930,7 +930,7 @@ void main() {
930
930
  #define SAMPLES 16
931
931
  #define FSAMPLES 16.0
932
932
  uniform sampler2D sceneDiffuse;
933
- uniform sampler2D sceneNormal;
933
+ uniform highp sampler2D sceneNormal;
934
934
  uniform highp sampler2D sceneDepth;
935
935
  uniform mat4 projectionMatrixInv;
936
936
  uniform mat4 viewMatrixInv;
@@ -980,7 +980,7 @@ uniform sampler2D bluenoise;
980
980
  float b = farZ * nearZ / (nearZ - farZ);
981
981
  float linDepth = a + b / depth;
982
982
  vec4 clipVec = vec4(uv, linDepth, 1.0) * 2.0 - 1.0;
983
- vec4 wpos = viewMatrixInv * projectionMatrixInv * clipVec;
983
+ vec4 wpos = projectionMatrixInv * clipVec;
984
984
  return wpos.xyz / wpos.w;
985
985
  }
986
986
  vec3 getWorldPos(float depth, vec2 coord) {
@@ -991,7 +991,7 @@ uniform sampler2D bluenoise;
991
991
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
992
992
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
993
993
  // Perspective division
994
- vec4 worldSpacePosition = viewMatrixInv * viewSpacePosition;
994
+ vec4 worldSpacePosition = viewSpacePosition;
995
995
  worldSpacePosition.xyz /= worldSpacePosition.w;
996
996
  return worldSpacePosition.xyz;
997
997
  }
@@ -1070,7 +1070,7 @@ void main() {
1070
1070
  ;
1071
1071
  float moveAmt = samplesR[int(mod(i + noise.a * FSAMPLES, FSAMPLES))];
1072
1072
  vec3 samplePos = worldPos + radiusToUse * moveAmt * sampleDirection;
1073
- vec4 offset = projViewMat * vec4(samplePos, 1.0);
1073
+ vec4 offset = projMat * vec4(samplePos, 1.0);
1074
1074
  offset.xyz /= offset.w;
1075
1075
  offset.xyz = offset.xyz * 0.5 + 0.5;
1076
1076
  float sampleDepth = textureLod(sceneDepth, offset.xy, 0.0).x;
@@ -1173,6 +1173,24 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1173
1173
  },
1174
1174
  "distanceFalloff": {
1175
1175
  value: 1
1176
+ },
1177
+ "fog": {
1178
+ value: false
1179
+ },
1180
+ "fogExp": {
1181
+ value: false
1182
+ },
1183
+ "fogDensity": {
1184
+ value: 0
1185
+ },
1186
+ "fogNear": {
1187
+ value: Infinity
1188
+ },
1189
+ "fogFar": {
1190
+ value: Infinity
1191
+ },
1192
+ "colorMultiply": {
1193
+ value: true
1176
1194
  }
1177
1195
  },
1178
1196
  vertexShader: (
@@ -1188,8 +1206,8 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1188
1206
  /* glsl */
1189
1207
  `
1190
1208
  uniform sampler2D sceneDiffuse;
1191
- uniform sampler2D sceneDepth;
1192
- uniform sampler2D downsampledDepth;
1209
+ uniform highp sampler2D sceneDepth;
1210
+ uniform highp sampler2D downsampledDepth;
1193
1211
  uniform sampler2D tDiffuse;
1194
1212
  uniform sampler2D blueNoise;
1195
1213
  uniform vec2 resolution;
@@ -1204,8 +1222,15 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1204
1222
  uniform bool logDepth;
1205
1223
  uniform bool ortho;
1206
1224
  uniform bool screenSpaceRadius;
1225
+ uniform bool fog;
1226
+ uniform bool fogExp;
1227
+ uniform bool colorMultiply;
1228
+ uniform float fogDensity;
1229
+ uniform float fogNear;
1230
+ uniform float fogFar;
1207
1231
  uniform float radius;
1208
1232
  uniform float distanceFalloff;
1233
+ uniform vec3 cameraPos;
1209
1234
  varying vec2 vUv;
1210
1235
  highp float linearize_depth(highp float d, highp float zNear,highp float zFar)
1211
1236
  {
@@ -1235,7 +1260,7 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1235
1260
  float b = farZ * nearZ / (nearZ - farZ);
1236
1261
  float linDepth = a + b / depth;
1237
1262
  vec4 clipVec = vec4(uv, linDepth, 1.0) * 2.0 - 1.0;
1238
- vec4 wpos = viewMatrixInv * projectionMatrixInv * clipVec;
1263
+ vec4 wpos = projectionMatrixInv * clipVec;
1239
1264
  return wpos.xyz / wpos.w;
1240
1265
  }
1241
1266
  vec3 getWorldPos(float depth, vec2 coord) {
@@ -1248,7 +1273,7 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1248
1273
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
1249
1274
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
1250
1275
  // Perspective division
1251
- vec4 worldSpacePosition = viewMatrixInv * viewSpacePosition;
1276
+ vec4 worldSpacePosition = viewSpacePosition;
1252
1277
  worldSpacePosition.xyz /= worldSpacePosition.w;
1253
1278
  return worldSpacePosition.xyz;
1254
1279
  }
@@ -1285,12 +1310,11 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1285
1310
  void main() {
1286
1311
  //vec4 texel = texture2D(tDiffuse, vUv);//vec3(0.0);
1287
1312
  vec4 sceneTexel = texture2D(sceneDiffuse, vUv);
1288
-
1289
- #ifdef HALFRES
1290
1313
  float depth = texture2D(
1291
1314
  sceneDepth,
1292
1315
  vUv
1293
1316
  ).x;
1317
+ #ifdef HALFRES
1294
1318
  vec4 texel;
1295
1319
  if (depth == 1.0) {
1296
1320
  texel = vec4(0.0, 0.0, 0.0, 1.0);
@@ -1338,10 +1362,24 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1338
1362
 
1339
1363
 
1340
1364
  float finalAo = pow(texel.a, intensity);
1365
+ float fogFactor;
1366
+ float fogDepth = distance(
1367
+ cameraPos,
1368
+ getWorldPos(depth, vUv)
1369
+ );
1370
+ if (fog) {
1371
+ if (fogExp) {
1372
+ fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );
1373
+ } else {
1374
+ fogFactor = smoothstep( fogNear, fogFar, fogDepth );
1375
+ }
1376
+ }
1377
+ finalAo = mix(finalAo, 1.0, fogFactor);
1378
+ vec3 aoApplied = color * mix(vec3(1.0), sceneTexel.rgb, float(colorMultiply));
1341
1379
  if (renderMode == 0.0) {
1342
- gl_FragColor = vec4( mix(sceneTexel.rgb, color * sceneTexel.rgb, 1.0 - finalAo), sceneTexel.a);
1380
+ gl_FragColor = vec4( mix(sceneTexel.rgb, aoApplied, 1.0 - finalAo), sceneTexel.a);
1343
1381
  } else if (renderMode == 1.0) {
1344
- gl_FragColor = vec4( mix(vec3(1.0), color * sceneTexel.rgb, 1.0 - finalAo), sceneTexel.a);
1382
+ gl_FragColor = vec4( mix(vec3(1.0), aoApplied, 1.0 - finalAo), sceneTexel.a);
1345
1383
  } else if (renderMode == 2.0) {
1346
1384
  gl_FragColor = vec4( sceneTexel.rgb, sceneTexel.a);
1347
1385
  } else if (renderMode == 3.0) {
@@ -1350,7 +1388,7 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1350
1388
  } else if (abs(vUv.x - 0.5) < 1.0 / resolution.x) {
1351
1389
  gl_FragColor = vec4(1.0);
1352
1390
  } else {
1353
- gl_FragColor = vec4( mix(sceneTexel.rgb, color * sceneTexel.rgb, 1.0 - finalAo), sceneTexel.a);
1391
+ gl_FragColor = vec4( mix(sceneTexel.rgb, aoApplied, 1.0 - finalAo), sceneTexel.a);
1354
1392
  }
1355
1393
  } else if (renderMode == 4.0) {
1356
1394
  if (vUv.x < 0.5) {
@@ -1358,7 +1396,7 @@ const $12b21d24d1192a04$export$a815acccbd2c9a49 = {
1358
1396
  } else if (abs(vUv.x - 0.5) < 1.0 / resolution.x) {
1359
1397
  gl_FragColor = vec4(1.0);
1360
1398
  } else {
1361
- gl_FragColor = vec4( mix(vec3(1.0), color * sceneTexel.rgb, 1.0 - finalAo), sceneTexel.a);
1399
+ gl_FragColor = vec4( mix(vec3(1.0), aoApplied, 1.0 - finalAo), sceneTexel.a);
1362
1400
  }
1363
1401
  }
1364
1402
  #include <dithering_fragment>
@@ -1490,7 +1528,7 @@ const $e52378cd0f5a973d$export$57856b59f317262e = {
1490
1528
  float b = farZ * nearZ / (nearZ - farZ);
1491
1529
  float linDepth = a + b / depth;
1492
1530
  vec4 clipVec = vec4(uv, linDepth, 1.0) * 2.0 - 1.0;
1493
- vec4 wpos = viewMatrixInv * projectionMatrixInv * clipVec;
1531
+ vec4 wpos = projectionMatrixInv * clipVec;
1494
1532
  return wpos.xyz / wpos.w;
1495
1533
  }
1496
1534
  vec3 getWorldPos(float depth, vec2 coord) {
@@ -1502,7 +1540,7 @@ const $e52378cd0f5a973d$export$57856b59f317262e = {
1502
1540
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
1503
1541
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
1504
1542
  // Perspective division
1505
- vec4 worldSpacePosition = viewMatrixInv * viewSpacePosition;
1543
+ vec4 worldSpacePosition = viewSpacePosition;
1506
1544
  worldSpacePosition.xyz /= worldSpacePosition.w;
1507
1545
  return worldSpacePosition.xyz;
1508
1546
  }
@@ -1519,6 +1557,10 @@ const $e52378cd0f5a973d$export$57856b59f317262e = {
1519
1557
  vec3 normal = data.rgb * 2.0 - 1.0;
1520
1558
  float count = 1.0;
1521
1559
  float d = texture2D(sceneDepth, vUv).x;
1560
+ if (d == 1.0) {
1561
+ gl_FragColor = data;
1562
+ return;
1563
+ }
1522
1564
  vec3 worldPos = getWorldPos(d, vUv);
1523
1565
  float size = radius;
1524
1566
  float angle;
@@ -1551,7 +1593,7 @@ const $e52378cd0f5a973d$export$57856b59f317262e = {
1551
1593
  float dSample = texture2D(sceneDepth, uv + offset).x;
1552
1594
  vec3 worldPosSample = getWorldPos(dSample, uv + offset);
1553
1595
  float tangentPlaneDist = abs(dot(worldPos - worldPosSample, normal));
1554
- float rangeCheck = exp(-1.0 * tangentPlaneDist * (1.0 / distanceFalloffToUse)) * max(dot(normal, normalSample), 0.0) * (1.0 - abs(occSample - baseOcc));
1596
+ 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));
1555
1597
  occlusion += occSample * rangeCheck;
1556
1598
  count += rangeCheck;
1557
1599
  }
@@ -1597,7 +1639,7 @@ const $26aca173e0984d99$export$1efdf491687cd442 = {
1597
1639
  fragmentShader: (
1598
1640
  /* glsl */
1599
1641
  `
1600
- uniform sampler2D sceneDepth;
1642
+ uniform highp sampler2D sceneDepth;
1601
1643
  uniform vec2 resolution;
1602
1644
  uniform float near;
1603
1645
  uniform float far;
@@ -1616,7 +1658,7 @@ const $26aca173e0984d99$export$1efdf491687cd442 = {
1616
1658
  float b = farZ * nearZ / (nearZ - farZ);
1617
1659
  float linDepth = a + b / depth;
1618
1660
  vec4 clipVec = vec4(uv, linDepth, 1.0) * 2.0 - 1.0;
1619
- vec4 wpos = viewMatrixInv * projectionMatrixInv * clipVec;
1661
+ vec4 wpos = projectionMatrixInv * clipVec;
1620
1662
  return wpos.xyz / wpos.w;
1621
1663
  }
1622
1664
  vec3 getWorldPos(float depth, vec2 coord) {
@@ -1627,7 +1669,7 @@ const $26aca173e0984d99$export$1efdf491687cd442 = {
1627
1669
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
1628
1670
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
1629
1671
  // Perspective division
1630
- vec4 worldSpacePosition = viewMatrixInv * viewSpacePosition;
1672
+ vec4 worldSpacePosition = viewSpacePosition;
1631
1673
  worldSpacePosition.xyz /= worldSpacePosition.w;
1632
1674
  return worldSpacePosition.xyz;
1633
1675
  }
@@ -1782,7 +1824,8 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
1782
1824
  logarithmicDepthBuffer: false,
1783
1825
  screenSpaceRadius: false,
1784
1826
  halfRes: false,
1785
- depthAwareUpsampling: true
1827
+ depthAwareUpsampling: true,
1828
+ colorMultiply: true
1786
1829
  }, {
1787
1830
  set: (target, propName, value) => {
1788
1831
  const oldProp = target[propName];
@@ -1816,6 +1859,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
1816
1859
  value: null
1817
1860
  }
1818
1861
  },
1862
+ depthWrite: false,
1819
1863
  vertexShader: `
1820
1864
  varying vec2 vUv;
1821
1865
  void main() {
@@ -1841,6 +1885,11 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
1841
1885
  magFilter: THREE.LinearFilter,
1842
1886
  depthBuffer: false
1843
1887
  });
1888
+ this.outputTargetInternal = new THREE.WebGLRenderTarget(this.width, this.height, {
1889
+ minFilter: THREE.LinearFilter,
1890
+ magFilter: THREE.LinearFilter,
1891
+ depthBuffer: false
1892
+ });
1844
1893
  this.bluenoise = new THREE.DataTexture($87431ee93b037844$var$bluenoiseBits, 128, 128);
1845
1894
  this.bluenoise.colorSpace = THREE.NoColorSpace;
1846
1895
  this.bluenoise.wrapS = THREE.RepeatWrapping;
@@ -1850,6 +1899,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
1850
1899
  this.bluenoise.needsUpdate = true;
1851
1900
  this.lastTime = 0;
1852
1901
  this.needsDepthTexture = true;
1902
+ this.needsSwap = true;
1853
1903
  this._r = new THREE.Vector2();
1854
1904
  this._c = new THREE.Color();
1855
1905
  }
@@ -1990,6 +2040,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
1990
2040
  this.readTargetInternal.setSize(width * c, height * c);
1991
2041
  if (this.configuration.halfRes)
1992
2042
  this.depthDownsampleTarget.setSize(width * c, height * c);
2043
+ this.outputTargetInternal.setSize(width, height);
1993
2044
  }
1994
2045
  setDepthTexture(depthTexture) {
1995
2046
  this.depthTexture = depthTexture;
@@ -2003,6 +2054,10 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
2003
2054
  this.configureDenoisePass(this.configuration.logarithmicDepthBuffer);
2004
2055
  this.configureEffectCompositer(this.configuration.logarithmicDepthBuffer);
2005
2056
  }
2057
+ if (inputBuffer.texture.type !== this.outputTargetInternal.texture.type) {
2058
+ this.outputTargetInternal.texture.type = inputBuffer.texture.type;
2059
+ this.outputTargetInternal.texture.needsUpdate = true;
2060
+ }
2006
2061
  let gl;
2007
2062
  let ext;
2008
2063
  let timerQuery;
@@ -2042,7 +2097,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
2042
2097
  this.effectShaderQuad.material.uniforms["projViewMat"].value = this.camera.projectionMatrix.clone().multiply(this.camera.matrixWorldInverse.clone());
2043
2098
  this.effectShaderQuad.material.uniforms["projectionMatrixInv"].value = this.camera.projectionMatrixInverse;
2044
2099
  this.effectShaderQuad.material.uniforms["viewMatrixInv"].value = this.camera.matrixWorld;
2045
- this.effectShaderQuad.material.uniforms["cameraPos"].value = this.camera.position;
2100
+ this.effectShaderQuad.material.uniforms["cameraPos"].value = this.camera.getWorldPosition(new THREE.Vector3());
2046
2101
  this.effectShaderQuad.material.uniforms["resolution"].value = this.configuration.halfRes ? this._r.clone().multiplyScalar(0.5).floor() : this._r;
2047
2102
  this.effectShaderQuad.material.uniforms["time"].value = performance.now() / 1e3;
2048
2103
  this.effectShaderQuad.material.uniforms["samples"].value = this.samples;
@@ -2068,7 +2123,7 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
2068
2123
  this.poissonBlurQuad.material.uniforms["viewMat"].value = this.camera.matrixWorldInverse;
2069
2124
  this.poissonBlurQuad.material.uniforms["projectionMatrixInv"].value = this.camera.projectionMatrixInverse;
2070
2125
  this.poissonBlurQuad.material.uniforms["viewMatrixInv"].value = this.camera.matrixWorld;
2071
- this.poissonBlurQuad.material.uniforms["cameraPos"].value = this.camera.position;
2126
+ this.poissonBlurQuad.material.uniforms["cameraPos"].value = this.camera.getWorldPosition(new THREE.Vector3());
2072
2127
  this.poissonBlurQuad.material.uniforms["resolution"].value = this.configuration.halfRes ? this._r.clone().multiplyScalar(0.5).floor() : this._r;
2073
2128
  this.poissonBlurQuad.material.uniforms["time"].value = performance.now() / 1e3;
2074
2129
  this.poissonBlurQuad.material.uniforms["blueNoise"].value = this.bluenoise;
@@ -2103,8 +2158,29 @@ class $87431ee93b037844$export$2489f9981ab0fa82 extends postprocessing.Pass {
2103
2158
  this.effectCompositerQuad.material.uniforms["gammaCorrection"].value = this.autosetGamma ? this.renderToScreen : this.configuration.gammaCorrection;
2104
2159
  this.effectCompositerQuad.material.uniforms["tDiffuse"].value = this.writeTargetInternal.texture;
2105
2160
  this.effectCompositerQuad.material.uniforms["color"].value = this._c.copy(this.configuration.color).convertSRGBToLinear();
2106
- renderer.setRenderTarget(this.renderToScreen ? null : outputBuffer);
2161
+ this.effectCompositerQuad.material.uniforms["colorMultiply"].value = this.configuration.colorMultiply;
2162
+ this.effectCompositerQuad.material.uniforms["cameraPos"].value = this.camera.getWorldPosition(new THREE.Vector3());
2163
+ this.effectCompositerQuad.material.uniforms["fog"].value = !!this.scene.fog;
2164
+ if (this.scene.fog) {
2165
+ if (this.scene.fog.isFog) {
2166
+ this.effectCompositerQuad.material.uniforms["fogExp"].value = false;
2167
+ this.effectCompositerQuad.material.uniforms["fogNear"].value = this.scene.fog.near;
2168
+ this.effectCompositerQuad.material.uniforms["fogFar"].value = this.scene.fog.far;
2169
+ } else if (this.scene.fog.isFogExp2) {
2170
+ this.effectCompositerQuad.material.uniforms["fogExp"].value = true;
2171
+ this.effectCompositerQuad.material.uniforms["fogDensity"].value = this.scene.fog.density;
2172
+ } else
2173
+ console.error(`Unsupported fog type ${this.scene.fog.constructor.name} in SSAOPass.`);
2174
+ }
2175
+ renderer.setRenderTarget(
2176
+ /* this.renderToScreen ? null :
2177
+ outputBuffer*/
2178
+ this.outputTargetInternal
2179
+ );
2107
2180
  this.effectCompositerQuad.render(renderer);
2181
+ renderer.setRenderTarget(this.renderToScreen ? null : outputBuffer);
2182
+ this.copyQuad.material.uniforms["tDiffuse"].value = this.outputTargetInternal.texture;
2183
+ this.copyQuad.render(renderer);
2108
2184
  if (this.debugMode) {
2109
2185
  gl.endQuery(ext.TIME_ELAPSED_EXT);
2110
2186
  $87431ee93b037844$var$checkTimerQuery(timerQuery, gl, this);