I made this very simple, perfectly working, implementation of the Phong Relflection Model (there is no environment yet, but this does not bother me now). Functions should be self-learning.
public class PhongIllumination implements IlluminationModel {
@RGBParam(r = 0, g = 0, b = 0)
public Vec3 ambient;
@RGBParam(r = 1, g = 1, b = 1)
public Vec3 diffuse;
@RGBParam(r = 1, g = 1, b = 1)
public Vec3 specular;
@FloatParam(value = 20, min = 1, max = 200.0f)
public float shininess;
public Vec3 shade(Vec3 P, Vec3 V, Vec3 N, Vec3 surfaceColor, Light lights[]) {
Vec3 surfaceColordiffused = Vec3.mul(surfaceColor, diffuse);
Vec3 totalintensity = new Vec3(0, 0, 0);
for (int i = 0; i < lights.length; i++) {
Vec3 L = lights[i].calcDirection(P);
N = N.normalize();
V = V.normalize();
Vec3 R = Vec3.reflect(L, N);
float diffuseLight = Vec3.dot(N, L);
float specularLight = Vec3.dot(V, R);
if (diffuseLight > 0) {
totalintensity = Vec3.add(Vec3.mul(Vec3.mul(
surfaceColordiffused, lights[i].calcIntensity(P)),
diffuseLight), totalintensity);
if (specularLight > 0) {
Vec3 Il = lights[i].calcIntensity(P);
Vec3 Ilincident = Vec3.mul(Il, Math.max(0.0f, Vec3
.dot(N, L)));
Vec3 intensity = Vec3.mul(Vec3.mul(specular, Ilincident),
(float) Math.pow(specularLight, shininess));
totalintensity = Vec3.add(totalintensity, intensity);
}
}
}
return totalintensity;
}
}
Now I need to adapt it to become a Blinn-Phong lighting model
I used the formulas from hearn and baker, followed the pseudo-codes and tried to implement it several times according to wikipedia articles in several languages, but it never worked. I just donβt see mirror reflections or they are so weak and / or are in the wrong place and / or have the wrong color.
, .
Half Way :
Vec3 H = Vec3.mul(Vec3.add(L.normalize(), V), Vec3.add(L.normalize(), V).length());
float specularLight = Vec3.dot(H, N);
( , ). .
. , , .


, :

, blinn phong. . .
Edit:
, mutiplying |L+V| , H. :
Vec3 H = Vec3.mul(Vec3.add(L.normalize(), V), 1/Vec3.add(L.normalize(), V).length());
, . :

, :

.
, . .
: http://en.wikipedia.org/wiki/File:Blinn-Phong_vectors.svg
H N , V R. V , , "". .
, - ( R). , anywehre ...
: ( ), - .
, - , . ?
: , N/H V/R. , 4, . , .