color shading(vec pos, vec normal, vec light_pos) { vec lv = light_pos.sub(pos).normal(); float f = max(normal.dot(lv), 0); return color(255 * f, 0, 0); }
vec light_pos = new vec(10, 10, -10);
... float t = intersect_line_sphere(eyepos, raydir, sphere_center, sphere_radius); if (t >= 0) { vec pos = eyepos.add(raydir.scale(t)); vec nrm = pos.sub(sphere_center).normal(); img[j] = shading(pos, nrm, light_pos); } else { img[j] = color(0, 0, 0); }
|