@react-three/postprocessing 2.7.1 → 2.8.0

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.
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ import { BlendFunction, Effect } from 'postprocessing';
3
+ export declare class TiltShiftEffect extends Effect {
4
+ constructor({ blendFunction, blur, gradient, start, end, delta, }?: {
5
+ blendFunction?: BlendFunction;
6
+ blur?: number;
7
+ gradient?: number;
8
+ start?: number[];
9
+ end?: number[];
10
+ delta?: number[];
11
+ });
12
+ }
13
+ export declare const TiltShift2: import("react").ForwardRefExoticComponent<{
14
+ blendFunction?: BlendFunction;
15
+ blur?: number;
16
+ gradient?: number;
17
+ start?: number[];
18
+ end?: number[];
19
+ delta?: number[];
20
+ } & Partial<{
21
+ blendFunction: BlendFunction;
22
+ opacity: number;
23
+ }> & import("react").RefAttributes<typeof TiltShiftEffect>>;
package/dist/index.cjs CHANGED
@@ -10,6 +10,7 @@ var fiber = require('@react-three/fiber');
10
10
  var _extends = require('@babel/runtime/helpers/extends');
11
11
  var _construct = require('@babel/runtime/helpers/construct');
12
12
  var threeStdlib = require('three-stdlib');
13
+ var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
13
14
  var screenSpaceReflections = require('screen-space-reflections');
14
15
 
15
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -18,6 +19,7 @@ var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(
18
19
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
19
20
  var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
20
21
  var _construct__default = /*#__PURE__*/_interopDefaultLegacy(_construct);
22
+ var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
21
23
 
22
24
  var _excluded$9 = ["blendFunction", "opacity"];
23
25
 
@@ -702,6 +704,38 @@ var LUT = /*#__PURE__*/React.forwardRef(function LUT(_ref, ref) {
702
704
 
703
705
  var TiltShift = wrapEffect(postprocessing.TiltShiftEffect, postprocessing.BlendFunction.ADD);
704
706
 
707
+ var TiltShiftShader = {
708
+ fragmentShader: "\n // original shader by Evan Wallace\n uniform float blur;\n uniform float gradient;\n uniform vec2 start;\n uniform vec2 end;\n uniform vec2 delta;\n\n float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n }\n\n void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {\n\n vec4 color = vec4(0.0);\n float total = 0.0;\n vec2 startPixel = vec2(start.x * resolution.x, start.y * resolution.y);\n vec2 endPixel = vec2(end.x * resolution.x, end.y * resolution.y);\n\n /* randomize the lookup values to hide the fixed number of samples */\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n vec2 normal = normalize(vec2(startPixel.y - endPixel.y, endPixel.x - startPixel.x));\n float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradient) * blur;\n\n #pragma unroll_loop_start\n for (float i = -3.0; i <= 3.0; i++) {\n float percent = (i + offset - 0.5) / 3.0;\n float weight = 1.0 - abs(percent);\n vec4 sample_t = texture2D(inputBuffer, uv + delta / resolution * percent * radius);\n /* switch to pre-multiplied alpha to correctly blur transparent images */\n sample_t.rgb *= sample_t.a;\n color += sample_t * weight;\n total += weight;\n }\n #pragma unroll_loop_end\n\n outputColor = color / total;\n /* switch back from pre-multiplied alpha */\n outputColor.rgb /= outputColor.a + 0.00001;\n }\n "
709
+ };
710
+ var TiltShiftEffect = /*#__PURE__*/function (_Effect) {
711
+ _inheritsLoose__default["default"](TiltShiftEffect, _Effect);
712
+
713
+ function TiltShiftEffect(_temp) {
714
+ var _ref = _temp === void 0 ? {} : _temp,
715
+ _ref$blendFunction = _ref.blendFunction,
716
+ blendFunction = _ref$blendFunction === void 0 ? postprocessing.BlendFunction.ADD : _ref$blendFunction,
717
+ _ref$blur = _ref.blur,
718
+ blur = _ref$blur === void 0 ? 20.0 : _ref$blur,
719
+ _ref$gradient = _ref.gradient,
720
+ gradient = _ref$gradient === void 0 ? 1100.0 : _ref$gradient,
721
+ _ref$start = _ref.start,
722
+ start = _ref$start === void 0 ? [0.5, 0.0] : _ref$start,
723
+ _ref$end = _ref.end,
724
+ end = _ref$end === void 0 ? [0.5, 1.0] : _ref$end,
725
+ _ref$delta = _ref.delta,
726
+ delta = _ref$delta === void 0 ? [1, 1] : _ref$delta;
727
+
728
+ return _Effect.call(this, 'TiltShiftEffect', TiltShiftShader.fragmentShader, {
729
+ blendFunction: blendFunction,
730
+ attributes: postprocessing.EffectAttribute.CONVOLUTION,
731
+ uniforms: new Map([['blur', new three.Uniform(blur)], ['gradient', new three.Uniform(gradient)], ['start', new three.Uniform(start)], ['end', new three.Uniform(end)], ['delta', new three.Uniform(delta)]])
732
+ }) || this;
733
+ }
734
+
735
+ return TiltShiftEffect;
736
+ }(postprocessing.Effect);
737
+ var TiltShift2 = wrapEffect(TiltShiftEffect, postprocessing.BlendFunction.NORMAL);
738
+
705
739
  var _excluded = ["ENABLE_BLUR", "USE_MRT"];
706
740
 
707
741
  var SSR = /*#__PURE__*/React.forwardRef(function SSR(_ref, ref) {
@@ -780,6 +814,8 @@ exports.Sepia = Sepia;
780
814
  exports.ShockWave = ShockWave;
781
815
  exports.Texture = Texture;
782
816
  exports.TiltShift = TiltShift;
817
+ exports.TiltShift2 = TiltShift2;
818
+ exports.TiltShiftEffect = TiltShiftEffect;
783
819
  exports.ToneMapping = ToneMapping;
784
820
  exports.Vignette = Vignette;
785
821
  exports.selectionContext = selectionContext;
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export * from './effects/Vignette';
24
24
  export * from './effects/ShockWave';
25
25
  export * from './effects/LUT';
26
26
  export * from './effects/TiltShift';
27
+ export * from './effects/TiltShift2';
27
28
  export * from './effects/SSR';
28
29
  export * from './Selection';
29
30
  export * from './EffectComposer';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
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, TiltShiftEffect } 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, TiltShiftEffect as TiltShiftEffect$1, Effect, EffectAttribute } from 'postprocessing';
2
2
  import React, { forwardRef, useMemo, useLayoutEffect, createContext, useEffect, useRef, useImperativeHandle, useContext, useState } from 'react';
3
- import { Vector2, HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping } from 'three';
3
+ import { Vector2, HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
4
4
  import { useThree, useFrame, useLoader } from '@react-three/fiber';
5
5
  import { isWebGL2Available } from 'three-stdlib';
6
6
  import _extends from '@babel/runtime/helpers/esm/extends';
@@ -599,7 +599,71 @@ const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
599
599
  });
600
600
  });
