@react-three/postprocessing 3.0.2 → 3.0.3

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 (45) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +81 -81
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +555 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +66 -68
  7. package/src/EffectComposer.test.tsx +126 -126
  8. package/src/EffectComposer.tsx +200 -200
  9. package/src/Selection.tsx +46 -46
  10. package/src/effects/ASCII.tsx +135 -135
  11. package/src/effects/Autofocus.tsx +153 -153
  12. package/src/effects/Bloom.tsx +6 -6
  13. package/src/effects/BrightnessContrast.tsx +4 -4
  14. package/src/effects/ChromaticAberration.tsx +5 -5
  15. package/src/effects/ColorAverage.tsx +15 -15
  16. package/src/effects/ColorDepth.tsx +4 -4
  17. package/src/effects/Depth.tsx +4 -4
  18. package/src/effects/DepthOfField.tsx +89 -89
  19. package/src/effects/DotScreen.tsx +4 -4
  20. package/src/effects/FXAA.tsx +4 -4
  21. package/src/effects/Glitch.tsx +40 -40
  22. package/src/effects/GodRays.tsx +16 -16
  23. package/src/effects/Grid.tsx +21 -21
  24. package/src/effects/HueSaturation.tsx +4 -4
  25. package/src/effects/LUT.tsx +26 -26
  26. package/src/effects/LensFlare.tsx +611 -611
  27. package/src/effects/N8AO.tsx +81 -81
  28. package/src/effects/Noise.tsx +4 -4
  29. package/src/effects/Outline.tsx +117 -117
  30. package/src/effects/Pixelation.tsx +15 -15
  31. package/src/effects/Ramp.tsx +150 -150
  32. package/src/effects/SMAA.tsx +4 -4
  33. package/src/effects/SSAO.tsx +41 -41
  34. package/src/effects/ScanlineEffect.tsx +7 -7
  35. package/src/effects/SelectiveBloom.tsx +126 -126
  36. package/src/effects/Sepia.tsx +4 -4
  37. package/src/effects/ShockWave.tsx +4 -4
  38. package/src/effects/Texture.tsx +23 -23
  39. package/src/effects/TiltShift.tsx +4 -4
  40. package/src/effects/TiltShift2.tsx +90 -90
  41. package/src/effects/ToneMapping.tsx +6 -6
  42. package/src/effects/Vignette.tsx +4 -4
  43. package/src/effects/Water.tsx +35 -35
  44. package/src/index.ts +40 -40
  45. package/src/util.tsx +55 -55
