@react-three/postprocessing 3.0.4 → 3.0.5

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 (93) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +81 -81
  3. package/dist/EffectComposer.d.ts +7 -6
  4. package/dist/Selection.d.ts +8 -8
  5. package/dist/effects/ASCII.d.ts +5 -4
  6. package/dist/effects/Autofocus.d.ts +8 -7
  7. package/dist/effects/Bloom.d.ts +2 -5
  8. package/dist/effects/BrightnessContrast.d.ts +2 -5
  9. package/dist/effects/ChromaticAberration.d.ts +7 -7
  10. package/dist/effects/ColorAverage.d.ts +7 -8
  11. package/dist/effects/ColorDepth.d.ts +2 -5
  12. package/dist/effects/Depth.d.ts +2 -5
  13. package/dist/effects/DepthOfField.d.ts +7 -18
  14. package/dist/effects/DotScreen.d.ts +2 -5
  15. package/dist/effects/FXAA.d.ts +2 -5
  16. package/dist/effects/Glitch.d.ts +4 -21
  17. package/dist/effects/GodRays.d.ts +7 -19
  18. package/dist/effects/Grid.d.ts +6 -7
  19. package/dist/effects/HueSaturation.d.ts +2 -5
  20. package/dist/effects/LUT.d.ts +4 -3
  21. package/dist/effects/LensFlare.d.ts +8 -8
  22. package/dist/effects/N8AO.d.ts +4 -2
  23. package/dist/effects/Noise.d.ts +2 -5
  24. package/dist/effects/Outline.d.ts +4 -23
  25. package/dist/effects/Pixelation.d.ts +3 -2
  26. package/dist/effects/Ramp.d.ts +1 -5
  27. package/dist/effects/SMAA.d.ts +2 -5
  28. package/dist/effects/SSAO.d.ts +7 -30
  29. package/dist/effects/ScanlineEffect.d.ts +2 -5
  30. package/dist/effects/SelectiveBloom.d.ts +5 -10
  31. package/dist/effects/Sepia.d.ts +2 -5
  32. package/dist/effects/ShockWave.d.ts +2 -5
  33. package/dist/effects/Texture.d.ts +7 -8
  34. package/dist/effects/TiltShift.d.ts +2 -5
  35. package/dist/effects/TiltShift2.d.ts +1 -5
  36. package/dist/effects/ToneMapping.d.ts +2 -6
  37. package/dist/effects/Vignette.d.ts +2 -5
  38. package/dist/effects/Water.d.ts +1 -5
  39. package/dist/index.d.ts +11 -10
  40. package/dist/index.js +855 -551
  41. package/dist/index.js.map +1 -1
  42. package/dist/tests/test-utils.d.ts +12 -0
  43. package/dist/util.d.ts +25 -17
  44. package/dist/wrapEffect.d.ts +12 -0
  45. package/package.json +73 -67
  46. package/src/EffectComposer.tsx +278 -200
  47. package/src/Selection.tsx +86 -46
  48. package/src/effects/ASCII.tsx +136 -135
  49. package/src/effects/Autofocus.tsx +175 -153
  50. package/src/effects/Bloom.tsx +6 -6
  51. package/src/effects/BrightnessContrast.tsx +4 -4
  52. package/src/effects/ChromaticAberration.tsx +30 -5
  53. package/src/effects/ColorAverage.tsx +17 -15
  54. package/src/effects/ColorDepth.tsx +4 -4
  55. package/src/effects/Depth.tsx +4 -4
  56. package/src/effects/DepthOfField.tsx +87 -89
  57. package/src/effects/DotScreen.tsx +4 -4
  58. package/src/effects/FXAA.tsx +4 -4
  59. package/src/effects/Glitch.tsx +37 -40
  60. package/src/effects/GodRays.tsx +20 -16
  61. package/src/effects/Grid.tsx +28 -21
  62. package/src/effects/HueSaturation.tsx +4 -4
  63. package/src/effects/LUT.tsx +27 -26
  64. package/src/effects/LensFlare.tsx +611 -611
  65. package/src/effects/N8AO.tsx +81 -81
  66. package/src/effects/Noise.tsx +4 -4
  67. package/src/effects/Outline.tsx +85 -117
  68. package/src/effects/Pixelation.tsx +17 -15
  69. package/src/effects/Ramp.tsx +150 -150
  70. package/src/effects/SMAA.tsx +4 -4
  71. package/src/effects/SSAO.tsx +44 -41
  72. package/src/effects/ScanlineEffect.tsx +7 -7
  73. package/src/effects/SelectiveBloom.tsx +116 -126
  74. package/src/effects/Sepia.tsx +4 -4
  75. package/src/effects/ShockWave.tsx +4 -4
  76. package/src/effects/Texture.tsx +27 -23
  77. package/src/effects/TiltShift.tsx +4 -4
  78. package/src/effects/TiltShift2.tsx +90 -90
  79. package/src/effects/ToneMapping.tsx +6 -6
  80. package/src/effects/Vignette.tsx +4 -4
  81. package/src/effects/Water.tsx +35 -35
  82. package/src/index.ts +41 -40
  83. package/src/tests/ChromaticAberration.test.tsx +31 -0
  84. package/src/tests/EffectComposer.test.tsx +911 -0
  85. package/src/tests/Outline.test.tsx +89 -0
  86. package/src/tests/Selection.test.tsx +324 -0
  87. package/src/tests/SelectiveBloom.test.tsx +118 -0
  88. package/src/tests/effects.smoke.test.tsx +234 -0
  89. package/src/tests/test-utils.tsx +96 -0
  90. package/src/tests/wrapEffect.test.tsx +209 -0
  91. package/src/util.tsx +96 -55
  92. package/src/wrapEffect.tsx +122 -0
  93. package/src/EffectComposer.test.tsx +0 -126
