drawModel = regl({
frag: `
#extension GL_OES_standard_derivatives : enable
precision mediump float;
varying vec3 vnormal;
varying vec3 vposition;
// https://github.com/rreusser/glsl-solid-wireframe
float wireframe (vec3 parameter, float width, float feather) {
float w1 = width - feather * 0.5;
vec3 d = fwidth(parameter);
vec3 looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
vec3 a3 = smoothstep(d * w1, d * (w1 + feather), looped);
return min(a3.x, a3.z);
return min(min(a3.x, a3.y), a3.z);
}
void main () {
float m = wireframe(vposition * 2.0, 0.5, 2.0);
gl_FragColor = mix(vec4(1.0), vec4(abs(vnormal), 0.6), m);
}`,
vert: `
precision mediump float;
uniform mat4 projection, view;
attribute vec3 position, normal;
varying vec3 vnormal;
varying vec3 vposition;
void main () {
vnormal = normal;
vposition = position;
gl_Position = projection * view * vec4(position, 1.0);;
}`,
attributes: {
position: model.positions,
normal: normals(model.cells, model.positions)
},
blend: {
enable: true,
func: {
srcRGB: "src alpha",
srcAlpha: 1,
dstRGB: "one minus src alpha",
dstAlpha: 1
},
equation: {
rgb: "add",
alpha: "add"
}
},
elements: model.cells
})