@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.
- package/LICENSE +21 -21
- package/README.md +80 -81
- package/dist/EffectComposer.d.ts +14 -6
- package/dist/EffectGroup.d.ts +9 -0
- package/dist/Selection.d.ts +8 -8
- package/dist/createEffectComponent.d.ts +30 -0
- package/dist/effects/ASCII.d.ts +29 -7
- package/dist/effects/Autofocus.d.ts +8 -7
- package/dist/effects/Bloom.d.ts +10 -5
- package/dist/effects/BrightnessContrast.d.ts +15 -5
- package/dist/effects/ChromaticAberration.d.ts +30 -7
- package/dist/effects/ColorAverage.d.ts +7 -8
- package/dist/effects/ColorDepth.d.ts +8 -5
- package/dist/effects/Depth.d.ts +13 -5
- package/dist/effects/DepthOfField.d.ts +7 -18
- package/dist/effects/DotScreen.d.ts +15 -5
- package/dist/effects/FXAA.d.ts +11 -5
- package/dist/effects/Glitch.d.ts +17 -29
- package/dist/effects/GodRays.d.ts +7 -19
- package/dist/effects/Grid.d.ts +8 -8
- package/dist/effects/HueSaturation.d.ts +15 -5
- package/dist/effects/LUT.d.ts +4 -3
- package/dist/effects/LensFlare.d.ts +52 -11
- package/dist/effects/Noise.d.ts +8 -5
- package/dist/effects/Outline.d.ts +9 -25
- package/dist/effects/Pixelation.d.ts +3 -2
- package/dist/effects/Ramp.d.ts +58 -10
- package/dist/effects/SMAA.d.ts +10 -5
- package/dist/effects/SSAO.d.ts +7 -30
- package/dist/effects/ScanlineEffect.d.ts +13 -5
- package/dist/effects/SelectiveBloom.d.ts +5 -10
- package/dist/effects/Sepia.d.ts +13 -5
- package/dist/effects/ShockWave.d.ts +12 -5
- package/dist/effects/Texture.d.ts +7 -8
- package/dist/effects/TiltShift.d.ts +10 -5
- package/dist/effects/TiltShift2.d.ts +44 -8
- package/dist/effects/ToneMapping.d.ts +9 -7
- package/dist/effects/Vignette.d.ts +19 -5
- package/dist/effects/Water.d.ts +17 -5
- package/dist/index.d.ts +15 -11
- package/dist/index.js +1841 -45
- package/dist/index.js.map +1 -1
- package/dist/passes/DepthPicking.d.ts +11 -0
- package/dist/{effects → passes}/N8AO.d.ts +5 -2
- package/dist/util.d.ts +19 -17
- package/dist/wrapEffect.d.ts +12 -0
- package/package.json +74 -67
- package/src/EffectComposer.tsx +379 -200
- package/src/EffectGroup.tsx +74 -0
- package/src/Selection.tsx +86 -46
- package/src/createEffectComponent.tsx +71 -0
- package/src/effects/ASCII.tsx +183 -135
- package/src/effects/Autofocus.tsx +122 -153
- package/src/effects/Bloom.tsx +34 -6
- package/src/effects/BrightnessContrast.tsx +7 -4
- package/src/effects/ChromaticAberration.tsx +22 -5
- package/src/effects/ColorAverage.tsx +4 -15
- package/src/effects/ColorDepth.tsx +25 -4
- package/src/effects/Depth.tsx +6 -4
- package/src/effects/DepthOfField.tsx +109 -89
- package/src/effects/DotScreen.tsx +7 -4
- package/src/effects/FXAA.tsx +6 -4
- package/src/effects/Glitch.tsx +32 -40
- package/src/effects/GodRays.tsx +104 -16
- package/src/effects/Grid.tsx +27 -21
- package/src/effects/HueSaturation.tsx +7 -4
- package/src/effects/LUT.tsx +25 -26
- package/src/effects/LensFlare.tsx +765 -611
- package/src/effects/Noise.tsx +16 -4
- package/src/effects/Outline.tsx +84 -117
- package/src/effects/Pixelation.tsx +20 -15
- package/src/effects/Ramp.tsx +239 -150
- package/src/effects/SMAA.tsx +20 -4
- package/src/effects/SSAO.tsx +152 -41
- package/src/effects/ScanlineEffect.tsx +7 -7
- package/src/effects/SelectiveBloom.tsx +98 -126
- package/src/effects/Sepia.tsx +6 -4
- package/src/effects/ShockWave.tsx +32 -4
- package/src/effects/Texture.tsx +28 -23
- package/src/effects/TiltShift.tsx +32 -4
- package/src/effects/TiltShift2.tsx +156 -90
- package/src/effects/ToneMapping.tsx +19 -6
- package/src/effects/Vignette.tsx +7 -4
- package/src/effects/Water.tsx +50 -35
- package/src/index.ts +43 -40
- package/src/passes/DepthPicking.tsx +63 -0
- package/src/passes/N8AO.tsx +105 -0
- package/src/tests/Autofocus.test.tsx +38 -0
- package/src/tests/Bloom.test.tsx +76 -0
- package/src/tests/ChromaticAberration.test.tsx +81 -0
- package/src/tests/ColorDepth.test.tsx +71 -0
- package/src/tests/DepthOfField.test.tsx +130 -0
- package/src/tests/DepthPicking.test.tsx +250 -0
- package/src/tests/EffectComposer.test.tsx +1404 -0
- package/src/tests/EffectGroup.test.tsx +337 -0
- package/src/tests/Glitch.test.tsx +56 -0
- package/src/tests/GodRays.test.tsx +101 -0
- package/src/tests/Grid.test.tsx +34 -0
- package/src/tests/LUT.test.tsx +64 -0
- package/src/tests/N8AO.test.tsx +92 -0
- package/src/tests/Outline.test.tsx +211 -0
- package/src/tests/SSAO.test.tsx +140 -0
- package/src/tests/Selection.test.tsx +324 -0
- package/src/tests/SelectiveBloom.test.tsx +166 -0
- package/src/tests/ShockWave.test.tsx +95 -0
- package/src/tests/TiltShift.test.tsx +76 -0
- package/src/tests/createEffectComponent.test.tsx +286 -0
- package/src/tests/effects.smoke.test.tsx +238 -0
- package/src/tests/test-utils.tsx +96 -0
- package/src/tests/wrapEffect.test.tsx +209 -0
- package/src/util.tsx +221 -55
- package/src/wrapEffect.tsx +123 -0
- package/src/EffectComposer.test.tsx +0 -126
- package/src/effects/N8AO.tsx +0 -81
package/src/effects/Glitch.tsx
CHANGED
|
@@ -1,40 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GlitchEffect, GlitchMode } from 'postprocessing'
|
|
3
|
-
import { Ref
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
}
|
package/src/effects/GodRays.tsx
CHANGED
|
@@ -1,16 +1,104 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
package/src/effects/Grid.tsx
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { GridEffect } from 'postprocessing'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 {
|
|
3
|
-
|
|
4
|
-
export const HueSaturation = /* @__PURE__ */
|
|
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)
|
package/src/effects/LUT.tsx
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
export type LUTProps = {
|
|
7
|
-
lut: Texture
|
|
8
|
-
blendFunction?: BlendFunction
|
|
9
|
-
tetrahedralInterpolation?: boolean
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
}
|