-
Notifications
You must be signed in to change notification settings - Fork 0
/
light.js
50 lines (44 loc) · 1.17 KB
/
light.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
42
43
44
45
46
47
48
49
50
class Light {
/**
* Construct a light.
* @param {number} x
* @param {number} y
* @param {number} z
* @param {number} r
* @param {number} g
* @param {number} b
* @param {number} light_no
*/
constructor( x, y, z, r, g, b, light_no ) {
this.x = x;
this.y = y;
this.z = z;
this.r = r;
this.g = g;
this.b = b;
this.light_no = light_no;
}
/**
*
* @param {WebGLRenderingContext} gl
* @param {WebGLProgram} program
*/
bind( gl, program, modelview ) {
if( this.light_no == 0 ) { // this is the sun
set_uniform_vec3( gl, program, 'sun_dir', this.x, this.y, this.z );
set_uniform_vec3( gl, program, 'sun_color', this.r, this.g, this.b );
}
else {
set_uniform_vec3(
gl, program,
'light' + this.light_no + '_loc',
this.x, this.y, this.z
);
set_uniform_vec3(
gl, program,
'light' + this.light_no + '_color',
this.r, this.g, this.b
);
}
}
}