@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/Noise.tsx
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { BlendFunction, NoiseEffect } from 'postprocessing'
|
|
2
|
+
import type { Ref } from 'react'
|
|
3
|
+
import { createEffectComponent, type EffectOptions } from '../createEffectComponent'
|
|
4
|
+
|
|
5
|
+
const NoiseImpl = /* @__PURE__ */ createEffectComponent<typeof NoiseEffect, EffectOptions<typeof NoiseEffect>>(
|
|
6
|
+
NoiseEffect
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
export type NoiseProps = EffectOptions<typeof NoiseEffect> & {
|
|
10
|
+
opacity?: number
|
|
11
|
+
ref?: Ref<NoiseEffect>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function Noise({ blendFunction = BlendFunction.COLOR_DODGE, ...props }: NoiseProps) {
|
|
15
|
+
return <NoiseImpl blendFunction={blendFunction} {...props} />
|
|
16
|
+
}
|
package/src/effects/Outline.tsx
CHANGED
|
@@ -1,117 +1,84 @@
|
|
|
1
|
-
import { OutlineEffect } from 'postprocessing'
|
|
2
|
-
import { Ref, RefObject,
|
|
3
|
-
import { Object3D } from 'three'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
export type OutlineProps =
|
|
12
|
-
Partial<{
|
|
13
|
-
selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
|
|
14
|
-
selectionLayer: number
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
effect.selection.clear()
|
|
86
|
-
invalidate()
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}, [effect, selection, api, invalidate])
|
|
90
|
-
|
|
91
|
-
useEffect(() => {
|
|
92
|
-
effect.selectionLayer = selectionLayer
|
|
93
|
-
invalidate()
|
|
94
|
-
}, [effect, invalidate, selectionLayer])
|
|
95
|
-
|
|
96
|
-
const ref = useRef<OutlineEffect>(undefined)
|
|
97
|
-
useEffect(() => {
|
|
98
|
-
if (api && api.enabled) {
|
|
99
|
-
if (api.selected?.length) {
|
|
100
|
-
effect.selection.set(api.selected)
|
|
101
|
-
invalidate()
|
|
102
|
-
return () => {
|
|
103
|
-
effect.selection.clear()
|
|
104
|
-
invalidate()
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, [api, effect.selection, invalidate])
|
|
109
|
-
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
return () => {
|
|
112
|
-
effect.dispose()
|
|
113
|
-
}
|
|
114
|
-
}, [effect])
|
|
115
|
-
|
|
116
|
-
return <primitive ref={forwardRef} object={effect} />
|
|
117
|
-
})
|
|
1
|
+
import { OutlineEffect } from 'postprocessing'
|
|
2
|
+
import { Ref, RefObject, use, useEffect, useMemo } from 'react'
|
|
3
|
+
import { Color, Object3D, type ColorRepresentation } from 'three'
|
|
4
|
+
import { EffectComposerContext } from '../EffectComposer'
|
|
5
|
+
import { applyPierced, EMPTY_ARRAY, readPierced, useDispose, useLiveDefaults, useSelectionSync } from '../util'
|
|
6
|
+
|
|
7
|
+
type ObjectRef = RefObject<Object3D | null>
|
|
8
|
+
|
|
9
|
+
type OutlineEffectOptions = NonNullable<ConstructorParameters<typeof OutlineEffect>[2]>
|
|
10
|
+
|
|
11
|
+
export type OutlineProps = Omit<OutlineEffectOptions, 'visibleEdgeColor' | 'hiddenEdgeColor'> &
|
|
12
|
+
Partial<{
|
|
13
|
+
selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
|
|
14
|
+
selectionLayer: number
|
|
15
|
+
visibleEdgeColor: ColorRepresentation
|
|
16
|
+
hiddenEdgeColor: ColorRepresentation
|
|
17
|
+
ref?: Ref<OutlineEffect>
|
|
18
|
+
}>
|
|
19
|
+
|
|
20
|
+
// Every OutlineEffect option that has a real setter (verified against
|
|
21
|
+
// postprocessing's source) - resolutionScale/resolutionX/resolutionY are
|
|
22
|
+
// the only ones without one, since they only feed the internal blur pass
|
|
23
|
+
// at construction time. scene/camera are required constructor args, so
|
|
24
|
+
// OutlineEffect can't use createEffectComponent (needs `new Effect()` to
|
|
25
|
+
// work with zero args) - built by hand instead.
|
|
26
|
+
const LIVE_KEYS = [
|
|
27
|
+
'patternTexture',
|
|
28
|
+
'patternScale',
|
|
29
|
+
'edgeStrength',
|
|
30
|
+
'pulseSpeed',
|
|
31
|
+
'visibleEdgeColor',
|
|
32
|
+
'hiddenEdgeColor',
|
|
33
|
+
'multisampling',
|
|
34
|
+
'width',
|
|
35
|
+
'height',
|
|
36
|
+
'kernelSize',
|
|
37
|
+
'blur',
|
|
38
|
+
'xRay',
|
|
39
|
+
'dithering',
|
|
40
|
+
'blendMode-blendFunction',
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
// The setter stores whatever it's given as-is, unlike the constructor -
|
|
44
|
+
// wrap in a Color here too, or a raw hex/string breaks the shader uniform.
|
|
45
|
+
function set(effect: OutlineEffect, key: string, value: unknown): void {
|
|
46
|
+
if (key === 'visibleEdgeColor' || key === 'hiddenEdgeColor') applyPierced(effect, key, new Color(value as never))
|
|
47
|
+
else applyPierced(effect, key, value)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function Outline({
|
|
51
|
+
selection = EMPTY_ARRAY,
|
|
52
|
+
selectionLayer = 10,
|
|
53
|
+
blendFunction,
|
|
54
|
+
resolutionScale,
|
|
55
|
+
resolutionX,
|
|
56
|
+
resolutionY,
|
|
57
|
+
ref,
|
|
58
|
+
...liveProps
|
|
59
|
+
}: OutlineProps) {
|
|
60
|
+
const { scene, camera, autoClear } = use(EffectComposerContext)
|
|
61
|
+
|
|
62
|
+
const effect = useMemo(
|
|
63
|
+
() => new OutlineEffect(scene, camera, { resolutionScale, resolutionX, resolutionY }),
|
|
64
|
+
[scene, camera, resolutionScale, resolutionX, resolutionY]
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (autoClear !== false) {
|
|
69
|
+
console.warn('Outline requires <EffectComposer autoClear={false}> to render correctly.')
|
|
70
|
+
}
|
|
71
|
+
}, [autoClear])
|
|
72
|
+
|
|
73
|
+
useLiveDefaults(
|
|
74
|
+
effect,
|
|
75
|
+
{ ...liveProps, 'blendMode-blendFunction': blendFunction } as Record<string, unknown>,
|
|
76
|
+
LIVE_KEYS,
|
|
77
|
+
readPierced,
|
|
78
|
+
set
|
|
79
|
+
)
|
|
80
|
+
useSelectionSync(effect, selection, selectionLayer)
|
|
81
|
+
useDispose(effect)
|
|
82
|
+
|
|
83
|
+
return <primitive ref={ref} object={effect} />
|
|
84
|
+
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { PixelationEffect } from 'postprocessing'
|
|
2
|
+
import type { Ref } from 'react'
|
|
3
|
+
import { createEffectComponent } from '../createEffectComponent'
|
|
4
|
+
|
|
5
|
+
// PixelationEffect's sole constructor arg is a bare number, not an options
|
|
6
|
+
// object - granularity is a real live setter though, so it's just a normal
|
|
7
|
+
// prop; only the curated default (5, vs the class's own default of 30)
|
|
8
|
+
// needs a thin wrapper.
|
|
9
|
+
const PixelationImpl = /* @__PURE__ */ createEffectComponent<typeof PixelationEffect, { granularity?: number }>(
|
|
10
|
+
PixelationEffect
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
export type PixelationProps = {
|
|
14
|
+
granularity?: number
|
|
15
|
+
ref?: Ref<PixelationEffect>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Pixelation({ granularity = 5, ref }: PixelationProps) {
|
|
19
|
+
return <PixelationImpl granularity={granularity} ref={ref} />
|
|
20
|
+
}
|
package/src/effects/Ramp.tsx
CHANGED
|
@@ -1,150 +1,239 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
uniform vec2
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
uniform vec4
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
uniform float
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
uniform bool
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
vec2
|
|
35
|
-
vec2
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
vec2
|
|
42
|
-
vec2
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
float
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
118
|
-
*
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
*
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
['
|
|
141
|
-
['
|
|
142
|
-
['
|
|
143
|
-
['
|
|
144
|
-
['
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
1
|
+
import { BlendFunction, Effect } from 'postprocessing'
|
|
2
|
+
import type { Ref } from 'react'
|
|
3
|
+
import { Uniform } from 'three'
|
|
4
|
+
import { createEffectComponent } from '../createEffectComponent'
|
|
5
|
+
|
|
6
|
+
const RampShader = {
|
|
7
|
+
fragmentShader: /* glsl */ `
|
|
8
|
+
uniform int rampType;
|
|
9
|
+
|
|
10
|
+
uniform vec2 rampStart;
|
|
11
|
+
uniform vec2 rampEnd;
|
|
12
|
+
|
|
13
|
+
uniform vec4 startColor;
|
|
14
|
+
uniform vec4 endColor;
|
|
15
|
+
|
|
16
|
+
uniform float rampBias;
|
|
17
|
+
uniform float rampGain;
|
|
18
|
+
|
|
19
|
+
uniform bool rampMask;
|
|
20
|
+
uniform bool rampInvert;
|
|
21
|
+
|
|
22
|
+
float getBias(float time, float bias) {
|
|
23
|
+
return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
float getGain(float time, float gain) {
|
|
27
|
+
if (time < 0.5)
|
|
28
|
+
return getBias(time * 2.0, gain) / 2.0;
|
|
29
|
+
else
|
|
30
|
+
return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
34
|
+
vec2 centerPixel = uv * resolution;
|
|
35
|
+
vec2 startPixel = rampStart * resolution;
|
|
36
|
+
vec2 endPixel = rampEnd * resolution;
|
|
37
|
+
|
|
38
|
+
float rampAlpha;
|
|
39
|
+
|
|
40
|
+
if (rampType == 1) {
|
|
41
|
+
vec2 fuv = centerPixel / resolution.y;
|
|
42
|
+
vec2 suv = startPixel / resolution.y;
|
|
43
|
+
vec2 euv = endPixel / resolution.y;
|
|
44
|
+
|
|
45
|
+
float radius = length(suv - euv);
|
|
46
|
+
float falloff = length(fuv - suv);
|
|
47
|
+
rampAlpha = smoothstep(0.0, radius, falloff);
|
|
48
|
+
} else {
|
|
49
|
+
float radius = length(startPixel - endPixel);
|
|
50
|
+
vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));
|
|
51
|
+
|
|
52
|
+
float fade = dot(centerPixel - startPixel, direction);
|
|
53
|
+
if (rampType == 2) fade = abs(fade);
|
|
54
|
+
|
|
55
|
+
rampAlpha = smoothstep(0.0, 1.0, fade / radius);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));
|
|
59
|
+
|
|
60
|
+
if (rampMask) {
|
|
61
|
+
vec4 inputBuff = texture2D(inputBuffer, uv);
|
|
62
|
+
outputColor = mix(inputBuff, inputColor, rampAlpha);
|
|
63
|
+
} else {
|
|
64
|
+
outputColor = mix(startColor, endColor, rampAlpha);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export enum RampType {
|
|
71
|
+
Linear,
|
|
72
|
+
Radial,
|
|
73
|
+
MirroredLinear,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type RampTuple2 = [number, number]
|
|
77
|
+
type RampTuple4 = [number, number, number, number]
|
|
78
|
+
|
|
79
|
+
export class RampEffect extends Effect {
|
|
80
|
+
constructor({
|
|
81
|
+
/**
|
|
82
|
+
* Type of ramp gradient.
|
|
83
|
+
*/
|
|
84
|
+
rampType = RampType.Linear,
|
|
85
|
+
/**
|
|
86
|
+
* Starting point of the ramp gradient in normalized coordinates.
|
|
87
|
+
*
|
|
88
|
+
* Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.
|
|
89
|
+
*/
|
|
90
|
+
rampStart = [0.5, 0.5] as RampTuple2,
|
|
91
|
+
/**
|
|
92
|
+
* Ending point of the ramp gradient in normalized coordinates.
|
|
93
|
+
*
|
|
94
|
+
* Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`
|
|
95
|
+
*/
|
|
96
|
+
rampEnd = [1, 1] as RampTuple2,
|
|
97
|
+
/**
|
|
98
|
+
* Color at the starting point of the gradient.
|
|
99
|
+
*
|
|
100
|
+
* Default is black: `[0, 0, 0, 1]`
|
|
101
|
+
*/
|
|
102
|
+
startColor = [0, 0, 0, 1] as RampTuple4,
|
|
103
|
+
/**
|
|
104
|
+
* Color at the ending point of the gradient.
|
|
105
|
+
*
|
|
106
|
+
* Default is white: `[1, 1, 1, 1]`
|
|
107
|
+
*/
|
|
108
|
+
endColor = [1, 1, 1, 1] as RampTuple4,
|
|
109
|
+
/**
|
|
110
|
+
* Bias for the interpolation curve when both bias and gain are 0.5.
|
|
111
|
+
*
|
|
112
|
+
* Ranges from `[0 - 1]`. Default is `0.5`.
|
|
113
|
+
*/
|
|
114
|
+
rampBias = 0.5,
|
|
115
|
+
/**
|
|
116
|
+
* Gain for the interpolation curve when both bias and gain are 0.5.
|
|
117
|
+
*
|
|
118
|
+
* Ranges from `[0 - 1]`. Default is `0.5`.
|
|
119
|
+
*/
|
|
120
|
+
rampGain = 0.5,
|
|
121
|
+
/**
|
|
122
|
+
* When enabled, the ramp gradient is used as an effect mask, and colors are ignored.
|
|
123
|
+
*
|
|
124
|
+
* Default is `false`.
|
|
125
|
+
*/
|
|
126
|
+
rampMask = false,
|
|
127
|
+
/**
|
|
128
|
+
* Controls whether the ramp gradient is inverted.
|
|
129
|
+
*
|
|
130
|
+
* When disabled, rampStart is transparent and rampEnd is opaque.
|
|
131
|
+
*
|
|
132
|
+
* Default is `false`.
|
|
133
|
+
*/
|
|
134
|
+
rampInvert = false,
|
|
135
|
+
...params
|
|
136
|
+
} = {}) {
|
|
137
|
+
super('RampEffect', RampShader.fragmentShader, {
|
|
138
|
+
...params,
|
|
139
|
+
uniforms: new Map<string, Uniform>([
|
|
140
|
+
['rampType', new Uniform(rampType)],
|
|
141
|
+
['rampStart', new Uniform(rampStart)],
|
|
142
|
+
['rampEnd', new Uniform(rampEnd)],
|
|
143
|
+
['startColor', new Uniform(startColor)],
|
|
144
|
+
['endColor', new Uniform(endColor)],
|
|
145
|
+
['rampBias', new Uniform(rampBias)],
|
|
146
|
+
['rampGain', new Uniform(rampGain)],
|
|
147
|
+
['rampMask', new Uniform(rampMask)],
|
|
148
|
+
['rampInvert', new Uniform(rampInvert)],
|
|
149
|
+
]),
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private u<T>(name: string): T {
|
|
154
|
+
return this.uniforms.get(name)!.value
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private setU(name: string, value: unknown): void {
|
|
158
|
+
this.uniforms.get(name)!.value = value
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get rampType(): RampType {
|
|
162
|
+
return this.u('rampType')
|
|
163
|
+
}
|
|
164
|
+
set rampType(value: RampType) {
|
|
165
|
+
this.setU('rampType', value)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
get rampStart(): RampTuple2 {
|
|
169
|
+
return this.u('rampStart')
|
|
170
|
+
}
|
|
171
|
+
set rampStart(value: RampTuple2) {
|
|
172
|
+
this.setU('rampStart', value)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
get rampEnd(): RampTuple2 {
|
|
176
|
+
return this.u('rampEnd')
|
|
177
|
+
}
|
|
178
|
+
set rampEnd(value: RampTuple2) {
|
|
179
|
+
this.setU('rampEnd', value)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
get startColor(): RampTuple4 {
|
|
183
|
+
return this.u('startColor')
|
|
184
|
+
}
|
|
185
|
+
set startColor(value: RampTuple4) {
|
|
186
|
+
this.setU('startColor', value)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
get endColor(): RampTuple4 {
|
|
190
|
+
return this.u('endColor')
|
|
191
|
+
}
|
|
192
|
+
set endColor(value: RampTuple4) {
|
|
193
|
+
this.setU('endColor', value)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
get rampBias(): number {
|
|
197
|
+
return this.u('rampBias')
|
|
198
|
+
}
|
|
199
|
+
set rampBias(value: number) {
|
|
200
|
+
this.setU('rampBias', value)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
get rampGain(): number {
|
|
204
|
+
return this.u('rampGain')
|
|
205
|
+
}
|
|
206
|
+
set rampGain(value: number) {
|
|
207
|
+
this.setU('rampGain', value)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
get rampMask(): boolean {
|
|
211
|
+
return this.u('rampMask')
|
|
212
|
+
}
|
|
213
|
+
set rampMask(value: boolean) {
|
|
214
|
+
this.setU('rampMask', value)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
get rampInvert(): boolean {
|
|
218
|
+
return this.u('rampInvert')
|
|
219
|
+
}
|
|
220
|
+
set rampInvert(value: boolean) {
|
|
221
|
+
this.setU('rampInvert', value)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export type RampProps = {
|
|
226
|
+
blendFunction?: BlendFunction
|
|
227
|
+
rampType?: RampType
|
|
228
|
+
rampStart?: RampTuple2
|
|
229
|
+
rampEnd?: RampTuple2
|
|
230
|
+
startColor?: RampTuple4
|
|
231
|
+
endColor?: RampTuple4
|
|
232
|
+
rampBias?: number
|
|
233
|
+
rampGain?: number
|
|
234
|
+
rampMask?: boolean
|
|
235
|
+
rampInvert?: boolean
|
|
236
|
+
ref?: Ref<RampEffect>
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export const Ramp = /* @__PURE__ */ createEffectComponent<typeof RampEffect, RampProps>(RampEffect)
|