Sphere's Shade method
public Color Shade(Ray ray, Vector lights, Vector objects, Color bgnd) {
// An object shader doesn't really do too much other than
// supply a few critical bits of geometric information
// for a surface shader. It must must compute:
//
// 1. the point of intersection (p)
// 2. a unit-length surface normal (n)
// 3. a unit-length vector towards the ray's origin (v)
//
float px, py, pz;
px = ray.origin.x + ray.t*ray.direction.x;
py = ray.origin.y + ray.t*ray.direction.y;
pz = ray.origin.z + ray.t*ray.direction.z;
Vector3D p, v, n;
p = new Vector3D(px, py, pz);
v = new Vector3D(-ray.direction.x, -ray.direction.y, -ray.direction.z);
n = new Vector3D(px - center.x, py - center.y, pz - center.z);
n.normalize();
// The illumination model is applied by the surface's Shade() method
return surface.Shade(p, n, v, lights, objects, bgnd);
}
}
|