-
Notifications
You must be signed in to change notification settings - Fork 8
/
lightness.js
41 lines (32 loc) · 1.2 KB
/
lightness.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('Lightness')
this.allocation = ['Texture'];
}
builder(node) {
super.builder(node);
const inp = new Input('image', 'Image', sockets.image);
const inp2 = new Input('scalar', 'Scalar', sockets.num);
inp2.addControl(new FieldControl(this.editor, 'scalar', {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 scalar = typeof inputs['scalar'][0] === 'number'
? inputs['scalar'][0]
: node.data.scalar;
const result = Utils.createMockCanvas();
result.blend(texture, scalar, 'a+b');
outputs['image'] = result.toTexture();
this.updatePreview(node, outputs['image']);
}
}