Trace(ray) object_point = Closest_intersection(ray) if object_point returnShade(object_point, ray) elsereturn Background_Color
Shade(point, ray) radiance = black; /*初始化 */ for each light source shadow_ray = calc_shadow_ray(point,light) if !in_shadow(shadow_ray,light) radiance += phong_illumination(point,ray,light) if material is specularly reflective radiance += spec_reflectance * Trace(reflected_ray(point,ray))) if material is specularly transmissive radiance += spec_transmittance * Trace(refracted_ray(point,ray))) return radiance
computeImage(eye) for each pixel radiance = 0; H = integral(h(p)); for each sample // Np viewing rays pick sample point p within support of h; construct ray at eye, direction p-eye; radiance = radiance + rad(ray)*h(p); radiance = radiance/(#samples*H);
rad(ray) find closest intersection point x of ray with scene; return(Le(x,eye-x) + computeRadiance(x, eye-x));