-
Notifications
You must be signed in to change notification settings - Fork 28
/
ChromaticAberrationPlugin.ts
61 lines (51 loc) · 2.06 KB
/
ChromaticAberrationPlugin.ts
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
61
import {uiFolderContainer, uiSlider, uiToggle} from 'uiconfig.js'
import {glsl, onChange, serialize} from 'ts-browser-helpers'
import {uniform} from '../../three'
import ChromaticAberration from './shaders/ChromaticAberrationPlugin.glsl'
import {AScreenPassExtensionPlugin} from './AScreenPassExtensionPlugin'
/**
* Chromatic Aberration Plugin
* Adds an extension to {@link ScreenPass} material
* for applying chromatic aberration effect on the final buffer before rendering to screen.
* The intensity of the aberration can be controlled with the `intensity`(previously aberrationIntensity) property.
*
* @category Plugins
*/
@uiFolderContainer('ChromaticAberration')
export class ChromaticAberrationPlugin extends AScreenPassExtensionPlugin<''> {
static readonly PluginType = 'ChromaticAberration'
readonly extraUniforms = {
aberrationIntensity: {value: 1},
} as const
@onChange(ChromaticAberrationPlugin.prototype.setDirty)
@uiToggle('Enable')
@serialize() enabled: boolean
@uiSlider('Intensity', [0., 0.3], 0.001)
@uniform({propKey: 'aberrationIntensity'})
@serialize('aberrationIntensity') intensity = 0.5
/**
* The priority of the material extension when applied to the material in ScreenPass
* set to very low priority, so applied at the end
*/
priority = -50
parsFragmentSnippet = () => {
if (this.isDisabled()) return ''
return glsl`
uniform float aberrationIntensity;
${ChromaticAberration}
`
}
protected _shaderPatch = 'diffuseColor = ChromaticAberration(diffuseColor);'
get aberrationIntensity() {
console.warn('ChromaticAberrationPlugin.aberrationIntensity is deprecated, use ChromaticAberrationPlugin.intensity instead')
return this.intensity
}
set aberrationIntensity(v) {
console.warn('ChromaticAberrationPlugin.aberrationIntensity is deprecated, use ChromaticAberrationPlugin.intensity instead')
this.intensity = v
}
constructor(enabled = true) {
super()
this.enabled = enabled
}
}