-
Notifications
You must be signed in to change notification settings - Fork 28
/
FilmicGrainPlugin.ts
68 lines (57 loc) · 2.17 KB
/
FilmicGrainPlugin.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
62
63
64
65
66
67
68
import {uiFolderContainer, uiSlider, uiToggle} from 'uiconfig.js'
import {glsl, onChange, serialize} from 'ts-browser-helpers'
import {uniform} from '../../three'
import FilmicGrain from './shaders/FilmicGrainPlugin.glsl'
import {AScreenPassExtensionPlugin} from './AScreenPassExtensionPlugin'
/**
* Filmic Grain Plugin
* Adds an extension to {@link ScreenPass} material
* for applying filmic grain effect on the final buffer before rendering to screen.
* The intensity of the grain can be controlled with the `intensity` property
* and the `multiply` property can be used to multiply the grain effect on the image instead of adding.
*
* @category Plugins
*/
@uiFolderContainer('FilmicGrain')
export class FilmicGrainPlugin extends AScreenPassExtensionPlugin<''> {
static readonly PluginType = 'FilmicGrain'
readonly extraUniforms = {
grainIntensity: {value: 1},
grainMultiply: {value: false},
} as const
@onChange(FilmicGrainPlugin.prototype.setDirty)
@uiToggle('Enable')
@serialize() enabled: boolean
@uiSlider('Intensity', [0., 20], 0.01)
@uniform({propKey: 'grainIntensity'})
@serialize('grainIntensity') intensity = 10
@uiToggle('Multiply')
@uniform({propKey: 'grainMultiply'})
@serialize('grainMultiply') multiply = false
/**
* 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 grainIntensity;
uniform bool grainMultiply;
${FilmicGrain}
`
}
protected _shaderPatch = 'diffuseColor = FilmicGrain(diffuseColor);'
get grainIntensity() {
console.warn('FilmicGrainPlugin.grainIntensity is deprecated, use FilmicGrainPlugin.intensity instead')
return this.intensity
}
set grainIntensity(v) {
console.warn('FilmicGrainPlugin.grainIntensity is deprecated, use FilmicGrainPlugin.intensity instead')
this.intensity = v
}
constructor(enabled = true) {
super()
this.enabled = enabled
}
}