Post by mariog on Nov 4, 2019 9:27:43 GMT
Hi,
I've been trying to track down the cause of this bug for two days now and it has got me beat. I am stuck at the end of Chapter 6, rendering a sphere with Phong shading. The image below is what I get when I run the program.
It is almost as if the program thinks the light is behind the object for some intersection points. The intersection routines are working fine (all the tests pass) as do the tests for the lighting. I keep focusing on the lighting function believing that the error must be in there somewhere. Here is the code for my lighting function:
public Color lighting(Material material, Light light, Tuple point, Tuple eyev, Tuple normalv) {
// combine the surface color with the light's color/intensity
Color effectiveColor = material.color.mult(light.intensity);
// find direction to light source
Tuple lightv = light.position.sub(point).normalize();
// compute ambient contribution
Color ambient = effectiveColor.mult(material.ambient);
// lightDotNormal represents the cosine of the angle between the
// light vector and the nromal vector. A negative number means the
// light is on the other side of the surface
double lightDotNormal = lightv.dot(normalv);
Color diffuse = null;
Color specular = null;
if( lightDotNormal < 0) {System.out.println("lightDotNormal: "+lightDotNormal);
diffuse = Color.rgb(0,0,0);
specular = Color.rgb(0,0,0);
} else {
diffuse = effectiveColor.mult(material.diffuse).mult(lightDotNormal);
// reflectDotEye represents the cosine of the angle between the
// reflection vector and the eye vector. A negative number means
// the light reflects away from the eye
Tuple reflectv = reflect(lightv.negate(), normalv);
double reflectDotEye = reflectv.dot(eyev);
if( reflectDotEye <= 0 ) {
specular = Color.rgb(0,0,0);
} else {
double factor = Math.pow(reflectDotEye, material.shininess);
specular = light.intensity.mult(material.specular).mult(factor);
}
}
return ambient.add(diffuse).add(specular);
}
Can anyone help by suggesting a test that I can perform that will help me track down the source of the bug? Thanks.