Surface Shader (cont)
// Check if the surface point is in shadow
Vector3D poffset;
poffset = new Vector3D(p.x+TINY*l.x, p.y+TINY*l.y, p.z+TINY*l.z);
Ray shadowRay = new Ray(poffset, l);
if (shadowRay.trace(objects))
break;
// Illuminate point
float lambert = Vector3D.dot(n, l);
if (lambert > 0) {
// add in diffuse relectance contribution to color
if (kd > 0) {
r += kd*lambert*ir*light.ir;
g += kd*lambert*ig*light.ig;
b += kd*lambert*ib*light.ib;
}
|