@react-three/postprocessing 3.0.4 → 3.1.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.
Files changed (114) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +80 -81
  3. package/dist/EffectComposer.d.ts +14 -6
  4. package/dist/EffectGroup.d.ts +9 -0
  5. package/dist/Selection.d.ts +8 -8
  6. package/dist/createEffectComponent.d.ts +30 -0
  7. package/dist/effects/ASCII.d.ts +29 -7
  8. package/dist/effects/Autofocus.d.ts +8 -7
  9. package/dist/effects/Bloom.d.ts +10 -5
  10. package/dist/effects/BrightnessContrast.d.ts +15 -5
  11. package/dist/effects/ChromaticAberration.d.ts +30 -7
  12. package/dist/effects/ColorAverage.d.ts +7 -8
  13. package/dist/effects/ColorDepth.d.ts +8 -5
  14. package/dist/effects/Depth.d.ts +13 -5
  15. package/dist/effects/DepthOfField.d.ts +7 -18
  16. package/dist/effects/DotScreen.d.ts +15 -5
  17. package/dist/effects/FXAA.d.ts +11 -5
  18. package/dist/effects/Glitch.d.ts +17 -29
  19. package/dist/effects/GodRays.d.ts +7 -19
  20. package/dist/effects/Grid.d.ts +8 -8
  21. package/dist/effects/HueSaturation.d.ts +15 -5
  22. package/dist/effects/LUT.d.ts +4 -3
  23. package/dist/effects/LensFlare.d.ts +52 -11
  24. package/dist/effects/Noise.d.ts +8 -5
  25. package/dist/effects/Outline.d.ts +9 -25
  26. package/dist/effects/Pixelation.d.ts +3 -2
  27. package/dist/effects/Ramp.d.ts +58 -10
  28. package/dist/effects/SMAA.d.ts +10 -5
  29. package/dist/effects/SSAO.d.ts +7 -30
  30. package/dist/effects/ScanlineEffect.d.ts +13 -5
  31. package/dist/effects/SelectiveBloom.d.ts +5 -10
  32. package/dist/effects/Sepia.d.ts +13 -5
  33. package/dist/effects/ShockWave.d.ts +12 -5
  34. package/dist/effects/Texture.d.ts +7 -8
  35. package/dist/effects/TiltShift.d.ts +10 -5
  36. package/dist/effects/TiltShift2.d.ts +44 -8
  37. package/dist/effects/ToneMapping.d.ts +9 -7
  38. package/dist/effects/Vignette.d.ts +19 -5
  39. package/dist/effects/Water.d.ts +17 -5
  40. package/dist/index.d.ts +15 -11
  41. package/dist/index.js +1841 -45
  42. package/dist/index.js.map +1 -1
  43. package/dist/passes/DepthPicking.d.ts +11 -0
  44. package/dist/{effects → passes}/N8AO.d.ts +5 -2
  45. package/dist/util.d.ts +19 -17
  46. package/dist/wrapEffect.d.ts +12 -0
  47. package/package.json +74 -67
  48. package/src/EffectComposer.tsx +379 -200
  49. package/src/EffectGroup.tsx +74 -0
  50. package/src/Selection.tsx +86 -46
  51. package/src/createEffectComponent.tsx +71 -0
  52. package/src/effects/ASCII.tsx +183 -135
  53. package/src/effects/Autofocus.tsx +122 -153
  54. package/src/effects/Bloom.tsx +34 -6
  55. package/src/effects/BrightnessContrast.tsx +7 -4
  56. package/src/effects/ChromaticAberration.tsx +22 -5
  57. package/src/effects/ColorAverage.tsx +4 -15
  58. package/src/effects/ColorDepth.tsx +25 -4
  59. package/src/effects/Depth.tsx +6 -4
  60. package/src/effects/DepthOfField.tsx +109 -89
  61. package/src/effects/DotScreen.tsx +7 -4
  62. package/src/effects/FXAA.tsx +6 -4
  63. package/src/effects/Glitch.tsx +32 -40
  64. package/src/effects/GodRays.tsx +104 -16
  65. package/src/effects/Grid.tsx +27 -21
  66. package/src/effects/HueSaturation.tsx +7 -4
  67. package/src/effects/LUT.tsx +25 -26
  68. package/src/effects/LensFlare.tsx +765 -611
  69. package/src/effects/Noise.tsx +16 -4
  70. package/src/effects/Outline.tsx +84 -117
  71. package/src/effects/Pixelation.tsx +20 -15
  72. package/src/effects/Ramp.tsx +239 -150
  73. package/src/effects/SMAA.tsx +20 -4
  74. package/src/effects/SSAO.tsx +152 -41
  75. package/src/effects/ScanlineEffect.tsx +7 -7
  76. package/src/effects/SelectiveBloom.tsx +98 -126
  77. package/src/effects/Sepia.tsx +6 -4
  78. package/src/effects/ShockWave.tsx +32 -4
  79. package/src/effects/Texture.tsx +28 -23
  80. package/src/effects/TiltShift.tsx +32 -4
  81. package/src/effects/TiltShift2.tsx +156 -90
  82. package/src/effects/ToneMapping.tsx +19 -6
  83. package/src/effects/Vignette.tsx +7 -4
  84. package/src/effects/Water.tsx +50 -35
  85. package/src/index.ts +43 -40
  86. package/src/passes/DepthPicking.tsx +63 -0
  87. package/src/passes/N8AO.tsx +105 -0
  88. package/src/tests/Autofocus.test.tsx +38 -0
  89. package/src/tests/Bloom.test.tsx +76 -0
  90. package/src/tests/ChromaticAberration.test.tsx +81 -0
  91. package/src/tests/ColorDepth.test.tsx +71 -0
  92. package/src/tests/DepthOfField.test.tsx +130 -0
  93. package/src/tests/DepthPicking.test.tsx +250 -0
  94. package/src/tests/EffectComposer.test.tsx +1404 -0
  95. package/src/tests/EffectGroup.test.tsx +337 -0
  96. package/src/tests/Glitch.test.tsx +56 -0
  97. package/src/tests/GodRays.test.tsx +101 -0
  98. package/src/tests/Grid.test.tsx +34 -0
  99. package/src/tests/LUT.test.tsx +64 -0
  100. package/src/tests/N8AO.test.tsx +92 -0
  101. package/src/tests/Outline.test.tsx +211 -0
  102. package/src/tests/SSAO.test.tsx +140 -0
  103. package/src/tests/Selection.test.tsx +324 -0
  104. package/src/tests/SelectiveBloom.test.tsx +166 -0
  105. package/src/tests/ShockWave.test.tsx +95 -0
  106. package/src/tests/TiltShift.test.tsx +76 -0
  107. package/src/tests/createEffectComponent.test.tsx +286 -0
  108. package/src/tests/effects.smoke.test.tsx +238 -0
  109. package/src/tests/test-utils.tsx +96 -0
  110. package/src/tests/wrapEffect.test.tsx +209 -0
  111. package/src/util.tsx +221 -55
  112. package/src/wrapEffect.tsx +123 -0
  113. package/src/EffectComposer.test.tsx +0 -126
  114. package/src/effects/N8AO.tsx +0 -81
