예제 #1
0
def intersect_scene(scene, ray):
    # scene, ray -> Maybe (float, vector)
    for prim in scene:
        prim_type = sc.get_type(prim)
        ray = ry.normalize(ray)
        t = sc.intersect(prim_type)(prim, ray)
        if t and t > 0:
            normal = sc.get_normal(prim_type)(prim, ry.at_t(ray, t))
            return t, normal
        continue
    return None, None
예제 #2
0
def get_color(scene, lights, ray):
    # scene, lights, ray -> int
    t, normal = intersect_scene(scene, ray)
    ep = 1

    if not t or t <= 0:
        return 0
    if t:
        # calulate new pos...
        new_pos = ry.at_t(ray, t)
        new_pos = vr.add_vector(new_pos, vr.scale_mul(ep, normal))
        return intersect_lights(scene, lights, new_pos, normal)