drawBunny = regl({
frag: await glsl`
precision mediump float;
${reglTools}
#pragma glslify: colormap = require('glsl-colormap/${colorMapName}')
varying vec3 vnormal, vpolars;
uniform bool useR;
void main () {
if (useR) {
gl_FragColor = colormap(vpolars.y);
if (vpolars.y < 0.001) {
gl_FragColor = vec4(vec3(0.0), 1.0);
}
// if (vpolars.y > 0.5) {
// gl_FragColor = vec4(vpolars.y-0.5, 0.0, 0.0, 1.0);
// } else {
// gl_FragColor = vec4(0.0, 0.0, 0.5-vpolars.y, 1.0);
// }
} else {
gl_FragColor = vec4(hsl2rgb(vec3(vpolars.x, 1.0, (vpolars.z-0.5)*0.6+0.5)), 1.0);
}
}`,
vert: `
precision mediump float;
uniform mat4 projection, view;
uniform vec3 offset;
uniform bool drawSphere;
attribute vec3 spherePosition, shPosition, normal, polars;
varying vec3 vnormal, vpolars;
void main () {
vec3 position;
if (drawSphere) {
position = spherePosition;
} else {
position = shPosition;
}
vnormal = normal;
vpolars = polars;
gl_Position = projection * view * vec4(position+offset, 1.0);
}`,
attributes: {
shPosition: data.shPositions,
spherePosition: data.spherePositions,
normal: normals(data.cells, data.shPositions),
polars: data.polars
},
uniforms: {
offset: regl.prop("offset"),
drawSphere: regl.prop("drawSphere"),
useR: regl.prop("useR")
},
elements: data.cells
})