I am trying to implement specular and diffuse lighting for a simple sphere ray tracing application, but I am having problems with my vectors.
I am trying to use the following to update the light, but the generated image looks exactly the same, so I know I am doing something wrong. I assume I am messing up the vectors in some way. Hit is the sphere that has been hit and mindis is the distance to this spheres point. Pir, pig, pib are the rgb for the color.
P3D intersection = ray.position.add(ray.direction).scale(mindis);
P3D l = intersection.sub(light).normalize();
P3D n = hit.center.sub(intersection).normalize();
double dot = l.dot(n);
P3D f = l.add(n).scale(-2.0 * dot);
double dot2 = f.dot(ray.direction);
pir += dot2 * 20;
pig += dot2 * 20;
pib += dot2 * 20;