@react-three/postprocessing 3.0.3 → 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.
- package/LICENSE +21 -21
- package/README.md +81 -81
- package/dist/EffectComposer.d.ts +28 -0
- package/dist/Selection.d.ts +17 -0
- package/dist/effects/ASCII.d.ts +19 -0
- package/dist/effects/Autofocus.d.ts +23 -0
- package/dist/effects/Bloom.d.ts +2 -0
- package/dist/effects/BrightnessContrast.d.ts +2 -0
- package/dist/effects/ChromaticAberration.d.ts +8 -0
- package/dist/effects/ColorAverage.d.ts +7 -0
- package/dist/effects/ColorDepth.d.ts +2 -0
- package/dist/effects/Depth.d.ts +2 -0
- package/dist/effects/DepthOfField.d.ts +14 -0
- package/dist/effects/DotScreen.d.ts +2 -0
- package/dist/effects/FXAA.d.ts +2 -0
- package/dist/effects/Glitch.d.ts +13 -0
- package/dist/effects/GodRays.d.ts +9 -0
- package/dist/effects/Grid.d.ts +11 -0
- package/dist/effects/HueSaturation.d.ts +2 -0
- package/dist/effects/LUT.d.ts +10 -0
- package/dist/effects/LensFlare.d.ts +54 -0
- package/dist/effects/N8AO.d.ts +19 -0
- package/dist/effects/Noise.d.ts +2 -0
- package/dist/effects/Outline.d.ts +11 -0
- package/dist/effects/Pixelation.d.ts +7 -0
- package/dist/effects/Ramp.d.ts +74 -0
- package/dist/effects/SMAA.d.ts +2 -0
- package/dist/effects/SSAO.d.ts +7 -0
- package/dist/effects/ScanlineEffect.d.ts +2 -0
- package/dist/effects/SelectiveBloom.d.ts +15 -0
- package/dist/effects/Sepia.d.ts +2 -0
- package/dist/effects/ShockWave.d.ts +2 -0
- package/dist/effects/Texture.d.ts +10 -0
- package/dist/effects/TiltShift.d.ts +2 -0
- package/dist/effects/TiltShift2.d.ts +18 -0
- package/dist/effects/ToneMapping.d.ts +4 -0
- package/dist/effects/Vignette.d.ts +2 -0
- package/dist/effects/Water.d.ts +8 -0
- package/dist/index.d.ts +38 -1
- package/dist/index.js +855 -551
- package/dist/index.js.map +1 -1
- package/dist/tests/test-utils.d.ts +12 -0
- package/dist/util.d.ts +25 -0
- package/dist/wrapEffect.d.ts +12 -0
- package/package.json +73 -66
- package/src/EffectComposer.tsx +278 -200
- package/src/Selection.tsx +86 -46
- package/src/effects/ASCII.tsx +136 -135
- package/src/effects/Autofocus.tsx +175 -153
- package/src/effects/Bloom.tsx +6 -6
- package/src/effects/BrightnessContrast.tsx +4 -4
- package/src/effects/ChromaticAberration.tsx +30 -5
- package/src/effects/ColorAverage.tsx +17 -15
- package/src/effects/ColorDepth.tsx +4 -4
- package/src/effects/Depth.tsx +4 -4
- package/src/effects/DepthOfField.tsx +87 -89
- package/src/effects/DotScreen.tsx +4 -4
- package/src/effects/FXAA.tsx +4 -4
- package/src/effects/Glitch.tsx +37 -40
- package/src/effects/GodRays.tsx +20 -16
- package/src/effects/Grid.tsx +28 -21
- package/src/effects/HueSaturation.tsx +4 -4
- package/src/effects/LUT.tsx +27 -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 +85 -117
- package/src/effects/Pixelation.tsx +17 -15
- package/src/effects/Ramp.tsx +150 -150
- package/src/effects/SMAA.tsx +4 -4
- package/src/effects/SSAO.tsx +44 -41
- package/src/effects/ScanlineEffect.tsx +7 -7
- package/src/effects/SelectiveBloom.tsx +116 -126
- package/src/effects/Sepia.tsx +4 -4
- package/src/effects/ShockWave.tsx +4 -4
- package/src/effects/Texture.tsx +27 -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 +41 -40
- package/src/tests/ChromaticAberration.test.tsx +31 -0
- package/src/tests/EffectComposer.test.tsx +911 -0
- package/src/tests/Outline.test.tsx +89 -0
- package/src/tests/Selection.test.tsx +324 -0
- package/src/tests/SelectiveBloom.test.tsx +118 -0
- package/src/tests/effects.smoke.test.tsx +234 -0
- package/src/tests/test-utils.tsx +96 -0
- package/src/tests/wrapEffect.test.tsx +209 -0
- package/src/util.tsx +96 -55
- package/src/wrapEffect.tsx +122 -0
- package/src/EffectComposer.test.tsx +0 -126
package/src/effects/Ramp.tsx
CHANGED
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { wrapEffect } from '../
|
|
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 { Effect } from 'postprocessing'
|
|
2
|
+
import { Uniform } from 'three'
|
|
3
|
+
import { wrapEffect } from '../wrapEffect'
|
|
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)
|
package/src/effects/SMAA.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SMAAEffect } from 'postprocessing'
|
|
2
|
-
import { wrapEffect } from '../
|
|
3
|
-
|
|
4
|
-
export const SMAA = /* @__PURE__ */ wrapEffect(SMAAEffect)
|
|
1
|
+
import { SMAAEffect } from 'postprocessing'
|
|
2
|
+
import { wrapEffect } from '../wrapEffect'
|
|
3
|
+
|
|
4
|
+
export const SMAA = /* @__PURE__ */ wrapEffect(SMAAEffect)
|
package/src/effects/SSAO.tsx
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { EffectComposerContext } from '../EffectComposer'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
41
|
-
|
|
1
|
+
import { BlendFunction, SSAOEffect } from 'postprocessing'
|
|
2
|
+
import { Ref, useContext, useMemo } from 'react'
|
|
3
|
+
import { EffectComposerContext } from '../EffectComposer'
|
|
4
|
+
import { useDispose } from '../util'
|
|
5
|
+
|
|
6
|
+
// first two args are camera and texture
|
|
7
|
+
type SSAOProps = ConstructorParameters<typeof SSAOEffect>[2] & { ref?: Ref<SSAOEffect> }
|
|
8
|
+
|
|
9
|
+
export function SSAO({ ref, ...props }: SSAOProps) {
|
|
10
|
+
const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext)
|
|
11
|
+
|
|
12
|
+
const effect = useMemo<SSAOEffect | {}>(() => {
|
|
13
|
+
if (normalPass === null && downSamplingPass === null) {
|
|
14
|
+
console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.')
|
|
15
|
+
return {}
|
|
16
|
+
}
|
|
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
|
+
|
|
41
|
+
useDispose(effect)
|
|
42
|
+
|
|
43
|
+
return <primitive ref={ref} object={effect} />
|
|
44
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { wrapEffect } from '../
|
|
3
|
-
|
|
4
|
-
export const Scanline = /* @__PURE__ */ wrapEffect(ScanlineEffect, {
|
|
5
|
-
blendFunction: BlendFunction.OVERLAY,
|
|
6
|
-
density: 1.25,
|
|
7
|
-
})
|
|
1
|
+
import { BlendFunction, ScanlineEffect } from 'postprocessing'
|
|
2
|
+
import { wrapEffect } from '../wrapEffect'
|
|
3
|
+
|
|
4
|
+
export const Scanline = /* @__PURE__ */ wrapEffect(ScanlineEffect, {
|
|
5
|
+
blendFunction: BlendFunction.OVERLAY,
|
|
6
|
+
density: 1.25,
|
|
7
|
+
})
|
|
@@ -1,126 +1,116 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { BloomEffectOptions } from 'postprocessing'
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { EffectComposerContext } from '../EffectComposer'
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
intensity,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
kernelSize,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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 { useThree } from '@react-three/fiber'
|
|
2
|
+
import type { BloomEffectOptions } from 'postprocessing'
|
|
3
|
+
import { BlendFunction, SelectiveBloomEffect } from 'postprocessing'
|
|
4
|
+
import { Ref, RefObject, use, useEffect, useMemo } from 'react'
|
|
5
|
+
import { Object3D } from 'three'
|
|
6
|
+
import { EffectComposerContext } from '../EffectComposer'
|
|
7
|
+
import { EMPTY_ARRAY, resolveRef, useDispose, useSelectionSync } from '../util'
|
|
8
|
+
|
|
9
|
+
type ObjectRef = RefObject<Object3D | null>
|
|
10
|
+
|
|
11
|
+
export type SelectiveBloomProps = BloomEffectOptions &
|
|
12
|
+
Partial<{
|
|
13
|
+
lights: Object3D[] | ObjectRef[]
|
|
14
|
+
selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
|
|
15
|
+
selectionLayer: number
|
|
16
|
+
inverted: boolean
|
|
17
|
+
ignoreBackground: boolean
|
|
18
|
+
ref?: Ref<SelectiveBloomEffect>
|
|
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 function SelectiveBloom({
|
|
25
|
+
selection = EMPTY_ARRAY,
|
|
26
|
+
selectionLayer = 10,
|
|
27
|
+
lights = EMPTY_ARRAY,
|
|
28
|
+
inverted = false,
|
|
29
|
+
ignoreBackground = false,
|
|
30
|
+
luminanceThreshold,
|
|
31
|
+
luminanceSmoothing,
|
|
32
|
+
mipmapBlur,
|
|
33
|
+
intensity,
|
|
34
|
+
radius,
|
|
35
|
+
levels,
|
|
36
|
+
kernelSize,
|
|
37
|
+
resolutionScale,
|
|
38
|
+
width,
|
|
39
|
+
height,
|
|
40
|
+
resolutionX,
|
|
41
|
+
resolutionY,
|
|
42
|
+
ref,
|
|
43
|
+
}: SelectiveBloomProps) {
|
|
44
|
+
const { scene, camera } = use(EffectComposerContext)
|
|
45
|
+
|
|
46
|
+
const invalidate = useThree((state) => state.invalidate)
|
|
47
|
+
|
|
48
|
+
const effect = useMemo(() => {
|
|
49
|
+
const instance = new SelectiveBloomEffect(scene, camera, {
|
|
50
|
+
blendFunction: BlendFunction.ADD,
|
|
51
|
+
luminanceThreshold,
|
|
52
|
+
luminanceSmoothing,
|
|
53
|
+
mipmapBlur,
|
|
54
|
+
intensity,
|
|
55
|
+
radius,
|
|
56
|
+
levels,
|
|
57
|
+
kernelSize,
|
|
58
|
+
resolutionScale,
|
|
59
|
+
width,
|
|
60
|
+
height,
|
|
61
|
+
resolutionX,
|
|
62
|
+
resolutionY,
|
|
63
|
+
})
|
|
64
|
+
instance.inverted = inverted
|
|
65
|
+
instance.ignoreBackground = ignoreBackground
|
|
66
|
+
return instance
|
|
67
|
+
}, [
|
|
68
|
+
scene,
|
|
69
|
+
camera,
|
|
70
|
+
luminanceThreshold,
|
|
71
|
+
luminanceSmoothing,
|
|
72
|
+
mipmapBlur,
|
|
73
|
+
intensity,
|
|
74
|
+
radius,
|
|
75
|
+
levels,
|
|
76
|
+
kernelSize,
|
|
77
|
+
resolutionScale,
|
|
78
|
+
width,
|
|
79
|
+
height,
|
|
80
|
+
resolutionX,
|
|
81
|
+
resolutionY,
|
|
82
|
+
inverted,
|
|
83
|
+
ignoreBackground,
|
|
84
|
+
])
|
|
85
|
+
|
|
86
|
+
// Must run before the lights effect below: addLight/removeLight read
|
|
87
|
+
// effect.selection.layer live, so it needs to already reflect the
|
|
88
|
+
// latest selectionLayer by the time lights get (re-)assigned to it.
|
|
89
|
+
useSelectionSync(effect, selection, selectionLayer)
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (lights.length === 0) {
|
|
93
|
+
console.warn('SelectiveBloom requires lights to work.')
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Refs may not have attached yet - resolve and drop nullish entries
|
|
98
|
+
// rather than crashing addLight/removeLight on a null object.
|
|
99
|
+
const resolvedLights = lights.map((light) => resolveRef(light)).filter((light): light is Object3D => light != null)
|
|
100
|
+
if (resolvedLights.length === 0) return
|
|
101
|
+
|
|
102
|
+
resolvedLights.forEach((light) => addLight(light, effect))
|
|
103
|
+
|
|
104
|
+
invalidate()
|
|
105
|
+
|
|
106
|
+
return () => {
|
|
107
|
+
resolvedLights.forEach((light) => removeLight(light, effect))
|
|
108
|
+
|
|
109
|
+
invalidate()
|
|
110
|
+
}
|
|
111
|
+
}, [effect, invalidate, lights, selectionLayer])
|
|
112
|
+
|
|
113
|
+
useDispose(effect)
|
|
114
|
+
|
|
115
|
+
return <primitive ref={ref} object={effect} />
|
|
116
|
+
}
|
package/src/effects/Sepia.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SepiaEffect } from 'postprocessing'
|
|
2
|
-
import { wrapEffect } from '../
|
|
3
|
-
|
|
4
|
-
export const Sepia = /* @__PURE__ */ wrapEffect(SepiaEffect)
|
|
1
|
+
import { SepiaEffect } from 'postprocessing'
|
|
2
|
+
import { wrapEffect } from '../wrapEffect'
|
|
3
|
+
|
|
4
|
+
export const Sepia = /* @__PURE__ */ wrapEffect(SepiaEffect)
|