//pref
Ambient|float|0.0|0.6|1
Diffuse|float|0.0|0.7|1
Specular|float|0.0|0.2|1
Shininess|float|1|60|120
PenWidth|float|0.01|0.5|1
Blinn-Phong shading with Lambertian diffuse. Copyright 2015 Chris Rorden, BSD2clause.|note
//frag
#version 120
varying vec3 vN, vV, vL;
varying vec4 vP, vClr;
uniform float Ambient = 0.6;
uniform float Diffuse = 0.7;
uniform float Specular = 0.2;
uniform float Shininess = 60.0;
uniform float PenWidth = 0.75;
uniform vec4 ClipPlane = vec4(2.0, 0.0, 0.0, 0.0);

vec3 desaturate(vec3 color, float Desaturation) {
	vec3 grayXfer = vec3(0.3, 0.59, 0.11);
	vec3 gray = vec3(dot(grayXfer, color));
	return mix(color, gray, Desaturation);
}

void main() {
	if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
	vec3 n = normalize(vN);
	float lightNormDot = abs(dot(n,normalize(vV))); //with respect to viewer
	if (PenWidth < lightNormDot) discard;
	vec3 l = normalize(vL);
	vec3 h = normalize(l+normalize(vV));
	vec3 a = vClr.rgb;
	vec3 bg = desaturate(a,0.8);
	vec3 backcolor = 0.7*Ambient*bg + 0.7*abs(dot(n,l))*Diffuse*bg;
	vec3 d = a * dot(n,l) * Diffuse;
	a *= Ambient;
	float s = pow(max(0.0,dot(n,h)), Shininess) * Specular;
	float backface = step(0.00, n.z);
	gl_FragColor = vec4(mix(backcolor.rgb, a + d + s,  backface), 1.0);
}