@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,5 +1,30 @@
1
- import { ChromaticAberrationEffect } from 'postprocessing'
2
- import { type EffectProps, wrapEffect } from '../util'
3
-
4
- export type ChromaticAberrationProps = EffectProps<typeof ChromaticAberrationEffect>
5
- export const ChromaticAberration = /* @__PURE__ */ wrapEffect(ChromaticAberrationEffect)
1
+ import type { ReactThreeFiber } from '@react-three/fiber'
2
+ import { ChromaticAberrationEffect } from 'postprocessing'
3
+ import type { Ref } from 'react'
4
+ import { useMemo } from 'react'
5
+ import { useDispose, useVector2 } from '../util'
6
+
7
+ export type ChromaticAberrationProps = Omit<
8
+ Partial<ConstructorParameters<typeof ChromaticAberrationEffect>[0]>,
9
+ 'offset'
10
+ > & {
11
+ ref?: Ref<ChromaticAberrationEffect>
12
+ offset?: ReactThreeFiber.Vector2
13
+ }
14
+
15
+ export function ChromaticAberration({ ref, ...props }: ChromaticAberrationProps) {
16
+ const offset = useVector2(props, 'offset')
17
+
18
+ const effect = useMemo(
19
+ () =>
20
+ new ChromaticAberrationEffect({
21
+ ...props,
22
+ offset,
23
+ } as ConstructorParameters<typeof ChromaticAberrationEffect>[0]),
24
+ [offset, props]
25
+ )
26
+
27
+ useDispose(effect)
28
+
29
+ return <primitive object={effect} ref={ref} />
30
+ }
@@ -1,15 +1,17 @@
1
- import { ColorAverageEffect, BlendFunction } from 'postprocessing'
2
- import React, { Ref, forwardRef, useMemo } from 'react'
3
-
4
- export type ColorAverageProps = Partial<{
5
- blendFunction: BlendFunction
6
- }>
7
-
8
- export const ColorAverage = /* @__PURE__ */ forwardRef<ColorAverageEffect, ColorAverageProps>(function ColorAverage(
9
- { blendFunction = BlendFunction.NORMAL }: ColorAverageProps,
10
- ref: Ref<ColorAverageEffect>
11
- ) {
12
- /** Because ColorAverage blendFunction is not an object but a number, we have to define a custom prop "blendFunction" */
13
- const effect = useMemo(() => new ColorAverageEffect(blendFunction), [blendFunction])
14
- return <primitive ref={ref} object={effect} dispose={null} />
15
- })
1
+ import { BlendFunction, ColorAverageEffect } from 'postprocessing'
2
+ import type { Ref } from 'react'
3
+ import { useMemo } from 'react'
4
+ import { useDispose } from '../util'
5
+
6
+ export type ColorAverageProps = {
7
+ blendFunction?: BlendFunction
8
+ ref?: Ref<ColorAverageEffect>
9
+ }
10
+
11
+ export function ColorAverage({ blendFunction = BlendFunction.NORMAL, ref }: ColorAverageProps) {
12
+ const effect = useMemo(() => new ColorAverageEffect(blendFunction), [blendFunction])
13
+
14
+ useDispose(effect)
15
+
16
+ return <primitive object={effect} ref={ref} />
17
+ }
@@ -1,4 +1,4 @@
1
- import { ColorDepthEffect } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const ColorDepth = /* @__PURE__ */ wrapEffect(ColorDepthEffect)
1
+ import { ColorDepthEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../wrapEffect'
3
+
4
+ export const ColorDepth = /* @__PURE__ */ wrapEffect(ColorDepthEffect)
@@ -1,4 +1,4 @@
1
- import { DepthEffect } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const Depth = /* @__PURE__ */ wrapEffect(DepthEffect)
1
+ import { DepthEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../wrapEffect'
3
+
4
+ export const Depth = /* @__PURE__ */ wrapEffect(DepthEffect)
@@ -1,89 +1,87 @@
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 type { ReactThreeFiber } from '@react-three/fiber'
2
+ import { DepthOfFieldEffect, MaskFunction } from 'postprocessing'
3
+ import type { Ref } from 'react'
4
+ import { use, useMemo } from 'react'
5
+ import { type DepthPackingStrategies, type Texture, Vector3 } from 'three'
6
+ import { EffectComposerContext } from '../EffectComposer'
7
+ import { useDispose } from '../util'
8
+
9
+ export type DepthOfFieldProps = ConstructorParameters<typeof DepthOfFieldEffect>[1] &
10
+ Partial<{
11
+ ref: Ref<DepthOfFieldEffect>
12
+ target: ReactThreeFiber.Vector3
13
+ depthTexture: {
14
+ texture: Texture
15
+ // TODO: narrow to DepthPackingStrategies
16
+ packing: number
17
+ }
18
+ // TODO: not used
19
+ blur: number
20
+ }>
21
+
22
+ export function DepthOfField({
23
+ ref,
24
+ blendFunction,
25
+ worldFocusDistance,
26
+ worldFocusRange,
27
+ focusDistance,
28
+ focusRange,
29
+ focalLength,
30
+ bokehScale,
31
+ resolutionScale,
32
+ resolutionX,
33
+ resolutionY,
34
+ width,
35
+ height,
36
+ target,
37
+ depthTexture,
38
+ ...props
39
+ }: DepthOfFieldProps) {
40
+ const { camera } = use(EffectComposerContext)
41
+ const autoFocus = target != null
42
+
43
+ const effect = useMemo(() => {
44
+ const effect = new DepthOfFieldEffect(camera, {
45
+ blendFunction,
46
+ worldFocusDistance,
47
+ worldFocusRange,
48
+ focusDistance,
49
+ focusRange,
50
+ focalLength,
51
+ bokehScale,
52
+ resolutionScale,
53
+ resolutionX,
54
+ resolutionY,
55
+ width,
56
+ height,
57
+ })
58
+ // Creating a target enables autofocus, R3F will set via props
59
+ if (autoFocus) effect.target = new Vector3()
60
+ // Depth texture for depth picking with optional packing strategy
61
+ if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing as DepthPackingStrategies)
62
+ // Temporary fix that restores DOF 6.21.3 behavior, everything since then lets shapes leak through the blur
63
+ const maskPass = (effect as any).maskPass
64
+ maskPass.maskFunction = MaskFunction.MULTIPLY_RGB_SET_ALPHA
65
+ return effect
66
+ }, [
67
+ camera,
68
+ blendFunction,
69
+ worldFocusDistance,
70
+ worldFocusRange,
71
+ focusDistance,
72
+ focusRange,
73
+ focalLength,
74
+ bokehScale,
75
+ resolutionScale,
76
+ resolutionX,
77
+ resolutionY,
78
+ width,
79
+ height,
80
+ autoFocus,
81
+ depthTexture,
82
+ ])
83
+
84
+ useDispose(effect)
85
+
86
+ return <primitive {...props} object={effect} ref={ref} target={target} />
87
+ }
@@ -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 '../wrapEffect'
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 '../wrapEffect'
3
+
4
+ export const FXAA = /* @__PURE__ */ wrapEffect(FXAAEffect)
@@ -1,40 +1,37 @@
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 { ReactThreeFiber, useThree } from '@react-three/fiber'
2
+ import { GlitchEffect, GlitchMode } from 'postprocessing'
3
+ import { Ref, useLayoutEffect, useMemo } from 'react'
4
+ import { useDispose, useVector2 } from '../util'
5
+
6
+ export type GlitchProps = ConstructorParameters<typeof GlitchEffect>[0] &
7
+ Partial<{
8
+ mode: GlitchMode
9
+ active: boolean
10
+ delay: ReactThreeFiber.Vector2
11
+ duration: ReactThreeFiber.Vector2
12
+ chromaticAberrationOffset: ReactThreeFiber.Vector2
13
+ strength: ReactThreeFiber.Vector2
14
+ ref?: Ref<GlitchEffect>
15
+ }>
16
+
17
+ export function Glitch({ active = true, ref, ...props }: GlitchProps) {
18
+ const invalidate = useThree((state) => state.invalidate)
19
+ const delay = useVector2(props, 'delay')
20
+ const duration = useVector2(props, 'duration')
21
+ const strength = useVector2(props, 'strength')
22
+ const chromaticAberrationOffset = useVector2(props, 'chromaticAberrationOffset')
23
+
24
+ const effect = useMemo(
25
+ () => new GlitchEffect({ ...props, delay, duration, strength, chromaticAberrationOffset }),
26
+ [delay, duration, props, strength, chromaticAberrationOffset]
27
+ )
28
+
29
+ useLayoutEffect(() => {
30
+ effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED
31
+ invalidate()
32
+ }, [active, effect, invalidate, props.mode])
33
+
34
+ useDispose(effect)
35
+
36
+ return <primitive ref={ref} object={effect} />
37
+ }
@@ -1,16 +1,20 @@
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 { Ref, RefObject, useContext, useLayoutEffect, useMemo } from 'react'
3
+ import { Mesh, Points } from 'three'
4
+ import { EffectComposerContext } from '../EffectComposer'
5
+ import { resolveRef, useDispose } from '../util'
6
+
7
+ type GodRaysProps = ConstructorParameters<typeof GodRaysEffect>[2] & {
8
+ sun: Mesh | Points | RefObject<Mesh | Points>
9
+ ref?: Ref<GodRaysEffect>
10
+ }
11
+
12
+ export function GodRays({ ref, ...props }: GodRaysProps) {
13
+ const { camera } = useContext(EffectComposerContext)
14
+ const effect = useMemo(() => new GodRaysEffect(camera, resolveRef(props.sun), props), [camera, props])
15
+ useLayoutEffect(() => void (effect.lightSource = resolveRef(props.sun)), [effect, props.sun])
16
+
17
+ useDispose(effect)
18
+
19
+ return <primitive ref={ref} object={effect} />
20
+ }
@@ -1,21 +1,28 @@
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 { useThree } from '@react-three/fiber'
2
+ import { GridEffect } from 'postprocessing'
3
+ import { Ref, useLayoutEffect, useMemo } from 'react'
4
+ import { useDispose } from '../util'
5
+
6
+ type GridProps = ConstructorParameters<typeof GridEffect>[0] &
7
+ Partial<{
8
+ size: {
9
+ width: number
10
+ height: number
11
+ }
12
+ ref: Ref<GridEffect>
13
+ }>
14
+
15
+ export function Grid({ size, ref, ...props }: GridProps) {
16
+ const invalidate = useThree((state) => state.invalidate)
17
+
18
+ const effect = useMemo(() => new GridEffect(props), [props])
19
+
20
+ useLayoutEffect(() => {
21
+ if (size) effect.setSize(size.width, size.height)
22
+ invalidate()
23
+ }, [effect, size, invalidate])
24
+
25
+ useDispose(effect)
26
+
27
+ return <primitive ref={ref} object={effect} />
28
+ }
@@ -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 '../wrapEffect'
3
+
4
+ export const HueSaturation = /* @__PURE__ */ wrapEffect(HueSaturationEffect)
@@ -1,26 +1,27 @@
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 { BlendFunction, LUT3DEffect } from 'postprocessing'
3
+ import { Ref, useLayoutEffect, useMemo } from 'react'
4
+ import type { Texture } from 'three'
5
+ import { useDispose } from '../util'
6
+
7
+ export type LUTProps = {
8
+ lut: Texture
9
+ blendFunction?: BlendFunction
10
+ tetrahedralInterpolation?: boolean
11
+ ref?: Ref<LUT3DEffect>
12
+ }
13
+
14
+ export function LUT({ lut, tetrahedralInterpolation, ref, ...props }: LUTProps) {
15
+ const effect = useMemo(() => new LUT3DEffect(lut, props), [lut, props])
16
+ const invalidate = useThree((state) => state.invalidate)
17
+
18
+ useLayoutEffect(() => {
19
+ if (tetrahedralInterpolation) effect.tetrahedralInterpolation = tetrahedralInterpolation
20
+ if (lut) effect.lut = lut
21
+ invalidate()
22
+ }, [effect, invalidate, lut, tetrahedralInterpolation])
23
+
24
+ useDispose(effect)
25
+
26
+ return <primitive ref={ref} object={effect} />
27
+ }