-
Notifications
You must be signed in to change notification settings - Fork 8
/
blur.js
41 lines (32 loc) · 1.19 KB
/
blur.js
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
import { Input } from 'rete';
import FieldControl from '../../controls/field';
import TextureComponent from '../../common/components/texture';
import Utils from '../../utils';
import sockets from '../../sockets';
export default class extends TextureComponent {
constructor() {
super('Blur')
this.allocation = ['Texture'];
}
builder(node) {
super.builder(node);
const inp = new Input('image', 'Image', sockets.image);
const inp2 = new Input('radius', 'Radius', sockets.image);
inp2.addControl(new FieldControl(this.editor, 'radius', {type: 'number', value: 1}));
return node
.addInput(inp)
.addInput(inp2);
}
async worker(node, inputs, outputs) {
const texture = inputs['image'][0]instanceof WebGLTexture
? inputs['image'][0]
: Utils.createMockTexture();
const radius = typeof inputs['radius'][0] === 'number'
? inputs['radius'][0]
: node.data.radius;
const result = Utils.createMockCanvas();
result.blur(texture, radius);
outputs['image'] = result.toTexture();
this.updatePreview(node, outputs['image']);
}
}