def intersect(self, ray, intersection): """Compute an intersection.""" w2p = self.world_to_primitive.interpolate(ray.time) ray_primitive = w2p(ray) intersection = Intersection() if not self.primitive.intersect(ray_primitive, intersection): return False ray.maxt = ray_primitive.maxt intersection.primitive_id = self.primitive_id if not w2p.is_identity(): # Compute world-to-object transformation for instance intersection.world_to_object = intersection.world_to_object * w2p intersection.object_to_world = inverse( intersection.world_to_object) p2w = inverse(w2p) # Transform instance's differential geometry to world space intersection.dg.p = p2w(intersection.dg.p) intersection.dg.nn = normalize(p2w(intersection.dg.nn)) intersection.dg.dpdu = p2w(intersection.dg.dp_du) intersection.dg.dpdv = p2w(intersection.dg.dp_dv) intersection.dg.dndu = p2w(intersection.dg.dn_du) intersection.dg.dndv = p2w(intersection.dg.dn_dv) return True
def __init__(self, camera_to_world, projection, screen_window, s_open, s_close, lens_radius, focal_distance, film): """Default constructor for ProjectiveCamera.""" super(ProjectiveCamera, self).__init__(camera_to_world, s_open, s_close, film) # initialize depth of field parameters self.lens_radius = lens_radius self.focal_distance = focal_distance # compute projective camera transformations self.camera_to_screen = projection # compute projective camera screen transformations sc1 = scale(float(film.x_resolution), float(film.y_resolution), 1.0) sc2 = scale(1.0 / (screen_window[1] - screen_window[0]), 1.0 / (screen_window[2] - screen_window[3]), 1.0) tr = translate(Point(-screen_window[0], -screen_window[3], 0.0)) self.screen_to_raster = sc1 * sc2 * tr self.raster_to_screen = inverse(self.screen_to_raster) self.raster_to_camera = inverse(self.camera_to_screen) * \ self.raster_to_screen
def intersect(self, ray, intersection): """Compute an intersection.""" w2p = self.world_to_primitive.interpolate(ray.time) ray_primitive = w2p(ray) intersection = Intersection() if not self.primitive.intersect(ray_primitive, intersection): return False ray.maxt = ray_primitive.maxt intersection.primitive_id = self.primitive_id if not w2p.is_identity(): # Compute world-to-object transformation for instance intersection.world_to_object = intersection.world_to_object * w2p intersection.object_to_world = inverse(intersection.world_to_object) p2w = inverse(w2p) # Transform instance's differential geometry to world space intersection.dg.p = p2w(intersection.dg.p) intersection.dg.nn = normalize(p2w(intersection.dg.nn)) intersection.dg.dpdu = p2w(intersection.dg.dp_du) intersection.dg.dpdv = p2w(intersection.dg.dp_dv) intersection.dg.dndu = p2w(intersection.dg.dn_du) intersection.dg.dndv = p2w(intersection.dg.dn_dv) return True