-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
LensDirtEffect.tsx
60 lines (55 loc) · 1.41 KB
/
LensDirtEffect.tsx
1
2
3
4
5
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
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
import { pipe } from "fp-ts/function"
import * as PP from "postprocessing"
import {
Input,
Luminance,
Mul,
Smoothstep,
Texture2D,
UniformUnit
} from "shader-composer"
import {
InputColor,
PostProcessingEffectMaster,
ShaderComposerEffect,
UV
} from "shader-composer-postprocessing"
import { Texture } from "three"
import { usePostProcessingEffect } from "../lib/usePostProcessingEffect"
export type LensDirtEffectProps = ConstructorParameters<
typeof LensDirtEffectImpl
>[0]
export const LensDirtEffect = (props: LensDirtEffectProps) => {
usePostProcessingEffect(() => new LensDirtEffectImpl(props), props)
return null
}
export type LensDirtEffectArgs = {
texture: Texture
blendFunction?: PP.BlendFunction
minLuminance?: Input<"float">
maxLuminance?: Input<"float">
strength?: Input<"float">
}
export class LensDirtEffectImpl extends ShaderComposerEffect {
constructor({
texture,
blendFunction = PP.BlendFunction.ADD,
minLuminance = 0.1,
maxLuminance = 0.3,
strength = 1
}: LensDirtEffectArgs) {
const u_texture = UniformUnit("sampler2D", texture)
super({
blendFunction,
root: PostProcessingEffectMaster({
color: pipe(
InputColor,
(v) => Luminance(v),
(v) => Smoothstep(minLuminance, maxLuminance, v),
(v) => Mul(v, strength),
(v) => Mul(Texture2D(u_texture, UV).color, v)
)
})
})
}
}