@@ -1,40 +1,32 @@
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 type { ReactThreeFiber } from '@react-three/fiber'
2
+ import { GlitchEffect, GlitchMode } from 'postprocessing'
3
+ import type { Ref } from 'react'
4
+ import { useMemo } from 'react'
5
+ import { createEffectComponent, type EffectOptions } from '../createEffectComponent'
6
+
7
+ type GlitchOptions = Omit<
8
+ EffectOptions<typeof GlitchEffect>,
9
+ 'delay' | 'duration' | 'strength' | 'chromaticAberrationOffset'
10
+ > & {
11
+ delay?: ReactThreeFiber.Vector2
12
+ duration?: ReactThreeFiber.Vector2
13
+ strength?: ReactThreeFiber.Vector2
14
+ chromaticAberrationOffset?: ReactThreeFiber.Vector2
15
+ mode?: GlitchMode
16
+ }
17
+
18
+ const GlitchImpl = /* @__PURE__ */ createEffectComponent<typeof GlitchEffect, GlitchOptions>(GlitchEffect)
19
+
20
+ export type GlitchProps = GlitchOptions & {
21
+ active?: boolean
22
+ opacity?: number
23
+ ref?: Ref<GlitchEffect>
24
+ }
25
+
26
+ // dtSize only seeds the auto-generated perturbation map at construction time
27
+ // (skipped entirely once a perturbationMap is provided) - routed through
28
+ // args so it still works as a plain prop.
29
+ export function Glitch({ active = true, mode = GlitchMode.SPORADIC, dtSize, ...props }: GlitchProps) {
30
+ const args = useMemo<[EffectOptions<typeof GlitchEffect>]>(() => [{ dtSize }], [dtSize])
31
+ return <GlitchImpl args={args} mode={active ? mode : GlitchMode.DISABLED} {...props} />
32
+ }
@@ -1,16 +1,104 @@
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 { useThree } from '@react-three/fiber'
2
+ import { GodRaysEffect } from 'postprocessing'
3
+ import { Ref, RefObject, use, useEffect, useLayoutEffect, useMemo } from 'react'
4
+ import { Mesh, Points } from 'three'
5
+ import { EffectComposerContext } from '../EffectComposer'
6
+ import { applyPierced, readPierced, resolveRef, useDispose, useLiveDefaults } from '../util'
7
+
8
+ type GodRaysProps = ConstructorParameters<typeof GodRaysEffect>[2] & {
9
+ sun: Mesh | Points | RefObject<Mesh | Points>
10
+ ref?: Ref<GodRaysEffect>
11
+ }
12
+
13
+ // GodRaysMaterial (godRaysMaterial) is where density/decay/weight/exposure
14
+ // actually live - clampMax maps to its differently-named maxIntensity.
15
+ // resolutionScale/resolutionX/resolutionY have no setter at all in
16
+ // postprocessing - construction-only. camera+sun being required constructor
17
+ // args also rule out createEffectComponent (needs `new Effect()` to work
18
+ // with zero args).
19
+ const LIVE_KEYS = [
20
+ 'blendMode-blendFunction',
21
+ 'godRaysMaterial-density',
22
+ 'godRaysMaterial-decay',
23
+ 'godRaysMaterial-weight',
24
+ 'godRaysMaterial-exposure',
25
+ 'clampMax',
26
+ 'blur',
27
+ 'kernelSize',
28
+ 'samples',
29
+ 'width',
30
+ 'height',
31
+ ]
32
+
33
+ function get(effect: GodRaysEffect, key: string): unknown {
34
+ return key === 'clampMax' ? effect.godRaysMaterial.maxIntensity : readPierced(effect, key)
35
+ }
36
+
37
+ function set(effect: GodRaysEffect, key: string, value: unknown): void {
38
+ if (key === 'clampMax') effect.godRaysMaterial.maxIntensity = value as number
39
+ else applyPierced(effect, key, value)
40
+ }
41
+
42
+ export function GodRays({
43
+ sun,
44
+ blendFunction,
45
+ density,
46
+ decay,
47
+ weight,
48
+ exposure,
49
+ clampMax,
50
+ blur,
51
+ kernelSize,
52
+ samples,
53
+ width,
54
+ height,
55
+ resolutionScale,
56
+ resolutionX,
57
+ resolutionY,
58
+ ref,
59
+ }: GodRaysProps) {
60
+ const { camera, autoClear } = use(EffectComposerContext)
61
+ const invalidate = useThree((state) => state.invalidate)
62
+
63
+ const effect = useMemo(
64
+ () => new GodRaysEffect(camera, resolveRef(sun), { resolutionScale, resolutionX, resolutionY }),
65
+ [camera, resolutionScale, resolutionX, resolutionY]
66
+ )
67
+
68
+ useEffect(() => {
69
+ if (autoClear !== false) {
70
+ console.warn(
71
+ 'GodRays renders an internal extra pass that needs <EffectComposer autoClear={false}> - without it, occlusion by other objects will look wrong.'
72
+ )
73
+ }
74
+ }, [autoClear])
75
+
76
+ useLayoutEffect(() => {
77
+ effect.lightSource = resolveRef(sun)
78
+ invalidate()
79
+ }, [effect, sun, invalidate])
80
+
81
+ useLiveDefaults(
82
+ effect,
83
+ {
84
+ 'blendMode-blendFunction': blendFunction,
85
+ 'godRaysMaterial-density': density,
86
+ 'godRaysMaterial-decay': decay,
87
+ 'godRaysMaterial-weight': weight,
88
+ 'godRaysMaterial-exposure': exposure,
89
+ clampMax,
90
+ blur,
91
+ kernelSize,
92
+ samples,
93
+ width,
94
+ height,
95
+ },
96
+ LIVE_KEYS,
97
+ get,
98
+ set
99
+ )
100
+
101
+ useDispose(effect)
102
+
103
+ return <primitive ref={ref} object={effect} />
104
+ }
@@ -1,21 +1,27 @@
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 { type Ref, useImperativeHandle, useLayoutEffect, useRef } from 'react'
4
+ import { createEffectComponent, type EffectOptions } from '../createEffectComponent'
5
+
6
+ const GridImpl = /* @__PURE__ */ createEffectComponent<typeof GridEffect, EffectOptions<typeof GridEffect>>(GridEffect)
7
+
8
+ export type GridProps = EffectOptions<typeof GridEffect> & {
9
+ size?: { width: number; height: number }
10
+ opacity?: number
11
+ ref?: Ref<GridEffect>
12
+ }
13
+
14
+ export function Grid({ size, ref, ...props }: GridProps) {
15
+ const invalidate = useThree((state) => state.invalidate)
16
+ const localRef = useRef<GridEffect>(null)
17
+ useImperativeHandle(ref, () => localRef.current!, [])
18
+
19
+ useLayoutEffect(() => {
20
+ if (size) {
21
+ localRef.current?.setSize(size.width, size.height)
22
+ invalidate()
23
+ }
24
+ }, [size, invalidate])
25
+
26
+ return <GridImpl ref={localRef} {...props} />
27
+ }
@@ -1,4 +1,7 @@
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 { createEffectComponent, type EffectOptions } from '../createEffectComponent'
3
+
4
+ export const HueSaturation = /* @__PURE__ */ createEffectComponent<
5
+ typeof HueSaturationEffect,
6
+ EffectOptions<typeof HueSaturationEffect>
7
+ >(HueSaturationEffect)
@@ -1,26 +1,25 @@
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 { BlendFunction, LUT3DEffect } from 'postprocessing'
2
+ import { Ref, useMemo } from 'react'
3
+ import type { Texture } from 'three'
4
+ import { useDispose, useLiveDefaults } from '../util'
5
+
6
+ export type LUTProps = {
7
+ lut: Texture
8
+ blendFunction?: BlendFunction
9
+ tetrahedralInterpolation?: boolean
10
+ ref?: Ref<LUT3DEffect>
11
+ }
12
+
13
+ const LIVE_KEYS = ['blendMode-blendFunction', 'lut', 'tetrahedralInterpolation']
14
+
15
+ // lut is LUT3DEffect's required constructor arg (no default) - only used
16
+ // for the initial instance, later changes go through its own live setter
17
+ // (via useLiveDefaults below) instead of reconstructing.
18
+ export function LUT({ lut, blendFunction, tetrahedralInterpolation, ref }: LUTProps) {
19
+ const effect = useMemo(() => new LUT3DEffect(lut), [])
20
+
21
+ useLiveDefaults(effect, { 'blendMode-blendFunction': blendFunction, lut, tetrahedralInterpolation }, LIVE_KEYS)
22
+ useDispose(effect)
23
+
24
+ return <primitive ref={ref} object={effect} />
25
+ }