-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrush.ts
69 lines (60 loc) · 1.67 KB
/
brush.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
69
import { vec3 } from 'gl-matrix';
import { srgbToRgb } from './color';
import { fillTexture } from './compositor';
const DEFAULT_ROUGHNESS = 0.5;
const DEFAULT_METALLIC = 0.0;
export default class Brush {
gl: WebGL2RenderingContext;
albedoTexture: WebGLTexture;
roughnessTexture: WebGLTexture;
metallicTexture: WebGLTexture;
constructor(gl: WebGL2RenderingContext) {
this.gl = gl;
this.albedoTexture = gl.createTexture();
this.roughnessTexture = gl.createTexture();
this.metallicTexture = gl.createTexture();
this.color = vec3.create();
this.roughness = DEFAULT_ROUGHNESS;
this.metallic = DEFAULT_METALLIC;
}
set color(sRgb: vec3) {
const [r, g, b] = sRgb.map(srgbToRgb);
fillTexture(
this.gl,
this.albedoTexture,
1,
1,
new Uint8ClampedArray([r * 255, g * 255, b * 255, 255])
);
}
set roughness(roughness: number) {
const roughnessByte = roughness * 255;
fillTexture(
this.gl,
this.roughnessTexture,
1,
1,
new Uint8ClampedArray([
roughnessByte,
roughnessByte,
roughnessByte,
255,
])
);
}
set metallic(metallic: number) {
const metallicByte = metallic * 255;
fillTexture(
this.gl,
this.metallicTexture,
1,
1,
new Uint8ClampedArray([
metallicByte,
metallicByte,
metallicByte,
255,
])
);
}
}