@react-three/postprocessing 2.4.5 → 2.5.1

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Downloads](https://img.shields.io/npm/dt/@react-three/postprocessing.svg?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/@react-three/postprocessing)
5
5
  [![Discord Shield](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=ffffff)](https://discord.gg/ZZjjNvJ)
6
6
 
7
- `react-postprocessing` is a [postprocessing](https://github.com/vanruesc/postprocessing) wrapper for [@react-three/fiber](https://github.com/pmndrs/@react-three/fiber). This is not (yet) meant for complex orchestration of effects, but can save you [hundreds of LOC](https://twitter.com/0xca0a/status/1289501594698960897) for a straight forward effects-chain.
7
+ `react-postprocessing` is a [postprocessing](https://github.com/pmndrs/postprocessing) wrapper for [@react-three/fiber](https://github.com/pmndrs/@react-three/fiber). This is not (yet) meant for complex orchestration of effects, but can save you [hundreds of LOC](https://twitter.com/0xca0a/status/1289501594698960897) for a straight forward effects-chain.
8
8
 
9
9
  ```bash
10
10
  npm install @react-three/postprocessing
@@ -20,7 +20,7 @@ npm install @react-three/postprocessing
20
20
 
21
21
  #### Why postprocessing and not three/examples/jsm/postprocessing?
22
22
 
23
- From [https://github.com/vanruesc/postprocessing](https://github.com/vanruesc/postprocessing#performance)
23
+ From [https://github.com/pmndrs/postprocessing](https://github.com/pmndrs/postprocessing#performance)
24
24
 
25
25
  > This library provides an EffectPass which automatically organizes and merges any given combination of effects. This minimizes the amount of render operations and makes it possible to combine many effects without the performance penalties of traditional pass chaining. Additionally, every effect can choose its own blend function.
26
26
  >
@@ -1,49 +1,55 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  declare type SSRProps = {
3
- /** Enables the effect pass */
4
- enabled?: boolean;
5
- /** Size of the output buffer */
6
- resolutionScale?: number;
7
- /** Size of the blur buffer */
8
- blurSize?: number;
9
- /** Whether to blur the reflections and blend these blurred reflections depending on the roughness and depth of the reflection ray */
10
- useBlur?: boolean;
11
- /** The kernel size of the blur pass which is used to blur reflections; higher kernel sizes will result in blurrier reflections with more artifacts */
3
+ /** whether you want to use Temporal Resolving to re-use reflections from the last frames; this will reduce noise tremendously but may result in "smearing" */
4
+ temporalResolve?: boolean;
5
+ /** a value between 0 and 1 to set how much the last frame's reflections should be blended in; higher values will result in less noisy reflections when moving the camera but a more smeary look */
6
+ temporalResolveMix?: number;
7
+ /** a value between 0 and 1 to set how much the reprojected reflection should be corrected; higher values will reduce smearing but will result in less flickering at reflection edges */
8
+ temporalResolveCorrectionMix?: number;
9
+ /** the maximum number of samples for reflections; settings it to 0 means unlimited samples; setting it to a value like 6 can help make camera movements less disruptive when calculating reflections */
10
+ maxSamples?: number;
11
+ /** whether to blur the reflections and blend these blurred reflections with the raw ones depending on the blurMix value */
12
+ ENABLE_BLUR?: boolean;
13
+ /** how much the blurred reflections should be mixed with the raw reflections */
14
+ blurMix?: number;
15
+ /** the sharpness of the Bilateral Filter used to blur reflections */
16
+ blurSharpness?: number;
17
+ /** the kernel size of the Bilateral Blur Filter; higher kernel sizes will result in blurrier reflections with more artifacts */
12
18
  blurKernelSize?: number;
13
- /** How much the reflection ray should travel in each of its iteration; higher values will give deeper reflections but with more artifacts */
19
+ /** how much the reflection ray should travel in each of its iteration; higher values will give deeper reflections but with more artifacts */
14
20
  rayStep?: number;
15
- /** The intensity of the reflections */
21
+ /** the intensity of the reflections */
16
22
  intensity?: number;
17
- /** The power by which the reflections should be potentiated; higher values will give a more intense and vibrant look */
18
- power?: number;
19
- /** How much deep reflections will be blurred (as reflections become blurrier the further away the object they are reflecting is) */
20
- depthBlur?: number;
21
- /** Whether jittering is enabled; jittering will randomly jitter the reflections resulting in a more noisy but overall more realistic look, enabling jittering can be expensive depending on the view angle */
22
- enableJittering?: boolean;
23
- /** How intense jittering should be */
23
+ /** the maximum roughness a texel can have to have reflections calculated for it */
24
+ maxRoughness?: number;
25
+ /** whether jittering is enabled; jittering will randomly jitter the reflections resulting in a more noisy but overall more realistic look, enabling jittering can be expensive depending on the view angle */
26
+ ENABLE_JITTERING?: boolean;
27
+ /** how intense jittering should be */
24
28
  jitter?: number;
25
- /** How much the jittered rays should be spread; higher values will give a rougher look regarding the reflections but are more expensive to compute with */
29
+ /** how much the jittered rays should be spread; higher values will give a rougher look regarding the reflections but are more expensive to compute with */
26
30
  jitterSpread?: number;
27
- /** Roughness fade out */
28
- roughnessFadeOut?: number;
29
- /** The number of steps a reflection ray can maximally do to find an object it intersected (and thus reflects) */
31
+ /** how intense jittering should be in relation to a material's roughness */
32
+ jitterRough?: number;
33
+ /** the number of steps a reflection ray can maximally do to find an object it intersected (and thus reflects) */
30
34
  MAX_STEPS?: number;
31
- /** Once we had our ray intersect something, we need to find the exact point in space it intersected and thus it reflects; this can be done through binary search with the given number of maximum steps */
35
+ /** once we had our ray intersect something, we need to find the exact point in space it intersected and thus it reflects; this can be done through binary search with the given number of maximum steps */
32
36
  NUM_BINARY_SEARCH_STEPS?: number;
33
- /** The maximum depth difference between a ray and the particular depth at its screen position after refining with binary search; lower values will result in better performance */
37
+ /** the maximum depth difference between a ray and the particular depth at its screen position after refining with binary search; lower values will result in better performance */
34
38
  maxDepthDifference?: number;
35
- /** The maximum depth for which reflections will be calculated */
39
+ /** the maximum depth for which reflections will be calculated */
36
40
  maxDepth?: number;
37
- /** The maximum depth difference between a ray and the particular depth at its screen position before refining with binary search; lower values will result in better performance */
41
+ /** the maximum depth difference between a ray and the particular depth at its screen position before refining with binary search; lower values will result in better performance */
38
42
  thickness?: number;
39
43
  /** Index of Refraction, used for calculating fresnel; reflections tend to be more intense the steeper the angle between them and the viewer is, the ior parameter set how much the intensity varies */
40
44
  ior?: number;
41
- /** WebGL2 only - whether to use multiple render targets when rendering the G-buffers (normals, depth and roughness); using them can improve performance as they will render all information to multiple buffers for each fragment in one run */
42
- useMRT?: boolean;
43
- /** If normal maps should be taken account of when calculating reflections */
44
- useNormalMap?: boolean;
45
- /** If roughness maps should be taken account of when calculating reflections */
46
- useRoughnessMap?: boolean;
45
+ /** if there should still be reflections for rays for which a reflecting point couldn't be found; enabling this will result in stretched looking reflections which can look good or bad depending on the angle */
46
+ STRETCH_MISSED_RAYS?: boolean;
47
+ /** WebGL2 only - whether to use multiple render targets when rendering the G-buffers (normals, depth and roughness); using them can improve performance as they will render all information to multiple buffers for each fragment in one run; this setting can't be changed during run-time */
48
+ USE_MRT?: boolean;
49
+ /** if roughness maps should be taken account of when calculating reflections */
50
+ USE_ROUGHNESSMAP?: boolean;
51
+ /** if normal maps should be taken account of when calculating reflections */
52
+ USE_NORMALMAP?: boolean;
47
53
  };
48
- export declare const SSR: import("react").ForwardRefExoticComponent<SSRProps & import("react").RefAttributes<SSRPass>>;
54
+ export declare const SSR: React.ForwardRefExoticComponent<SSRProps & React.RefAttributes<SSREffect>>;
49
55
  export {};
package/dist/index.cjs CHANGED
@@ -701,101 +701,38 @@ var LUT = /*#__PURE__*/React.forwardRef(function LUT(_ref, ref) {
701
701
  });
702
702
  });
703
703
 
704
- var _excluded = ["resolutionScale", "blurSize", "enabled"];
704
+ var _excluded = ["ENABLE_BLUR", "USE_MRT"];
705
705
 
706
706
  var SSR = /*#__PURE__*/React.forwardRef(function SSR(_ref, ref) {
707
- var _ref$resolutionScale = _ref.resolutionScale,
708
- resolutionScale = _ref$resolutionScale === void 0 ? 1 : _ref$resolutionScale,
709
- _ref$blurSize = _ref.blurSize,
710
- blurSize = _ref$blurSize === void 0 ? 512 : _ref$blurSize,
711
- _ref$enabled = _ref.enabled,
712
- enabled = _ref$enabled === void 0 ? true : _ref$enabled,
707
+ var _ref$ENABLE_BLUR = _ref.ENABLE_BLUR,
708
+ ENABLE_BLUR = _ref$ENABLE_BLUR === void 0 ? true : _ref$ENABLE_BLUR,
709
+ _ref$USE_MRT = _ref.USE_MRT,
710
+ USE_MRT = _ref$USE_MRT === void 0 ? true : _ref$USE_MRT,
713
711
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded);
714
712
 
715
713
  var _useThree = fiber.useThree(),
716
- size = _useThree.size,
717
- viewport = _useThree.viewport,
718
714
  invalidate = _useThree.invalidate;
719
715
 
720
716
  var _useContext = React.useContext(EffectComposerContext),
721
- composer = _useContext.composer,
722
717
  scene = _useContext.scene,
723
718
  camera = _useContext.camera;
724
719
 
725
- var _useState = React.useState(function () {
726
- return new screenSpaceReflections.SSRPass(scene, camera, _extends__default["default"]({
727
- width: size.width * viewport.dpr * resolutionScale,
728
- height: size.height * viewport.dpr * resolutionScale,
729
- blurWidth: blurSize,
730
- blurHeight: blurSize,
731
- blurKernelSize: postprocessing.KernelSize.SMALL,
732
- rayStep: 0.1,
733
- intensity: 1,
734
- power: 1,
735
- depthBlur: 0.1,
736
- enableJittering: false,
737
- jitter: 0.1,
738
- jitterSpread: 0.1,
739
- roughnessFadeOut: 1,
740
- MAX_STEPS: 20,
741
- NUM_BINARY_SEARCH_STEPS: 5,
742
- maxDepthDifference: 1,
743
- maxDepth: 1,
744
- thickness: 10,
745
- ior: 1.45,
746
- useBlur: true,
747
- useMRT: true,
748
- useNormalMap: true,
749
- useRoughnessMap: true
720
+ var effect = React.useMemo(function () {
721
+ return new screenSpaceReflections.SSREffect(scene, camera, _extends__default["default"]({
722
+ ENABLE_BLUR: ENABLE_BLUR,
723
+ USE_MRT: USE_MRT
750
724
  }, props));
751
- }),
752
- pass = _useState[0];
753
-
754
- React.useEffect(function () {
725
+ }, [screenSpaceReflections.SSREffect, scene, camera, ENABLE_BLUR, USE_MRT]);
726
+ React.useLayoutEffect(function () {
755
727
  Object.keys(props).forEach(function (key) {
756
- return pass.reflectionUniforms[key] && (pass.reflectionUniforms[key].value = props[key]);
728
+ return effect[key] = props[key];
757
729
  });
758
730
  invalidate();
759
731
  }, [props]);
760
- React.useEffect(function () {
761
- // Steps
762
- pass.reflectionsPass.fullscreenMaterial.defines.MAX_STEPS = Math.ceil(props.MAX_STEPS);
763
- pass.reflectionsPass.fullscreenMaterial.defines.NUM_BINARY_SEARCH_STEPS = Math.ceil(props.NUM_BINARY_SEARCH_STEPS); // Blur
764
-
765
- if (props.useBlur) {
766
- pass.fullscreenMaterial.defines.USE_BLUR = '';
767
- pass.reflectionsPass.fullscreenMaterial.defines.USE_BLUR = '';
768
- } else {
769
- delete pass.fullscreenMaterial.defines.USE_BLUR;
770
- delete pass.reflectionsPass.fullscreenMaterial.defines.USE_BLUR;
771
- } // Jitter
772
-
773
-
774
- if (props.enableJittering) {
775
- pass.reflectionsPass.fullscreenMaterial.defines.USE_JITTERING = '';
776
- } else {
777
- delete pass.reflectionsPass.fullscreenMaterial.defines.USE_JITTERING;
778
- } // Enabled
779
-
780
-
781
- pass.fullscreenMaterial.defines.RENDER_MODE = enabled ? 0 : 4; // Update materials
782
-
783
- pass.reflectionsPass.fullscreenMaterial.needsUpdate = true;
784
- pass.fullscreenMaterial.needsUpdate = true;
785
- invalidate();
786
- }, [enabled, props.useBlur, props.enableJittering, props.NUM_BINARY_SEARCH_STEPS, props.MAX_STEPS]);
787
- React.useEffect(function () {
788
- pass.setSize(size.width * viewport.dpr * resolutionScale, size.height * viewport.dpr * resolutionScale);
789
- pass.kawaseBlurPass.setSize(blurSize, blurSize);
790
- invalidate();
791
- }, [resolutionScale, blurSize, size, viewport, composer, pass, invalidate]);
792
- React.useLayoutEffect(function () {
793
- composer.addPass(pass);
794
- return function () {
795
- composer.removePass(pass); //pass.dispose()
796
- };
797
- }, [composer, pass]);
798
- return null;
732
+ return /*#__PURE__*/React__default["default"].createElement("primitive", {
733
+ ref: ref,
734
+ object: effect
735
+ });
799
736
  });
800
737
 
801
738
  exports.Bloom = Bloom;
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAPreset, EdgeDetectionMode, SMAAImageLoader, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUTEffect, KernelSize } from 'postprocessing';
1
+ import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAPreset, EdgeDetectionMode, SMAAImageLoader, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUTEffect } from 'postprocessing';
2
2
  import React, { forwardRef, useMemo, useLayoutEffect, createContext, useEffect, useRef, useImperativeHandle, useContext, useState } from 'react';
3
3
  import { Vector2, HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping } from 'three';
4
4
  import { useThree, useFrame, useLoader } from '@react-three/fiber';
5
5
  import { isWebGL2Available } from 'three-stdlib';
6
6
  import mergeRefs from 'react-merge-refs';
7
7
  import _extends from '@babel/runtime/helpers/esm/extends';
8
- import { SSRPass } from 'screen-space-reflections';
8
+ import { SSREffect } from 'screen-space-reflections';
9
9
 
10
10
  const isRef = ref => !!ref.current;
11
11
 
@@ -597,90 +597,30 @@ const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
597
597
 
598
598
  const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
599
599
  let {
600
- resolutionScale = 1,
601
- blurSize = 512,
602
- enabled = true,
600
+ ENABLE_BLUR = true,
601
+ USE_MRT = true,
603
602
  ...props
604
603
  } = _ref;
605
604
  const {
606
- size,
607
- viewport,
608
605
  invalidate
609
606
  } = useThree();
610
607
  const {
611
- composer,
612
608
  scene,
613
609
  camera
614
610
  } = useContext(EffectComposerContext);
615
- const [pass] = useState(() => new SSRPass(scene, camera, {
616
- width: size.width * viewport.dpr * resolutionScale,
617
- height: size.height * viewport.dpr * resolutionScale,
618
- blurWidth: blurSize,
619
- blurHeight: blurSize,
620
- blurKernelSize: KernelSize.SMALL,
621
- rayStep: 0.1,
622
- intensity: 1,
623
- power: 1,
624
- depthBlur: 0.1,
625
- enableJittering: false,
626
- jitter: 0.1,
627
- jitterSpread: 0.1,
628
- roughnessFadeOut: 1,
629
- MAX_STEPS: 20,
630
- NUM_BINARY_SEARCH_STEPS: 5,
631
- maxDepthDifference: 1,
632
- maxDepth: 1,
633
- thickness: 10,
634
- ior: 1.45,
635
- useBlur: true,
636
- useMRT: true,
637
- useNormalMap: true,
638
- useRoughnessMap: true,
611
+ const effect = useMemo(() => new SSREffect(scene, camera, {
612
+ ENABLE_BLUR,
613
+ USE_MRT,
639
614
  ...props
640
- }));
641
- useEffect(() => {
642
- Object.keys(props).forEach(key => pass.reflectionUniforms[key] && (pass.reflectionUniforms[key].value = props[key]));
615
+ }), [SSREffect, scene, camera, ENABLE_BLUR, USE_MRT]);
616
+ useLayoutEffect(() => {
617
+ Object.keys(props).forEach(key => effect[key] = props[key]);
643
618
  invalidate();
644
619
  }, [props]);
645
- useEffect(() => {
646
- // Steps
647
- pass.reflectionsPass.fullscreenMaterial.defines.MAX_STEPS = Math.ceil(props.MAX_STEPS);
648
- pass.reflectionsPass.fullscreenMaterial.defines.NUM_BINARY_SEARCH_STEPS = Math.ceil(props.NUM_BINARY_SEARCH_STEPS); // Blur
649
-
650
- if (props.useBlur) {
651
- pass.fullscreenMaterial.defines.USE_BLUR = '';
652
- pass.reflectionsPass.fullscreenMaterial.defines.USE_BLUR = '';
653
- } else {
654
- delete pass.fullscreenMaterial.defines.USE_BLUR;
655
- delete pass.reflectionsPass.fullscreenMaterial.defines.USE_BLUR;
656
- } // Jitter
657
-
658
-
659
- if (props.enableJittering) {
660
- pass.reflectionsPass.fullscreenMaterial.defines.USE_JITTERING = '';
661
- } else {
662
- delete pass.reflectionsPass.fullscreenMaterial.defines.USE_JITTERING;
663
- } // Enabled
664
-
665
-
666
- pass.fullscreenMaterial.defines.RENDER_MODE = enabled ? 0 : 4; // Update materials
667
-
668
- pass.reflectionsPass.fullscreenMaterial.needsUpdate = true;
669
- pass.fullscreenMaterial.needsUpdate = true;
670
- invalidate();
671
- }, [enabled, props.useBlur, props.enableJittering, props.NUM_BINARY_SEARCH_STEPS, props.MAX_STEPS]);
672
- useEffect(() => {
673
- pass.setSize(size.width * viewport.dpr * resolutionScale, size.height * viewport.dpr * resolutionScale);
674
- pass.kawaseBlurPass.setSize(blurSize, blurSize);
675
- invalidate();
676
- }, [resolutionScale, blurSize, size, viewport, composer, pass, invalidate]);
677
- useLayoutEffect(() => {
678
- composer.addPass(pass);
679
- return () => {
680
- composer.removePass(pass); //pass.dispose()
681
- };
682
- }, [composer, pass]);
683
- return null;
620
+ return /*#__PURE__*/React.createElement("primitive", {
621
+ ref: ref,
622
+ object: effect
623
+ });
684
624
  });
685
625
 
686
626
  export { Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DotScreen, EffectComposer, EffectComposerContext, Glitch, GodRays, Grid, HueSaturation, LUT, Noise, Outline, Pixelation, SMAA, SSAO, SSR, Scanline, Select, Selection, SelectiveBloom, Sepia, ShockWave, Texture, ToneMapping, Vignette, selectionContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/postprocessing",
3
- "version": "2.4.5",
3
+ "version": "2.5.1",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",
@@ -39,9 +39,9 @@
39
39
  "typegen": "tsc --emitDeclarationOnly || true"
40
40
  },
41
41
  "dependencies": {
42
- "postprocessing": "^6.28.1",
42
+ "postprocessing": "^6.28.4",
43
43
  "react-merge-refs": "^1.1.0",
44
- "screen-space-reflections": "^1.0.7",
44
+ "screen-space-reflections": "^2.0.6",
45
45
  "three-stdlib": "^2.8.11"
46
46
  },
47
47
  "devDependencies": {