601
601
 
602
- const TiltShift = wrapEffect(TiltShiftEffect, BlendFunction.ADD);
602
+ const TiltShift = wrapEffect(TiltShiftEffect$1, BlendFunction.ADD);
603
+
604
+ const TiltShiftShader = {
605
+ fragmentShader: `
606
+ // original shader by Evan Wallace
607
+ uniform float blur;
608
+ uniform float gradient;
609
+ uniform vec2 start;
610
+ uniform vec2 end;
611
+ uniform vec2 delta;
612
+
613
+ float random(vec3 scale, float seed) {
614
+ /* use the fragment position for a different seed per-pixel */
615
+ return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
616
+ }
617
+
618
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
619
+
620
+ vec4 color = vec4(0.0);
621
+ float total = 0.0;
622
+ vec2 startPixel = vec2(start.x * resolution.x, start.y * resolution.y);
623
+ vec2 endPixel = vec2(end.x * resolution.x, end.y * resolution.y);
624
+
625
+ /* randomize the lookup values to hide the fixed number of samples */
626
+ float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
627
+ vec2 normal = normalize(vec2(startPixel.y - endPixel.y, endPixel.x - startPixel.x));
628
+ float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradient) * blur;
629
+
630
+ #pragma unroll_loop_start
631
+ for (float i = -3.0; i <= 3.0; i++) {
632
+ float percent = (i + offset - 0.5) / 3.0;
633
+ float weight = 1.0 - abs(percent);
634
+ vec4 sample_t = texture2D(inputBuffer, uv + delta / resolution * percent * radius);
635
+ /* switch to pre-multiplied alpha to correctly blur transparent images */
636
+ sample_t.rgb *= sample_t.a;
637
+ color += sample_t * weight;
638
+ total += weight;
639
+ }
640
+ #pragma unroll_loop_end
641
+
642
+ outputColor = color / total;
643
+ /* switch back from pre-multiplied alpha */
644
+ outputColor.rgb /= outputColor.a + 0.00001;
645
+ }
646
+ `
647
+ };
648
+ class TiltShiftEffect extends Effect {
649
+ constructor(_temp) {
650
+ let {
651
+ blendFunction = BlendFunction.ADD,
652
+ blur = 20.0,
653
+ gradient = 1100.0,
654
+ start = [0.5, 0.0],
655
+ end = [0.5, 1.0],
656
+ delta = [1, 1]
657
+ } = _temp === void 0 ? {} : _temp;
658
+ super('TiltShiftEffect', TiltShiftShader.fragmentShader, {
659
+ blendFunction,
660
+ attributes: EffectAttribute.CONVOLUTION,
661
+ uniforms: new Map([['blur', new Uniform(blur)], ['gradient', new Uniform(gradient)], ['start', new Uniform(start)], ['end', new Uniform(end)], ['delta', new Uniform(delta)]])
662
+ });
663
+ }
664
+
665
+ }
666
+ const TiltShift2 = wrapEffect(TiltShiftEffect, BlendFunction.NORMAL);
603
667
 
604
668
  const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
605
669
  let {
@@ -644,4 +708,4 @@ const SSR = /*#__PURE__*/forwardRef(function SSR(_ref, ref) {
644
708
  });
645
709
  });
646
710
 
647
- 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, TiltShift, ToneMapping, Vignette, selectionContext };
711
+ 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, TiltShift, TiltShift2, TiltShiftEffect, ToneMapping, Vignette, selectionContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/postprocessing",
3
- "version": "2.7.1",
3
+ "version": "2.8.0",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",