@react-three/postprocessing 3.0.0-rc.2 → 3.0.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 +81 -81
- package/package.json +68 -68
- package/src/EffectComposer.test.tsx +126 -126
- package/src/EffectComposer.tsx +200 -200
- package/src/Selection.tsx +46 -46
- package/src/effects/ASCII.tsx +135 -135
- package/src/effects/Autofocus.tsx +153 -153
- package/src/effects/Bloom.tsx +6 -6
- package/src/effects/BrightnessContrast.tsx +4 -4
- package/src/effects/ChromaticAberration.tsx +5 -5
- package/src/effects/ColorAverage.tsx +15 -15
- package/src/effects/ColorDepth.tsx +4 -4
- package/src/effects/Depth.tsx +4 -4
- package/src/effects/DepthOfField.tsx +89 -89
- package/src/effects/DotScreen.tsx +4 -4
- package/src/effects/FXAA.tsx +4 -4
- package/src/effects/Glitch.tsx +40 -40
- package/src/effects/GodRays.tsx +16 -16
- package/src/effects/Grid.tsx +21 -21
- package/src/effects/HueSaturation.tsx +4 -4
- package/src/effects/LUT.tsx +26 -26
- package/src/effects/LensFlare.tsx +611 -611
- package/src/effects/N8AO.tsx +81 -81
- package/src/effects/Noise.tsx +4 -4
- package/src/effects/Outline.tsx +117 -117
- package/src/effects/Pixelation.tsx +15 -15
- package/src/effects/Ramp.tsx +150 -150
- package/src/effects/SMAA.tsx +4 -4
- package/src/effects/SSAO.tsx +41 -41
- package/src/effects/ScanlineEffect.tsx +7 -7
- package/src/effects/SelectiveBloom.tsx +126 -126
- package/src/effects/Sepia.tsx +4 -4
- package/src/effects/ShockWave.tsx +4 -4
- package/src/effects/Texture.tsx +23 -23
- package/src/effects/TiltShift.tsx +4 -4
- package/src/effects/TiltShift2.tsx +90 -90
- package/src/effects/ToneMapping.tsx +6 -6
- package/src/effects/Vignette.tsx +4 -4
- package/src/effects/Water.tsx +35 -35
- package/src/index.ts +40 -40
- package/src/util.tsx +55 -55
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -555
- package/dist/index.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ShockWaveEffect } from 'postprocessing'
|
|
2
|
-
import { wrapEffect } from '../util'
|
|
3
|
-
|
|
4
|
-
export const ShockWave = /* @__PURE__ */ wrapEffect(ShockWaveEffect)
|
|
1
|
+
import { ShockWaveEffect } from 'postprocessing'
|
|
2
|
+
import { wrapEffect } from '../util'
|
|
3
|
+
|
|
4
|
+
export const ShockWave = /* @__PURE__ */ wrapEffect(ShockWaveEffect)
|
package/src/effects/Texture.tsx
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { TextureEffect } from 'postprocessing'
|
|
2
|
-
import { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'
|
|
3
|
-
import { useLoader } from '@react-three/fiber'
|
|
4
|
-
import { TextureLoader, SRGBColorSpace, RepeatWrapping } from 'three'
|
|
5
|
-
|
|
6
|
-
type TextureProps = ConstructorParameters<typeof TextureEffect>[0] & {
|
|
7
|
-
textureSrc: string
|
|
8
|
-
/** opacity of provided texture */
|
|
9
|
-
opacity?: number
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const Texture = /* @__PURE__ */ forwardRef<TextureEffect, TextureProps>(function Texture(
|
|
13
|
-
{ textureSrc, texture, opacity = 1, ...props }: TextureProps,
|
|
14
|
-
ref: Ref<TextureEffect>
|
|
15
|
-
) {
|
|
16
|
-
const t = useLoader(TextureLoader, textureSrc)
|
|
17
|
-
useLayoutEffect(() => {
|
|
18
|
-
t.colorSpace = SRGBColorSpace
|
|
19
|
-
t.wrapS = t.wrapT = RepeatWrapping
|
|
20
|
-
}, [t])
|
|
21
|
-
const effect = useMemo(() => new TextureEffect({ ...props, texture: t || texture }), [props, t, texture])
|
|
22
|
-
return <primitive ref={ref} object={effect} blendMode-opacity-value={opacity} dispose={null} />
|
|
23
|
-
})
|
|
1
|
+
import { TextureEffect } from 'postprocessing'
|
|
2
|
+
import { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'
|
|
3
|
+
import { useLoader } from '@react-three/fiber'
|
|
4
|
+
import { TextureLoader, SRGBColorSpace, RepeatWrapping } from 'three'
|
|
5
|
+
|
|
6
|
+
type TextureProps = ConstructorParameters<typeof TextureEffect>[0] & {
|
|
7
|
+
textureSrc: string
|
|
8
|
+
/** opacity of provided texture */
|
|
9
|
+
opacity?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Texture = /* @__PURE__ */ forwardRef<TextureEffect, TextureProps>(function Texture(
|
|
13
|
+
{ textureSrc, texture, opacity = 1, ...props }: TextureProps,
|
|
14
|
+
ref: Ref<TextureEffect>
|
|
15
|
+
) {
|
|
16
|
+
const t = useLoader(TextureLoader, textureSrc)
|
|
17
|
+
useLayoutEffect(() => {
|
|
18
|
+
t.colorSpace = SRGBColorSpace
|
|
19
|
+
t.wrapS = t.wrapT = RepeatWrapping
|
|
20
|
+
}, [t])
|
|
21
|
+
const effect = useMemo(() => new TextureEffect({ ...props, texture: t || texture }), [props, t, texture])
|
|
22
|
+
return <primitive ref={ref} object={effect} blendMode-opacity-value={opacity} dispose={null} />
|
|
23
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TiltShiftEffect, BlendFunction } from 'postprocessing'
|
|
2
|
-
import { wrapEffect } from '../util'
|
|
3
|
-
|
|
4
|
-
export const TiltShift = /* @__PURE__ */ wrapEffect(TiltShiftEffect, { blendFunction: BlendFunction.ADD })
|
|
1
|
+
import { TiltShiftEffect, BlendFunction } from 'postprocessing'
|
|
2
|
+
import { wrapEffect } from '../util'
|
|
3
|
+
|
|
4
|
+
export const TiltShift = /* @__PURE__ */ wrapEffect(TiltShiftEffect, { blendFunction: BlendFunction.ADD })
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import { Uniform } from 'three'
|
|
2
|
-
import { BlendFunction, Effect, EffectAttribute } from 'postprocessing'
|
|
3
|
-
import { wrapEffect } from '../util'
|
|
4
|
-
|
|
5
|
-
const TiltShiftShader = {
|
|
6
|
-
fragmentShader: `
|
|
7
|
-
|
|
8
|
-
// original shader by Evan Wallace
|
|
9
|
-
|
|
10
|
-
#define MAX_ITERATIONS 100
|
|
11
|
-
|
|
12
|
-
uniform float blur;
|
|
13
|
-
uniform float taper;
|
|
14
|
-
uniform vec2 start;
|
|
15
|
-
uniform vec2 end;
|
|
16
|
-
uniform vec2 direction;
|
|
17
|
-
uniform int samples;
|
|
18
|
-
|
|
19
|
-
float random(vec3 scale, float seed) {
|
|
20
|
-
/* use the fragment position for a different seed per-pixel */
|
|
21
|
-
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
25
|
-
vec4 color = vec4(0.0);
|
|
26
|
-
float total = 0.0;
|
|
27
|
-
vec2 startPixel = vec2(start.x * resolution.x, start.y * resolution.y);
|
|
28
|
-
vec2 endPixel = vec2(end.x * resolution.x, end.y * resolution.y);
|
|
29
|
-
float f_samples = float(samples);
|
|
30
|
-
float half_samples = f_samples / 2.0;
|
|
31
|
-
|
|
32
|
-
// use screen diagonal to normalize blur radii
|
|
33
|
-
float maxScreenDistance = distance(vec2(0.0), resolution); // diagonal distance
|
|
34
|
-
float gradientRadius = taper * (maxScreenDistance);
|
|
35
|
-
float blurRadius = blur * (maxScreenDistance / 16.0);
|
|
36
|
-
|
|
37
|
-
/* randomize the lookup values to hide the fixed number of samples */
|
|
38
|
-
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
39
|
-
vec2 normal = normalize(vec2(startPixel.y - endPixel.y, endPixel.x - startPixel.x));
|
|
40
|
-
float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradientRadius) * blurRadius;
|
|
41
|
-
|
|
42
|
-
#pragma unroll_loop_start
|
|
43
|
-
for (int i = 0; i <= MAX_ITERATIONS; i++) {
|
|
44
|
-
if (i >= samples) { break; } // return early if over sample count
|
|
45
|
-
float f_i = float(i);
|
|
46
|
-
float s_i = -half_samples + f_i;
|
|
47
|
-
float percent = (s_i + offset - 0.5) / half_samples;
|
|
48
|
-
float weight = 1.0 - abs(percent);
|
|
49
|
-
vec4 sample_i = texture2D(inputBuffer, uv + normalize(direction) / resolution * percent * radius);
|
|
50
|
-
/* switch to pre-multiplied alpha to correctly blur transparent images */
|
|
51
|
-
sample_i.rgb *= sample_i.a;
|
|
52
|
-
color += sample_i * weight;
|
|
53
|
-
total += weight;
|
|
54
|
-
}
|
|
55
|
-
#pragma unroll_loop_end
|
|
56
|
-
|
|
57
|
-
outputColor = color / total;
|
|
58
|
-
|
|
59
|
-
/* switch back from pre-multiplied alpha */
|
|
60
|
-
outputColor.rgb /= outputColor.a + 0.00001;
|
|
61
|
-
}
|
|
62
|
-
`,
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export class TiltShiftEffect extends Effect {
|
|
66
|
-
constructor({
|
|
67
|
-
blendFunction = BlendFunction.NORMAL,
|
|
68
|
-
blur = 0.15, // [0, 1], can go beyond 1 for extra
|
|
69
|
-
taper = 0.5, // [0, 1], can go beyond 1 for extra
|
|
70
|
-
start = [0.5, 0.0], // [0,1] percentage x,y of screenspace
|
|
71
|
-
end = [0.5, 1.0], // [0,1] percentage x,y of screenspace
|
|
72
|
-
samples = 10.0, // number of blur samples
|
|
73
|
-
direction = [1, 1], // direction of blur
|
|
74
|
-
} = {}) {
|
|
75
|
-
super('TiltShiftEffect', TiltShiftShader.fragmentShader, {
|
|
76
|
-
blendFunction,
|
|
77
|
-
attributes: EffectAttribute.CONVOLUTION,
|
|
78
|
-
uniforms: new Map<string, Uniform<number | number[]>>([
|
|
79
|
-
['blur', new Uniform(blur)],
|
|
80
|
-
['taper', new Uniform(taper)],
|
|
81
|
-
['start', new Uniform(start)],
|
|
82
|
-
['end', new Uniform(end)],
|
|
83
|
-
['samples', new Uniform(samples)],
|
|
84
|
-
['direction', new Uniform(direction)],
|
|
85
|
-
]),
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const TiltShift2 = /* @__PURE__ */ wrapEffect(TiltShiftEffect, { blendFunction: BlendFunction.NORMAL })
|
|
1
|
+
import { Uniform } from 'three'
|
|
2
|
+
import { BlendFunction, Effect, EffectAttribute } from 'postprocessing'
|
|
3
|
+
import { wrapEffect } from '../util'
|
|
4
|
+
|
|
5
|
+
const TiltShiftShader = {
|
|
6
|
+
fragmentShader: `
|
|
7
|
+
|
|
8
|
+
// original shader by Evan Wallace
|
|
9
|
+
|
|
10
|
+
#define MAX_ITERATIONS 100
|
|
11
|
+
|
|
12
|
+
uniform float blur;
|
|
13
|
+
uniform float taper;
|
|
14
|
+
uniform vec2 start;
|
|
15
|
+
uniform vec2 end;
|
|
16
|
+
uniform vec2 direction;
|
|
17
|
+
uniform int samples;
|
|
18
|
+
|
|
19
|
+
float random(vec3 scale, float seed) {
|
|
20
|
+
/* use the fragment position for a different seed per-pixel */
|
|
21
|
+
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
25
|
+
vec4 color = vec4(0.0);
|
|
26
|
+
float total = 0.0;
|
|
27
|
+
vec2 startPixel = vec2(start.x * resolution.x, start.y * resolution.y);
|
|
28
|
+
vec2 endPixel = vec2(end.x * resolution.x, end.y * resolution.y);
|
|
29
|
+
float f_samples = float(samples);
|
|
30
|
+
float half_samples = f_samples / 2.0;
|
|
31
|
+
|
|
32
|
+
// use screen diagonal to normalize blur radii
|
|
33
|
+
float maxScreenDistance = distance(vec2(0.0), resolution); // diagonal distance
|
|
34
|
+
float gradientRadius = taper * (maxScreenDistance);
|
|
35
|
+
float blurRadius = blur * (maxScreenDistance / 16.0);
|
|
36
|
+
|
|
37
|
+
/* randomize the lookup values to hide the fixed number of samples */
|
|
38
|
+
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
39
|
+
vec2 normal = normalize(vec2(startPixel.y - endPixel.y, endPixel.x - startPixel.x));
|
|
40
|
+
float radius = smoothstep(0.0, 1.0, abs(dot(uv * resolution - startPixel, normal)) / gradientRadius) * blurRadius;
|
|
41
|
+
|
|
42
|
+
#pragma unroll_loop_start
|
|
43
|
+
for (int i = 0; i <= MAX_ITERATIONS; i++) {
|
|
44
|
+
if (i >= samples) { break; } // return early if over sample count
|
|
45
|
+
float f_i = float(i);
|
|
46
|
+
float s_i = -half_samples + f_i;
|
|
47
|
+
float percent = (s_i + offset - 0.5) / half_samples;
|
|
48
|
+
float weight = 1.0 - abs(percent);
|
|
49
|
+
vec4 sample_i = texture2D(inputBuffer, uv + normalize(direction) / resolution * percent * radius);
|
|
50
|
+
/* switch to pre-multiplied alpha to correctly blur transparent images */
|
|
51
|
+
sample_i.rgb *= sample_i.a;
|
|
52
|
+
color += sample_i * weight;
|
|
53
|
+
total += weight;
|
|
54
|
+
}
|
|
55
|
+
#pragma unroll_loop_end
|
|
56
|
+
|
|
57
|
+
outputColor = color / total;
|
|
58
|
+
|
|
59
|
+
/* switch back from pre-multiplied alpha */
|
|
60
|
+
outputColor.rgb /= outputColor.a + 0.00001;
|
|
61
|
+
}
|
|
62
|
+
`,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class TiltShiftEffect extends Effect {
|
|
66
|
+
constructor({
|
|
67
|
+
blendFunction = BlendFunction.NORMAL,
|
|
68
|
+
blur = 0.15, // [0, 1], can go beyond 1 for extra
|
|
69
|
+
taper = 0.5, // [0, 1], can go beyond 1 for extra
|
|
70
|
+
start = [0.5, 0.0], // [0,1] percentage x,y of screenspace
|
|
71
|
+
end = [0.5, 1.0], // [0,1] percentage x,y of screenspace
|
|
72
|
+
samples = 10.0, // number of blur samples
|
|
73
|
+
direction = [1, 1], // direction of blur
|
|
74
|
+
} = {}) {
|
|
75
|
+
super('TiltShiftEffect', TiltShiftShader.fragmentShader, {
|
|
76
|
+
blendFunction,
|
|
77
|
+
attributes: EffectAttribute.CONVOLUTION,
|
|
78
|
+
uniforms: new Map<string, Uniform<number | number[]>>([
|
|
79
|
+
['blur', new Uniform(blur)],
|
|
80
|
+
['taper', new Uniform(taper)],
|
|
81
|
+
['start', new Uniform(start)],
|
|
82
|
+
['end', new Uniform(end)],
|
|
83
|
+
['samples', new Uniform(samples)],
|
|
84
|
+
['direction', new Uniform(direction)],
|
|
85
|
+
]),
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const TiltShift2 = /* @__PURE__ */ wrapEffect(TiltShiftEffect, { blendFunction: BlendFunction.NORMAL })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ToneMappingEffect } from 'postprocessing'
|
|
2
|
-
import { type EffectProps, wrapEffect } from '../util'
|
|
3
|
-
|
|
4
|
-
export type ToneMappingProps = EffectProps<typeof ToneMappingEffect>
|
|
5
|
-
|
|
6
|
-
export const ToneMapping = /* @__PURE__ */ wrapEffect(ToneMappingEffect)
|
|
1
|
+
import { ToneMappingEffect } from 'postprocessing'
|
|
2
|
+
import { type EffectProps, wrapEffect } from '../util'
|
|
3
|
+
|
|
4
|
+
export type ToneMappingProps = EffectProps<typeof ToneMappingEffect>
|
|
5
|
+
|
|
6
|
+
export const ToneMapping = /* @__PURE__ */ wrapEffect(ToneMappingEffect)
|
package/src/effects/Vignette.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VignetteEffect } from 'postprocessing'
|
|
2
|
-
import { wrapEffect } from '../util'
|
|
3
|
-
|
|
4
|
-
export const Vignette = /* @__PURE__ */ wrapEffect(VignetteEffect)
|
|
1
|
+
import { VignetteEffect } from 'postprocessing'
|
|
2
|
+
import { wrapEffect } from '../util'
|
|
3
|
+
|
|
4
|
+
export const Vignette = /* @__PURE__ */ wrapEffect(VignetteEffect)
|
package/src/effects/Water.tsx
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Uniform } from 'three'
|
|
2
|
-
import { BlendFunction, Effect, EffectAttribute } from 'postprocessing'
|
|
3
|
-
import { wrapEffect } from '../util'
|
|
4
|
-
|
|
5
|
-
const WaterShader = {
|
|
6
|
-
fragmentShader: /* glsl */ `
|
|
7
|
-
uniform float factor;
|
|
8
|
-
|
|
9
|
-
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
10
|
-
vec2 vUv = uv;
|
|
11
|
-
float frequency = 6.0 * factor;
|
|
12
|
-
float amplitude = 0.015 * factor;
|
|
13
|
-
float x = vUv.y * frequency + time * 0.7;
|
|
14
|
-
float y = vUv.x * frequency + time * 0.3;
|
|
15
|
-
vUv.x += cos(x + y) * amplitude * cos(y);
|
|
16
|
-
vUv.y += sin(x - y) * amplitude * cos(y);
|
|
17
|
-
vec4 rgba = texture(inputBuffer, vUv);
|
|
18
|
-
outputColor = rgba;
|
|
19
|
-
}
|
|
20
|
-
`,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class WaterEffectImpl extends Effect {
|
|
24
|
-
constructor({ blendFunction = BlendFunction.NORMAL, factor = 0 } = {}) {
|
|
25
|
-
super('WaterEffect', WaterShader.fragmentShader, {
|
|
26
|
-
blendFunction,
|
|
27
|
-
attributes: EffectAttribute.CONVOLUTION,
|
|
28
|
-
uniforms: new Map<string, Uniform<number | number[]>>([['factor', new Uniform(factor)]]),
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const WaterEffect = /* @__PURE__ */ wrapEffect(WaterEffectImpl, {
|
|
34
|
-
blendFunction: BlendFunction.NORMAL,
|
|
35
|
-
})
|
|
1
|
+
import { Uniform } from 'three'
|
|
2
|
+
import { BlendFunction, Effect, EffectAttribute } from 'postprocessing'
|
|
3
|
+
import { wrapEffect } from '../util'
|
|
4
|
+
|
|
5
|
+
const WaterShader = {
|
|
6
|
+
fragmentShader: /* glsl */ `
|
|
7
|
+
uniform float factor;
|
|
8
|
+
|
|
9
|
+
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
10
|
+
vec2 vUv = uv;
|
|
11
|
+
float frequency = 6.0 * factor;
|
|
12
|
+
float amplitude = 0.015 * factor;
|
|
13
|
+
float x = vUv.y * frequency + time * 0.7;
|
|
14
|
+
float y = vUv.x * frequency + time * 0.3;
|
|
15
|
+
vUv.x += cos(x + y) * amplitude * cos(y);
|
|
16
|
+
vUv.y += sin(x - y) * amplitude * cos(y);
|
|
17
|
+
vec4 rgba = texture(inputBuffer, vUv);
|
|
18
|
+
outputColor = rgba;
|
|
19
|
+
}
|
|
20
|
+
`,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class WaterEffectImpl extends Effect {
|
|
24
|
+
constructor({ blendFunction = BlendFunction.NORMAL, factor = 0 } = {}) {
|
|
25
|
+
super('WaterEffect', WaterShader.fragmentShader, {
|
|
26
|
+
blendFunction,
|
|
27
|
+
attributes: EffectAttribute.CONVOLUTION,
|
|
28
|
+
uniforms: new Map<string, Uniform<number | number[]>>([['factor', new Uniform(factor)]]),
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const WaterEffect = /* @__PURE__ */ wrapEffect(WaterEffectImpl, {
|
|
34
|
+
blendFunction: BlendFunction.NORMAL,
|
|
35
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
export * from './Selection'
|
|
2
|
-
export * from './EffectComposer'
|
|
3
|
-
export * from './util'
|
|
4
|
-
|
|
5
|
-
export * from './effects/Autofocus'
|
|
6
|
-
export * from './effects/LensFlare'
|
|
7
|
-
export * from './effects/Bloom'
|
|
8
|
-
export * from './effects/BrightnessContrast'
|
|
9
|
-
export * from './effects/ChromaticAberration'
|
|
10
|
-
export * from './effects/ColorAverage'
|
|
11
|
-
export * from './effects/ColorDepth'
|
|
12
|
-
export * from './effects/Depth'
|
|
13
|
-
export * from './effects/DepthOfField'
|
|
14
|
-
export * from './effects/DotScreen'
|
|
15
|
-
export * from './effects/Glitch'
|
|
16
|
-
export * from './effects/GodRays'
|
|
17
|
-
export * from './effects/Grid'
|
|
18
|
-
export * from './effects/HueSaturation'
|
|
19
|
-
export * from './effects/Noise'
|
|
20
|
-
export * from './effects/Outline'
|
|
21
|
-
export * from './effects/Pixelation'
|
|
22
|
-
export * from './effects/ScanlineEffect'
|
|
23
|
-
export * from './effects/SelectiveBloom'
|
|
24
|
-
export * from './effects/Sepia'
|
|
25
|
-
export * from './effects/SSAO'
|
|
26
|
-
export * from './effects/SMAA'
|
|
27
|
-
export * from './effects/FXAA'
|
|
28
|
-
export * from './effects/Ramp'
|
|
29
|
-
export * from './effects/Texture'
|
|
30
|
-
export * from './effects/ToneMapping'
|
|
31
|
-
export * from './effects/Vignette'
|
|
32
|
-
export * from './effects/ShockWave'
|
|
33
|
-
export * from './effects/LUT'
|
|
34
|
-
export * from './effects/TiltShift'
|
|
35
|
-
export * from './effects/TiltShift2'
|
|
36
|
-
export * from './effects/ASCII'
|
|
37
|
-
export * from './effects/Water'
|
|
38
|
-
|
|
39
|
-
// These are not effect passes
|
|
40
|
-
export * from './effects/N8AO'
|
|
1
|
+
export * from './Selection'
|
|
2
|
+
export * from './EffectComposer'
|
|
3
|
+
export * from './util'
|
|
4
|
+
|
|
5
|
+
export * from './effects/Autofocus'
|
|
6
|
+
export * from './effects/LensFlare'
|
|
7
|
+
export * from './effects/Bloom'
|
|
8
|
+
export * from './effects/BrightnessContrast'
|
|
9
|
+
export * from './effects/ChromaticAberration'
|
|
10
|
+
export * from './effects/ColorAverage'
|
|
11
|
+
export * from './effects/ColorDepth'
|
|
12
|
+
export * from './effects/Depth'
|
|
13
|
+
export * from './effects/DepthOfField'
|
|
14
|
+
export * from './effects/DotScreen'
|
|
15
|
+
export * from './effects/Glitch'
|
|
16
|
+
export * from './effects/GodRays'
|
|
17
|
+
export * from './effects/Grid'
|
|
18
|
+
export * from './effects/HueSaturation'
|
|
19
|
+
export * from './effects/Noise'
|
|
20
|
+
export * from './effects/Outline'
|
|
21
|
+
export * from './effects/Pixelation'
|
|
22
|
+
export * from './effects/ScanlineEffect'
|
|
23
|
+
export * from './effects/SelectiveBloom'
|
|
24
|
+
export * from './effects/Sepia'
|
|
25
|
+
export * from './effects/SSAO'
|
|
26
|
+
export * from './effects/SMAA'
|
|
27
|
+
export * from './effects/FXAA'
|
|
28
|
+
export * from './effects/Ramp'
|
|
29
|
+
export * from './effects/Texture'
|
|
30
|
+
export * from './effects/ToneMapping'
|
|
31
|
+
export * from './effects/Vignette'
|
|
32
|
+
export * from './effects/ShockWave'
|
|
33
|
+
export * from './effects/LUT'
|
|
34
|
+
export * from './effects/TiltShift'
|
|
35
|
+
export * from './effects/TiltShift2'
|
|
36
|
+
export * from './effects/ASCII'
|
|
37
|
+
export * from './effects/Water'
|
|
38
|
+
|
|
39
|
+
// These are not effect passes
|
|
40
|
+
export * from './effects/N8AO'
|
package/src/util.tsx
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import React, { RefObject } from 'react'
|
|
2
|
-
import { Vector2 } from 'three'
|
|
3
|
-
import * as THREE from 'three'
|
|
4
|
-
import { type ReactThreeFiber, type ThreeElement, extend, useThree } from '@react-three/fiber'
|
|
5
|
-
import type { Effect, Pass, BlendFunction } from 'postprocessing'
|
|
6
|
-
|
|
7
|
-
export const resolveRef = <T,>(ref: T | React.RefObject<T>) =>
|
|
8
|
-
typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref
|
|
9
|
-
|
|
10
|
-
export type EffectConstructor = new (...args: any[]) => Effect | Pass
|
|
11
|
-
|
|
12
|
-
export type EffectProps<T extends EffectConstructor> = ThreeElement<T> &
|
|
13
|
-
ConstructorParameters<T>[0] & {
|
|
14
|
-
blendFunction?: BlendFunction
|
|
15
|
-
opacity?: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let i = 0
|
|
19
|
-
const components = new WeakMap<EffectConstructor, React.ExoticComponent<any> | string>()
|
|
20
|
-
|
|
21
|
-
export const wrapEffect = <T extends EffectConstructor>(effect: T, defaults?: EffectProps<T>) =>
|
|
22
|
-
/* @__PURE__ */ function Effect({ blendFunction = defaults?.blendFunction, opacity = defaults?.opacity, ...props }) {
|
|
23
|
-
let Component = components.get(effect)
|
|
24
|
-
if (!Component) {
|
|
25
|
-
const key = `@react-three/postprocessing/${effect.name}-${i++}`
|
|
26
|
-
extend({ [key]: effect })
|
|
27
|
-
components.set(effect, (Component = key))
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const camera = useThree((state) => state.camera)
|
|
31
|
-
const args = React.useMemo(
|
|
32
|
-
() => [...(defaults?.args ?? []), ...(props.args ?? [{ ...defaults, ...props }])],
|
|
33
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
-
[JSON.stringify(props)]
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<Component
|
|
39
|
-
camera={camera}
|
|
40
|
-
blendMode-blendFunction={blendFunction}
|
|
41
|
-
blendMode-opacity-value={opacity}
|
|
42
|
-
{...props}
|
|
43
|
-
args={args}
|
|
44
|
-
/>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const useVector2 = (props: Record<string, unknown>, key: string): THREE.Vector2 => {
|
|
49
|
-
const value = props[key] as ReactThreeFiber.Vector2 | undefined
|
|
50
|
-
return React.useMemo(() => {
|
|
51
|
-
if (typeof value === 'number') return new THREE.Vector2(value, value)
|
|
52
|
-
else if (value) return new THREE.Vector2(...(value as THREE.Vector2Tuple))
|
|
53
|
-
else return new THREE.Vector2()
|
|
54
|
-
}, [value])
|
|
55
|
-
}
|
|
1
|
+
import React, { RefObject } from 'react'
|
|
2
|
+
import { Vector2 } from 'three'
|
|
3
|
+
import * as THREE from 'three'
|
|
4
|
+
import { type ReactThreeFiber, type ThreeElement, extend, useThree } from '@react-three/fiber'
|
|
5
|
+
import type { Effect, Pass, BlendFunction } from 'postprocessing'
|
|
6
|
+
|
|
7
|
+
export const resolveRef = <T,>(ref: T | React.RefObject<T>) =>
|
|
8
|
+
typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref
|
|
9
|
+
|
|
10
|
+
export type EffectConstructor = new (...args: any[]) => Effect | Pass
|
|
11
|
+
|
|
12
|
+
export type EffectProps<T extends EffectConstructor> = ThreeElement<T> &
|
|
13
|
+
ConstructorParameters<T>[0] & {
|
|
14
|
+
blendFunction?: BlendFunction
|
|
15
|
+
opacity?: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let i = 0
|
|
19
|
+
const components = new WeakMap<EffectConstructor, React.ExoticComponent<any> | string>()
|
|
20
|
+
|
|
21
|
+
export const wrapEffect = <T extends EffectConstructor>(effect: T, defaults?: EffectProps<T>) =>
|
|
22
|
+
/* @__PURE__ */ function Effect({ blendFunction = defaults?.blendFunction, opacity = defaults?.opacity, ...props }) {
|
|
23
|
+
let Component = components.get(effect)
|
|
24
|
+
if (!Component) {
|
|
25
|
+
const key = `@react-three/postprocessing/${effect.name}-${i++}`
|
|
26
|
+
extend({ [key]: effect })
|
|
27
|
+
components.set(effect, (Component = key))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const camera = useThree((state) => state.camera)
|
|
31
|
+
const args = React.useMemo(
|
|
32
|
+
() => [...(defaults?.args ?? []), ...(props.args ?? [{ ...defaults, ...props }])],
|
|
33
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
+
[JSON.stringify(props)]
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Component
|
|
39
|
+
camera={camera}
|
|
40
|
+
blendMode-blendFunction={blendFunction}
|
|
41
|
+
blendMode-opacity-value={opacity}
|
|
42
|
+
{...props}
|
|
43
|
+
args={args}
|
|
44
|
+
/>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const useVector2 = (props: Record<string, unknown>, key: string): THREE.Vector2 => {
|
|
49
|
+
const value = props[key] as ReactThreeFiber.Vector2 | undefined
|
|
50
|
+
return React.useMemo(() => {
|
|
51
|
+
if (typeof value === 'number') return new THREE.Vector2(value, value)
|
|
52
|
+
else if (value) return new THREE.Vector2(...(value as THREE.Vector2Tuple))
|
|
53
|
+
else return new THREE.Vector2()
|
|
54
|
+
}, [value])
|
|
55
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../src/index.ts'
|