@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,150 +1,150 @@
1
- import { Uniform } from 'three'
2
- import { Effect } from 'postprocessing'
3
- import { wrapEffect } from '../util'
4
-
5
- const RampShader = {
6
- fragmentShader: /* glsl */ `
7
- uniform int rampType;
8
-
9
- uniform vec2 rampStart;
10
- uniform vec2 rampEnd;
11
-
12
- uniform vec4 startColor;
13
- uniform vec4 endColor;
14
-
15
- uniform float rampBias;
16
- uniform float rampGain;
17
-
18
- uniform bool rampMask;
19
- uniform bool rampInvert;
20
-
21
- float getBias(float time, float bias) {
22
- return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);
23
- }
24
-
25
- float getGain(float time, float gain) {
26
- if (time < 0.5)
27
- return getBias(time * 2.0, gain) / 2.0;
28
- else
29
- return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;
30
- }
31
-
32
- void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
33
- vec2 centerPixel = uv * resolution;
34
- vec2 startPixel = rampStart * resolution;
35
- vec2 endPixel = rampEnd * resolution;
36
-
37
- float rampAlpha;
38
-
39
- if (rampType == 1) {
40
- vec2 fuv = centerPixel / resolution.y;
41
- vec2 suv = startPixel / resolution.y;
42
- vec2 euv = endPixel / resolution.y;
43
-
44
- float radius = length(suv - euv);
45
- float falloff = length(fuv - suv);
46
- rampAlpha = smoothstep(0.0, radius, falloff);
47
- } else {
48
- float radius = length(startPixel - endPixel);
49
- vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));
50
-
51
- float fade = dot(centerPixel - startPixel, direction);
52
- if (rampType == 2) fade = abs(fade);
53
-
54
- rampAlpha = smoothstep(0.0, 1.0, fade / radius);
55
- }
56
-
57
- rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));
58
-
59
- if (rampMask) {
60
- vec4 inputBuff = texture2D(inputBuffer, uv);
61
- outputColor = mix(inputBuff, inputColor, rampAlpha);
62
- } else {
63
- outputColor = mix(startColor, endColor, rampAlpha);
64
- }
65
- }
66
- `,
67
- }
68
-
69
- export enum RampType {
70
- Linear,
71
- Radial,
72
- MirroredLinear,
73
- }
74
-
75
- export class RampEffect extends Effect {
76
- constructor({
77
- /**
78
- * Type of ramp gradient.
79
- */
80
- rampType = RampType.Linear,
81
- /**
82
- * Starting point of the ramp gradient in normalized coordinates.
83
- *
84
- * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.
85
- */
86
- rampStart = [0.5, 0.5],
87
- /**
88
- * Ending point of the ramp gradient in normalized coordinates.
89
- *
90
- * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`
91
- */
92
- rampEnd = [1, 1],
93
- /**
94
- * Color at the starting point of the gradient.
95
- *
96
- * Default is black: `[0, 0, 0, 1]`
97
- */
98
- startColor = [0, 0, 0, 1],
99
- /**
100
- * Color at the ending point of the gradient.
101
- *
102
- * Default is white: `[1, 1, 1, 1]`
103
- */
104
- endColor = [1, 1, 1, 1],
105
- /**
106
- * Bias for the interpolation curve when both bias and gain are 0.5.
107
- *
108
- * Ranges from `[0 - 1]`. Default is `0.5`.
109
- */
110
- rampBias = 0.5,
111
- /**
112
- * Gain for the interpolation curve when both bias and gain are 0.5.
113
- *
114
- * Ranges from `[0 - 1]`. Default is `0.5`.
115
- */
116
- rampGain = 0.5,
117
- /**
118
- * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.
119
- *
120
- * Default is `false`.
121
- */
122
- rampMask = false,
123
- /**
124
- * Controls whether the ramp gradient is inverted.
125
- *
126
- * When disabled, rampStart is transparent and rampEnd is opaque.
127
- *
128
- * Default is `false`.
129
- */
130
- rampInvert = false,
131
- ...params
132
- } = {}) {
133
- super('RampEffect', RampShader.fragmentShader, {
134
- ...params,
135
- uniforms: new Map<string, Uniform>([
136
- ['rampType', new Uniform(rampType)],
137
- ['rampStart', new Uniform(rampStart)],
138
- ['rampEnd', new Uniform(rampEnd)],
139
- ['startColor', new Uniform(startColor)],
140
- ['endColor', new Uniform(endColor)],
141
- ['rampBias', new Uniform(rampBias)],
142
- ['rampGain', new Uniform(rampGain)],
143
- ['rampMask', new Uniform(rampMask)],
144
- ['rampInvert', new Uniform(rampInvert)],
145
- ]),
146
- })
147
- }
148
- }
149
-
150
- export const Ramp = /* @__PURE__ */ wrapEffect(RampEffect)
1
+ import { Uniform } from 'three'
2
+ import { Effect } from 'postprocessing'
3
+ import { wrapEffect } from '../util'
4
+
5
+ const RampShader = {
6
+ fragmentShader: /* glsl */ `
7
+ uniform int rampType;
8
+
9
+ uniform vec2 rampStart;
10
+ uniform vec2 rampEnd;
11
+
12
+ uniform vec4 startColor;
13
+ uniform vec4 endColor;
14
+
15
+ uniform float rampBias;
16
+ uniform float rampGain;
17
+
18
+ uniform bool rampMask;
19
+ uniform bool rampInvert;
20
+
21
+ float getBias(float time, float bias) {
22
+ return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);
23
+ }
24
+
25
+ float getGain(float time, float gain) {
26
+ if (time < 0.5)
27
+ return getBias(time * 2.0, gain) / 2.0;
28
+ else
29
+ return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;
30
+ }
31
+
32
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
33
+ vec2 centerPixel = uv * resolution;
34
+ vec2 startPixel = rampStart * resolution;
35
+ vec2 endPixel = rampEnd * resolution;
36
+
37
+ float rampAlpha;
38
+
39
+ if (rampType == 1) {
40
+ vec2 fuv = centerPixel / resolution.y;
41
+ vec2 suv = startPixel / resolution.y;
42
+ vec2 euv = endPixel / resolution.y;
43
+
44
+ float radius = length(suv - euv);
45
+ float falloff = length(fuv - suv);
46
+ rampAlpha = smoothstep(0.0, radius, falloff);
47
+ } else {
48
+ float radius = length(startPixel - endPixel);
49
+ vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));
50
+
51
+ float fade = dot(centerPixel - startPixel, direction);
52
+ if (rampType == 2) fade = abs(fade);
53
+
54
+ rampAlpha = smoothstep(0.0, 1.0, fade / radius);
55
+ }
56
+
57
+ rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));
58
+
59
+ if (rampMask) {
60
+ vec4 inputBuff = texture2D(inputBuffer, uv);
61
+ outputColor = mix(inputBuff, inputColor, rampAlpha);
62
+ } else {
63
+ outputColor = mix(startColor, endColor, rampAlpha);
64
+ }
65
+ }
66
+ `,
67
+ }
68
+
69
+ export enum RampType {
70
+ Linear,
71
+ Radial,
72
+ MirroredLinear,
73
+ }
74
+
75
+ export class RampEffect extends Effect {
76
+ constructor({
77
+ /**
78
+ * Type of ramp gradient.
79
+ */
80
+ rampType = RampType.Linear,
81
+ /**
82
+ * Starting point of the ramp gradient in normalized coordinates.
83
+ *
84
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.
85
+ */
86
+ rampStart = [0.5, 0.5],
87
+ /**
88
+ * Ending point of the ramp gradient in normalized coordinates.
89
+ *
90
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`
91
+ */
92
+ rampEnd = [1, 1],
93
+ /**
94
+ * Color at the starting point of the gradient.
95
+ *
96
+ * Default is black: `[0, 0, 0, 1]`
97
+ */
98
+ startColor = [0, 0, 0, 1],
99
+ /**
100
+ * Color at the ending point of the gradient.
101
+ *
102
+ * Default is white: `[1, 1, 1, 1]`
103
+ */
104
+ endColor = [1, 1, 1, 1],
105
+ /**
106
+ * Bias for the interpolation curve when both bias and gain are 0.5.
107
+ *
108
+ * Ranges from `[0 - 1]`. Default is `0.5`.
109
+ */
110
+ rampBias = 0.5,
111
+ /**
112
+ * Gain for the interpolation curve when both bias and gain are 0.5.
113
+ *
114
+ * Ranges from `[0 - 1]`. Default is `0.5`.
115
+ */
116
+ rampGain = 0.5,
117
+ /**
118
+ * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.
119
+ *
120
+ * Default is `false`.
121
+ */
122
+ rampMask = false,
123
+ /**
124
+ * Controls whether the ramp gradient is inverted.
125
+ *
126
+ * When disabled, rampStart is transparent and rampEnd is opaque.
127
+ *
128
+ * Default is `false`.
129
+ */
130
+ rampInvert = false,
131
+ ...params
132
+ } = {}) {
133
+ super('RampEffect', RampShader.fragmentShader, {
134
+ ...params,
135
+ uniforms: new Map<string, Uniform>([
136
+ ['rampType', new Uniform(rampType)],
137
+ ['rampStart', new Uniform(rampStart)],
138
+ ['rampEnd', new Uniform(rampEnd)],
139
+ ['startColor', new Uniform(startColor)],
140
+ ['endColor', new Uniform(endColor)],
141
+ ['rampBias', new Uniform(rampBias)],
142
+ ['rampGain', new Uniform(rampGain)],
143
+ ['rampMask', new Uniform(rampMask)],
144
+ ['rampInvert', new Uniform(rampInvert)],
145
+ ]),
146
+ })
147
+ }
148
+ }
149
+
150
+ export const Ramp = /* @__PURE__ */ wrapEffect(RampEffect)
@@ -1,4 +1,4 @@
1
- import { SMAAEffect } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const SMAA = /* @__PURE__ */ wrapEffect(SMAAEffect)
1
+ import { SMAAEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../util'
3
+
4
+ export const SMAA = /* @__PURE__ */ wrapEffect(SMAAEffect)
@@ -1,41 +1,41 @@
1
- import { Ref, forwardRef, useContext, useMemo } from 'react'
2
- import { SSAOEffect, BlendFunction } from 'postprocessing'
3
- import { EffectComposerContext } from '../EffectComposer'
4
-
5
- // first two args are camera and texture
6
- type SSAOProps = ConstructorParameters<typeof SSAOEffect>[2]
7
-
8
- export const SSAO = /* @__PURE__ */ forwardRef<SSAOEffect, SSAOProps>(function SSAO(
9
- props: SSAOProps,
10
- ref: Ref<SSAOEffect>
11
- ) {
12
- const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext)
13
- const effect = useMemo<SSAOEffect | {}>(() => {
14
- if (normalPass === null && downSamplingPass === null) {
15
- console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.')
16
- return {}
17
- }
18
- return new SSAOEffect(camera, normalPass && !downSamplingPass ? (normalPass as any).texture : null, {
19
- blendFunction: BlendFunction.MULTIPLY,
20
- samples: 30,
21
- rings: 4,
22
- distanceThreshold: 1.0,
23
- distanceFalloff: 0.0,
24
- rangeThreshold: 0.5,
25
- rangeFalloff: 0.1,
26
- luminanceInfluence: 0.9,
27
- radius: 20,
28
- bias: 0.5,
29
- intensity: 1.0,
30
- color: undefined,
31
- // @ts-ignore
32
- normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
33
- resolutionScale: resolutionScale ?? 1,
34
- depthAwareUpsampling: true,
35
- ...props,
36
- })
37
- // NOTE: `props` is an unstable reference, so we can't memoize it
38
- // eslint-disable-next-line react-hooks/exhaustive-deps
39
- }, [camera, downSamplingPass, normalPass, resolutionScale])
40
- return <primitive ref={ref} object={effect} dispose={null} />
41
- })
1
+ import { Ref, forwardRef, useContext, useMemo } from 'react'
2
+ import { SSAOEffect, BlendFunction } from 'postprocessing'
3
+ import { EffectComposerContext } from '../EffectComposer'
4
+
5
+ // first two args are camera and texture
6
+ type SSAOProps = ConstructorParameters<typeof SSAOEffect>[2]
7
+
8
+ export const SSAO = /* @__PURE__ */ forwardRef<SSAOEffect, SSAOProps>(function SSAO(
9
+ props: SSAOProps,
10
+ ref: Ref<SSAOEffect>
11
+ ) {
12
+ const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext)
13
+ const effect = useMemo<SSAOEffect | {}>(() => {
14
+ if (normalPass === null && downSamplingPass === null) {
15
+ console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.')
16
+ return {}
17
+ }
18
+ return new SSAOEffect(camera, normalPass && !downSamplingPass ? (normalPass as any).texture : null, {
19
+ blendFunction: BlendFunction.MULTIPLY,
20
+ samples: 30,
21
+ rings: 4,
22
+ distanceThreshold: 1.0,
23
+ distanceFalloff: 0.0,
24
+ rangeThreshold: 0.5,
25
+ rangeFalloff: 0.1,
26
+ luminanceInfluence: 0.9,
27
+ radius: 20,
28
+ bias: 0.5,
29
+ intensity: 1.0,
30
+ color: undefined,
31
+ // @ts-ignore
32
+ normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
33
+ resolutionScale: resolutionScale ?? 1,
34
+ depthAwareUpsampling: true,
35
+ ...props,
36
+ })
37
+ // NOTE: `props` is an unstable reference, so we can't memoize it
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ }, [camera, downSamplingPass, normalPass, resolutionScale])
40
+ return <primitive ref={ref} object={effect} dispose={null} />
41
+ })
@@ -1,7 +1,7 @@
1
- import { ScanlineEffect, BlendFunction } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const Scanline = /* @__PURE__ */ wrapEffect(ScanlineEffect, {
5
- blendFunction: BlendFunction.OVERLAY,
6
- density: 1.25,
7
- })
1
+ import { ScanlineEffect, BlendFunction } from 'postprocessing'
2
+ import { wrapEffect } from '../util'
3
+
4
+ export const Scanline = /* @__PURE__ */ wrapEffect(ScanlineEffect, {
5
+ blendFunction: BlendFunction.OVERLAY,
6
+ density: 1.25,
7
+ })
@@ -1,126 +1,126 @@
1
- import { SelectiveBloomEffect, BlendFunction } from 'postprocessing'
2
- import type { BloomEffectOptions } from 'postprocessing'
3
- import React, { Ref, RefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'
4
- import { Object3D } from 'three'
5
- import { useThree } from '@react-three/fiber'
6
- import { EffectComposerContext } from '../EffectComposer'
7
- import { selectionContext } from '../Selection'
8
- import { resolveRef } from '../util'
9
-
10
- type ObjectRef = RefObject<Object3D>
11
-
12
- export type SelectiveBloomProps = BloomEffectOptions &
13
- Partial<{
14
- lights: Object3D[] | ObjectRef[]
15
- selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
16
- selectionLayer: number
17
- inverted: boolean
18
- ignoreBackground: boolean
19
- }>
20
-
21
- const addLight = (light: Object3D, effect: SelectiveBloomEffect) => light.layers.enable(effect.selection.layer)
22
- const removeLight = (light: Object3D, effect: SelectiveBloomEffect) => light.layers.disable(effect.selection.layer)
23
-
24
- export const SelectiveBloom = /* @__PURE__ */ forwardRef(function SelectiveBloom(
25
- {
26
- selection = [],
27
- selectionLayer = 10,
28
- lights = [],
29
- inverted = false,
30
- ignoreBackground = false,
31
- luminanceThreshold,
32
- luminanceSmoothing,
33
- intensity,
34
- width,
35
- height,
36
- kernelSize,
37
- mipmapBlur,
38
-
39
- ...props
40
- }: SelectiveBloomProps,
41
- forwardRef: Ref<SelectiveBloomEffect>
42
- ) {
43
- if (lights.length === 0) {
44
- console.warn('SelectiveBloom requires lights to work.')
45
- }
46
-
47
- const invalidate = useThree((state) => state.invalidate)
48
- const { scene, camera } = useContext(EffectComposerContext)
49
- const effect = useMemo(() => {
50
- const effect = new SelectiveBloomEffect(scene, camera, {
51
- blendFunction: BlendFunction.ADD,
52
- luminanceThreshold,
53
- luminanceSmoothing,
54
- intensity,
55
- width,
56
- height,
57
- kernelSize,
58
- mipmapBlur,
59
- ...props,
60
- })
61
- effect.inverted = inverted
62
- effect.ignoreBackground = ignoreBackground
63
- return effect
64
- }, [
65
- scene,
66
- camera,
67
- luminanceThreshold,
68
- luminanceSmoothing,
69
- intensity,
70
- width,
71
- height,
72
- kernelSize,
73
- mipmapBlur,
74
- inverted,
75
- ignoreBackground,
76
- props,
77
- ])
78
-
79
- const api = useContext(selectionContext)
80
-
81
- useEffect(() => {
82
- // Do not allow array selection if declarative selection is active
83
- // TODO: array selection should probably be deprecated altogether
84
- if (!api && selection) {
85
- effect.selection.set(
86
- Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]
87
- )
88
- invalidate()
89
- return () => {
90
- effect.selection.clear()
91
- invalidate()
92
- }
93
- }
94
- }, [effect, selection, api, invalidate])
95
-
96
- useEffect(() => {
97
- effect.selection.layer = selectionLayer
98
- invalidate()
99
- }, [effect, invalidate, selectionLayer])
100
-
101
- useEffect(() => {
102
- if (lights && lights.length > 0) {
103
- lights.forEach((light) => addLight(resolveRef(light), effect))
104
- invalidate()
105
- return () => {
106
- lights.forEach((light) => removeLight(resolveRef(light), effect))
107
- invalidate()
108
- }
109
- }
110
- }, [effect, invalidate, lights, selectionLayer])
111
-
112
- useEffect(() => {
113
- if (api && api.enabled) {
114
- if (api.selected?.length) {
115
- effect.selection.set(api.selected)
116
- invalidate()
117
- return () => {
118
- effect.selection.clear()
119
- invalidate()
120
- }
121
- }
122
- }
123
- }, [api, effect.selection, invalidate])
124
-
125
- return <primitive ref={forwardRef} object={effect} dispose={null} />
126
- })
1
+ import { SelectiveBloomEffect, BlendFunction } from 'postprocessing'
2
+ import type { BloomEffectOptions } from 'postprocessing'
3
+ import React, { Ref, RefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'
4
+ import { Object3D } from 'three'
5
+ import { useThree } from '@react-three/fiber'
6
+ import { EffectComposerContext } from '../EffectComposer'
7
+ import { selectionContext } from '../Selection'
8
+ import { resolveRef } from '../util'
9
+
10
+ type ObjectRef = RefObject<Object3D>
11
+
12
+ export type SelectiveBloomProps = BloomEffectOptions &
13
+ Partial<{
14
+ lights: Object3D[] | ObjectRef[]
15
+ selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
16
+ selectionLayer: number
17
+ inverted: boolean
18
+ ignoreBackground: boolean
19
+ }>
20
+
21
+ const addLight = (light: Object3D, effect: SelectiveBloomEffect) => light.layers.enable(effect.selection.layer)
22
+ const removeLight = (light: Object3D, effect: SelectiveBloomEffect) => light.layers.disable(effect.selection.layer)
23
+
24
+ export const SelectiveBloom = /* @__PURE__ */ forwardRef(function SelectiveBloom(
25
+ {
26
+ selection = [],
27
+ selectionLayer = 10,
28
+ lights = [],
29
+ inverted = false,
30
+ ignoreBackground = false,
31
+ luminanceThreshold,
32
+ luminanceSmoothing,
33
+ intensity,
34
+ width,
35
+ height,
36
+ kernelSize,
37
+ mipmapBlur,
38
+
39
+ ...props
40
+ }: SelectiveBloomProps,
41
+ forwardRef: Ref<SelectiveBloomEffect>
42
+ ) {
43
+ if (lights.length === 0) {
44
+ console.warn('SelectiveBloom requires lights to work.')
45
+ }
46
+
47
+ const invalidate = useThree((state) => state.invalidate)
48
+ const { scene, camera } = useContext(EffectComposerContext)
49
+ const effect = useMemo(() => {
50
+ const effect = new SelectiveBloomEffect(scene, camera, {
51
+ blendFunction: BlendFunction.ADD,
52
+ luminanceThreshold,
53
+ luminanceSmoothing,
54
+ intensity,
55
+ width,
56
+ height,
57
+ kernelSize,
58
+ mipmapBlur,
59
+ ...props,
60
+ })
61
+ effect.inverted = inverted
62
+ effect.ignoreBackground = ignoreBackground
63
+ return effect
64
+ }, [
65
+ scene,
66
+ camera,
67
+ luminanceThreshold,
68
+ luminanceSmoothing,
69
+ intensity,
70
+ width,
71
+ height,
72
+ kernelSize,
73
+ mipmapBlur,
74
+ inverted,
75
+ ignoreBackground,
76
+ props,
77
+ ])
78
+
79
+ const api = useContext(selectionContext)
80
+
81
+ useEffect(() => {
82
+ // Do not allow array selection if declarative selection is active
83
+ // TODO: array selection should probably be deprecated altogether
84
+ if (!api && selection) {
85
+ effect.selection.set(
86
+ Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]
87
+ )
88
+ invalidate()
89
+ return () => {
90
+ effect.selection.clear()
91
+ invalidate()
92
+ }
93
+ }
94
+ }, [effect, selection, api, invalidate])
95
+
96
+ useEffect(() => {
97
+ effect.selection.layer = selectionLayer
98
+ invalidate()
99
+ }, [effect, invalidate, selectionLayer])
100
+
101
+ useEffect(() => {
102
+ if (lights && lights.length > 0) {
103
+ lights.forEach((light) => addLight(resolveRef(light), effect))
104
+ invalidate()
105
+ return () => {
106
+ lights.forEach((light) => removeLight(resolveRef(light), effect))
107
+ invalidate()
108
+ }
109
+ }
110
+ }, [effect, invalidate, lights, selectionLayer])
111
+
112
+ useEffect(() => {
113
+ if (api && api.enabled) {
114
+ if (api.selected?.length) {
115
+ effect.selection.set(api.selected)
116
+ invalidate()
117
+ return () => {
118
+ effect.selection.clear()
119
+ invalidate()
120
+ }
121
+ }
122
+ }
123
+ }, [api, effect.selection, invalidate])
124
+
125
+ return <primitive ref={forwardRef} object={effect} dispose={null} />
126
+ })
@@ -1,4 +1,4 @@
1
- import { SepiaEffect } from 'postprocessing'
2
- import { wrapEffect } from '../util'
3
-
4
- export const Sepia = /* @__PURE__ */ wrapEffect(SepiaEffect)
1
+ import { SepiaEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../util'
3
+
4
+ export const Sepia = /* @__PURE__ */ wrapEffect(SepiaEffect)