@@ -1,89 +1,89 @@
1
- import { DepthOfFieldEffect, MaskFunction } from 'postprocessing'
2
- import { Ref, forwardRef, useMemo, useEffect, useContext } from 'react'
3
- import { ReactThreeFiber } from '@react-three/fiber'
4
- import { type DepthPackingStrategies, type Texture, Vector3 } from 'three'
5
- import { EffectComposerContext } from '../EffectComposer'
6
-
7
- type DOFProps = ConstructorParameters<typeof DepthOfFieldEffect>[1] &
8
- Partial<{
9
- target: ReactThreeFiber.Vector3
10
- depthTexture: {
11
- texture: Texture
12
- // TODO: narrow to DepthPackingStrategies
13
- packing: number
14
- }
15
- // TODO: not used
16
- blur: number
17
- }>
18
-
19
- export const DepthOfField = /* @__PURE__ */ forwardRef(function DepthOfField(
20
- {
21
- blendFunction,
22
- worldFocusDistance,
23
- worldFocusRange,
24
- focusDistance,
25
- focusRange,
26
- focalLength,
27
- bokehScale,
28
- resolutionScale,
29
- resolutionX,
30
- resolutionY,
31
- width,
32
- height,
33
- target,
34
- depthTexture,
35
- ...props
36
- }: DOFProps,
37
- ref: Ref<DepthOfFieldEffect>
38
- ) {
39
- const { camera } = useContext(EffectComposerContext)
40
- const autoFocus = target != null
41
- const effect = useMemo(() => {
42
- const effect = new DepthOfFieldEffect(camera, {
43
- blendFunction,
44
- worldFocusDistance,
45
- worldFocusRange,
46
- focusDistance,
47
- focusRange,
48
- focalLength,
49
- bokehScale,
50
- resolutionScale,
51
- resolutionX,
52
- resolutionY,
53
- width,
54
- height,
55
- })
56
- // Creating a target enables autofocus, R3F will set via props
57
- if (autoFocus) effect.target = new Vector3()
58
- // Depth texture for depth picking with optional packing strategy
59
- if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing as DepthPackingStrategies)
60
- // Temporary fix that restores DOF 6.21.3 behavior, everything since then lets shapes leak through the blur
61
- const maskPass = (effect as any).maskPass
62
- maskPass.maskFunction = MaskFunction.MULTIPLY_RGB_SET_ALPHA
63
- return effect
64
- }, [
65
- camera,
66
- blendFunction,
67
- worldFocusDistance,
68
- worldFocusRange,
69
- focusDistance,
70
- focusRange,
71
- focalLength,
72
- bokehScale,
73
- resolutionScale,
74
- resolutionX,
75
- resolutionY,
76
- width,
77
- height,
78
- autoFocus,
79
- depthTexture,
80
- ])
81
-
82
- useEffect(() => {
83
- return () => {
84
- effect.dispose()
85
- }
86
- }, [effect])
87
-
88
- return <primitive {...props} ref={ref} object={effect} target={target} />
89
- })
1
+ import { DepthOfFieldEffect, MaskFunction } from 'postprocessing'
2
+ import { Ref, forwardRef, useMemo, useEffect, useContext } from 'react'
3
+ import { ReactThreeFiber } from '@react-three/fiber'
4
+ import { type DepthPackingStrategies, type Texture, Vector3 } from 'three'
5
+ import { EffectComposerContext } from '../EffectComposer'
6
+
7
+ type DOFProps = ConstructorParameters<typeof DepthOfFieldEffect>[1] &
8
+ Partial<{
9
+ target: ReactThreeFiber.Vector3
10
+ depthTexture: {
11
+ texture: Texture
12
+ // TODO: narrow to DepthPackingStrategies
13
+ packing: number
14
+ }
15
+ // TODO: not used
16
+ blur: number
17
+ }>
18
+
19
+ export const DepthOfField = /* @__PURE__ */ forwardRef(function DepthOfField(
20
+ {
21
+ blendFunction,
22
+ worldFocusDistance,
23
+ worldFocusRange,
24
+ focusDistance,
25
+ focusRange,
26
+ focalLength,
27
+ bokehScale,
28
+ resolutionScale,
29
+ resolutionX,
30
+ resolutionY,
31
+ width,
32
+ height,
33
+ target,
34
+ depthTexture,
35
+ ...props
36
+ }: DOFProps,
37
+ ref: Ref<DepthOfFieldEffect>
38
+ ) {
39
+ const { camera } = useContext(EffectComposerContext)
40
+ const autoFocus = target != null
41
+ const effect = useMemo(() => {
42
+ const effect = new DepthOfFieldEffect(camera, {
43
+ blendFunction,
44
+ worldFocusDistance,
45
+ worldFocusRange,
46
+ focusDistance,
47
+ focusRange,
48
+ focalLength,
49
+ bokehScale,
50
+ resolutionScale,
51
+ resolutionX,
52
+ resolutionY,
53
+ width,
54
+ height,
55
+ })
56
+ // Creating a target enables autofocus, R3F will set via props
57
+ if (autoFocus) effect.target = new Vector3()
58
+ // Depth texture for depth picking with optional packing strategy
59
+ if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing as DepthPackingStrategies)
60
+ // Temporary fix that restores DOF 6.21.3 behavior, everything since then lets shapes leak through the blur
61
+ const maskPass = (effect as any).maskPass
62
+ maskPass.maskFunction = MaskFunction.MULTIPLY_RGB_SET_ALPHA
63
+ return effect
64
+ }, [
65
+ camera,
66
+ blendFunction,
67
+ worldFocusDistance,
68
+ worldFocusRange,
69
+ focusDistance,
70
+ focusRange,
71
+ focalLength,
72
+ bokehScale,
73
+ resolutionScale,
74
+ resolutionX,
75
+ resolutionY,
76
+ width,
77
+ height,
78
+ autoFocus,
79
+ depthTexture,
80
+ ])
81
+
82
+ useEffect(() => {
83
+ return () => {
84
+ effect.dispose()
85
+ }
86
+ }, [effect])
87
+
88
+ return <primitive {...props} ref={ref} object={effect} target={target} />
89
+ })
@@ -1,4 +1,4 @@
1
- import { DotScreenEffect } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const DotScreen = /* @__PURE__ */ wrapEffect(DotScreenEffect)
1
+ import { DotScreenEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../util'
3
+
4
+ export const DotScreen = /* @__PURE__ */ wrapEffect(DotScreenEffect)
@@ -1,4 +1,4 @@
1
- import { FXAAEffect } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const FXAA = /* @__PURE__ */ wrapEffect(FXAAEffect)
1
+ import { FXAAEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../util'
3
+
4
+ export const FXAA = /* @__PURE__ */ wrapEffect(FXAAEffect)
@@ -1,40 +1,40 @@
1
- import { Vector2 } from 'three'
2
- import { GlitchEffect, GlitchMode } from 'postprocessing'
3
- import { Ref, forwardRef, useMemo, useLayoutEffect, useEffect } from 'react'
4
- import { ReactThreeFiber, useThree } from '@react-three/fiber'
5
- import { useVector2 } from '../util'
6
-
7
- export type GlitchProps = ConstructorParameters<typeof GlitchEffect>[0] &
8
- Partial<{
9
- mode: GlitchMode
10
- active: boolean
11
- delay: ReactThreeFiber.Vector2
12
- duration: ReactThreeFiber.Vector2
13
- chromaticAberrationOffset: ReactThreeFiber.Vector2
14
- strength: ReactThreeFiber.Vector2
15
- }>
16
-
17
- export const Glitch = /* @__PURE__ */ forwardRef<GlitchEffect, GlitchProps>(function Glitch(
18
- { active = true, ...props }: GlitchProps,
19
- ref: Ref<GlitchEffect>
20
- ) {
21
- const invalidate = useThree((state) => state.invalidate)
22
- const delay = useVector2(props, 'delay')
23
- const duration = useVector2(props, 'duration')
24
- const strength = useVector2(props, 'strength')
25
- const chromaticAberrationOffset = useVector2(props, 'chromaticAberrationOffset')
26
- const effect = useMemo(
27
- () => new GlitchEffect({ ...props, delay, duration, strength, chromaticAberrationOffset }),
28
- [delay, duration, props, strength, chromaticAberrationOffset]
29
- )
30
- useLayoutEffect(() => {
31
- effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED
32
- invalidate()
33
- }, [active, effect, invalidate, props.mode])
34
- useEffect(() => {
35
- return () => {
36
- effect.dispose?.()
37
- }
38
- }, [effect])
39
- return <primitive ref={ref} object={effect} dispose={null} />
40
- })
1
+ import { Vector2 } from 'three'
2
+ import { GlitchEffect, GlitchMode } from 'postprocessing'
3
+ import { Ref, forwardRef, useMemo, useLayoutEffect, useEffect } from 'react'
4
+ import { ReactThreeFiber, useThree } from '@react-three/fiber'
5
+ import { useVector2 } from '../util'
6
+
7
+ export type GlitchProps = ConstructorParameters<typeof GlitchEffect>[0] &
8
+ Partial<{
9
+ mode: GlitchMode
10
+ active: boolean
11
+ delay: ReactThreeFiber.Vector2
12
+ duration: ReactThreeFiber.Vector2
13
+ chromaticAberrationOffset: ReactThreeFiber.Vector2
14
+ strength: ReactThreeFiber.Vector2
15
+ }>
16
+
17
+ export const Glitch = /* @__PURE__ */ forwardRef<GlitchEffect, GlitchProps>(function Glitch(
18
+ { active = true, ...props }: GlitchProps,
19
+ ref: Ref<GlitchEffect>
20
+ ) {
21
+ const invalidate = useThree((state) => state.invalidate)
22
+ const delay = useVector2(props, 'delay')
23
+ const duration = useVector2(props, 'duration')
24
+ const strength = useVector2(props, 'strength')
25
+ const chromaticAberrationOffset = useVector2(props, 'chromaticAberrationOffset')
26
+ const effect = useMemo(
27
+ () => new GlitchEffect({ ...props, delay, duration, strength, chromaticAberrationOffset }),
28
+ [delay, duration, props, strength, chromaticAberrationOffset]
29
+ )
30
+ useLayoutEffect(() => {
31
+ effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED
32
+ invalidate()
33
+ }, [active, effect, invalidate, props.mode])
34
+ useEffect(() => {
35
+ return () => {
36
+ effect.dispose?.()
37
+ }
38
+ }, [effect])
39
+ return <primitive ref={ref} object={effect} dispose={null} />
40
+ })
@@ -1,16 +1,16 @@
1
- import { GodRaysEffect } from 'postprocessing'
2
- import React, { Ref, forwardRef, useMemo, useContext, useLayoutEffect } from 'react'
3
- import { Mesh, Points } from 'three'
4
- import { EffectComposerContext } from '../EffectComposer'
5
- import { resolveRef } from '../util'
6
-
7
- type GodRaysProps = ConstructorParameters<typeof GodRaysEffect>[2] & {
8
- sun: Mesh | Points | React.RefObject<Mesh | Points>
9
- }
10
-
11
- export const GodRays = /* @__PURE__ */ forwardRef(function GodRays(props: GodRaysProps, ref: Ref<GodRaysEffect>) {
12
- const { camera } = useContext(EffectComposerContext)
13
- const effect = useMemo(() => new GodRaysEffect(camera, resolveRef(props.sun), props), [camera, props])
14
- useLayoutEffect(() => void (effect.lightSource = resolveRef(props.sun)), [effect, props.sun])
15
- return <primitive ref={ref} object={effect} dispose={null} />
16
- })
1
+ import { GodRaysEffect } from 'postprocessing'
2
+ import React, { Ref, forwardRef, useMemo, useContext, useLayoutEffect } from 'react'
3
+ import { Mesh, Points } from 'three'
4
+ import { EffectComposerContext } from '../EffectComposer'
5
+ import { resolveRef } from '../util'
6
+
7
+ type GodRaysProps = ConstructorParameters<typeof GodRaysEffect>[2] & {
8
+ sun: Mesh | Points | React.RefObject<Mesh | Points>
9
+ }
10
+
11
+ export const GodRays = /* @__PURE__ */ forwardRef(function GodRays(props: GodRaysProps, ref: Ref<GodRaysEffect>) {
12
+ const { camera } = useContext(EffectComposerContext)
13
+ const effect = useMemo(() => new GodRaysEffect(camera, resolveRef(props.sun), props), [camera, props])
14
+ useLayoutEffect(() => void (effect.lightSource = resolveRef(props.sun)), [effect, props.sun])
15
+ return <primitive ref={ref} object={effect} dispose={null} />
16
+ })
@@ -1,21 +1,21 @@
1
- import React, { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'
2
- import { GridEffect } from 'postprocessing'
3
- import { useThree } from '@react-three/fiber'
4
-
5
- type GridProps = ConstructorParameters<typeof GridEffect>[0] &
6
- Partial<{
7
- size: {
8
- width: number
9
- height: number
10
- }
11
- }>
12
-
13
- export const Grid = /* @__PURE__ */ forwardRef(function Grid({ size, ...props }: GridProps, ref: Ref<GridEffect>) {
14
- const invalidate = useThree((state) => state.invalidate)
15
- const effect = useMemo(() => new GridEffect(props), [props])
16
- useLayoutEffect(() => {
17
- if (size) effect.setSize(size.width, size.height)
18
- invalidate()
19
- }, [effect, size, invalidate])
20
- return <primitive ref={ref} object={effect} dispose={null} />
21
- })
1
+ import React, { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'
2
+ import { GridEffect } from 'postprocessing'
3
+ import { useThree } from '@react-three/fiber'
4
+
5
+ type GridProps = ConstructorParameters<typeof GridEffect>[0] &
6
+ Partial<{
7
+ size: {
8
+ width: number
9
+ height: number
10
+ }
11
+ }>
12
+
13
+ export const Grid = /* @__PURE__ */ forwardRef(function Grid({ size, ...props }: GridProps, ref: Ref<GridEffect>) {
14
+ const invalidate = useThree((state) => state.invalidate)
15
+ const effect = useMemo(() => new GridEffect(props), [props])
16
+ useLayoutEffect(() => {
17
+ if (size) effect.setSize(size.width, size.height)
18
+ invalidate()
19
+ }, [effect, size, invalidate])
20
+ return <primitive ref={ref} object={effect} dispose={null} />
21
+ })
@@ -1,4 +1,4 @@
1
- import { HueSaturationEffect } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const HueSaturation = /* @__PURE__ */ wrapEffect(HueSaturationEffect)
1
+ import { HueSaturationEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../util'
3
+
4
+ export const HueSaturation = /* @__PURE__ */ wrapEffect(HueSaturationEffect)
@@ -1,26 +1,26 @@
1
- import { useThree } from '@react-three/fiber'
2
- import { LUT3DEffect, BlendFunction } from 'postprocessing'
3
- import React, { forwardRef, Ref, useLayoutEffect, useMemo } from 'react'
4
- import type { Texture } from 'three'
5
-
6
- export type LUTProps = {
7
- lut: Texture
8
- blendFunction?: BlendFunction
9
- tetrahedralInterpolation?: boolean
10
- }
11
-
12
- export const LUT = /* @__PURE__ */ forwardRef(function LUT(
13
- { lut, tetrahedralInterpolation, ...props }: LUTProps,
14
- ref: Ref<LUT3DEffect>
15
- ) {
16
- const effect = useMemo(() => new LUT3DEffect(lut, props), [lut, props])
17
- const invalidate = useThree((state) => state.invalidate)
18
-
19
- useLayoutEffect(() => {
20
- if (tetrahedralInterpolation) effect.tetrahedralInterpolation = tetrahedralInterpolation
21
- if (lut) effect.lut = lut
22
- invalidate()
23
- }, [effect, invalidate, lut, tetrahedralInterpolation])
24
-
25
- return <primitive ref={ref} object={effect} dispose={null} />
26
- })
1
+ import { useThree } from '@react-three/fiber'
2
+ import { LUT3DEffect, BlendFunction } from 'postprocessing'
3
+ import React, { forwardRef, Ref, useLayoutEffect, useMemo } from 'react'
4
+ import type { Texture } from 'three'
5
+
6
+ export type LUTProps = {
7
+ lut: Texture
8
+ blendFunction?: BlendFunction
9
+ tetrahedralInterpolation?: boolean
10
+ }
11
+
12
+ export const LUT = /* @__PURE__ */ forwardRef(function LUT(
13
+ { lut, tetrahedralInterpolation, ...props }: LUTProps,
14
+ ref: Ref<LUT3DEffect>
15
+ ) {
16
+ const effect = useMemo(() => new LUT3DEffect(lut, props), [lut, props])
17
+ const invalidate = useThree((state) => state.invalidate)
18
+
19
+ useLayoutEffect(() => {
20
+ if (tetrahedralInterpolation) effect.tetrahedralInterpolation = tetrahedralInterpolation
21
+ if (lut) effect.lut = lut
22
+ invalidate()
23
+ }, [effect, invalidate, lut, tetrahedralInterpolation])
24
+
25
+ return <primitive ref={ref} object={effect} dispose={null} />
26
+ })