@@ -1,81 +1,81 @@
1
- // From https://github.com/N8python/n8ao
2
- // https://twitter.com/N8Programs/status/1660996748485984261
3
-
4
- import { Ref, forwardRef, useLayoutEffect, useMemo } from 'react'
5
- /* @ts-ignore */
6
- import { N8AOPostPass } from 'n8ao'
7
- import { useThree, ReactThreeFiber, applyProps } from '@react-three/fiber'
8
-
9
- export type N8AOProps = {
10
- aoRadius?: number
11
- distanceFalloff?: number
12
- intensity?: number
13
- quality?: 'performance' | 'low' | 'medium' | 'high' | 'ultra'
14
- aoSamples?: number
15
- denoiseSamples?: number
16
- denoiseRadius?: number
17
- color?: ReactThreeFiber.Color
18
- halfRes?: boolean
19
- depthAwareUpsampling?: boolean
20
- screenSpaceRadius?: boolean
21
- renderMode?: 0 | 1 | 2 | 3 | 4
22
- }
23
-
24
- export const N8AO = /* @__PURE__ */ forwardRef<N8AOPostPass, N8AOProps>(
25
- (
26
- {
27
- halfRes,
28
- screenSpaceRadius,
29
- quality,
30
- depthAwareUpsampling = true,
31
- aoRadius = 5,
32
- aoSamples = 16,
33
- denoiseSamples = 4,
34
- denoiseRadius = 12,
35
- distanceFalloff = 1,
36
- intensity = 1,
37
- color,
38
- renderMode = 0,
39
- },
40
- ref: Ref<N8AOPostPass>
41
- ) => {
42
- const { camera, scene } = useThree()
43
- const effect = useMemo(() => new N8AOPostPass(scene, camera), [camera, scene])
44
-
45
- // TODO: implement dispose upstream; this effect has memory leaks without
46
- useLayoutEffect(() => {
47
- applyProps(effect.configuration, {
48
- color,
49
- aoRadius,
50
- distanceFalloff,
51
- intensity,
52
- aoSamples,
53
- denoiseSamples,
54
- denoiseRadius,
55
- screenSpaceRadius,
56
- renderMode,
57
- halfRes,
58
- depthAwareUpsampling,
59
- })
60
- }, [
61
- screenSpaceRadius,
62
- color,
63
- aoRadius,
64
- distanceFalloff,
65
- intensity,
66
- aoSamples,
67
- denoiseSamples,
68
- denoiseRadius,
69
- renderMode,
70
- halfRes,
71
- depthAwareUpsampling,
72
- effect,
73
- ])
74
-
75
- useLayoutEffect(() => {
76
- if (quality) effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1))
77
- }, [effect, quality])
78
-
79
- return <primitive ref={ref} object={effect} />
80
- }
81
- )
1
+ // From https://github.com/N8python/n8ao
2
+ // https://twitter.com/N8Programs/status/1660996748485984261
3
+
4
+ import { ReactThreeFiber, applyProps, useThree } from '@react-three/fiber'
5
+ import { Ref, useLayoutEffect, useMemo } from 'react'
6
+ /* @ts-ignore */
7
+ import { N8AOPostPass } from 'n8ao'
8
+ import { useDispose } from '../util'
9
+
10
+ export type N8AOProps = {
11
+ aoRadius?: number
12
+ distanceFalloff?: number
13
+ intensity?: number
14
+ quality?: 'performance' | 'low' | 'medium' | 'high' | 'ultra'
15
+ aoSamples?: number
16
+ denoiseSamples?: number
17
+ denoiseRadius?: number
18
+ color?: ReactThreeFiber.Color
19
+ halfRes?: boolean
20
+ depthAwareUpsampling?: boolean
21
+ screenSpaceRadius?: boolean
22
+ renderMode?: 0 | 1 | 2 | 3 | 4
23
+ ref?: Ref<N8AOPostPass>
24
+ }
25
+
26
+ export function N8AO({
27
+ halfRes,
28
+ screenSpaceRadius,
29
+ quality,
30
+ depthAwareUpsampling = true,
31
+ aoRadius = 5,
32
+ aoSamples = 16,
33
+ denoiseSamples = 4,
34
+ denoiseRadius = 12,
35
+ distanceFalloff = 1,
36
+ intensity = 1,
37
+ color,
38
+ renderMode = 0,
39
+ ref,
40
+ }: N8AOProps) {
41
+ const { camera, scene } = useThree()
42
+ const effect = useMemo(() => new N8AOPostPass(scene, camera), [camera, scene])
43
+
44
+ // TODO: implement dispose upstream; this effect has memory leaks without
45
+ useDispose(effect)
46
+
47
+ useLayoutEffect(() => {
48
+ applyProps(effect.configuration, {
49
+ color,
50
+ aoRadius,
51
+ distanceFalloff,
52
+ intensity,
53
+ aoSamples,
54
+ denoiseSamples,
55
+ denoiseRadius,
56
+ screenSpaceRadius,
57
+ renderMode,
58
+ halfRes,
59
+ depthAwareUpsampling,
60
+ })
61
+ }, [
62
+ screenSpaceRadius,
63
+ color,
64
+ aoRadius,
65
+ distanceFalloff,
66
+ intensity,
67
+ aoSamples,
68
+ denoiseSamples,
69
+ denoiseRadius,
70
+ renderMode,
71
+ halfRes,
72
+ depthAwareUpsampling,
73
+ effect,
74
+ ])
75
+
76
+ useLayoutEffect(() => {
77
+ if (quality) effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1))
78
+ }, [effect, quality])
79
+
80
+ return <primitive ref={ref} object={effect} />
81
+ }
@@ -1,4 +1,4 @@
1
- import { NoiseEffect, BlendFunction } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const Noise = /* @__PURE__ */ wrapEffect(NoiseEffect, { blendFunction: BlendFunction.COLOR_DODGE })
1
+ import { BlendFunction, NoiseEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../wrapEffect'
3
+
4
+ export const Noise = /* @__PURE__ */ wrapEffect(NoiseEffect, { blendFunction: BlendFunction.COLOR_DODGE })
@@ -1,117 +1,85 @@
1
- import { OutlineEffect } from 'postprocessing'
2
- import { Ref, RefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'
3
- import { Object3D } from 'three'
4
- import { useThree } from '@react-three/fiber'
5
- import { EffectComposerContext } from '../EffectComposer'
6
- import { selectionContext } from '../Selection'
7
- import { resolveRef } from '../util'
8
-
9
- type ObjectRef = RefObject<Object3D>
10
-
11
- export type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] &
12
- Partial<{
13
- selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
14
- selectionLayer: number
15
- }>
16
-
17
- export const Outline = /* @__PURE__ */ forwardRef(function Outline(
18
- {
19
- selection = [],
20
- selectionLayer = 10,
21
- blendFunction,
22
- patternTexture,
23
- edgeStrength,
24
- pulseSpeed,
25
- visibleEdgeColor,
26
- hiddenEdgeColor,
27
- width,
28
- height,
29
- kernelSize,
30
- blur,
31
- xRay,
32
- ...props
33
- }: OutlineProps,
34
- forwardRef: Ref<OutlineEffect>
35
- ) {
36
- const invalidate = useThree((state) => state.invalidate)
37
- const { scene, camera } = useContext(EffectComposerContext)
38
-
39
- const effect = useMemo(
40
- () =>
41
- new OutlineEffect(scene, camera, {
42
- blendFunction,
43
- patternTexture,
44
- edgeStrength,
45
- pulseSpeed,
46
- visibleEdgeColor,
47
- hiddenEdgeColor,
48
- width,
49
- height,
50
- kernelSize,
51
- blur,
52
- xRay,
53
- ...props,
54
- }),
55
- // NOTE: `props` is an unstable reference, so we can't memoize it
56
- // eslint-disable-next-line react-hooks/exhaustive-deps
57
- [
58
- blendFunction,
59
- blur,
60
- camera,
61
- edgeStrength,
62
- height,
63
- hiddenEdgeColor,
64
- kernelSize,
65
- patternTexture,
66
- pulseSpeed,
67
- scene,
68
- visibleEdgeColor,
69
- width,
70
- xRay,
71
- ]
72
- )
73
-
74
- const api = useContext(selectionContext)
75
-
76
- useEffect(() => {
77
- // Do not allow array selection if declarative selection is active
78
- // TODO: array selection should probably be deprecated altogether
79
- if (!api && selection) {
80
- effect.selection.set(
81
- Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]
82
- )
83
- invalidate()
84
- return () => {
85
- effect.selection.clear()
86
- invalidate()
87
- }
88
- }
89
- }, [effect, selection, api, invalidate])
90
-
91
- useEffect(() => {
92
- effect.selectionLayer = selectionLayer
93
- invalidate()
94
- }, [effect, invalidate, selectionLayer])
95
-
96
- const ref = useRef<OutlineEffect>(undefined)
97
- useEffect(() => {
98
- if (api && api.enabled) {
99
- if (api.selected?.length) {
100
- effect.selection.set(api.selected)
101
- invalidate()
102
- return () => {
103
- effect.selection.clear()
104
- invalidate()
105
- }
106
- }
107
- }
108
- }, [api, effect.selection, invalidate])
109
-
110
- useEffect(() => {
111
- return () => {
112
- effect.dispose()
113
- }
114
- }, [effect])
115
-
116
- return <primitive ref={forwardRef} object={effect} />
117
- })
1
+ import { OutlineEffect } from 'postprocessing'
2
+ import { Ref, RefObject, use, useMemo } from 'react'
3
+ import { Object3D } from 'three'
4
+ import { EffectComposerContext } from '../EffectComposer'
5
+ import { EMPTY_ARRAY, useDispose, useSelectionSync } from '../util'
6
+
7
+ type ObjectRef = RefObject<Object3D | null>
8
+
9
+ export type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] &
10
+ Partial<{
11
+ selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
12
+ selectionLayer: number
13
+ ref?: Ref<OutlineEffect>
14
+ }>
15
+
16
+ export function Outline({
17
+ selection = EMPTY_ARRAY,
18
+ selectionLayer = 10,
19
+ blendFunction,
20
+ patternTexture,
21
+ patternScale,
22
+ edgeStrength,
23
+ pulseSpeed,
24
+ visibleEdgeColor,
25
+ hiddenEdgeColor,
26
+ multisampling,
27
+ resolutionScale,
28
+ resolutionX,
29
+ resolutionY,
30
+ width,
31
+ height,
32
+ kernelSize,
33
+ blur,
34
+ xRay,
35
+ ref,
36
+ }: OutlineProps) {
37
+ const { scene, camera } = use(EffectComposerContext)
38
+
39
+ const effect = useMemo(
40
+ () =>
41
+ new OutlineEffect(scene, camera, {
42
+ blendFunction,
43
+ patternTexture,
44
+ patternScale,
45
+ edgeStrength,
46
+ pulseSpeed,
47
+ visibleEdgeColor,
48
+ hiddenEdgeColor,
49
+ multisampling,
50
+ resolutionScale,
51
+ resolutionX,
52
+ resolutionY,
53
+ width,
54
+ height,
55
+ kernelSize,
56
+ blur,
57
+ xRay,
58
+ }),
59
+ [
60
+ blendFunction,
61
+ patternTexture,
62
+ patternScale,
63
+ edgeStrength,
64
+ pulseSpeed,
65
+ visibleEdgeColor,
66
+ hiddenEdgeColor,
67
+ multisampling,
68
+ resolutionScale,
69
+ resolutionX,
70
+ resolutionY,
71
+ width,
72
+ height,
73
+ kernelSize,
74
+ blur,
75
+ xRay,
76
+ camera,
77
+ scene,
78
+ ]
79
+ )
80
+
81
+ useSelectionSync(effect, selection, selectionLayer)
82
+ useDispose(effect)
83
+
84
+ return <primitive ref={ref} object={effect} />
85
+ }
@@ -1,15 +1,17 @@
1
- import { forwardRef, useMemo, Ref } from 'react'
2
- import { PixelationEffect } from 'postprocessing'
3
-
4
- export type PixelationProps = {
5
- granularity?: number
6
- }
7
-
8
- export const Pixelation = /* @__PURE__ */ forwardRef<PixelationEffect, PixelationProps>(function Pixelation(
9
- { granularity = 5 }: PixelationProps,
10
- ref: Ref<PixelationEffect>
11
- ) {
12
- /** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
13
- const effect = useMemo(() => new PixelationEffect(granularity), [granularity])
14
- return <primitive ref={ref} object={effect} dispose={null} />
15
- })
1
+ import { PixelationEffect } from 'postprocessing'
2
+ import { Ref, useMemo } from 'react'
3
+ import { useDispose } from '../util'
4
+
5
+ export type PixelationProps = {
6
+ granularity?: number
7
+ ref?: Ref<PixelationEffect>
8
+ }
9
+
10
+ export function Pixelation({ granularity = 5, ref }: PixelationProps) {
11
+ /** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
12
+ const effect = useMemo(() => new PixelationEffect(granularity), [granularity])
13
+
14
+ useDispose(effect)
15
+
16
+ return <primitive ref={ref} object={effect} />
17
+ }