drawBox = regl({
frag: `
precision mediump float;
uniform vec4 color;
varying vec3 vertex_normal;
uniform vec3 light_dir;
void main () {
gl_FragColor = vec4(clamp(color.xyz*dot(vertex_normal,light_dir),0.0,1.0),1.0);
//gl_FragColor = vec4(vec3(gl_FragCoord.z),1.0);
}`,
vert: `
attribute vec3 position;
attribute vec3 normal;
varying vec3 vertex_normal;
uniform mat4 modelview;
uniform mat4 projection;
void main () {
vec4 worldpos = modelview*vec4(position, 1.0);
gl_Position = projection*worldpos;
vertex_normal = (modelview*vec4(normal,0.0)).xyz;
}`,
attributes: {
position: box.positions,
normal: box.normals
},
uniforms: {
color: [1, 1, 1, 1],
light_dir : vec3.normalize([], vec3.set ([],1,1,1)),
modelview : regl.prop('modelview'),
projection : regl.prop ('projection')
},
depth: {
enable: true,
func: '<',
mask: true,
},
count: box.positions.length/3
})