vec3 N = normalize(normal); // Points away from surfaceThen you need to compute (clamped) dot products between them:
vec3 L1 = normalize(vec3(0,1,0)); // Points toward light 1
vec3 C = normalize(vec3(cameraloc)-position); // Points toward camera
vec3 H1 = normalize(C+L1); // Blinn's "halfway vector" for light 1
float A=0.2; // Ambient illuminationAnd finally you just combine these together--you can get lots of different effects by combining them in different ways. Here I've added in "M" for the object ("Material") color, and "K" for a checkerboard pattern.
float D=clamp(dot(N,L1),0.0,1.0); // Diffuse light fraction
float S=pow(clamp(dot(N,H1),0.0,1.0),50.0); // Specular fraction. Constant controls highlight size
A- Ambient, 0.2 |
D- Diffuse, dot(N,L) |
M- Material Color, gl_Color |
S- Specular, pow(dot(N,H),...) |
M*A Typical Pure Ambient |
M*D Typical Pure Diffuse |
M*(D+A) Typical Lambertian |
M*(D+A)+S Classic Phong Lighting |
K- Checkerboard, using step(fract(position)) |
K*M*(D+A)+S Checkerboard controls overall diffuse color. |
M*(D+A)+K*S Checkerboard controls shininess. |
M*(D+A)+S+0.5*K Gently glowing checkerboard. |